Esempio n. 1
0
    def test_no_algorithm_group(self):
        try:

            self.assertRaises(cli.parse_args(["hash"]), lambda: SystemExit)
        except SystemExit:
            self.assertEqual(True,
                             True)  #cant find other way to check system exit
Esempio n. 2
0
def main():
    print(HELLO_MSG)
    args = parse_args()
    print(args)
    if args.action == "run":
        launch_on_all_nodes()
    elif args.action == "eval":
        evaluate_all()
Esempio n. 3
0
def showconfig():
    opts, args = cli.parse_args()
    cf = opts.pop('configfile')
    print "# Configuration file: %s\n" % cf
    keys = opts.keys()
    keys.sort()
    for key in keys:
        print '%s=%r' % (key, opts[key])
    return 0
Esempio n. 4
0
def shell():
    """
    Run an interactive Python shell configured for our models. 
    """
    from django.core.management.commands import shell
    opts, args = cli.parse_args()
    cmd = shell.Command()
    cmd.handle_noargs()
    return 0
Esempio n. 5
0
 def command_sequence_test(self, commands, output):
     self.stealOutput()
     expected = self.strip_list(output if type(output) in (list, tuple)
                                       else [output])
     for command in commands:
         if type(command) == type(''):
             args = command.split(' ')
         else:
             args = command
         cli.execute_command_line(*cli.parse_args(args))
     self.reset()
     self.assertEqual(self.strip_list(self.out.buffer), expected)
def main():
    params = cli.parse_args()
    config = Config(params)
    provider = Conoha()
    provider.authenticate('', '', '')
    acls = provider.get_acl_config()
    for acl_cfg in acls:
        acl_obj = provider.create_acl_item(acl_cfg.name, acl_cfg.description)
        for rule_cfg in acl_cfg.rules:
            provider.add_acl_rule(acl_obj.id, rule_cfg)
    vm = provider.create_vm()
    config.apply_hosts(vm)
Esempio n. 7
0
 def activity(self):
     self.output.setText("请稍等几秒钟......")
     sentence = self.input.text()
     print(self.input.text())
     args = parse_args()
     print("ok")
     IE = TripleIE(sentence, args.ltp, args.clean)
     out = IE.run()
     if re.search(r"句子结构不完整", out, flags=0) == None:
         CL = Classify(sentence, out)
         out += "句子类型:" + CL.SentenceType()
     self.output.setText(out)
Esempio n. 8
0
 def showTaggedSuccessTest(self, mode):
     self.stealOutput()
     (flag, spec, o) = specify_DADGAD(mode, self.db.host)
     description = cli.describe_by_mode(o)
     args = (['show', '-U', '-v', flag, spec, 'rating', '/fluiddb/about']
             + self.hostname)
     cli.execute_command_line(*cli.parse_args(args))
     self.reset()
     self.assertEqual(self.out.buffer,
             ['Object %s:' % description, '\n',
              '  /%s/rating = 10' % self.user.encode('UTF-8'), '\n',
              '  /fluiddb/about = "DADGAD"', '\n'])
     self.assertEqual(self.err.buffer, [])
Esempio n. 9
0
def main():
    # parse command line arguments
    args = parse_args()

    # parse information about products and categories
    parser = WBParser(args.url)
    products_collection = parser.parse_products(exclude_desc=args.brief)
    categories_collection = parser.parse_categories()

    # display it
    print("~~~ Products ~~~")
    pprint(products_collection)
    print("\n~~~ Categories ~~~")
    pprint(categories_collection)
Esempio n. 10
0
def main(args=None):
    timeit = time.time()
    repo = Path(sys.argv[0]).resolve().parent.parent
    langs = repo/'data'/'languages.csv'
    targets = repo/'data'/'rank_turbulence_divergence'
    outdir = repo/'data'/'timeseries'
    plots = repo/'plots'

    args = cli.parse_args(args)
    Path(outdir).mkdir(parents=True, exist_ok=True)

    if args.dtype == 'figures':

        jhu = Path(args.jhu) / 'csse_covid_19_data/csse_covid_19_time_series'
        confirmed = jhu / 'time_series_covid19_confirmed_global.csv'
        deaths = jhu / 'time_series_covid19_deaths_global.csv'
        us_confirmed = jhu / 'time_series_covid19_confirmed_US.csv'
        us_deaths = jhu / 'time_series_covid19_deaths_US.csv'

        contagiograms.plot(
            consts.contagiograms,
            savepath=plots,
            start_date=datetime(2020, 1, 1),
            t1="1W",
            t2=7,
        )
        
        vis.cases(
            savepath=plots / f'coronagrams_cases',
            words_by_country=consts.words_by_country,
            deaths=deaths,
            confirmed=confirmed,
            us_deaths=us_deaths,
            us_confirmed=us_confirmed,
            lang_hashtbl=Path(langs),
        )

    else:
        for f in targets.rglob('*grams'):
            logging.info(f'{f.parent.stem}|{f.stem}')

            utils.update_timeseries(
                save_path=outdir/f.parent.stem/f.stem,
                languages_path=langs,
                ngrams_path=f,
                database=f.stem.split('_')[-1]
            )

    logging.info(f'Total time elapsed: {time.time() - timeit:.2f} sec.')
Esempio n. 11
0
def main():
    args = parse_args(args=sys.argv[1:])
    (architecture, input_shape, optimizer, learning_rate, n_epochs, pool,
     n_dense, units, patience, batch_norm, dropouts, maxnorm, l2_reg,
     patience) = (args.architecture, args.input_shape, args.optimizer,
                  args.learning_rate, args.n_epochs, args.pool, args.n_dense,
                  args.units, args.patience, args.batch_norm, args.dropouts
                  or [], args.maxnorm, args.l2_reg, args.patience)

    print('Model training with parameters:')
    pprint(vars(args))

    model = PretrainedModel(input_shape=input_shape)

    model.create(*get(architecture),
                 n_dense=n_dense,
                 pool=pool,
                 units=units,
                 bn=batch_norm,
                 dropouts=dropouts,
                 maxnorm=maxnorm,
                 l2_reg=l2_reg)

    ok = model.create_model_folder(root=join(MODELS_FOLDER, 'face_landmarks'),
                                   subfolder=args.identifier)

    if not ok:
        sys.exit(1)

    model.save_parameters(model.parameters_path)
    model.compile(optimizer=optimizer)

    callbacks = [
        CSVLogger(filename=model.history_path),
        EarlyStopping(patience=patience, verbose=1),
        ModelCheckpoint(filepath=model.weights_path,
                        save_best_only=True,
                        save_weights_only=False)
    ]

    model.train(n_epochs=n_epochs,
                train_folder=LFPW_TRAIN,
                valid_folder=LFPW_VALID,
                callbacks=callbacks)

    avg_rmse = model.score(LFPW_VALID)
    print(f'Trained model validation RMSE: {avg_rmse:2.4f}')
    print(f'The folder with results: {model.subfolder}')
    print(f'Training history file: {model.history_path}')
Esempio n. 12
0
def _setup_tools():
    """
    Common setup for various tools.
    """
    opts, args = cli.parse_args()
    try:
        zone = _fix_zone(args[0])
    except IndexError:
        log.error(USAGE_ZONE)
    _check_permissions(zone)

    # We have to wait until Django is configured to import our models
    import models
    globals()['models'] = models
    return opts, zone
Esempio n. 13
0
def main():

    utils.myprint_switches = ["std"]  # [] to suppress printing

    print("multi.py -- Bayesian audit support program.")

    utils.start_datetime_string = utils.datetime_string()
    print("Starting date-time:", utils.start_datetime_string)

    args = cli.parse_args()
    e = Election()
    try:
        cli.process_args(e, args)
    finally:
        utils.close_myprint_files()
Esempio n. 14
0
 def untagTest(self, mode, verbose=True):
     self.stealOutput()
     (flag, spec, o) = specify_DADGAD(mode, self.db.host)
     description = cli.describe_by_mode(o)
     flags = ['-v', flag] if verbose else [flag]
     args = ['untag'] + ['-U'] + flags + [spec, 'rating'] + self.hostname
     cli.execute_command_line(*cli.parse_args(args))
     self.reset()
     if verbose:
         target = ['Removed tag rating from object %s\n' % description,
                   '\n']
     else:
         target = []
     self.assertEqual(self.out.buffer, target)
     self.assertEqual(self.err.buffer, [])
Esempio n. 15
0
def main():
    args = parse_args({
        'resnet18': resnet18,
        'resnet34': resnet34,
        'resnet50': resnet50
    })

    img_sz, trn_sz, val_sz, n, bs = (
        args.image_size,
        args.train_size,
        args.valid_size,
        args.n_epochs,
        args.batch_size,
    )

    arch, log, device, path = (
        args.network,
        args.log,
        args.device,
        args.models_path
    )

    defaults.device = args.device

    tfms = create_transforms()
    bunch = create_bunch(subset_sizes=(trn_sz, val_sz), img_size=img_sz, bs=bs, ds_tfms=tfms, log=args.log)
    learn = create_cnn(bunch, arch)
    learn.metrics = [accuracy, map3]

    learn.fit_one_cycle(1, max_lr=1e-02)
    learn.fit_one_cycle(1, max_lr=1e-02 / 2)
    saved_path = learn.save('base', return_path=True)
    log.info('Intermediate model saved into %s', saved_path)

    learn.unfreeze()
    learn.freeze_to(-1)
    learn.fit_one_cycle(1, max_lr=slice(2e-04, 1e-03))
    saved_path = learn.save('unfreeze_one', return_path=True)
    log.info('Intermediate model saved into %s', saved_path)

    learn.unfreeze()
    learn.fit_one_cycle(1, max_lr=slice(1e-04, 3e-04))
    saved_path = learn.save('unfreeze_all', return_path=True)
    log.info('Intermediate model saved into %s', saved_path)

    learn.fit_one_cycle(1, max_lr=slice(1e-05, 5e-04))
    saved_path = learn.save('unfreeze_all', return_path=True)
    log.info('Done! The final model is saved into file %s', saved_path)
Esempio n. 16
0
def main():
    args = parse_args(sys.argv[1:])
    log_parser = LogParser(LineParser)
    parsed_lines = log_parser.parse(args.filename)
    analyzer = Analyzer(parsed_lines, start=args.start, end=args.end)
    try:
        stats = analyzer.get_output_stats()
    except (TypeError, ZeroDivisionError):
        print((
            'It looks like in given time frame there were made less than two requests.\n'
            'Stats are unavailable.'))
    else:
        message = ('Requests: {requests}\n'
                   'Requests per second: {request_per_second}\n'
                   'Responses: {status_count}\n'
                   'Avg 2XX response size: {2XX_avg_size}\n').format(**stats)
        print(message, end='')
Esempio n. 17
0
 def tagTest(self, mode, verbose=True):
     self.stealOutput()
     (flag, spec, o) = specify_DADGAD(mode, self.db.host)
     description = cli.describe_by_mode(o)
     flags = ['-v', flag] if verbose else [flag]
     args = ['tag'] + ['-U'] + flags + [spec, 'rating=10'] + self.hostname
     cli.execute_command_line(*cli.parse_args(args))
     self.reset()
     if verbose:
         target = ['Tagged object %s with rating = 10' % description, '\n']
     else:
         if mode == 'query':
             target = ['1 object matched', '\n']
         else:
             target = []
     self.assertEqual(self.out.buffer, target)
     self.assertEqual(self.err.buffer, [])
Esempio n. 18
0
def main():
    args = parse_args({
        'resnet18': resnet18,
        'resnet34': resnet34,
        'resnet50': resnet50
    })

    img_sz, trn_sz, val_sz, n, bs = (
        args.image_size,
        args.train_size,
        args.valid_size,
        args.n_epochs,
        args.batch_size,
    )

    arch, log, device, path = (args.network, args.log, args.device,
                               args.models_path)

    defaults.device = device

    learn = train(arch=arch,
                  epochs=n,
                  lr=3e-2,
                  img_size=img_sz,
                  batch_size=bs,
                  train_size=trn_sz,
                  valid_size=val_sz,
                  log=log,
                  path=path)

    name = f'{args.arch_name}_{args.suffix}_{img_sz}_{n}'
    learn.save(name)

    # learn = train(arch=arch,
    #               preload=name,
    #               epochs=int(max(1, n//2)),
    #               lr=3e-2/3,
    #               img_size=img_sz*3//2,
    #               batch_size=bs*2,
    #               train_size=trn_sz,
    #               valid_size=val_sz,
    #               log=log,
    #               path=path)

    print('Done!')
Esempio n. 19
0
def createdb():
    """
    Create the database tables needed by psz.
    """
    from django.core.management.commands import syncdb
    opts, args = cli.parse_args()
    cmd = syncdb.Command()
    cmd.handle_noargs()
    from django.db import connection
    cursor = connection.cursor()
    # Django can't created indexes on MySQL text fields
    # http://code.djangoproject.com/ticket/2495
    # so we have to do it by hand
    if DEFAULTS['db_engine'] == 'mysql': 
        # XXX we should construct the table name dynamically
        cursor.execute('create index zone_index on psz_dnskey (zone(255))')
        cursor.execute('create index zone_index on psz_logmessage (zone(255))')
    return 0
Esempio n. 20
0
File: main.py Progetto: axvr/txtdb
def main():
    args = cli.parse_args()

    # Create the database if it doesn't already exist
    mkpath(args.database)

    # Instantiate the requested database instance
    db = Database(args.database, args.ignore_lock)

    # Execute a SQL file
    if args.sql_file:
        sql_runner.sql_file(args.sql_file, db)

    # SQL REPL
    if args.interactive:
        sql_runner.sql_repl(db)

    # TODO maybe accept SQL input through STDIN

    return
Esempio n. 21
0
def main():
    args = parse_args(args=sys.argv[1:])

    input_shape, n_epochs, n_top, units, pool, l2, patience = (
        args.input_shape, args.n_epochs, args.n_dense, args.units, args.pool,
        args.l2_reg, args.patience)

    print('Model training with parameters:')
    pprint(vars(args))

    model = ResNet34(input_shape=input_shape)
    model.create(pool='avg', n_top=n_top, units=units, l2_reg=l2)
    model.compile(optimizer=args.optimizer)

    ok = model.create_model_folder(root=join(MODELS_FOLDER, 'face_landmarks'),
                                   subfolder=args.identifier)

    if not ok:
        sys.exit(1)

    model.save_parameters(model.parameters_path)

    callbacks = [
        CSVLogger(filename=model.history_path),
        EarlyStopping(patience=patience, verbose=1),
        ModelCheckpoint(filepath=model.weights_path,
                        save_best_only=True,
                        save_weights_only=False)
    ]

    model.train(n_epochs=n_epochs,
                train_folder=LFPW_TRAIN,
                valid_folder=LFPW_VALID,
                callbacks=callbacks)

    avg_rmse = model.score(LFPW_VALID)
    print(f'Trained model validation RMSE: {avg_rmse:2.4f}')
    print(f'The folder with results: {model.subfolder}')
    print(f'Training history file: {model.history_path}')
Esempio n. 22
0
from sys import argv
from cli import parse_args

parse_args(argv)
Esempio n. 23
0
    def test_algorithm_group(self):


        self.assertEqual(cli.parse_args(["--sha1","-c","6","hash"]).sha1,True)
Esempio n. 24
0
import cli

if __name__ == "__main__":
    cli.parse_args()
Esempio n. 25
0
def main():
    args = parse_args()

    transformers_logger = logging.getLogger("transformers")
    transformers_logger.setLevel(logging.ERROR)

    if args.predict_file is None and args.do_eval:
        raise ValueError(
            "Cannot do evaluation without an evaluation data file. Either supply a file to --eval_data_file "
            "or remove the --do_eval argument.")

    if args.output_dir and os.path.exists(args.output_dir) and \
            os.listdir(args.output_dir) and args.do_train and not args.overwrite_output_dir:
        raise ValueError(
            "Output directory ({}) already exists and is not empty. Use --overwrite_output_dir to overcome."
            .format(args.output_dir))

    if args.overwrite_output_dir and os.path.isdir(args.output_dir):
        shutil.rmtree(args.output_dir)
    os.mkdir(args.output_dir)

    # Setup CUDA, GPU & distributed training
    if args.local_rank == -1 or args.no_cuda:
        device = torch.device("cuda" if torch.cuda.is_available()
                              and not args.no_cuda else "cpu")
        args.n_gpu = torch.cuda.device_count()
    else:  # Initializes the distributed backend which will take care of sychronizing nodes/GPUs
        torch.cuda.set_device(args.local_rank)
        device = torch.device("cuda", args.local_rank)
        torch.distributed.init_process_group(backend='nccl')
        args.n_gpu = 1
    args.device = device

    # Setup logging
    logging.basicConfig(
        format='%(asctime)s - %(levelname)s - %(name)s -   %(message)s',
        datefmt='%m/%d/%Y %H:%M:%S',
        level=logging.INFO if args.local_rank in [-1, 0] else logging.WARN)

    with open(os.path.join(args.output_dir, 'args.txt'), 'w') as f:
        f.write(str(args))

    for key, val in vars(args).items():
        logger.info(f"{key} - {val}")

    try:
        write_meta_data(args.output_dir, args)
    except git.exc.InvalidGitRepositoryError:
        logger.info("didn't save metadata - No git repo!")

    logger.info(
        "Process rank: %s, device: %s, n_gpu: %s, distributed training: %s, amp training: %s",
        args.local_rank, device, args.n_gpu, bool(args.local_rank != -1),
        args.amp)

    # Set seed
    set_seed(args)

    # Load pretrained model and tokenizer
    if args.local_rank not in [-1, 0]:
        # Barrier to make sure only the first process in distributed training download model & vocab
        torch.distributed.barrier()

    if args.config_name:
        config = AutoConfig.from_pretrained(args.config_name,
                                            cache_dir=args.cache_dir)
    elif args.model_name_or_path:
        config = AutoConfig.from_pretrained(args.model_name_or_path,
                                            cache_dir=args.cache_dir)
    else:
        config = CONFIG_MAPPING[args.model_type]()
        logger.warning(
            "You are instantiating a new config instance from scratch.")
    #config.hidden_dropout_prob = args.encoder_dropout_prob

    if args.tokenizer_name:
        tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_name,
                                                  cache_dir=args.cache_dir)
    elif args.model_name_or_path:
        tokenizer = AutoTokenizer.from_pretrained(args.model_name_or_path,
                                                  cache_dir=args.cache_dir)
    else:
        raise ValueError(
            "You are instantiating a new tokenizer from scratch. This is not supported, but you can do it from another script, save it,"
            "and load it from here, using --tokenizer_name")

    config_class = LongformerConfig
    base_model_prefix = "longformer"

    S2E.config_class = config_class
    S2E.base_model_prefix = base_model_prefix
    model = S2E.from_pretrained(args.model_name_or_path,
                                config=config,
                                cache_dir=args.cache_dir,
                                args=args)

    model.to(args.device)

    if args.local_rank == 0:
        # End of barrier to make sure only the first process in distributed training download model & vocab
        torch.distributed.barrier()

    logger.info("Training/evaluation parameters %s", args)

    evaluator = Evaluator(args, tokenizer)
    # Training
    if args.do_train:
        train_dataset = get_dataset(args, tokenizer, evaluate=False)

        global_step, tr_loss = train(args, train_dataset, model, tokenizer,
                                     evaluator)
        logger.info(" global_step = %s, average loss = %s", global_step,
                    tr_loss)

    # Saving best-practices: if you use save_pretrained for the model and tokenizer,
    # you can reload them using from_pretrained()
    if args.do_train and (args.local_rank == -1
                          or torch.distributed.get_rank() == 0):
        # Create output directory if needed
        if not os.path.exists(args.output_dir) and args.local_rank in [-1, 0]:
            os.makedirs(args.output_dir)

        logger.info("Saving model checkpoint to %s", args.output_dir)
        # Save a trained model, configuration and tokenizer using `save_pretrained()`.
        # They can then be reloaded using `from_pretrained()`
        model_to_save = model.module if hasattr(
            model,
            'module') else model  # Take care of distributed/parallel training
        model_to_save.save_pretrained(args.output_dir)
        tokenizer.save_pretrained(args.output_dir)

        # Good practice: save your training arguments together with the trained model
        torch.save(args, os.path.join(args.output_dir, 'training_args.bin'))

    # Evaluation
    results = {}

    if args.do_eval and args.local_rank in [-1, 0]:
        result = evaluator.evaluate(model,
                                    prefix="final_evaluation",
                                    official=True)
        results.update(result)
        return results

    return results
Esempio n. 26
0
        states = generate_states(
            args.size,
            args.prefix_length,
            args.amount,
            f
        )
    assert len(states) != 0

    for i in range(len(states)):
        moved_state = move_state(states[i][0], args.prefix_length)
        revealed_state = states[i][1]
        if not args.special:
            if args.reveal_random:
                revealed_state = reveal_random_values_simple(args.preselected, moved_state)
            elif args.reveal:
                revealed_state = reveal_values_simple(args.preselected, moved_state)
        else:
            # args.special
            if args.reveal_random:
                revealed_state = reveal_random_values_special(args.preselected_even, args.preselected_odd, moved_state)
            elif args.reveal:
                revealed_state = reveal_values_special(args.preselected_even, args.preselected_odd, moved_state)
        
        states[i][1] = revealed_state

    write_states(states, args.smt)


if __name__ == '__main__':
    main(parse_args())
Esempio n. 27
0
def repl_or_go():
    action, args, options, parser = cli.parse_args(sys.argv)
    if len(args) == 0 and not options.version:
        REPL('This is fish version %s.' % fishlib.VERSION)
    else:
        return cli.go()
Esempio n. 28
0
        
        axes1[axId].set_yticks([-200,-100,0,100,200])
        axes2[axId].set_yticks([-20,-10,0,10,20])
        
        if axId > 0:
            axes1[axId].yaxis.set_ticklabels([])
            axes2[axId].yaxis.set_ticklabels([])
            
        axId += 1
    axes1[0].set_ylabel("y")
    axes2[0].set_ylabel("y")
    for ax in axes2:
        ax.set_xlabel("x")

if __name__ == "__main__":
    args = cli.parse_args()

    def plot_and_save_as_needed(name):
        if args.save:
            print("Saving "+name)
            plt.savefig(name, bbox_inches='tight')
        if not args.noshow:
            plt.show()
        plt.close()
    
    dataset = settings.DATASETS[args.dataset_id]
    
    experiments = {
        "BBB": bbb_decay.bbb_decay_base.get_variant("BBB covviz "+dataset),
        "SLANG L=1":slang.slang_base.get_variant("SLANG covviz L=1 "+dataset),
        "SLANG L=5":slang.slang_base.get_variant("SLANG covviz L=5 "+dataset),
Esempio n. 29
0
from cli import parse_args
from draw import show_results
from rng import *

RNG_GENERATORS = {
    'raw': lehmer_random,
    'uniform': uniform_random,
    'gaussian': gaussian_random,
    'exponential': exponential_random,
    'gamma': gamma_random,
    'triangle': triangle_random,
    'simpson': simpson_random
}

if __name__ == '__main__':
    options = parse_args()
    rng = RNG_GENERATORS[options.mode](vars(options))
    random_values = list(rng)

    checking_report = indirect_signs_checking(
        random_values) if options.mode == 'raw' else None
    numerical_characteristics = numerical_characteristics_estimation(
        random_values)
    interval_distribution = count_interval_distribution(
        random_values, options.intervals_count)
    periodic_stats = aperiodic_interval_and_period(random_values)

    show_results(interval_distribution, checking_report,
                 numerical_characteristics, periodic_stats)
Esempio n. 30
0
def main():
    args = cli.parse_args(sys.argv[1:])
    cli.handle_parsed_args(args)
Esempio n. 31
0
    def test_character_group(self):

        self.assertEqual(cli.parse_args(["--sha1","-c","6","hash"]).chars,6)
Esempio n. 32
0
        log_path (str): Path to the log files directory.

    Returns:
        list: The relevant epoch numbers.
    """
    if type(spec) is list:
        return spec

    metric, n_epochs = spec
    df = pd.read_csv(os.path.join(log_path, 'history.csv'), index_col=0)
    df.sort_values(by=metric, ascending=metric in ['val_loss'], inplace=True)
    return df.index.values[:n_epochs]


def _log_parameters(output_path, **params):
    """Write the given parameter values to a JSON file.

    Args:
        output_path (str): Output file path.
        **params: Parameter values to log.
    """
    with open(output_path, 'w') as f:
        json.dump(params, f, indent=2)


if __name__ == '__main__':
    try:
        sys.exit(main(cli.parse_args()))
    except FileNotFoundError as error:
        sys.exit(error)
Esempio n. 33
0
    def save_field(self, field_name, output_file=None):
        """
        Save value of the field to the file.
        :param field_name:
        :param output_file Output file if it should be different from current settings path
        :return:
        """
        output_file = output_file if output_file else self.settings_path
        current_values = {}
        try:
            with open(output_file) as save_file:
                current_values = json.load(save_file)
        except Exception as error:
            logger.error("Error while reading settings file: {}".format(
                str(error)))

        current_values[field_name] = getattr(self, field_name)
        try:
            with open(output_file, mode='w') as save_file:
                json.dump(current_values, save_file, indent=4, sort_keys=True)
        except Exception as error:
            logger.error("Error while reading settings file: {}".format(
                str(error)))

        logger.info("Wrote {}:{}".format(field_name,
                                         current_values[field_name]))


SETTINGS = SettingsManager(cli.parse_args()[0])
Esempio n. 34
0
    p.make_phi()

    problem_file = coalesce([p.P, p.phi, p.daisy_name], p.daisy_models_name)

    if not run_spin(problem_file):
        p.print_no_solution()
        clean_and_exit()

    make_all_trails(problem_file, p.max_attacks)
    trail_cmds = generate_trail_commands(p.daisy_models_name)
    trails = parse_all_trails(trail_cmds, p.recovery_huh)
    attackers = make_attackers(trails, trail_cmds, p)

    write_attackers(attackers)
    clean_up()
    '''
    # Characterize the attacks
    if p.characterize_huh:
        (E, A) = characterizeAttacks(model, phi, with_recovery, attacker_name)
        clean_up()
        return 0 if (E + A) > 0 else -1
    else:
        '''

    return 0  # assume it worked if not asked to prove it ...


if __name__ == "__main__":
    problem = parse_args()
    solve_attacker_syn(problem)
Esempio n. 35
0
# -*- coding: utf-8 -*-
# pylint: disable=import-error, no-name-in-module

import os

from cli import parse_args

# parse arguments
_args = parse_args()

# CLI arguments
KILL_SIGNAL = _args.signal
SERVER_NAME_HOST = _args.host
SERVER_NAME_PORT = _args.port
DOCKER_COMPOSE = _args.docker_compose
DUMP_PATH = _args.dump_path
LOGS_PATH = _args.logs_path
API_LOGS = _args.api_logs
API_ROOT = _args.api_root
INTERVAL = _args.interval
MAX_RETRY = _args.max_retry

# macros
EXIT_SUCCESS = 0
EXIT_FAILURE = 1

# log files
FILE = os.path.join(LOGS_PATH, 'dump.log')
FAIL = os.path.join(LOGS_PATH, 'fail.log')

# unset args
Esempio n. 36
0
    def test_no_algorithm_group(self):
        try:

            self.assertRaises(cli.parse_args(["hash"]),lambda :SystemExit)
        except SystemExit:
            self.assertEqual(True,True) #cant find other way to check system exit
Esempio n. 37
0
    def test_character_group(self):

        self.assertEqual(
            cli.parse_args(["--sha1", "-c", "6", "hash"]).chars, 6)
Esempio n. 38
0
    def test_algorithm_group(self):

        self.assertEqual(
            cli.parse_args(["--sha1", "-c", "6", "hash"]).sha1, True)
Esempio n. 39
0

def choose_hasher(arguments):
    if arguments.md5:
        hasher = Hasher.MD5Hasher()
    elif arguments.sha1:
        hasher = Hasher.SHA1Hasher()
    elif arguments.sha256 :
        hasher = Hasher.SHA256Hasher()

    return hasher



if __name__=="__main__":
    arguments = cli.parse_args(sys.argv[1:]) # removing the filename
    hasher = choose_hasher(arguments)
    key_generator = choose_key_generator(arguments)

    desired_hash = arguments.hash

    #matric
    init_time = time.time()
    keys=0


    for key in key_generator.gen_keywords():


        joined_key = "".join(key)
        output_hash = hasher.getHash(joined_key,True)
Esempio n. 40
0
		We used *time.sleep(2)* in order to avoid issues related to items counting (stochastics fluctuations in time are significant and most of the times the set_score
		function wouldn't work because of that, compromising the learning process) 

"""

#“Code is more often read than written.” --Guido Van Rossum
# author : Simone Azeglio

import MalmoPython
import time

from cli import parse_args
from mission import mission

if __name__ == "__main__":
    mazeXMLFile, alg, out = parse_args()

    m = mission()
    m.load(mazeXMLFile)

    while True:
        m.start()
        # initialize action
        action = ''
        # Loop until mission ends:
        try:
            while m.is_running():
                time.sleep(0.1)
                # get observation --> return what the agent can see
                observations = m.get_observation()
Esempio n. 41
0
from cli import parse_args
from pynytimes import NYTAPI
mode, topic_url, articles_to_scrape, driver_path = parse_args()

# For testing: If True only one article is scrapped
DEMO = False
DEMO_TOPIC = 'https://www.nytimes.com/section/world/africa'
DEMO_ARTICLE_SCRAP = 1

# Database details
HOST = 'localhost'
DATABASE = 'nytimes'

# your variables
USER = '******'
PASSWORD = '******'

# Settings for the logger
LOG = 'log_file.log'
NYTname = 'scrapper'

# API key for the NYT API
nyt = NYTAPI("qeOAmrE6yGzowmzGiIpoK0ZBHOnyJ8BG", https=False)