diff options
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 50 |
1 files changed, 24 insertions, 26 deletions
@@ -14,6 +14,7 @@ | |||
14 | # See the License for the specific language governing permissions and | 14 | # See the License for the specific language governing permissions and |
15 | # limitations under the License. | 15 | # limitations under the License. |
16 | 16 | ||
17 | from __future__ import print_function | ||
17 | import getpass | 18 | import getpass |
18 | import imp | 19 | import imp |
19 | import netrc | 20 | import netrc |
@@ -98,15 +99,14 @@ class _Repo(object): | |||
98 | if name == 'help': | 99 | if name == 'help': |
99 | name = 'version' | 100 | name = 'version' |
100 | else: | 101 | else: |
101 | print >>sys.stderr, 'fatal: invalid usage of --version' | 102 | print('fatal: invalid usage of --version', file=sys.stderr) |
102 | return 1 | 103 | return 1 |
103 | 104 | ||
104 | try: | 105 | try: |
105 | cmd = self.commands[name] | 106 | cmd = self.commands[name] |
106 | except KeyError: | 107 | except KeyError: |
107 | print >>sys.stderr,\ | 108 | print("repo: '%s' is not a repo command. See 'repo help'." % name, |
108 | "repo: '%s' is not a repo command. See 'repo help'."\ | 109 | file=sys.stderr) |
109 | % name | ||
110 | return 1 | 110 | return 1 |
111 | 111 | ||
112 | cmd.repodir = self.repodir | 112 | cmd.repodir = self.repodir |
@@ -114,9 +114,8 @@ class _Repo(object): | |||
114 | Editor.globalConfig = cmd.manifest.globalConfig | 114 | Editor.globalConfig = cmd.manifest.globalConfig |
115 | 115 | ||
116 | if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: | 116 | if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: |
117 | print >>sys.stderr, \ | 117 | print("fatal: '%s' requires a working directory" % name, |
118 | "fatal: '%s' requires a working directory"\ | 118 | file=sys.stderr) |
119 | % name | ||
120 | return 1 | 119 | return 1 |
121 | 120 | ||
122 | copts, cargs = cmd.OptionParser.parse_args(argv) | 121 | copts, cargs = cmd.OptionParser.parse_args(argv) |
@@ -142,22 +141,21 @@ class _Repo(object): | |||
142 | minutes, seconds = divmod(remainder, 60) | 141 | minutes, seconds = divmod(remainder, 60) |
143 | if gopts.time: | 142 | if gopts.time: |
144 | if hours == 0: | 143 | if hours == 0: |
145 | print >>sys.stderr, 'real\t%dm%.3fs' \ | 144 | print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr) |
146 | % (minutes, seconds) | ||
147 | else: | 145 | else: |
148 | print >>sys.stderr, 'real\t%dh%dm%.3fs' \ | 146 | print('real\t%dh%dm%.3fs' % (hours, minutes, seconds), |
149 | % (hours, minutes, seconds) | 147 | file=sys.stderr) |
150 | except DownloadError as e: | 148 | except DownloadError as e: |
151 | print >>sys.stderr, 'error: %s' % str(e) | 149 | print('error: %s' % str(e), file=sys.stderr) |
152 | return 1 | 150 | return 1 |
153 | except ManifestInvalidRevisionError as e: | 151 | except ManifestInvalidRevisionError as e: |
154 | print >>sys.stderr, 'error: %s' % str(e) | 152 | print('error: %s' % str(e), file=sys.stderr) |
155 | return 1 | 153 | return 1 |
156 | except NoSuchProjectError as e: | 154 | except NoSuchProjectError as e: |
157 | if e.name: | 155 | if e.name: |
158 | print >>sys.stderr, 'error: project %s not found' % e.name | 156 | print('error: project %s not found' % e.name, file=sys.stderr) |
159 | else: | 157 | else: |
160 | print >>sys.stderr, 'error: no project in current directory' | 158 | print('error: no project in current directory', file=sys.stderr) |
161 | return 1 | 159 | return 1 |
162 | 160 | ||
163 | return result | 161 | return result |
@@ -183,7 +181,7 @@ def _CheckWrapperVersion(ver, repo_path): | |||
183 | repo_path = '~/bin/repo' | 181 | repo_path = '~/bin/repo' |
184 | 182 | ||
185 | if not ver: | 183 | if not ver: |
186 | print >>sys.stderr, 'no --wrapper-version argument' | 184 | print('no --wrapper-version argument', file=sys.stderr) |
187 | sys.exit(1) | 185 | sys.exit(1) |
188 | 186 | ||
189 | exp = _CurrentWrapperVersion() | 187 | exp = _CurrentWrapperVersion() |
@@ -193,25 +191,25 @@ def _CheckWrapperVersion(ver, repo_path): | |||
193 | 191 | ||
194 | exp_str = '.'.join(map(str, exp)) | 192 | exp_str = '.'.join(map(str, exp)) |
195 | if exp[0] > ver[0] or ver < (0, 4): | 193 | if exp[0] > ver[0] or ver < (0, 4): |
196 | print >>sys.stderr, """ | 194 | print(""" |
197 | !!! A new repo command (%5s) is available. !!! | 195 | !!! A new repo command (%5s) is available. !!! |
198 | !!! You must upgrade before you can continue: !!! | 196 | !!! You must upgrade before you can continue: !!! |
199 | 197 | ||
200 | cp %s %s | 198 | cp %s %s |
201 | """ % (exp_str, _MyWrapperPath(), repo_path) | 199 | """ % (exp_str, _MyWrapperPath(), repo_path), file=sys.stderr) |
202 | sys.exit(1) | 200 | sys.exit(1) |
203 | 201 | ||
204 | if exp > ver: | 202 | if exp > ver: |
205 | print >>sys.stderr, """ | 203 | print(""" |
206 | ... A new repo command (%5s) is available. | 204 | ... A new repo command (%5s) is available. |
207 | ... You should upgrade soon: | 205 | ... You should upgrade soon: |
208 | 206 | ||
209 | cp %s %s | 207 | cp %s %s |
210 | """ % (exp_str, _MyWrapperPath(), repo_path) | 208 | """ % (exp_str, _MyWrapperPath(), repo_path), file=sys.stderr) |
211 | 209 | ||
212 | def _CheckRepoDir(repo_dir): | 210 | def _CheckRepoDir(repo_dir): |
213 | if not repo_dir: | 211 | if not repo_dir: |
214 | print >>sys.stderr, 'no --repo-dir argument' | 212 | print('no --repo-dir argument', file=sys.stderr) |
215 | sys.exit(1) | 213 | sys.exit(1) |
216 | 214 | ||
217 | def _PruneOptions(argv, opt): | 215 | def _PruneOptions(argv, opt): |
@@ -281,7 +279,7 @@ def _AddPasswordFromUserInput(handler, msg, req): | |||
281 | url = req.get_full_url() | 279 | url = req.get_full_url() |
282 | user, password = handler.passwd.find_user_password(None, url) | 280 | user, password = handler.passwd.find_user_password(None, url) |
283 | if user is None: | 281 | if user is None: |
284 | print msg | 282 | print(msg) |
285 | try: | 283 | try: |
286 | user = raw_input('User: ') | 284 | user = raw_input('User: ') |
287 | password = getpass.getpass() | 285 | password = getpass.getpass() |
@@ -388,10 +386,10 @@ def _Main(argv): | |||
388 | finally: | 386 | finally: |
389 | close_ssh() | 387 | close_ssh() |
390 | except KeyboardInterrupt: | 388 | except KeyboardInterrupt: |
391 | print >>sys.stderr, 'aborted by user' | 389 | print('aborted by user', file=sys.stderr) |
392 | result = 1 | 390 | result = 1 |
393 | except ManifestParseError as mpe: | 391 | except ManifestParseError as mpe: |
394 | print >>sys.stderr, 'fatal: %s' % mpe | 392 | print('fatal: %s' % mpe, file=sys.stderr) |
395 | result = 1 | 393 | result = 1 |
396 | except RepoChangedException as rce: | 394 | except RepoChangedException as rce: |
397 | # If repo changed, re-exec ourselves. | 395 | # If repo changed, re-exec ourselves. |
@@ -401,8 +399,8 @@ def _Main(argv): | |||
401 | try: | 399 | try: |
402 | os.execv(__file__, argv) | 400 | os.execv(__file__, argv) |
403 | except OSError as e: | 401 | except OSError as e: |
404 | print >>sys.stderr, 'fatal: cannot restart repo after upgrade' | 402 | print('fatal: cannot restart repo after upgrade', file=sys.stderr) |
405 | print >>sys.stderr, 'fatal: %s' % e | 403 | print('fatal: %s' % e, file=sys.stderr) |
406 | result = 128 | 404 | result = 128 |
407 | 405 | ||
408 | sys.exit(result) | 406 | sys.exit(result) |