diff options
Diffstat (limited to 'subcmds/manifest.py')
| -rw-r--r-- | subcmds/manifest.py | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/subcmds/manifest.py b/subcmds/manifest.py index 4374a9d0..dcd3df17 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py | |||
| @@ -17,14 +17,25 @@ 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() | ||
| 20 | 31 | ||
| 21 | class Manifest(PagedCommand): | 32 | class Manifest(PagedCommand): |
| 22 | common = False | 33 | common = False |
| 23 | helpSummary = "Manifest inspection utility" | 34 | helpSummary = "Manifest inspection utility" |
| 24 | helpUsage = """ | 35 | helpUsage = """ |
| 25 | %prog [-o {-|NAME.xml} [-r]] | 36 | %prog [options] |
| 26 | """ | 37 | """ |
| 27 | _helpDescription = """ | 38 | _xmlHelp = """ |
| 28 | 39 | ||
| 29 | With the -o option, exports the current manifest for inspection. | 40 | With the -o option, exports the current manifest for inspection. |
| 30 | The manifest and (if present) local_manifest.xml are combined | 41 | The manifest and (if present) local_manifest.xml are combined |
| @@ -35,23 +46,30 @@ in a Git repository for use during future 'repo init' invocations. | |||
| 35 | 46 | ||
| 36 | @property | 47 | @property |
| 37 | def helpDescription(self): | 48 | def helpDescription(self): |
| 38 | help = self._helpDescription + '\n' | 49 | help = '' |
| 39 | r = os.path.dirname(__file__) | 50 | if isinstance(self.manifest, XmlManifest): |
| 40 | r = os.path.dirname(r) | 51 | help += self._xmlHelp + '\n' + _doc('manifest_xml.txt') |
| 41 | fd = open(os.path.join(r, 'docs', 'manifest-format.txt')) | 52 | if isinstance(self.manifest, SubmoduleManifest): |
| 42 | for line in fd: | 53 | help += _doc('manifest_submodule.txt') |
| 43 | help += line | ||
| 44 | fd.close() | ||
| 45 | return help | 54 | return help |
| 46 | 55 | ||
| 47 | def _Options(self, p): | 56 | def _Options(self, p): |
| 48 | p.add_option('-r', '--revision-as-HEAD', | 57 | if isinstance(self.manifest, XmlManifest): |
| 49 | dest='peg_rev', action='store_true', | 58 | p.add_option('--upgrade', |
| 50 | help='Save revisions as current HEAD') | 59 | dest='upgrade', action='store_true', |
| 51 | p.add_option('-o', '--output-file', | 60 | help='Upgrade XML manifest to submodule') |
| 52 | dest='output_file', | 61 | p.add_option('-r', '--revision-as-HEAD', |
| 53 | help='File to save the manifest to', | 62 | dest='peg_rev', action='store_true', |
| 54 | metavar='-|NAME.xml') | 63 | help='Save revisions as current HEAD') |
| 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 | ||
| 55 | 73 | ||
| 56 | def _Output(self, opt): | 74 | def _Output(self, opt): |
| 57 | if opt.output_file == '-': | 75 | if opt.output_file == '-': |
| @@ -64,13 +82,38 @@ in a Git repository for use during future 'repo init' invocations. | |||
| 64 | if opt.output_file != '-': | 82 | if opt.output_file != '-': |
| 65 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file | 83 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file |
| 66 | 84 | ||
| 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 | |||
| 67 | def Execute(self, opt, args): | 105 | def Execute(self, opt, args): |
| 68 | if args: | 106 | if args: |
| 69 | self.Usage() | 107 | self.Usage() |
| 70 | 108 | ||
| 71 | if opt.output_file is not None: | 109 | if isinstance(self.manifest, XmlManifest): |
| 72 | self._Output(opt) | 110 | if opt.upgrade: |
| 73 | return | 111 | self._Upgrade() |
| 112 | return | ||
| 113 | |||
| 114 | if opt.output_file is not None: | ||
| 115 | self._Output(opt) | ||
| 116 | return | ||
| 74 | 117 | ||
| 75 | print >>sys.stderr, 'error: no operation to perform' | 118 | print >>sys.stderr, 'error: no operation to perform' |
| 76 | print >>sys.stderr, 'error: see repo help manifest' | 119 | print >>sys.stderr, 'error: see repo help manifest' |
