summaryrefslogtreecommitdiffstats
path: root/modules/directory.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/directory.py')
-rw-r--r--modules/directory.py86
1 files changed, 86 insertions, 0 deletions
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()
+