From c3ab809d52c939dfce693bbd87cef98922c3466d Mon Sep 17 00:00:00 2001 From: shakeyourbunny Date: Wed, 8 May 2019 21:53:04 +0200 Subject: [PATCH] new configuration option "dontremoveunknown", new CLI parsing, bugfixes --- CHANGELOG | 22 ++++++++++++++-- README.md | 18 ++++++++++++- VERSION | 2 +- rwms_config.ini | 3 +++ rwms_sort.py | 69 ++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 100 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4c718e9..0091bce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,25 @@ RWMS (RimWorldModSorter) changelog: +0.94.3 (2019-05-08: +new: +- new configuration option "dontremoveunknown": do not remove unknown mods (and stick them at the bottom of the list) +- new command line parser, try --help +- new command line option "--disable-steam", overrides same configuration file setting +- new command line option "--dont-remove-unknown-mods", overrides same configuration file setting +- new command line option "--reset-to-core", resets ModsConfig.xml to Core only (idea taken from Mehni's tool) +- documentation added + +changed: +- "contributors" command line option changed to "--contributors" (new parser) +- small delays removed + +fixed: +- configuration directive "openbrowser_on_update" works now +- minor XML fix, empty li-element removed in ModsConfig.xml + + 0.94.2 (2019-05-04): -modified: +changed: - changed unknown data file format slightly for easier processing. 0.94.1 (2019-05-04): @@ -10,7 +28,7 @@ new: - table of contents in documentation. - added documentation about contents of the unknown data file which is generated for submission. -modified: +changed: - reworked data format for unknown mods file, now has versioning, some meta information about installation and Steam Workshop links to mods if steam support is not disabled. Reason for including this meta information is relieving me from the guesswork of the installation I'm already doing if I have to pinpoint bugs. diff --git a/README.md b/README.md index 93600b0..003414d 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,9 @@ Discussion thread on Ludeon: https://ludeon.com/forums/index.php?topic=48518.0 ## Table of contents * [Description](#description) * [Usage](#usage) + * [Command Line Options](#command-line-options) * [Upgrading](#upgrading) - * [Installation](#installation) + * [Installation](#installation) * [Python 3.6 ](#python-36) * [Windows](#windows) * [Linux distributions](#linux-distributions) @@ -44,6 +45,18 @@ the mod load order. For using the script you need an active internet connection which will connect to Github, where the current sort order database resides. +## Command Line Options +Option | Description +--- | --- +--help | displays helps and valid command line arguments +--disable-steam | force disable Steam checks +--dont-remove-unknown-mods | do not remove unknown mods +--contributors | list all contributors to the script and the database who have contributed more than 10 mods +--reset-to-core | reset ModsConfig.xml to just Core + +Note that the switches which are named identical to the configuration options override these, so the +priority order of options is: **default settings - configuration file - command line arguments.** + ## Usage Just run the script with @@ -68,6 +81,8 @@ If some mods are unknown, the script will generate a *rws_unknown_mods_YYYYmmdd- where all unknown mods are listed. Please submit this file in the forum thread or in the sister project, RWMSDB on https://github.com/shakeyourbunny/RWMSDB/issues +## + ## Upgrading It is recommended that you do a clean installation, but you can copy over your rwms_config.ini in the new directory, but do not forget to check this documentation for @@ -157,6 +172,7 @@ waitforkeypress_on_exit | True | wait for a keypress / Enter to exit the program entry | default value | description --- | --- | --- disablesteam | False | ignore any steam installations or related stuff +dontremoveunknown | False | do not remove unknown mods from the ModsConfig.xml (and stick them at the bottom) ### GitHub submission options If you want your unknown mods automatically submitted as an issue, please configure these diff --git a/VERSION b/VERSION index d89b314..4c85439 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.94.2 +0.94.3 diff --git a/rwms_config.ini b/rwms_config.ini index 197281b..15cc96d 100644 --- a/rwms_config.ini +++ b/rwms_config.ini @@ -20,6 +20,9 @@ waitforkeypress_on_exit = True ; disable check for steam disablesteam = False +; do not remove unknown mods, leave me alone +dontremoveunknown = True + ; ------------------------------------------------------------------------------- ; -- installation directories options -- ; steam installation directory diff --git a/rwms_sort.py b/rwms_sort.py index df870dc..34265dd 100644 --- a/rwms_sort.py +++ b/rwms_sort.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python # RimWorld Module Sorter import collections import json @@ -9,6 +9,7 @@ import time import webbrowser import xml.etree.ElementTree as ET +from argparse import ArgumentParser from operator import itemgetter from urllib.request import urlopen @@ -22,10 +23,21 @@ # ################################################################################## # some basic initialization -VERSION = "0.94.2" +VERSION = "0.94.3" twx, twy = shutil.get_terminal_size() +parser = ArgumentParser() + +# configuration overrides +parser.add_argument("--disable-steam", action="store_true", help="force disable steam detection") +parser.add_argument("--dont-remove-unknown-mods", action="store_true", help="do not remove unknown mods") + +# misc options +parser.add_argument("--contributors", action="store_true", help="display all contributors to RWMS(DB)") +parser.add_argument("--reset-to-core", action="store_true", help="reset mod list to Core only") +args = parser.parse_args() + banner = "** RWMS {} by shakeyourbunny ".format(VERSION) print("{:*<{tw}}".format(banner, tw=twx)) print("bugs: https://github.com/shakeyourbunny/RWMS/issues") @@ -37,6 +49,14 @@ wait_on_error = rimworld_configuration.__load_value_from_config("waitforkeypress_on_error", True) wait_on_exit = rimworld_configuration.__load_value_from_config("waitforkeypress_on_exit", True) disablesteam = rimworld_configuration.__load_value_from_config("disablesteam", True) +dontremoveunknown = rimworld_configuration.__load_value_from_config("dontremoveunknown", False) + +# command line switches, override configuration file +if args.disable_steam: + disablesteam = True + +if args.dont_remove_unknown_mods: + dontremoveunknown = True if updatecheck: if rwms_update.is_update_available(VERSION): @@ -44,7 +64,9 @@ print("") print("Release: https://github.com/shakeyourbunny/RWMS/releases") print("") - # time.sleep(1) + if openbrowser_on_update: + webbrowser.open_new("https://www.github.com/shakeyourbunny/RWMS/releases") + if rimworld_configuration.__detect_rimworld() == "": rwms_error.fatal_error("no valid RimWorld installation detected!", wait_on_error) @@ -147,7 +169,8 @@ def load_mod_data(cats, db, basedir, modsource): database["timestamp"])) print("{} known mods, {} contributors.".format(len(database["db"]), len(database["contributor"]))) -if len(sys.argv) > 1 and sys.argv[1] == "contributors": +# if len(sys.argv) > 1 and sys.argv[1] == "contributors": +if args.contributors: print("{:<30} {:<6}".format('Contributor', '# Mods')) d = sorted(database["contributor"].items(), key=itemgetter(1), reverse=True) for contributors in d: @@ -163,7 +186,6 @@ def load_mod_data(cats, db, basedir, modsource): for c in contributors.most_common(5): print("{} ({}), ".format(c[0], c[1]), end='') print("") - time.sleep(1) modsconfigfile = rimworld_configuration.get_modsconfigfile() print("") @@ -211,7 +233,6 @@ def load_mod_data(cats, db, basedir, modsource): pass # print("Unknown mod ID {}, deactivating it from mod list.".format(mods)) -time.sleep(1) print("Sorting mods.") newlist = sorted(mods_data_active, key=itemgetter(1)) print("") @@ -232,7 +253,23 @@ def load_mod_data(cats, db, basedir, modsource): xml.remove(li) # ET.dump(doc) -xml_sorted = ET.SubElement(xml, 'li') +if args.reset_to_core: + while True: + data = input("Do you want to reset your mod list to Core only (y/n)? ") + if data.lower() in ('y', 'n'): + break + if data.lower() == "y": + print("Resetting your ModsConfig.xml to Core only!") + + xml_sorted = ET.SubElement(xml, 'li') + xml_sorted.text = "Core" + + doc.write(modsconfigfile, encoding='UTF-8', xml_declaration='False') + if wait_on_exit: + print("") + input("Press ENTER to close the program.") + sys.exit(1) + for mods in newlist: # print(mods) if mods[0] == "": @@ -247,7 +284,6 @@ def load_mod_data(cats, db, basedir, modsource): if mod_unknown: print("") print("Processing unknown mods.") - time.sleep(3) DB = dict() DB["version"] = 2 @@ -261,6 +297,15 @@ def load_mod_data(cats, db, basedir, modsource): unknown_meta["time"] = str(time.ctime()) DB["meta"] = unknown_meta + if dontremoveunknown: + print("Adding in unknown mods in the load order (at the bottom).") + for mods in mod_unknown: + if mods[0] == "": + print("skipping, empty?") + else: + xml_sorted = ET.SubElement(xml, 'li') + xml_sorted.text = str(mods[1]) + unknown_diff = dict() for mods in mod_unknown: if not disablesteam: @@ -302,7 +347,12 @@ def load_mod_data(cats, db, basedir, modsource): # ask for confirmation to write the ModsConfig.xml anyway while True: - data = input("Do you REALLY want to write ModsConfig.xml (unknown mods are removed from loading) (y/n): ") + if dontremoveunknown: + print("Unknown mods will be written at the end of the mod list.") + else: + print("Unknown mods will be removed.") + + data = input("Do you REALLY want to write ModsConfig.xml (y/n): ") if data.lower() in ('y', 'n'): break @@ -319,7 +369,6 @@ def load_mod_data(cats, db, basedir, modsource): else: print("ModsConfig.xml was NOT modified.") -time.sleep(2) if wait_on_exit: print("") input("Press ENTER to close the program.")