Exemplo n.º 1
0
    def test_configuration_not_present(self, mock):
        self.assertFalse(path.exists('dummy'), "dummy configuration shouldn't be present")
        config = configure.get_configuration('dummy')

        self.assertTrue(config['directories']['app_data_directory'], 'C:\\')
        self.assertTrue(config['directories']['base_kbdx'], 'C:\\')

        os.remove('dummy')
Exemplo n.º 2
0
        return self.get_players_waiting.execute() > 0

    def find_players_for_match(self, limit: int) -> List[Player]:
        return self.get_players.execute(limit)

    def setup_match(self, players: List[Player]) -> Game:
        game = create_new_game(players)

        if self.add_new_game.execute(game):

            for player in game.players:
                player.game_id = game.game_id
                self.add_player_to_game.execute(player)

            return game
        else:
            return None


if __name__ == '__main__':
    conf = get_configuration()

    logging.basicConfig(level=logging.INFO)
    logging.info("Starting up match making service")
    logging.info(conf)

    configure_inject(conf)

    match_maker = MatchMakerApp(conf)
    match_maker.start()
Exemplo n.º 3
0
    def test_configuration_present(self):
        config = configure.get_configuration('resources/test_config.ini')

        self.assertTrue(config['directories']['app_data_directory'], 'C:\\')
        self.assertTrue(config['directories']['base_kbdx'], 'C:\\')
Exemplo n.º 4
0
def sate_main(argv=sys.argv):
    '''Returns (True, dir, temp_fs) on successful execution or raises an exception.

    Where `dir` is either None or the undeleted directory of temporary files.
    and `temp_fs` is is the TempFS object used to create `dir` (if `dir` is
    not None)

    Note that if `argv` is sys.argv then the first element will be skipped, but
        if it is not the sys.argv list then the first element will be interpretted
        as an argument (and will NOT be skipped).
    '''

    _START_TIME = time.time()
    usage = """usage: %prog [options] <settings_file1> <settings_file2> ..."""
    parser = optparse.OptionParser(usage=usage,
                                   description=PROGRAM_LONG_DESCRIPTION,
                                   formatter=IndentedHelpFormatterWithNL(),
                                   version="%s v%s" %
                                   (PROGRAM_NAME, PROGRAM_VERSION))

    user_config = get_configuration()
    command_line_group = user_config.get('commandline')
    command_line_group.add_to_optparser(parser)
    sate_group = user_config.get('sate')
    sate_group.add_to_optparser(parser)

    group = optparse.OptionGroup(parser, "SATe tools extra options")
    group.add_option('--tree-estimator-model',
                     type='string',
                     dest='tree_estimator_model',
                     help='Do not use this option.')
    parser.add_option_group(group)

    if argv == sys.argv:
        (options, args) = parser.parse_args(argv[1:])
    else:
        (options, args) = parser.parse_args(argv)
    #if options.multilocus:
    #    sys.exit("SATe: Multilocus mode is disabled in this release.")
    if options.tree_estimator_model and options.tree_estimator and len(
            args) == 0:
        if options.tree_estimator.lower() == 'raxml':
            user_config.raxml.model = options.tree_estimator_model
        elif options.tree_estimator.lower() == 'fasttree':
            user_config.fasttree.model = options.tree_estimator_model

    config_filenames = list(args)
    for fn in config_filenames:
        if fn[0] == '"' and fn[-1] == '"':
            fn = fn[1:-1]
        if not os.path.exists(fn):
            raise Exception(
                'The configuration (settings) file "%s" does not exist' % fn)
        try:
            user_config.read_config_filepath(fn)
        except:
            raise Exception(
                'The file "%s" does not appear to be a valid configuration file format. It lacks section headers.'
                % fn)
    user_config.set_values_from_dict(options.__dict__)
    command_line_group.job = coerce_string_to_nice_outfilename(
        command_line_group.job, 'Job', 'satejob')

    if user_config.commandline.auto or (user_config.commandline.untrusted):
        if user_config.commandline.input is None:
            sys.exit("ERROR: Input file(s) not specified.")
        from sate.usersettingclasses import get_list_of_seq_filepaths_from_dir
        from sate.alignment import summary_stats_from_parse
        try:
            if user_config.commandline.multilocus:
                fn_list = get_list_of_seq_filepaths_from_dir(
                    user_config.commandline.input)
            else:
                fn_list = [user_config.commandline.input]
            datatype_list = [user_config.commandline.datatype.upper()]
            careful_parse = user_config.commandline.untrusted
            summary_stats = summary_stats_from_parse(
                fn_list, datatype_list, careful_parse=careful_parse)
        except:
            if user_config.commandline.auto:
                MESSENGER.send_error(
                    "Error reading input while setting options for the --auto mode\n"
                )
            else:
                MESSENGER.send_error("Error reading input\n")
            raise
        if user_config.commandline.auto:
            user_config.commandline.auto = False
            auto_opts = get_auto_defaults_from_summary_stats(
                summary_stats[0], summary_stats[1], summary_stats[2])
            user_config.get('sate').set_values_from_dict(auto_opts['sate'])
            user_config.get('commandline').set_values_from_dict(
                auto_opts['commandline'])
            user_config.get('fasttree').set_values_from_dict(
                auto_opts['fasttree'])

    if user_config.commandline.raxml_search_after:
        if user_config.sate.tree_estimator.upper() != 'FASTTREE':
            sys.exit(
                "ERROR: the 'raxml_search_after' option is only supported when the tree_estimator is FastTree"
            )

    exportconfig = command_line_group.exportconfig
    if exportconfig:
        command_line_group.exportconfig = None
        user_config.save_to_filepath(exportconfig)

        ### TODO: wrap up in messaging system
        sys.stdout.write(
            'Configuration written to "%s". Exiting successfully.\n' %
            exportconfig)

        return True, None, None

    if user_config.commandline.input is None:
        sys.exit("ERROR: Input file(s) not specified.")

    # note: need to read sequence files first to allow SateProducts to
    # correctly self-configure
    user_config.read_seq_filepaths(
        src=user_config.commandline.input,
        multilocus=user_config.commandline.multilocus)
    sate_products = filemgr.SateProducts(user_config)

    export_config_as_temp = True
    if export_config_as_temp:
        name_cfg = sate_products.get_abs_path_for_tag('sate_config.txt')
        command_line_group.exportconfig = None
        user_config.save_to_filepath(name_cfg)
        MESSENGER.send_info('Configuration written to "%s".\n' % name_cfg)

    MESSENGER.run_log_streams.append(sate_products.run_log_stream)
    MESSENGER.err_log_streams.append(sate_products.err_log_stream)
    temp_dir, temp_fs = run_sate_from_config(user_config, sate_products)
    _TIME_SPENT = time.time() - _START_TIME
    MESSENGER.send_info("Total time spent: %ss" % _TIME_SPENT)
    return True, temp_dir, temp_fs
Exemplo n.º 5
0
"""
See README.md
"""
import json
import os
import configure

from keyboard_map import KeyBoardMapCreator
from macro.bind import MacroBinderCreator
from macro.write import MacroWriter

PROGRAM_CONFIG = configure.get_configuration(
    os.path.join("resources", "program_configuration.ini"))
APP_DATA_DIRECTORY = PROGRAM_CONFIG['directories']['app_data_directory']
BASE_KBDX = PROGRAM_CONFIG['directories']['base_kbdx']

MACRO_WRTIER = MacroWriter("macros",
                           os.path.join(APP_DATA_DIRECTORY, "usermacros"),
                           "resources")
MACRO_BINDER = MacroBinderCreator(APP_DATA_DIRECTORY, BASE_KBDX)
KEYBOARD_MAP = KeyBoardMapCreator(
    os.path.join("resources", "keyboard-layout_blank.png"),
    os.path.join("resources", "keys.cfg"),
    os.path.join("resources", "AcariSans-Regular.ttf"))

HOTKEY_CONFIG = json.load(open(os.path.join("resources", "config.json")))

for keyboard_key in HOTKEY_CONFIG.keys():
    for key_combo in ["key", "shift", "ctrl", "alt", "shift-alt", "ctrl-alt"]:
        if key_combo in HOTKEY_CONFIG[keyboard_key].keys():
            MACRO_BINDER.bind(keyboard_key, key_combo)