summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorChirayu Desai <cdesai@cyanogenmod.org>2013-03-01 19:14:38 +0530
committerChirayu Desai <cdesai@cyanogenmod.org>2013-04-18 21:35:49 +0530
commit217ea7d2747e3098009afe0b389fc4b45f55ea5a (patch)
tree4ea2663a01fb22002ec6cd6ede9cb3babd89a692 /project.py
parentfef4ae74e26efecf5c803793351b6c843eab4970 (diff)
downloadgit-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 'project.py')
-rw-r--r--project.py49
1 files changed, 28 insertions, 21 deletions
diff --git a/project.py b/project.py
index 20bf866c..feac5c01 100644
--- a/project.py
+++ b/project.py
@@ -36,6 +36,11 @@ from trace import IsTrace, Trace
36 36
37from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M 37from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
38 38
39try:
40 input = raw_input
41except NameError:
42 pass
43
39def _lwrite(path, content): 44def _lwrite(path, content):
40 lock = '%s.lock' % path 45 lock = '%s.lock' % path
41 46
@@ -78,7 +83,7 @@ def _ProjectHooks():
78 if _project_hook_list is None: 83 if _project_hook_list is None:
79 d = os.path.abspath(os.path.dirname(__file__)) 84 d = os.path.abspath(os.path.dirname(__file__))
80 d = os.path.join(d , 'hooks') 85 d = os.path.join(d , 'hooks')
81 _project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d)) 86 _project_hook_list = [os.path.join(d, x) for x in os.listdir(d)]
82 return _project_hook_list 87 return _project_hook_list
83 88
84 89
@@ -361,7 +366,7 @@ class RepoHook(object):
361 'Do you want to allow this script to run ' 366 'Do you want to allow this script to run '
362 '(yes/yes-never-ask-again/NO)? ') % ( 367 '(yes/yes-never-ask-again/NO)? ') % (
363 self._GetMustVerb(), self._script_fullpath) 368 self._GetMustVerb(), self._script_fullpath)
364 response = raw_input(prompt).lower() 369 response = input(prompt).lower()
365 print() 370 print()
366 371
367 # User is doing a one-time approval. 372 # User is doing a one-time approval.
@@ -646,7 +651,7 @@ class Project(object):
646 all_refs = self._allrefs 651 all_refs = self._allrefs
647 heads = {} 652 heads = {}
648 653
649 for name, ref_id in all_refs.iteritems(): 654 for name, ref_id in all_refs.items():
650 if name.startswith(R_HEADS): 655 if name.startswith(R_HEADS):
651 name = name[len(R_HEADS):] 656 name = name[len(R_HEADS):]
652 b = self.GetBranch(name) 657 b = self.GetBranch(name)
@@ -655,7 +660,7 @@ class Project(object):
655 b.revision = ref_id 660 b.revision = ref_id
656 heads[name] = b 661 heads[name] = b
657 662
658 for name, ref_id in all_refs.iteritems(): 663 for name, ref_id in all_refs.items():
659 if name.startswith(R_PUB): 664 if name.startswith(R_PUB):
660 name = name[len(R_PUB):] 665 name = name[len(R_PUB):]
661 b = heads.get(name) 666 b = heads.get(name)
@@ -761,10 +766,7 @@ class Project(object):
761 paths.extend(df.keys()) 766 paths.extend(df.keys())
762 paths.extend(do) 767 paths.extend(do)
763 768
764 paths = list(set(paths)) 769 for p in sorted(set(paths)):
765 paths.sort()
766
767 for p in paths:
768 try: 770 try:
769 i = di[p] 771 i = di[p]
770 except KeyError: 772 except KeyError:
@@ -856,13 +858,13 @@ class Project(object):
856 all_refs = self._allrefs 858 all_refs = self._allrefs
857 heads = set() 859 heads = set()
858 canrm = {} 860 canrm = {}
859 for name, ref_id in all_refs.iteritems(): 861 for name, ref_id in all_refs.items():
860 if name.startswith(R_HEADS): 862 if name.startswith(R_HEADS):
861 heads.add(name) 863 heads.add(name)
862 elif name.startswith(R_PUB): 864 elif name.startswith(R_PUB):
863 canrm[name] = ref_id 865 canrm[name] = ref_id
864 866
865 for name, ref_id in canrm.iteritems(): 867 for name, ref_id in canrm.items():
866 n = name[len(R_PUB):] 868 n = name[len(R_PUB):]
867 if R_HEADS + n not in heads: 869 if R_HEADS + n not in heads:
868 self.bare_git.DeleteRef(name, ref_id) 870 self.bare_git.DeleteRef(name, ref_id)
@@ -873,14 +875,14 @@ class Project(object):
873 heads = {} 875 heads = {}
874 pubed = {} 876 pubed = {}
875 877
876 for name, ref_id in self._allrefs.iteritems(): 878 for name, ref_id in self._allrefs.items():
877 if name.startswith(R_HEADS): 879 if name.startswith(R_HEADS):
878 heads[name[len(R_HEADS):]] = ref_id 880 heads[name[len(R_HEADS):]] = ref_id
879 elif name.startswith(R_PUB): 881 elif name.startswith(R_PUB):
880 pubed[name[len(R_PUB):]] = ref_id 882 pubed[name[len(R_PUB):]] = ref_id
881 883
882 ready = [] 884 ready = []
883 for branch, ref_id in heads.iteritems(): 885 for branch, ref_id in heads.items():
884 if branch in pubed and pubed[branch] == ref_id: 886 if branch in pubed and pubed[branch] == ref_id:
885 continue 887 continue
886 if selected_branch and branch != selected_branch: 888 if selected_branch and branch != selected_branch:
@@ -1223,7 +1225,7 @@ class Project(object):
1223 cmd = ['fetch', remote.name] 1225 cmd = ['fetch', remote.name]
1224 cmd.append('refs/changes/%2.2d/%d/%d' \ 1226 cmd.append('refs/changes/%2.2d/%d/%d' \
1225 % (change_id % 100, change_id, patch_id)) 1227 % (change_id % 100, change_id, patch_id))
1226 cmd.extend(map(str, remote.fetch)) 1228 cmd.extend(list(map(str, remote.fetch)))
1227 if GitCommand(self, cmd, bare=True).Wait() != 0: 1229 if GitCommand(self, cmd, bare=True).Wait() != 0:
1228 return None 1230 return None
1229 return DownloadedChange(self, 1231 return DownloadedChange(self,
@@ -1612,7 +1614,7 @@ class Project(object):
1612 ids = set(all_refs.values()) 1614 ids = set(all_refs.values())
1613 tmp = set() 1615 tmp = set()
1614 1616
1615 for r, ref_id in GitRefs(ref_dir).all.iteritems(): 1617 for r, ref_id in GitRefs(ref_dir).all.items():
1616 if r not in all_refs: 1618 if r not in all_refs:
1617 if r.startswith(R_TAGS) or remote.WritesTo(r): 1619 if r.startswith(R_TAGS) or remote.WritesTo(r):
1618 all_refs[r] = ref_id 1620 all_refs[r] = ref_id
@@ -1627,13 +1629,10 @@ class Project(object):
1627 ids.add(ref_id) 1629 ids.add(ref_id)
1628 tmp.add(r) 1630 tmp.add(r)
1629 1631
1630 ref_names = list(all_refs.keys())
1631 ref_names.sort()
1632
1633 tmp_packed = '' 1632 tmp_packed = ''
1634 old_packed = '' 1633 old_packed = ''
1635 1634
1636 for r in ref_names: 1635 for r in sorted(all_refs):
1637 line = '%s %s\n' % (all_refs[r], r) 1636 line = '%s %s\n' % (all_refs[r], r)
1638 tmp_packed += line 1637 tmp_packed += line
1639 if r not in tmp: 1638 if r not in tmp:
@@ -1666,7 +1665,7 @@ class Project(object):
1666 cmd.append('--no-tags') 1665 cmd.append('--no-tags')
1667 else: 1666 else:
1668 cmd.append('--tags') 1667 cmd.append('--tags')
1669 cmd.append((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')) 1668 cmd.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')))
1670 elif tag_name is not None: 1669 elif tag_name is not None:
1671 cmd.append('tag') 1670 cmd.append('tag')
1672 cmd.append(tag_name) 1671 cmd.append(tag_name)
@@ -1676,7 +1675,7 @@ class Project(object):
1676 branch = self.upstream 1675 branch = self.upstream
1677 if branch.startswith(R_HEADS): 1676 if branch.startswith(R_HEADS):
1678 branch = branch[len(R_HEADS):] 1677 branch = branch[len(R_HEADS):]
1679 cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)) 1678 cmd.append(str((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)))
1680 1679
1681 ok = False 1680 ok = False
1682 for _i in range(2): 1681 for _i in range(2):
@@ -2102,6 +2101,10 @@ class Project(object):
2102 line = fd.read() 2101 line = fd.read()
2103 finally: 2102 finally:
2104 fd.close() 2103 fd.close()
2104 try:
2105 line = line.decode()
2106 except AttributeError:
2107 pass
2105 if line.startswith('ref: '): 2108 if line.startswith('ref: '):
2106 return line[5:-1] 2109 return line[5:-1]
2107 return line[:-1] 2110 return line[:-1]
@@ -2195,7 +2198,7 @@ class Project(object):
2195 if not git_require((1, 7, 2)): 2198 if not git_require((1, 7, 2)):
2196 raise ValueError('cannot set config on command line for %s()' 2199 raise ValueError('cannot set config on command line for %s()'
2197 % name) 2200 % name)
2198 for k, v in config.iteritems(): 2201 for k, v in config.items():
2199 cmdv.append('-c') 2202 cmdv.append('-c')
2200 cmdv.append('%s=%s' % (k, v)) 2203 cmdv.append('%s=%s' % (k, v))
2201 cmdv.append(name) 2204 cmdv.append(name)
@@ -2211,6 +2214,10 @@ class Project(object):
2211 name, 2214 name,
2212 p.stderr)) 2215 p.stderr))
2213 r = p.stdout 2216 r = p.stdout
2217 try:
2218 r = r.decode()
2219 except AttributeError:
2220 pass
2214 if r.endswith('\n') and r.index('\n') == len(r) - 1: 2221 if r.endswith('\n') and r.index('\n') == len(r) - 1:
2215 return r[:-1] 2222 return r[:-1]
2216 return r 2223 return r