Example #1
0
    def handle_transaction(my, base_dir, transaction_code, dirname):

        import time

        start = time.time()

        # check to see if the transaction exists already
        log = Search.get_by_code("sthpw/transaction_log", transaction_code)
        if log:
            print "Transaction [%s] already exists. Skipping ..." % log.get_code(
            )
            return

        transaction_path = "%s/%s/sthpw_transaction_log.spt" % (base_dir,
                                                                dirname)
        if not os.path.exists(transaction_path):
            # this file has not arrived yet, so ignore
            return

        manifest_path = "%s/%s/manifest.xml" % (base_dir, dirname)
        f = open(manifest_path)
        manifest_xml = f.read()
        f.close()

        transaction_path = "%s/%s/sthpw_transaction_log.spt" % (base_dir,
                                                                dirname)

        search = Search("sthpw/sync_log")
        search.add_filter("transaction_code", transaction_code)
        sync_log = search.get_sobject()
        #if sync_log:
        #    print "Already processed [%s]" % transaction_code
        #    return

        try:

            from tactic.command import PluginInstaller
            from run_transaction_cmd import RunTransactionCmd

            # import the transaction data
            installer = PluginInstaller(manifest=manifest_xml)

            jobs = installer.import_data(transaction_path, commit=False)
            transaction_log = jobs[0]

            file_base_dir = "%s/%s" % (base_dir, dirname)

            # run the transaction in its own command
            from run_transaction_cmd import RunTransactionCmd
            run_transaction = RunTransactionCmd(
                transaction_xml=transaction_log, base_dir=file_base_dir)
            Command.execute_cmd(run_transaction)

            status = "complete"

        # May need special handing
        #except MissingItemException, e:
        #    print "WARNING: Could not run transaction [%s]" % transaction_code
        #    print "Error reported: ", str(e)
        #    search = SearchType.create("sthpw/sync_error")

        except Exception, e:
            print "WARNING: Could not run transaction [%s]" % transaction_code
            print "Error reported: ", str(e)
            status = "error"
            error = str(e)
Example #2
0
    def handle_transaction(my, base_dir, transaction_code, dirname):

        import time

        start = time.time()


        # check to see if the transaction exists already
        log = Search.get_by_code("sthpw/transaction_log", transaction_code)
        if log:
            print "Transaction [%s] already exists. Skipping ..." % log.get_code()
            return



        transaction_path = "%s/%s/sthpw_transaction_log.spt" % (base_dir, dirname)
        if not os.path.exists(transaction_path):
            # this file has not arrived yet, so ignore
            return


        manifest_path = "%s/%s/manifest.xml" % (base_dir, dirname)
        f = open(manifest_path)
        manifest_xml = f.read()
        f.close()

        transaction_path = "%s/%s/sthpw_transaction_log.spt" % (base_dir, dirname)

        search = Search("sthpw/sync_log")
        search.add_filter("transaction_code", transaction_code)
        sync_log = search.get_sobject()
        #if sync_log:
        #    print "Already processed [%s]" % transaction_code
        #    return

        try:

            from tactic.command import PluginInstaller
            from run_transaction_cmd import RunTransactionCmd


            # import the transaction data
            installer = PluginInstaller(manifest=manifest_xml)

            jobs = installer.import_data(transaction_path, commit=False)
            transaction_log = jobs[0]

            file_base_dir = "%s/%s" % (base_dir, dirname)

            # run the transaction in its own command
            from run_transaction_cmd import RunTransactionCmd
            run_transaction = RunTransactionCmd(transaction_xml=transaction_log, base_dir=file_base_dir)
            Command.execute_cmd(run_transaction)

            status = "complete"

        # May need special handing
        #except MissingItemException, e:
        #    print "WARNING: Could not run transaction [%s]" % transaction_code
        #    print "Error reported: ", str(e)
        #    search = SearchType.create("sthpw/sync_error")



        except Exception, e:
            print "WARNING: Could not run transaction [%s]" % transaction_code
            print "Error reported: ", str(e)
            status = "error"
            error = str(e)
Example #3
0
    def get_display(my):

        top = my.top
        my.set_as_panel(top)
        top.add_style("width: 500px")

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

        manifest_path = "%s/manifest.xml" % template_dir

        f = open(manifest_path)
        manifest_xml = f.read()
        f.close()

        template = os.path.basename(template_dir)


        button = ActionButtonWdg(title="Delete", tip="Delete template from installation")
        button.add_style("float: right")
        top.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'template': template,
            'cbjs_action': '''

            var template = bvr.template;
            if (!confirm("Are you sure you wish to delete the ["+template+"] template?") ) {
                return;
            }


            var cmd = "tactic.ui.app.ProjectTemplateDeleteCmd";
            var server = TacticServerStub.get();
            spt.app_busy.show("Removing Template", template)

            var kwargs = {
                'template': template
            }
            try {
                server.execute_cmd(cmd, kwargs);

                var top = bvr.src_el.getParent(".spt_project_template_top");
                spt.panel.refresh(top);
            } catch(e) {
                spt.alert(spt.exception.handler(e));
            }



            spt.app_busy.hide();
            '''
        } )



        button = ActionButtonWdg(title="Save As", tip="Save template as file")
        button.add_style("float: right")
        top.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'template_dir': template_dir,
            'cbjs_action': '''
            var applet = spt.Applet.get();
            var dirname = applet.open_file_browser();
            if (!dirname) {
                return;
            }

            var class_name = 'tactic.ui.app.ProjectTemplateDownloadCmd';
            var kwargs = {
                'template_dir': bvr.template_dir
            }
            var server = TacticServerStub.get();
            var ret_val = server.execute_cmd(class_name, kwargs);
            var info = ret_val['info'];
            var filename = info['filename'];

            var env = spt.Environment.get();
            var ticket = env.get_ticket();

            var server = env.get_server_url();
            var url = server + "/assets/_cache/" + ticket + "/" + filename;
            applet.download_file(url, dirname + "/" + filename);

            applet.open_explorer(dirname);

            '''
        } )




        #button = ActionButtonWdg(title="Dump", tip="Create a template from a project")
        #button.add_style("float: right")
        #top.add(button)
        #button.add_behavior( {
        #    'type': 'click_up',
        #    'cbjs_action': '''
        #    '''
        #} )



        info_div = DivWdg()
        top.add(info_div)
        info_div.add_style("padding: 20px")

        info_div.set_unique_id()
        info_div.add_smart_style("spt_none", "font-style", "italic")
        info_div.add_smart_style("spt_none", "opacity", "0.5")

        #project = Project.get()

        # import the transaction data
        from tactic.command import PluginInstaller
        installer = PluginInstaller(manifest=manifest_xml)
        project_path = "%s/%s" % (template_dir, "sthpw_project.spt")
        jobs = installer.import_data(project_path, commit=False)
        project = jobs[0]

        project_code = project.get_code()

        info_div.add("<br/>")
        info_div.add("Template Code: <b>%s</b><br/>" % project_code)
        info_div.add("<br/>")

        info_div.add("Title: <b>%s</b><br/>" % project.get_value("title"))
        info_div.add("<br/>")


        description = project.get_value("description", no_exception=True)
        if not description:
            description = "<span class='spt_none'>None</span>"
        info_div.add("Description: %s<br/>" % description)
        info_div.add("<br/>")


        version = project.get_value("version", no_exception=True)
        if not version:
            version = "<span class='spt_none'>None</span>"
        info_div.add("Version: %s<br/>" % version)
        info_div.add("<br/>")

        status = project.get_value("status", no_exception=True)
        if not status:
            status = "<span class='spt_none'>None</span>"
        info_div.add("Status: %s<br/>" % status )
        info_div.add("<br/>")



        top.add("<span style='opacity: 0.5'>Manifest Path: %s</span>" % manifest_path)


        return top
Example #4
0
    def get_display(self):

        top = self.top
        self.set_as_panel(top)
        top.add_style("width: 500px")

        template_dir = self.kwargs.get("template_dir")

        manifest_path = "%s/manifest.xml" % template_dir

        f = open(manifest_path)
        manifest_xml = f.read()
        f.close()

        template = os.path.basename(template_dir)


        button = ActionButtonWdg(title="Delete", tip="Delete template from installation")
        button.add_style("float: right")
        top.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'template': template,
            'cbjs_action': '''

            var template = bvr.template;
            if (!confirm("Are you sure you wish to delete the ["+template+"] template?") ) {
                return;
            }


            var cmd = "tactic.ui.app.ProjectTemplateDeleteCmd";
            var server = TacticServerStub.get();
            spt.app_busy.show("Removing Template", template)

            var kwargs = {
                'template': template
            }
            try {
                server.execute_cmd(cmd, kwargs);

                var top = bvr.src_el.getParent(".spt_project_template_top");
                spt.panel.refresh(top);
            } catch(e) {
                spt.alert(spt.exception.handler(e));
            }



            spt.app_busy.hide();
            '''
        } )



        button = ActionButtonWdg(title="Save As", tip="Save template as file")
        button.add_style("float: right")
        top.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'template_dir': template_dir,
            'cbjs_action': '''
            var applet = spt.Applet.get();
            var dirname = applet.open_file_browser();
            if (!dirname) {
                return;
            }

            var class_name = 'tactic.ui.app.ProjectTemplateDownloadCmd';
            var kwargs = {
                'template_dir': bvr.template_dir
            }
            var server = TacticServerStub.get();
            var ret_val = server.execute_cmd(class_name, kwargs);
            var info = ret_val['info'];
            var filename = info['filename'];

            var env = spt.Environment.get();
            var ticket = env.get_ticket();

            var server = env.get_server_url();
            var url = server + "/assets/_cache/" + ticket + "/" + filename;
            applet.download_file(url, dirname + "/" + filename);

            applet.open_explorer(dirname);

            '''
        } )




        #button = ActionButtonWdg(title="Dump", tip="Create a template from a project")
        #button.add_style("float: right")
        #top.add(button)
        #button.add_behavior( {
        #    'type': 'click_up',
        #    'cbjs_action': '''
        #    '''
        #} )



        info_div = DivWdg()
        top.add(info_div)
        info_div.add_style("padding: 20px")

        info_div.set_unique_id()
        info_div.add_smart_style("spt_none", "font-style", "italic")
        info_div.add_smart_style("spt_none", "opacity", "0.5")

        #project = Project.get()

        # import the transaction data
        from tactic.command import PluginInstaller
        installer = PluginInstaller(manifest=manifest_xml)
        project_path = "%s/%s" % (template_dir, "sthpw_project.spt")
        jobs = installer.import_data(project_path, commit=False)
        project = jobs[0]

        project_code = project.get_code()

        info_div.add("<br/>")
        info_div.add("Template Code: <b>%s</b><br/>" % project_code)
        info_div.add("<br/>")

        info_div.add("Title: <b>%s</b><br/>" % project.get_value("title"))
        info_div.add("<br/>")


        description = project.get_value("description", no_exception=True)
        if not description:
            description = "<span class='spt_none'>None</span>"
        info_div.add("Description: %s<br/>" % description)
        info_div.add("<br/>")


        version = project.get_value("version", no_exception=True)
        if not version:
            version = "<span class='spt_none'>None</span>"
        info_div.add("Version: %s<br/>" % version)
        info_div.add("<br/>")

        status = project.get_value("status", no_exception=True)
        if not status:
            status = "<span class='spt_none'>None</span>"
        info_div.add("Status: %s<br/>" % status )
        info_div.add("<br/>")



        top.add("<span style='opacity: 0.5'>Manifest Path: %s</span>" % manifest_path)


        return top