コード例 #1
0
    def execute(self):

        import os
        path = self.kwargs.get("path")
        path = path.replace("\\", "/")
        basename = os.path.basename(path)

        upload_dir = Environment.get_upload_dir()

        path = "%s/%s" % (upload_dir, basename)

        paths = ZipUtil.extract(path)


        # TODO: why do we need to read the manifest here?
        # ... should be automatic
        manifest_path = "%s/transaction_log/manifest.xml" % upload_dir
        if not os.path.exists(manifest_path):
            raise TacticException("Cannot find manifest file [%s]" % manifest_path)
        f = codecs.open(manifest_path, 'r', 'utf-8')
        manifest_xml = f.read()
        f.close()
        creator = PluginInstaller(base_dir=upload_dir, manifest=manifest_xml)
        creator.execute()


        # run the transactions
        logs = creator.get_jobs()
        for log in logs:
            transaction_xml = log.get_value("transaction")
            cmd = RunTransactionCmd(transaction_xml=transaction_xml)
            cmd.execute()

            # This is needed here, because normaly, RunTransactionCmd
            # is run by a sync, so it blocks further syncs.  When
            # a transaction session is installed, we need to propogate
            # this to the other machines
            cmd = TransactionQueueAppendCmd()
            input = {
                'search_type': 'sthpw/transaction_log',
                'sobject': log
            }
            cmd.input = input
            cmd.execute()
コード例 #2
0
    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)
        installer.execute()
コード例 #3
0
ファイル: project_template_cmd.py プロジェクト: 0-T-0/TACTIC
    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 )
        installer.execute()