示例#1
0
def cli():
    parser_main = ArgumentParser()
    parser_main.set_defaults(func=parser_main.print_usage)
    sub_parsers = parser_main.add_subparsers(help='sub-command')

    # main_parser

    # sub_parser: img
    parser_img = sub_parsers.add_parser('image',
                                        help='convert image file format')

    parser_img.add_argument('path', nargs='?', help='image file path')
    parser_img.add_argument('-o', '--outdir', help='output directory')
    parser_img.add_argument('-ext',
                            '--ext',
                            help='to this format like png gif ...')

    parser_img.set_defaults(func=main_img)

    # sub_parser: info
    parser_info = sub_parsers.add_parser('info', help='recognise file format')
    parser_info.add_argument('path', nargs='?', help='file path')

    parser_info.set_defaults(func=main_info)

    parse_result = parser_main.parse_args()
    args = remove_value(remove_key(parse_result.__dict__, 'func'), None)
    try:
        parse_result.func(**args)
    except Exception as ex:
        color.print_err(type(ex), ex)
        color.print_err('Invalid args')
示例#2
0
def cli():
    parser_main = ArgumentParser()
    parser_main.set_defaults(func=parser_main.print_usage)
    sub_parsers = parser_main.add_subparsers(help='sub-command')

    # main_parser


    # sub_parser: img
    parser_img = sub_parsers.add_parser('image', help='convert image file format')

    parser_img.add_argument('path', nargs='?', help='image file path')
    parser_img.add_argument('-o', '--outdir', help='output directory')
    parser_img.add_argument('-ext', '--ext',
                            help='to this format like png gif ...')

    parser_img.set_defaults(func=main_img)

    # sub_parser: info
    parser_info = sub_parsers.add_parser('info', help='recognise file format')
    parser_info.add_argument('path', nargs='?', help='file path')

    parser_info.set_defaults(func=main_info)

    parse_result = parser_main.parse_args()
    args = remove_value(remove_key(parse_result.__dict__, 'func'), None)
    try:
        parse_result.func(**args)
    except Exception as ex:
        color.print_err(type(ex), ex)
        color.print_err('Invalid args')
示例#3
0
def shell_interactive():
    parser = ArgumentParser(description='find max size file')

    parser.add_argument('--trace', type=int, choices=[0, 1, 2],
                        help=('about print 0->close;1->only dir;2-> add file'
                              'default close-0'))

    parser.add_argument('-n', '--topnum', type=int,
                        help='the number of file which will be echoed ')

    parser.add_argument('-.', '--extname',
                        help='default search any form of file such as .py')

    parser.add_argument('-p', '--path', dest='dirname', default=os.curdir,
                        help='searched dir')

    parser.add_argument('--quick', action='store_true', default=True,
                        help=('if open the quick search mod (ignore the line search)'
                              'default true'))

    parser.add_argument('-pat', '--pattern',
                        help='regular matching file name')

    args = parser.parse_args()

    from minghu6.algs.userdict import remove_value
    return remove_value(args.__dict__, None)
示例#4
0
def shell_interactive():
    parser = ArgumentParser()

    parser.add_argument('--repl', dest='clojure_repl_flag', action='store_true',
                        help='start clojure repl')

    parser.add_argument('iteral', metavar='other_args', nargs='*',
                        help='Nore: use -- to pass the args start with -/-- ')

    parser.add_argument('--config_file',
                        help='point to the config file path ')
    parser.add_argument('--alias',
                        help='point to the config file\'s alias')

    parser.add_argument('--use',
                        help='use alias of config_file')

    parser.add_argument('-c', '--compile', dest='__compile', action='store_true',
                        help='compile thr progeam use alias config')

    parser.add_argument('-m', '--main',
                        help='point to the main func manualy for run program')

    parser.add_argument('-l', '--list', dest='view_files', metavar='alias_names',
                        nargs='+',
                        help='list the config file accoding to alias,'
                             '* for all')

    parser.add_argument('-sl', '--shortlist', action='store_true',
                        help='short list all the ini file name')

    parser.add_argument('--update', dest='update_files', metavar='alias_names',
                        nargs='+',
                        help='update the config file accoding to alias,'
                             '* for all')
    # rm!! care!!
    parser.add_argument('-rm', '--remove', dest='remove_files',
                        metavar='alias_names',
                        nargs='+',
                        help='rm the record (do not rm the physical file)')

    parser.add_argument('--refind', dest='refind_list', metavar='[clojure|python|*]',
                        nargs='+',
                        help='refind some confirm config such as clojure jar')

    args = parser.parse_args()

    # print(args.iteral)

    if args.clojure_repl_flag:
        args.__dict__['run_clojure_flag'] = False

    from minghu6.algs.userdict import remove_value
    return remove_value(args.__dict__, None)
示例#5
0
def interactive():
    import argparse
    from ast import literal_eval as eval

    parser = argparse.ArgumentParser()

    parser.add_argument('-C', '--C', type=eval, default=0,
                        help='z_k+1=z_k^power+C')

    parser.add_argument('-p', '--power', type=eval, default=2,
                        help='z_k+1=z_k^power+C')

    parser.add_argument('-x', '--x', dest='cx', type=int, default=0,
                        help='cx')

    parser.add_argument('-y', '--y', dest='cy', type=int, default=0,
                        help='cy')

    parser.add_argument('-d', '--d', type=eval, default=2.5,
                        help='(cx-d,cx+d) (cy-d,cy+d)')

    parser.add_argument('-e', '--escape_radius', type=eval, default=2,
                        help=('Escape Radius,default 2 \n'
                              'Do not change'))

    parser.add_argument('-n', '--iter_num', type=int, default=100,
                        help='Max number of iter times')

    parser.add_argument('-f', '--func', dest='draw_func',
                        choices=['normal', 'mpich'],
                        help='select kind of exec,default(normal)')

    args = parser.parse_args()

    global draw_func
    if args.draw_func is not None:
        if args.draw_func == 'normal':
            draw_func = draw_mandelbrot
        elif args.draw_func == 'mpich':
            draw_func = draw_mandelbrot_mpich
        else:
            raise Exception('args f error')
    else:
        draw_func = draw_mandelbrot

    from minghu6.algs.userdict import remove_key, remove_value
    args = remove_value(remove_key(args.__dict__, 'draw_func'), None)

    return args
示例#6
0
def cli():
    parser_main = ArgumentParser(prog='captcha',
                                 description='A captcha processor')
    parser_main.set_defaults(func=parser_main.print_usage)
    sub_parsers = parser_main.add_subparsers(help='main-sub-command')

    # main_parser

    ################################################################################
    # sub_parser: preprocessing
    parser_preprocessing = sub_parsers.add_parser(
        'preproc', help='preprocessing the image')

    parser_preprocessing.add_argument(
        'path', nargs='?', help='image file path(exclude image url)')

    parser_preprocessing.add_argument('-o',
                                      '--outdir',
                                      help='output directory default curdir')
    parser_preprocessing.add_argument(
        '-m',
        '--method',
        dest='preprocessing_method',
        nargs='?',
        required=True,
        choices=['binary', 'clear_noise', 'sharpen', 'remove_frame'],
        help='preprocessing method')
    parser_preprocessing.add_argument(
        '-w',
        '--width',
        required=False,
        help='frame width to remove(default 2 pix)')

    parser_preprocessing.set_defaults(func=main_preprocessing)

    ################################################################################
    # sub_parser: train
    parser_train = sub_parsers.add_parser('train',
                                          help='train the captcha data')
    train_sub_parsers = parser_train.add_subparsers(help='train-sub-command')
    # train_sub_parser: get_raw
    parser_train_getRawCaptcha = train_sub_parsers.add_parser(
        'get_raw', help='get the raw captcha data')

    parser_train_getRawCaptcha.add_argument('url',
                                            nargs='?',
                                            help='raw captcha url')

    parser_train_getRawCaptcha.add_argument('-n',
                                            '--num',
                                            type=int,
                                            help='the number of raw captcha')

    parser_train_getRawCaptcha.add_argument(
        '-o', '--outdir', help='output directory default curdir')

    parser_train_getRawCaptcha.set_defaults(func=train_get_raw)

    ## train_sub_parser: train_cmd
    parser_train_trainCmd = train_sub_parsers.add_parser(
        'train_cmd', help='create train cmd file')

    parser_train_trainCmd.add_argument('-l', '--language', help='language')
    parser_train_trainCmd.add_argument('-font', '--font', help='font name')
    parser_train_trainCmd.add_argument('-o',
                                       '--outdir',
                                       help='output directory default curdir')
    parser_train_trainCmd.add_argument('-shell',
                                       '--shell',
                                       dest='shell_type',
                                       choices=['cmd', 'bash'],
                                       help='cmd shell type')

    parser_train_trainCmd.set_defaults(func=train_train_cmd)
    ################################################################################
    # sub_parser: split
    parser_split = sub_parsers.add_parser('split', help='split the image')
    parser_split.add_argument('path',
                              nargs='?',
                              help='image file path(exclude image url)')

    parser_split.add_argument('-n',
                              '--num',
                              type=int,
                              help='point the number of char of img')

    parser_split.add_argument('-m',
                              '--method',
                              dest='split_method',
                              choices=['bisect', 'boxsplit'],
                              help='split method (default bisect)')

    parser_split.add_argument('-o',
                              '--outdir',
                              help='output directory default curdir')
    parser_split.set_defaults(func=main_split)

    ################################################################################

    # sub_parser: recognise
    parser_recognise = sub_parsers.add_parser('recognise',
                                              help='recognise the captcha')

    recognise_sub_parsers = parser_recognise.add_subparsers(
        help='recognise-sub-command')

    ## recognise_sub_parser: tesseract
    parser_recognise_tesseract = recognise_sub_parsers.add_parser(
        'tesseract', help='recognise the captcha using tesseract')
    parser_recognise_tesseract.add_argument(
        'path', nargs='?', help='image file path(exclude image url)')
    parser_recognise_tesseract.add_argument(
        '-args', type=str, help='equivalent tesseract "args" stdout ')

    parser_recognise_tesseract.set_defaults(func=recognise_tesseract)

    ################################################################################

    # sub_parser: fetch
    parser_fetch = sub_parsers.add_parser('fetch', help='fetch captcha batch')

    parser_fetch.add_argument('url', help='captcha url')

    parser_fetch.add_argument('-n',
                              '--num',
                              type=int,
                              required=True,
                              help='fetch number')

    parser_fetch.add_argument('-o',
                              '--outdir',
                              default=os.curdir,
                              help='captcha store path')

    parser_fetch.add_argument('-ext',
                              '--ext',
                              help='captcha ext, such as .png')
    parser_fetch.add_argument(
        '-p',
        '--pattern',
        dest='captcha_pattern',
        default='$(UUID)',
        help=('captcha name pattern, support macro UUID and NO\n'
              'such as $(UUID)_download, '
              'download_$(UUID), '
              '$(UUID)_$(NO) etc.'))

    parser_fetch.set_defaults(func=main_fetch)

    ################################################################################
    parse_result = parser_main.parse_args()
    # remove_key(parse_result.__dict__, 'func'),
    args = remove_value(remove_key(parse_result.__dict__, 'func'), None)
    parse_result.func(**args)
示例#7
0
def shell_interactive():
    parser = ArgumentParser()

    parser.add_argument('--repl',
                        dest='clojure_repl_flag',
                        action='store_true',
                        help='start clojure repl')

    parser.add_argument('iteral',
                        metavar='other_args',
                        nargs='*',
                        help='Nore: use -- to pass the args start with -/-- ')

    parser.add_argument('--config_file', help='point to the config file path ')
    parser.add_argument('--alias', help='point to the config file\'s alias')

    parser.add_argument('--use', help='use alias of config_file')

    parser.add_argument('-c',
                        '--compile',
                        dest='__compile',
                        action='store_true',
                        help='compile thr progeam use alias config')

    parser.add_argument('-m',
                        '--main',
                        help='point to the main func manualy for run program')

    parser.add_argument('-l',
                        '--list',
                        dest='view_files',
                        metavar='alias_names',
                        nargs='+',
                        help='list the config file accoding to alias,'
                        '* for all')

    parser.add_argument('-sl',
                        '--shortlist',
                        action='store_true',
                        help='short list all the ini file name')

    parser.add_argument('--update',
                        dest='update_files',
                        metavar='alias_names',
                        nargs='+',
                        help='update the config file accoding to alias,'
                        '* for all')
    # rm!! care!!
    parser.add_argument('-rm',
                        '--remove',
                        dest='remove_files',
                        metavar='alias_names',
                        nargs='+',
                        help='rm the record (do not rm the physical file)')

    parser.add_argument('--refind',
                        dest='refind_list',
                        metavar='[clojure|python|*]',
                        nargs='+',
                        help='refind some confirm config such as clojure jar')

    args = parser.parse_args()

    # print(args.iteral)

    if args.clojure_repl_flag:
        args.__dict__['run_clojure_flag'] = False

    from minghu6.algs.userdict import remove_value
    return remove_value(args.__dict__, None)
示例#8
0
def cli():
    parser_main = ArgumentParser(prog='captcha', description='A captcha processor')
    parser_main.set_defaults(func=parser_main.print_usage)
    sub_parsers = parser_main.add_subparsers(help='main-sub-command')

    # main_parser

    ################################################################################
    # sub_parser: preprocessing
    parser_preprocessing = sub_parsers.add_parser('preproc',
                                                  help='preprocessing the image')

    parser_preprocessing.add_argument('path', nargs='?',
                                      help='image file path(exclude image url)')

    parser_preprocessing.add_argument('-o', '--outdir', help='output directory default curdir')
    parser_preprocessing.add_argument('-m', '--method',
                                      dest='preprocessing_method',
                                      nargs='?',
                                      required=True,
                                      choices=['binary', 'clear_noise', 'sharpen', 'remove_frame'],
                                      help='preprocessing method')
    parser_preprocessing.add_argument('-w', '--width',
                                      required=False,
                                      help='frame width to remove(default 2 pix)')

    parser_preprocessing.set_defaults(func=main_preprocessing)

    ################################################################################
    # sub_parser: train
    parser_train = sub_parsers.add_parser('train', help='train the captcha data')
    train_sub_parsers = parser_train.add_subparsers(help='train-sub-command')
    # train_sub_parser: get_raw
    parser_train_getRawCaptcha = train_sub_parsers.add_parser('get_raw',
                                                              help='get the raw captcha data')

    parser_train_getRawCaptcha.add_argument('url', nargs='?',
                                            help='raw captcha url')

    parser_train_getRawCaptcha.add_argument('-n', '--num', type=int,
                                            help='the number of raw captcha')

    parser_train_getRawCaptcha.add_argument('-o', '--outdir', help='output directory default curdir')

    parser_train_getRawCaptcha.set_defaults(func=train_get_raw)

    ## train_sub_parser: train_cmd
    parser_train_trainCmd = train_sub_parsers.add_parser('train_cmd',
                                                         help='create train cmd file')

    parser_train_trainCmd.add_argument('-l', '--language', help='language')
    parser_train_trainCmd.add_argument('-font', '--font', help='font name')
    parser_train_trainCmd.add_argument('-o', '--outdir', help='output directory default curdir')
    parser_train_trainCmd.add_argument('-shell', '--shell', dest='shell_type',
                                       choices=['cmd', 'bash'], help='cmd shell type')

    parser_train_trainCmd.set_defaults(func=train_train_cmd)
    ################################################################################
    # sub_parser: split
    parser_split = sub_parsers.add_parser('split', help='split the image')
    parser_split.add_argument('path', nargs='?',
                              help='image file path(exclude image url)')

    parser_split.add_argument('-n', '--num', type=int,
                              help='point the number of char of img')

    parser_split.add_argument('-m', '--method', dest='split_method',
                              choices=['bisect', 'boxsplit'],
                              help='split method (default bisect)')

    parser_split.add_argument('-o', '--outdir', help='output directory default curdir')
    parser_split.set_defaults(func=main_split)

    ################################################################################

    # sub_parser: recognise
    parser_recognise = sub_parsers.add_parser('recognise',
                                              help='recognise the captcha')

    recognise_sub_parsers = parser_recognise.add_subparsers(help='recognise-sub-command')

    ## recognise_sub_parser: tesseract
    parser_recognise_tesseract = recognise_sub_parsers.add_parser('tesseract',
                                                                  help='recognise the captcha using tesseract')
    parser_recognise_tesseract.add_argument('path', nargs='?', help='image file path(exclude image url)')
    parser_recognise_tesseract.add_argument('-args', type=str, help='equivalent tesseract "args" stdout ')

    parser_recognise_tesseract.set_defaults(func=recognise_tesseract)

    ################################################################################

    # sub_parser: fetch
    parser_fetch = sub_parsers.add_parser('fetch',
                                          help='fetch captcha batch')

    parser_fetch.add_argument('url', help='captcha url')

    parser_fetch.add_argument('-n', '--num', type=int, required=True,
                              help='fetch number')

    parser_fetch.add_argument('-o', '--outdir', default=os.curdir,
                              help='captcha store path')

    parser_fetch.add_argument('-ext', '--ext', help='captcha ext, such as .png')
    parser_fetch.add_argument('-p', '--pattern', dest='captcha_pattern',
                              default='$(UUID)',
                              help=('captcha name pattern, support macro UUID and NO\n'
                                    'such as $(UUID)_download, '
                                    'download_$(UUID), '
                                    '$(UUID)_$(NO) etc.'))

    parser_fetch.set_defaults(func=main_fetch)

    ################################################################################
    parse_result = parser_main.parse_args()
    # remove_key(parse_result.__dict__, 'func'),
    args = remove_value(remove_key(parse_result.__dict__, 'func'), None)
    parse_result.func(**args)