summaryrefslogtreecommitdiffstats
path: root/modules/dirfactory.py
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-03 15:41:24 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-03 15:41:24 -0500
commit36953f9c563700d4ef67149c2c13c1df70b02c96 (patch)
tree06c39559b2e66f6467f95fcdafc88d60d47d78b3 /modules/dirfactory.py
parente427d02a7693c395d26c03f6a12a09ca504009bc (diff)
downloadfedora-devshell-36953f9c563700d4ef67149c2c13c1df70b02c96.tar.gz
fedora-devshell-36953f9c563700d4ef67149c2c13c1df70b02c96.tar.xz
fedora-devshell-36953f9c563700d4ef67149c2c13c1df70b02c96.zip
Add directory factory autodetect powers
Diffstat (limited to 'modules/dirfactory.py')
-rw-r--r--modules/dirfactory.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/modules/dirfactory.py b/modules/dirfactory.py
new file mode 100644
index 0000000..3665a89
--- /dev/null
+++ b/modules/dirfactory.py
@@ -0,0 +1,70 @@
+# 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: Yaakov M. Nemoy <ynemoy@redhat.com>
+#
+
+from __future__ import with_statement
+
+from configobj import ConfigObj
+from inspect import isclass
+from os import getcwd
+from os.path import abspath, exists
+
+from base.util import pwd, log
+from base.module import Module
+from modules.package import Package
+from modules.directory import Directory
+from modules.revisioncontrol import RevisionControl
+from modules.sourceball import SourceBall
+
+# TODO: i'm jumping through bureaucrautic hoops right now.
+# Don't program at 3am kids, it's harmful to your sanity
+foo = []
+for x,y in globals().copy().iteritems():
+ foo.append([x,y])
+foo = dict(foo)
+dirs = dict([[key.lower(), val] for key, val in foo.iteritems() if isclass(val) and issubclass(val, Directory)])
+
+class DirFactory(Module):
+ def __new__(cls, name=None):
+ if not name:
+ log.debug('no name with dirfactory')
+ dir = getcwd()
+ type = whatis_sysdir(dir)
+ else:
+ log.debug('dirfactory.new with name ' + name)
+ dir = abspath(name)
+ if not exists(dir):
+ type = 'directory'
+ else:
+ type = whatis_sysdir(dir)
+ new_cls = dirs[type]
+ log.debug(new_cls)
+ foo = new_cls.__new__(new_cls, name)
+ foo.__init__(name)
+ log.debug(foo)
+ log.debug(foo.cfg)
+ return foo
+
+def whatis_sysdir(dir):
+ with pwd(dir):
+ cfg = ConfigObj('.devshell')
+ try:
+ type = cfg['type']
+ log.debug('is type ' + type)
+ return type
+ except KeyError, e:
+ return 'directory'