40 config = open(
'/etc/cc1/%s/config.py' % module).readlines()
42 raise Exception(
'config_open')
47 if line.startswith(key):
48 if type(value) == type(
""):
49 new_config.append(
'%s="%s"\n' % (key, value))
51 new_config.append(
'%s=%d\n' % (key, value))
53 new_config.append(line)
55 config = open(
'/etc/cc1/%s/config.py' % module,
'w')
56 config.write(
''.join(new_config))
65 return filter(
lambda option: option[0:2] !=
"__", dir(config))
74 config = __import__(
'config')
76 config = __import__(
'%s.config' % module, fromlist=[module.lower()])
78 config_example = __import__(
'%s.config_example' % module, fromlist=[module.lower()])
79 defaults = __import__(
'%s.defaults' % module, fromlist=[module.lower()])
86 for option_name
in options(config_example):
89 value = getattr(config, option_name)
90 except AttributeError:
92 value = getattr(defaults, option_name)
95 print "[info] '%s' configuration option '%s' not present, using default: %s" % (module, option_name, str(value))
96 except AttributeError:
99 print "[error] '%s' configuration option '%s' missing!" % (module, option_name)
102 for option_name
in options(config):
104 getattr(config_example, option_name)
105 except AttributeError:
106 print "[warning] '%s' configuration option '%s' is not used by CC1 and maybe should be removed" % (module, option_name)
110 raise Exception(
"'%s' configuration file is invalid. Please, edit your config.py file!." % module)
112 print "[info] CC1 %s configuration is valid." % module
116 shutil.copyfile(
'/usr/lib/cc1/%s/config_example.py' % site,
'/etc/cc1/%s/config.example' % site)
117 if os.path.exists(
'/etc/cc1/%s/config.py' % site):
119 if not os.path.exists(
'/usr/lib/cc1/%s/config.py' % site):
120 os.symlink(
'/etc/cc1/%s/config.py' % site,
'/usr/lib/cc1/%s/config.py' % site)
122 print "WARNING: %s alredy configured" % site
125 shutil.copyfile(
'/etc/cc1/%s/config.example' % site,
'/etc/cc1/%s/config.py' % site)
127 os.symlink(
'/etc/cc1/%s/config.py' % site,
'/usr/lib/cc1/%s/config.py' % site)
133 if os.path.exists(
'/usr/lib/cc1/%s/config.py' % site):
134 os.unlink(
'/usr/lib/cc1/%s/config.py' % site)
140 if os.path.exists(
'/etc/cc1/%s/config.py' % site):
141 os.remove(
'/etc/cc1/%s/config.py' % site)
143 if os.path.exists(
'/etc/cc1/%s/config.example' % site):
144 os.remove(
'/etc/cc1/%s/config.example' % site)