r123 - branches/rewrite/src
Nat Budin
partial-mirror-devel@lists.alioth.debian.org
Thu, 01 Jul 2004 21:11:40 -0600
Author: natbudin-guest
Date: Thu Jul 1 21:11:40 2004
New Revision: 123
Modified:
branches/rewrite/src/Config.py
Log:
Added logic for nominally parsing @VARIABLE@ key specs, fixed some typos. Config.py now parses our sample config file.
Modified: branches/rewrite/src/Config.py
==============================================================================
--- branches/rewrite/src/Config.py (original)
+++ branches/rewrite/src/Config.py Thu Jul 1 21:11:40 2004
@@ -18,6 +18,7 @@
from logging import *
from ConfigParser import ConfigParser, DEFAULTSECT
+from sys import exit
class Config(dict):
"""
@@ -44,50 +45,70 @@
'get_suggests',
'get_recommends',
'get_provides',
+ 'include_from_task',
+ 'exclude_from_task',
+ 'backends',
+ 'name',
+ 'resolve_deps_using',
]
def __init__(self, filename):
conf = ConfigParser()
conf.read(filename)
-
- # Read the default section.
- self['default'] = {}
+
+ # Read the default section.
+ self['DEFAULT'] = {}
for item, value in conf.items(DEFAULTSECT):
- if item not in required_in_default:
- error.msg("ERROR: [%s] is not allowed in default section of configuration file." % (item))
+ if item not in Config.required_in_default:
+ error("[%s] is not allowed in default section of configuration file." % (item))
exit(1)
- self['default'][item] = value
+ self['DEFAULT'][item] = value
for section in conf.sections():
self[section] = {}
for item, value in conf.items(section):
- if item not in allowed_in_backend:
- error.msg("ERROR: [%s] is not allowed in a backend section of a config file (it was found in [%s])."
- % (item, section))
- exit(1)
+ # is this item from the default section? if so, go on to the
+ # next item
+ if self['DEFAULT'].has_key(item):
+ if self['DEFAULT'][item] == value:
+ continue
+ if item not in Config.allowed_in_backend:
+ actually_its_ok = False
+ for allowed_key in Config.allowed_in_backend:
+ # check the allowed_in_backend keys with @VARIABLES@
+ if allowed_key.find('@') != -1:
+ nonvar_length = allowed_key.find('@')
+ if allowed_key[:nonvar_length] == item[:nonvar_length]:
+ # found it!
+ actually_its_ok = True
+ break
+ if not actually_its_ok:
+ error("[%s] is not allowed in a backend section of a config file (it was found in [%s])."
+ % (item, section))
+ exit(1)
self[section][item] = value
- def getValue(self, section, key):
+ def getValue(self, key, section='DEFAULT'):
# get a config value for a certain section. if it's not specified,
# fall back to DEFAULT
if not self.has_key(section):
- error.msg("ERROR: no config section called [%s]." % (section))
+ error("no config section called [%s]." % (section))
exit(1)
if self[section].has_key(key):
return self[section][key]
- if not self['default'].has_key(key):
- error.msg("ERROR: [%s] is not present in section [%s] or the default section of config file." % (key, section)
+ if not self['DEFAULT'].has_key(key):
+ error("[%s] is not present in section [%s] or the default section of config file." % (key, section))
exit(1)
- return self['default'][key]
+ return self['DEFAULT'][key]
def dump(self):
- print 'mirror_dir =', self.mirror_dir
- print 'architectures =', self.architectures
- print 'sections = ', self.sections
- print 'distributions =', self.distributions
- print 'get_provides = ', self.get_provides
- print 'get_recommends = ', self.get_recommends
- print 'get_suggests = ', self.get_suggests
+ print 'mirror_dir =', self.getValue('mirror_dir')
+ print 'architectures =', self.getValue('architectures')
+ print 'sections = ', self.getValue('sections')
+ print 'distributions =', self.getValue('distributions')
+ print 'get_provides = ', self.getValue('get_provides')
+ print 'get_recommends = ', self.getValue('get_recommends')
+ print 'get_suggests = ', self.getValue('get_suggests')
conf = Config('../etc/debpartial-mirror.conf')