def evolve(args, instance): print >> args.out, "=" * 78 print >> args.out, "Instance: ", instance root, closer = args.get_root(instance) set_current_instance(instance) managers = list(getUtilitiesFor(IEvolutionManager)) for pkg_name, factory in managers: __import__(pkg_name) pkg = sys.modules[pkg_name] VERSION = pkg.VERSION print >> args.out, 'Package %s' % pkg_name manager = factory(root, pkg_name, VERSION, 0) db_version = manager.get_db_version() print >> args.out, 'Code at software version %s' % VERSION print >> args.out, 'Database at version %s' % db_version if VERSION <= db_version: print >> args.out, 'Nothing to do' elif args.latest: evolve_to_latest(manager) ver = manager.get_db_version() print >> args.out, 'Evolved %s to %s' % (pkg_name, ver) else: print >> args.out, 'Not evolving (use --latest to do actual evolution)' print >> args.out, '' transaction.commit()
def update_feeds_for_instance(args, instance): log.info("Updating feeds for %s", instance) root, closer = args.get_root(instance) set_current_instance(instance) set_subsystem('update_feeds') feeds.update_feeds(root, log, args.force) transaction.commit()
def digest(args, instance): root, closer = args.get_root(instance) set_current_instance(instance) set_subsystem('digest') alerts = Alerts() alerts.send_digests(root) closer()
def mailin(args, instance): log.info("Processing mailin for %s" % instance) root, closer = args.get_root(instance) set_current_instance(instance) set_subsystem('mailin') zodb_uri = get_setting(root, 'postoffice.zodb_uri') zodb_path = get_setting(root, 'postoffice.zodb_path', '/postoffice') queue = get_setting(root, 'postoffice.queue') if zodb_uri is None: args.parser.error("postoffice.zodb_uri must be set in config file") if queue is None: args.parser.error("postoffice.queue must be set in config file") runner = None try: runner = MailinRunner2(root, zodb_uri, zodb_path, queue) runner() transaction.commit() p_jar = getattr(root, '_p_jar', None) if p_jar is not None: # Attempt to fix memory leak p_jar.db().cacheMinimize() except: transaction.abort() raise finally: closer() if runner is not None: runner.close()
def generate_stats(args, instance): root, closer = args.get_root(instance) set_current_instance(instance) settings = get_settings() folder = settings.get('statistics_folder') if folder is None: return log.info("Generating stats for %s" % instance) if not os.path.exists(folder): os.makedirs(folder) generate_reports(root, folder)
def site_dispatch(request): instances = get_instances(request.registry.settings) path = list(request.matchdict.get('subpath')) host = request.host # Copy request, getting rid of bfg keys from the environ environ = request.environ.copy() for key in list(environ.keys()): if key.startswith('bfg.'): del environ[key] request = request.__class__(environ) # nginx likes to set script name to '/' with screws up everybody # trying to write urls and causes them to add an extra slash if len(request.script_name) == 1: request.script_name = '' # See if we're in a virtual hosting environment name = instances.get_virtual_host(host) if not name and path: # We are not in a virtual hosting environment, so the first element of # the path_info is the name of the instance. name = path.pop(0) # Get the Karl instance to dispatch to instance = instances.get(name) # If we found the instance, rewrite paths for subrequest if instance is not None: script_name = '/'.join((request.script_name, name)) path_info = '/' + '/'.join(path) request.script_name = script_name request.path_info = path_info else: # Get the Karl instance to dispatch to instance = instances.get(name) # If we still don't have an instance, see if one is defined as the root # instance. if instance is None: name = instances.root_instance if name is not None: instance = instances.get(name) if instance is None: raise NotFound # Dispatch set_current_instance(name) return request.get_response(instance.pipeline())
def dump_senders(args, instance): root, closer = args.get_root(instance) set_current_instance(instance) set_subsystem('dump_senders') pc = find_peopledirectory_catalog(root) for email in pc['email']._fwd_index.keys(): if ',' in email: for e in email.split(','): if not e.isspace() and len(e) != 0: print e.strip() + " permit_auth_destination" else: if not email.isspace() and len(email) != 0: print email.strip() + " permit_auth_destination"
def usersync(args): root, closer = args.get_root(args.inst) set_current_instance(args.inst) set_subsystem('usersync') if args.password and args.password_file: args.parser.error('cannot set both --password and --password-file') if args.password_file: with open(args.password_file) as f: password = f.read().strip('\n') else: password = args.password log.info("Syncing users at %s" % args.url) sync = UserSync(root) sync(args.url, args.username, password) transaction.commit()
def samplegen(args, instance): root, closer = args.get_root(instance) set_current_instance(instance) try: add_sample_users(root) for i in range(int(args.communities)): add_sample_community(root) except: transaction.abort() raise else: if args.dryrun: transaction.abort() else: transaction.commit()
def cleantags(args, instance): root, closer = args.get_root(instance) set_current_instance(instance) profiles = root['profiles'] engine = root.tags assign_to = args.assign_to print "searching for tags with non-existing user" for user in list(engine.getUsers()): if not user in profiles: print "Reassigning tags by missing user '%s' to '%s'" % ( user, assign_to) engine.reassign(user, assign_to) if args.dryrun: print '*** aborting ***' transaction.abort() else: print '*** committing ***' transaction.commit()
def samplegen(args, instance): root, closer = args.get_root(instance) set_current_instance(instance) try: add_sample_users(root) for i in range(int(args.communities)): try: add_sample_community(root, more_files=(args.more_files and i==0)) except TypeError: # fall back for old versions that do not support more_files add_sample_community(root) except: transaction.abort() raise else: if args.dryrun: transaction.abort() else: transaction.commit()
def test_it(self): from karlserve.instance import set_current_instance from karlserve.instance import get_current_instance set_current_instance('foo') self.assertEqual(get_current_instance(), 'foo')