summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-11 18:04:15 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-11 18:04:15 -0500
commit6f22d71cf8218abff64773545456fa6084ed2096 (patch)
treee38b5c5c408593fd1b64608eb569517b40fcee08
parent53d8493edc8552bd95a1fae4b6aef472b4bc10d2 (diff)
downloadfedora-devshell-6f22d71cf8218abff64773545456fa6084ed2096.tar.gz
fedora-devshell-6f22d71cf8218abff64773545456fa6084ed2096.tar.xz
fedora-devshell-6f22d71cf8218abff64773545456fa6084ed2096.zip
Rewrites SourceBall to be of type PackageSource and own its own directory
-rw-r--r--modules/sourceball.py88
1 files changed, 56 insertions, 32 deletions
diff --git a/modules/sourceball.py b/modules/sourceball.py
index ac306cc..d66277e 100644
--- a/modules/sourceball.py
+++ b/modules/sourceball.py
@@ -19,61 +19,85 @@ from __future__ import with_statement
import tarfile
+from os import makedirs, getcwd
from os.path import abspath, split, basename, join
from shutil import copytree
from subprocess import Popen, PIPE
+from tempfile import mkdtemp
from base.base import log
from base.exceptions import ExecutionException
-from base.util import pwd, copy
+from base.util import pwd, copy, move
-from modules.package import Package
+from modules.dirfactory import DirFactory
+from modules.package import PackageSource
-class SourceBall(Package):
+class SourceBall(PackageSource):
'''a type of package that is a single sourceball, a spec file, and some patches'''
_type = 'sourceball'
+ def __init__(self, name=None, tarball=''):
+ if tarball:
+ tmp_dir = mkdtemp()
+ with pwd(tmp_dir):
+ sourceball_name = copy(tarball, split(tarball)[1])
+ sourceball = tarfile.open(sourceball_name)
+ extract_dir = min([(x.name, x) for x in sourceball])[0]
+ extract_dir = basename(abspath(extract_dir))
+ if name and not name == extract_dir:
+ raise ExecutionException("tarball is not target directory")
+ if not name:
+ name = extract_dir
+ super(SourceBall, self).__init__(name)
+ if tarball:
+ with pwd(self.dir):
+ sourceball.extractall()
+ with pwd(self.branch_dir):
+ sourceball.extractall()
+ move(self.name, self.orig_dir(self.name))
+ with pwd(self.parent):
+ move(join(tmp_dir, sourceball_name), sourceball_name)
+ self.cfg['sourceball'] = sourceball_name
+
+ def make_dir(self, dir):
+ super(PackageSource, self).make_dir(dir)
+ with pwd(dir):
+ makedirs('.pkg_src')
+
+ @property
+ def branch(self):
+ return join('.pkg_src', 'branches')
+
+ @property
+ def branch_dir(self):
+ return join(self.dir, self.branch)
+
+ @property
+ def sourceball(self):
+ return self.cfg['sourceball']
+
+ @property
+ def sourceball_loc(self):
+ return join(self.parent, self.sourceball)
+
def orig_dir(self, dir):
'''where is the original source kept
use for making patches against modified source'''
return dir + '_orig'
-
+
def source(self, *args):
'''gives source directory
-
+
first parameter, if 'orig' gives the original source, otherwise
you get the modified source
'''
if args[0] == 'orig':
- return self.orig_dir(self.cfg['source'])
+ return join(self.branch, self.orig_dir(self.name)))
else:
- return self.cfg['source']
+ return self.name
- def add_sourceball(self, sourceball_name, extract_dir=None):
- '''given a path to a sourceball, set it up here'''
- log.debug('addincg sourceball with dir ' + self.dir)
- with pwd(self.dir):
- try:
- sourceball_name = copy(sourceball_name,
- split(sourceball_name)[1])
-
- self.cfg['sourceball'] = sourceball_name
- sourceball = tarfile.open(sourceball_name)
- if not extract_dir:
- extract_dir = min([(x.name, x) for x in sourceball])[0]
- extract_dir = basename(abspath(extract_dir))
- log.debug('extract_dir is %s' % extract_dir)
- log.debug('config is of ' + str(self.cfg))
- self.cfg['source'] = extract_dir
- log.debug('cfg[\'source\'] is ' + self.cfg['source'])
- orig_extract_dir = self.orig_dir(extract_dir)
- sourceball.extractall()
- copytree(abspath(extract_dir), abspath(orig_extract_dir))
- except OSError, e:
- #TODO: Fill this in with something better
- #Chances are the _orig dir already exists
- raise ExecutionException(e, 'something went wrong')
- #TODO: figure out what exceptions TarFile will throw
+ def source_dir(self, *args):
+ return join(self.dir, self.source(*args))
__all__ = ['SourceBall']