def _configure(): # Load configuration file from (optional) environment variable # Also see http://zope.org/Collectors/Zope/1233 import os configfile = os.environ.get('ZOPE_CONFIG') if configfile is not None: configure(configfile)
def main(argv=sys.argv): if len(sys.argv) < 3: raise Exception("must specify a zope config file and a celery command") argv = argv filepath = sys.argv[2] os.environ['ZOPE_CONFIG'] = filepath sys.argv = [''] from Zope2.Startup.run import configure configure(os.environ['ZOPE_CONFIG']) # Fix for setuptools generated scripts, so that it will # work with multiprocessing fork emulation. # (see multiprocessing.forking.get_preparation_data()) if __name__ != "__main__": sys.modules["__main__"] = sys.modules[__name__] # load tasks up tasks = dict([(i.name, i.load()) for i in iter_entry_points( group='celery_tasks', name=None)]) tasks = getConfiguration().environment.get('CELERY_TASKS') if tasks: try: __import__(tasks) except ImportError: logger.warn('error importing tasks: ' + tasks) argv.remove(argv[2]) # restore argv sys.argv = argv Worker(app=getCelery()).execute_from_commandline()
def main(argv=sys.argv): if len(sys.argv) != 4: raise Exception("Must specify configuration path, site name and days") site_name = sys.argv[2] days = int(sys.argv[3]) now = datetime.datetime.now() argv = argv filepath = sys.argv[1] os.environ['ZOPE_CONFIG'] = filepath sys.argv = [''] from Zope2.Startup.run import configure configure(os.environ['ZOPE_CONFIG']) app = spoofRequest(Zope2.app()) request = app.REQUEST site = app.unrestrictedTraverse(site_name) setSite(site) storage = IGarbageStorage(site) if storage and isInstalled(site=site): expunge = [] for key, item in storage.garbagecan_contents(): delta = now - item.garbagecan_date if delta.days > days: expunge.append(key) for key in expunge: storage.expunge(key) if AUDIT: notify( AuditableActionPerformedEvent(site, request, 'Expunge (script)', key.split(':')[0])) transaction.commit()
def main(argv=sys.argv): if len(sys.argv) < 3: raise Exception("must specify a zope config file and a celery command") argv = argv # find the index of the conf file in the args conf_index = 2 for idx, arg in enumerate(sys.argv): if '.conf' in arg: conf_index = idx break filepath = sys.argv[conf_index] os.environ['ZOPE_CONFIG'] = filepath sys.argv = [''] from Zope2.Startup.run import configure configure(os.environ['ZOPE_CONFIG']) # Fix for setuptools generated scripts, so that it will # work with multiprocessing fork emulation. # (see multiprocessing.forking.get_preparation_data()) if __name__ != "__main__": sys.modules["__main__"] = sys.modules[__name__] # load tasks up tasks = dict([(i.name, i.load()) for i in iter_entry_points( group='celery_tasks', name=None)]) tasks = getConfiguration().environment.get('CELERY_TASKS') if tasks: try: __import__(tasks) except ImportError: logger.warn('error importing tasks: ' + tasks) argv.remove(filepath) # restore argv sys.argv = argv Worker(app=getCelery()).execute_from_commandline()
def main(argv=sys.argv): if len(sys.argv) < 3: raise Exception("must specify a zope config file and a celery command") argv = argv # find the index of the conf file in the args conf_index = 2 for idx, arg in enumerate(sys.argv): if '.conf' in arg: conf_index = idx break filepath = sys.argv[conf_index] os.environ['ZOPE_CONFIG'] = filepath sys.argv = [''] try: from Zope2.Startup.run import configure startup = configure(os.environ['ZOPE_CONFIG']) except ImportError: from Zope2.Startup.run import configure_wsgi startup = configure_wsgi(os.environ['ZOPE_CONFIG']) # Fix for setuptools generated scripts, so that it will # work with multiprocessing fork emulation. # (see multiprocessing.forking.get_preparation_data()) if __name__ != "__main__": sys.modules["__main__"] = sys.modules[__name__] # load entry point tasks up tasks = [] for entry_point in iter_entry_points(group='celery_tasks', name=None): try: tasks.append((entry_point.name, entry_point.load())) except ImportError: logger.warn('error importing tasks: ' + entry_point.name) raise tasks = dict(tasks) for name, task_list in tasks.items(): logger.warn('importing tasks: ' + name) extra_config = getattr(task_list, 'extra_config', None) if extra_config is not None: logger.warn('Found additional Zope config.') extra_config(startup) # load env tasks up tasks = getConfiguration().environment.get('CELERY_TASKS') if tasks: for task_list in tasks.split(): try: logger.warn('importing tasks: ' + tasks) module = import_module(tasks) extra_config = getattr(module, 'extra_config', None) if extra_config is not None: logger.warn('Found additional Zope config.') extra_config(startup) except ImportError: logger.warn('error importing tasks: ' + tasks) raise argv.remove(filepath) # restore argv sys.argv = argv Worker(app=getCelery()).execute_from_commandline()