def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ config = PylonsConfig() # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')]) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='joj', paths=paths) config['routes.map'] = make_map(config) config['pylons.app_globals'] = app_globals.Globals(config) config['pylons.h'] = joj.lib.helpers config['pylons.app_globals'].genshi_loader = TemplateLoader( paths['templates'], auto_reload=True) # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) config['pylons.strict_tmpl_context'] = False # Setting up SQLAlchemy here initialise_session(config) # Hackery alert - the htmlfill function of formencode # fails when parsing html markup inside a CDATA section # which is bad for any JS that adds elements for example # Found a workaround here: # http://osdir.com/ml/python.formencode/2006-10/msg00019.html # FillingParser.CDATA_CONTENT_ELEMENTS = () return config
log = logging.getLogger(__name__) here_dir = os.path.dirname(os.path.abspath(__file__)) conf_dir = os.path.dirname(os.path.dirname(here_dir)) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) if len(sys.argv) is not 2 or sys.argv[1] == '-h': print "Usage: update_job_statuses <config filename>" print " updates the job statuses in the database from the jobs service" print " config filename: filename of the configuration file e.g. development.ini" exit() log.debug("setup") wsgiapp = loadapp('config:' + sys.argv[1], relative_to=conf_dir) config = wsgiapp.config model.initialise_session(config) wmc_util.set_http_openers(config) job_runner_client = JobRunnerClient(config) job_status_updater = JobStatusUpdaterService(job_runner_client, config) try: log.info("Getting and setting statuses") job_status_updater.update() log.info("Statuses updated") except Exception, ex: log.exception("Cron job throw an exception: %s" % ex.message) exit(-1)