Exemplo n.º 1
0
    def xml_build(self):
        '''
        build XML tree

        @return: xml
        '''

        head = Xml.Element('home')
        tree = self._xml_build_loop(head, 1)    # 1 is id of Home
        self._init_release()
        Xml._xml_build_info(self, head, tree)
        return Xml.ElementTree(head)
Exemplo n.º 2
0
    def __init__(self, dirs, file=None, tim=time()):
        # initialize inherit class
        Xml.__init__(self)

        self._dir = dirs
        self._file = file

        self.time = int(tim)
        self.base = u_dir_child(dirs)

        # isolation_level for commit
        # check_same_thread for multithreading
        # cached_statements for cache
        self.__conn = connect(file, timeout=2, isolation_level='IMMEDIATE', \
                              check_same_thread=False, cached_statements=255)
        self.cursor = self.__conn.cursor()
        # avoiding dots optimization
        self.__exec = self.cursor.execute
        self.__exem = self.cursor.executemany
        self.__one = self.cursor.fetchone
        self.__all = self.cursor.fetchall
Exemplo n.º 3
0
    def _xml_build_loop(self, tree, ide):
        '''
        build branch of every directory
        RECURSIVE

        @param xml tree:    upper branch
        @param integer ide:    id of upper dir
        @return: list
        '''

        info = [0, 0, 0, 0]    # dir, file, new, del counter
        _set = '1'    # set flag to xml
        branch = None    # subelement of tree
        sub = None    # subelement of branch
        tupl_ = None    # list returned from loop
        sql_id = 0
        sql_del = 0
        sql_dtime = ''
        sql_lin = 0

        # build dir
        self.__exec('SELECT Id,Name,Mtime,Del,Dtime,Lin FROM DIR \
                    WHERE Obsolete=0 AND Parent=?;', \
                    (ide,))
        sql_get = self.__all()
        for lop in sql_get:
            sql_id = int(lop[0])
            sql_del = int(lop[3])
            sql_dtime = str(lop[4])
            sql_lin = int(lop[5])
            self._upd_link(sql_id, False)    # update link flag

            # build branch
            branch = Xml.SubElement(tree, XML_DI, {'id': str(sql_id)})
            info[0] += 1
            Xml._xml_build_dir(branch, lop)
            if(sql_del):
                branch.attrib['del'] = _set
                sub = Xml.SubElement(branch, 'dtime')
                sub.text = sql_dtime
                info[3] += 1
            elif(not sql_lin):
                branch.attrib['new'] = _set
                sub = Xml.SubElement(branch, 'ltime')
                sub.text = str(self.time)
                info[2] += 1

            # __loop
            tupl_ = self._xml_build_loop(branch, sql_id)
            info[0] += tupl_[0]    # update dir
            info[1] += tupl_[1]    # update file
            info[2] += tupl_[2]    # update new
            info[3] += tupl_[3]    # update del

        # build files
        self.__exec('SELECT Id,Name,Atime,Mtime,Hash,Del,Dtime,Lin FROM FILE \
                    WHERE Obsolete=0 AND Parent=?;', \
                    (ide,))
        sql_get = self.__all()
        for lop in sql_get:
            sql_id = int(lop[0])
            sql_del = int(lop[5])
            sql_dtime = str(lop[6])
            sql_lin = int(lop[7])
            self._upd_link(sql_id)    # update link flag

            # build tree
            branch = Xml.SubElement(tree, XML_FI, {'id': str(sql_id)})
            info[1] += 1
            Xml._xml_build_file(branch, lop)
            if(sql_del):
                branch.attrib['del'] = _set
                sub = Xml.SubElement(branch, 'dtime')
                sub.text = sql_dtime
                info[3] += 1
            elif(not sql_lin):
                branch.attrib['new'] = _set
                sub = Xml.SubElement(branch, 'ltime')
                sub.text = str(self.time)
                info[2] += 1

        return info