diff options
Diffstat (limited to 'subcmds/manifest.py')
-rw-r--r-- | subcmds/manifest.py | 81 |
1 files changed, 19 insertions, 62 deletions
diff --git a/subcmds/manifest.py b/subcmds/manifest.py index dcd3df17..4374a9d0 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py | |||
@@ -17,25 +17,14 @@ import os | |||
17 | import sys | 17 | import sys |
18 | 18 | ||
19 | from command import PagedCommand | 19 | from command import PagedCommand |
20 | from manifest_submodule import SubmoduleManifest | ||
21 | from manifest_xml import XmlManifest | ||
22 | |||
23 | def _doc(name): | ||
24 | r = os.path.dirname(__file__) | ||
25 | r = os.path.dirname(r) | ||
26 | fd = open(os.path.join(r, 'docs', name)) | ||
27 | try: | ||
28 | return fd.read() | ||
29 | finally: | ||
30 | fd.close() | ||
31 | 20 | ||
32 | class Manifest(PagedCommand): | 21 | class Manifest(PagedCommand): |
33 | common = False | 22 | common = False |
34 | helpSummary = "Manifest inspection utility" | 23 | helpSummary = "Manifest inspection utility" |
35 | helpUsage = """ | 24 | helpUsage = """ |
36 | %prog [options] | 25 | %prog [-o {-|NAME.xml} [-r]] |
37 | """ | 26 | """ |
38 | _xmlHelp = """ | 27 | _helpDescription = """ |
39 | 28 | ||
40 | With the -o option, exports the current manifest for inspection. | 29 | With the -o option, exports the current manifest for inspection. |
41 | The manifest and (if present) local_manifest.xml are combined | 30 | The manifest and (if present) local_manifest.xml are combined |
@@ -46,30 +35,23 @@ in a Git repository for use during future 'repo init' invocations. | |||
46 | 35 | ||
47 | @property | 36 | @property |
48 | def helpDescription(self): | 37 | def helpDescription(self): |
49 | help = '' | 38 | help = self._helpDescription + '\n' |
50 | if isinstance(self.manifest, XmlManifest): | 39 | r = os.path.dirname(__file__) |
51 | help += self._xmlHelp + '\n' + _doc('manifest_xml.txt') | 40 | r = os.path.dirname(r) |
52 | if isinstance(self.manifest, SubmoduleManifest): | 41 | fd = open(os.path.join(r, 'docs', 'manifest-format.txt')) |
53 | help += _doc('manifest_submodule.txt') | 42 | for line in fd: |
43 | help += line | ||
44 | fd.close() | ||
54 | return help | 45 | return help |
55 | 46 | ||
56 | def _Options(self, p): | 47 | def _Options(self, p): |
57 | if isinstance(self.manifest, XmlManifest): | 48 | p.add_option('-r', '--revision-as-HEAD', |
58 | p.add_option('--upgrade', | 49 | dest='peg_rev', action='store_true', |
59 | dest='upgrade', action='store_true', | 50 | help='Save revisions as current HEAD') |
60 | help='Upgrade XML manifest to submodule') | 51 | p.add_option('-o', '--output-file', |
61 | p.add_option('-r', '--revision-as-HEAD', | 52 | dest='output_file', |
62 | dest='peg_rev', action='store_true', | 53 | help='File to save the manifest to', |
63 | help='Save revisions as current HEAD') | 54 | metavar='-|NAME.xml') |
64 | p.add_option('-o', '--output-file', | ||
65 | dest='output_file', | ||
66 | help='File to save the manifest to', | ||
67 | metavar='-|NAME.xml') | ||
68 | |||
69 | def WantPager(self, opt): | ||
70 | if isinstance(self.manifest, XmlManifest) and opt.upgrade: | ||
71 | return False | ||
72 | return True | ||
73 | 55 | ||
74 | def _Output(self, opt): | 56 | def _Output(self, opt): |
75 | if opt.output_file == '-': | 57 | if opt.output_file == '-': |
@@ -82,38 +64,13 @@ in a Git repository for use during future 'repo init' invocations. | |||
82 | if opt.output_file != '-': | 64 | if opt.output_file != '-': |
83 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file | 65 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file |
84 | 66 | ||
85 | def _Upgrade(self): | ||
86 | old = self.manifest | ||
87 | |||
88 | if isinstance(old, SubmoduleManifest): | ||
89 | print >>sys.stderr, 'error: already upgraded' | ||
90 | sys.exit(1) | ||
91 | |||
92 | old._Load() | ||
93 | for p in old.projects.values(): | ||
94 | if not os.path.exists(p.gitdir) \ | ||
95 | or not os.path.exists(p.worktree): | ||
96 | print >>sys.stderr, 'fatal: project "%s" missing' % p.relpath | ||
97 | sys.exit(1) | ||
98 | |||
99 | new = SubmoduleManifest(old.repodir) | ||
100 | new.FromXml_Local_1(old, checkout=False) | ||
101 | new.FromXml_Definition(old) | ||
102 | new.FromXml_Local_2(old) | ||
103 | print >>sys.stderr, 'upgraded manifest; commit result manually' | ||
104 | |||
105 | def Execute(self, opt, args): | 67 | def Execute(self, opt, args): |
106 | if args: | 68 | if args: |
107 | self.Usage() | 69 | self.Usage() |
108 | 70 | ||
109 | if isinstance(self.manifest, XmlManifest): | 71 | if opt.output_file is not None: |
110 | if opt.upgrade: | 72 | self._Output(opt) |
111 | self._Upgrade() | 73 | return |
112 | return | ||
113 | |||
114 | if opt.output_file is not None: | ||
115 | self._Output(opt) | ||
116 | return | ||
117 | 74 | ||
118 | print >>sys.stderr, 'error: no operation to perform' | 75 | print >>sys.stderr, 'error: no operation to perform' |
119 | print >>sys.stderr, 'error: see repo help manifest' | 76 | print >>sys.stderr, 'error: see repo help manifest' |