diff options
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/common/gitscraper.py | 40 | ||||
-rwxr-xr-x | utils/common/tarball.py | 6 |
2 files changed, 23 insertions, 23 deletions
diff --git a/utils/common/gitscraper.py b/utils/common/gitscraper.py index a6b6cf39a6..85a8467617 100755 --- a/utils/common/gitscraper.py +++ b/utils/common/gitscraper.py | |||
@@ -41,22 +41,22 @@ def get_refs(repo): | |||
41 | @param repo Path to repository root. | 41 | @param repo Path to repository root. |
42 | @return Dict matching hashes to each ref. | 42 | @return Dict matching hashes to each ref. |
43 | ''' | 43 | ''' |
44 | print "Getting list of refs" | 44 | print("Getting list of refs") |
45 | output = subprocess.Popen(["git", "show-ref"], stdout=subprocess.PIPE, | 45 | output = subprocess.Popen(["git", "show-ref"], stdout=subprocess.PIPE, |
46 | stderr=subprocess.PIPE, cwd=repo) | 46 | stderr=subprocess.PIPE, cwd=repo) |
47 | cmdout = output.communicate() | 47 | cmdout = output.communicate() |
48 | refs = {} | 48 | refs = {} |
49 | 49 | ||
50 | if len(cmdout[1]) > 0: | 50 | if len(cmdout[1]) > 0: |
51 | print "An error occured!\n" | 51 | print("An error occured!\n") |
52 | print cmdout[1] | 52 | print(cmdout[1]) |
53 | return refs | 53 | return refs |
54 | 54 | ||
55 | for line in cmdout: | 55 | for line in cmdout: |
56 | regex = re.findall(r'([a-f0-9]+)\s+(\S+)', line) | 56 | regex = re.findall(b'([a-f0-9]+)\s+(\S+)', line) |
57 | for r in regex: | 57 | for r in regex: |
58 | # ref is the key, hash its value. | 58 | # ref is the key, hash its value. |
59 | refs[r[1]] = r[0] | 59 | refs[r[1].decode()] = r[0].decode() |
60 | 60 | ||
61 | return refs | 61 | return refs |
62 | 62 | ||
@@ -75,24 +75,25 @@ def get_lstree(repo, start, filterlist=[]): | |||
75 | objects = {} | 75 | objects = {} |
76 | 76 | ||
77 | if len(cmdout[1]) > 0: | 77 | if len(cmdout[1]) > 0: |
78 | print "An error occured!\n" | 78 | print("An error occured!\n") |
79 | print cmdout[1] | 79 | print(cmdout[1]) |
80 | return objects | 80 | return objects |
81 | 81 | ||
82 | for line in cmdout[0].split('\n'): | 82 | for line in cmdout[0].decode().split('\n'): |
83 | regex = re.findall(r'([0-9]+)\s+([a-z]+)\s+([0-9a-f]+)\s+(\S+)', line) | 83 | regex = re.findall(b'([0-9]+)\s+([a-z]+)\s+([0-9a-f]+)\s+(\S+)', |
84 | line.encode()) | ||
84 | for rf in regex: | 85 | for rf in regex: |
85 | # filter | 86 | # filter |
86 | add = False | 87 | add = False |
87 | for f in filterlist: | 88 | for f in filterlist: |
88 | if rf[3].find(f) == 0: | 89 | if rf[3].decode().find(f) == 0: |
89 | add = True | 90 | add = True |
90 | 91 | ||
91 | # If two files have the same content they have the same hash, so | 92 | # If two files have the same content they have the same hash, so |
92 | # the filename has to be used as key. | 93 | # the filename has to be used as key. |
93 | if len(filterlist) == 0 or add == True: | 94 | if len(filterlist) == 0 or add == True: |
94 | if rf[3] in objects: | 95 | if rf[3] in objects: |
95 | print "FATAL: key already exists in dict!" | 96 | print("FATAL: key already exists in dict!") |
96 | return {} | 97 | return {} |
97 | objects[rf[3]] = rf[2] | 98 | objects[rf[3]] = rf[2] |
98 | return objects | 99 | return objects |
@@ -110,14 +111,13 @@ def get_object(repo, blob, destfile): | |||
110 | cmdout = output.communicate() | 111 | cmdout = output.communicate() |
111 | # make sure output path exists | 112 | # make sure output path exists |
112 | if len(cmdout[1]) > 0: | 113 | if len(cmdout[1]) > 0: |
113 | print "An error occured!\n" | 114 | print("An error occured!\n") |
114 | print cmdout[1] | 115 | print(cmdout[1]) |
115 | return False | 116 | return False |
116 | if not os.path.exists(os.path.dirname(destfile)): | 117 | if not os.path.exists(os.path.dirname(destfile)): |
117 | os.makedirs(os.path.dirname(destfile)) | 118 | os.makedirs(os.path.dirname(destfile)) |
118 | f = open(destfile, 'wb') | 119 | f = open(destfile, 'wb') |
119 | for line in cmdout[0]: | 120 | f.write(cmdout[0]) |
120 | f.write(line) | ||
121 | f.close() | 121 | f.close() |
122 | return True | 122 | return True |
123 | 123 | ||
@@ -132,8 +132,8 @@ def describe_treehash(repo, treehash): | |||
132 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=repo) | 132 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=repo) |
133 | cmdout = output.communicate() | 133 | cmdout = output.communicate() |
134 | if len(cmdout[1]) > 0: | 134 | if len(cmdout[1]) > 0: |
135 | print "An error occured!\n" | 135 | print("An error occured!\n") |
136 | print cmdout[1] | 136 | print(cmdout[1]) |
137 | return "" | 137 | return "" |
138 | return cmdout[0].rstrip() | 138 | return cmdout[0].rstrip() |
139 | 139 | ||
@@ -148,13 +148,13 @@ def scrape_files(repo, treehash, filelist, dest=""): | |||
148 | created below dest as necessary. | 148 | created below dest as necessary. |
149 | @return Destination path. | 149 | @return Destination path. |
150 | ''' | 150 | ''' |
151 | print "Scraping files from repository" | 151 | print("Scraping files from repository") |
152 | 152 | ||
153 | if dest == "": | 153 | if dest == "": |
154 | dest = tempfile.mkdtemp() | 154 | dest = tempfile.mkdtemp() |
155 | treeobjects = get_lstree(repo, treehash, filelist) | 155 | treeobjects = get_lstree(repo, treehash, filelist) |
156 | for obj in treeobjects: | 156 | for obj in treeobjects: |
157 | get_object(repo, treeobjects[obj], os.path.join(dest, obj)) | 157 | get_object(repo, treeobjects[obj], os.path.join(dest.encode(), obj)) |
158 | 158 | ||
159 | return dest | 159 | return dest |
160 | 160 | ||
@@ -185,7 +185,7 @@ def archive_files(repo, treehash, filelist, basename, tmpfolder="", | |||
185 | os.path.join(tmpfolder, basename)) | 185 | os.path.join(tmpfolder, basename)) |
186 | if basename is "": | 186 | if basename is "": |
187 | return "" | 187 | return "" |
188 | print "Archiving files from repository" | 188 | print("Archiving files from repository") |
189 | if archive == "7z": | 189 | if archive == "7z": |
190 | outfile = basename + ".7z" | 190 | outfile = basename + ".7z" |
191 | output = subprocess.Popen(["7z", "a", | 191 | output = subprocess.Popen(["7z", "a", |
diff --git a/utils/common/tarball.py b/utils/common/tarball.py index 57765a55c7..2e32776702 100755 --- a/utils/common/tarball.py +++ b/utils/common/tarball.py | |||
@@ -5,7 +5,7 @@ import os | |||
5 | import sys | 5 | import sys |
6 | 6 | ||
7 | if len(sys.argv) < 2: | 7 | if len(sys.argv) < 2: |
8 | print "Usage: %s <version|hash>" % sys.argv[0] | 8 | print("Usage: %s <version|hash>" % sys.argv[0]) |
9 | sys.exit() | 9 | sys.exit() |
10 | 10 | ||
11 | repository = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../..") | 11 | repository = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../..") |
@@ -17,7 +17,7 @@ if '.' in sys.argv[1]: | |||
17 | if ref in refs: | 17 | if ref in refs: |
18 | tree = refs[ref] | 18 | tree = refs[ref] |
19 | else: | 19 | else: |
20 | print "Could not find hash for version!" | 20 | print("Could not find hash for version!") |
21 | sys.exit() | 21 | sys.exit() |
22 | else: | 22 | else: |
23 | tree = sys.argv[1] | 23 | tree = sys.argv[1] |
@@ -25,6 +25,6 @@ else: | |||
25 | 25 | ||
26 | gitscraper.archive_files(repository, tree, [], basename, archive="7z") | 26 | gitscraper.archive_files(repository, tree, [], basename, archive="7z") |
27 | 27 | ||
28 | print "done." | 28 | print("done.") |
29 | 29 | ||
30 | 30 | ||