当前位置: 首页>>代码示例>>Python>>正文


Python Tag.link_sqlite方法代码示例

本文整理汇总了Python中tag.Tag.link_sqlite方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.link_sqlite方法的具体用法?Python Tag.link_sqlite怎么用?Python Tag.link_sqlite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tag.Tag的用法示例。


在下文中一共展示了Tag.link_sqlite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: copy_video

# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import link_sqlite [as 别名]
    def copy_video(self, vhash, source_db, dest_db, copy_tags=False):
        Video.link_sqlite(source_db)
        v = self.hash_to_vid(vhash)
        self.log.info("Copy video %s" % v)
        video_params = {}
        for k in v.__get_table_keys__():
            if k not in v.ban_keys:
                video_params[k] = getattr(v, k)
        Video.link_sqlite(dest_db)
        new_vid = Video.new(**video_params)

        if copy_tags:
            Tag.link_sqlite(source_db)
            for t in v.get_tags():
                new_tag = self.copy_tag(t, source_db, dest_db, copy_tag_data=True)
                new_tag.set_parent(new_vid)

        return new_vid
开发者ID:athityakumar,项目名称:software,代码行数:20,代码来源:merge.py

示例2: copy_tag

# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import link_sqlite [as 别名]
    def copy_tag(self, t, source_db, dest_db, copy_tag_data=False):
        self.log.info("Copy tag %s" % t)
        Tag.link_sqlite(source_db)
        tag_params = {}
        for k in t.__get_table_keys__():
            if k not in t.ban_keys:
                tag_params[k] = getattr(t, k)
        Tag.link_sqlite(dest_db)
        new_tag = Tag.tag_new(**tag_params)

        if copy_tag_data:
            Tag.link_sqlite(source_db)
            for frame in t.get_frame_list():
                Tag.link_sqlite(source_db)
                frame_info = t.get_frame_info(frame)
                Tag.link_sqlite(dest_db)
                new_tag.add_frame_info(frame, **frame_info)

        return new_tag
开发者ID:athityakumar,项目名称:software,代码行数:21,代码来源:merge.py

示例3: __init__

# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import link_sqlite [as 别名]
    def __init__(self, filename):
        if filename is None:
            self.log.warning("Invalid database filename specified")
            self.error = True
            return None

        self.conn = sqlite3.connect(filename, check_same_thread=False, \
                                              isolation_level="EXCLUSIVE")
        self.conn.row_factory = sqlite3.Row #return rows objects instead of raw tuples
        self.c = self.conn.cursor()

        self.c.execute("PRAGMA synchronous = 0")
        self.c.execute("PRAGMA journal_mode = OFF")

        self.filename = os.path.abspath(filename)
        self.root_dir = os.path.dirname(self.filename)

        DBInfo.link_sqlite(self)
        Video.link_sqlite(self)
        Tag.link_sqlite(self)

        ### Upgrade functionality
        db_version = DBInfo.get_version()
        if db_version > DATABASE_VERSION:
            self.log.error("Are you trying to provide a database file from the future? Why would you do that? (provided database version %d; expected <= %d)" % (db_version, DATABASE_VERSION))
            self.error = True
            return None

        if db_version != DATABASE_VERSION:
            self.log.warning("Old database version (database is version %d and most recent is version %d)" % (db_version, DATABASE_VERSION))

            backup_filename = "cave_upgrade_backup"
            self.log.info("Creating database backup at %s" % backup_filename)
            shutil.copy2(filename, backup_filename)
            
            #Methods provided to upgrade an old database version to the newest version
            #Running update_functions[i] must upgrade a database of version i-1 to version i.
            #An upgrade function should be provided whenever the DATABASE_VERSION is updated to
            #ensure old versions are still compatible
            upgrade_functions = {}

            def add_hash():
                SqlClass.turn_off_commits()
                videos = Video.get_all()
                tags = [video.get_tags() for video in videos]
                # We need to get all the frame info before
                # we erase the video table!
                for tag_ls in tags:
                    for tag in tag_ls:
                        tag._populate_frame_dict()

                for video in videos:
                    if not video.present():
                        self.log.error("Not all videos are present, cannot upgrade database!")
                        return False

                [video.remove() for video in videos]
                Video.remove_table()
                Video.table_setup()
                for i, video in enumerate(videos):
                    video.video_hash = \
                      hash_video(self.get_absolute_path(video.video_path))
                    Video.add(video)
                    for tag in tags[i]:
                        self.log.info("Adding tag %s in video %s" %(tag, video.video_path))
                        Tag.tag_add(tag)

                SqlClass.turn_on_commits()
                self.conn.commit()
                return True

            upgrade_functions[2] = add_hash

            while db_version < DATABASE_VERSION:
                i = db_version + 1
                if i not in upgrade_functions.keys():
                    self.error = True
                    self.log.error("Unable to upgrade database to version %d: No upgrade functionality provided." % i)
                    return None
                self.log.info("Upgrading database from version %d to %d" \
                              % (db_version, i))
                try:
                    success = upgrade_functions[i]()
                except Exception as e:
                    traceback.print_exc()
                    success = False

                if success:
                    DBInfo.set_version(i)
                    db_version = i
                else:
                    self.log.error("Upgrading database failed.")
                    shutil.copy2(backup_filename, filename)
                    os.remove(backup_filename)
                    break
        ###

        self.log.info("Database linked to %s" % filename)
        self.error = False
开发者ID:athityakumar,项目名称:software,代码行数:101,代码来源:database.py


注:本文中的tag.Tag.link_sqlite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。