summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2008-10-02 19:23:48 -0400
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2008-10-02 19:23:48 -0400
commitc5f9da98ce8cacf1d21641e0e6e9f18d738612ed (patch)
tree55ee31a2b248987b7a4b97f4e37802468eae71ba /modules
parentc5b35b0b3c5b15705d238563223c91381fb3cf8b (diff)
downloadfedora-devshell-c5f9da98ce8cacf1d21641e0e6e9f18d738612ed.tar.gz
fedora-devshell-c5f9da98ce8cacf1d21641e0e6e9f18d738612ed.tar.xz
fedora-devshell-c5f9da98ce8cacf1d21641e0e6e9f18d738612ed.zip
Adds a package module that can manage a package plus source in a traditional manner.
This is going to be the API for package manipulation for what I have in mind.
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