def _test_cache(self): from pyasm.common import Config Config.set_value("security", "mode", "cache", no_exception=True) #Config.set_value("security", "authenticate_class", "pyasm.security.authenticate_test.AutocreateAuthenticate", no_exception=True) Config.set_value("security", "authenticate_class", "pyasm.security.mms_authenticate.MMSAuthenticate", no_exception=True) mode = Config.get_value("security", "authenticate_class", use_cache=False) mode = Config.get_value("security", "mode", use_cache=False) self.assertEquals(mode, "cache") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() self.assertEquals(None, login) from pyasm.search import Transaction transaction = Transaction.get(create=True) transaction.start() self.security.login_user("foofoo", "wow") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() self.assertNotEquals(None, login)
def execute(self): # save prefix local_prefix = self.get_value("local_prefix") self.server_prefix = Config.get_value("install", "server") if not local_prefix and not self.server_prefix: raise TacticException("Cannot have empty local server prefix") if local_prefix and local_prefix != self.server_prefix: Config.set_value("install", "server", local_prefix) Config.save_config() self.project_code = self.get_value("project") if not self.project_code: self.project_code = Project.get_project_code() # create a share share = SearchType.create("sthpw/sync_server") self.handle_info(share) self.handle_sync_mode(share) share.commit()
def _test_cache(my): from pyasm.common import Config Config.set_value("security", "mode", "cache", no_exception=True) #Config.set_value("security", "authenticate_class", "pyasm.security.authenticate_test.AutocreateAuthenticate", no_exception=True) Config.set_value("security", "authenticate_class", "pyasm.security.mms_authenticate.MMSAuthenticate", no_exception=True) mode = Config.get_value("security", "authenticate_class", use_cache=False) mode = Config.get_value("security", "mode", use_cache=False) my.assertEquals(mode, "cache") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() my.assertEquals(None, login) from pyasm.search import Transaction transaction = Transaction.get(create=True) transaction.start() my.security.login_user("foofoo", "wow") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() my.assertNotEquals(None, login)
def _test_base_dir_alias(my): Config.set_value( "checkin", "asset_base_dir", { 'default': '/tmp/tactic/default', 'alias': '/tmp/tactic/alias', 'alias2': '/tmp/tactic/alias2', }) asset_dict = Environment.get_asset_dirs() default_dir = asset_dict.get("default") my.assertEquals("/tmp/tactic/default", default_dir) aliases = asset_dict.keys() # "plugins" is assumed in some branch if 'plugins' in aliases: my.assertEquals(4, len(aliases)) else: my.assertEquals(3, len(aliases)) my.assertNotEquals(None, "alias" in aliases) # create a naming naming = SearchType.create("config/naming") naming.set_value("search_type", "unittest/person") naming.set_value("context", "alias") naming.set_value("dir_naming", "alias") naming.set_value("file_naming", "text.txt") naming.set_value("base_dir_alias", "alias") naming.commit() # create 2nd naming where naming = SearchType.create("config/naming") naming.set_value("search_type", "unittest/person") naming.set_value("context", "alias2") naming.set_value("dir_naming", "alias2") naming.set_value("base_dir_alias", "alias2") naming.set_value("file_naming", "text.txt") naming.set_value("checkin_type", "auto") naming.commit() my.clear_naming() # create a new test.txt file for context in ['alias', 'alias2']: file_path = "./test.txt" file = open(file_path, 'w') file.write("whatever") file.close() checkin = FileCheckin(my.person, file_path, context=context) checkin.execute() snapshot = checkin.get_snapshot() lib_dir = snapshot.get_lib_dir() expected = "/tmp/tactic/%s/%s" % (context, context) my.assertEquals(expected, lib_dir) path = "%s/text.txt" % (lib_dir) exists = os.path.exists(path) my.assertEquals(True, exists)
def _test_base_dir_alias(my): Config.set_value("checkin", "asset_base_dir", { 'default': '/tmp/tactic/default', 'alias': '/tmp/tactic/alias', 'alias2': '/tmp/tactic/alias2', }); asset_dict = Environment.get_asset_dirs() default_dir = asset_dict.get("default") my.assertEquals( "/tmp/tactic/default", default_dir) aliases = asset_dict.keys() # "plugins" is assumed in some branch if 'plugins' in aliases: my.assertEquals( 4, len(aliases)) else: my.assertEquals( 3, len(aliases)) my.assertNotEquals( None, "alias" in aliases ) # create a naming naming = SearchType.create("config/naming") naming.set_value("search_type", "unittest/person") naming.set_value("context", "alias") naming.set_value("dir_naming", "alias") naming.set_value("file_naming", "text.txt") naming.set_value("base_dir_alias", "alias") naming.commit() # create 2nd naming where naming = SearchType.create("config/naming") naming.set_value("search_type", "unittest/person") naming.set_value("context", "alias2") naming.set_value("dir_naming", "alias2") naming.set_value("base_dir_alias", "alias2") naming.set_value("file_naming", "text.txt") naming.set_value("checkin_type", "auto") naming.commit() my.clear_naming() # create a new test.txt file for context in ['alias', 'alias2']: file_path = "./test.txt" file = open(file_path, 'w') file.write("whatever") file.close() checkin = FileCheckin(my.person, file_path, context=context) checkin.execute() snapshot = checkin.get_snapshot() lib_dir = snapshot.get_lib_dir() expected = "/tmp/tactic/%s/%s" % (context, context) my.assertEquals(expected, lib_dir) path = "%s/text.txt" % (lib_dir) exists = os.path.exists(path) my.assertEquals(True, exists)
def configure_palette(my): web = WebContainer.get_web() palette = web.get_form_value("look/palette") if palette: Config.set_value("look", "palette", palette) else: Config.set_value("look", "palette", "")
def configure_palette(my): my.section = 'Look and Feel' web = WebContainer.get_web() palette = web.get_form_value("look/palette") if palette: Config.set_value("look", "palette", palette) else: Config.set_value("look", "palette", "")
def configure_services(my): web = WebContainer.get_web() options = ['server', '_user', '_password', '_port', '_tls_enabled','_sender_disabled'] for option in options: server = web.get_form_value("services/mail%s" %option) if server: Config.set_value("services", "mail%s" %option, server) else: #Config.remove("services", "mail%s"%option) Config.set_value("services", "mail%s"%option, "")
def configure_gen_services(my): my.section = 'Services' web = WebContainer.get_web() options = ['process_count', 'process_time_alive', 'thread_count', 'python_path','rsync'] for option in options: value = web.get_form_value("services/%s" %option) if value: Config.set_value("services", option, value) else: Config.set_value("services", option, "")
def configure_security(my): my.section = 'Security' web = WebContainer.get_web() options = ['allow_guest','ticket_expiry','authenticate_mode', 'authenticate_class','authenticate_version','auto_create_user', 'api_require_password','api_password','max_login_attempt','account_logout_duration'] for option in options: security_value = web.get_form_value("security/%s" %option) if security_value: Config.set_value("security", option, security_value) else: Config.set_value("security", option, "")
def configure_mail_services(my): my.section = 'Mail Server' web = WebContainer.get_web() options = [ 'server', '_user', '_password', '_port', '_tls_enabled', '_sender_disabled' ] for option in options: server = web.get_form_value("services/mail%s" % option) if server: Config.set_value("services", "mail%s" % option, server) else: #Config.remove("services", "mail%s"%option) Config.set_value("services", "mail%s" % option, "")
def configure_gen_services(my): my.section = 'Services' web = WebContainer.get_web() options = [ 'process_count', 'process_time_alive', 'thread_count', 'python_path' ] for option in options: value = web.get_form_value("services/%s" % option) if value: Config.set_value("services", option, value) else: Config.set_value("services", option, "")
def configure_security(my): my.section = 'Security' web = WebContainer.get_web() options = [ 'allow_guest', 'ticket_expiry', 'authenticate_mode', 'authenticate_class', 'authenticate_version', 'auto_create_user', 'api_require_password', 'api_password', 'max_login_attempt', 'account_logout_duration' ] for option in options: security_value = web.get_form_value("security/%s" % option) if security_value: Config.set_value("security", option, security_value) else: Config.set_value("security", option, "")
def _test_autocreate(my): from pyasm.common import Config Config.set_value("security", "mode", "autocreate", no_exception=True) Config.set_value( "security", "authenticate_class", "pyasm.security.authenticate_test.AutocreateAuthenticate", no_exception=True) mode = Config.get_value("security", "mode", use_cache=False) my.assertEquals(mode, "autocreate") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() my.assertEquals(None, login) from pyasm.search import Transaction transaction = Transaction.get(create=True) transaction.start() my.security.login_user("foofoo", "wow") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() my.assertNotEquals(None, login) email = login.get_value("email") my.assertEquals("*****@*****.**", email) transaction.rollback() # after rollback, this user should not exist search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() my.assertEquals(None, login)
def _test_autocreate(self): from pyasm.common import Config Config.set_value("security", "mode", "autocreate", no_exception=True) Config.set_value("security", "authenticate_class", "pyasm.security.authenticate_test.AutocreateAuthenticate", no_exception=True) mode = Config.get_value("security", "mode", use_cache=False) self.assertEquals(mode, "autocreate") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() self.assertEquals(None, login) from pyasm.search import Transaction transaction = Transaction.get(create=True) transaction.start() self.security.login_user("foofoo", "wow") # verify that the user exists in the database search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() self.assertNotEquals(None, login) email = login.get_value("email") self.assertEquals("*****@*****.**", email) transaction.rollback() # after rollback, this user should not exist search = Search("sthpw/login") search.add_filter("login", "foofoo") login = search.get_sobject() self.assertEquals(None, login)
def configure_asset_dir(my): my.section = 'Asset Management Setup' web = WebContainer.get_web() keys = web.get_form_keys() option_list = [] for key in keys: if key.startswith('checkin/'): key = key.replace('checkin/', '') option_list.append(key) asset_dir = web.get_form_value("checkin/asset_base_dir") if asset_dir != None: if asset_dir and not os.path.exists(asset_dir): os.makedirs(asset_dir) Config.set_value("checkin", "asset_base_dir", asset_dir) if 'asset_base_dir' in option_list: option_list.remove('asset_base_dir') for item_dir in option_list: item_in_list = web.get_form_value('checkin/%s' % item_dir) if item_in_list: Config.set_value("checkin", '%s' % item_dir, item_in_list) else: Config.set_value("checkin", '%s' % item_dir, "")
def configure_asset_dir(my): web = WebContainer.get_web() keys = web.get_form_keys() option_list = [] for key in keys: if key.startswith('checkin/'): key = key.replace('checkin/','') option_list.append(key) asset_dir = web.get_form_value("checkin/asset_base_dir") if asset_dir != None: if asset_dir and not os.path.exists(asset_dir): os.makedirs(asset_dir) Config.set_value("checkin", "asset_base_dir", asset_dir) if 'asset_base_dir' in option_list: option_list.remove('asset_base_dir') for item_dir in option_list: item_in_list=web.get_form_value('checkin/%s'%item_dir) if item_in_list: Config.set_value("checkin", '%s'%item_dir, item_in_list) else: Config.set_value("checkin", '%s'%item_dir, "")
def execute(self): web = WebContainer.get_web() xml_string = Config.get_xml_data().to_string() keys = web.get_form_keys() for key in keys: value = web.get_form_value(key) is_config_key = key.find("/") != -1 if key == "database/password": self.handle_password() elif is_config_key: module_name, key = key.split("/") Config.set_value(module_name, key, value) xml_string2 = Config.get_xml_data().to_string() if xml_string2 != xml_string: Config.save_config()
def execute(self): web = WebContainer.get_web() xml_string = Config.get_xml_data().to_string() keys = web.get_form_keys() for key in keys: value = web.get_form_value(key) is_config_key = key.find("/") != -1 if key == "database/password": self.handle_password() elif is_config_key: module_name, key = key.split("/") Config.set_value(module_name, key, value ) xml_string2 = Config.get_xml_data().to_string() if xml_string2 != xml_string: Config.save_config()
def execute(my): # save prefix local_prefix = my.get_value("local_prefix") my.server_prefix = Config.get_value("install", "server") if not local_prefix and not my.server_prefix: raise TacticException("Cannot have empty local server prefix") if local_prefix and local_prefix != my.server_prefix: Config.set_value("install", "server", local_prefix) Config.save_config() my.project_code = my.get_value("project") if not my.project_code: my.project_code = Project.get_project_code() # create a share share = SearchType.create("sthpw/sync_server") my.handle_info(share) my.handle_sync_mode(share) share.commit()
def configure_install(my): web = WebContainer.get_web() default_project = web.get_form_value("install/default_project") tmp_dir = web.get_form_value("install/tmp_dir") if tmp_dir: Config.set_value("install", "tmp_dir", tmp_dir) else: Config.set_value("install", "tmp_dir", '') if default_project: Config.set_value("install", "default_project", default_project) else: Config.remove("install", "default_project")
def configure_install(my): my.section = 'Installation' web = WebContainer.get_web() default_project = web.get_form_value("install/default_project") tmp_dir = web.get_form_value("install/tmp_dir") if default_project: Config.set_value("install", "default_project", default_project) else: Config.remove("install", "default_project") if tmp_dir: Config.set_value("install", "tmp_dir", tmp_dir) else: Config.set_value("install", "tmp_dir", '')
import os import tacticenv from pyasm.common import Config from pyasm.search import DbPasswordUtil DbPasswordUtil.set_password('') Config.set_value("database", "server", os.environ['TACTIC_POSTGRES_PORT_5432_TCP_ADDR']) Config.save_config()
def execute(self): project_code = self.kwargs.get('project_code') project_title = self.kwargs.get('project_title') project_type = self.kwargs.get('project_type') project_description = self.kwargs.get("description") if not project_type: project_type = "simple" is_template = self.kwargs.get('is_template') project_theme = self.kwargs.get('project_theme') use_default_side_bar = self.kwargs.get('use_default_side_bar') if use_default_side_bar in [False, 'false']: use_default_side_bar = False else: use_default_side_bar = True assert project_code assert project_type if project_type: # check to see if it exists search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: # just create a default one in this case if it is named # after the project code if not is_template and project_type == project_code: project_type = 'default' # create a new project type search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: project_type_sobj = SearchType.create("sthpw/project_type") project_type_sobj.set_value("code", project_type) project_type_sobj.set_value("type", "simple") project_type_sobj.commit() # set the current project to Admin Project.set_project("admin") # create a new project sobject project = SearchType.create("sthpw/project") project.set_value("code", project_code) project.set_value("title", project_title) project.set_value("type", project_type) if project_description: project.set_value("description", project_description) # set the update of the database to current (this is obsolete) #project.set_value("last_db_update", "now()") project.set_value("last_version_update", "2.5.0.v01") if is_template in ['true', True, 'True']: project.set_value("is_template", True) else: project.set_value("is_template", False) if project_type != "default": category = Common.get_display_title(project_type) project.set_value("category", category) project.commit() # if there is an image, check it in upload_path = self.kwargs.get("project_image_path") if upload_path: if not os.path.exists(upload_path): raise TacticException( "Cannot find upload image for project [%s]" % upload_path) file_type = 'main' file_paths = [upload_path] file_types = [file_type] source_paths = [upload_path] from pyasm.biz import IconCreator if os.path.isfile(upload_path): icon_creator = IconCreator(upload_path) icon_creator.execute() web_path = icon_creator.get_web_path() icon_path = icon_creator.get_icon_path() if web_path: file_paths = [upload_path, web_path, icon_path] file_types = [file_type, 'web', 'icon'] from pyasm.checkin import FileCheckin checkin = FileCheckin(project, context='icon', file_paths=file_paths, file_types=file_types) checkin.execute() # find project's base_type base_type = project.get_base_type() if not base_type and project_type == 'unittest': base_type = 'unittest' elif not base_type: base_type = 'simple' # get the database for this project db_resource = project.get_project_db_resource() database = db_resource.get_database_impl() #database = DatabaseImpl.get() database_type = database.get_database_type() if database_type == 'Oracle': raise TacticException( "Creation of project is not supported. Please create manually") # creating project database print "Creating database '%s' ..." % project_code try: # create the datbase database.create_database(db_resource) except Exception as e: print str(e) print "WARNING: Error creating database [%s]" % project_code # import the appropriate schema with config first database.import_schema(db_resource, base_type) self.create_schema(project_code) # before we upgrade, we have to commit the transaction # This is because upgrade actually run as separate processes # so if not commit has been made, the tables from importing the # schema will not have existed yet DbContainer.commit_thread_sql() self.upgrade() # import the appropriate data database.import_default_data(db_resource, base_type) # import default links if use_default_side_bar: self.import_default_side_bar() # create specified stypes self.create_search_types() # create theme if project_theme: self.create_theme(project_theme) # set as main project is_main_project = self.kwargs.get("is_main_project") if is_main_project in [True, 'true', 'on']: Config.set_value("install", "default_project", project_code) Config.save_config() Config.reload_config() # initiate the DbContainer DbContainer.get('sthpw') self.info['result'] = "Finished creating project [%s]." % project_code print "Done."
def configure_db(my): web = WebContainer.get_web() vendor = web.get_form_value("database/vendor") if vendor == 'Sqlite': # take the current files and copy them to the database folder db_dir = web.get_form_value("database/sqlite_db_dir") if not db_dir: raise TacticException("No Folder configured for Sqlite Database") if not os.path.exists(db_dir): os.makedirs(db_dir) # check to see if the sthpw database is in this folder sthpw_path = "%s/sthpw.db" % (db_dir) if not os.path.exists(sthpw_path): # copy the default database over install_dir = Environment.get_install_dir() template_db = "%s/src/install/start/db/sthpw.db" % install_dir shutil.copy(template_db, db_dir) Config.set_value("database", "sqlite_db_dir", db_dir) Config.remove("database", "server") Config.remove("database", "port") Config.remove("database", "user") Config.remove("database", "password") else: defaults = DEFAULTS[vendor] default_server = defaults['server'] default_port = defaults['port'] default_user = defaults['user'] default_password = defaults['password'] Config.remove("database", "sqlite_db_dir") # get the info 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 if server: Config.set_value("database", "server", server) else: #Config.remove("database", "server") Config.set_value("database", "server", "") if port: Config.set_value("database", "port", port) else: #Config.remove("database", "port") Config.set_value("database", "port", "") if user: Config.set_value("database", "user", user) else: #Config.remove("database", "user") Config.set_value("database", "user", "") if password: Config.set_value("database", "password", password) else: Config.set_value("database", "password", "") #Config.remove("database", "password") # save the database Config.set_value("database", "vendor", vendor)
class CreateProjectCmd(Command): def is_undoable(cls): return False is_undoable = classmethod(is_undoable) def get_title(my): return "Create Project" def get_args_keys(my): return { 'project_code': 'code of the new project', 'project_title': 'title of the new project', 'project_type': 'determines the type of project which specifies the initial schema and the naming conventions', #'copy_pipelines': 'flag to copy template site pipelines to project' } def check(my): project_code = my.kwargs.get('project_code') regexs = '^\d|\W' m = re.search(r'%s' % regexs, project_code) if m: if isinstance(project_code, unicode): project_code = project_code.encode('utf-8') else: project_code = unicode(project_code).encode('utf-8') raise TacticException( '<project_code> [%s] cannot contain special characters or start with a number.' % project_code) # check to see if this project already exists test_project = Project.get_by_code(project_code) if test_project: if test_project.get_value('s_status') == 'retired': raise TacticException( 'Project with code [%s] already exists but is retired.' % project_code) else: raise TacticException( 'Project with code [%s] already exists.' % project_code) return True def execute(my): project_code = my.kwargs.get('project_code') project_title = my.kwargs.get('project_title') project_type = my.kwargs.get('project_type') if not project_type: project_type = "simple" is_template = my.kwargs.get('is_template') project_theme = my.kwargs.get('project_theme') use_default_side_bar = my.kwargs.get('use_default_side_bar') if use_default_side_bar in [False, 'false']: use_default_side_bar = False else: use_default_side_bar = True assert project_code assert project_type if project_type: # check to see if it exists search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: # just create a default one in this case if it is named # after the project code if not is_template and project_type == project_code: project_type = 'default' # create a new project type search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: project_type_sobj = SearchType.create("sthpw/project_type") project_type_sobj.set_value("code", project_type) project_type_sobj.set_value("type", "simple") project_type_sobj.commit() # set the current project to Admin Project.set_project("admin") # create a new project sobject project = SearchType.create("sthpw/project") project.set_value("code", project_code) project.set_value("title", project_title) project.set_value("type", project_type) # set the update of the database to current (this is obsolete) #project.set_value("last_db_update", "now()") project.set_value("last_version_update", "2.5.0.v01") if is_template in ['true', True, 'True']: project.set_value("is_template", True) else: project.set_value("is_template", False) if project_type != "default": category = Common.get_display_title(project_type) project.set_value("category", category) project.commit() # if there is an image, check it in upload_path = my.kwargs.get("project_image_path") if upload_path: if not os.path.exists(upload_path): raise TacticException( "Cannot find upload image for project [%s]" % upload_path) file_type = 'main' file_paths = [upload_path] file_types = [file_type] source_paths = [upload_path] from pyasm.biz import IconCreator if os.path.isfile(upload_path): icon_creator = IconCreator(upload_path) icon_creator.execute() web_path = icon_creator.get_web_path() icon_path = icon_creator.get_icon_path() if web_path: file_paths = [upload_path, web_path, icon_path] file_types = [file_type, 'web', 'icon'] from pyasm.checkin import FileCheckin checkin = FileCheckin(project, context='icon', file_paths=file_paths, file_types=file_types) checkin.execute() # find project's base_type base_type = project.get_base_type() if not base_type and project_type == 'unittest': base_type = 'unittest' elif not base_type: base_type = 'simple' # get the database for this project db_resource = project.get_project_db_resource() database = db_resource.get_database_impl() #database = DatabaseImpl.get() database_type = database.get_database_type() if database_type == 'Oracle': raise TacticException( "Creation of project is not supported. Please create manually") # creating project database print "Creating database '%s' ..." % project_code try: # create the datbase database.create_database(db_resource) except Exception, e: print str(e) print "WARNING: Error creating database [%s]" % project_code # import the appropriate schema with config first database.import_schema(db_resource, base_type) my.create_schema(project_code) # before we upgrade, we have to commit the transaction # This is because upgrade actually run as separate processes # so if not commit has been made, the tables from importing the # schema will not have existed yet DbContainer.commit_thread_sql() my.upgrade() # import the appropriate data database.import_default_data(db_resource, base_type) # import default links if use_default_side_bar: my.import_default_side_bar() # create specified stypes my.create_search_types() # create theme if project_theme: my.create_theme(project_theme) # set as main project is_main_project = my.kwargs.get("is_main_project") if is_main_project in [True, 'true', 'on']: Config.set_value("install", "default_project", project_code) Config.save_config() Config.reload_config() # initiate the DbContainer DbContainer.get('sthpw') my.info['result'] = "Finished creating project [%s]." % project_code print "Done."
def ask_questions(my): # set vendor default_vendor = Config.get_value("database", "vendor") print print "Please enter the database vendor (PostgreSQL or Oracle):" print while 1: if not default_vendor: default_vendor = "PostgreSQL" vendor = raw_input("(%s) -> " % default_vendor) if not vendor: vendor = default_vendor print if vendor in ['PostgreSQL', 'Oracle']: break else: print "ERROR: Vendor must one of 'PostgreSQL' or 'Oracle'" print # set server default_server = Config.get_value("database", "server") if not default_server: default_server = "localhost" print print "Please enter database server hostname or IP address:" print server = raw_input("(%s) -> " % default_server) if not server: server = default_server print # set the user default_user = Config.get_value("database", "user") if not default_user: default_user = "******" print print "Please enter user name accessing the database:" if vendor == "Oracle": print " (To access Oracle using schema names, type '__EMPTY__')" print user = raw_input("(%s) -> " % default_user) if not user: user = default_user print # set password from pyasm.search import DbPasswordUtil current_password = DbPasswordUtil.get_password() password = 0 password2 = 1 print print "Please enter database password:"******" (ENTER to keep password, '__EMPTY__' for empty password)" import getpass while password != password2: print password = getpass.getpass("Enter Password -> ") if password: password2 = getpass.getpass("Confirm Password -> ") else: password = current_password password2 = password break print if password == password2: break else: print "ERROR: Passwords do not match" # Summary: print print "Vendor: [%s]" % vendor print "Server: [%s]" % server print "User: [%s]" % user print ok = raw_input("Save to config (N/y) -> ") if ok.lower() != "y": print "Aborted" return # save the info from pyasm.search import DbPasswordUtil DbPasswordUtil.set_password(password) Config.set_value("database", "vendor", vendor) Config.set_value("database", "server", server) if user == "__EMPTY__": user = "" Config.set_value("database", "user", user) Config.save_config() path = Config.get_config_path() print print "Saved new database information to [%s]. Please restart TACTIC for the changes to take effect" % path print '''
def execute(self): project_code = self.kwargs.get('project_code') project_title = self.kwargs.get('project_title') project_type = self.kwargs.get('project_type') project_description = self.kwargs.get("description") if not project_type: project_type = "simple" is_template = self.kwargs.get('is_template') project_theme = self.kwargs.get('project_theme') use_default_side_bar = self.kwargs.get('use_default_side_bar') if use_default_side_bar in [False, 'false']: use_default_side_bar = False else: use_default_side_bar = True assert project_code assert project_type if project_type: # check to see if it exists search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: # just create a default one in this case if it is named # after the project code if not is_template and project_type == project_code: project_type = 'default' # create a new project type search = Search("sthpw/project_type") search.add_filter("code", project_type) project_type_sobj = search.get_sobject() if not project_type_sobj: project_type_sobj = SearchType.create("sthpw/project_type") project_type_sobj.set_value("code", project_type) project_type_sobj.set_value("type", "simple") project_type_sobj.commit() # set the current project to Admin Project.set_project("admin") # create a new project sobject project = SearchType.create("sthpw/project") project.set_value("code", project_code) project.set_value("title", project_title) project.set_value("type", project_type) if project_description: project.set_value("description", project_description) # set the update of the database to current (this is obsolete) #project.set_value("last_db_update", "now()") project.set_value("last_version_update", "2.5.0.v01") if is_template in ['true', True, 'True']: project.set_value("is_template", True) else: project.set_value("is_template", False) if project_type != "default": category = Common.get_display_title(project_type) project.set_value("category", category) project.commit() # if there is an image, check it in upload_path = self.kwargs.get("project_image_path") if upload_path: if not os.path.exists(upload_path): raise TacticException("Cannot find upload image for project [%s]" % upload_path) file_type = 'main' file_paths = [upload_path] file_types = [file_type] source_paths = [upload_path] from pyasm.biz import IconCreator if os.path.isfile(upload_path): icon_creator = IconCreator(upload_path) icon_creator.execute() web_path = icon_creator.get_web_path() icon_path = icon_creator.get_icon_path() if web_path: file_paths = [upload_path, web_path, icon_path] file_types = [file_type, 'web', 'icon'] from pyasm.checkin import FileCheckin checkin = FileCheckin(project, context='icon', file_paths=file_paths, file_types=file_types) checkin.execute() # find project's base_type base_type = project.get_base_type() if not base_type and project_type =='unittest': base_type = 'unittest' elif not base_type: base_type = 'simple' # get the database for this project db_resource = project.get_project_db_resource() database = db_resource.get_database_impl() #database = DatabaseImpl.get() database_type = database.get_database_type() if database_type == 'Oracle': raise TacticException("Creation of project is not supported. Please create manually") # creating project database print "Creating database '%s' ..." % project_code try: # create the datbase database.create_database(db_resource) except Exception as e: print str(e) print "WARNING: Error creating database [%s]" % project_code # import the appropriate schema with config first database.import_schema(db_resource, base_type) self.create_schema(project_code) # before we upgrade, we have to commit the transaction # This is because upgrade actually run as separate processes # so if not commit has been made, the tables from importing the # schema will not have existed yet DbContainer.commit_thread_sql() self.upgrade() # import the appropriate data database.import_default_data(db_resource, base_type) # import default links if use_default_side_bar: self.import_default_side_bar() # create specified stypes self.create_search_types() # create theme if project_theme: self.create_theme(project_theme) # set as main project is_main_project = self.kwargs.get("is_main_project") if is_main_project in [True,'true','on']: Config.set_value("install", "default_project", project_code) Config.save_config() Config.reload_config() # initiate the DbContainer DbContainer.get('sthpw') self.info['result'] = "Finished creating project [%s]."%project_code print "Done."
def configure_db(my): my.section = 'Database Setup' web = WebContainer.get_web() vendor = web.get_form_value("database/vendor") if not vendor: raise TacticException("A vendor needs to be passed in.") if vendor == 'Sqlite': # take the current files and copy them to the database folder db_dir = web.get_form_value("database/sqlite_db_dir") if not db_dir: raise TacticException( "No Folder configured for Sqlite Database") if not os.path.exists(db_dir): os.makedirs(db_dir) # check to see if the sthpw database is in this folder sthpw_path = "%s/sthpw.db" % (db_dir) if not os.path.exists(sthpw_path): # copy the default database over install_dir = Environment.get_install_dir() template_db = "%s/src/install/start/db/sthpw.db" % install_dir shutil.copy(template_db, db_dir) Config.set_value("database", "sqlite_db_dir", db_dir) Config.remove("database", "server") Config.remove("database", "port") Config.remove("database", "user") Config.remove("database", "password") else: defaults = DEFAULTS[vendor] default_server = defaults['server'] default_port = defaults['port'] default_user = defaults['user'] default_password = defaults['password'] Config.remove("database", "sqlite_db_dir") if vendor == 'MySQL': default_encoding = defaults['encoding'] default_charset = defaults['charset'] encoding = web.get_form_value("encoding") if not encoding: encoding = default_encoding if encoding: Config.set_value("database", "encoding", encoding) else: Config.set_value("database", "encoding", "") charset = web.get_form_value("charset") if not charset: charset = default_charset if charset: Config.set_value("database", "charset", charset) else: Config.set_value("database", "charset", "") # get the info 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 if server: Config.set_value("database", "server", server) else: #Config.remove("database", "server") Config.set_value("database", "server", "") if port: Config.set_value("database", "port", port) else: #Config.remove("database", "port") Config.set_value("database", "port", "") if user: Config.set_value("database", "user", user) else: #Config.remove("database", "user") Config.set_value("database", "user", "") if password: Config.set_value("database", "password", password) else: Config.set_value("database", "password", "") #Config.remove("database", "password") # save the database Config.set_value("database", "vendor", vendor)