Ejemplo n.º 1
0
 def build_tree(self, root_path):
     self.root_path = root_path
     files = os.listdir(self.root_path)
     self.root = entry.root_entry(root_path)
     print "Scanning root index..."
     for f in files:
         #print f
         if not f.startswith('.'):
             fpath = os.path.join(self.root_path, f)
             if os.path.isfile(fpath):
                 e = entry.e_file(f, self.root)
                 self.root.add_child(e)
             elif os.path.isdir(fpath):
                 e = entry.e_dir(f)
                 self.root.add_child(e)
                 self.__scan_folder(e)
Ejemplo n.º 2
0
    def from_xml(self, input):
        xml_tree = ET.parse(input)

        xml_root = xml_tree.getroot()

        if xml_root.tag == 'sufs_index': # todo put this into a constants
            for child in xml_root:
                if child.tag == 'root':
                    self.root = entry.root_entry()
                for ic in child:
                    if ic.tag == 'file':
                        ef = entry.e_file(ic.attrib['name'], self.root, False)
                        ef.set_hash(ic.attrib['hash'])
                        ef.length = int(ic.attrib['length'])
                        self.root.add_child(ef)
                    elif ic.tag == 'folder':
                        ed = entry.e_dir(ic.attrib['name'], self.root)
                        self.root.add_child(ed)
                        self.__parse_xml_folder(ic, ed)