Commit c9868a24 authored by Nicolas Wavrant's avatar Nicolas Wavrant

recipe-zeroknown: uses class attributes as musch as possible

parent 5a84f622
...@@ -41,39 +41,33 @@ class WriteRecipe(GenericBaseRecipe): ...@@ -41,39 +41,33 @@ class WriteRecipe(GenericBaseRecipe):
self.filename = options['filename'].strip() self.filename = options['filename'].strip()
self.path = os.path.join(buildout['buildout']['directory'], self.filename) self.path = os.path.join(buildout['buildout']['directory'], self.filename)
del options['filename'] self.name = name
self.options = options.copy()
del self.options['filename']
del self.options['recipe']
# We don't want to save the recipe name
recipe = options.pop('recipe')
# Set up the parser, and write config file if needed # Set up the parser, and write config file if needed
self.parser = ConfigParser.ConfigParser() self.parser = ConfigParser.ConfigParser()
try: try:
self.parser.read(self.path) self.parser.read(self.path)
#clean_options(options) #clean_options(options)
for key in options: for key in self.options:
if key not in self.parser.options(name): if key not in self.parser.options(self.name):
self.parser.set(name, key, options[key]) self.parser.set(self.name, key, self.options[key])
with open(self.path, 'w') as file: with open(self.path, 'w') as file:
self.parser.write(file) self.parser.write(file)
# If the file or section do not exist # If the file or section do not exist
except ConfigParser.NoSectionError, IOError: except ConfigParser.NoSectionError, IOError:
#clean_options(options) self.full_install()
self.full_install(name, options)
# Or buildout will fail
options['recipe'] = recipe
# So that we can get the value in another buildout section
options['filename'] = self.filename
install = update = lambda self: [] install = update = lambda self: []
def full_install(self, name, options): def full_install(self):
self.parser.add_section(name) self.parser.read(self.path)
for key in options: self.parser.add_section(self.name)
self.parser.set(name, key, options[key]) for key in self.options:
self.parser.set(self.name, key, self.options[key])
with open(self.path, 'w') as file: with open(self.path, 'w') as file:
self.parser.write(file) self.parser.write(file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment