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


Python Environment.get_env_object方法代码示例

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


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

示例1: get_display

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_env_object [as 别名]
    def get_display(my):

        top = my.top
        top.add_class("spt_sandbox_select_top")

        sandbox_options = [
                {
                    'name': 'fast',
                    'base_dir': 'C:/Fast',
                },
                {
                    'name': 'faster',
                    'base_dir': 'C:/Faster',
                },
                {
                    'name': 'slow',
                    'base_dir': 'Z:/Slow',
                }
        ]

        process = my.kwargs.get("process")

        search_key = my.kwargs.get("search_key")
        sobject = Search.get_by_search_key(search_key)


        search_type = sobject.get_base_search_type()

        client_os = Environment.get_env_object().get_client_os()
        if client_os == 'nt':
            prefix = "win32"
        else:
            prefix = "linux"
        alias_dict = Config.get_dict_value("checkin", "%s_sandbox_dir" % prefix)

        search_key = sobject.get_search_key()
        key = "sandbox_dir:%s" % search_key
        from pyasm.web import WidgetSettings
        value = WidgetSettings.get_value_by_key(key)


        sandboxes_div = DivWdg()
        top.add(sandboxes_div)

        sandboxes_div.add_relay_behavior( {
            'type': 'mouseenter',
            'bvr_match_class': 'spt_sandbox_option',
            'cbjs_action': '''
            var last_background = bvr.src_el.getStyle("background-color");
            bvr.src_el.setAttribute("spt_last_background", last_background);
            bvr.src_el.setStyle("background-color", "#E0E0E0");
            bvr.src_el.setStyle("opacity", "1.0");
            '''
        } )

        sandboxes_div.add_relay_behavior( {
            'type': 'mouseleave',
            'bvr_match_class': 'spt_sandbox_option',
            'cbjs_action': '''
            var last_background = bvr.src_el.getAttribute("spt_last_background");
            bvr.src_el.setStyle("background-color", last_background);
            if (!bvr.src_el.hasClass("spt_selected")) {
                bvr.src_el.setStyle("opacity", "0.5");
            }
            '''
        } )




        sandboxes_div.add_relay_behavior( {
            'type': 'mouseup',
            'key': key,
            'bvr_match_class': 'spt_sandbox_option',
            'cbjs_action': '''
            var sandbox_dir = bvr.src_el.getAttribute("spt_sandbox_dir");
            var server = TacticServerStub.get();
            server.set_widget_setting(bvr.key, sandbox_dir);


            var applet = spt.Applet.get();

            applet.makedirs(sandbox_dir);

            //var top = bvr.src_el.getParent(".spt_sandbox_select_top");
            var top = bvr.src_el.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        } )



        #search = Search("config/naming")
        #search.add_filter("search_type", search_type)
        #search.add_filter("process", process)
        #namings = search.get_sobjects()
        #naming = namings[0]

        from pyasm.biz import Snapshot, Naming
        virtual_snapshot = Snapshot.create_new()
#.........这里部分代码省略.........
开发者ID:0-T-0,项目名称:TACTIC,代码行数:103,代码来源:sandbox_select_wdg.py

示例2: check_new_job

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_env_object [as 别名]
    def check_new_job(self, queue_type=None):

        num_jobs = len(self.jobs)
        if num_jobs >= self.max_jobs:
            print("Already at max jobs [%s]" % self.max_jobs)
            return
      
        self.job = self.get_next_job(queue_type)
        if not self.job:
            return

		
        # set the process key
        process_key = self.get_process_key()
        self.job.set_value("host", process_key)
        self.job.commit()

        self.jobs.append(self.job)

        # get some info from the job
        command = self.job.get_value("command")
        job_code = self.job.get_value("code")

        try: 
            kwargs = self.job.get_json_value("data")
        except:
            try:
                # DEPRECATED
                kwargs = self.job.get_json_value("serialized")
            except:
                kwargs = {}
        if not kwargs:
            kwargs = {}

        login = self.job.get_value("login")
        script_path = self.job.get_value("script_path", no_exception=True)

        project_code = self.job.get_value("project_code")

        if script_path:
            command = 'tactic.command.PythonCmd'

            folder = os.path.dirname(script_path)
            title = os.path.basename(script_path)

            search = Search("config/custom_script")
            search.add_filter("folder", folder)
            search.add_filter("title", title)
            custom_script = search.get_sobject()
            script_code = custom_script.get_value("script")

            kwargs['code'] = script_code



        # add the job to the kwargs
        kwargs['job'] = self.job

        #print("command: ", command)
        #print("kwargs: ", kwargs)


        # Because we started a new thread, the environment may not
        # yet be initialized
        try:
            from pyasm.common import Environment
            Environment.get_env_object()
        except:
            # it usually is run at the very first transaction
            Batch()
        Project.set_project(project_code)


        queue = self.job.get_value("queue", no_exception=True)
        queue_type = 'repeat'

        stop_on_error = False

        print("Running job: ", self.job.get_value("code") )

        if queue_type == 'inline':

            cmd = Common.create_from_class_path(command, kwargs=kwargs)
            try:
                Container.put(Command.TOP_CMD_KEY, None)
                Container.put(Transaction.KEY, None)
                Command.execute_cmd(cmd)

                # set job to complete
                self.job.set_value("state", "complete")
            except Exception as e:
                self.job.set_value("state", "error")

            self.job.commit()
            self.jobs.remove(self.job)
            self.job = None

            self.jobs_completed += 1


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

示例3: get_base_dir

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_env_object [as 别名]
    def get_base_dir(my, protocol=None):
        '''get the default base directory for this sobject'''
        dirs = []
        base_dir = ''
        
        if not protocol:
            protocol = my.protocol

        if protocol == "http":

            repo_handler = my.sobject.get_repo_handler(my.snapshot)
            if repo_handler.is_tactic_repo():
                base_dir = Config.get_value("checkin", "web_base_dir")
            else:
                base_dir = Config.get_value("perforce", "web_base_dir")


        elif protocol == "remote":
            # TODO: currently needs web to do this
            base_dir = Environment.get_env_object().get_base_url().to_string()

            repo_handler = my.sobject.get_repo_handler(my.snapshot)
            if repo_handler.is_tactic_repo():
                sub_dir = Config.get_value("checkin", "web_base_dir")
            else:
                sub_dir = Config.get_value("perforce", "web_base_dir")

            base_dir = "%s%s" % (base_dir, sub_dir)

        elif protocol == "file":
            #base_dir = Config.get_value("checkin", "asset_base_dir")
            base_dir = Environment.get_asset_dir(my._file_object)

        elif protocol == "env":
            base_dir = "$TACTIC_ASSET_DIR"

        # This is the central repository as seen from the client
        elif protocol in ["client_lib", "client_repo"]:
            
            if Environment.get_env_object().get_client_os() =='nt':
                base_dir = my.get_custom_setting('win32_client_repo_dir')
                if not base_dir:
                    if my._file_object:
                        base_dir_alias = my._file_object.get_value('base_dir_alias')
                        if base_dir_alias:
                            alias_dict = Config.get_value("checkin", "base_dir_alias", sub_key=base_dir_alias)
                            base_dir = alias_dict.get("win32_client_repo_dir")
                    if not base_dir:
                        base_dir = Config.get_value("checkin", "win32_client_repo_dir", no_exception=True)
            else:
                base_dir = my.get_custom_setting('linux_client_repo_dir')
                if not base_dir:
                    if my._file_object:
                        base_dir_alias = my._file_object.get_value('base_dir_alias')
                        if base_dir_alias:
                            alias_dict = Config.get_value("checkin", "base_dir_alias", sub_key=base_dir_alias)
                            base_dir = alias_dict.get("linux_client_repo_dir")
                        if not base_dir:
                            base_dir = Config.get_value("checkin", "linux_client_repo_dir", no_exception=True)
            if not base_dir:
                #base_dir = Config.get_value("checkin", "asset_base_dir")
                base_dir = Environment.get_asset_dir()

        # DEPRECATED: The local repo.  This one has logic to add "repo" dir
        # at the end.  Use local_repo which does not have this logic.
        # keeping this around for backward compatibility
        elif protocol == "local":
            remote_repo = my.get_remote_repo()
            if remote_repo:
                #base_dir = remote_repo.get_value("repo_base_dir")
                base_dir = Environment.get_asset_dir()
            else:
                if Environment.get_env_object().get_client_os() =='nt':
                    base_dir = Config.get_value("checkin","win32_local_base_dir")
                else:
                    base_dir = Config.get_value("checkin","linux_local_base_dir")
                base_dir += "/repo"

        # The local repo
        elif protocol == "local_repo":
            remote_repo = my.get_remote_repo()
            if remote_repo:
                base_dir = remote_repo.get_value("repo_base_dir")
            else:
                if Environment.get_env_object().get_client_os() =='nt':
                    base_dir = Config.get_value("checkin","win32_local_repo_dir")
                else:
                    base_dir = Config.get_value("checkin","linux_local_repo_dir")
                if not base_dir:
                    base_dir = Environment.get_asset_dir()


        elif protocol == "sandbox":
            remote_repo = my.get_remote_repo()
            if remote_repo:
                base_dir = remote_repo.get_value("sandbox_base_dir")
            else:

                base_dir = PrefSetting.get_value_by_key("sandbox_base_dir")
                if not base_dir:
#.........这里部分代码省略.........
开发者ID:davidsouthpaw,项目名称:TACTIC,代码行数:103,代码来源:dir_naming.py

示例4: check_new_job

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_env_object [as 别名]
    def check_new_job(my):

        num_jobs = len(my.jobs)
        if num_jobs >= my.max_jobs:
            print "Already at max jobs [%s]" % my.max_jobs
            return


        my.job = my.get_next_job()
        if not my.job:
            return

        # set the process key
        process_key = my.get_process_key()
        my.job.set_value("host", process_key)
        my.job.commit()

        my.jobs.append(my.job)

        # get some info from the job
        command = my.job.get_value("command")
        job_code = my.job.get_value("code")
        #print "Grabbing job [%s] ... " % job_code

        try: 
            kwargs = my.job.get_json_value("data")
        except:
            try:
                kwargs = my.job.get_json_value("serialized")
            except:
                kwargs = {}

        project_code = my.job.get_value("project_code")
        login = my.job.get_value("login")
        script_path = my.job.get_value("script_path", no_exception=True)


        if script_path:
            Project.set_project(project_code)
            command = 'tactic.command.PythonCmd'

            folder = os.path.dirname(script_path)
            title = os.path.basename(script_path)

            search = Search("config/custom_script")
            search.add_filter("folder", folder)
            search.add_filter("title", title)
            custom_script = search.get_sobject()
            script_code = custom_script.get_value("script")

            kwargs['code'] = script_code



        # add the job to the kwargs
        kwargs['job'] = my.job

        #print "command: ", command
        #print "kwargs: ", kwargs


        # Because we started a new thread, the environment may not
        # yet be initialized
        try:
            from pyasm.common import Environment
            Environment.get_env_object()
        except:
            print "running batch"
            Batch()


        queue = my.job.get_value("queue", no_exception=True)
        queue_type = 'repeat'

        print "running job: ", my.job.get_value("code") 

        if queue_type == 'inline':

            cmd = Common.create_from_class_path(command, kwargs=kwargs)
            try:
                Command.execute_cmd(cmd)

                # set job to complete
                my.job.set_value("state", "complete")
            except Exception, e:
                my.job.set_value("state", "error")

            my.job.commit()
            my.jobs.remove(my.job)
            my.job = None
开发者ID:blezek,项目名称:TACTIC,代码行数:92,代码来源:queue.py

示例5: get_base_dir

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_env_object [as 别名]
    def get_base_dir(my, protocol=None, alias="default"):
        '''get the default base directory for this sobject'''
        dirs = []
        base_dir = ''

        client_os = Environment.get_env_object().get_client_os()
        if client_os == 'nt':
            prefix = "win32"
        else:
            prefix = "linux"

        if not alias:
            alias = "default"


        if not protocol:
            protocol = my.protocol

        if protocol == "http":

            repo_handler = my.sobject.get_repo_handler(my.snapshot)
            if repo_handler.is_tactic_repo():
                base_dir = Environment.get_web_dir(alias=alias)
            else:
                alias_dict = Config.get_dict_value("perforce", "web_base_dir")
                base_dir = alias_dict.get(alias)

            if not base_dir:
                asset_alias_dict = Environment.get_asset_dirs()
                base_dir = asset_alias_dict.get(alias)
                base_dir = "/%s" % os.path.basename(base_dir)

            if not base_dir:
                base_dir = alias_dict.get("default")

            if not base_dir:
                base_dir = "/assets"


        elif protocol == "remote":
            # NOTE: currently needs web to get the full http base url
            base_dir = Environment.get_env_object().get_base_url().to_string()

       
            sub_dir = my.get_base_dir(protocol='http', alias=alias)
            base_dir = "%s%s" % (base_dir, sub_dir[0])

            
        elif protocol == "file":
            base_dir = Environment.get_asset_dir(alias=alias)

        elif protocol == "env":
            base_dir = "$TACTIC_ASSET_DIR"


        # This is the central repository as seen from the client
        elif protocol in ["client_lib", "client_repo"]:
            base_dir = my.get_custom_setting('%s_client_repo_dir' % prefix)
            if not base_dir:
                alias_dict = Config.get_dict_value("checkin", "%s_client_repo_dir" % prefix)
                base_dir = alias_dict.get(alias)

            if not base_dir:
                base_dir = Environment.get_asset_dir()


        # DEPRECATED: The local repo.  This one has logic to add "repo" dir
        # at the end.  Use local_repo which does not have this logic.
        # keeping this around for backward compatibility
        elif protocol == "local":
            remote_repo = my.get_remote_repo()
            if remote_repo:
                #base_dir = remote_repo.get_value("repo_base_dir")
                base_dir = Environment.get_asset_dir()
            else:
                if Environment.get_env_object().get_client_os() =='nt':
                    base_dir = Config.get_value("checkin","win32_local_base_dir")
                else:
                    base_dir = Config.get_value("checkin","linux_local_base_dir")
                base_dir += "/repo"

        # The local repo
        elif protocol == "local_repo":
            remote_repo = my.get_remote_repo()
            if remote_repo:
                base_dir = remote_repo.get_value("repo_base_dir")
            else:
                if Environment.get_env_object().get_client_os() =='nt':
                    base_dir = Config.get_value("checkin","win32_local_repo_dir")
                else:
                    base_dir = Config.get_value("checkin","linux_local_repo_dir")
                if not base_dir:
                    base_dir = Environment.get_asset_dir()


        elif protocol == "sandbox":

            remote_repo = my.get_remote_repo()
            if remote_repo:
                base_dir = remote_repo.get_value("sandbox_base_dir")
#.........这里部分代码省略.........
开发者ID:0-T-0,项目名称:TACTIC,代码行数:103,代码来源:dir_naming.py

示例6: handle_directories

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_env_object [as 别名]
    def handle_directories(self, top):
        # deal with asset directories
        top.add(DivWdg('Asset Folders', css='spt_info_title'))
        mailserver = Config.get_value("services", "mailserver")
        table = Table()
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("asset_base_dir: ")
        td.add_style("width: 150px")
        asset_base_dir = Config.get_value("checkin", "asset_base_dir")
        if asset_base_dir:
            table.add_cell( asset_base_dir )
            tr = table.add_row()
            tr.add_style('border-bottom: 1px #bbb solid')
            # check if it is writable
            is_writable = os.access(asset_base_dir, os.W_OK)
            span = SpanWdg("writable:")
            span.add_style('padding-left: 20px')
            td = table.add_cell(span)
            td = table.add_cell(str(is_writable))
        else:
            table.add_cell( "None configured")

        client_os = Environment.get_env_object().get_client_os()
        if os.name == 'nt':
            os_name = 'win32'
        else:
            os_name = 'linux'
        if client_os == 'nt':
            client_os_name = 'win32'
        else:
            client_os_name = 'linux'

        env = Environment.get()
        client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True)
        client_asset_dir = env.get_client_repo_dir()

        table.add_row()
        td = table.add_cell("%s_server_handoff_dir: " % os_name)
        td.add_style("width: 150px")
        handoff_dir = Config.get_value("checkin", "%s_server_handoff_dir" % os_name)
        
        if handoff_dir:
            table.add_cell( handoff_dir )
            table.add_row()
            # check if it is writable
            is_writable = os.access(handoff_dir, os.W_OK)
            span = SpanWdg("writable:")
            span.add_style('padding-left: 20px')
            td = table.add_cell(span)
            td = table.add_cell(str(is_writable))
        else:
            table.add_cell( "None configured")

        table.add_row()
        td = table.add_cell("%s hand-off test: " % client_os_name)
        td.add_style("width: 150px")

        button = ActionButtonWdg(title='Test')
        button.add_behavior( {
            'type': 'click_up',
            'handoff_dir': client_handoff_dir,
            'asset_dir': client_asset_dir,
            'cbjs_action': '''
            
            var env = spt.Environment.get();


            var applet = spt.Applet.get();
            var handoff_state = applet.exists(bvr.handoff_dir);
            var asset_state = applet.exists(bvr.asset_dir);
            if (asset_state == false) {
                env.set_transfer_mode("web");
                spt.error('client repo directory is not accessible: ' + bvr.asset_dir);
            }
            else if (handoff_state == false) {
                env.set_transfer_mode("web");
                spt.error('client handoff directory is not accessible: ' + bvr.handoff_dir);
            }
            else {
                env.set_transfer_mode("copy");
                spt.info('<div>client handoff directory: ' + bvr.handoff_dir + '</div><br/><div>client repo directory :' + bvr.asset_dir +  '</div><br/><div> can be successfully accessed.</div>', {type:'html'});
            }
            '''
            } )

        table.add_cell( button )
开发者ID:mincau,项目名称:TACTIC,代码行数:91,代码来源:system_info_wdg.py


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