diff options
| author | Chirayu Desai <cdesai@cyanogenmod.org> | 2013-03-01 19:14:38 +0530 |
|---|---|---|
| committer | Chirayu Desai <cdesai@cyanogenmod.org> | 2013-04-18 21:35:49 +0530 |
| commit | 217ea7d2747e3098009afe0b389fc4b45f55ea5a (patch) | |
| tree | 4ea2663a01fb22002ec6cd6ede9cb3babd89a692 /subcmds | |
| parent | fef4ae74e26efecf5c803793351b6c843eab4970 (diff) | |
| download | git-repo-217ea7d2747e3098009afe0b389fc4b45f55ea5a.tar.gz | |
Some fixes for supporting python3
* Fix imports.
* Use python3 syntax.
* Wrap map() calls with list().
* Use list() only wherever needed.
(Thanks Conley!)
* Fix dictionary iteration methods
(s/iteritems/items/).
* Make use of sorted() in appropriate places
* Use iterators directly in the loop.
* Don't use .keys() wherever it isn't needed.
* Use sys.maxsize instead of sys.maxint
TODO:
* Make repo work fully with python3. :)
Some of this was done by the '2to3' tool [1], by
applying the needed fixes in a way that doesn't
break compatibility with python2.
Links:
[1]: http://docs.python.org/2/library/2to3.html
Change-Id: Ibdf3bf9a530d716db905733cb9bfef83a48820f7
Signed-off-by: Chirayu Desai <cdesai@cyanogenmod.org>
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/__init__.py | 4 | ||||
| -rw-r--r-- | subcmds/branches.py | 5 | ||||
| -rw-r--r-- | subcmds/help.py | 10 | ||||
| -rw-r--r-- | subcmds/info.py | 2 | ||||
| -rw-r--r-- | subcmds/overview.py | 2 | ||||
| -rw-r--r-- | subcmds/status.py | 11 | ||||
| -rw-r--r-- | subcmds/sync.py | 31 | ||||
| -rw-r--r-- | subcmds/upload.py | 7 |
8 files changed, 47 insertions, 25 deletions
diff --git a/subcmds/__init__.py b/subcmds/__init__.py index 1fac802e..84efb4de 100644 --- a/subcmds/__init__.py +++ b/subcmds/__init__.py | |||
| @@ -38,8 +38,8 @@ for py in os.listdir(my_dir): | |||
| 38 | try: | 38 | try: |
| 39 | cmd = getattr(mod, clsn)() | 39 | cmd = getattr(mod, clsn)() |
| 40 | except AttributeError: | 40 | except AttributeError: |
| 41 | raise SyntaxError, '%s/%s does not define class %s' % ( | 41 | raise SyntaxError('%s/%s does not define class %s' % ( |
| 42 | __name__, py, clsn) | 42 | __name__, py, clsn)) |
| 43 | 43 | ||
| 44 | name = name.replace('_', '-') | 44 | name = name.replace('_', '-') |
| 45 | cmd.NAME = name | 45 | cmd.NAME = name |
diff --git a/subcmds/branches.py b/subcmds/branches.py index 06d45abe..c2e7c4b9 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py | |||
| @@ -98,14 +98,13 @@ is shown, then the branch appears in all projects. | |||
| 98 | project_cnt = len(projects) | 98 | project_cnt = len(projects) |
| 99 | 99 | ||
| 100 | for project in projects: | 100 | for project in projects: |
| 101 | for name, b in project.GetBranches().iteritems(): | 101 | for name, b in project.GetBranches().items(): |
| 102 | b.project = project | 102 | b.project = project |
| 103 | if name not in all_branches: | 103 | if name not in all_branches: |
| 104 | all_branches[name] = BranchInfo(name) | 104 | all_branches[name] = BranchInfo(name) |
| 105 | all_branches[name].add(b) | 105 | all_branches[name].add(b) |
| 106 | 106 | ||
| 107 | names = all_branches.keys() | 107 | names = list(sorted(all_branches)) |
| 108 | names.sort() | ||
| 109 | 108 | ||
| 110 | if not names: | 109 | if not names: |
| 111 | print(' (no branches)', file=sys.stderr) | 110 | print(' (no branches)', file=sys.stderr) |
diff --git a/subcmds/help.py b/subcmds/help.py index 78428825..4aa3f863 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
| @@ -34,8 +34,7 @@ Displays detailed usage information about a command. | |||
| 34 | def _PrintAllCommands(self): | 34 | def _PrintAllCommands(self): |
| 35 | print('usage: repo COMMAND [ARGS]') | 35 | print('usage: repo COMMAND [ARGS]') |
| 36 | print('The complete list of recognized repo commands are:') | 36 | print('The complete list of recognized repo commands are:') |
| 37 | commandNames = self.commands.keys() | 37 | commandNames = list(sorted(self.commands)) |
| 38 | commandNames.sort() | ||
| 39 | 38 | ||
| 40 | maxlen = 0 | 39 | maxlen = 0 |
| 41 | for name in commandNames: | 40 | for name in commandNames: |
| @@ -55,10 +54,9 @@ Displays detailed usage information about a command. | |||
| 55 | def _PrintCommonCommands(self): | 54 | def _PrintCommonCommands(self): |
| 56 | print('usage: repo COMMAND [ARGS]') | 55 | print('usage: repo COMMAND [ARGS]') |
| 57 | print('The most commonly used repo commands are:') | 56 | print('The most commonly used repo commands are:') |
| 58 | commandNames = [name | 57 | commandNames = list(sorted([name |
| 59 | for name in self.commands.keys() | 58 | for name, command in self.commands.items() |
| 60 | if self.commands[name].common] | 59 | if command.common])) |
| 61 | commandNames.sort() | ||
| 62 | 60 | ||
| 63 | maxlen = 0 | 61 | maxlen = 0 |
| 64 | for name in commandNames: | 62 | for name in commandNames: |
diff --git a/subcmds/info.py b/subcmds/info.py index 325874b5..c10e56cd 100644 --- a/subcmds/info.py +++ b/subcmds/info.py | |||
| @@ -163,7 +163,7 @@ class Info(PagedCommand): | |||
| 163 | all_branches = [] | 163 | all_branches = [] |
| 164 | for project in self.GetProjects(args): | 164 | for project in self.GetProjects(args): |
| 165 | br = [project.GetUploadableBranch(x) | 165 | br = [project.GetUploadableBranch(x) |
| 166 | for x in project.GetBranches().keys()] | 166 | for x in project.GetBranches()] |
| 167 | br = [x for x in br if x] | 167 | br = [x for x in br if x] |
| 168 | if self.opt.current_branch: | 168 | if self.opt.current_branch: |
| 169 | br = [x for x in br if x.name == project.CurrentBranch] | 169 | br = [x for x in br if x.name == project.CurrentBranch] |
diff --git a/subcmds/overview.py b/subcmds/overview.py index 418459ae..eed8cf20 100644 --- a/subcmds/overview.py +++ b/subcmds/overview.py | |||
| @@ -42,7 +42,7 @@ are displayed. | |||
| 42 | all_branches = [] | 42 | all_branches = [] |
| 43 | for project in self.GetProjects(args): | 43 | for project in self.GetProjects(args): |
| 44 | br = [project.GetUploadableBranch(x) | 44 | br = [project.GetUploadableBranch(x) |
| 45 | for x in project.GetBranches().keys()] | 45 | for x in project.GetBranches()] |
| 46 | br = [x for x in br if x] | 46 | br = [x for x in br if x] |
| 47 | if opt.current_branch: | 47 | if opt.current_branch: |
| 48 | br = [x for x in br if x.name == project.CurrentBranch] | 48 | br = [x for x in br if x.name == project.CurrentBranch] |
diff --git a/subcmds/status.py b/subcmds/status.py index cce00c81..9810337f 100644 --- a/subcmds/status.py +++ b/subcmds/status.py | |||
| @@ -21,10 +21,15 @@ except ImportError: | |||
| 21 | import dummy_threading as _threading | 21 | import dummy_threading as _threading |
| 22 | 22 | ||
| 23 | import glob | 23 | import glob |
| 24 | try: | ||
| 25 | # For python2 | ||
| 26 | import StringIO as io | ||
| 27 | except ImportError: | ||
| 28 | # For python3 | ||
| 29 | import io | ||
| 24 | import itertools | 30 | import itertools |
| 25 | import os | 31 | import os |
| 26 | import sys | 32 | import sys |
| 27 | import StringIO | ||
| 28 | 33 | ||
| 29 | from color import Coloring | 34 | from color import Coloring |
| 30 | 35 | ||
| @@ -142,7 +147,7 @@ the following meanings: | |||
| 142 | for project in all_projects: | 147 | for project in all_projects: |
| 143 | sem.acquire() | 148 | sem.acquire() |
| 144 | 149 | ||
| 145 | class BufList(StringIO.StringIO): | 150 | class BufList(io.StringIO): |
| 146 | def dump(self, ostream): | 151 | def dump(self, ostream): |
| 147 | for entry in self.buflist: | 152 | for entry in self.buflist: |
| 148 | ostream.write(entry) | 153 | ostream.write(entry) |
| @@ -182,7 +187,7 @@ the following meanings: | |||
| 182 | try: | 187 | try: |
| 183 | os.chdir(self.manifest.topdir) | 188 | os.chdir(self.manifest.topdir) |
| 184 | 189 | ||
| 185 | outstring = StringIO.StringIO() | 190 | outstring = io.StringIO() |
| 186 | self._FindOrphans(glob.glob('.*') + \ | 191 | self._FindOrphans(glob.glob('.*') + \ |
| 187 | glob.glob('*'), \ | 192 | glob.glob('*'), \ |
| 188 | proj_dirs, proj_dirs_parents, outstring) | 193 | proj_dirs, proj_dirs_parents, outstring) |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 42c5f915..8fb94885 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -24,8 +24,24 @@ import socket | |||
| 24 | import subprocess | 24 | import subprocess |
| 25 | import sys | 25 | import sys |
| 26 | import time | 26 | import time |
| 27 | import urlparse | 27 | try: |
| 28 | import xmlrpclib | 28 | # For python3 |
| 29 | import urllib.parse | ||
| 30 | except ImportError: | ||
| 31 | # For python2 | ||
| 32 | import imp | ||
| 33 | import urlparse | ||
| 34 | urllib = imp.new_module('urllib') | ||
| 35 | urllib.parse = urlparse | ||
| 36 | try: | ||
| 37 | # For python3 | ||
| 38 | import xmlrpc.client | ||
| 39 | except ImportError: | ||
| 40 | # For python2 | ||
| 41 | import imp | ||
| 42 | import xmlrpclib | ||
| 43 | xmlrpc = imp.new_module('xmlrpc') | ||
| 44 | xmlrpc.client = xmlrpclib | ||
| 29 | 45 | ||
| 30 | try: | 46 | try: |
| 31 | import threading as _threading | 47 | import threading as _threading |
| @@ -498,7 +514,7 @@ later is required to fix a server side protocol bug. | |||
| 498 | file=sys.stderr) | 514 | file=sys.stderr) |
| 499 | else: | 515 | else: |
| 500 | try: | 516 | try: |
| 501 | parse_result = urlparse.urlparse(manifest_server) | 517 | parse_result = urllib.parse(manifest_server) |
| 502 | if parse_result.hostname: | 518 | if parse_result.hostname: |
| 503 | username, _account, password = \ | 519 | username, _account, password = \ |
| 504 | info.authenticators(parse_result.hostname) | 520 | info.authenticators(parse_result.hostname) |
| @@ -516,7 +532,7 @@ later is required to fix a server side protocol bug. | |||
| 516 | 1) | 532 | 1) |
| 517 | 533 | ||
| 518 | try: | 534 | try: |
| 519 | server = xmlrpclib.Server(manifest_server) | 535 | server = xmlrpc.client.Server(manifest_server) |
| 520 | if opt.smart_sync: | 536 | if opt.smart_sync: |
| 521 | p = self.manifest.manifestProject | 537 | p = self.manifest.manifestProject |
| 522 | b = p.GetBranch(p.CurrentBranch) | 538 | b = p.GetBranch(p.CurrentBranch) |
| @@ -525,8 +541,7 @@ later is required to fix a server side protocol bug. | |||
| 525 | branch = branch[len(R_HEADS):] | 541 | branch = branch[len(R_HEADS):] |
| 526 | 542 | ||
| 527 | env = os.environ.copy() | 543 | env = os.environ.copy() |
| 528 | if (env.has_key('TARGET_PRODUCT') and | 544 | if 'TARGET_PRODUCT' in env and 'TARGET_BUILD_VARIANT' in env: |
| 529 | env.has_key('TARGET_BUILD_VARIANT')): | ||
| 530 | target = '%s-%s' % (env['TARGET_PRODUCT'], | 545 | target = '%s-%s' % (env['TARGET_PRODUCT'], |
| 531 | env['TARGET_BUILD_VARIANT']) | 546 | env['TARGET_BUILD_VARIANT']) |
| 532 | [success, manifest_str] = server.GetApprovedManifest(branch, target) | 547 | [success, manifest_str] = server.GetApprovedManifest(branch, target) |
| @@ -554,11 +569,11 @@ later is required to fix a server side protocol bug. | |||
| 554 | else: | 569 | else: |
| 555 | print('error: %s' % manifest_str, file=sys.stderr) | 570 | print('error: %s' % manifest_str, file=sys.stderr) |
| 556 | sys.exit(1) | 571 | sys.exit(1) |
| 557 | except (socket.error, IOError, xmlrpclib.Fault) as e: | 572 | except (socket.error, IOError, xmlrpc.client.Fault) as e: |
| 558 | print('error: cannot connect to manifest server %s:\n%s' | 573 | print('error: cannot connect to manifest server %s:\n%s' |
| 559 | % (self.manifest.manifest_server, e), file=sys.stderr) | 574 | % (self.manifest.manifest_server, e), file=sys.stderr) |
| 560 | sys.exit(1) | 575 | sys.exit(1) |
| 561 | except xmlrpclib.ProtocolError as e: | 576 | except xmlrpc.client.ProtocolError as e: |
| 562 | print('error: cannot connect to manifest server %s:\n%d %s' | 577 | print('error: cannot connect to manifest server %s:\n%d %s' |
| 563 | % (self.manifest.manifest_server, e.errcode, e.errmsg), | 578 | % (self.manifest.manifest_server, e.errcode, e.errmsg), |
| 564 | file=sys.stderr) | 579 | file=sys.stderr) |
diff --git a/subcmds/upload.py b/subcmds/upload.py index 48ee685c..a34938e5 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -23,6 +23,11 @@ from editor import Editor | |||
| 23 | from error import HookError, UploadError | 23 | from error import HookError, UploadError |
| 24 | from project import RepoHook | 24 | from project import RepoHook |
| 25 | 25 | ||
| 26 | try: | ||
| 27 | input = raw_input | ||
| 28 | except NameError: | ||
| 29 | pass | ||
| 30 | |||
| 26 | UNUSUAL_COMMIT_THRESHOLD = 5 | 31 | UNUSUAL_COMMIT_THRESHOLD = 5 |
| 27 | 32 | ||
| 28 | def _ConfirmManyUploads(multiple_branches=False): | 33 | def _ConfirmManyUploads(multiple_branches=False): |
| @@ -33,7 +38,7 @@ def _ConfirmManyUploads(multiple_branches=False): | |||
| 33 | print('ATTENTION: You are uploading an unusually high number of commits.') | 38 | print('ATTENTION: You are uploading an unusually high number of commits.') |
| 34 | print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across ' | 39 | print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across ' |
| 35 | 'branches?)') | 40 | 'branches?)') |
| 36 | answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip() | 41 | answer = input("If you are sure you intend to do this, type 'yes': ").strip() |
| 37 | return answer == "yes" | 42 | return answer == "yes" |
| 38 | 43 | ||
| 39 | def _die(fmt, *args): | 44 | def _die(fmt, *args): |
