def config_content(self, command, vars): """ Called by ``self.write_config``, this returns the text content for the config file, given the provided variables. """ settable_vars = [ var('db_url', 'Database url for sqlite, postgres or mysql', default='sqlite:///%(here)s/studio.db'), var('ms_url', 'Url to the mapserv CGI', default='http://localhost/cgi-bin/mapserv'), var('admin_password', 'Password for default admin user', default=secret.secret_string(length=8)) ] for svar in settable_vars: if command.interactive: prompt = 'Enter %s' % svar.full_description() response = command.challenge(prompt, svar.default, svar.should_echo) vars[svar.name] = response else: if not vars.has_key(svar.name): vars[svar.name] = svar.default vars['cookie_secret'] = secret.secret_string() # call default pylons install return super(StudioInstaller, self).config_content(command, vars)
def test_secret_string(): data = secret.secret_string() assert isinstance(data, str) data = secret.secret_string(20) assert isinstance(data, str) assert len(data) == 20
def setup_environment_and_database(env_dir=None, enabled_plugins=''): global_config = {} env_dir = env_dir or '/invalid' app_instance_secret = secret.secret_string() app_config = { 'plugins': enabled_plugins, 'sqlalchemy.url': 'sqlite://', 'layout_template': 'layout', 'external_template': 'false', 'image_dir': os.path.join(env_dir, 'images'), 'media_dir': os.path.join(env_dir, 'media'), 'beaker.session.secret': app_instance_secret, 'sa_auth.cookie_secret': app_instance_secret, } pylons_config = load_environment(global_config, app_config) paste_registry = Registry() paste_registry.prepare() app_globals = pylons_config['pylons.app_globals'] register_instance(paste_registry, 'app_globals', app_globals) pylons_config.update({ 'paste.registry': paste_registry, 'pylons.pylons': pylons, }) metadata.create_all(bind=DBSession.bind, checkfirst=True) return pylons_config
def command(self): self.requirement = self.args[0] if '#' in self.requirement: if self.options.ep_name is not None: raise BadCommand( "You may not give both --name and a requirement with " "#name") self.requirement, self.options.ep_name = self.requirement.split('#', 1) if not self.options.ep_name: self.options.ep_name = 'main' self.distro = self.get_distribution(self.requirement) self.installer = self.get_installer( self.distro, self.options.ep_group, self.options.ep_name) if self.options.show_info: if len(self.args) > 1: raise BadCommand( "With --info you can only give one argument") return self.show_info() if len(self.args) < 2: # See if sysconfig can give us a default filename options = [_f for _f in self.call_sysconfig_functions( 'default_config_filename', self.installer) if _f] if not options: raise BadCommand( "You must give a configuration filename") self.config_file = options[0] else: self.config_file = self.args[1] self.check_config_file() self.project_name = self.distro.project_name self.vars = self.sysconfig_install_vars(self.installer) self.vars.update(self.parse_vars(self.args[2:])) self.vars['project_name'] = self.project_name self.vars['requirement'] = self.requirement self.vars['ep_name'] = self.options.ep_name self.vars['ep_group'] = self.options.ep_group self.vars.setdefault('app_name', self.project_name.lower()) self.vars.setdefault('app_instance_uuid', uuid.uuid4()) self.vars.setdefault('app_instance_secret', secret.secret_string()) if self.verbose > 1: print_vars = list(self.vars.items()) print_vars.sort() print('Variables for installation:') for name, value in print_vars: print(' %s: %r' % (name, value)) self.installer.write_config(self, self.config_file, self.vars) edit_success = True if self.options.edit: edit_success = self.run_editor() setup_configs = self.installer.editable_config_files(self.config_file) # @@: We'll just assume the first file in the list is the one # that works with setup-app... setup_config = setup_configs[0] if self.options.run_setup: if not edit_success: print('Config-file editing was not successful.') if self.ask('Run setup-app anyway?', default=False): self.run_setup(setup_config) else: self.run_setup(setup_config) else: filenames = self.installer.editable_config_files(self.config_file) assert not isinstance(filenames, str), ( "editable_config_files returned a string, not a list") if not filenames and filenames is not None: print('No config files need editing') else: print('Now you should edit the config files') if filenames: for fn in filenames: print(' %s' % fn)
def command(self): self.requirement = self.args[0] if "#" in self.requirement: if self.options.ep_name is not None: raise BadCommand("You may not give both --name and a requirement with " "#name") self.requirement, self.options.ep_name = self.requirement.split("#", 1) if not self.options.ep_name: self.options.ep_name = "main" self.distro = self.get_distribution(self.requirement) self.installer = self.get_installer(self.distro, self.options.ep_group, self.options.ep_name) if self.options.show_info: if len(self.args) > 1: raise BadCommand("With --info you can only give one argument") return self.show_info() if len(self.args) < 2: # See if sysconfig can give us a default filename options = filter(None, self.call_sysconfig_functions("default_config_filename", self.installer)) if not options: raise BadCommand("You must give a configuration filename") self.config_file = options[0] else: self.config_file = self.args[1] self.check_config_file() self.project_name = self.distro.project_name self.vars = self.sysconfig_install_vars(self.installer) self.vars.update(self.parse_vars(self.args[2:])) self.vars["project_name"] = self.project_name self.vars["requirement"] = self.requirement self.vars["ep_name"] = self.options.ep_name self.vars["ep_group"] = self.options.ep_group self.vars.setdefault("app_name", self.project_name.lower()) self.vars.setdefault("app_instance_uuid", uuid.uuid4()) self.vars.setdefault("app_instance_secret", secret.secret_string()) if self.verbose > 1: print_vars = self.vars.items() print_vars.sort() print "Variables for installation:" for name, value in print_vars: print " %s: %r" % (name, value) self.installer.write_config(self, self.config_file, self.vars) edit_success = True if self.options.edit: edit_success = self.run_editor() setup_configs = self.installer.editable_config_files(self.config_file) # @@: We'll just assume the first file in the list is the one # that works with setup-app... setup_config = setup_configs[0] if self.options.run_setup: if not edit_success: print "Config-file editing was not successful." if self.ask("Run setup-app anyway?", default=False): self.run_setup(setup_config) else: self.run_setup(setup_config) else: filenames = self.installer.editable_config_files(self.config_file) assert not isinstance(filenames, basestring), "editable_config_files returned a string, not a list" if not filenames and filenames is not None: print "No config files need editing" else: print "Now you should edit the config files" if filenames: for fn in filenames: print " %s" % fn