def main(argv=sys.argv): logging.basicConfig() log.setLevel(logging.INFO) parser = OptionParser( description="Generate some statistics about Karl usage", usage="%prog [options]", ) parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() if len(args): parser.error("Command does not take arguments.") config = options.config if not config: config = get_default_config() root, closer = open_root(config) try: gen_stats(root) finally: transaction.abort()
def evolve(context): """ Replace OSI's old OSI-specific peopledir implementation with newer, universal peopledir. NOTE: We have to keep the old peopledir package around at least long enough to run this in production. """ if isinstance(context['people'], OSIPeople): print "Delete old peopledir" del context['people'] print "Create new peopledir" context['people'] = people = create_content(IPeopleDirectory) assert isinstance(people, NewPeople) print "Perform fresh gsa_sync" # Use local copy if available, to save time in testing here = os.path.dirname(os.path.dirname(sys.argv[0])) local_gsa = os.path.abspath(os.path.join(here, 'gsa_sync.xml')) if os.path.exists(local_gsa): url = 'file://%s' % local_gsa user = password = None else: url = GSA_URL user, password = '******', 'oBaMa2012' print "Using url:", url GsaSync(context, url, user, password)() print "Run peopleconf" config = get_default_config() run_peopleconf(context, config, force_reindex=True)
def main(): parser = OptionParser(description=__doc__) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") options, args = parser.parse_args() if args: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) peopledir = find_peopledirectory(root) reindex_peopledirectory(peopledir) if options.dry_run: transaction.abort() else: transaction.commit()
def main(): parser = OptionParser(description=__doc__, usage='usage: %prog [options]') parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() try: group = args[0] except IndexError: parser.error('need "group" arg') config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: reset_passwords(root, group) except: transaction.abort() raise else: transaction.commit()
def main(): logging.basicConfig() log.setLevel(logging.INFO) parser = OptionParser(description=__doc__, ) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() me = sys.argv[0] me = os.path.abspath(me) sandbox = os.path.dirname(os.path.dirname(me)) outfile_path = os.path.join(sandbox, 'var', 'usage_metadata.csv') config = options.config if config is None: config = get_default_config() root, closer = open_root(config) _export_metadata(root, outfile_path) log.info("All done.")
def main(argv=sys.argv): logging.basicConfig() parser = optparse.OptionParser( description=__doc__, usage="%prog [options]", ) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-O', '--output', dest='output', default='.', help="Path to the directory where reports should be written.", metavar='DIR') options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many arguments. " + str(args)) config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, name='karl') root, closer = get_root(app) folder = os.path.abspath(options.output) generate_reports(root, folder)
def main(argv=sys.argv[1:]): parser = optparse.OptionParser(description=__doc__, usage='%prog [options] message') parser.add_option( '-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-L', '--level', dest='level', help='Log level: debug, info, warn or error', default='info') options, args = parser.parse_args(argv) if not args: parser.error("No message given.") config = options.config if config is None: config = get_default_config() root, closer = open_root(config) func = getattr(logging.getLogger('karl'), options.level, None) if func is None: parser.error("Bad level: %s" % options.level) func(' '.join(args))
def main(argv=sys.argv): logging.basicConfig() parser = optparse.OptionParser( description=__doc__, usage="%prog [options]", ) parser.add_option( '-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option( '-O', '--output', dest='output', default='.', help="Path to the directory where reports should be written.", metavar='DIR') options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many arguments. " + str(args)) config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, name='karl') root, closer = get_root(app) folder = os.path.abspath(options.output) generate_reports(root, folder)
def main(argv=sys.argv, root=None, peopleconf_func=peopleconf): parser = optparse.OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-f', '--force-reindex', dest='force_reindex', action='store_true', default=False, help="Reindex the people catalog unconditionally") parser.add_option('--dry-run', dest='dryrun', action='store_true', default=False, help="Don't actually commit the transaction") options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() if root is None: root, closer = open_root(config) try: run_peopleconf(root, config, peopleconf_func, force_reindex=options.force_reindex) except: transaction.abort() raise else: if options.dryrun: transaction.abort() else: transaction.commit()
def main(): parser = OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") parser.add_option('-i', '--interval', dest='commit_interval', action="store", default=200, help="Commit every N transactions") parser.add_option('-p', '--path', dest='path', action="store", default=None, metavar='EXPR', help="Reindex only objects whose path matches a regular expression") options, args = parser.parse_args() if args: parser.error("Too many parameters: %s" % repr(args)) commit_interval = int(options.commit_interval) if options.path: path_re = re.compile(options.path) else: path_re = None config = options.config if config is None: config = get_default_config() root, closer = open_root(config) def output(msg): print msg reindex_catalog(root, path_re=path_re, commit_interval=commit_interval, dry_run=options.dry_run, output=output)
def main(): parser = OptionParser(description=__doc__, usage="usage: %prog [options] username password") parser.add_option( "-C", "--config", dest="config", default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini", ) options, args = parser.parse_args() try: username, password = args except ValueError: parser.error('Too many or too few args (need "username password"))') config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: adduser(root, username, password) except: transaction.abort() raise else: transaction.commit()
def main(argv=sys.argv): logging.basicConfig() parser = optparse.OptionParser(description=__doc__, usage="%prog [options]") parser.add_option( "-C", "--config", dest="config", help="Path to configuration file (defaults to $CWD/etc/karl.ini)", metavar="FILE", ) parser.add_option( "-O", "--output", dest="output", default=".", help="Path to the directory where reports should be written.", metavar="DIR", ) options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many arguments. " + str(args)) config = options.config if config is None: config = get_default_config() app = loadapp("config:%s" % config, name="karl") root, closer = get_root(app) folder = os.path.abspath(options.output) generate_reports(root, folder)
def main(argv=sys.argv, root=None): parser = optparse.OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('--assign-to', '-a', dest='assign_to', default='system', metavar='USER', help="Assign tags for missing users to USER (default: system)") parser.add_option('--dry-run', '-n', dest='dry_run', action='store_true', default=False, help="Don't actually commit any transaction") options, args = parser.parse_args(argv[1:]) logging.basicConfig() if root is None: config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: cleantags(root, options.assign_to) except: transaction.abort() raise else: if options.dry_run: print '*** aborting ***' transaction.abort() else: print '*** committing ***' transaction.commit()
def main(): parser = OptionParser(description=__doc__, usage="%prog [options] old_name new_name") parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option( '-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") parser.add_option('-M', '--merge', dest='merge', action='store_true', default=False, help='Merge with an existing user.') options, args = parser.parse_args() if len(args) < 2: parser.error("Too few parameters: %s" % repr(args)) if len(args) > 2: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) old_name, new_name = args rename_user(root, old_name, new_name, options.merge, sys.stdout) if options.dry_run: transaction.abort() else: transaction.commit()
def main(): parser = optparse.OptionParser(description=__doc__, usage="%prog [options] queue_path") parser.add_option( "-C", "--config", dest="config", default=None, help="Path to configuration file (defaults to $CWD/etc/karl.ini)", metavar="FILE", ) parser.add_option("--daemon", "-D", dest="daemon", action="store_true", default=False, help="Run in daemon mode.") parser.add_option( "--interval", "-i", dest="interval", type="int", default=6 * 3600, help="Interval, in seconds, between executions when in " "daemon mode.", ) parser.add_option( "--server", "-s", dest="hostname", default="localhost", help="SMTP server host name", metavar="HOST" ) parser.add_option("--port", "-P", dest="port", type="int", default=25, help="Port of SMTP server", metavar="PORT") parser.add_option("--username", "-u", dest="username", default=None, help="Username, if authentication is required") parser.add_option("--password", "-p", dest="password", default=None, help="Password, if authentication is required") parser.add_option( "--force-tls", "-f", dest="force_tls", action="store_true", default=False, help="Require that TLS be used." ) parser.add_option( "--no-tls", "-n", dest="no_tls", action="store_true", default=False, help="Require that TLS not be used." ) options, args = parser.parse_args() if not args: parser.error("Please specify queue path.") elif len(args) > 1: parser.error("Too many arguments.") queue_path = args[0] config = options.config if config is None: config = get_default_config() app = loadapp("config:%s" % config, "karl") set_subsystem("mailout") mailer = SMTPMailer( hostname=options.hostname, port=options.port, username=options.username, password=options.password, no_tls=options.no_tls, force_tls=options.force_tls, ) qp = QueueProcessor(mailer, queue_path) if options.daemon: run_daemon("digest", qp.send_messages, options.interval) else: qp.send_messages()
def main(): parser = OptionParser(description=__doc__, usage='usage: %prog [options]') parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. " "Defaults to$CWD/etc/karl.ini") parser.add_option('-v', '--verbose', dest='verbose', action='count', default='1', help="Show more information.") parser.add_option('-q', '--quiet', dest='verbose', action='store_const', const=0, help="Show no extra information.") options, args = parser.parse_args() config = options.config if config is None: config = get_default_config()
def main(argv=sys.argv): logging.basicConfig() logging.getLogger('karl').setLevel(logging.INFO) parser = optparse.OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-c', '--communities', dest='communities', default='10', help='Number of communities to add (default 10)') parser.add_option('--dry-run', dest='dryrun', action='store_true', default=False, help="Don't actually commit the transaction") options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: add_sample_users(root) for i in range(int(options.communities)): add_sample_community(root, more_files=i==0) except: transaction.abort() raise else: if options.dryrun: transaction.abort() else: transaction.commit()
def main(argv=sys.argv): parser = optparse.OptionParser( description=__doc__, usage="%prog [options] [user1, user2, ...]", ) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-f', '--filter', dest='filter', action='store_true', help='Limit results to users specified by username in stdin. Users' ' should be whitespace delimited.', default=False) options, args = parser.parse_args(argv[1:]) ids = None if options.filter: ids = sys.stdin.read().split() if args: if ids is not None: ids.extend(args) else: ids = args config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, name='karl') root, closer = get_root(app) out_csv = csv.writer(sys.stdout) out_csv.writerow(['username', 'community', 'last_activity']) for row in stats.user_activity_report(root, ids): username, community, last_activity = row out_csv.writerow([username, community.__name__, last_activity.ctime()])
def archive_console(): """ A console script which archives a community to the local filesystem. Used for testing. """ usage = "usage: %prog [options] community destination" parser = OptionParser(usage, description=__doc__) parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() if len(args) < 2: parser.error("Not enough arguments.") community_name = args.pop(0) path = args.pop(0) if args: parser.error("Too many parameters: %s" % repr(args)) if os.path.exists(path): parser.error("Folder already exists: %s" % path) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) community = root['communities'].get(community_name) if not community: parser.error("No such community: %s" % community_name) realize_archive_to_fs(archive(community), os.path.abspath(path))
def main(): parser = optparse.OptionParser( description=__doc__, usage="%prog [options] queue_path", ) parser.add_option('-C', '--config', dest='config', default=None, help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('--daemon', '-D', dest='daemon', action='store_true', default=False, help='Run in daemon mode.') parser.add_option('--interval', '-i', dest='interval', type='int', default=6*3600, help='Interval, in seconds, between executions when in ' 'daemon mode.') parser.add_option('--server', '-s', dest='hostname', default="localhost", help='SMTP server host name', metavar='HOST') parser.add_option('--port', '-P', dest='port', type='int', default=25, help='Port of SMTP server', metavar='PORT') parser.add_option('--username', '-u', dest='username', default=None, help='Username, if authentication is required') parser.add_option('--password', '-p', dest='password', default=None, help='Password, if authentication is required') parser.add_option('--force-tls', '-f', dest='force_tls', action='store_true', default=False, help='Require that TLS be used.') parser.add_option('--no-tls', '-n', dest='no_tls', action='store_true', default=False, help='Require that TLS not be used.') options, args = parser.parse_args() if not args: parser.error('Please specify queue path.') elif len(args) > 1: parser.error('Too many arguments.') queue_path = args[0] config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, 'karl') set_subsystem('mailout') mailer = SMTPMailer( hostname=options.hostname, port=options.port, username=options.username, password=options.password, no_tls=options.no_tls, force_tls=options.force_tls ) qp = QueueProcessor(mailer, queue_path) if options.daemon: run_daemon('digest', qp.send_messages, options.interval) else: qp.send_messages()
def worker(): """ Console script which connects to Redis and pops one unit of work off of either the copy queue or the remove queue and performs the required operation. If no work is queued for it to do, it will block, waiting for work. This command does not loop. Once one community is copied or removed, the command exits. The intent is that for looping behavior, this can be run from supervisor which will automatically restart the command after it exits. This insures that all connection caches, etc, are cleaned up on each iteration. """ logging.basicConfig(level=logging.INFO) usage = "usage: %prog [options]" parser = OptionParser(usage, description=__doc__) parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() if args: parser.error("Too many arguments.") config = options.config if config is None: config = get_default_config() root, closer = open_root(config) registry = get_current_registry() queue = RedisArchiveQueue.from_settings(registry.settings) closer() log.info("Waiting for work.") operation, community = next(work_queue(queue, config)) log.info("Got work.") with persistent_log(community) as plog: try: if operation == queue.COPY_QUEUE_KEY: log.info("Copy to box: %s", community.title) copy_community_to_box(community) elif operation == queue.MOTHBALL_QUEUE_KEY: log.info("Mothball: %s", community.title) mothball_community(community) else: log.warn("unknown operation: %s", operation) transaction.commit() log.info('Finished job.') except: log.error('Error during archive.', exc_info=True) transaction.abort() # Save the exception status in its own transaction community.archive_status = 'exception' raise finally: # Persist log in its own transaction so that even if there is an # error we get a log community.archive_log = plog plog.save() transaction.commit()
def main(argv=sys.argv, root=None, update_func=update_feeds, tx=transaction): parser = optparse.OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-f', '--force', dest='force', action='store_true', default=False, help='Update all feeds, even if unchanged') parser.add_option('--dry-run', dest='dryrun', action='store_true', default=False, help="Don't actually commit the transaction") parser.add_option('--daemon', '-D', dest='daemon', action='store_true', default=False, help='Run in daemon mode.') parser.add_option('--interval', '-i', dest='interval', type='int', default=300, help='Interval, in seconds, between executions when in ' 'daemon mode.') parser.add_option('--timeout', '-t', dest='timeout', type='int', default=None, help='Timeout, in seconds, for URL requests.') options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() if root is None: app = loadapp('config:%s' % config, name='karl') #else: unit test def run(root=root): closer = lambda: None # unit test try: if root is None: root, closer = get_root(app) #else: unit test set_subsystem('update_feeds') update_func(root, config, force=options.force) except: tx.abort() closer() raise else: if options.dryrun: tx.abort() else: tx.commit() closer() if options.timeout is not None: socket.setdefaulttimeout(options.timeout) if options.daemon: run_daemon('update_feeds', run, options.interval) else: run()
def main(): parser = OptionParser(description=__doc__, usage='usage: %prog [options] username password') parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. " "Defaults to$CWD/etc/karl.ini") parser.add_option('--clear', dest='clear', default=False, action='store_true', help="Clear any existing announcement. Default false.") parser.add_option('-n', '--dry-run', dest='dry_run', default=False, action='store_true', help="Don't actually commit any change.") parser.add_option('-v', '--verbose', dest='verbose', action='count', default='1', help="Show more information.") parser.add_option('-q', '--quiet', dest='verbose', action='store_const', const=0, help="Show no extra information.") options, args = parser.parse_args() if options.clear: if args: parser.error("No arguments allowed with '--clear'") func = clear_site_announce else: func = set_site_announce config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: previous, now = func(root, *args) except: transaction.abort() raise if options.verbose: print 'Before:', previous print 'After:', now if options.dry_run: transaction.abort() else: transaction.commit()
def main(args=sys.argv): if PGTextIndex is None: print >>sys.stderr, NO_PG_TEXT_INDEX sys.exit(1) parser = OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-D', '--dsn', dest='dsn', default=None, help="dsn to connect to postgresql database") parser.add_option('-n', '--database-name', dest='database_name', default=None, help="Name of database to connect to") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") parser.add_option('-i', '--interval', dest='commit_interval', action="store", default=200, help="Commit every N transactions") options, args = parser.parse_args() if args: parser.error("Too many parameters: %s" % repr(args)) commit_interval = int(options.commit_interval) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) def output(msg): print msg try: index = PGTextIndex( get_weighted_textrepr, options.dsn, # "dbname=karl user=karl host=localhost password=karl", database_name=options.database_name ) if options.dry_run: transaction.abort() else: transaction.commit() # reindex_catalog commits its own transactions catalog = root.catalog catalog['texts'] = index reindex_catalog(root, commit_interval=commit_interval, dry_run=options.dry_run, output=output) except: transaction.abort() raise
def main(argv=sys.argv): logging.basicConfig() log.setLevel(logging.INFO) parser = OptionParser( description="Move content to another folder", usage="%prog [options] content_path dest_folder", ) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transaction") parser.add_option('-S', '--security-state', dest='security_state', default=None, help="Force workflow transition to given state. By " "default no transition is performed.") options, args = parser.parse_args() if len(args) != 2: parser.error("Source content and destination folder are required") config = options.config if not config: config = get_default_config() root, closer = open_root(config) try: move_content(root, args[0], args[1], options.security_state) except: transaction.abort() raise else: if options.dry_run: log.info("Aborting transaction.") transaction.abort() else: log.info("Committing transaction.") transaction.commit()
def main(): os.environ['PASTE_CONFIG_FILE'] = get_default_config() cmd = ServeCommand('karl') cmd.description = """\ Run the KARL application. If start/stop/restart is given, then --daemon is implied, and it will start (normal operation), stop (--stop-daemon), or do both. You can also include variable assignments like 'http_port=8080' and then use %(http_port)s in your config files. """ exit_code = cmd.run(sys.argv[1:]) sys.exit(exit_code)
def main(argv=sys.argv, root=None): parser = optparse.OptionParser(description=__doc__) parser.add_option( '-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option( '--assign-to', '-a', dest='assign_to', default='system', metavar='USER', help="Assign tags for missing users to USER (default: system)") parser.add_option('--dry-run', '-n', dest='dry_run', action='store_true', default=False, help="Don't actually commit any transaction") options, args = parser.parse_args(argv[1:]) logging.basicConfig() if root is None: config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: cleantags(root, options.assign_to) except: transaction.abort() raise else: if options.dry_run: print '*** aborting ***' transaction.abort() else: print '*** committing ***' transaction.commit()
def main(argv=sys.argv): parser = optparse.OptionParser( description=__doc__, usage="%prog [options] [user1, user2, ...]", ) parser.add_option( '-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option( '-f', '--filter', dest='filter', action='store_true', help='Limit results to users specified by username in stdin. Users' ' should be whitespace delimited.', default=False) options, args = parser.parse_args(argv[1:]) ids = None if options.filter: ids = sys.stdin.read().split() if args: if ids is not None: ids.extend(args) else: ids = args config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, name='karl') root, closer = get_root(app) out_csv = csv.writer(sys.stdout) out_csv.writerow(['username', 'community', 'last_activity']) for row in stats.user_activity_report(root, ids): username, community, last_activity = row out_csv.writerow([username, community.__name__, last_activity.ctime()])
def main(): parser = OptionParser(description=__doc__, usage='usage: %prog [options] username password') parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('--dry-run', '-n', dest='dry_run', action='store_true', default=False, help="Don't actually commit any transaction") path = '/' options, args = parser.parse_args() if args: path = args[0] config = options.config if config is None: config = get_default_config() root, closer = open_root(config) model = find_resource(root, path) def out(msg): sys.stderr.write(msg) sys.stderr.write('\n') sys.stderr.flush() try: reset_security_workflow(model, output=out) except: transaction.abort() raise else: if options.dry_run: print 'no transaction committed due to --dry-run' else: transaction.commit()
def main(argv=sys.argv): logging.basicConfig() logging.getLogger('karl').setLevel(logging.INFO) parser = optparse.OptionParser(description=__doc__) parser.add_option( '-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-c', '--communities', dest='communities', default='10', help='Number of communities to add (default 10)') parser.add_option('--dry-run', dest='dryrun', action='store_true', default=False, help="Don't actually commit the transaction") options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: add_sample_users(root) for i in range(int(options.communities)): add_sample_community(root, more_files=i == 0) except: transaction.abort() raise else: if options.dryrun: transaction.abort() else: transaction.commit()
def main(): parser = optparse.OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', default=None, help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-l', '--log-file', dest='log_file', default=None, help="log file name (default to stderr)") parser.add_option('--daemon', '-D', dest='daemon', action='store_true', default=False, help='Run in daemon mode.') parser.add_option('--frequency', '-f', dest='frequency', default='daily', help='Digest frequency: daily/weekly/biweekly.') parser.add_option('--interval', '-i', dest='interval', type='int', default=6*3600, help='Interval, in seconds, between executions when in ' 'daemon mode.') options, args = parser.parse_args() if options.log_file: logging.basicConfig(filename=options.log_file) else: logging.basicConfig() # log to stderr config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, 'karl') alerts = queryUtility(IAlerts, default=Alerts()) def run(): set_subsystem('digest') root, closer = get_root(app) alerts.send_digests(root, options.frequency) closer() if options.daemon: run_daemon('digest', run, options.interval) else: run()
def main(argv=sys.argv): logging.basicConfig() log.setLevel(logging.INFO) parser = OptionParser( description="Move content to another folder", usage="%prog [options] content_path dest_folder", ) parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transaction") parser.add_option('-S', '--security-state', dest='security_state', default=None, help="Force workflow transition to given state. By " "default no transition is performed.") options, args = parser.parse_args() if len(args) != 2: parser.error("Source content and destination folder are required") config = options.config if not config: config = get_default_config() root, closer = open_root(config) try: move_content(root, args[0], args[1], options.security_state) except: transaction.abort() raise else: if options.dry_run: log.info("Aborting transaction.") transaction.abort() else: log.info("Committing transaction.") transaction.commit()
def _parse_options(argv): parser = OptionParser( description="Import a Karl2 GenericSetup dump into Karl3. The " "import_source is the path to a Karl 2 dump", ) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transaction") parser.add_option('-L', '--link', dest='link', default=None, help="Check a single link") options, args = parser.parse_args() if args: parser.error() global config config = options.config if config is None: config = get_default_config() global dry_run dry_run = options.dry_run global check_link check_link = options.link print "check link:", check_link
def main(argv=sys.argv): config = None script = None if '-C' in argv: index = argv.index('-C') argv.pop(index) config = argv.pop(index) if len(argv) > 1: script = argv[1] if not config: config = get_default_config() root, closer = open_root(config) if script is None: cprt = ('Type "help" for more information. "root" is the karl ' 'root object.') banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt) interact(banner, local={'root': root}) else: code = compile(open(script).read(), script, 'exec') exec code in {'root': root}
def main(argv=sys.argv): config = None script = None if '-C' in argv: index = argv.index('-C') argv.pop(index) config = argv.pop(index) if len(argv) > 1: script = argv[1] if not config: config = get_default_config() root, closer = open_root(config) if script is None: cprt = ('Type "help" for more information. "root" is the karl ' 'root object.') banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt) interact(banner, local={'root':root}) else: code = compile(open(script).read(), script, 'exec') exec code in {'root': root}
def main(): parser = optparse.OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', default=None, help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-l', '--log-file', dest='log_file', default=None, help="log file name (default to stderr)") parser.add_option('--daemon', '-D', dest='daemon', action='store_true', default=False, help='Run in daemon mode.') parser.add_option('--interval', '-i', dest='interval', type='int', default=6*3600, help='Interval, in seconds, between executions when in ' 'daemon mode.') options, args = parser.parse_args() if options.log_file: logging.basicConfig(filename=options.log_file) else: logging.basicConfig() # log to stderr config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, 'karl') alerts = queryUtility(IAlerts, default=Alerts()) def run(): set_subsystem('digest') root, closer = get_root(app) alerts.send_digests(root) closer() if options.daemon: run_daemon('digest', run, options.interval) else: run()
def main(argv=sys.argv[1:]): parser = optparse.OptionParser(description=__doc__, usage='%prog [options] message') parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-L', '--level', dest='level', help='Log level: debug, info, warn or error', default='info') options, args = parser.parse_args(argv) if not args: parser.error("No message given.") config = options.config if config is None: config = get_default_config() root, closer = open_root(config) func = getattr(get_logger(), options.level, None) if func is None: parser.error("Bad level: %s" % options.level) func(' '.join(args))
def main(): parser = OptionParser(description=__doc__) parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") options, args = parser.parse_args() if args: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) peopledir = find_peopledirectory(root) reindex_peopledirectory(peopledir) if options.dry_run: transaction.abort() else: transaction.commit()
def main(): parser = OptionParser(description=__doc__, usage='usage: %prog [options] username password') parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('--dry-run', '-n', dest='dry_run', action='store_true', default=False, help="Don't actually commit any transaction") path = '/' options, args = parser.parse_args() if args: path = args[0] config = options.config if config is None: config = get_default_config() root, closer = open_root(config) model = find_resource(root, path) def out(msg): sys.stderr.write(msg) sys.stderr.write('\n') sys.stderr.flush() try: reset_security_workflow(model, output=out) except: transaction.abort() raise else: if options.dry_run: print 'no transaction committed due to --dry-run' else: transaction.commit()
def archive_console(): """ A console script which archives a community to the local filesystem. Used for testing. """ usage = "usage: %prog [options] community destination" parser = OptionParser(usage, description=__doc__) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() if len(args) < 2: parser.error("Not enough arguments.") community_name = args.pop(0) path = args.pop(0) if args: parser.error("Too many parameters: %s" % repr(args)) if os.path.exists(path): parser.error("Folder already exists: %s" % path) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) community = root['communities'].get(community_name) if not community: parser.error("No such community: %s" % community_name) realize_archive_to_fs(archive(community), os.path.abspath(path))
def main(): parser = OptionParser(description=__doc__, usage='usage: %prog [options] username password') parser.add_option('-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() try: username, password = args except ValueError: parser.error('Too many or too few args (need "username password"))') config = options.config if config is None: config = get_default_config() root, closer = open_root(config) try: adduser(root, username, password) except: transaction.abort() raise else: transaction.commit()
def main(args=sys.argv): if PGTextIndex is None: print >> sys.stderr, NO_PG_TEXT_INDEX sys.exit(1) parser = OptionParser(description=__doc__) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-D', '--dsn', dest='dsn', default=None, help="dsn to connect to postgresql database") parser.add_option('-n', '--database-name', dest='database_name', default=None, help="Name of database to connect to") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") parser.add_option('-i', '--interval', dest='commit_interval', action="store", default=200, help="Commit every N transactions") options, args = parser.parse_args() if args: parser.error("Too many parameters: %s" % repr(args)) commit_interval = int(options.commit_interval) config = options.config if config is None: config = get_default_config() root, closer = open_root(config) def output(msg): print msg try: index = PGTextIndex( get_weighted_textrepr, options. dsn, # "dbname=karl user=karl host=localhost password=karl", database_name=options.database_name) if options.dry_run: transaction.abort() else: transaction.commit() # reindex_catalog commits its own transactions catalog = root.catalog catalog['texts'] = index reindex_catalog(root, commit_interval=commit_interval, dry_run=options.dry_run, output=output) except: transaction.abort() raise
def main(argv=None): if argv is None: import sys argv = sys.argv parser = optparse.OptionParser( description=__doc__, formatter=HelpFormatter(), ) parser.add_option( '-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-f', '--force-reindex', dest='force_reindex', action='store_true', default=False, help="Reindex the people catalog unconditionally") parser.add_option('--dry-run', dest='dry_run', action='store_true', default=False, help="Don't actually commit the transaction") options, args = parser.parse_args(argv[1:]) if not args or args[0] not in ('dump', 'load'): parser.error("Must specify either 'dump' or 'load <filename>'" % repr(args)) kw = {} if args[0] == 'dump': if len(args) > 1: parser.error("Must specify either 'dump' or 'load <filename>'" % repr(args)) if options.force_reindex: parser.error("--force-reindex invalid for 'dump'") func = dump_peopleconf do_commit = False else: # 'load' if len(args) != 2: parser.error("Must specify either 'dump' or 'load <filename>'" % repr(args)) func = load_peopleconf kw['filename'] = args[1] if options.force_reindex: kw['force_reindex'] = True do_commit = not options.dry_run config = options.config if config is None: config = get_default_config() root, closer = open_root(config) func(root, **kw) if do_commit: transaction.commit()
def main(): parser = OptionParser(description=__doc__) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") parser.add_option('-d', '--dry-run', dest='dry_run', action="store_true", default=False, help="Don't commit the transactions") parser.add_option('-i', '--interval', dest='commit_interval', action="store", default=200, help="Commit every N transactions") parser.add_option( '-p', '--path', dest='path', action="store", default=None, metavar='EXPR', help="Reindex only objects whose path matches a regular expression") parser.add_option('-n', '--index', dest='indexes', action="append", help="Reindex only the given index (can be repeated)") options, args = parser.parse_args() if args: parser.error("Too many parameters: %s" % repr(args)) commit_interval = int(options.commit_interval) if options.path: path_re = re.compile(options.path) else: path_re = None config = options.config if config is None: config = get_default_config() root, closer = open_root(config) def output(msg): print msg kw = {} if options.indexes: kw['indexes'] = options.indexes reindex_catalog(root, path_re=path_re, commit_interval=commit_interval, dry_run=options.dry_run, output=output, **kw)
def _callFUT(self): from karl.scripting import get_default_config return get_default_config()
def setup(self): from karl.scripting import get_default_config from karl.scripting import open_root root, self.closer = open_root(get_default_config()) self.root = root._p_jar.root()
def main(argv=sys.argv, root=None, update_func=update_feeds, tx=transaction): parser = optparse.OptionParser(description=__doc__) parser.add_option( '-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('-f', '--force', dest='force', action='store_true', default=False, help='Update all feeds, even if unchanged') parser.add_option('--dry-run', dest='dryrun', action='store_true', default=False, help="Don't actually commit the transaction") parser.add_option('--daemon', '-D', dest='daemon', action='store_true', default=False, help='Run in daemon mode.') parser.add_option('--interval', '-i', dest='interval', type='int', default=300, help='Interval, in seconds, between executions when in ' 'daemon mode.') parser.add_option('--timeout', '-t', dest='timeout', type='int', default=None, help='Timeout, in seconds, for URL requests.') options, args = parser.parse_args(argv[1:]) if args: parser.error("Too many parameters: %s" % repr(args)) config = options.config if config is None: config = get_default_config() if root is None: app = loadapp('config:%s' % config, name='karl') #else: unit test def run(root=root): closer = lambda: None # unit test try: if root is None: root, closer = get_root(app) #else: unit test update_func(root, config, force=options.force) except: tx.abort() closer() raise else: if options.dryrun: tx.abort() else: tx.commit() closer() if options.timeout is not None: socket.setdefaulttimeout(options.timeout) if options.daemon: run_daemon('update_feeds', run, options.interval) else: run()
if set_version < 0: raise Exception except: usage('Bad version number %s' % v) if latest and (set_version is not None): usage('Cannot use both --latest and --set-version together') if set_version and not package: usage('Not setting db version to %s (specify --package to ' 'specify which package to set the db version for)' % set_version) # hook gsm for good measure and max fwd compat getSiteManager.sethook(get_current_registry) root, closer = open_root(get_default_config()) managers = list(getUtilitiesFor(IEvolutionManager)) if package and package not in [x[0] for x in managers]: usage('No such package "%s"' % package) for pkg_name, factory in managers: if (package is None) or (pkg_name == package): __import__(pkg_name) pkg = sys.modules[pkg_name] VERSION = pkg.VERSION print 'Package %s' % pkg_name manager = factory(root, pkg_name, VERSION, 0) db_version = manager.get_db_version() print 'Code at software version %s' % VERSION
def main(): parser = argparse.ArgumentParser( description="Add or remove KARL site-wide announcements", usage="%(prog)s command [options]") parser.add_argument('-C', '--config', dest="config", help="Specify a paster config file. Defaults to " "$CWD/etc/karl.ini", required=False, default=None) parser.add_argument('command', action='store', help='list, add, remove, clear-all, or clear-old', default='list') parser.add_argument('--text', action='store', dest='text', help='Text to add as a site announcement. Used only ' 'with the `add` command', required=False, default=None) parser.add_argument('--id', action='store', dest='id', type=int, help='ID (shown in `list` command) of announcement to ' 'remove. Used only with `remove` command.', required=False, default=None) parser.add_argument('--date', action='store', type=valid_date, help='Any site action added previous to this date ' '(YYYY/MM/DD) will be removed. Used only with ' 'the `clear-date` command.', dest='cleardate', required=False, default=None) parser.add_argument('-n', '--dry-run', action='store_true', default=False, help='Do everything except commit changes.', dest='dryrun', required=False) parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Print more information to stdout', required=False, dest='verbose') args = parser.parse_args() # CONFIG/SITE-CONTEXT config = args.config if config is None: config = get_default_config() root, closer = open_root(config) # EXEC COMMANDS cmd = args.command.strip().lower() try: if cmd == 'list': do_list(args, root) elif cmd == 'add': do_add(args, root) elif cmd == 'remove': do_remove(args, root) elif cmd == 'clear-all': do_clearall(args, root) elif cmd == 'clear-date': do_cleardate(args, root) except Exception as ex: if args.verbose: print ex else: print "Aborting due to exception" transaction.abort() sys.exit(0) # COMMIT/ABORT if args.dryrun: if args.verbose: print "Dry-run, aborting commit to database." transaction.abort() else: if args.verbose: print "Committing to database." transaction.commit()
def main2(argv=sys.argv[1:]): """ Version which uses repoze.postoffice. """ logging.basicConfig() parser = optparse.OptionParser( description=__doc__, usage="%prog [options] maildir_root", ) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('--dry-run', '-n', dest='dry_run', action='store_true', default=False, help="Don't actually commit any transaction") parser.add_option('--verbose', '-v', dest='verbose', action='store_true', default=False, help="Output info level logging.") parser.add_option('--daemon', '-D', dest='daemon', action='store_true', default=False, help='Run in daemon mode.') parser.add_option('--interval', '-i', dest='interval', type='int', default=300, help='Interval, in seconds, between executions when in ' 'daemon mode.') options, args = parser.parse_args(argv) if args: parser.error('Unknown arguments: %s' % ' '.join(args)) config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, name='karl') log_level = logging.WARN if options.verbose: log_level = logging.INFO logging.getLogger('karl.mailin').setLevel(log_level) def run(): root, closer = get_root(app) 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: parser.error("postoffice.zodb_uri must be set in config file") if queue is None: parser.error("postoffice.queue must be set in config file") runner = MailinRunner2(root, zodb_uri, zodb_path, queue) try: runner() if options.dry_run: transaction.abort() else: 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() runner.close() if options.daemon: run_daemon('mailin', run, options.interval) else: run()
def main(argv=sys.argv, factory=MailinRunner, root=None): parser = optparse.OptionParser( description=__doc__, usage="%prog [options] maildir_root", ) parser.add_option('-C', '--config', dest='config', help='Path to configuration file (defaults to $CWD/etc/karl.ini)', metavar='FILE') parser.add_option('--dry-run', '-n', dest='dry_run', action='store_true', default=False, help="Don't actually commit any transaction") parser.add_option('--quiet', '-q', dest='verbosity', action='store_const', const=0, default=1, help="Quiet: no extraneous output") parser.add_option('--verbose', '-v', dest='verbosity', action='count', help="Increase verbosity of output") parser.add_option('--pending-queue', '-p', dest='pq_file', help="Path to the repoze.mailin IPendingQueue db " "(default, '%{maildir_root}s/pending.db')") parser.add_option('--log-file', '-l', dest='log_file', default='log/mailin.log', help="Log file name (default, 'log/mailin.log')") parser.add_option('--default-tool', '-t', dest='default_tool', default=None, help="Name of the default tool to handle new " "content, if none is supplied in the 'To:' " "address (default, None).") parser.add_option('--text-scrubber', '-s', dest='text_scrubber', help="Name of the utlity (implementing " "karl.utilities.interfaces.IMailinTextScrubber) " "used to scrub text of mail-in content.") parser.add_option('--draino', '-d', dest='run_draino', action='store_true', default=False, help="Run draino command before processing mailin.") parser.add_option('--daemon', '-D', dest='daemon', action='store_true', default=False, help='Run in daemon mode.') parser.add_option('--interval', '-i', dest='interval', type='int', default=300, help='Interval, in seconds, between executions when in ' 'daemon mode.') options, args = parser.parse_args(argv[1:]) if len(args) != 1: parser.error('Please pass exactly one maildir_root parameter') maildir_root = args[0] if not os.path.isdir(maildir_root): parser.error('Not a directory: %s' % maildir_root) maildir = os.path.join(maildir_root, 'Maildir') if not os.path.isdir(maildir): parser.error('Not a directory: %s' % maildir) contents = os.listdir(maildir) for sub in ('cur', 'new', 'tmp'): if not sub in contents: parser.error('Not a maildir: %s' % maildir) if options.pq_file is None: options.pq_file = os.path.join(maildir_root, 'pending.db') if root is None: config = options.config if config is None: config = get_default_config() app = loadapp('config:%s' % config, name='karl') #else: unit test def run(root=root): closer = lambda: None # unit test if options.run_draino: draino_args = ['draino', '-vvv', '-p', '%s/Maildir' % maildir_root, maildir_root] if options.dry_run: draino_args.insert(1, '--dry-run') draino = Draino(draino_args) if root is None: root, closer = get_root(app) #else: unit test set_subsystem('mailin') if options.run_draino: draino.run() runner = factory(root, maildir_root, options) runner() p_jar = getattr(root, '_p_jar', None) if p_jar is not None: # Attempt to fix memory leak p_jar.db().cacheMinimize() closer() if options.daemon: run_daemon('mailin', run, options.interval) else: run()
def worker(): """ Console script which connects to Redis and pops one unit of work off of either the copy queue or the remove queue and performs the required operation. If no work is queued for it to do, it will block, waiting for work. This command does not loop. Once one community is copied or removed, the command exits. The intent is that for looping behavior, this can be run from supervisor which will automatically restart the command after it exits. This insures that all connection caches, etc, are cleaned up on each iteration. """ logging.basicConfig(level=logging.INFO) usage = "usage: %prog [options]" parser = OptionParser(usage, description=__doc__) parser.add_option( '-C', '--config', dest='config', default=None, help="Specify a paster config file. Defaults to $CWD/etc/karl.ini") options, args = parser.parse_args() if args: parser.error("Too many arguments.") config = options.config if config is None: config = get_default_config() root, closer = open_root(config) registry = get_current_registry() queue = RedisArchiveQueue.from_settings(registry.settings) closer() log.info("Waiting for work.") operation, community = next(work_queue(queue, config)) log.info("Got work.") with persistent_log(community) as plog: try: if operation == queue.COPY_QUEUE_KEY: log.info("Copy to box: %s", community.title) copy_community_to_box(community) elif operation == queue.MOTHBALL_QUEUE_KEY: log.info("Mothball: %s", community.title) mothball_community(community) else: log.warn("unknown operation: %s", operation) transaction.commit() log.info('Finished job.') except: log.error('Error during archive.', exc_info=True) transaction.abort() # Save the exception status in its own transaction community.archive_status = 'exception' raise finally: # Persist log in its own transaction so that even if there is an # error we get a log community.archive_log = plog plog.save() transaction.commit()