daha sade bir config parser
This commit is contained in:
+41
-21
@@ -9,36 +9,56 @@
|
|||||||
#configuration parameters.
|
#configuration parameters.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from ConfigParser import ConfigParser
|
from ConfigParser import ConfigParser, NoSectionError
|
||||||
from constants import const
|
from constants import const
|
||||||
|
|
||||||
|
class ConfigurationSection:
|
||||||
|
def __init__(self, items=None):
|
||||||
|
self.items = items
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
if not self.items:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
for item in self.items:
|
||||||
|
if item[0] == attr:
|
||||||
|
return item[1]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
# should we move this class to its own module?
|
||||||
|
class ConfigurationFile(object):
|
||||||
|
def __init__(self, filePath):
|
||||||
|
parser = ConfigParser()
|
||||||
|
self.filePath = filePath
|
||||||
|
#/etc/pisi/pisi.conf
|
||||||
|
#[general]
|
||||||
|
#destinationDirectory = /tmp
|
||||||
|
#[build]
|
||||||
|
#host = i686-pc-linux-gnu
|
||||||
|
#CFLAGS= -mcpu=i686 -O2 -pipe -fomit-frame-pointer
|
||||||
|
#CXXFLAGS= -mcpu=i686 -O2 -pipe -fomit-frame-pointer
|
||||||
|
|
||||||
|
parser.read(self.filePath)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.general = ConfigurationSection(parser.items("general"))
|
||||||
|
self.build = ConfigurationSection(parser.items("build"))
|
||||||
|
except NoSectionError:
|
||||||
|
self.general = ConfigurationSection()
|
||||||
|
self.build = ConfigurationSection()
|
||||||
|
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
"""Config Singleton"""
|
"""Config Singleton"""
|
||||||
|
|
||||||
class configimpl:
|
class configimpl:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
configParser = ConfigParser()
|
self.conf = ConfigurationFile("/etc/pisi/pisi.conf")
|
||||||
configParser.read('/etc/pisi/pisi.conf')
|
|
||||||
#/etc/pisi/pisi.conf
|
|
||||||
#
|
|
||||||
#[general]
|
|
||||||
#destinationDirectory = /tmp
|
|
||||||
#
|
|
||||||
#[build]
|
|
||||||
#host = i686-pc-linux-gnu
|
|
||||||
#CFLAGS= -mcpu=i686 -O2 -pipe -fomit-frame-pointer
|
|
||||||
#CXXFLAGS= -mcpu=i686 -O2 -pipe -fomit-frame-pointer
|
|
||||||
|
|
||||||
|
|
||||||
self.destdir = os.getcwd() + configParser.get('general', \
|
|
||||||
'destinationDirectory')
|
|
||||||
# only for ALPHA
|
|
||||||
# the idea is that destdir can be set with --destdir=...
|
|
||||||
|
|
||||||
self.host = configParser.get('build', 'host')
|
self.destdir = self.conf.general.destinationDirectory
|
||||||
self.cflags = configParser.get('build', 'CFLAGS')
|
if not self.destdir:
|
||||||
self.cxxflags = configParser.get('build', 'CXXFLAGS')
|
self.destdir = os.getcwd()+"/tmp" # FOR ALPHA
|
||||||
|
|
||||||
# directory accessor functions
|
# directory accessor functions
|
||||||
# here is how it goes
|
# here is how it goes
|
||||||
|
|||||||
Reference in New Issue
Block a user