def export_template(my): xml = Xml() my.xml = xml xml.create_doc("manifest") manifest_node = xml.get_root_node() # Old implementation. Code is now on the data node xml.set_attribute(manifest_node, "code", my.template_project_code) # dump the notification entries data_node = xml.create_element("data") xml.append_child(manifest_node, data_node) code_node = xml.create_element("code") xml.append_child(data_node, code_node) xml.set_node_value(code_node, my.template_project_code) version = my.kwargs.get("version") or "" version_node = xml.create_element("version") xml.append_child(data_node, version_node) xml.set_node_value(version_node, version) # dump the project entry data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute( data_node, "expression", "@SOBJECT(sthpw/project['code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/project") xml.set_attribute(data_node, "unique", "true") # dump the project_type entry data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute( data_node, "expression", "@SOBJECT(sthpw/project['code','%s'].sthpw/project_type)" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/project_type") xml.set_attribute(data_node, "unique", "true") # dump the schema entry data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute( data_node, "expression", "@SOBJECT(sthpw/schema['code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/schema") xml.set_attribute(data_node, "unique", "true") # find the project template search types namespace = my.project_type if not namespace or namespace == "default": namespace = my.project_code project_search_types = Search.eval( "@GET(sthpw/search_object['namespace','%s'].search_type)" % namespace) #project_types = Search.eval("@GET(sthpw/search_object['namespace','%s'].search_type)" % my.project_code) # just dump the definition for data for search_type in project_search_types: data_node = xml.create_element("search_type") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "code", search_type) search_types = [ "config/custom_script", "config/widget_config", "config/naming", "config/client_trigger", "config/process", "config/trigger", "config/url", #"config/ingest_rule", #"config/ingest_session", ] for search_type in search_types: data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "search_type", search_type) # find the currval st_obj = SearchType.get(search_type) # have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1 seq_id = SearchType.sequence_nextval(search_type) seq_id = SearchType.sequence_currval(search_type) seq_id -= 1 if seq_id > 0: SearchType.sequence_setval(search_type, seq_id) xml.set_attribute(data_node, "seq_max", seq_id) #xml.set_attribute(data_node, "path", "data.spt") # dump the login_groups entries data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute( data_node, "expression", "@SOBJECT(sthpw/login_group['project_code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/login_group") xml.set_attribute(data_node, "unique", "true") # dump the pipelines entries data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute( data_node, "expression", "@SOBJECT(sthpw/pipeline['project_code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/pipeline") xml.set_attribute(data_node, "unique", "true") # dump the notification entries data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute( data_node, "expression", "@SOBJECT(sthpw/notification['project_code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/notification") from plugin import PluginCreator creator = PluginCreator(base_dir=my.base_dir, manifest=xml.to_string(), force=True, version=version) creator.execute() my.zip_path = creator.get_zip_path()
def execute(self): project_code = self.kwargs.get("project_code") transaction_code = self.kwargs.get("transaction_code") login = self.kwargs.get("login") session = self.kwargs.get("session") start_time = session.get("start_time") end_time = session.get("end_time") search_keys = session.get("search_keys") if search_keys != None: if search_keys == '': raise TacticException("No search keys passed in") search_keys = search_keys.split("|") if not search_keys: raise TacticException("No search keys passed in") transactions = Search.get_by_search_keys(search_keys) codes = [x.get_code() for x in transactions] assert len(search_keys) == len(codes) expr = '''@SOBJECT(sthpw/transaction_log['code','in','%s']['@ORDER_BY','code asc'])''' % ("|".join(codes)) else: expr = '''@SOBJECT(sthpw/transaction_log['login','%s']['namespace','%s']['timestamp','>','%s']['timestamp','<','%s']['@ORDER_BY','code asc'])''' % (login, project_code, start_time, end_time) manifest_xml = ''' <manifest code='transaction_log' version='1'> <sobject expression="%s" search_type="sthpw/transaction_log"/> </manifest> ''' % (expr) plugin = SearchType.create("sthpw/plugin") plugin.set_value("code", "transaction_log") plugin.set_value("version", "1.0") creator = PluginCreator(manifest=manifest_xml, plugin=plugin) creator.execute() plugin_path = creator.get_plugin_path() plugin_dir = creator.get_plugin_dir() # find all the logs (again!!!) # FIXME: should get from plugin expr = expr.replace(">", ">") expr = expr.replace("<", "<") logs = Search.eval(expr) asset_dir = Environment.get_asset_dir() for log in logs: transaction_xml = log.get_xml_value("transaction").to_string() cmd = TransactionFilesCmd(transaction_xml=transaction_xml) paths = cmd.execute() for path in paths: rel_path = path.replace(asset_dir, "") rel_path = rel_path.lstrip("/") new_path = "%s/assets/%s" % (plugin_dir, rel_path) dirname = os.path.dirname(new_path) if not os.path.exists(dirname): os.makedirs(dirname) print("adding: [%s]" % new_path) shutil.copy(path, new_path)
def export_template(my): xml = Xml() my.xml = xml xml.create_doc("manifest") manifest_node = xml.get_root_node() # Old implementation. Code is now on the data node xml.set_attribute(manifest_node, "code", my.template_project_code) # dump the notification entries data_node = xml.create_element("data") xml.append_child(manifest_node, data_node) code_node = xml.create_element("code") xml.append_child(data_node, code_node) xml.set_node_value(code_node, my.template_project_code) version = my.kwargs.get("version") or "" version_node = xml.create_element("version") xml.append_child(data_node, version_node) xml.set_node_value(version_node, version) # dump the project entry data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/project['code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/project") xml.set_attribute(data_node, "unique", "true") # dump the project_type entry data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/project['code','%s'].sthpw/project_type)" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/project_type") xml.set_attribute(data_node, "unique", "true") # dump the schema entry data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/schema['code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/schema") xml.set_attribute(data_node, "unique", "true") # find the project template search types namespace = my.project_type if not namespace or namespace == "default": namespace = my.project_code project_search_types = Search.eval("@GET(sthpw/search_object['namespace','%s'].search_type)" % namespace) #project_types = Search.eval("@GET(sthpw/search_object['namespace','%s'].search_type)" % my.project_code) # just dump the definition for data for search_type in project_search_types: data_node = xml.create_element("search_type") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "code", search_type) search_types = [ "config/custom_script", "config/widget_config", "config/naming", "config/client_trigger", "config/process", "config/trigger", "config/url", #"config/ingest_rule", #"config/ingest_session", ] for search_type in search_types: data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "search_type", search_type) # find the currval st_obj = SearchType.get(search_type) # have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1 seq_id = SearchType.sequence_nextval(search_type) seq_id = SearchType.sequence_currval(search_type) seq_id -= 1 if seq_id > 0: SearchType.sequence_setval(search_type, seq_id) xml.set_attribute(data_node, "seq_max", seq_id) #xml.set_attribute(data_node, "path", "data.spt") # dump the login_groups entries data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/login_group['project_code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/login_group") xml.set_attribute(data_node, "unique", "true") # dump the pipelines entries data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/pipeline['project_code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/pipeline") xml.set_attribute(data_node, "unique", "true") # dump the notification entries data_node = xml.create_element("sobject") xml.append_child(manifest_node, data_node) xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/notification['project_code','%s'])" % my.project_code) xml.set_attribute(data_node, "search_type", "sthpw/notification") from plugin import PluginCreator creator = PluginCreator( base_dir=my.base_dir, manifest=xml.to_string(), force=True, version=version ) creator.execute() my.zip_path = creator.get_zip_path()