def execute(self): web = WebContainer.get_web() # get the input names input_names = web.get_form_value( SerialStatusWdg.STATUS_CMD_INPUT).split('|') values = [] for input_name in input_names: value = web.get_form_value(input_name) if value: values.append(web.get_form_value(input_name)) # FIXME: HARDCODED Value for status column!!!! column = "status" for value in values: # get the sobject to be updated search_type, id, status = value.split("|") search = Search(search_type) search.add_id_filter(id) self.sobject = search.get_sobject() status_attr = self.sobject.get_attr(column) cur_status = status_attr.get_current_process() if cur_status == status: continue status_attr.set_status(status) update_column = 'time_update' if update_column in self.sobject.get_attr_names(): self.sobject.set_value(update_column, Sql.get_timestamp_now(), quoted=False) self.sobject.commit() # if this is successful, the store it in the status_log status_log = SObjectFactory.create("sthpw/status_log") status_log.set_value("login", Environment.get_user_name()) status_log.set_value("search_type", search_type) status_log.set_value("search_id", id) #status_log.set_value("status", "%s to %s" % (cur_status, status) ) status_log.commit() status_log.set_value("from_status", cur_status) status_log.set_value("to_status", status) # Call the finaled trigger Trigger.call(self, status)
def create(name, desc, search_type, xml=None, code=None, color=None): '''will only create if it does not exist, otherwise it just updates''' if code: sobject = Pipeline.get_by_code(code) else: sobject = None if sobject == None: #sobject = Pipeline( Pipeline.SEARCH_TYPE ) sobject = SearchType.create(Pipeline.SEARCH_TYPE) else: return sobject if not xml: xml = Xml() xml.create_doc('pipeline') if isinstance(xml, basestring): xml_string = xml xml = Xml() xml.read_string(xml_string) sobject.set_value("pipeline", xml.get_xml()) sobject.set_pipeline(xml.to_string()) sobject.set_value('timestamp', Sql.get_default_timestamp_now(), quoted=False) if code: sobject.set_value('code', code.strip()) sobject.set_value('name', name.strip()) sobject.set_value('search_type', search_type) sobject.set_value('description', desc) if color: sobject.set_value("color", color) sobject.commit() process_names = sobject.get_process_names() for i, process_name in enumerate(process_names): process = SearchType.create("config/process") process.set_value("pipeline_code", sobject.get_code()) process.set_value("process", process_name) process.set_value("sort_order", i) process.set_value("subcontext_options", "(main)") process.commit() return sobject
def get_display(self, widget): """run through the full web app pipeline""" if widget == None: raise WebAppException("No top level widget defined") # add to the access log # FIXME: this does not get committed if there is an exception. The # transaction will back out. access_log_flag = False access_log = None if access_log_flag: access_log = SearchType.create("sthpw/access_log") access_log.set_value("url", "www.yahoo.com") access_log.set_value("start_time", Sql.get_timestamp_now(), quoted=False) access_log.commit() start = time.time() # do a security check on the widget # DEPRECATED widget.check_security() # draw all of the widgets widget = widget.get_display() if widget: Widget.get_display(widget) if access_log_flag: access_log.set_value("end_time", Sql.get_timestamp_now(), quoted=False) duration = time.time() - start duration = float(int(duration * 1000)) / 1000 access_log.set_value("duration", str(duration)) access_log.commit()
def execute(my): web = WebContainer.get_web() # get the input names input_names = web.get_form_value(SerialStatusWdg.STATUS_CMD_INPUT).split('|') values = [] for input_name in input_names: value = web.get_form_value(input_name) if value: values.append(web.get_form_value(input_name)) # FIXME: HARDCODED Value for status column!!!! column = "status" for value in values: # get the sobject to be updated search_type,id,status = value.split("|") search = Search(search_type) search.add_id_filter(id) my.sobject = search.get_sobject() status_attr = my.sobject.get_attr(column) cur_status = status_attr.get_current_process() if cur_status == status: continue status_attr.set_status(status) update_column = 'time_update' if update_column in my.sobject.get_attr_names(): my.sobject.set_value(update_column, Sql.get_timestamp_now(), quoted=False) my.sobject.commit() # if this is successful, the store it in the status_log status_log = SObjectFactory.create("sthpw/status_log") status_log.set_value("login", Environment.get_user_name() ) status_log.set_value("search_type", search_type) status_log.set_value("search_id", id) #status_log.set_value("status", "%s to %s" % (cur_status, status) ) status_log.commit() status_log.set_value("from_status", cur_status) status_log.set_value("to_status", status) # Call the finaled trigger Trigger.call(my, status)
def get_display(my, widget): """run through the full web app pipeline""" if widget == None: raise WebAppException("No top level widget defined") # add to the access log # FIXME: this does not get committed if there is an exception. The # transaction will back out. access_log_flag = False access_log = None if access_log_flag: access_log = SearchType.create("sthpw/access_log") access_log.set_value("url", "www.yahoo.com") access_log.set_value("start_time", Sql.get_timestamp_now(), quoted=False) access_log.commit() start = time.time() # do a security check on the widget # DEPRECATED widget.check_security() # draw all of the widgets widget = widget.get_display() if widget: Widget.get_display(widget) if access_log_flag: access_log.set_value("end_time", Sql.get_timestamp_now(), quoted=False) duration = time.time() - start duration = float(int(duration * 1000)) / 1000 access_log.set_value("duration", str(duration) ) access_log.commit()
def create(pipeline_name, desc, pipe_search_type): '''will only create if it does not exist, otherwise it just updates''' sobject = Pipeline.get_by_name(pipeline_name) if sobject == None: #sobject = Pipeline( Pipeline.SEARCH_TYPE ) sobject = SearchType.create( Pipeline.SEARCH_TYPE ) else: return sobject xml = Xml() xml.create_doc('pipeline') root = xml.get_root_node() #Xml.set_attribute(root, 'type', type) sobject.set_value("pipeline", xml.get_xml()) sobject.set_value('timestamp', Sql.get_default_timestamp_now(), quoted=False ) sobject.set_value('code', pipeline_name) sobject.set_value('search_type', pipe_search_type) sobject.set_value('description', desc) sobject.commit() return sobject
def test_postgres(my, vendor): web = WebContainer.get_web() defaults = DEFAULTS[vendor] default_server = defaults['server'] default_port = defaults['port'] default_user = defaults['user'] default_password = defaults['password'] server = web.get_form_value("server") if not server: server = default_server port = web.get_form_value("port") if not port: port = default_port else: port = int(port) user = web.get_form_value("user") if not user: user = default_user password = web.get_form_value("password") if not password: password = default_password # Need to access remote database create = False impl = DatabaseImpl.get(vendor) exists = impl.database_exists("sthpw", host=server, port=port) if not create: if not exists: my.info['error'] = "Database [sthpw] does not exist. This is required for TACTIC to function." return else: print "Running bootstrap" install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" # create the database and inject the bootstrap data impl.create_database("sthpw", host=server, port=port) cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % (python, install_dir, vendor.lower()) os.system(cmd) from pyasm.search import Sql sql = Sql("sthpw", server, user, password=password, vendor=vendor, port=port) try: # attempt sql.connect() sql.do_query("select id from transaction_log limit 1") except Exception, e: my.info['error'] = "Could not connect to database with (vendor=%s, server=%s, user=%s, port=%s)" % (vendor, server, user, port) my.info['message'] = str(e) print e
def test_postgres(my, vendor): web = WebContainer.get_web() defaults = DEFAULTS[vendor] default_server = defaults['server'] default_port = defaults['port'] default_user = defaults['user'] default_password = defaults['password'] server = web.get_form_value("server") if not server: server = default_server port = web.get_form_value("port") if not port: port = default_port else: port = int(port) user = web.get_form_value("user") if not user: user = default_user password = web.get_form_value("password") if not password: password = default_password # Need to access remote database create = False impl = DatabaseImpl.get(vendor) exists = impl.database_exists("sthpw", host=server, port=port) if not create: if not exists: my.info[ 'error'] = "Database [sthpw] does not exist. This is required for TACTIC to function." return else: print "Running bootstrap" install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" # create the database and inject the bootstrap data impl.create_database("sthpw", host=server, port=port) cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % ( python, install_dir, vendor.lower()) os.system(cmd) from pyasm.search import Sql sql = Sql("sthpw", server, user, password=password, vendor=vendor, port=port) try: # attempt sql.connect() sql.do_query("select id from transaction_log limit 1") except Exception, e: my.info[ 'error'] = "Could not connect to database with (vendor=%s, server=%s, user=%s, port=%s)" % ( vendor, server, user, port) my.info['message'] = str(e) print e
def execute(self): if not self.sobject.is_insert(): # do nothing return project = self.sobject project_code = project.get_code() project_type = project.get_base_type() database = DatabaseImpl.get() # check if database exists print "Creating database '%s' ..." % project_code if database.database_exists(project_code): print "... already exists" else: # create the datbase database.create_database(project_code) # import the appropriate schema database.import_schema(project_code, project_type) # import the appropriate data database.import_default_data(project_code, project_type) # copy files from the default template site_dir = Environment.get_site_dir() install_dir = Environment.get_install_dir() template_dir = "%s/src/tactic_sites/template" % install_dir template_dir = template_dir.replace("\\","/") project_dir = "%s/sites/%s" % (site_dir, project_code) project_dir = project_dir.replace("\\","/") # set the update of the database to current project.set_value("last_db_update", Sql.get_timestamp_now(), quoted=False) project.commit() # copy all of the files from the template to the template directory print "Creating project directories [%s]..." % project_dir if not os.path.exists(template_dir): print "... skipping: template dir [%s] does not exist" % template_dir return if not os.path.exists(project_dir): for root, dirs, files in os.walk(template_dir): root = root.replace("\\","/") # ignore ".svn" if root.find("/.svn") != -1: continue for file in files: # ignore compiled python files if file.endswith(".pyc"): continue old = "%s/%s" % (root, file) new = old.replace(template_dir, project_dir) dirname = os.path.dirname(new) System().makedirs(dirname) shutil.copyfile(old,new) else: print "... skipping. Already exists." print "Done."
def execute(my): error_list = [] from pyasm.biz import Project Project.clear_cache() sthpw_search = Search("sthpw/project") sthpw_search.add_filter('code','sthpw') sthpw_search.set_show_retired(True) sthpw_proj = sthpw_search.get_sobject() search = Search("sthpw/project") if my.project_code: search.add_filter("code", my.project_code) else: #search.add_enum_order_by("type", ['sthpw','prod','game','design','simple', 'unittest']) search.add_enum_order_by("code", ['sthpw']) projects = search.get_sobjects() project_codes = SObject.get_values(projects, 'code') # append sthpw project in case it's retired if 'sthpw' not in project_codes and sthpw_proj: if not my.project_code: projects.insert(0, sthpw_proj) sthpw_proj.reactivate() current_dir = os.getcwd() tmp_dir = Environment.get_tmp_dir() output_file = '%s/upgrade_output.txt' % tmp_dir if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) elif os.path.exists(output_file): os.unlink(output_file) ofile = open(output_file, 'w') import datetime ofile.write('Upgrade Time: %s\n\n' %datetime.datetime.now()) # dynamically generate #sql = DbContainer.get(code) database_type = Sql.get_default_database_type() #if database_type in ['Sqlite', 'MySQL']: if database_type != "PostgreSQL": # general an upgrade import imp namespaces = ['default', 'simple', 'sthpw', 'config'] for namespace in namespaces: if database_type == 'Sqlite': from pyasm.search.upgrade.sqlite import convert_sqlite_upgrade file_path = convert_sqlite_upgrade(namespace) elif database_type == 'MySQL': from pyasm.search.upgrade.mysql import convert_mysql_upgrade file_path = convert_mysql_upgrade(namespace) elif database_type == 'SQLServer': from pyasm.search.upgrade.sqlserver import convert_sqlserver_upgrade file_path = convert_sqlserver_upgrade(namespace) elif database_type == 'Oracle': file_path = convert_oracle_upgrade(namespace) else: raise Exception("Database type not implemented here") (path, name) = os.path.split(file_path) (name, ext) = os.path.splitext(name) (file, filename, data) = imp.find_module(name, [path]) module = imp.load_module(name, file, filename, data) class_name = "%s%sUpgrade" % (database_type,namespace.capitalize()) exec("%s = module.%s" % (class_name, class_name) ) # load all the default modules from pyasm.search.upgrade.project import * for project in projects: code = project.get_code() if code == "sthpw": type = "sthpw" else: type = project.get_type() if not type: type = 'default' if not my.quiet: print project.get_code(), type print "-"*30 # if the project is admin, the just ignore for now if code == 'admin': continue if not project.database_exists(): ofile.write("*" * 80 + '\n') msg = "Project [%s] does not have a database\n"% project.get_code() ofile.write(msg) print msg ofile.write("*" * 80 + '\n\n') continue upgrade = None if database_type != 'PostgreSQL': upgrade_class = "%s%sUpgrade" % (database_type, type.capitalize()) conf_upgrade = eval("%sConfigUpgrade()" % database_type) else: upgrade_class = "%sUpgrade" % type.capitalize() conf_upgrade = eval("ConfigUpgrade()") upgrade = eval("%s()" % upgrade_class) # upgrade config (done for every project but sthpw) conf_upgrade.set_project(project.get_code()) conf_upgrade.set_to_version(my.to_version) conf_upgrade.set_forced(my.is_forced) conf_upgrade.set_quiet(my.quiet) conf_upgrade.set_confirmed(my.is_confirmed) conf_upgrade.execute() # append the errors for each upgrade key = '%s|%s' %(project.get_code(), conf_upgrade.__class__.__name__) error_list.append((conf_upgrade.__class__.__name__, project.get_code(), \ Container.get_seq(key))) # perform the upgrade to the other tables if upgrade: upgrade.set_project(project.get_code() ) upgrade.set_to_version(my.to_version) upgrade.set_forced(my.is_forced) upgrade.set_quiet(my.quiet) upgrade.set_confirmed(my.is_confirmed) #Command.execute_cmd(upgrade) # put each upgrade function in its own transaction # carried out in BaseUpgrade upgrade.execute() # append the errors for each upgrade key = '%s|%s' %(project.get_code(), upgrade.__class__.__name__) error_list.append((upgrade.__class__.__name__, project.get_code(), \ Container.get_seq(key))) from pyasm.search import DatabaseImpl project.set_value("last_db_update", DatabaseImpl.get().get_timestamp_now(), quoted=False) if project.has_value('last_version_update'): last_version = project.get_value('last_version_update') if my.to_version > last_version: project.set_value("last_version_update", my.to_version) else: # it should be getting the upgrade now, redo the search print "Please run upgrade_db.py again, the sthpw db has just been updated" return project.commit(triggers=False) # print the errors for each upgrade for cls_name, project_code, errors in error_list: if not my.quiet: print print "Errors for %s [%s]:" %(project_code, cls_name) ofile.write("Errors for %s [%s]:\n" %(project_code, cls_name)) if not my.quiet: print "*" * 80 ofile.write("*" * 80 + '\n') for func, error in errors: if not my.quiet: print '[%s]' % func print "-" * 70 print error ofile.write('[%s]\n' % func) ofile.write("-" * 70 + '\n') ofile.write('%s\n' %error) ofile.close() if my.quiet: print "Please refer to the upgrade_output.txt file for any upgrade messages." print # handle sthpw database separately. This ensures that the project entry # gets created if none exists. #print "sthpw" #print "-"*30 #upgrade = SthpwUpgrade() #upgrade.set_project("sthpw") #Command.execute_cmd(upgrade) # update the template zip files data_dir = Environment.get_data_dir(manual=False) dest_dir = '%s/templates' %data_dir if os.path.exists(dest_dir): install_dir = Environment.get_install_dir() src_code_template_dir = '%s/src/install/start/templates' %install_dir if os.path.exists(src_code_template_dir): zip_files = os.listdir(src_code_template_dir) io_errors = False for zip_file in zip_files: if not zip_file.endswith(".zip"): continue try: src_file = '%s/%s' %(src_code_template_dir, zip_file) dest_file = '%s/%s' %(dest_dir, zip_file) shutil.copyfile(src_file, dest_file) except IOError, e: print e io_errors = True if not io_errors: print "Default project template files have been updated." else: print "There was a problem copying the default template files to <TACTIC_DATA_DIR>/templates."
def execute(my): if not my.sobject.is_insert(): # do nothing return project = my.sobject project_code = project.get_code() project_type = project.get_base_type() database = DatabaseImpl.get() # check if database exists print "Creating database '%s' ..." % project_code if database.database_exists(project_code): print "... already exists" else: # create the datbase database.create_database(project_code) # import the appropriate schema database.import_schema(project_code, project_type) # import the appropriate data database.import_default_data(project_code, project_type) # copy files from the default template site_dir = Environment.get_site_dir() install_dir = Environment.get_install_dir() template_dir = "%s/src/tactic_sites/template" % install_dir template_dir = template_dir.replace("\\","/") project_dir = "%s/sites/%s" % (site_dir, project_code) project_dir = project_dir.replace("\\","/") # set the update of the database to current project.set_value("last_db_update", Sql.get_timestamp_now(), quoted=False) project.commit() # copy all of the files from the template to the template directory print "Creating project directories [%s]..." % project_dir if not os.path.exists(template_dir): print "... skipping: template dir [%s] does not exist" % template_dir return if not os.path.exists(project_dir): for root, dirs, files in os.walk(template_dir): root = root.replace("\\","/") # ignore ".svn" if root.find("/.svn") != -1: continue for file in files: # ignore compiled python files if file.endswith(".pyc"): continue old = "%s/%s" % (root, file) new = old.replace(template_dir, project_dir) dirname = os.path.dirname(new) System().makedirs(dirname) shutil.copyfile(old,new) else: print "... skipping. Already exists." print "Done."
def execute(my): error_list = [] from pyasm.biz import Project Project.clear_cache() sthpw_search = Search("sthpw/project") sthpw_search.add_filter('code', 'sthpw') sthpw_search.set_show_retired(True) sthpw_proj = sthpw_search.get_sobject() search = Search("sthpw/project") if my.project_code: search.add_filter("code", my.project_code) else: #search.add_enum_order_by("type", ['sthpw','prod','game','design','simple', 'unittest']) search.add_enum_order_by("code", ['sthpw']) projects = search.get_sobjects() project_codes = SObject.get_values(projects, 'code') # append sthpw project in case it's retired if 'sthpw' not in project_codes and sthpw_proj: if not my.project_code: projects.insert(0, sthpw_proj) sthpw_proj.reactivate() current_dir = os.getcwd() tmp_dir = Environment.get_tmp_dir() output_file = '%s/upgrade_output.txt' % tmp_dir if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) elif os.path.exists(output_file): os.unlink(output_file) ofile = open(output_file, 'w') import datetime ofile.write('Upgrade Time: %s\n\n' % datetime.datetime.now()) # dynamically generate #sql = DbContainer.get(code) database_type = Sql.get_default_database_type() #if database_type in ['Sqlite', 'MySQL']: if database_type != "PostgreSQL": # general an upgrade import imp namespaces = ['default', 'simple', 'sthpw', 'config'] for namespace in namespaces: if database_type == 'Sqlite': from pyasm.search.upgrade.sqlite import convert_sqlite_upgrade file_path = convert_sqlite_upgrade(namespace) elif database_type == 'MySQL': from pyasm.search.upgrade.mysql import convert_mysql_upgrade file_path = convert_mysql_upgrade(namespace) elif database_type == 'SQLServer': from pyasm.search.upgrade.sqlserver import convert_sqlserver_upgrade file_path = convert_sqlserver_upgrade(namespace) elif database_type == 'Oracle': file_path = convert_oracle_upgrade(namespace) else: raise Exception("Database type not implemented here") (path, name) = os.path.split(file_path) (name, ext) = os.path.splitext(name) (file, filename, data) = imp.find_module(name, [path]) module = imp.load_module(name, file, filename, data) class_name = "%s%sUpgrade" % (database_type, namespace.capitalize()) exec("%s = module.%s" % (class_name, class_name)) # load all the default modules from pyasm.search.upgrade.project import * for project in projects: code = project.get_code() if code == "sthpw": type = "sthpw" else: type = project.get_type() if not type: type = 'default' if not my.quiet: print project.get_code(), type print "-" * 30 # if the project is admin, the just ignore for now if code == 'admin': continue if not project.database_exists(): ofile.write("*" * 80 + '\n') msg = "Project [%s] does not have a database\n" % project.get_code( ) ofile.write(msg) print msg ofile.write("*" * 80 + '\n\n') continue upgrade = None if database_type != 'PostgreSQL': upgrade_class = "%s%sUpgrade" % (database_type, type.capitalize()) conf_upgrade = eval("%sConfigUpgrade()" % database_type) else: upgrade_class = "%sUpgrade" % type.capitalize() conf_upgrade = eval("ConfigUpgrade()") upgrade = eval("%s()" % upgrade_class) # upgrade config (done for every project but sthpw) conf_upgrade.set_project(project.get_code()) conf_upgrade.set_to_version(my.to_version) conf_upgrade.set_forced(my.is_forced) conf_upgrade.set_quiet(my.quiet) conf_upgrade.set_confirmed(my.is_confirmed) conf_upgrade.execute() # append the errors for each upgrade key = '%s|%s' % (project.get_code(), conf_upgrade.__class__.__name__) error_list.append((conf_upgrade.__class__.__name__, project.get_code(), \ Container.get_seq(key))) # perform the upgrade to the other tables if upgrade: upgrade.set_project(project.get_code()) upgrade.set_to_version(my.to_version) upgrade.set_forced(my.is_forced) upgrade.set_quiet(my.quiet) upgrade.set_confirmed(my.is_confirmed) #Command.execute_cmd(upgrade) # put each upgrade function in its own transaction # carried out in BaseUpgrade upgrade.execute() # append the errors for each upgrade key = '%s|%s' % (project.get_code(), upgrade.__class__.__name__) error_list.append((upgrade.__class__.__name__, project.get_code(), \ Container.get_seq(key))) from pyasm.search import DatabaseImpl project.set_value("last_db_update", DatabaseImpl.get().get_timestamp_now(), quoted=False) if project.has_value('last_version_update'): last_version = project.get_value('last_version_update') if my.to_version > last_version: project.set_value("last_version_update", my.to_version) else: # it should be getting the upgrade now, redo the search print "Please run upgrade_db.py again, the sthpw db has just been updated" return project.commit(triggers=False) # print the errors for each upgrade for cls_name, project_code, errors in error_list: if not my.quiet: print print "Errors for %s [%s]:" % (project_code, cls_name) ofile.write("Errors for %s [%s]:\n" % (project_code, cls_name)) if not my.quiet: print "*" * 80 ofile.write("*" * 80 + '\n') for func, error in errors: if not my.quiet: print '[%s]' % func print "-" * 70 print error ofile.write('[%s]\n' % func) ofile.write("-" * 70 + '\n') ofile.write('%s\n' % error) ofile.close() if my.quiet: print "Please refer to the file [%s] for any upgrade messages." % output_file print # handle sthpw database separately. This ensures that the project entry # gets created if none exists. #print "sthpw" #print "-"*30 #upgrade = SthpwUpgrade() #upgrade.set_project("sthpw") #Command.execute_cmd(upgrade) # update the template zip files data_dir = Environment.get_data_dir(manual=False) dest_dir = '%s/templates' % data_dir if os.path.exists(dest_dir): install_dir = Environment.get_install_dir() src_code_template_dir = '%s/src/install/start/templates' % install_dir if os.path.exists(src_code_template_dir): zip_files = os.listdir(src_code_template_dir) io_errors = False for zip_file in zip_files: if not zip_file.endswith(".zip"): continue try: src_file = '%s/%s' % (src_code_template_dir, zip_file) dest_file = '%s/%s' % (dest_dir, zip_file) shutil.copyfile(src_file, dest_file) except IOError, e: print e io_errors = True if not io_errors: print "Default project template files have been updated." else: print "There was a problem copying the default template files to <TACTIC_DATA_DIR>/templates."