* unuttum :(

This commit is contained in:
Eray Özkural
2005-06-23 13:49:17 +00:00
parent 9768625985
commit 90be2d8ced
2 changed files with 108 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
from constants import const
class Config(object):
"""Config Singleton"""
class configimpl:
def __init__(self):
# self.c.destdir = '' # install default to root by default
self.destdir = './tmp' # only for ALPHA
# the idea is that destdir can be set with --destdir=...
# directory accessor functions
# here is how it goes
# x_dir: system wide directory for storing info type x
# pkg_x_dir: per package directory for storing info type x
def lib_dir(self):
return self.destdir + const.lib_dir_suffix
def db_dir(self):
return self.destdir + const.db_dir_suffix
def archives_dir(self):
return self.destdir + const.archives_dir_suffix
def tmp_dir(self):
return self.destdir + const.tmp_dir_suffix
def work_dir(self):
return self.destdir + const.work_dir_suffix
def install_dir(self):
return self.destdir + const.install_dir_suffix
__configinstance = configimpl()
def __init__(self):
pass
def __getattr__(self, attr):
return getattr(self.__configinstance, attr)
def __setattr__(self, attr, value):
return setattr(self.__configinstance, attr, value)
# create a default context WITH NO PSPEC
config = Config()
+59
View File
@@ -0,0 +1,59 @@
class _constant:
"Constant members implementation"
class ConstError(TypeError):
pass
def __setattr__(self, name, value):
if self.__dict__.has_key(name):
raise self.ConstError, "Can't rebind constant: %s" % name
# Binding an attribute once to a const is available
self.__dict__[name] = value
def __delattr__(self, name):
if self.__dict__.has_key(name):
raise self.ConstError, "Can't unbind constant: %s" % name
# we don't have an attribute by this name
raise NameError, name
class Constants:
"Pisi constants"
__c = _constant()
def __init__(self):
# Metadata
#TODO: These two will be defined in a configuration file.
self.__c.distribution = "Pardus"
self.__c.distributionRelease = "0.1"
self.__c.lib_dir_suffix = "/var/lib/pisi"
self.__c.db_dir_suffix = "/var/db/pisi"
self.__c.archives_dir_suffix = "/var/cache/pisi/archives"
self.__c.tmp_dir_suffix = "/var/tmp/pisi"
# directory suffixes for build
self.__c.work_dir_suffix = "/work"
self.__c.install_dir_suffix = "/install"
# file/directory names
self.__c.actions_file = "actions.py"
self.__c.files_dir = "files"
self.__c.files_xml = "files.xml"
self.__c.metadata_xml = "metadata.xml"
# functions in actions_file
self.__c.setup_func = "setup"
self.__c.build_func = "build"
self.__c.install_func = "install"
def __getattr__(self, attr):
return getattr(self.__c, attr)
def __setattr__(self, attr, value):
return setattr(self.__c, attr, value)
def __delattr__(self, attr):
return delattr(self.__c, attr)
# singleton for easy access here
const = Constants()