summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-03 00:49:32 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-03 00:49:32 -0500
commite427d02a7693c395d26c03f6a12a09ca504009bc (patch)
tree0960e873f842d548bf5064e03ee9800e3c3ae5d6
parent9779e186a5cf6adb3dd5bc1b7f7fee2f5d328e9e (diff)
downloadfedora-devshell-e427d02a7693c395d26c03f6a12a09ca504009bc.tar.gz
fedora-devshell-e427d02a7693c395d26c03f6a12a09ca504009bc.tar.xz
fedora-devshell-e427d02a7693c395d26c03f6a12a09ca504009bc.zip
major refactoring to do better generic directories
-rw-r--r--base/module.py1
-rw-r--r--modules/directory.py86
-rw-r--r--modules/package.py74
3 files changed, 97 insertions, 64 deletions
diff --git a/base/module.py b/base/module.py
index 04c2a7d..19b89ca 100644
--- a/base/module.py
+++ b/base/module.py
@@ -21,4 +21,3 @@ class Module(object):
""" Our parent class for all command modules """
def close(self):
raise NotImplementedError
- pass
diff --git a/modules/directory.py b/modules/directory.py
new file mode 100644
index 0000000..ed27eeb
--- /dev/null
+++ b/modules/directory.py
@@ -0,0 +1,86 @@
+# Fedora Developer Shell
+#
+# 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Authors: Luke Macken <lmacken@redhat.com>
+# Yaakov M. Nemoy <ynemoy@redhat.com>
+#
+
+from __future__ import with_statement
+
+from configobj import ConfigObj
+from os import makedirs, getcwd
+from os.path import abspath, join, split, splitext, basename, exists
+
+from base.base import log
+from base.module import Module
+from base.util import pwd
+
+
+class Directory(Module):
+ _type = 'directory'
+ def __init__(self, name=None):
+ if not name:
+ log.debug('no name with package')
+ cwd = getcwd()
+ log.debug(split(cwd))
+ if self.is_dir_pkg(cwd):
+ self.load_dir(cwd)
+ else:
+ self.make_dir(cwd)
+ #TODO: detect name somehow
+ else:
+ log.debug('package.init with name ' + name)
+ dir = abspath(name)
+ if not exists(dir):
+ makedirs(dir)
+ if self.is_sysdir_dir(dir):
+ self.load_dir(dir)
+ else:
+ self.make_dir(dir)
+
+ def is_sysdir_dir(self, dir):
+ with pwd(dir):
+ cfg = ConfigObj('.devshell')
+ try:
+ if self._type in cfg['type']:
+ log.debug('is type ' + self._type)
+ return True
+ else:
+ return False
+ except KeyError, e:
+ return False
+
+ def load_dir(self, dir):
+ log.debug('directory.load_dir')
+ with pwd(dir):
+ self.cfg = ConfigObj('.devshell')
+ self.name = self.cfg['name']
+ self.dir = self.cfg['dir']
+
+ def make_dir(self, dir):
+ log.debug('directory.make_dir')
+ with pwd(dir):
+ self.cfg = ConfigObj('.devshell')
+ name = split(getcwd())[1]
+ self.cfg['type'] = self._type
+ self.cfg['name'] = self.name = name
+ self.cfg['dir'] = self.dir = dir
+ self.cfg.write()
+
+ def close(self):
+ log.debug('writing self.cfg for directory')
+ with pwd(self.dir):
+ self.cfg.write()
+
diff --git a/modules/package.py b/modules/package.py
index b548c58..4efb186 100644
--- a/modules/package.py
+++ b/modules/package.py
@@ -17,74 +17,27 @@
#
from __future__ import with_statement
-import tarfile
-from os import makedirs, getcwd
-from os.path import abspath, join, split, splitext, basename, exists
-from configobj import ConfigObj
-from subprocess import Popen, PIPE
-from urllib import urlretrieve
-from base.module import Module
from base.base import log
from base.exceptions import ExecutionException
from base.util import pwd, copy
from base.profiles import ver_rel
-#TODO: Find universal library for parsing URLs and PATHs alike
+from modules.directory import Directory
-class Package(Module):
- def __init__(self, name=None):
- if not name:
- log.debug('no name with package')
- cwd = getcwd()
- log.debug(split(cwd))
- if self.is_dir_pkg(cwd):
- self.load_pkg(cwd)
- else:
- self.make_pkg(cwd)
- name = split(getcwd())[1]
-
- self.code_dir = getcwd()
- #detect name somehow
- else:
- log.debug('package.init with name ' + name)
- dir = abspath(name)
- if not exists(dir):
- makedirs(dir)
- if self.is_dir_pkg(dir):
- self.load_pkg(dir)
- else:
- self.make_pkg(dir)
- def is_dir_pkg(self, dir):
- with pwd(dir):
- cfg = ConfigObj('.devshell')
- try:
- if cfg['type'] == 'package':
- log.debug('is type package')
- return True
- else:
- return False
- except KeyError, e:
- return False
-
- def load_pkg(self, dir):
- log.debug('package.load_pkg')
- with pwd(dir):
- self.cfg = ConfigObj('.devshell')
- self.name = self.cfg['name']
- self.code_dir = self.cfg['code_dir']
+class Package(Directory):
+ _type = 'package'
+ def load_dir(self, dir):
+ super(Package, self).load_dir(dir)
+ # this is a hack for some refactoring backwards compatibility
+ #TODO: replace code_dir with just dir
+ self.code_dir = self.cfg['dir']
- def make_pkg(self, dir):
- log.debug('package.make_pkg')
- with pwd(dir):
- name = split(getcwd())[1]
- self.cfg = ConfigObj('.devshell')
- self.cfg['type'] = 'package'
- self.cfg['name'] = self.name = name
- self.cfg['code_dir'] = self.code_dir = dir
- self.cfg.write()
+ def make_dir(self, dir):
+ super(Package, self).make_dir(dir)
+ self.code_dir = dir
def add_spec(self, spec_file):
log.debug('spec_file is %s' % spec_file)
@@ -96,11 +49,6 @@ class Package(Module):
log.error(str(e))
raise ExecutionException(e, 'spec-file could not be added')
- def close(self):
- log.debug('writing self.cfg for package')
- with pwd(self.code_dir):
- self.cfg.write()
-
@property
def spec_file(self):
return self.name + '.spec'