Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowgar committed Oct 7, 2014
2 parents a220087 + 80aab11 commit 8e68ee8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
8 changes: 7 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ factors that into the shopping for each subsequent hop.
== CHANGE LOG
==============================================================================

v4.0.2 Oct 06/2014
More systems/stations from ShadowGar!

v4.0.1 Oct 06/2014
Improved "--sublime" option, now supports Sublime Text 2 and works under Mac/Lin

v4.0 Oct 05/2014
Updated to Beta 2 - All credit to ShadowGar

Expand Down Expand Up @@ -399,7 +405,7 @@ UPDATE sub-command:

--sublime
--subl
Like "--editor" but finds and uses the Sublime Text 3 editor.
Like "--editor" but finds and uses the Sublime Text editor (2 and 3).
You can use "--editor" to tell it exactly where the editor
is located if it fails to find it.

Expand Down
39 changes: 31 additions & 8 deletions trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import sys # Inevitably.
import time
import pathlib # For path
import os

######################################################################
# The thing I hate most about Python is the global lock. What kind
Expand Down Expand Up @@ -481,6 +482,18 @@ def runCommand(args):
######################################################################
# "update" command functionality.

def getSublimeTextPaths():
paths = []
import platform
system = platform.system()
if system == 'Windows':
for folder in ["Program Files", "Program Files (x86)"]:
for version in [2, 3]:
paths.append("C:\\{}\\Sublime Text {}".format(folder, version))
paths += os.environ['PATH'].split(os.pathsep)
return [ paths, "sublime_text.exe" if system == 'Windows' else "subl" ]


def editUpdate(args, stationID):
"""
Dump the price data for a specific station to a file and
Expand All @@ -506,11 +519,17 @@ def editUpdate(args, stationID):
if "SUBLIME_EDITOR" in os.environ:
editor = os.environ["SUBLIME_EDITOR"]
else:
editor = "C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
if not pathlib.Path(editor).exists():
editor = "C:\\Program Files (x86)\\Sublime Text 3\\sublime_text.exe"
if not pathlib.Path(editor).exists():
print("ERROR: --sublime specified but could not find your Sublime Text 3 installation. Either specify the path to your editor with --editor or set the SUBLIME_EDITOR environment variable.")
(paths, binary) = getSublimeTextPaths()
for path in paths:
candidate = os.path.join(path, binary)
try:
if pathlib.Path(candidate).exists():
editor = candidate
break
except OSError:
pass
else:
raise CommandLineError("ERROR: --sublime specified but could not find your Sublime Text installation. Either specify the path to your editor with --editor or set the SUBLIME_EDITOR environment variable.")
editorArgs += [ "--wait" ]
elif args.notepad:
if args.debug: print("# Notepad mode")
Expand Down Expand Up @@ -541,8 +560,11 @@ def editUpdate(args, stationID):

# Launch the editor
editorCommandLine = [ editor ] + editorArgs + [ absoluteFilename ]
if args.debug: print("# Invoking [{}]".format(str(editorCommandLine)))
result = subprocess.call(editorCommandLine)
if args.debug: print("# Invoking [{}]".format(' '.join(editorCommandLine)))
try:
result = subprocess.call(editorCommandLine)
except FileNotFoundError:
raise CommandLineError("Unable to launch specified editor: {}".format(editorCommandLine))
if result != 0:
print("NOTE: Edit failed ({}), nothing to import.".format(result))
sys.exit(1)
Expand Down Expand Up @@ -847,7 +869,7 @@ def main():
switches = [
ParseArgument('--editor', help='Generates a text file containing the prices for the station and loads it into the specified editor.', default=None, type=str, action=EditAction),
[ # Mutually exclusive group:
ParseArgument('--sublime', help='Like --editor but uses Sublime Text 3, which is nice.', action=EditActionStoreTrue),
ParseArgument('--sublime', help='Like --editor but uses Sublime Text (2 or 3), which is nice.', action=EditActionStoreTrue),
ParseArgument('--notepad', help='Like --editor but uses Notepad.', action=EditActionStoreTrue),
]
]
Expand Down Expand Up @@ -878,3 +900,4 @@ def main():
print("%s: %s" % (sys.argv[0], str(e)))
if mfd:
mfd.finish()

0 comments on commit 8e68ee8

Please sign in to comment.