From 2f97e978caf6d4cec0331a4f9ca07f8c48e2d0b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Sat, 2 Jul 2005 00:52:54 +0000 Subject: [PATCH] =?UTF-8?q?=C3=96n=20tan=C4=B1ml=C4=B1lar=C4=B1=20grupla?= =?UTF-8?q?=20ve=20=C3=B6ntan=C4=B1ml=C4=B1lar=C4=B1n=20se=C3=A7ilmesini?= =?UTF-8?q?=20Config=20s=C4=B1n=C4=B1f=C4=B1ndan=20soyutla.=20Bu=20hali=20?= =?UTF-8?q?ile=20daha=20iyi=20oldu=20san=C4=B1r=C4=B1m.=20ConfParser=20s?= =?UTF-8?q?=C4=B1n=C4=B1flar=C4=B1n=C4=B1=20configfile.py=20i=C3=A7erisine?= =?UTF-8?q?=20ta=C5=9F=C4=B1yaca=C4=9F=C4=B1m=20sonra.=20=C5=9Eimdilik=20b?= =?UTF-8?q?urada=20kals=C4=B1n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pisi/config.py | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/pisi/config.py b/pisi/config.py index 36c37178..bcccadc6 100644 --- a/pisi/config.py +++ b/pisi/config.py @@ -12,12 +12,35 @@ import os from ConfigParser import ConfigParser, NoSectionError 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): - def __init__(self, items=[]): + def __init__(self, section, 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): if not self.items: + if hasattr(self.defaults, attr): + return getattr(self.defaults, attr) return "" for item in self.items: if item[0] == attr: @@ -40,18 +63,14 @@ class ConfigurationFile(object): parser.read(self.filePath) try: - self.general = ConfigurationSection(parser.items("general")) - self.build = ConfigurationSection(parser.items("build")) + self.general = ConfigurationSection("general", + parser.items("general")) + self.build = ConfigurationSection("build", + parser.items("build")) except NoSectionError: - self.general = ConfigurationSection() - self.build = ConfigurationSection() + self.general = ConfigurationSection("general") + 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): """Config Singleton""" @@ -60,13 +79,7 @@ class Config(object): def __init__(self): self.conf = ConfigurationFile("/etc/pisi/pisi.conf") - 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 # here is how it goes