summaryrefslogtreecommitdiffstats
path: root/subcmds
diff options
context:
space:
mode:
authorConley Owens <cco3@android.com>2013-04-19 15:31:28 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-04-19 15:31:29 +0000
commitc4c01f914c7cdfa997be60ea97cd487d63333a04 (patch)
treec7063f88ab55998187c907807364ce7f4444cc4a /subcmds
parent51813dfed1528307c46707bc38b4db33b87bb36e (diff)
parent217ea7d2747e3098009afe0b389fc4b45f55ea5a (diff)
downloadgit-repo-c4c01f914c7cdfa997be60ea97cd487d63333a04.tar.gz
Merge "Some fixes for supporting python3"
Diffstat (limited to 'subcmds')
-rw-r--r--subcmds/__init__.py4
-rw-r--r--subcmds/branches.py5
-rw-r--r--subcmds/help.py10
-rw-r--r--subcmds/info.py2
-rw-r--r--subcmds/overview.py2
-rw-r--r--subcmds/status.py11
-rw-r--r--subcmds/sync.py31
-rw-r--r--subcmds/upload.py7
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
23import glob 23import glob
24try:
25 # For python2
26 import StringIO as io
27except ImportError:
28 # For python3
29 import io
24import itertools 30import itertools
25import os 31import os
26import sys 32import sys
27import StringIO
28 33
29from color import Coloring 34from 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
24import subprocess 24import subprocess
25import sys 25import sys
26import time 26import time
27import urlparse 27try:
28import xmlrpclib 28 # For python3
29 import urllib.parse
30except ImportError:
31 # For python2
32 import imp
33 import urlparse
34 urllib = imp.new_module('urllib')
35 urllib.parse = urlparse
36try:
37 # For python3
38 import xmlrpc.client
39except ImportError:
40 # For python2
41 import imp
42 import xmlrpclib
43 xmlrpc = imp.new_module('xmlrpc')
44 xmlrpc.client = xmlrpclib
29 45
30try: 46try:
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
23from error import HookError, UploadError 23from error import HookError, UploadError
24from project import RepoHook 24from project import RepoHook
25 25
26try:
27 input = raw_input
28except NameError:
29 pass
30
26UNUSUAL_COMMIT_THRESHOLD = 5 31UNUSUAL_COMMIT_THRESHOLD = 5
27 32
28def _ConfirmManyUploads(multiple_branches=False): 33def _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
39def _die(fmt, *args): 44def _die(fmt, *args):