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


Python Database.delete_tag方法代码示例

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


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

示例1: cmd_tags

# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete_tag [as 别名]
    def cmd_tags(self, *args):
        parser = argparse.ArgumentParser(prog="tags", description="Modify tags of the opened file")
        parser.add_argument("-a", "--add", metavar="TAG", help="Add tags to the opened file (comma separated)")
        parser.add_argument("-d", "--delete", metavar="TAG", help="Delete a tag from the opened file")
        try:
            args = parser.parse_args(args)
        except:
            return

        # This command requires a session to be opened.
        if not __sessions__.is_set():
            self.log("error", "No session opened")
            parser.print_usage()
            return

        # If no arguments are specified, there's not much to do.
        # However, it could make sense to also retrieve a list of existing
        # tags from this command, and not just from the "find" command alone.
        if args.add is None and args.delete is None:
            parser.print_usage()
            return

        # TODO: handle situation where addition or deletion of a tag fail.

        db = Database()
        if not db.find(key="sha256", value=__sessions__.current.file.sha256):
            self.log(
                "error",
                "The opened file is not stored in the database. " "If you want to add it use the `store` command.",
            )
            return

        if args.add:
            # Add specified tags to the database's entry belonging to
            # the opened file.
            db.add_tags(__sessions__.current.file.sha256, args.add)
            self.log("info", "Tags added to the currently opened file")

            # We refresh the opened session to update the attributes.
            # Namely, the list of tags returned by the 'info' command
            # needs to be re-generated, or it wouldn't show the new tags
            # until the existing session is closed a new one is opened.
            self.log("info", "Refreshing session to update attributes...")
            __sessions__.new(__sessions__.current.file.path)

        if args.delete:
            # Delete the tag from the database.
            db.delete_tag(args.delete, __sessions__.current.file.sha256)
            # Refresh the session so that the attributes of the file are
            # updated.
            self.log("info", "Refreshing session to update attributes...")
            __sessions__.new(__sessions__.current.file.path)
开发者ID:noscripter,项目名称:viper,代码行数:54,代码来源:commands.py

示例2: tags

# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete_tag [as 别名]
def tags(tag_action=False):
    # Set DB
    db = Database()
    
    # Search or Delete
    if request.method == 'GET':
        action = request.query.action
        value = request.query.value.strip()
        
        if value:
            if action == 'search':
                # This will search all projects
                # Get project list
                projects = project_list()
                # Add Main db to list.
                projects.append('../')
                # Search All projects
                p_list = []
                results = {}
                for project in projects:
                    __project__.open(project)
                    # Init DB
                    db = Database()
                    #get results
                    proj_results = []
                    rows = db.find(key='tag', value=value)
                    for row in rows:
                        if project == '../':
                            project = 'Main'
                        proj_results.append([row.name, row.sha256])
                    results[project] = proj_results
                    p_list.append(project)
                # Return the search template
                return template('search.tpl', projects=p_list, results=results)
            else:
                return template('error.tpl', error="'{0}' Is not a valid tag action".format(action))
                             
    # Add / Delete                        
    if request.method == 'POST':
        file_hash = request.forms.get('sha256')
        project = request.forms.get('project')
        tag_name = request.forms.get('tag')
        if tag_action == 'add':
            if file_hash and project:
                tags = request.forms.get('tags')
                db.add_tags(file_hash, tags)
        if tag_action == 'del':
            if file_hash and tag_name:
                db.delete_tag(tag_name, file_hash)
        redirect('/file/{0}/{1}'.format(project, file_hash))
开发者ID:barryirwin,项目名称:Similarity-Analysis,代码行数:52,代码来源:web.py

示例3: tags

# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import delete_tag [as 别名]
def tags(tag_action=False):
    # Set DB
    db = Database()

    # Search or Delete
    if request.method == "GET":
        action = request.query.action
        value = request.query.value.strip()

        if value:
            if action == "search":
                # This will search all projects
                # Get project list
                projects = project_list()
                # Add Main db to list.
                projects.append("../")
                # Search All projects
                p_list = []
                results = {}
                for project in projects:
                    __project__.open(project)
                    # Init DB
                    db = Database()
                    # get results
                    proj_results = []
                    rows = db.find(key="tag", value=value)
                    for row in rows:
                        if project == "../":
                            project = "Main"
                        proj_results.append([row.name, row.sha256])
                    results[project] = proj_results
                    p_list.append(project)
                # Return the search template
                return template("search.tpl", projects=p_list, results=results)
            else:
                return template("error.tpl", error="'{0}' Is not a valid tag action".format(action))

    # Add / Delete
    if request.method == "POST":
        file_hash = request.forms.get("sha256")
        project = request.forms.get("project")
        tag_name = request.forms.get("tag")
        if tag_action == "add":
            if file_hash and project:
                tags = request.forms.get("tags")
                db.add_tags(file_hash, tags)
        if tag_action == "del":
            if file_hash and tag_name:
                db.delete_tag(tag_name, file_hash)
        redirect("/file/{0}/{1}".format(project, file_hash))
开发者ID:noscripter,项目名称:viper,代码行数:52,代码来源:web.py


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