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