update_db_module.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:DawnlightSearch 作者: chg-hou 项目源码 文件源码
def update_uuid(self):
        self.mutex.lock()

        # https://docs.python.org/2/library/sqlite3.html
        try:
            cur = MainCon.cur
            cur.execute('''
                SELECT uuid FROM `UUID` ;
                ''')
            uuid_in_db = cur.fetchall()
            self.mutex.unlock()
            uuids = [x[0] for x in uuid_in_db]
            logger.debug('SystemDevices.refresh_state')
            SystemDevices.refresh_state()
            logger.debug('SystemDevices.refresh_state END')
            deviceDict = SystemDevices.deviceDict
            uuid_list = []
            for dev_id, dev in deviceDict.items():
                uuid = dev['uuid']
                fstype = dev['fstype']
                label = dev['label']
                major_dnum, minor_dnum = dev_id
                uuid_list.append(uuid)
                if not uuid in uuids:
                    cur.execute('''INSERT INTO UUID (included, uuid, alias, fstype,name,label,major_dnum,minor_dnum, path)
                                 VALUES (?, ?,   ?,  ?,   ?,    ?,    ?,   ?, ?)''',
                                (False, dev['uuid'], dev['mountpoint'], dev['fstype'], dev['name'], dev['label'],
                                 major_dnum, minor_dnum, dev['mountpoint']))
                else:
                    cur.execute('''UPDATE  UUID SET fstype=?,name=?,label=?,major_dnum=?,minor_dnum=?,path=?
                        WHERE uuid=?''',
                                (dev['fstype'], dev['name'], dev['label'],
                                 major_dnum, minor_dnum, dev['mountpoint'],
                                 dev['uuid'])
                                )
            MainCon.con.commit()

        except Exception as e:
            self.show_statusbar_warning_msg_SIGNAL.emit(str(e))
            logger.error(str(e))

        self.mutex.unlock()
        logger.debug('init_table')
        for uuid in uuid_list:
            self.init_table(uuid, clear_table=False)
        logger.debug('init_table END')
        try:
            MainCon.con.commit()
        except Exception as e:
            logger.error(str(e))
            # self.con.commit()  # commit
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号