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


Python Environment.get_template_dir方法代码示例

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


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

示例1: execute

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

        my.base_dir = my.kwargs.get("base_dir")
        if not my.base_dir:
            my.base_dir = Environment.get_template_dir()


        my.project_code = my.kwargs.get("project_code")
        if not my.project_code:
            my.project_code = Project.get_project_code()

        assert my.project_code

        # project code can be called anything, and we want to have a _template suffix for the template code
        #my.plugin_code = "%s_template" % my.project_code

        #my.template_project_code = re.sub( '_template$', '', my.plugin_code)
        my.template_project_code = my.project_code
        my.project = Project.get_by_code(my.project_code)
        if not my.project:
            raise TacticException('This project [%s] does not exist'%my.project_code)

        my.project_type = my.project.get_value("type")
        if not my.project_type:
            my.project_type = my.project_code
        Project.set_project(my.project_code)

        my.export_template()
开发者ID:0-T-0,项目名称:TACTIC,代码行数:30,代码来源:project_template_cmd.py

示例2: execute

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

        from pyasm.common import ZipUtil
        ziputil = ZipUtil()

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

        upload_dir = Environment.get_upload_dir()
        template_dir = Environment.get_template_dir()

        for path in paths:
            path = path.replace("\\", "/")
            basename = os.path.basename(path)
            upload_path = "%s/%s" % (upload_dir, basename)

            if not upload_path.endswith(".zip"):
                continue

            print "upload: ", upload_path
            if not os.path.exists(upload_path):
                continue


            print "template_dir: ", template_dir
            shutil.move(upload_path, template_dir)
            to_path = "%s/%s" % (template_dir, basename)

            # unzip the file
            ziputil.extract(to_path)
开发者ID:0-T-0,项目名称:TACTIC,代码行数:31,代码来源:project_template_wdg.py

示例3: execute

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

        self.base_dir = self.kwargs.get("base_dir")
        if not self.base_dir:
            self.base_dir = Environment.get_template_dir()


        self.project_code = self.kwargs.get("project_code")
        if not self.project_code:
            self.project_code = Project.get_project_code()

        assert self.project_code

        # project code can be called anything, and we want to have a _template suffix for the template code
        #self.plugin_code = "%s_template" % self.project_code

        #self.template_project_code = re.sub( '_template$', '', self.plugin_code)
        self.template_project_code = self.project_code
        self.project = Project.get_by_code(self.project_code)
        if not self.project:
            raise TacticException('This project [%s] does not exist'%self.project_code)

        self.project_type = self.project.get_value("type")
        if not self.project_type:
            self.project_type = self.project_code
        Project.set_project(self.project_code)

        self.export_template()
开发者ID:mincau,项目名称:TACTIC,代码行数:30,代码来源:project_template_cmd.py

示例4: handle_path

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

        src_path = src_path.replace("\\", "/")

        # upload folder
        basename = os.path.basename(src_path)

        if my.mode =='copy':
            target_path = src_path
            target_dir = os.path.dirname(target_path)
        else:
            target_dir = Environment.get_upload_dir()
            target_path = "%s/%s" % (target_dir, basename)
    

        base_dir = Environment.get_template_dir()
        template_dir = "%s/%s" % (base_dir, my.project_code)
        

        if os.path.exists(template_dir):
            shutil.rmtree(template_dir)
            #raise TacticException("Template is already installed at [%s]" %template_dir)

        # unzip the file
        from pyasm.common import ZipUtil
        # this is fixed for windows if zipping doesn't use compression
        paths = ZipUtil.extract(target_path)

        # veryify that the paths extracted are the expected ones
        rootname, ext = os.path.splitext(basename)

        # check if it unzips at the templates folder directly
        unzip_at_template_dir = False
        # move the plugin zip file to the appropriate folder
        if my.mode == 'copy':
            # if they manually drop the zip file already here, skip
            if target_dir != base_dir:
                shutil.copy(target_path, base_dir)
            else:
                unzip_at_template_dir = True
        else:
            shutil.move(target_path, base_dir)


        # move unzipped files into the plugin area
        # remove any version info, only allow 1 particular version installed for now
        import re
        rootname = re.sub('(.*)(-)(\d.*)', r'\1', rootname)
        unzip_path = "%s/%s" % (target_dir, rootname)
       
        
        dest_dir = '%s/%s'%(base_dir, rootname)
        
        if not unzip_at_template_dir and os.path.exists(dest_dir):
            shutil.rmtree(dest_dir)

            shutil.move(unzip_path, dest_dir)
开发者ID:0-T-0,项目名称:TACTIC,代码行数:59,代码来源:project_template_cmd.py

示例5: get_display

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

        div = DivWdg()
        div.add_class("spt_project_template_top")
        my.set_as_panel(div)

        div.add_color("background", "background")

        upload_div = DivWdg()
        upload_div.add_style("padding: 10px")
        upload_div.add_style("width: 600px")



        # add the main layout
        table = ResizableTableWdg()
        table.add_color("color", "color")
        div.add(table)

        table.add_row()
        left = table.add_cell()
        left.add_border()
        left.add_style("min-width: 250px")
        left.add_style("height: 400px")

        left.add(my.get_templates_wdg() )

        right = table.add_cell()
        right.add_border()
        right.add_style("width: 400px")
        right.add_style("height: 400px")
        right.add_style("padding: 5px")
        right.add_class("spt_project_template_content")

        template = my.kwargs.get("template")
        if template: 
            template_dir = Environment.get_template_dir()
            template_dir = "%s/%s" % (template_dir, template)
            class_name = 'tactic.ui.app.ProjectTemplateEditWdg';
            content_div = ProjectTemplateEditWdg(template_dir=template_dir)
        else:
            content_div = DivWdg()
            content_div.add_style("margin: 40px")
            content_div.add_style("width: 300px")
            content_div.add_style("height: 150px")
            content_div.add_style("opacity: 0.7")
            content_div.add_border()
            content_div.add_color("background", "background3")
            content_div.add("<br/>"*4)
            content_div.add("No templates selected")
            content_div.add_style("text-align: center")

        right.add(content_div)

        return div
开发者ID:0-T-0,项目名称:TACTIC,代码行数:57,代码来源:project_template_wdg.py

示例6: get_display

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_template_dir [as 别名]

#.........这里部分代码省略.........
        copy_div.add_style("padding-top: 20px")





        template = ActionButtonWdg(title="Manage", tip="Manage Templates")
        copy_div.add(template)
        template.add_style("float: right")
        template.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
                var class_name = 'tactic.ui.app.ProjectTemplateWdg'
                spt.panel.load_popup("Templates", class_name)
            '''
        } )
        template.add_style("margin-top: -5px")




        copy_div.add("<b>Copy From Template: &nbsp;&nbsp;</b>")



        search = Search("sthpw/project")
        search.add_filter("is_template", True)
        template_projects = search.get_sobjects()
        values = [x.get_value("code") for x in template_projects]
        labels = [x.get_value("title") for x in template_projects]


        # find all of the template projects installed
        template_dir = Environment.get_template_dir()
        import os
        if not os.path.exists(template_dir):
            paths = []
        else:
            paths = os.listdir(template_dir);


            file_values = []
            file_labels = []
            for path in paths:
                if path.endswith("zip"):
                    orig_path = '%s/%s'%(template_dir, path)
                    path = path.replace(".zip", "")
                    parts = path.split("-")
                    plugin_code = parts[0]

                    # skip if there is a matching project in the database
                    #match_project = plugin_code.replace("_template", "")
                    
                    match_project = plugin_code
                    old_style_plugin_code = re.sub( '_template$', '', plugin_code)

                    if match_project in values:
                        continue
                    elif old_style_plugin_code in values:
                        continue

                    label = "%s (from file)" % Common.get_display_title(match_project)

                    # for zip file, we want the path as well
                    value = '%s|%s'%(plugin_code, orig_path)
                    file_values.append(value)
开发者ID:hellios78,项目名称:TACTIC,代码行数:70,代码来源:page_header_wdg.py

示例7: get_templates_wdg

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_template_dir [as 别名]

#.........这里部分代码省略.........
                server.execute_cmd(cmd, kwargs);

                var path = paths[0]
                path = path.replace(/\\/g, "/");
                var parts = path.split("/");
                var name = parts[parts.length-1];
                var parts2 = name.split("-");
                var name = parts2[0];


                var top = bvr.src_el.getParent(".spt_project_template_top");
                top.setAttribute("spt_template", name);
                spt.panel.refresh(top);
                spt.app_busy.hide();
                spt.notify.show_message("Project Template ["+name+"] has been installed.");
            }catch (e) {
                spt.app_busy.hide();
                spt.alert(spt.exception.handler(e));
            }

            '''
        } )




        div.add(title_div)
        title_div.add("<b>Installed Templates</b>")
        title_div.add_gradient("background", "background", 0, -10)
        title_div.add_color("color", "color3")
        title_div.add_style("margin: -5px -5px 5px -5px")
        title_div.add_style("font-weight: bold")
        title_div.add_style("padding: 8px")

        templates_div = DivWdg()
        div.add(templates_div)

        templates_div.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_project_template_top");
            var content = top.getElement(".spt_project_template_content")
            var class_name = 'tactic.ui.app.ProjectTemplateEditWdg';
            var template_dir = bvr.src_el.getAttribute("spt_template_dir");
            var kwargs = {
                template_dir: template_dir
            };
            spt.panel.load(content, class_name, kwargs);
            '''
        } )
        templates_div.add_class("hand")


        bgcolor = title_div.get_color("background3")
        bgcolor2 = title_div.get_color("background3", -10)
        templates_div.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "%s")
            ''' % bgcolor2
        } )
        templates_div.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_template',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "%s")
            ''' % bgcolor
        } )





        template_dir = Environment.get_template_dir()
        if not template_dir:
            raise Exception("No template dir defined")
        #template_dir = "/home/apache/project_templates"
        dirnames = os.listdir(template_dir)

        #templates = ['scrum', 'tickets', 'vfx', 'game']
        for template in dirnames:

            path = "%s/%s" % (template_dir, template)

            if not os.path.isdir(path):
                continue


            template_div = DivWdg()
            templates_div.add(template_div)
            icon = IconWdg("View Template [%s]" % template, IconWdg.DETAILS)
            template_div.add(icon)
            template_div.add(template)
            template_div.add_style("padding: 5px 3px 5px 3px")
            template_div.add_class("spt_template")
            template_div.add_attr("spt_template_dir", path)

        return div
开发者ID:0-T-0,项目名称:TACTIC,代码行数:104,代码来源:project_template_wdg.py

示例8: import_template

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

        if my.path:
            base_dir = os.path.dirname(my.path)
        else:
            base_dir = Environment.get_template_dir()


        version = my.kwargs.get("version")
        if version:
            template_dir = "%s/%s-%s" % (base_dir, my.template_code, version)
        else:
            template_dir = "%s/%s" % (base_dir, my.template_code)

        template_dir = my.get_template_dir(template_dir)
        
        # if the directory does not exist then look for a zip file
        use_zip = False
        if not os.path.exists(template_dir):
            template_zip = "%s.zip" % (template_dir)
            if os.path.exists(template_zip):
                use_zip = True
            else:
                hint = "Please check if you have created the Template already using the Update button in the Template Project view."
                if version:
                    raise TacticException("No template found for [%s] version [%s]. %s" % (my.template_code, version, hint))
                else:
                    raise TacticException("No template found for [%s]. %s" % (my.template_code, hint))
                    



        # check to see if the database exists in the default
        # database implementation
        from pyasm.search import DbContainer, DatabaseImpl
        impl = DatabaseImpl.get()
        exists = impl.database_exists(my.project_code)

        # if the database already exists, then raise an exception
        if exists and my.new_project:
            msg = "WARNING: Database [%s] already exists" % my.project_code
            print msg
            raise TacticException(msg)


        # this is the overriding factor:
        if my.is_template == True:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == False:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == None:
            # these 2 is for old usage using the command line script create_template.py
            if my.template_project_code != my.project_code:
                my.is_template = False
                title = Common.get_display_title(my.project_code)
            else:
                my.is_template = True
                title = Common.get_display_title(my.template_project_code)


        # create a new project if this was desired
        if my.new_project == True:
            from create_project_cmd import CreateProjectCmd
            project_image_path = my.kwargs.get("project_image_path")

            # the project_type will get updated properly by the PluginInstaller
            # but that break the ties to the project_type entry created though,
            # which is ok
            creator = CreateProjectCmd(
                project_code=my.project_code,
                project_title=title,
                project_type=my.template_project_code,
                is_template=my.is_template,
                use_default_side_bar=False,
                project_image_path=project_image_path
            )
            creator.execute()


        # set the project
        Project.set_project(my.project_code)

        # import from a plugin
        if use_zip:
            kwargs = {
                'zip_path': template_zip,
                'code': my.project_code
            }

        else:
            kwargs = {
                'plugin_dir': template_dir
            }


        kwargs['filter_line_handler'] = my.filter_line_handler
        kwargs['filter_sobject_handler'] = my.filter_sobject_handler

        from plugin import PluginCreator, PluginInstaller
        installer = PluginInstaller( **kwargs )
#.........这里部分代码省略.........
开发者ID:0-T-0,项目名称:TACTIC,代码行数:103,代码来源:project_template_cmd.py


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