summaryrefslogtreecommitdiffstats
path: root/subcmds/manifest.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/manifest.py')
-rw-r--r--subcmds/manifest.py230
1 files changed, 137 insertions, 93 deletions
diff --git a/subcmds/manifest.py b/subcmds/manifest.py
index f4602a59..f72df348 100644
--- a/subcmds/manifest.py
+++ b/subcmds/manifest.py
@@ -20,12 +20,12 @@ from command import PagedCommand
20 20
21 21
22class Manifest(PagedCommand): 22class Manifest(PagedCommand):
23 COMMON = False 23 COMMON = False
24 helpSummary = "Manifest inspection utility" 24 helpSummary = "Manifest inspection utility"
25 helpUsage = """ 25 helpUsage = """
26%prog [-o {-|NAME.xml}] [-m MANIFEST.xml] [-r] 26%prog [-o {-|NAME.xml}] [-m MANIFEST.xml] [-r]
27""" 27"""
28 _helpDescription = """ 28 _helpDescription = """
29 29
30With the -o option, exports the current manifest for inspection. 30With the -o option, exports the current manifest for inspection.
31The manifest and (if present) local_manifests/ are combined 31The manifest and (if present) local_manifests/ are combined
@@ -40,92 +40,136 @@ when the manifest was generated. The 'dest-branch' attribute is set
40to indicate the remote ref to push changes to via 'repo upload'. 40to indicate the remote ref to push changes to via 'repo upload'.
41""" 41"""
42 42
43 @property 43 @property
44 def helpDescription(self): 44 def helpDescription(self):
45 helptext = self._helpDescription + '\n' 45 helptext = self._helpDescription + "\n"
46 r = os.path.dirname(__file__) 46 r = os.path.dirname(__file__)
47 r = os.path.dirname(r) 47 r = os.path.dirname(r)
48 with open(os.path.join(r, 'docs', 'manifest-format.md')) as fd: 48 with open(os.path.join(r, "docs", "manifest-format.md")) as fd:
49 for line in fd: 49 for line in fd:
50 helptext += line 50 helptext += line
51 return helptext 51 return helptext
52 52
53 def _Options(self, p): 53 def _Options(self, p):
54 p.add_option('-r', '--revision-as-HEAD', 54 p.add_option(
55 dest='peg_rev', action='store_true', 55 "-r",
56 help='save revisions as current HEAD') 56 "--revision-as-HEAD",
57 p.add_option('-m', '--manifest-name', 57 dest="peg_rev",
58 help='temporary manifest to use for this sync', metavar='NAME.xml') 58 action="store_true",
59 p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream', 59 help="save revisions as current HEAD",
60 default=True, action='store_false', 60 )
61 help='if in -r mode, do not write the upstream field ' 61 p.add_option(
62 '(only of use if the branch names for a sha1 manifest are ' 62 "-m",
63 'sensitive)') 63 "--manifest-name",
64 p.add_option('--suppress-dest-branch', dest='peg_rev_dest_branch', 64 help="temporary manifest to use for this sync",
65 default=True, action='store_false', 65 metavar="NAME.xml",
66 help='if in -r mode, do not write the dest-branch field ' 66 )
67 '(only of use if the branch names for a sha1 manifest are ' 67 p.add_option(
68 'sensitive)') 68 "--suppress-upstream-revision",
69 p.add_option('--json', default=False, action='store_true', 69 dest="peg_rev_upstream",
70 help='output manifest in JSON format (experimental)') 70 default=True,
71 p.add_option('--pretty', default=False, action='store_true', 71 action="store_false",
72 help='format output for humans to read') 72 help="if in -r mode, do not write the upstream field "
73 p.add_option('--no-local-manifests', default=False, action='store_true', 73 "(only of use if the branch names for a sha1 manifest are "
74 dest='ignore_local_manifests', help='ignore local manifests') 74 "sensitive)",
75 p.add_option('-o', '--output-file', 75 )
76 dest='output_file', 76 p.add_option(
77 default='-', 77 "--suppress-dest-branch",
78 help='file to save the manifest to. (Filename prefix for multi-tree.)', 78 dest="peg_rev_dest_branch",
79 metavar='-|NAME.xml') 79 default=True,
80 80 action="store_false",
81 def _Output(self, opt): 81 help="if in -r mode, do not write the dest-branch field "
82 # If alternate manifest is specified, override the manifest file that we're using. 82 "(only of use if the branch names for a sha1 manifest are "
83 if opt.manifest_name: 83 "sensitive)",
84 self.manifest.Override(opt.manifest_name, False) 84 )
85 85 p.add_option(
86 for manifest in self.ManifestList(opt): 86 "--json",
87 output_file = opt.output_file 87 default=False,
88 if output_file == '-': 88 action="store_true",
89 fd = sys.stdout 89 help="output manifest in JSON format (experimental)",
90 else: 90 )
91 if manifest.path_prefix: 91 p.add_option(
92 output_file = f'{opt.output_file}:{manifest.path_prefix.replace("/", "%2f")}' 92 "--pretty",
93 fd = open(output_file, 'w') 93 default=False,
94 94 action="store_true",
95 manifest.SetUseLocalManifests(not opt.ignore_local_manifests) 95 help="format output for humans to read",
96 96 )
97 if opt.json: 97 p.add_option(
98 print('warning: --json is experimental!', file=sys.stderr) 98 "--no-local-manifests",
99 doc = manifest.ToDict(peg_rev=opt.peg_rev, 99 default=False,
100 peg_rev_upstream=opt.peg_rev_upstream, 100 action="store_true",
101 peg_rev_dest_branch=opt.peg_rev_dest_branch) 101 dest="ignore_local_manifests",
102 102 help="ignore local manifests",
103 json_settings = { 103 )
104 # JSON style guide says Uunicode characters are fully allowed. 104 p.add_option(
105 'ensure_ascii': False, 105 "-o",
106 # We use 2 space indent to match JSON style guide. 106 "--output-file",
107 'indent': 2 if opt.pretty else None, 107 dest="output_file",
108 'separators': (',', ': ') if opt.pretty else (',', ':'), 108 default="-",
109 'sort_keys': True, 109 help="file to save the manifest to. (Filename prefix for "
110 } 110 "multi-tree.)",
111 fd.write(json.dumps(doc, **json_settings)) 111 metavar="-|NAME.xml",
112 else: 112 )
113 manifest.Save(fd, 113
114 peg_rev=opt.peg_rev, 114 def _Output(self, opt):
115 peg_rev_upstream=opt.peg_rev_upstream, 115 # If alternate manifest is specified, override the manifest file that
116 peg_rev_dest_branch=opt.peg_rev_dest_branch) 116 # we're using.
117 if output_file != '-': 117 if opt.manifest_name:
118 fd.close() 118 self.manifest.Override(opt.manifest_name, False)
119 if manifest.path_prefix: 119
120 print(f'Saved {manifest.path_prefix} submanifest to {output_file}', 120 for manifest in self.ManifestList(opt):
121 file=sys.stderr) 121 output_file = opt.output_file
122 else: 122 if output_file == "-":
123 print(f'Saved manifest to {output_file}', file=sys.stderr) 123 fd = sys.stdout
124 124 else:
125 125 if manifest.path_prefix:
126 def ValidateOptions(self, opt, args): 126 output_file = (
127 if args: 127 f"{opt.output_file}:"
128 self.Usage() 128 f'{manifest.path_prefix.replace("/", "%2f")}'
129 129 )
130 def Execute(self, opt, args): 130 fd = open(output_file, "w")
131 self._Output(opt) 131
132 manifest.SetUseLocalManifests(not opt.ignore_local_manifests)
133
134 if opt.json:
135 print("warning: --json is experimental!", file=sys.stderr)
136 doc = manifest.ToDict(
137 peg_rev=opt.peg_rev,
138 peg_rev_upstream=opt.peg_rev_upstream,
139 peg_rev_dest_branch=opt.peg_rev_dest_branch,
140 )
141
142 json_settings = {
143 # JSON style guide says Unicode characters are fully
144 # allowed.
145 "ensure_ascii": False,
146 # We use 2 space indent to match JSON style guide.
147 "indent": 2 if opt.pretty else None,
148 "separators": (",", ": ") if opt.pretty else (",", ":"),
149 "sort_keys": True,
150 }
151 fd.write(json.dumps(doc, **json_settings))
152 else:
153 manifest.Save(
154 fd,
155 peg_rev=opt.peg_rev,
156 peg_rev_upstream=opt.peg_rev_upstream,
157 peg_rev_dest_branch=opt.peg_rev_dest_branch,
158 )
159 if output_file != "-":
160 fd.close()
161 if manifest.path_prefix:
162 print(
163 f"Saved {manifest.path_prefix} submanifest to "
164 f"{output_file}",
165 file=sys.stderr,
166 )
167 else:
168 print(f"Saved manifest to {output_file}", file=sys.stderr)
169
170 def ValidateOptions(self, opt, args):
171 if args:
172 self.Usage()
173
174 def Execute(self, opt, args):
175 self._Output(opt)