Show More
@@ -1,92 +1,92 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 | return [ |
|
35 | return [ | |
36 | pjoin(root, 'IPython', 'frontend', 'html', 'notebook', 'static', 'components'), |
|
36 | pjoin(root, 'IPython', 'frontend', 'html', 'notebook', 'static', 'components'), | |
37 | ] |
|
37 | ] | |
38 |
|
38 | |||
39 | def is_repo(d): |
|
39 | def is_repo(d): | |
40 | """is d a git repo?""" |
|
40 | """is d a git repo?""" | |
41 | return os.path.exists(pjoin(d, '.git')) |
|
41 | return os.path.exists(pjoin(d, '.git')) | |
42 |
|
42 | |||
43 | def check_submodule_status(root=None): |
|
43 | def check_submodule_status(root=None): | |
44 | """check submodule status |
|
44 | """check submodule status | |
45 |
|
45 | |||
46 | Has three return values: |
|
46 | Has three return values: | |
47 |
|
47 | |||
48 | 'missing' - submodules are absent |
|
48 | 'missing' - submodules are absent | |
49 | 'unclean' - submodules have unstaged changes |
|
49 | 'unclean' - submodules have unstaged changes | |
50 | 'clean' - all submodules are up to date |
|
50 | 'clean' - all submodules are up to date | |
51 | """ |
|
51 | """ | |
52 |
|
52 | |||
53 | if hasattr(sys, "frozen"): |
|
53 | if hasattr(sys, "frozen"): | |
54 | # frozen via py2exe or similar, don't bother |
|
54 | # frozen via py2exe or similar, don't bother | |
55 | return 'clean' |
|
55 | return 'clean' | |
56 |
|
56 | |||
57 | if not root: |
|
57 | if not root: | |
58 | root = ipython_parent() |
|
58 | root = ipython_parent() | |
59 |
|
59 | |||
60 | submodules = ipython_submodules(root) |
|
60 | submodules = ipython_submodules(root) | |
61 |
|
61 | |||
62 | for submodule in submodules: |
|
62 | for submodule in submodules: | |
63 | if not os.path.exists(submodule): |
|
63 | if not os.path.exists(submodule): | |
64 | return 'missing' |
|
64 | return 'missing' | |
65 |
|
65 | |||
66 | if not is_repo(root): |
|
66 | if not is_repo(root): | |
67 | # not in git, assume clean |
|
67 | # not in git, assume clean | |
68 | return 'clean' |
|
68 | return 'clean' | |
69 |
|
69 | |||
70 | # check with git submodule status |
|
70 | # check with git submodule status | |
71 | proc = subprocess.Popen('git submodule status', |
|
71 | proc = subprocess.Popen('git submodule status', | |
72 | stdout=subprocess.PIPE, |
|
72 | stdout=subprocess.PIPE, | |
73 | stderr=subprocess.PIPE, |
|
73 | stderr=subprocess.PIPE, | |
74 | shell=True, |
|
74 | shell=True, | |
75 | cwd=root, |
|
75 | cwd=root, | |
76 | ) |
|
76 | ) | |
77 | status, _ = proc.communicate() |
|
77 | status, _ = proc.communicate() | |
78 | status = status.decode("ascii") |
|
78 | status = status.decode("ascii") | |
79 |
|
79 | |||
80 | for line in status.splitlines(): |
|
80 | for line in status.splitlines(): | |
81 | if status.startswith('-'): |
|
81 | if status.startswith('-'): | |
82 | return 'missing' |
|
82 | return 'missing' | |
83 | elif status.startswith('+'): |
|
83 | elif status.startswith('+'): | |
84 | return 'unclean' |
|
84 | return 'unclean' | |
85 |
|
85 | |||
86 | return 'clean' |
|
86 | return 'clean' | |
87 |
|
87 | |||
88 | def update_submodules(repo_dir): |
|
88 | def update_submodules(repo_dir): | |
89 | """update submodules in a repo""" |
|
89 | """update submodules in a repo""" | |
90 |
subprocess. |
|
90 | subprocess.check_call("git submodule init", cwd=repo_dir, shell=True) | |
91 |
subprocess. |
|
91 | subprocess.check_call("git submodule update --recursive", cwd=repo_dir, shell=True) | |
92 |
|
92 |
General Comments 0
You need to be logged in to leave comments.
Login now