Example #1
0
def check_mod_versions(verbose=True):
    '''
    Check for mod updates

    :param verbose: In non verbose mode will simply return True or False when it finds first mod to be updated.
    In verbose mode will output modids_to_update, mod_names, memory, data required for updater function to work.
    :return:  See above
    '''
    log.info("Checking for mod updates...")

    modids = get_active_mods()

    memory = read_config("mod_updater_data")
    if not memory:
        memory = {}
        for modid in modids:
            memory[modid] = {'last_update': datetime(year=1991, month=1, day=1)}
        # write_config("mod_updater_data", memory)

    for modid in modids:
        if modid not in memory:
            memory[modid] = {'last_update': datetime(year=1991, month=1, day=1)}
    write_config("mod_updater_data", memory)

    modids_to_update = []
    mod_names = []

    for modid in modids:
        log.debug(f"Querying info on mod {modid}")
        mod_info_html = requests.get(f"https://steamcommunity.com/sharedfiles/filedetails/?id={modid}").text
        soup = BeautifulSoup(mod_info_html, features="html.parser")
        date_string = \
            soup.find("div", {"id": "mainContents"}).find("div", {"class": "workshopItemPreviewArea"}).find_all(
                "div", {"class": "detailsStatRight"})[2].text

        try:
            workshop_updated_date = datetime.strptime(date_string, "%d %b, %Y @ %H:%M%p")
        except ValueError:
            workshop_updated_date = datetime.strptime(date_string, "%d %b @ %H:%M%p")
            workshop_updated_date = workshop_updated_date.replace(year=datetime.now().year)

        if workshop_updated_date > memory[modid]['last_update']:
            log.debug(
                f"Update required for mod: {modid}; Last updated date: {memory[modid]['last_update']}; Workshop date: {workshop_updated_date}")
            modids_to_update.append(modid)
            mod_name = soup.find("div", {"class": "workshopItemTitle"}).text
            mod_names.append(mod_name)
            # memory[modid]['last_update'] = datetime.now()
        # write_config("mod_updater_data", memory)

    if len(modids_to_update) > 0:
        log.info(f"Update required for mods: {modids_to_update}")
        data = {
            'mod_ids': modids_to_update,
            'mod_names': mod_names,
        }
        return data
    else:
        log.info("All mods are up to date.")
        return None
Example #2
0
def update_mods(mod_ids, **kwargs):
    success = True
    try:
        ModDodo(os.path.dirname(STEAMCMD), mod_ids, ARK_SERVER_DIR, False,
                False)
    except:
        log.error("Unable to update mods.", exc_info=True)
        success = False

    if success:
        memory = read_config("mod_updater_data")
        for modid in mod_ids:
            memory[modid]['last_update'] = datetime.now()
        write_config("mod_updater_data", memory)

    return success
Example #3
0
def _run(args, metadata, config):
    new_config = {}

    new_config["oracle_server"] = _input_value(
        "Oracle server (blank for localhost)", None)

    new_config["sys_password"] = _input_value(
        "Password for user 'sys'", None)

    prefix = _input_user_or_password(
        "Unique prefix for user names", "sync")

    for user in configuration.USERS:
        user_name = "{0}_{1}".format(prefix, user)

        new_config["sync_{0}_user".format(user)] = user_name
        new_config["sync_{0}_password".format(user)] = _input_user_or_password(
            "Password for user '{0}'".format(user_name), user_name)

    configuration.write_config(new_config, args.config_file)

    print
    print "Configuration written to '{0}'.".format(args.config_file)
Example #4
0
config = read_config()
if config['database_migrate']:
    log.debug("=====================")
    log.debug("Migration stuff...")
    try:
        from playhouse.migrate import *

        migrator = SqliteMigrator(db)

        open_count = IntegerField(default=0)

        migrate(migrator.add_column('Entry', 'open_count', open_count))
        log.debug("Migration success")
        log.debug("=====================")

        config['database_migrate'] = False
        write_config(config)
    except:
        log.error("Could not migrate", exc_info=True)
        log.debug("=====================")
# endregion

log.info(" ".join(["Using DB", str(db), "At path:", str(db_path)]))

# On init make sure we create database

db.connect()
db.create_tables([Entry])

# endregion
Example #5
0
def process_startup(**kwargs):
    if config_path.is_file():
        return read_config()
    return write_config()
Example #6
0
def test_write_settings(tmp_path):
    file = Path(tmp_path) / "settings.json"
    s = write_config(file)
    pprint(s)
    assert file.is_file()
Example #7
0
def test_read_settings(tmp_path):
    file = Path(tmp_path) / "settings.json"
    write_config(file)
    s = read_config(file)
    assert s.optimization_project == "optimization"