class DbConfigSaveCbk(Command): def execute(my): my.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: my.configure_db() my.configure_install() my.configure_mail_services() my.configure_gen_services() my.configure_asset_dir() my.configure_palette() my.configure_security() except Exception, e: raise TacticException('Error in [%s]: %s' % (my.section, e.__str__())) # FIXME: if this all fails, then revert back my.save_config() # after saving the config, test the database my.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) my.restart_program()
def execute(self): self.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: self.configure_db() self.configure_install() self.configure_mail_services() self.configure_gen_services() self.configure_asset_dir() self.configure_palette() self.configure_security() except Exception as e: raise TacticException('Error in [%s]: %s'%(self.section, e.__str__())) # FIXME: if this all fails, then revert back self.save_config() # after saving the config, test the database self.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) self.restart_program()
def execute(my): # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) my.configure_db() my.configure_install() my.configure_services() my.configure_asset_dir() my.configure_palette() # FIXME: if this all fails, then revert back my.save_config() # after saving the config, test the database my.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) my.restart_program()
def get_sqlite_wdg(my): div = DivWdg() div.add_class("spt_db_options") div.add_attr("spt_vendor", "Sqlite") div.add_style("padding: 20px") div.add("Database Folder: ") text = TextInputWdg(name="database/sqlite_db_dir") div.add(text) db_dir = Config.get_value("database", "sqlite_db_dir") if not db_dir: data_dir = Environment.get_data_dir() db_dir = "%s/db" % data_dir text.set_value(db_dir) return div
def copy_start(my): #import pdb; pdb.set_trace() data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) #import pdb; pdb.set_trace() # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir,filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True #import pdb; pdb.set_trace() asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config_path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return
def copy_start(self): data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) # create the dist folder to_dir = "%s/dist" % (data_dir) if not os.path.exists(to_dir): os.makedirs(to_dir) # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir, filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True # insert the plugin path to run get_asset_dir() plugin_dir = Environment.get_plugin_dir() sys.path.insert(0, plugin_dir) asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return
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): 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."