summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-10-17 20:50:58 +0100
committerLars Wirzenius <liw@liw.fi>2011-10-17 20:50:58 +0100
commit98507401bd5e3d52b448c7890f952f1a5ff01567 (patch)
treef96de8a09bc4639e4106f3ff117cb3f8f87a66d4
parentac699d56f600ff7109af0bf1c7a3744c49ebc4b5 (diff)
downloadmorph-98507401bd5e3d52b448c7890f952f1a5ff01567.tar.gz
Start a git module for abstracting away git operations.
-rw-r--r--morphlib/__init__.py1
-rw-r--r--morphlib/builder.py12
-rw-r--r--morphlib/git.py30
-rw-r--r--without-test-modules1
4 files changed, 38 insertions, 6 deletions
diff --git a/morphlib/__init__.py b/morphlib/__init__.py
index f4869eb1..6ec0f7fe 100644
--- a/morphlib/__init__.py
+++ b/morphlib/__init__.py
@@ -24,6 +24,7 @@ import bins
import builder
import cachedir
import execute
+import git
import morphology
import tempdir
import util
diff --git a/morphlib/builder.py b/morphlib/builder.py
index c5d1cb8c..6faa72b1 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -19,6 +19,7 @@ import logging
import os
import shutil
import StringIO
+import tarfile
import urlparse
import morphlib
@@ -92,13 +93,12 @@ class Builder(object):
'''Export sources from git into the ``self._build`` directory.'''
logging.debug('Creating build tree at %s' % self._build)
+ tarball = self.tempdir.join('sources.tar.gz')
+ morphlib.git.export_sources(repo, ref, tarball)
os.mkdir(self._build)
- tarball = self.tempdir.join('sources.tar')
- self.ex.runv(['git', 'archive',
- '--output', tarball,
- '--remote', repo,
- ref])
- self.ex.runv(['tar', '-C', self._build, '-xf', tarball])
+ f = tarfile.open(tarball)
+ f.extractall(path=self._build)
+ f.close()
os.remove(tarball)
def create_chunk(self, morph, repo, ref):
diff --git a/morphlib/git.py b/morphlib/git.py
new file mode 100644
index 00000000..47eb7ffe
--- /dev/null
+++ b/morphlib/git.py
@@ -0,0 +1,30 @@
+# Copyright (C) 2011 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+import gzip
+import logging
+
+import morphlib
+
+
+def export_sources(repo, ref, tar_filename):
+ '''Export the contents of a specific commit into a compressed tarball.'''
+ ex = morphlib.execute.Execute('.', msg=logging.debug)
+ tar = ex.runv(['git', 'archive', '--remote', repo, ref])
+ f = gzip.open(tar_filename, 'wb')
+ f.write(tar)
+ f.close()
+
diff --git a/without-test-modules b/without-test-modules
index 227bb836..e553a38d 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -1,2 +1,3 @@
morphlib/__init__.py
morphlib/builder.py
+morphlib/git.py