Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
new configuration option "dontremoveunknown", new CLI parsing, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shakeyourbunny committed May 8, 2019
1 parent b373b09 commit c3ab809
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 14 deletions.
22 changes: 20 additions & 2 deletions 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):
Expand All @@ -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.
Expand Down
18 changes: 17 additions & 1 deletion README.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.94.2
0.94.3
3 changes: 3 additions & 0 deletions rwms_config.ini
Expand Up @@ -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
Expand Down
69 changes: 59 additions & 10 deletions rwms_sort.py
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/env python
# RimWorld Module Sorter
import collections
import json
Expand All @@ -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

Expand All @@ -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")
Expand All @@ -37,14 +49,24 @@
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):
print("*** Update available, new version is {} ***".format(rwms_update.__load_version_from_repo()))
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)
Expand Down Expand Up @@ -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:
Expand All @@ -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("")
Expand Down Expand Up @@ -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("")
Expand All @@ -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] == "":
Expand All @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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.")

0 comments on commit c3ab809

Please sign in to comment.