summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/package.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/package.py b/modules/package.py
new file mode 100644
index 0000000..cb0548e
--- /dev/null
+++ b/modules/package.py
@@ -0,0 +1,64 @@
+import tarfile
+
+from os import makedirs, getcwd, chdir
+from shutil import copyfileobj, copytree
+from os.path import abspath, join, split, splitext, basename
+
+
+from base.module import Module
+from base.base import log
+from base.exceptions import ExecutionException
+
+#TODO: Find universal library for parsing URLs and PATHs alike
+
+class Package(Module):
+ def __init__(self, name=None):
+ if not name:
+ #detect name somehow
+ pass
+ # TODO: the following
+ #check location
+ #determine type of package
+ # to configure commands
+ self.name = name
+
+ def create(self, name):
+ if not self.name:
+ makedirs(join(getcwd(), name))
+
+ def add_spec(self, spec_file, name=None):
+ log.debug('spec_file is %s' % spec_file)
+ log.debug('name might be %s' % name)
+ if self.name:
+ name = self.name
+ log.debug('spec_file_name is %s' % name + '.spec')
+ try:
+ # we're using copyfileobj so later we can do this from a URL
+ src = file(spec_file, 'rb')
+ dst = file(join(getcwd(), name, name + '.spec'), 'wb')
+ copyfileobj(src, dst)
+ src.close()
+ dst.close()
+ except IOError, e:
+ log.error(str(e))
+ raise ExecutionException(e, 'spec-file could not be added')
+
+ def add_sourceball(self, sourceball_name, name=None, extract_dir=None):
+ if self.name:
+ name = self.name
+ #TODO: this is temporary
+ else:
+ log.debug(abspath(name))
+ chdir(abspath(name))
+ try:
+ 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)
+ orig_extract_dir = extract_dir + '_orig'
+ sourceball.extractall()
+ copytree(abspath(extract_dir), abspath(orig_extract_dir))
+ finally:
+ #TODO: figure out what exceptions TarFile will throw
+ pass \ No newline at end of file