diff options
-rwxr-xr-x | utils/common/gitscraper.py | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/utils/common/gitscraper.py b/utils/common/gitscraper.py index cfa017aed0..a6b6cf39a6 100755 --- a/utils/common/gitscraper.py +++ b/utils/common/gitscraper.py | |||
@@ -159,7 +159,8 @@ def scrape_files(repo, treehash, filelist, dest=""): | |||
159 | return dest | 159 | return dest |
160 | 160 | ||
161 | 161 | ||
162 | def archive_files(repo, treehash, filelist, basename, tmpfolder=""): | 162 | def archive_files(repo, treehash, filelist, basename, tmpfolder="", |
163 | archive="tbz"): | ||
163 | '''Archive list of files into tarball. | 164 | '''Archive list of files into tarball. |
164 | @param repo Path to repository root. | 165 | @param repo Path to repository root. |
165 | @param treehash Hash identifying the tree. | 166 | @param treehash Hash identifying the tree. |
@@ -169,15 +170,35 @@ def archive_files(repo, treehash, filelist, basename, tmpfolder=""): | |||
169 | basename inside of the archive as well (i.e. no tarbomb). | 170 | basename inside of the archive as well (i.e. no tarbomb). |
170 | @param tmpfolder Folder to put intermediate files in. If no folder is given | 171 | @param tmpfolder Folder to put intermediate files in. If no folder is given |
171 | a temporary one will get used. | 172 | a temporary one will get used. |
173 | @param archive Type of archive to create. Supported values are "tbz" and | ||
174 | "7z". The latter requires the 7z binary available in the | ||
175 | system's path. | ||
172 | @return Output filename. | 176 | @return Output filename. |
173 | ''' | 177 | ''' |
174 | print "Archiving files from repository" | ||
175 | 178 | ||
176 | workfolder = scrape_files(repo, treehash, filelist, tmpfolder) | 179 | if tmpfolder == "": |
177 | outfile = basename + ".tar.bz2" | 180 | temp_remove = True |
178 | tf = tarfile.open(outfile, "w:bz2") | 181 | tmpfolder = tempfile.mkdtemp() |
179 | tf.add(workfolder, basename) | 182 | else: |
180 | tf.close() | 183 | temp_remove = False |
184 | workfolder = scrape_files(repo, treehash, filelist, | ||
185 | os.path.join(tmpfolder, basename)) | ||
186 | if basename is "": | ||
187 | return "" | ||
188 | print "Archiving files from repository" | ||
189 | if archive == "7z": | ||
190 | outfile = basename + ".7z" | ||
191 | output = subprocess.Popen(["7z", "a", | ||
192 | os.path.join(os.getcwd(), basename + ".7z"), basename], | ||
193 | cwd=tmpfolder, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
194 | output.communicate() | ||
195 | else: | ||
196 | outfile = basename + ".tar.bz2" | ||
197 | tf = tarfile.open(outfile, "w:bz2") | ||
198 | tf.add(workfolder, basename) | ||
199 | tf.close() | ||
181 | if tmpfolder != workfolder: | 200 | if tmpfolder != workfolder: |
182 | shutil.rmtree(workfolder) | 201 | shutil.rmtree(workfolder) |
202 | if temp_remove: | ||
203 | shutil.rmtree(tmpfolder) | ||
183 | return outfile | 204 | return outfile |