1 """configuration files"""
18 self.cond = threading.Condition()
19 self.config = config.Config()
22 def checksum(self, path):
25 try: return sha.new(f.read()).digest()
27 except IOError: return None
29 def system(self, cmd):
31 logger.log('conf_files: running command %s' % cmd)
35 def update_conf_file(self, cf_rec):
36 if not cf_rec['enabled']: return
38 logger.log('conf_files: considering file %s' % dest)
39 err_cmd = cf_rec['error_cmd']
40 mode = string.atoi(cf_rec['file_permissions'], base=8)
41 uid = pwd.getpwnam(cf_rec['file_owner'])[2]
42 gid = grp.getgrnam(cf_rec['file_group'])[2]
43 url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source'])
44 contents = curlwrapper.retrieve(url)
45 logger.log('conf_files: retrieving url %s' % url)
46 if not cf_rec['always_update'] and sha.new(contents).digest() == self.checksum(dest):
47 logger.log('conf_files: skipping file %s, always_update is false and checksums are identical' % dest)
49 if self.system(cf_rec['preinstall_cmd']):
51 if not cf_rec['ignore_cmd_errors']: return
52 logger.log('conf_files: installing file %s' % dest)
53 tools.write_file(dest, lambda f: f.write(contents), mode=mode, uidgid=(uid,gid))
54 if self.system(cf_rec['postinstall_cmd']): system(err_cmd)
59 while self.data == None: self.cond.wait()
64 for f in d['conf_files']:
65 try: self.update_conf_file(f)
66 except: logger.log_exc()
68 def callback(self, data):
77 def GetSlivers_callback(data): main.callback(data)
79 def start(options): tools.as_daemon_thread(main.run)