def create(my): project = Project.get_by_code(my.project_code) if project: my.delete() print "Setting up a basic Sample3d project" # create the project create_cmd = CreateProjectCmd( project_code=my.project_code, project_title="Sample 3D") #, project_type="unittest") create_cmd.execute() # install the unittest plugin installer = PluginInstaller(relative_dir="TACTIC/internal/sample3d", verbose=False) installer.execute() # add 30 shots for x in xrange(30): shot = SearchType.create("prod/shot") shot.set_value('name', 'shot%s' % x) shot.set_value('sequence_code', 'SEQ_01') shot.commit(triggers=False) seq = SearchType.create("prod/sequence") seq.set_value('code', 'SEQ_01') seq.commit(triggers=False)
def create(self): project = Project.get_by_code(self.project_code) if project: self.delete() print "Setting up a basic Sample3d project" # create the project create_cmd = CreateProjectCmd(project_code=self.project_code, project_title="Sample 3D") #, project_type="unittest") create_cmd.execute() # install the unittest plugin installer = PluginInstaller(relative_dir="TACTIC/internal/sample3d", verbose=False) installer.execute() # add 30 shots for x in xrange(30): shot = SearchType.create("prod/shot") shot.set_value('name','shot%s'%x) shot.set_value('sequence_code','SEQ_01') shot.commit(triggers=False) if not Search.eval("@SOBJECT(prod/sequence['code','SEQ_01'])"): seq = SearchType.create("prod/sequence") seq.set_value('code','SEQ_01') seq.commit(triggers=False)
def import_schema(plugin_code): from pyasm.search import Transaction transaction = Transaction.get(create=True) install_dir = Environment.get_install_dir() base_dir = Environment.get_plugin_dir() template_dir = "%s/%s" % (base_dir, plugin_code) manifest_path = "%s/manifest.xml" % (template_dir) print "Reading manifest: ", manifest_path xml = Xml() xml.read_file(manifest_path) # create a new project installer = PluginInstaller(base_dir=base_dir, manifest=xml.to_string() ) installer.execute()
def import_schema(plugin_code): from pyasm.search import Transaction transaction = Transaction.get(create=True) install_dir = Environment.get_install_dir() base_dir = Environment.get_plugin_dir() template_dir = "%s/%s" % (base_dir, plugin_code) manifest_path = "%s/manifest.xml" % (template_dir) print "Reading manifest: ", manifest_path xml = Xml() xml.read_file(manifest_path) # create a new project installer = PluginInstaller(base_dir=base_dir, manifest=xml.to_string()) installer.execute()
def create(self): project = Project.get_by_code(self.project_code) if project: self.delete() print "Setting up clean Unittest project" # create the project create_cmd = CreateProjectCmd(project_code=self.project_code, project_title="Unittest") #, project_type="unittest") create_cmd.execute() # install the unittest plugin installer = PluginInstaller(relative_dir="TACTIC/internal/unittest", verbose=False) installer.execute()
def create(my): project = Project.get_by_code(my.project_code) if project: my.delete() print "Setting up a basic Sample3d project" # create the project create_cmd = CreateProjectCmd(project_code=my.project_code, project_title="Sample 3D") #, project_type="unittest") create_cmd.execute() # install the unittest plugin installer = PluginInstaller(relative_dir="TACTIC/internal/sample3d", verbose=False) installer.execute()
def create(my): project = Project.get_by_code(my.project_code) if project: my.delete() print "Setting up clean Unittest project" # create the project create_cmd = CreateProjectCmd(project_code=my.project_code, project_title="Unittest") #, project_type="unittest") create_cmd.execute() # install the unittest plugin installer = PluginInstaller(relative_dir="TACTIC/internal/unittest", verbose=False) installer.execute()
def create_theme(my, theme): # get a built-in plugin plugin_base_dir = Environment.get_plugin_dir() zip_path = "%s/%s.zip" % (plugin_base_dir, theme) manifest_path = "%s/%s/manifest.xml" % (plugin_base_dir, theme) plugin_base_dir2 = Environment.get_builtin_plugin_dir() zip_path2 = "%s/%s.zip" % (plugin_base_dir2, theme) manifest_path2 = "%s/%s/manifest.xml" % (plugin_base_dir2, theme) # install the theme from tactic.command import PluginInstaller if os.path.exists(manifest_path): plugin_dir = "%s/%s" % (plugin_base_dir, theme) installer = PluginInstaller(plugin_dir=plugin_dir, register=True) installer.execute() is_builtin = False elif os.path.exists(zip_path): installer = PluginInstaller(zip_path=zip_path, register=True) installer.execute() is_builtin = False elif os.path.exists(manifest_path2): plugin_dir = "%s/%s" % (plugin_base_dir2, theme) installer = PluginInstaller(plugin_dir=plugin_dir, register=True) installer.execute() is_builtin = True elif os.path.exists(zip_path2): installer = PluginInstaller(zip_path=zip_path2, register=True) installer.execute() is_builtin = True else: raise Exception("Installation error: cannot find %s theme" % theme) from pyasm.biz import PluginUtil if is_builtin: plugin_util = PluginUtil(base_dir=plugin_base_dir2) else: plugin_util = PluginUtil() data = plugin_util.get_plugin_data(theme) # if the theme does not have the url defined (which it likely # shouldn't, but just in case ... search = Search("config/url") search.add_filter("url", "/index") url = search.get_sobject() if not url: index_view = data.get("index_view") if not index_view: # don't use the folder in the theme base = os.path.basename(theme) index_view = "%s/index" % base # set this as the default index search = SearchType.create("config/url") search.set_value("url", "/index") search.set_value( "widget", ''' <element name='index'> <display class='tactic.ui.panel.CustomLayoutWdg'> <view>%s</view> </display> </element> ''' % index_view) search.set_value("description", "Index Page") search.commit()
def create_theme(my, theme): # get a built-in plugin plugin_base_dir = Environment.get_plugin_dir() zip_path = "%s/%s.zip" % (plugin_base_dir, theme) manifest_path = "%s/%s/manifest.xml" % (plugin_base_dir, theme) plugin_base_dir2 = Environment.get_builtin_plugin_dir() zip_path2 = "%s/%s.zip" % (plugin_base_dir2, theme) manifest_path2 = "%s/%s/manifest.xml" % (plugin_base_dir2, theme) # install the theme from tactic.command import PluginInstaller if os.path.exists(manifest_path): plugin_dir = "%s/%s" % (plugin_base_dir, theme) installer = PluginInstaller(plugin_dir=plugin_dir, register=True) installer.execute() is_builtin = False elif os.path.exists(zip_path): installer = PluginInstaller(zip_path=zip_path, register=True) installer.execute() is_builtin = False elif os.path.exists(manifest_path2): plugin_dir = "%s/%s" % (plugin_base_dir2, theme) installer = PluginInstaller(plugin_dir=plugin_dir, register=True) installer.execute() is_builtin = True elif os.path.exists(zip_path2): installer = PluginInstaller(zip_path=zip_path2, register=True) installer.execute() is_builtin = True else: raise Exception("Installation error: cannot find %s theme" % theme) from pyasm.biz import PluginUtil if is_builtin: plugin_util = PluginUtil(base_dir=plugin_base_dir2) else: plugin_util = PluginUtil() data = plugin_util.get_plugin_data(theme) # if the theme does not have the url defined (which it likely # shouldn't, but just in case ... search = Search("config/url") search.add_filter("url", "/index") url = search.get_sobject() if not url: index_view = data.get("index_view") if not index_view: # don't use the folder in the theme base = os.path.basename(theme) index_view = "%s/index" % base # set this as the default index search = SearchType.create("config/url") search.set_value("url", "/index") search.set_value( "widget", """ <element name='index'> <display class='tactic.ui.panel.CustomLayoutWdg'> <view>%s</view> </display> </element> """ % index_view, ) search.set_value("description", "Index Page") search.commit()
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)
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
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)
def execute(my): # This will go to a registered remote server and get the project #server_code = my.kwargs.get("server") #assert server_code ## get the registered server #server = Search.get_by_code("sthpw/sync_server", server_code) #assert server project_code = my.kwargs.get("project_code") assert project_code version = my.kwargs.get("version") if not version: version = "1.0.0" # build the project names template_name = "%s-%s.zip" % (project_code, version) data_name = "%s-data-%s.zip" % (project_code, version) file_name = "%s-files-%s.zip" % (project_code, version) tmp_dir = Environment.get_tmp_dir() to_dir = tmp_dir to_template_path = "%s/%s-%s.zip" % (to_dir, project_code, version) to_data_path = "%s/%s-data-%s.zip" % (to_dir, project_code, version) to_file_path = "%s/%s-files-%s.zip" % (to_dir, project_code, version) #sync_mode = server.get_value("sync_mode") sync_mode = "file" if sync_mode == "file": base_dir = my.kwargs.get("base_dir") from_template_path = "%s/%s" % (base_dir, template_name) from_data_path = "%s/%s" % (base_dir, data_name) from_file_path = "%s/%s" % (base_dir, file_name) to_file_path = from_file_path # copy the files # ???? why are we copying here? shutil.copy(from_template_path, to_template_path) shutil.copy(from_data_path, to_data_path) else: # TEST TEST TEST ticket = server.get_value("server") remote_server = TacticServerStub( protocol='xmlrpc', server=server, project=project_code, #user=user, #password=password, ticket=ticket, ) class_name = 'tactic.ui.sync.SyncCreateTemplateCmd' kwargs = {'project_code': project_code} remote_server.execute_cmd(class_name, kwargs) base_url = "http://%s/assets/_temp/" % server # download and install the files from_template_path = "%s/%s_template-%s.zip" % ( base_url, project_code, version) from_data_path = "%s/%s_data-%s.zip" % (base_url, project_code, version) remote_server.download(from_template_path, to_dir) remote_server.download(from_data_path, to_dir) # This makes the pretty big assumption that this is an official template if not os.path.exists(to_template_path): raise Exception("Path [%s] does not exist" % to_template_path) template_code = project_code try: new_project = False from tactic.command import ProjectTemplateInstallerCmd cmd = ProjectTemplateInstallerCmd(project_code=project_code, path=to_template_path, template_code=template_code, new_project=new_project, version=version) cmd.execute() Project.set_project(project_code) project = Project.get() # NOTE: this avoids breaking on search.py, line 203, where it checks # for tables. The caching mechanism for what tables are in the # database need to be refreshed once a template is imported from pyasm.search import DatabaseImpl, DbContainer DatabaseImpl.clear_table_cache() # import from a plugin kwargs = { #'base_dir': base_dir, #'manifest': my.xml.to_string(), 'code': "%s_data" % project_code, 'zip_path': to_data_path, } from tactic.command import PluginInstaller cmd = PluginInstaller(**kwargs) cmd.execute() # create zip of the project files if os.path.exists(to_file_path): from pyasm.common import ZipUtil zip_util = ZipUtil() asset_dir = Environment.get_asset_dir() to_file_dir = os.path.dirname(to_file_path) zip_util.extract(to_file_path, base_dir=asset_dir) except Exception, e: print "Error: ", str(e) raise
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