コード例 #1
0
ファイル: cmdline.py プロジェクト: wari/phil
def main(argv):
    if '-q' not in argv and '--quiet' not in argv:
        phil.out(BYLINE)

    parser = argparse.ArgumentParser(
        description=phil.wrap_paragraphs(
            'phil allows you to set up email reminders for meetings.'
            '\n\n'
            'This program comes with ABSOLUTELY NO WARRANTY.  '
            'This is free software and you are welcome to redistribute it'
            'under the terms of the GPLv3.'),
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument(
        '-q', '--quiet',
        action='store_true',
        default=False,
        help='runs phil quietly--only prints errors')

    parser.add_argument(
        '--debug',
        action='store_true',
        default=False,
        help='runs phil in debug mode--no sending email.')

    subparsers = parser.add_subparsers(
        title='Commands',
        help='Run "%(prog)s CMD --help" for additional help')

    createfile_parser = subparsers.add_parser(
        'createfile', help='rreates a configuration file')
    createfile_parser.add_argument(
        'conffile',
        help='name/path for the configuration file')
    createfile_parser.set_defaults(func=createfile_cmd)

    run_parser = subparsers.add_parser(
        'run', help='runs phil on the given configuration file')
    run_parser.add_argument(
        'runconffile',
        help='name/path for the configuration file')
    run_parser.set_defaults(func=run_cmd)

    next6_parser = subparsers.add_parser(
        'next6', help='tells you next 6 dates for an event')
    next6_parser.add_argument(
        'runconffile',
        help='name/path for the configuration file')
    next6_parser.set_defaults(func=next6_cmd)

    parsed = parser.parse_args(argv)

    return parsed.func(parsed)
コード例 #2
0
ファイル: cmdline.py プロジェクト: B-Rich/phil
def createfile_cmd(parsed):
    outfile = parsed.conffile
    path = os.path.abspath(outfile)
    conffile = phil.get_template()
    if os.path.exists(path):
        phil.err("{0} exists.  Remove it and try again or try again with " "a different filename.".format(outfile))
        return 1

    f = open(path, "w")
    f.write(conffile)
    f.close()

    phil.out("{0} written.  Open it in your favorite editor and read it.".format(outfile))
    return 0
コード例 #3
0
ファイル: cmdline.py プロジェクト: wari/phil
def createfile_cmd(parsed):
    outfile = parsed.conffile
    path = os.path.abspath(outfile)
    conffile = phil.get_template()
    if os.path.exists(path):
        phil.err('{0} exists.  Remove it and try again or try again with '
                 'a different filename.'.format(outfile))
        return 1

    f = open(path, 'w')
    f.write(conffile)
    f.close()

    phil.out('{0} written.  Open it in your favorite editor and read it.'
        .format(outfile))
    return 0
コード例 #4
0
ファイル: cmdline.py プロジェクト: B-Rich/phil
def main(argv):
    if "-q" not in argv and "--quiet" not in argv:
        phil.out(BYLINE)

    parser = argparse.ArgumentParser(
        description=phil.wrap_paragraphs(
            "phil allows you to set up email reminders for meetings."
            "\n\n"
            "This program comes with ABSOLUTELY NO WARRANTY.  "
            "This is free software and you are welcome to redistribute it"
            "under the terms of the GPLv3."
        ),
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    parser.add_argument(
        "-q", "--quiet", action="store_true", default=False, help="runs phil quietly--only prints errors"
    )

    parser.add_argument(
        "--debug", action="store_true", default=False, help="runs phil in debug mode--no sending email."
    )

    subparsers = parser.add_subparsers(title="Commands", help='Run "%(prog)s CMD --help" for additional help')

    createfile_parser = subparsers.add_parser("createfile", help="rreates a configuration file")
    createfile_parser.add_argument("conffile", help="name/path for the configuration file")
    createfile_parser.set_defaults(func=createfile_cmd)

    run_parser = subparsers.add_parser("run", help="runs phil on the given configuration file")
    run_parser.add_argument("runconffile", help="name/path for the configuration file")
    run_parser.set_defaults(func=run_cmd)

    next6_parser = subparsers.add_parser("next6", help="tells you next 6 dates for an event")
    next6_parser.add_argument("runconffile", help="name/path for the configuration file")
    next6_parser.set_defaults(func=next6_cmd)

    parsed = parser.parse_args(argv)

    return parsed.func(parsed)