diff options
Diffstat (limited to 'subcmds/init.py')
-rw-r--r-- | subcmds/init.py | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/subcmds/init.py b/subcmds/init.py index b6b98076..11312601 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
@@ -13,6 +13,7 @@ | |||
13 | # See the License for the specific language governing permissions and | 13 | # See the License for the specific language governing permissions and |
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | from __future__ import print_function | ||
16 | import os | 17 | import os |
17 | import platform | 18 | import platform |
18 | import re | 19 | import re |
@@ -117,18 +118,22 @@ to update the working directory files. | |||
117 | dest='config_name', action="store_true", default=False, | 118 | dest='config_name', action="store_true", default=False, |
118 | help='Always prompt for name/e-mail') | 119 | help='Always prompt for name/e-mail') |
119 | 120 | ||
121 | def _RegisteredEnvironmentOptions(self): | ||
122 | return {'REPO_MANIFEST_URL': 'manifest_url', | ||
123 | 'REPO_MIRROR_LOCATION': 'reference'} | ||
124 | |||
120 | def _SyncManifest(self, opt): | 125 | def _SyncManifest(self, opt): |
121 | m = self.manifest.manifestProject | 126 | m = self.manifest.manifestProject |
122 | is_new = not m.Exists | 127 | is_new = not m.Exists |
123 | 128 | ||
124 | if is_new: | 129 | if is_new: |
125 | if not opt.manifest_url: | 130 | if not opt.manifest_url: |
126 | print >>sys.stderr, 'fatal: manifest url (-u) is required.' | 131 | print('fatal: manifest url (-u) is required.', file=sys.stderr) |
127 | sys.exit(1) | 132 | sys.exit(1) |
128 | 133 | ||
129 | if not opt.quiet: | 134 | if not opt.quiet: |
130 | print >>sys.stderr, 'Get %s' \ | 135 | print('Get %s' % GitConfig.ForUser().UrlInsteadOf(opt.manifest_url), |
131 | % GitConfig.ForUser().UrlInsteadOf(opt.manifest_url) | 136 | file=sys.stderr) |
132 | m._InitGitDir() | 137 | m._InitGitDir() |
133 | 138 | ||
134 | if opt.manifest_branch: | 139 | if opt.manifest_branch: |
@@ -147,7 +152,7 @@ to update the working directory files. | |||
147 | r.ResetFetch() | 152 | r.ResetFetch() |
148 | r.Save() | 153 | r.Save() |
149 | 154 | ||
150 | groups = re.split('[,\s]+', opt.groups) | 155 | groups = re.split(r'[,\s]+', opt.groups) |
151 | all_platforms = ['linux', 'darwin'] | 156 | all_platforms = ['linux', 'darwin'] |
152 | platformize = lambda x: 'platform-' + x | 157 | platformize = lambda x: 'platform-' + x |
153 | if opt.platform == 'auto': | 158 | if opt.platform == 'auto': |
@@ -159,7 +164,7 @@ to update the working directory files. | |||
159 | elif opt.platform in all_platforms: | 164 | elif opt.platform in all_platforms: |
160 | groups.extend(platformize(opt.platform)) | 165 | groups.extend(platformize(opt.platform)) |
161 | elif opt.platform != 'none': | 166 | elif opt.platform != 'none': |
162 | print >>sys.stderr, 'fatal: invalid platform flag' | 167 | print('fatal: invalid platform flag', file=sys.stderr) |
163 | sys.exit(1) | 168 | sys.exit(1) |
164 | 169 | ||
165 | groups = [x for x in groups if x] | 170 | groups = [x for x in groups if x] |
@@ -175,12 +180,15 @@ to update the working directory files. | |||
175 | if is_new: | 180 | if is_new: |
176 | m.config.SetString('repo.mirror', 'true') | 181 | m.config.SetString('repo.mirror', 'true') |
177 | else: | 182 | else: |
178 | print >>sys.stderr, 'fatal: --mirror not supported on existing client' | 183 | print('fatal: --mirror is only supported when initializing a new ' |
184 | 'workspace.', file=sys.stderr) | ||
185 | print('Either delete the .repo folder in this workspace, or initialize ' | ||
186 | 'in another location.', file=sys.stderr) | ||
179 | sys.exit(1) | 187 | sys.exit(1) |
180 | 188 | ||
181 | if not m.Sync_NetworkHalf(is_new=is_new): | 189 | if not m.Sync_NetworkHalf(is_new=is_new): |
182 | r = m.GetRemote(m.remote.name) | 190 | r = m.GetRemote(m.remote.name) |
183 | print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url | 191 | print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr) |
184 | 192 | ||
185 | # Better delete the manifest git dir if we created it; otherwise next | 193 | # Better delete the manifest git dir if we created it; otherwise next |
186 | # time (when user fixes problems) we won't go through the "is_new" logic. | 194 | # time (when user fixes problems) we won't go through the "is_new" logic. |
@@ -197,19 +205,19 @@ to update the working directory files. | |||
197 | 205 | ||
198 | if is_new or m.CurrentBranch is None: | 206 | if is_new or m.CurrentBranch is None: |
199 | if not m.StartBranch('default'): | 207 | if not m.StartBranch('default'): |
200 | print >>sys.stderr, 'fatal: cannot create default in manifest' | 208 | print('fatal: cannot create default in manifest', file=sys.stderr) |
201 | sys.exit(1) | 209 | sys.exit(1) |
202 | 210 | ||
203 | def _LinkManifest(self, name): | 211 | def _LinkManifest(self, name): |
204 | if not name: | 212 | if not name: |
205 | print >>sys.stderr, 'fatal: manifest name (-m) is required.' | 213 | print('fatal: manifest name (-m) is required.', file=sys.stderr) |
206 | sys.exit(1) | 214 | sys.exit(1) |
207 | 215 | ||
208 | try: | 216 | try: |
209 | self.manifest.Link(name) | 217 | self.manifest.Link(name) |
210 | except ManifestParseError as e: | 218 | except ManifestParseError as e: |
211 | print >>sys.stderr, "fatal: manifest '%s' not available" % name | 219 | print("fatal: manifest '%s' not available" % name, file=sys.stderr) |
212 | print >>sys.stderr, 'fatal: %s' % str(e) | 220 | print('fatal: %s' % str(e), file=sys.stderr) |
213 | sys.exit(1) | 221 | sys.exit(1) |
214 | 222 | ||
215 | def _Prompt(self, prompt, value): | 223 | def _Prompt(self, prompt, value): |
@@ -231,24 +239,24 @@ to update the working directory files. | |||
231 | mp.config.SetString('user.name', gc.GetString('user.name')) | 239 | mp.config.SetString('user.name', gc.GetString('user.name')) |
232 | mp.config.SetString('user.email', gc.GetString('user.email')) | 240 | mp.config.SetString('user.email', gc.GetString('user.email')) |
233 | 241 | ||
234 | print '' | 242 | print() |
235 | print 'Your identity is: %s <%s>' % (mp.config.GetString('user.name'), | 243 | print('Your identity is: %s <%s>' % (mp.config.GetString('user.name'), |
236 | mp.config.GetString('user.email')) | 244 | mp.config.GetString('user.email'))) |
237 | print 'If you want to change this, please re-run \'repo init\' with --config-name' | 245 | print('If you want to change this, please re-run \'repo init\' with --config-name') |
238 | return False | 246 | return False |
239 | 247 | ||
240 | def _ConfigureUser(self): | 248 | def _ConfigureUser(self): |
241 | mp = self.manifest.manifestProject | 249 | mp = self.manifest.manifestProject |
242 | 250 | ||
243 | while True: | 251 | while True: |
244 | print '' | 252 | print() |
245 | name = self._Prompt('Your Name', mp.UserName) | 253 | name = self._Prompt('Your Name', mp.UserName) |
246 | email = self._Prompt('Your Email', mp.UserEmail) | 254 | email = self._Prompt('Your Email', mp.UserEmail) |
247 | 255 | ||
248 | print '' | 256 | print() |
249 | print 'Your identity is: %s <%s>' % (name, email) | 257 | print('Your identity is: %s <%s>' % (name, email)) |
250 | sys.stdout.write('is this correct [y/N]? ') | 258 | sys.stdout.write('is this correct [y/N]? ') |
251 | a = sys.stdin.readline().strip() | 259 | a = sys.stdin.readline().strip().lower() |
252 | if a in ('yes', 'y', 't', 'true'): | 260 | if a in ('yes', 'y', 't', 'true'): |
253 | break | 261 | break |
254 | 262 | ||
@@ -274,17 +282,17 @@ to update the working directory files. | |||
274 | self._on = True | 282 | self._on = True |
275 | out = _Test() | 283 | out = _Test() |
276 | 284 | ||
277 | print '' | 285 | print() |
278 | print "Testing colorized output (for 'repo diff', 'repo status'):" | 286 | print("Testing colorized output (for 'repo diff', 'repo status'):") |
279 | 287 | ||
280 | for c in ['black','red','green','yellow','blue','magenta','cyan']: | 288 | for c in ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan']: |
281 | out.write(' ') | 289 | out.write(' ') |
282 | out.printer(fg=c)(' %-6s ', c) | 290 | out.printer(fg=c)(' %-6s ', c) |
283 | out.write(' ') | 291 | out.write(' ') |
284 | out.printer(fg='white', bg='black')(' %s ' % 'white') | 292 | out.printer(fg='white', bg='black')(' %s ' % 'white') |
285 | out.nl() | 293 | out.nl() |
286 | 294 | ||
287 | for c in ['bold','dim','ul','reverse']: | 295 | for c in ['bold', 'dim', 'ul', 'reverse']: |
288 | out.write(' ') | 296 | out.write(' ') |
289 | out.printer(fg='black', attr=c)(' %-6s ', c) | 297 | out.printer(fg='black', attr=c)(' %-6s ', c) |
290 | out.nl() | 298 | out.nl() |
@@ -313,6 +321,23 @@ to update the working directory files. | |||
313 | # We store the depth in the main manifest project. | 321 | # We store the depth in the main manifest project. |
314 | self.manifest.manifestProject.config.SetString('repo.depth', depth) | 322 | self.manifest.manifestProject.config.SetString('repo.depth', depth) |
315 | 323 | ||
324 | def _DisplayResult(self): | ||
325 | if self.manifest.IsMirror: | ||
326 | init_type = 'mirror ' | ||
327 | else: | ||
328 | init_type = '' | ||
329 | |||
330 | print() | ||
331 | print('repo %shas been initialized in %s' | ||
332 | % (init_type, self.manifest.topdir)) | ||
333 | |||
334 | current_dir = os.getcwd() | ||
335 | if current_dir != self.manifest.topdir: | ||
336 | print('If this is not the directory in which you want to initialize ' | ||
337 | 'repo, please run:') | ||
338 | print(' rm -r %s/.repo' % self.manifest.topdir) | ||
339 | print('and try again.') | ||
340 | |||
316 | def Execute(self, opt, args): | 341 | def Execute(self, opt, args): |
317 | git_require(MIN_GIT_VERSION, fail=True) | 342 | git_require(MIN_GIT_VERSION, fail=True) |
318 | 343 | ||
@@ -329,10 +354,4 @@ to update the working directory files. | |||
329 | 354 | ||
330 | self._ConfigureDepth(opt) | 355 | self._ConfigureDepth(opt) |
331 | 356 | ||
332 | if self.manifest.IsMirror: | 357 | self._DisplayResult() |
333 | init_type = 'mirror ' | ||
334 | else: | ||
335 | init_type = '' | ||
336 | |||
337 | print '' | ||
338 | print 'repo %sinitialized in %s' % (init_type, self.manifest.topdir) | ||