Ön tanımlıları grupla ve öntanımlıların seçilmesini Config sınıfından
soyutla. Bu hali ile daha iyi oldu sanırım. ConfParser sınıflarını configfile.py içerisine taşıyacağım sonra. Şimdilik burada kalsın.
This commit is contained in:
+30
-17
@@ -12,12 +12,35 @@ import os
|
|||||||
from ConfigParser import ConfigParser, NoSectionError
|
from ConfigParser import ConfigParser, NoSectionError
|
||||||
from constants import const
|
from constants import const
|
||||||
|
|
||||||
|
class ConfigException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class GeneralDefaults:
|
||||||
|
destinationDirectory = os.getcwd()+"/tmp" # FOR ALPHA
|
||||||
|
|
||||||
|
class BuildDefaults:
|
||||||
|
host = "i686-pc-linux-gnu"
|
||||||
|
CFLAGS = "-mcpu=i686 -O2 -pipe -fomit-frame-pointer"
|
||||||
|
CXXFLAGS= "-mcpu=i686 -O2 -pipe -fomit-frame-pointer"
|
||||||
|
|
||||||
class ConfigurationSection(object):
|
class ConfigurationSection(object):
|
||||||
def __init__(self, items=[]):
|
def __init__(self, section, items=[]):
|
||||||
self.items = items
|
self.items = items
|
||||||
|
|
||||||
|
if section == "general":
|
||||||
|
self.defaults = GeneralDefaults
|
||||||
|
elif section == "build":
|
||||||
|
self.defaults = BuildDefaults
|
||||||
|
else:
|
||||||
|
e = "No section by name '%s'" % section
|
||||||
|
raise ConfigException, e
|
||||||
|
|
||||||
|
self.section = section
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if not self.items:
|
if not self.items:
|
||||||
|
if hasattr(self.defaults, attr):
|
||||||
|
return getattr(self.defaults, attr)
|
||||||
return ""
|
return ""
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item[0] == attr:
|
if item[0] == attr:
|
||||||
@@ -40,18 +63,14 @@ class ConfigurationFile(object):
|
|||||||
parser.read(self.filePath)
|
parser.read(self.filePath)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.general = ConfigurationSection(parser.items("general"))
|
self.general = ConfigurationSection("general",
|
||||||
self.build = ConfigurationSection(parser.items("build"))
|
parser.items("general"))
|
||||||
|
self.build = ConfigurationSection("build",
|
||||||
|
parser.items("build"))
|
||||||
except NoSectionError:
|
except NoSectionError:
|
||||||
self.general = ConfigurationSection()
|
self.general = ConfigurationSection("general")
|
||||||
self.build = ConfigurationSection()
|
self.build = ConfigurationSection("build")
|
||||||
|
|
||||||
class Defaults:
|
|
||||||
destinationDirectory = os.getcwd()+"/tmp" # FOR ALPHA
|
|
||||||
|
|
||||||
host = "i686-pc-linux-gnu"
|
|
||||||
CFLAGS = "-mcpu=i686 -O2 -pipe -fomit-frame-pointer"
|
|
||||||
CXXFLAGS= "-mcpu=i686 -O2 -pipe -fomit-frame-pointer"
|
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
"""Config Singleton"""
|
"""Config Singleton"""
|
||||||
@@ -60,13 +79,7 @@ class Config(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.conf = ConfigurationFile("/etc/pisi/pisi.conf")
|
self.conf = ConfigurationFile("/etc/pisi/pisi.conf")
|
||||||
|
|
||||||
self.destdir = self.conf.general.destinationDirectory
|
self.destdir = self.conf.general.destinationDirectory
|
||||||
if not self.destdir:
|
|
||||||
self.destdir = Defaults.destinationDirectory
|
|
||||||
|
|
||||||
if not self.conf.build.host:
|
|
||||||
self.conf.build.host = Defaults.host
|
|
||||||
|
|
||||||
# directory accessor functions
|
# directory accessor functions
|
||||||
# here is how it goes
|
# here is how it goes
|
||||||
|
|||||||
Reference in New Issue
Block a user