Esempio n. 1
0
def test_mw_unres():
    def unres_cmd(unresolved_arg):
        return unresolved_arg

    cmd = Command(unres_cmd)
    assert cmd.func is unres_cmd

    with pytest.raises(
            NameError,
            match=
            "unresolved middleware or handler arguments: .*unresolved_arg.*"):
        cmd.run(['unres_cmd'])

    def inner_mw(next_, arg):
        return next_()

    @face_middleware(provides='arg', flags=[Flag('--verbose', parse_as=True)])
    def outer_mw(next_):
        return next_(arg=1)

    def ok_cmd(arg):
        return None

    cmd = Command(ok_cmd, middlewares=[outer_mw])
    cmd.add_middleware(inner_mw)

    with pytest.raises(
            NameError,
            match=
            "unresolved middleware or handler arguments: .*arg.* check middleware order."
    ):
        cmd.run(['ok_cmd'])
    return
Esempio n. 2
0
def main(argv=None):
    cmd = Command(name='pacetrack', func=None)

    # subcommands
    update_subcmd = Command(update, posargs={'min_count': 1, 'display': 'campaign_id', 'provides': 'campaign_ids'})
    # update_subcmd.add('campaign_name')
    cmd.add(update_subcmd)
    cmd.add(update_all)
    cmd.add(render_all)
    cmd.add(list_campaigns)
    cmd.add(print_version, name='version')
    # cmd.add(prune)  # mostly for testing

    cmd.add('--jsub', parse_as=True, doc='run commands through the WMF Labs job grid (for production use only)')
    cmd.add('--force', parse_as=True, doc='ignore configured fetch frequency and force updates')
    cmd.add('--dry-run', parse_as=True, doc='log actions without performing them (e.g., do not remove files)')

    # flags
    cmd.add('--debug', doc='increase logging level', parse_as=True, missing=DEBUG)

    # middlewares
    cmd.add(mw_cli_log)

    try:
        cmd.run()
    except Exception:
        # TODO: once face is stable, this can become part of the middleware
        if os.getenv('PACETRACK_ENABLE_DEBUG'):
            import pdb;pdb.post_mortem()
        raise
Esempio n. 3
0
def test_next_reserved():
    def bad_cmd(next_):
        return

    cmd = Command(bad_cmd)

    with pytest.raises(NameError):
        cmd.run(['bad_cmd'])
def test_help_subcmd():
    hhandler = HelpHandler(flag=False, subcmd='help')
    cmd = Command(None, 'cmd', help=hhandler)

    try:
        cmd.run(['cmd', 'help'])
    except SystemExit as se:
        assert se.code == 0

    with pytest.raises(ValueError, match='requires a handler function or help handler'):
        Command(None, help=None)
Esempio n. 5
0
def main():
    cmd = Command(name='chert', func=None)

    cmd.add(init, posargs={'count': 1, 'name': 'target_dir'})
    cmd.add(serve)
    cmd.add(render)
    cmd.add(publish)
    cmd.add(clean)
    cmd.add(version)

    # cmd.add('--target-dir', doc='path to generate new chert site')

    cmd.add(_cur_input_path_mw)
    cmd.run()
Esempio n. 6
0
def main():
    cmd = Command(cut_mp4)

    cmd.add('--input', missing=ERROR, doc='path to the input mp4 file')
    cmd.add('--output', missing=ERROR, doc='path to write the output mp4 file')
    cmd.add('--start', doc='starting timestamp in hh:mm:ss format')
    cmd.add('--end', doc='ending timestamp in hh:mm:ss format')

    cmd.add('--no-align-keyframes',
            parse_as=True,
            doc="don't align to the nearest keyframe, potentially"
            " creating an unclean cut with video artifacts")

    cmd.run()
Esempio n. 7
0
File: cli.py Progetto: mahmoud/chert
def main():
    cmd = Command(name='chert', func=None)

    cmd.add(init, posargs={'min_count': 1, 'max_count': 1, 'display': 'target_dir', 'provides': 'target_dir'})
    cmd.add(serve)
    cmd.add(render)
    cmd.add(publish)
    cmd.add(clean)
    cmd.add(version)

    # cmd.add('--target-dir', doc='path to generate new chert site')

    cmd.add(_cur_input_path_mw)
    cmd.run()
Esempio n. 8
0
def main():
    cmd = Command(busy_loop, 'cmd', middlewares=[output_streams_mw])

    sum_subcmd = Command(sum_func, 'sum')
    sum_subcmd.add(
        '--num',
        parse_as=ListParam(int),
        missing=(0, ),
        doc='a number to include in the sum, expects integers at the moment'
        ' because it is fun to change things later')
    sum_subcmd.add(
        '--grummmmmmmmmmmmmmmmmmm',
        parse_as=int,
        multi=True,
        missing=0,
        doc='a bizarre creature, shrek-like, does nothing, but is here to'
        ' make the help longer and less helpful but still good for wraps.')

    cmd.add(sum_subcmd)

    cmd.add(verbose_mw)

    cmd.add(subtract, doc='', posargs=float)

    cmd.add(print_args, 'print', '', posargs=True)

    cmd.add('--loop-count', parse_as=int)

    return cmd.run()  # execute
Esempio n. 9
0
def main():
    cmd = Command(cut_mp4)

    cmd.add('--input', missing=ERROR, doc='path to the input mp4 file')
    cmd.add('--output', missing=ERROR, doc='path to write the output mp4 file')
    cmd.add('--start', doc='starting timestamp in hh:mm:ss format')
    cmd.add('--end', doc='ending timestamp in hh:mm:ss format')

    cmd.add('--filter-audio',
            parse_as=True,
            doc='do high-pass/low-pass noise filtration of audio.'
            ' good for noisy meetup recordings.')
    cmd.add('--no-align-keyframes',
            parse_as=True,
            doc="don't align to the nearest keyframe, potentially"
            " creating an unclean cut with video artifacts")

    cmd.run()
Esempio n. 10
0
def main(argv):
    posargs = PosArgSpec(str, max_count=2, display={'label': '[spec [target]]'})
    cmd = Command(glom_cli, posargs=posargs, middlewares=[mw_get_target])
    cmd.add('--target-file', str, missing=None, doc='path to target data source')
    cmd.add('--target-format', str, missing='json',
            doc='format of the source data (json or python)')
    cmd.add('--spec-file', str, missing=None, doc='path to glom spec definition')
    cmd.add('--spec-format', str, missing='python',
            doc='format of the glom spec definition (json, python, python-full)')

    cmd.add('--indent', int, missing=2,
            doc='number of spaces to indent the result, 0 to disable pretty-printing')

    cmd.add('--debug', parse_as=True, doc='interactively debug any errors that come up')
    cmd.add('--inspect', parse_as=True, doc='interactively explore the data')

    return cmd.run(argv) or 0
Esempio n. 11
0
def main(argv):
    posargs = PosArgSpec(str,
                         max_count=2,
                         display={'label': '[spec [target]]'})
    cmd = Command(glom_cli, posargs=posargs, middlewares=[mw_get_target])
    cmd.add('--target-file',
            str,
            missing=None,
            doc='path to target data source')
    cmd.add('--target-format',
            str,
            missing='json',
            doc='format of the source data (json or python)')
    cmd.add('--spec-file',
            str,
            missing=None,
            doc='path to glom spec definition')
    cmd.add(
        '--spec-format',
        str,
        missing='python',
        doc='format of the glom spec definition (json, python, python-full)')

    cmd.add(
        '--indent',
        int,
        missing=2,
        doc=
        'number of spaces to indent the result, 0 to disable pretty-printing')

    cmd.add('--debug',
            parse_as=True,
            doc='interactively debug any errors that come up')
    cmd.add('--inspect', parse_as=True, doc='interactively explore the data')

    return cmd.run(argv) or 0
Esempio n. 12
0
def main(argv=None):
    """\
    automation and analytics for curated lists of awesome software.

    Normal analysis workflow:

      * apatite pull-repos  (can take 3-4 hours, 25GB on the full APA, use --targets to limit)
      * apatite collect-metrics
      * apatite export-metrics
      * apatite analyze  # TODO
    """
    cmd = Command(name='apatite', func=None,
                  doc=main.__doc__)  # func=None means output help

    # add flags
    cmd.add('--file',
            missing='projects.yaml',
            doc='path to the project listing YAML file')
    cmd.add(
        '--confirm',
        parse_as=True,
        doc='show diff and prompt for confirmation before modifying the file')
    cmd.add(
        '--non-interactive',
        parse_as=True,
        doc=
        'disable falling back to interactive authentication, useful for automation'
    )
    cmd.add('--targets',
            parse_as=ListParam(str),
            missing=[],
            doc='specific target projects')
    cmd.add('--metrics',
            parse_as=ListParam(str),
            missing=[],
            doc='specific metrics to collect')
    cmd.add('--dry-run', parse_as=True, doc='do not save results')
    two_weeks_ago = _date_param('-2w')
    cmd.add(
        '--earliest',
        parse_as=_date_param,
        missing=two_weeks_ago,
        doc=(
            'minimum datetime value to accept (isodate or negative timedelta).'
            ' defaults to two weeks ago (-2w)'))
    cmd.add('--no-progress', parse_as=True)

    # add middlewares, outermost first ("first added, first called")
    cmd.add(mw_exit_handler)
    cmd.add(mw_ensure_project_listing)
    cmd.add(mw_ensure_work_dir)

    # add subcommands
    cmd.add(render)
    cmd.add(normalize)
    cmd.add(pull_repos)
    cmd.add(collect_metrics)
    cmd.add(show_recent_metrics)
    cmd.add(export_metrics)
    cmd.add(show_exportable_metrics)
    cmd.add(set_repo_added_dates)
    cmd.add(console)
    cmd.add(print_version, name='version')

    cmd.prepare(
    )  # an optional check on all subcommands, not just the one being executed

    try:
        cmd.run(argv=argv)  # exit behavior is handled by mw_exit_handler
    except Exception:
        if os.getenv('APATITE_DEBUG'):
            import pdb
            pdb.post_mortem()
        raise

    return
Esempio n. 13
0
def main():
    """
    The main entrypoint, setting up a face application, with middleware, common flags, and subcommands.
    """
    cmd = Command(name='montage-admin',
                  func=None,
                  doc="CLI tools for administrating Montage.")

    # middleware
    cmd.add(_admin_dao_mw)
    cmd.add(_rdb_session_mw)

    cmd.add('--username', missing=ERROR)
    cmd.add('--debug',
            parse_as=True,
            doc='get extra output, enable debug console before db commit')
    cmd.add('--force',
            parse_as=True,
            doc='skip some confirmations, use with caution')
    cmd.add('--campaign-id', parse_as=int, missing=ERROR)
    cmd.add('--round-id', parse_as=int, missing=ERROR)
    cmd.add('--csv-path', missing=ERROR)
    cmd.add('--url', missing=ERROR)

    cmd.add(
        add_organizer
    )  # , posargs={'count': 1, 'name': 'username'})  # TODO: figure out if we want posarg/flag overriding

    ser_cmd = Command(name='series',
                      func=None,
                      doc='tools for administrating Montage series')
    ser_cmd.add(add_series, name='add')

    cmd.add(ser_cmd)

    cmp_cmd = Command(name='campaign',
                      func=None,
                      doc='tools for administrating Montage campaigns')
    cmp_cmd.add(list_campaigns, name='list')
    cmp_cmd.add(create_campaign, name='create')
    cmp_cmd.add(add_coordinator, name='add-coordinator')
    cmp_cmd.add(cancel_campaign, name='cancel')
    cmp_cmd.add(backfill_series)

    cmd.add(cmp_cmd)

    rnd_cmd = Command(name='round',
                      func=None,
                      doc='tools for administrating Montage rounds')
    rnd_cmd.add(create_round, name='create')
    rnd_cmd.add(import_gist, name='import-gist')
    rnd_cmd.add(activate_round, name='activate')
    rnd_cmd.add(pause_round, name='pause')
    rnd_cmd.add(advance_round, name='advance')
    rnd_cmd.add(edit_round_quorum, name='edit-quorum')
    rnd_cmd.add(check_round_dupes, name='check-dupes')
    rnd_cmd.add(apply_round_ratings, name='apply-ratings')
    rnd_cmd.add(retask_duplicate_ratings, name='retask-dupes')
    rnd_cmd.add(shuffle_round_assignments, name='shuffle-tasks')
    rnd_cmd.add(cancel_round, name='cancel')

    cmd.add(rnd_cmd)

    cmd.add(rdb_console)
    cmd.prepare()
    return cmd.run()