Show More
@@ -1,92 +1,103 | |||
|
1 | 1 | """utilities for checking submodule status""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (C) 2013 The IPython Development Team |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import os |
|
15 | 15 | import subprocess |
|
16 | 16 | import sys |
|
17 | 17 | |
|
18 | 18 | #----------------------------------------------------------------------------- |
|
19 | 19 | # Globals |
|
20 | 20 | #----------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | pjoin = os.path.join |
|
23 | 23 | |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | # Code |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 | 28 | def ipython_parent(): |
|
29 | 29 | """return IPython's parent (i.e. root if run from git)""" |
|
30 | 30 | from IPython.utils.path import get_ipython_package_dir |
|
31 | 31 | return os.path.abspath(os.path.dirname(get_ipython_package_dir())) |
|
32 | 32 | |
|
33 | 33 | def ipython_submodules(root): |
|
34 | 34 | """return IPython submodules relative to root""" |
|
35 | from IPython.frontend.html.notebook import DEFAULT_STATIC_FILES_PATH | |
|
35 | 36 | return [ |
|
36 | pjoin(root, 'IPython', 'frontend', 'html', 'notebook', 'static', 'components'), | |
|
37 | pjoin(DEFAULT_STATIC_FILES_PATH, 'components') | |
|
37 | 38 | ] |
|
38 | 39 | |
|
39 | 40 | def is_repo(d): |
|
40 | 41 | """is d a git repo?""" |
|
41 | 42 | return os.path.exists(pjoin(d, '.git')) |
|
42 | 43 | |
|
44 | def is_package(): | |
|
45 | """Is a package manager responsible for the static files path?""" | |
|
46 | from IPython.utils.path import get_ipython_package_dir | |
|
47 | from IPython.frontend.html.notebook import DEFAULT_STATIC_FILES_PATH | |
|
48 | return not DEFAULT_STATIC_FILES_PATH.startswith(get_ipython_package_dir()) | |
|
49 | ||
|
43 | 50 | def check_submodule_status(root=None): |
|
44 | 51 | """check submodule status |
|
45 | 52 | |
|
46 | 53 | Has three return values: |
|
47 | 54 | |
|
48 | 55 | 'missing' - submodules are absent |
|
49 | 56 | 'unclean' - submodules have unstaged changes |
|
50 | 57 | 'clean' - all submodules are up to date |
|
51 | 58 | """ |
|
52 | 59 | |
|
53 | 60 | if hasattr(sys, "frozen"): |
|
54 | # frozen via py2exe or similar, don't bother | |
|
55 | return 'clean' | |
|
61 | # frozen via py2exe or similar, don't bother | |
|
62 | return 'clean' | |
|
63 | ||
|
64 | if is_package(): | |
|
65 | # package manager is responsible for static files, don't bother | |
|
66 | return 'clean' | |
|
56 | 67 | |
|
57 | 68 | if not root: |
|
58 | 69 | root = ipython_parent() |
|
59 | 70 | |
|
60 | 71 | submodules = ipython_submodules(root) |
|
61 | 72 | |
|
62 | 73 | for submodule in submodules: |
|
63 | 74 | if not os.path.exists(submodule): |
|
64 | 75 | return 'missing' |
|
65 | 76 | |
|
66 | 77 | if not is_repo(root): |
|
67 | 78 | # not in git, assume clean |
|
68 | 79 | return 'clean' |
|
69 | 80 | |
|
70 | 81 | # check with git submodule status |
|
71 | 82 | proc = subprocess.Popen('git submodule status', |
|
72 | 83 | stdout=subprocess.PIPE, |
|
73 | 84 | stderr=subprocess.PIPE, |
|
74 | 85 | shell=True, |
|
75 | 86 | cwd=root, |
|
76 | 87 | ) |
|
77 | 88 | status, _ = proc.communicate() |
|
78 | 89 | status = status.decode("ascii") |
|
79 | 90 | |
|
80 | 91 | for line in status.splitlines(): |
|
81 | 92 | if status.startswith('-'): |
|
82 | 93 | return 'missing' |
|
83 | 94 | elif status.startswith('+'): |
|
84 | 95 | return 'unclean' |
|
85 | 96 | |
|
86 | 97 | return 'clean' |
|
87 | 98 | |
|
88 | 99 | def update_submodules(repo_dir): |
|
89 | 100 | """update submodules in a repo""" |
|
90 | 101 | subprocess.check_call("git submodule init", cwd=repo_dir, shell=True) |
|
91 | 102 | subprocess.check_call("git submodule update --recursive", cwd=repo_dir, shell=True) |
|
92 | 103 |
General Comments 0
You need to be logged in to leave comments.
Login now