def test_localfile_backend_method3(self): """Tests for localfile/Backend/remove_task method: - parse task file to check if task has been removed. """ self.create_test_environment() doc, configxml = cleanxml.openxmlfile(self.datapath, 'config') xmlproject = doc.getElementsByTagName('backend') for domobj in xmlproject: dic = {} if domobj.hasAttribute("module"): dic["module"] = str(domobj.getAttribute("module")) dic["pid"] = str(domobj.getAttribute("pid")) dic["xmlobject"] = domobj dic["Enabled"] = True dic["path"] = self.taskpath beobj = localfile.Backend(dic) expectedres = True beobj.remove_task("0@1") beobj.quit() dataline = open(self.taskpath, 'r').read() if "0@1" in dataline: res = False else: res = True expectedres = True self.assertEqual(res, expectedres)
def __init__(self, parameters): """ Instantiates a new backend. @param parameters: A dictionary of parameters, generated from _static_parameters. A few parameters are added to those, the list of these is in the "DefaultBackend" class, look for the KEY_* constants. The backend should take care if one expected value is None or does not exist in the dictionary. """ super(Backend, self).__init__(parameters) # RETROCOMPATIBILIY # NOTE: retrocompatibility from the 0.2 series to 0.3. # We convert "filename" to "path and we forget about "filename " if "need_conversion" in parameters: parameters["path"] = parameters.pop("need_conversion") if self.KEY_DEFAULT_BACKEND not in parameters: parameters[self.KEY_DEFAULT_BACKEND] = True self.doc, self.xmlproj = cleanxml.openxmlfile(self.get_path(), "project") # status if backup was used while trying to open xml file self._used_backup = cleanxml.used_backup() self._backup_file_info = cleanxml.backup_file_info() # Make safety daily backup after loading cleanxml.savexml(self.get_path(), self.doc, backup=True)
def test_localfile_backend_method3(self): """Tests for localfile/Backend/remove_task method: - parse task file to check if task has been removed. """ self.create_test_environment() doc, configxml = cleanxml.openxmlfile(self.datapath, 'config') xmlproject = doc.getElementsByTagName('backend') for domobj in xmlproject: dic = {} if domobj.hasAttribute("module"): dic["module"] = str(domobj.getAttribute("module")) dic["pid"] = str(domobj.getAttribute("pid")) dic["xmlobject"] = domobj dic["enabled"] = True dic["path"] = self.taskpath beobj = localfile.Backend(dic) expectedres = True beobj.remove_task("0@1") beobj.quit() dataline = open(self.taskpath, 'r').read() if "0@1" in dataline: res = False else: res = True expectedres = True self.assertEqual(res, expectedres)
def load_tag_tree(self): """ Loads the tag tree from a xml file """ tagfile = os.path.join(CoreConfig().get_data_dir(), TAG_XMLFILE) doc, xmlstore = cleanxml.openxmlfile(tagfile, TAG_XMLROOT) for t in xmlstore.childNodes: if t.nodeType == t.TEXT_NODE: continue; tagname = t.getAttribute("name") parent = t.getAttribute("parent") tag_attr = {} attr = t.attributes for i in range(attr.length): at_name = attr.item(i).name if at_name not in ["name", "parent"]: at_val = t.getAttribute(at_name) tag_attr[at_name] = at_val if parent == CoreConfig.SEARCH_TAG: query = t.getAttribute("query") tag = self.new_search_tag(tagname, query, tag_attr) else: tag = self.new_tag(tagname, tag_attr) if parent: tag.set_parent(parent) self.tagfile = tagfile
def load_tag_tree(self): """ Loads the tag tree from a xml file """ doc, xmlstore = cleanxml.openxmlfile(TAGS_XMLFILE, TAG_XMLROOT) for t in xmlstore.childNodes: tagname = t.getAttribute("name") parent = t.getAttribute("parent") tag_attr = {} attr = t.attributes for i in range(attr.length): at_name = attr.item(i).name if at_name not in ["name", "parent"]: at_val = t.getAttribute(at_name) tag_attr[at_name] = at_val if parent == SEARCH_TAG: query = t.getAttribute("query") tag = self.new_search_tag(tagname, query, tag_attr) else: tag = self.new_tag(tagname, tag_attr) if parent: tag.set_parent(parent) self.tagfile_loaded = True
def __init__(self, parameters): """ Instantiates a new backend. @param parameters: A dictionary of parameters, generated from _static_parameters. A few parameters are added to those, the list of these is in the "DefaultBackend" class, look for the KEY_* constants. The backend should take care if one expected value is None or does not exist in the dictionary. """ super(Backend, self).__init__(parameters) # RETROCOMPATIBILIY # NOTE: retrocompatibility from the 0.2 series to 0.3. # We convert "filename" to "path and we forget about "filename " if "need_conversion" in parameters: parameters["path"] = parameters.pop("need_conversion") if self.KEY_DEFAULT_BACKEND not in parameters: parameters[self.KEY_DEFAULT_BACKEND] = True self.doc, self.xmlproj = cleanxml.openxmlfile( self.get_path(), "project") # status if backup was used while trying to open xml file self._used_backup = cleanxml.used_backup() self._backup_file_info = cleanxml.backup_file_info() # Make safety daily backup after loading cleanxml.savexml(self.get_path(), self.doc, backup=True)
def __init__(self, parameters): """ Instantiates a new backend. @param parameters: A dictionary of parameters, generated from _static_parameters. A few parameters are added to those, the list of these is in the "DefaultBackend" class, look for the KEY_* constants. The backend should take care if one expected value is None or does not exist in the dictionary. """ super(Backend, self).__init__(parameters) self.tids = [] #we keep the list of loaded task ids here #####RETROCOMPATIBILIY #NOTE: retrocompatibility from the 0.2 series to 0.3. # We convert "filename" to "path and we forget about "filename " if "need_conversion" in parameters: parameters["path"] = os.path.join(self.DEFAULT_PATH, \ parameters["need_conversion"]) del parameters["need_conversion"] if not self.KEY_DEFAULT_BACKEND in parameters: parameters[self.KEY_DEFAULT_BACKEND] = True #### self.doc, self.xmlproj = cleanxml.openxmlfile( \ self._parameters["path"], "project")
def this_is_the_first_run(self, xml): """ Called upon the very first GTG startup. This function is needed only in this backend, because it can be used as default one. The xml parameter is an object containing GTG default tasks. It will be saved to a file, and the backend will be set as default. @param xml: an xml object containing the default tasks. """ self._parameters[self.KEY_DEFAULT_BACKEND] = True cleanxml.savexml(self.get_path(), xml) self.doc, self.xmlproj = cleanxml.openxmlfile( self.get_path(), "project")
def _read_backend_configuration_file(self): """ Reads the file describing the current backend configuration (project.xml) and returns a list of dictionaries, each containing: - the xml object defining the backend characteristics under "xmlobject" - the name of the backend under "module" """ # Read configuration file, if it does not exist, create one doc, configxml = cleanxml.openxmlfile(PROJECTS_XMLFILE, "config") xmlproject = doc.getElementsByTagName("backend") # collect configured backends return [{"xmlobject": xp, "module": xp.getAttribute("module")} for xp in xmlproject]
def _read_backend_configuration_file(self): ''' Reads the file describing the current backend configuration (project.xml) and returns a list of dictionaries, each containing: - the xml object defining the backend characteristics under "xmlobject" - the name of the backend under "module" ''' # Read configuration file, if it does not exist, create one doc, configxml = cleanxml.openxmlfile(PROJECTS_XMLFILE, "config") xmlproject = doc.getElementsByTagName("backend") # collect configured backends return [{"xmlobject": xp, "module": xp.getAttribute("module")} for xp in xmlproject]
def _read_backend_configuration_file(self): ''' Reads the file describing the current backend configuration (project.xml) and returns a list of dictionaries, each containing: - the xml object defining the backend characteristics under "xmlobject" - the name of the backend under "module" ''' # Read configuration file, if it does not exist, create one datafile = os.path.join(CoreConfig().get_data_dir(), CoreConfig.DATA_FILE) doc, configxml = cleanxml.openxmlfile(datafile, "config") xmlproject = doc.getElementsByTagName("backend") # collect configured backends return [{"xmlobject": xp, "module": xp.getAttribute("module")} for xp in xmlproject]
def load_tag_tree(self): # Loading tags tagfile = os.path.join(CoreConfig().get_data_dir(), TAG_XMLFILE) doc, xmlstore = cleanxml.openxmlfile(tagfile,TAG_XMLROOT) for t in xmlstore.childNodes: #We should only care about tag with a name beginning with "@" #Other are special tags tagname = t.getAttribute("name") tag = self.new_tag(tagname) attr = t.attributes i = 0 while i < attr.length: at_name = attr.item(i).name at_val = t.getAttribute(at_name) tag.set_attribute(at_name, at_val) i += 1 parent = tag.get_attribute('parent') if parent: # if self.__tagstore.has_node(parent): # pnode = self.__tagstore.get_node(parent) # else: # pnode=self.new_tag(parent) tag.set_parent(parent) self.tagfile = tagfile
def initialize(self): """ This is called when a backend is enabled """ super(Backend, self).initialize() self.doc, self.xmlproj = cleanxml.openxmlfile(self.get_path(), "project")
def initialize(self): """ This is called when a backend is enabled """ super(Backend, self).initialize() self.doc, self.xmlproj = cleanxml.openxmlfile( self.get_path(), "project")
def initialize(self): """This is called when a backend is enabled""" super(Backend, self).initialize() self.doc, self.xmlproj = cleanxml.openxmlfile( \ self._parameters["path"], "project")