def import_manifest(my, nodes): paths_read = [] for node in nodes: node_name = my.xml.get_node_name(node) if node_name == 'search_type': search_type = my.xml.get_attribute(node, 'code') # implicitly add the entry to the schema table. # Reset the cache every time to ensure that any updates to # the scehma are reflected here. schema = Schema.get(reset_cache=True) xml = schema.get_xml() schema_node = xml.get_node("schema/search_type[@name='%s']" % search_type) parent = xml.get_node("schema") if schema_node == None: schema_node = xml.create_element("search_type") xml.set_attribute(schema_node, "name", search_type) #parent = xml.get_parent(node) xml.append_child(parent, schema_node) schema.set_value('schema', xml.to_string() ) schema.commit() # TODO: connections? path = my.xml.get_attribute(node, "path") if not path: path = "%s.spt" % search_type.replace("/", "_") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue if my.verbose: print "Reading search_type: ", path # NOTE: priviledged knowledge of the order or return values jobs = my.import_data(path, commit=True) paths_read.append(path) if not jobs: continue search_type_obj = jobs[0] if len(jobs) == 1: # only the search type was defined table = None else: table = jobs[1] try: # check to see if the search type already exists search_type_chk = SearchType.get(search_type) if search_type_chk: if my.verbose: print 'WARNING: Search Type [%s] is already registered' % search_type_chk.get_value("search_type") else: search_type_obj.commit() except SearchException, e: if e.__str__().find('not registered') != -1: search_type_obj.commit() # check if table exists has_table = False if has_table: if my.verbose: print 'WARNING: Table [%s] already exists' elif table: #print table.get_statement() if table: database = table.get_database() table_name = table.get_table() TableUndo.log(search_type, database, table_name) elif node_name == 'sobject': path = my.xml.get_attribute(node, "path") search_type = my.xml.get_attribute(node, "search_type") seq_max = my.xml.get_attribute(node, "seq_max") try: if seq_max: seq_max = int(seq_max) except ValueError: seq_max = 0 if not path: if search_type: path = "%s.spt" % search_type.replace("/","_") if not path: raise TacticException("No path specified") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue unique = my.xml.get_attribute(node, "unique") if unique == 'true': unique = True else: unique = False if my.verbose: print "Reading: ", path # jobs doesn't matter for sobject node jobs = my.import_data(path, unique=unique) # reset it in case it needs to execute a PYTHON tag right after Schema.get(reset_cache=True) # compare sequence st_obj = SearchType.get(search_type) SearchType.sequence_nextval(search_type) cur_seq_id = SearchType.sequence_currval(search_type) sql = DbContainer.get("sthpw") if seq_max > 0 and seq_max > cur_seq_id: # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: SearchType.sequence_setval(search_type, seq_max) else: cur_seq_id -= 1 # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: # this is a db requirement if cur_seq_id > 0: SearchType.sequence_setval(search_type, cur_seq_id) paths_read.append(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()
def import_manifest(my, nodes): paths_read = [] for node in nodes: node_name = my.xml.get_node_name(node) if node_name == 'search_type': search_type = my.xml.get_attribute(node, 'code') # implicitly add the entry to the schema table. # Reset the cache every time to ensure that any updates to # the scehma are reflected here. schema = Schema.get(reset_cache=True) xml = schema.get_xml() schema_node = xml.get_node("schema/search_type[@name='%s']" % search_type) parent = xml.get_node("schema") if schema_node == None: schema_node = xml.create_element("search_type") xml.set_attribute(schema_node, "name", search_type) #parent = xml.get_parent(node) xml.append_child(parent, schema_node) schema.set_value('schema', xml.to_string() ) schema.commit() # TODO: connections? path = my.xml.get_attribute(node, "path") if not path: path = "%s.spt" % search_type.replace("/", "_") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue if my.verbose: print "Reading search_type: ", path # NOTE: priviledged knowledge of the order or return values jobs = my.import_data(path, commit=True) paths_read.append(path) if not jobs: continue search_type_obj = jobs[0] if len(jobs) == 1: # only the search type was defined table = None else: table = jobs[1] try: # check to see if the search type already exists search_type_chk = SearchType.get(search_type) if search_type_chk: if my.verbose: print 'WARNING: Search Type [%s] is already registered' % search_type_chk.get_value("search_type") else: search_type_obj.commit() except SearchException, e: if e.__str__().find('not registered') != -1: search_type_obj.commit() # check if table exists has_table = False if has_table: if my.verbose: print 'WARNING: Table [%s] already exists' elif table: #print table.get_statement() if table: database = table.get_database() table_name = table.get_table() TableUndo.log(search_type, database, table_name) elif node_name == 'sobject': path = my.xml.get_attribute(node, "path") search_type = my.xml.get_attribute(node, "search_type") seq_max = my.xml.get_attribute(node, "seq_max") try: if seq_max: seq_max = int(seq_max) except ValueError: seq_max = 0 if not path: if search_type: path = "%s.spt" % search_type.replace("/","_") if not path: raise TacticException("No path specified") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue unique = my.xml.get_attribute(node, "unique") if unique == 'true': unique = True else: unique = False if my.verbose: print "Reading: ", path # jobs doesn't matter for sobject node jobs = my.import_data(path, unique=unique) # compare sequence st_obj = SearchType.get(search_type) SearchType.sequence_nextval(search_type) cur_seq_id = SearchType.sequence_currval(search_type) sql = DbContainer.get("sthpw") if seq_max > 0 and seq_max > cur_seq_id: # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: SearchType.sequence_setval(search_type, seq_max) else: cur_seq_id -= 1 # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: # this is a db requirement if cur_seq_id > 0: SearchType.sequence_setval(search_type, cur_seq_id) paths_read.append(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()