summaryrefslogtreecommitdiffstats
path: root/command.py
diff options
context:
space:
mode:
Diffstat (limited to 'command.py')
-rw-r--r--command.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/command.py b/command.py
index 4e0253fc..4dbe2e77 100644
--- a/command.py
+++ b/command.py
@@ -15,17 +15,19 @@
15 15
16import os 16import os
17import optparse 17import optparse
18import platform
19import re
18import sys 20import sys
19 21
20import manifest_loader
21
22from error import NoSuchProjectError 22from error import NoSuchProjectError
23from error import InvalidProjectGroupsError
23 24
24class Command(object): 25class Command(object):
25 """Base class for any command line action in repo. 26 """Base class for any command line action in repo.
26 """ 27 """
27 28
28 common = False 29 common = False
30 manifest = None
29 _optparse = None 31 _optparse = None
30 32
31 def WantPager(self, opt): 33 def WantPager(self, opt):
@@ -57,31 +59,24 @@ class Command(object):
57 """Perform the action, after option parsing is complete. 59 """Perform the action, after option parsing is complete.
58 """ 60 """
59 raise NotImplementedError 61 raise NotImplementedError
60
61 @property
62 def manifest(self):
63 return self.GetManifest()
64
65 def GetManifest(self, reparse=False, type=None):
66 return manifest_loader.GetManifest(self.repodir,
67 reparse=reparse,
68 type=type)
69 62
70 def GetProjects(self, args, missing_ok=False): 63 def GetProjects(self, args, missing_ok=False):
71 """A list of projects that match the arguments. 64 """A list of projects that match the arguments.
72 """ 65 """
73 all = self.manifest.projects 66 all = self.manifest.projects
67 result = []
74 68
75 mp = self.manifest.manifestProject 69 mp = self.manifest.manifestProject
76 if mp.relpath == '.':
77 all = dict(all)
78 all[mp.name] = mp
79 70
80 result = [] 71 groups = mp.config.GetString('manifest.groups')
72 if not groups:
73 groups = 'default,platform-' + platform.system().lower()
74 groups = [x for x in re.split('[,\s]+', groups) if x]
81 75
82 if not args: 76 if not args:
83 for project in all.values(): 77 for project in all.values():
84 if missing_ok or project.Exists: 78 if ((missing_ok or project.Exists) and
79 project.MatchesGroups(groups)):
85 result.append(project) 80 result.append(project)
86 else: 81 else:
87 by_path = None 82 by_path = None
@@ -97,9 +92,7 @@ class Command(object):
97 for p in all.values(): 92 for p in all.values():
98 by_path[p.worktree] = p 93 by_path[p.worktree] = p
99 94
100 try: 95 if os.path.exists(path):
101 project = by_path[path]
102 except KeyError:
103 oldpath = None 96 oldpath = None
104 while path \ 97 while path \
105 and path != oldpath \ 98 and path != oldpath \
@@ -110,11 +103,18 @@ class Command(object):
110 except KeyError: 103 except KeyError:
111 oldpath = path 104 oldpath = path
112 path = os.path.dirname(path) 105 path = os.path.dirname(path)
106 else:
107 try:
108 project = by_path[path]
109 except KeyError:
110 pass
113 111
114 if not project: 112 if not project:
115 raise NoSuchProjectError(arg) 113 raise NoSuchProjectError(arg)
116 if not missing_ok and not project.Exists: 114 if not missing_ok and not project.Exists:
117 raise NoSuchProjectError(arg) 115 raise NoSuchProjectError(arg)
116 if not project.MatchesGroups(groups):
117 raise InvalidProjectGroupsError(arg)
118 118
119 result.append(project) 119 result.append(project)
120 120