def run(self): """ Main entry point that executes these steps: * creates role in database. * creates database. * save new configuration on server.ini. * creates tables. """ try: config = ConfigParser() config.read(LOCAL_CONFIG_FILE) if not self._check_current_config(config): return faraday_path_conf = os.path.expanduser(CONST_FARADAY_HOME_PATH) # we use psql_log_filename for historical saving. we will ask faraday users this file. # current_psql_output is for checking psql command already known errors for each execution. psql_log_filename = os.path.join(faraday_path_conf, 'logs', 'psql_log.log') current_psql_output = TemporaryFile() with open(psql_log_filename, 'a+') as psql_log_file: hostname = 'localhost' username, password, process_status = self._configure_new_postgres_user( current_psql_output) current_psql_output.seek(0) psql_output = current_psql_output.read() # persist log in the faraday log psql_log.log psql_log_file.write(psql_output) self._check_psql_output(current_psql_output, process_status) if hostname.lower() in ['localhost', '127.0.0.1']: database_name = 'faraday' current_psql_output = TemporaryFile() database_name, process_status = self._create_database( database_name, username, current_psql_output) current_psql_output.seek(0) self._check_psql_output(current_psql_output, process_status) current_psql_output.close() conn_string = self._save_config(config, username, password, database_name, hostname) self._create_tables(conn_string) couchdb_config_present = server.config.couchdb if not (couchdb_config_present and couchdb_config_present.user and couchdb_config_present.password): self._create_admin_user(conn_string) else: print( 'Skipping new admin creation since couchdb configuration was found.' ) except KeyboardInterrupt: current_psql_output.close() print('User cancelled.') sys.exit(1)
def save_new_secret_key(app): if not os.path.exists(LOCAL_CONFIG_FILE): copy_default_config_to_local() config = ConfigParser() config.read(LOCAL_CONFIG_FILE) rng = SystemRandom() secret_key = "".join([rng.choice(string.ascii_letters + string.digits) for _ in xrange(25)]) app.config['SECRET_KEY'] = secret_key config.set('faraday_server', 'secret_key', secret_key) with open(LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile)
def setup_storage_path(): default_path = join(expanduser("~"), '.faraday/storage') if not os.path.exists(default_path): logger.info('Creating directory {0}'.format(default_path)) os.mkdir(default_path) config = ConfigParser() config.read(server.config.LOCAL_CONFIG_FILE) config.add_section('storage') config.set('storage', 'path', default_path) with open(server.config.LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile) return default_path
def run(self, choose_password): """ Main entry point that executes these steps: * creates role in database. * creates database. * save new configuration on server.ini. * creates tables. """ try: config = ConfigParser() config.read(LOCAL_CONFIG_FILE) if not self._check_current_config(config): return faraday_path_conf = os.path.expanduser(CONST_FARADAY_HOME_PATH) # we use psql_log_filename for historical saving. we will ask faraday users this file. # current_psql_output is for checking psql command already known errors for each execution. psql_log_filename = os.path.join(faraday_path_conf, 'logs', 'psql_log.log') current_psql_output = TemporaryFile() with open(psql_log_filename, 'a+') as psql_log_file: hostname = 'localhost' username, password, process_status = self._configure_new_postgres_user(current_psql_output) current_psql_output.seek(0) psql_output = current_psql_output.read() # persist log in the faraday log psql_log.log psql_log_file.write(psql_output) self._check_psql_output(current_psql_output, process_status) if hostname.lower() in ['localhost', '127.0.0.1']: database_name = 'faraday' current_psql_output = TemporaryFile() database_name, process_status = self._create_database(database_name, username, current_psql_output) current_psql_output.seek(0) self._check_psql_output(current_psql_output, process_status) current_psql_output.close() conn_string = self._save_config(config, username, password, database_name, hostname) self._create_tables(conn_string) couchdb_config_present = server.config.couchdb if not (couchdb_config_present and couchdb_config_present.user and couchdb_config_present.password): self._create_admin_user(conn_string, choose_password) else: print('Skipping new admin creation since couchdb configuration was found.') except KeyboardInterrupt: current_psql_output.close() print('User cancelled.') sys.exit(1)