Example #1
0
def setup_path_and_args():
    """ 
    This uses base.py to setup the correct paths, in case
    this is being called on the command line and not being
    imported. It also uses base.py to get all of the command line
    arguments.  It then processes the additional args.

    Returns a dictionary of the extra args we are reading from the
    command line.  This gets passed to our main function (init_db).
    """
    extra_news_items = 0
    extra_comments = 0
    create_new_objects = False

    opts = base.get_paths_options("e:c:X", ["extra-news=", "extra-comments=", "create-new"], 
            usage)

    for opt, arg in opts:
        if opt in ("--extra-news", "-e"):
            extra_news_items = base.get_int_arg(arg,
                    "ERROR! Argument to --extra-news must be a non-negative integer.",
                    usage)
        elif opt in ("--extra-comments", "-c"):
            extra_comments = base.get_int_arg(arg,
                    "ERROR! Argument to --extra-comments must be a non-negative integer.",
                    usage)
        elif opt in ("--create-new", "-X"):
            create_new_objects = True

    return {'extra_news_items':extra_news_items, 'extra_comments':extra_comments,
            'create_new_objects': create_new_objects}
Example #2
0
def setup_path_and_args():
    """ 
    This uses base.py to setup the correct paths, in case
    this is being called on the command line and not being
    imported. It also uses base.py to get all of the command line
    arguments.  It then processes the additional args.

    Returns a dictionary of the extra args we are reading from the
    command line.  This gets passed to our main function (init_db).
    """
    milliseconds = 500
    daemonize = False
    

    opts = base.get_paths_options("s:d", ["milliseconds=", "daemonize"], usage)

    for opt, arg in opts:
        if opt in ("--milliseconds", "-s"):
            milliseconds = base.get_int_arg(arg,
                    "ERROR! Argument to --milliseconds must be a positive integer.",
                    usage, must_be_pos=True)
        elif opt in ("-d", "--daemonize"):
            daemonize = True

    return {'milliseconds':milliseconds, 'daemonize':daemonize}