From 67708fd0901ccebcb87268accba7781c0cf8f19e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 18 Sep 2019 13:29:05 +0100 Subject: [PATCH] Initial work on getting the EDMC.py CLI to work under python3 *) Fix up print usage *) cPickle -> cpickle *) "EDMC.py -p " appears to have never been properly updated for multi-account support. --- EDMC.py | 10 +++++----- collate.py | 22 +++++++++++----------- edshipyard.py | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/EDMC.py b/EDMC.py index 6527adf4..989b05b6 100755 --- a/EDMC.py +++ b/EDMC.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # # Command-line interface. Requires prior setup through the GUI. # @@ -72,7 +72,7 @@ try: latest = ' (%s is available)' % items[lastversion] except: pass # Quietly suppress timeouts etc. - print '%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest) # just first three digits + print('%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest)) # just first three digits sys.exit(EXIT_SUCCESS) if args.j: @@ -92,7 +92,7 @@ try: monitor.parse_entry(line) except: if __debug__: - print 'Invalid journal entry "%s"' % repr(line) + print('Invalid journal entry "%s"' % repr(line)) except Exception as e: sys.stderr.write("Can't read Journal file: %s\n" % unicode(e).encode('ascii', 'replace')) sys.exit(EXIT_SYS_ERR) @@ -159,9 +159,9 @@ try: stats.export_status(data, args.t) if data['commander'].get('docked'): - print '%s,%s' % (data.get('lastSystem', {}).get('name', 'Unknown'), data.get('lastStarport', {}).get('name', 'Unknown')) + print('%s,%s' % (data.get('lastSystem', {}).get('name', 'Unknown'), data.get('lastStarport', {}).get('name', 'Unknown'))) else: - print data.get('lastSystem', {}).get('name', 'Unknown') + print(data.get('lastSystem', {}).get('name', 'Unknown')) if (args.m or args.o or args.s or args.n or args.j): if not data['commander'].get('docked'): diff --git a/collate.py b/collate.py index e006ce62..c1657ead 100755 --- a/collate.py +++ b/collate.py @@ -58,7 +58,7 @@ def addcommodities(data): for key in sorted(commodities): writer.writerow(commodities[key]) - print 'Added %d new commodities' % (len(commodities) - size_pre) + print('Added %d new commodities' % (len(commodities) - size_pre)) # keep a summary of modules found def addmodules(data): @@ -83,7 +83,7 @@ def addmodules(data): try: new = outfitting.lookup(module, companion.ship_map, True) except: - print '%d, %s:' % (module['id'], module['name']) + print('%d, %s:' % (module['id'], module['name'])) print_exc(0) new = None if new: @@ -110,7 +110,7 @@ def addmodules(data): for key in sorted(modules): writer.writerow(modules[key]) - print 'Added %d new modules' % (len(modules) - size_pre) + print('Added %d new modules' % (len(modules) - size_pre)) # keep a summary of ships found def addships(data): @@ -158,33 +158,33 @@ def addships(data): for key in sorted(ships): writer.writerow(ships[key]) - print 'Added %d new ships' % (len(ships) - size_pre) + print('Added %d new ships' % (len(ships) - size_pre)) if __name__ == "__main__": if len(sys.argv) <= 1: - print 'Usage: collate.py [dump.json]' + print('Usage: collate.py [dump.json]') else: # read from dumped json file(s) session = companion.Session() for f in sys.argv[1:]: with open(f) as h: - print f + print(f) data = json.load(h) if not data['commander'].get('docked'): - print 'Not docked!' + print('Not docked!') elif not data.get('lastStarport'): - print 'No starport!' + print('No starport!') else: if data['lastStarport'].get('commodities'): addcommodities(data) else: - print 'No market' + print('No market') if data['lastStarport'].get('modules'): addmodules(data) else: - print 'No outfitting' + print('No outfitting') if data['lastStarport'].get('ships'): addships(data) else: - print 'No shipyard' + print('No shipyard') diff --git a/edshipyard.py b/edshipyard.py index dc19fb1c..f8de96fe 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -1,6 +1,6 @@ # Export ship loadout in E:D Shipyard plain text format -import cPickle +import pickle from collections import defaultdict import os from os.path import join @@ -40,7 +40,7 @@ slot_map = { # Ship masses -ships = cPickle.load(open(join(config.respath, 'ships.p'), 'rb')) +ships = pickle.load(open(join(config.respath, 'ships.p'), 'rb')) # Export ship loadout in E:D Shipyard plain text format @@ -107,10 +107,10 @@ def export(data, filename=None): if slot.lower().startswith('slot'): loadout[slot[-1]].append(cr + name) elif __debug__ and not slot.lower().startswith('planetaryapproachsuite'): - print 'EDShipyard: Unknown slot %s' % slot + print('EDShipyard: Unknown slot %s' % slot) except AssertionError as e: - if __debug__: print 'EDShipyard: %s' % e + if __debug__: print('EDShipyard: %s' % e) continue # Silently skip unrecognized modules except: if __debug__: raise