def _setup(self): """ Set up logging, import pylons/paste/debexpo modules, parse config file, create config class and chdir to the incoming directory. """ # Look for ini file if not os.path.isfile(self.ini_file): self._fail('Cannot find ini file') self._setup_logging() # Import debexpo root directory sys.path.append(os.path.dirname(self.ini_file)) # Initialize Pylons app conf = appconfig('config:' + self.ini_file) pylons.config = load_environment(conf.global_conf, conf.local_conf) # Change into the incoming directory incoming_dir = pylons.config['debexpo.upload.incoming'] logging.info("Changing dir to %s", incoming_dir) os.chdir(incoming_dir) # Look for the changes file if not os.path.isfile(self.changes_file): self._fail('Cannot find changes file')
def main(): parser = OptionParser(usage="%prog -u FILE -i FILE") parser.add_option( '-u', '--user-json-path', dest='user_json_path', help= 'Path to JSON file with user data to import (/dev/stdin is permissible)', metavar='FILE', default=None) parser.add_option('-i', '--ini', dest='ini', help='Path to application ini file', metavar='FILE', default=None) (options, args) = parser.parse_args() if not options.user_json_path: parser.print_help() sys.exit(1) # Initialize Pylons app conf = appconfig('config:' + os.path.abspath(options.ini)) pylons.config = load_environment(conf.global_conf, conf.local_conf) list_of_dicts = simplejson.load(open(options.user_json_path)) import_users(list_of_dicts) return 0
def make_app(global_conf, full_stack=True, **app_conf): """Creates a Pylons WSGI application and returns it. ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) # Static files javascripts_app = StaticJavascripts() static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, javascripts_app, app]) return app
def __init__(self, inifile): """ This method does nothing in this cronjob """ self.inifile = os.path.abspath(inifile) conf = appconfig('config:' + self.inifile) pylons.config = load_environment(conf.global_conf, conf.local_conf) self.config = pylons.config self.gpg = GnuPG()
def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Creates a Pylons WSGI application and returns it. ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment config = load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp(config=config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) # Static files if asbool(static_files): static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) app.config = config return app
def make_app(global_conf, full_stack=True, **app_conf): """Creates a Pylons WSGI application and returns it. ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, error_template=error_template, **config["pylons.errorware"]) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) # Static files javascripts_app = StaticJavascripts() static_app = StaticURLParser(config["pylons.paths"]["static_files"]) app = Cascade([static_app, javascripts_app, app]) return app
def setup_config(command, filename, section, vars): """ Run when debexpo is being set up, when ``paster setup-app`` is executed and shouldn't be called directly. ``command`` Pointer to the setup function. ``filename`` File used for configuration. E.g. `development.ini`. ``section`` Section in the config file; usually `app:main`. ``vars`` Extra variables passed to the setup. """ conf = appconfig("config:" + filename) if not pylons.test.pylonsapp: config = load_environment(conf.global_conf, conf.local_conf) else: config = pylons.test.pylonsapp.config log.info("Creating database tables") import_all_models() meta.metadata.create_all(bind=meta.engine) log.info("Successfully setup database tables") if not os.path.isdir(config["debexpo.upload.incoming"]): log.info("Creating incoming directory") os.mkdir(config["debexpo.upload.incoming"]) else: log.info("Incoming directory already exists") if not os.path.isdir(config["debexpo.repository"]): log.info("Creating repository directory") os.mkdir(config["debexpo.repository"]) else: log.info("Repository directory already exists") log.info("Making sure all ISO countries are in the database") debexpo.model.user_countries.create_iso_countries() log.info("Making sure all tags do exist") debexpo.model.sponsor_metrics.create_tags() log.info("Import data store pre-existing data") debexpo.model.data_store.fill_data_store()
def setup_config(command, filename, section, vars): """ Run when debexpo is being set up, when ``paster setup-app`` is executed and shouldn't be called directly. ``command`` Pointer to the setup function. ``filename`` File used for configuration. E.g. `development.ini`. ``section`` Section in the config file; usually `app:main`. ``vars`` Extra variables passed to the setup. """ conf = appconfig('config:' + filename) if not pylons.test.pylonsapp: config = load_environment(conf.global_conf, conf.local_conf) else: config = pylons.test.pylonsapp.config log.info('Creating database tables') import_all_models() meta.metadata.create_all(bind=meta.engine) log.info('Successfully setup database tables') if not os.path.isdir(config['debexpo.upload.incoming']): log.info('Creating incoming directory') os.mkdir(config['debexpo.upload.incoming']) else: log.info('Incoming directory already exists') if not os.path.isdir(config['debexpo.repository']): log.info('Creating repository directory') os.mkdir(config['debexpo.repository']) else: log.info('Repository directory already exists') log.info('Making sure all ISO countries are in the database') debexpo.model.user_countries.create_iso_countries() log.info('Making sure all tags do exist') debexpo.model.sponsor_metrics.create_tags() log.info('Import data store pre-existing data') debexpo.model.data_store.fill_data_store()
def setup_config(command, filename, section, vars): """ Run when debexpo is being set up, when ``paster setup-app`` is executed and shouldn't be called directly. ``command`` Pointer to the setup function. ``filename`` File used for configuration. E.g. `development.ini`. ``section`` Section in the config file; usually `app:main`. ``vars`` Extra variables passed to the setup. """ conf = appconfig('config:' + filename) load_environment(conf.global_conf, conf.local_conf) log.info('Creating database tables') import_all_models() meta.metadata.create_all(bind=meta.engine) log.info('Successfully setup database tables') if not os.path.isdir(config['debexpo.upload.incoming']): log.info('Creating incoming directory') os.mkdir(config['debexpo.upload.incoming']) else: log.info('Incoming directory already exists') if not os.path.isdir(config['debexpo.repository']): log.info('Creating repository directory') os.mkdir(config['debexpo.repository']) else: log.info('Repository directory already exists')
def _setup(self): """ Set up logging, import pylons/paste/debexpo modules, parse config file and create config """ # Look for ini file if not os.path.isfile(self.ini_file): self._fail('Cannot find ini file %s' % self.ini_file) self._setup_logging() # Import debexpo root directory sys.path.append(os.path.dirname(self.ini_file)) # Import debexpo modules from paste.deploy import appconfig from pylons import config from debexpo.config.environment import load_environment # Save app config for later self.config = config # Initialize Pylons app conf = appconfig('config:' + options.ini) load_environment(conf.global_conf, conf.local_conf)
def _setup(self): """ Sets up the worker task. Setup logging, Pylons globals and so on """ global log config = ConfigParser.ConfigParser() config.read(self.inifile) if not config.has_section('loggers'): # Sorry, the logger has not been set up yet print('Config file does not have [loggers] section') sys.exit(1) logging.config.fileConfig(self.inifile) logger_name = 'debexpo.worker' log = logging.getLogger(logger_name) sys.path.append(os.path.dirname(self.inifile)) conf = appconfig('config:' + self.inifile) pylons.config = load_environment(conf.global_conf, conf.local_conf)
def main(): parser = OptionParser(usage="%prog -u FILE -i FILE") parser.add_option('-u', '--user-json-path', dest='user_json_path', help='Path to JSON file with user data to import (/dev/stdin is permissible)', metavar='FILE', default=None) parser.add_option('-i', '--ini', dest='ini', help='Path to application ini file', metavar='FILE', default=None) (options, args) = parser.parse_args() if not options.user_json_path: parser.print_help() sys.exit(1) # Initialize Pylons app conf = appconfig('config:' + os.path.abspath(options.ini)) pylons.config = load_environment(conf.global_conf, conf.local_conf) list_of_dicts = simplejson.load(open(options.user_json_path)) import_users(list_of_dicts) return 0