def write_options(self, values): """ Write or change the watch options in a configuration file. Values has to be a dictionary with the name from the options and the value. example: { 'name':'value', 'option1':'value' } If the name is not found, a new watch will be added, else the existing watch will be changed. """ self.cfg = ini_namespace(file(self.file_name)) name = values['name'] if not self.cfg._sections.has_key(name): self.cfg.new_namespace(name) #add a new watch in the list del values[ 'name'] #now that we know the name of the watch, we only want to write its options for option, value in values.iteritems(): self.cfg[name][option] = value try: f = open(self.file_name, "w") f.write(str(self.cfg).strip()) #write the new configuration file except IOError: self.specto.logger.log( _("There was an error writing to %s") % self.file_name, "critical", self.__class__) finally: f.close()
def __init__(self): #read the watch from ~/.specto/watches.list using the iniparser module self.file_name = os.environ['HOME'] + "/.specto/" + "watches.list" if not os.path.exists(self.file_name): f = open(self.file_name, "w") f.close() os.chmod(self.file_name, 0600)#This is important for security purposes, we make the file read-write to the owner only, otherwise everyone can read passwords. self.cfg = ini_namespace(file(self.file_name))
def search_watch(self, name): """ Returns True if the watch is found in ~/.specto/watches.list. """ self.cfg = ini_namespace(file(self.file_name)) if not self.cfg._sections.has_key(name): return False else: return True
def search_watch(self, name): """ Returns True if the watch is found in ~/.specto/watches.list. """ self.cfg = ini_namespace(file(self.file_name)) if not self.cfg._sections.has_key(name): return False else: return True
def __init__(self): #read the watch from ~/.specto/watches.list using the iniparser module self.file_name = os.environ['HOME'] + "/.specto/" + "watches.list" if not os.path.exists(self.file_name): f = open(self.file_name, "w") f.close() os.chmod( self.file_name, 0600 ) #This is important for security purposes, we make the file read-write to the owner only, otherwise everyone can read passwords. self.cfg = ini_namespace(file(self.file_name))
def write_options(self, file_name, values): """ Write or change the watch options in a configuration file. Values has to be a dictionary with the name from the options and the value. example: { 'name':'value', 'name':'value' } If the name is not found, a new watch will be added, else the excisting watch will be changed. """ if not os.path.exists(file_name): f = open(file_name, "w") f.close() self.cfg = ini_namespace(file(file_name)) name = values['name'] if not self.cfg._sections.has_key(name): self.cfg.new_namespace(name) #add a new watch del values['name'] for option, value in values.iteritems(): self.cfg[name][option] = value f = open(file_name, "w") f.write(str(self.cfg).strip()) #write the new configuration file f.close()
def write_options(self, values): """ Write or change the watch options in a configuration file. Values has to be a dictionary with the name from the options and the value. example: { 'name':'value', 'option1':'value' } If the name is not found, a new watch will be added, else the existing watch will be changed. """ self.cfg = ini_namespace(file(self.file_name)) name = values['name'] if not self.cfg._sections.has_key(name): self.cfg.new_namespace(name) #add a new watch in the list del values['name']#now that we know the name of the watch, we only want to write its options for option, value in values.iteritems(): self.cfg[name][option] = value try: f = open(self.file_name, "w") f.write(str(self.cfg).strip()) #write the new configuration file except IOError: self.specto.logger.log(_("There was an error writing to %s") % self.file_name, "critical", self.__class__) finally: f.close()