summaryrefslogtreecommitdiffstats
path: root/utils/common
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-04-12 21:08:38 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-04-12 21:08:38 +0200
commite9d5f6cb61fb9ef997213b64b8086574f591f3a5 (patch)
treef9826a4a937864f1a77107b072ec98c41d5ba249 /utils/common
parentd8cb5c7007ddd9f8801d2267edba3486347e7266 (diff)
downloadrockbox-e9d5f6cb61fb9ef997213b64b8086574f591f3a5.tar.gz
rockbox-e9d5f6cb61fb9ef997213b64b8086574f591f3a5.tar.bz2
rockbox-e9d5f6cb61fb9ef997213b64b8086574f591f3a5.zip
gitscraper: support compressing the sources as 7z.
The Rockbox source code uses 7z for its archive for size reasons. Add support for compressing as 7z (by calling the 7z command line utility) so it can be used for generating Rockbox source archives. Change-Id: I26097ff61ff183e5ddc07b2c4473f90dc0700178
Diffstat (limited to 'utils/common')
-rwxr-xr-xutils/common/gitscraper.py35
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=""):
return dest
-def archive_files(repo, treehash, filelist, basename, tmpfolder=""):
+def archive_files(repo, treehash, filelist, basename, tmpfolder="",
+ archive="tbz"):
'''Archive list of files into tarball.
@param repo Path to repository root.
@param treehash Hash identifying the tree.
@@ -169,15 +170,35 @@ def archive_files(repo, treehash, filelist, basename, tmpfolder=""):
basename inside of the archive as well (i.e. no tarbomb).
@param tmpfolder Folder to put intermediate files in. If no folder is given
a temporary one will get used.
+ @param archive Type of archive to create. Supported values are "tbz" and
+ "7z". The latter requires the 7z binary available in the
+ system's path.
@return Output filename.
'''
- print "Archiving files from repository"
- workfolder = scrape_files(repo, treehash, filelist, tmpfolder)
- outfile = basename + ".tar.bz2"
- tf = tarfile.open(outfile, "w:bz2")
- tf.add(workfolder, basename)
- tf.close()
+ if tmpfolder == "":
+ temp_remove = True
+ tmpfolder = tempfile.mkdtemp()
+ else:
+ temp_remove = False
+ workfolder = scrape_files(repo, treehash, filelist,
+ os.path.join(tmpfolder, basename))
+ if basename is "":
+ return ""
+ print "Archiving files from repository"
+ if archive == "7z":
+ outfile = basename + ".7z"
+ output = subprocess.Popen(["7z", "a",
+ os.path.join(os.getcwd(), basename + ".7z"), basename],
+ cwd=tmpfolder, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ output.communicate()
+ else:
+ outfile = basename + ".tar.bz2"
+ tf = tarfile.open(outfile, "w:bz2")
+ tf.add(workfolder, basename)
+ tf.close()
if tmpfolder != workfolder:
shutil.rmtree(workfolder)
+ if temp_remove:
+ shutil.rmtree(tmpfolder)
return outfile