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


Python Common.extract_keywords_from_path方法代码示例

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


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

示例1: handle_keywords

# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import extract_keywords_from_path [as 别名]
    def handle_keywords(self):

        input = self.get_input()
        caller = self.get_caller()

        sobj = caller

        base_search_type = sobj.get_base_search_type()


        has_keywords_data = False
        rename_collection = False
        if sobj:
            has_keywords_data = sobj.column_exists("keywords_data")

        is_collection = input.get("sobject").get("_is_collection")
        
        if input.get("is_delete") == True:
            # Collection relationships being removed
            mode = "delete"
            self.update_collection_keywords(mode, base_search_type, input)
            return


        # Collection relationships being created or added
        elif input.get("is_insert"):
            mode = "insert"
            self.update_collection_keywords(mode, base_search_type, input)



        # If keywords_data column exists and collection is being changed 
        # or folder structure changed
        if has_keywords_data:
            
            update_data = input.get("update_data")

            # If Relative dir is changed or file is renamed, update path keywords
            if ("relative_dir" in update_data or "name" in update_data) and not input.get("mode") == "insert":
                
                file_path = input.get("sobject").get("relative_dir")
                asset_name = input.get("sobject").get("name")

                project_code = Project.get_project_code()

                # Ignore the common keywords path
                ignore_path = "%s/asset" % project_code
                if ignore_path in file_path:
                    file_path = file_path.replace(ignore_path, "")

                path_keywords = Common.extract_keywords_from_path(file_path)
                path_keywords.append(asset_name.lower())
                path_keywords = " ".join(path_keywords)

                keywords_data = sobj.get_json_value("keywords_data", {})

                keywords_data['path'] = path_keywords
                sobj.set_json_value("keywords_data", keywords_data)
                sobj.commit(triggers=False)
                self.set_searchable_keywords(sobj)

            else:
                if "user_keywords" in update_data:
                    has_user_keywords = True

                    user_keywords = input.get("update_data").get("user_keywords")

                    if not user_keywords:
                        user_keywords = ""

                else:
                    has_user_keywords = False

                if is_collection:
                    if input.get("mode") == "update" and "name" in update_data:
                        rename_collection = True

                    # New Collection created
                    if input.get("is_insert"):
                        collection_keywords = update_data.get("user_keywords")
                        collection_name = update_data.get("name")

                        keywords_data = sobj.get_json_value("keywords_data", {})
                        if collection_keywords:
                            keywords_data['user'] = "%s %s" % (collection_name, collection_keywords)
                        else:
                            keywords_data['user'] = "%s" % collection_name
                            
                        sobj.set_json_value("keywords_data", keywords_data)
                        sobj.commit(triggers=False)
                        self.set_searchable_keywords(sobj)  

                    # If collection is renamed
                    elif rename_collection:
                        collection_name = update_data.get("name")
                        keywords_data = sobj.get_json_value("keywords_data", {})

                        if 'user' in keywords_data:
                            user = keywords_data.get('user')
                            old_collection_name = input.get("prev_data").get("name")
#.........这里部分代码省略.........
开发者ID:mincau,项目名称:TACTIC,代码行数:103,代码来源:global_search_trigger.py

示例2: execute

# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import extract_keywords_from_path [as 别名]
    def execute(self):

        file_path = self.kwargs.get("path")
        site = self.kwargs.get("site")
        project_code = self.kwargs.get("project_code")
        base_dir = self.kwargs.get("base_dir")
        search_type = self.kwargs.get("search_type")
        process = self.kwargs.get("process")
        watch_script_path = self.kwargs.get("script_path")
        if not process:
            process = "publish"

        basename = os.path.basename(file_path)

        context = self.kwargs.get("context")
        if not context:
            context = '%s/%s'  % (process, basename)


        # find the relative_dir and relative_path
        relative_path = file_path.replace("%s/" % base_dir, "")
        relative_dir = os.path.dirname(relative_path)

        file_name = os.path.basename(file_path)
        log_path = '%s/TACTIC_log.txt' %(base_dir)
        self.create_checkin_log()

        # Define asset type of the file
        asset_type = self.get_asset_type(file_path)
        description = "drop folder check-in of %s" %file_name

        from client.tactic_client_lib import TacticServerStub
        server = TacticServerStub.get(protocol='local')
        server.set_project(project_code)

        transaction = Transaction.get(create=True)
        server.start(title='Check-in of media', description='Check-in of media')

        server_return_value = {}

        try:
            filters = [
                    [ 'name', '=', file_name ],
                    #[ 'relative_dir', '=', relative_dir ]
                ]
            sobj = server.query(search_type, filters=filters, single=True)

            if not sobj:
                # create sobject if it does not yet exist
                sobj = SearchType.create(search_type)
                if SearchType.column_exists(search_type, "name"):
                    sobj.set_value("name", basename)
                if SearchType.column_exists(search_type, "media_type"):
                    sobj.set_value("media_type", asset_type)


                if SearchType.column_exists(search_type, "relative_dir"):
                    sobj.set_value("relative_dir", relative_dir)

                if SearchType.column_exists(search_type, "keywords"):
                    relative_path = relative_path
                    keywords = Common.extract_keywords_from_path(relative_path)
                    keywords = " ".join( keywords )
                    sobj.set_value("keywords", keywords)

                sobj.commit()
                search_key = sobj.get_search_key()
            else:
                search_key = sobj.get("__search_key__")


            #task = server.create_task(sobj.get('__search_key__'),process='publish')
            #server.update(task, {'status': 'New'})
            
            """
            #TEST: simulate different check-in duration
            from random import randint
            sec = randint(1, 5)
            print "checking in for ", sec, "sec"
            server.eval("@SOBJECT(sthpw/login)")
            import shutil
            dir_name,base_name = os.path.split(file_path)
            dest_dir = 'C:/ProgramData/Southpaw/watch_temp'
            if not os.path.exists(dest_dir):
                os.makedirs(dest_dir)
            shutil.move(file_path, '%s/%s'%(dest_dir, base_name))
            time.sleep(sec)
            # move back the file in a few seconds 
            shutil.move('%s/%s'%(dest_dir, base_name), file_path)
            """
            server_return_value = server.simple_checkin(search_key,  context, file_path, description=description, mode='move')

            if watch_script_path:
                cmd = PythonCmd(script_path=watch_script_path,search_type=search_type,drop_path=file_path,search_key=search_key)
                cmd.execute()



            
        except Exception as e:
#.........这里部分代码省略.........
开发者ID:mincau,项目名称:TACTIC,代码行数:103,代码来源:watch_drop_folder.py


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