Skip to content

Commit

Permalink
v4.5.1 Issue #39 Use script path to locate data directory.
Browse files Browse the repository at this point in the history
When starting up, change current directory to match the path of trade.py
- so if you do "trade/trade.py" it will look for "trade/data/..."

Also added --dir (aka -C) to change directory
  • Loading branch information
Oliver Smith committed Oct 20, 2014
1 parent dad8399 commit e34d1d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ files from other commanders to fill out your database.
== CHANGE LOG
==============================================================================

v4.5.1 Oct 20/2014
. (kfsone) Added --dir (-C) command line for specifying which directory you
want trade.py to look in for it's files.
. (kfsone) trade.py will now default to trying to look for files relative
to where the "trade.py" script was called from. So if you run
"c:\tradedangerous\trade.py" it will look for the data directory as
"c:\tradedangerous\data\" (Issue #39)

v4.5.0 Oct 20/2014
. (Smacker65/Community) Smacker brings the star database up to 567 systems.

Expand Down
13 changes: 13 additions & 0 deletions trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ def main():
commonArgs.add_argument('--detail', '-v', help='Increase level of detail in output.', default=0, required=False, action='count')
commonArgs.add_argument('--quiet', '-q', help='Reduce level of detail in output.', default=0, required=False, action='count')
commonArgs.add_argument('--db', help='Specify location of the SQLite database. Default: {}'.format(TradeDB.defaultDB), type=str, default=str(TradeDB.defaultDB))
commonArgs.add_argument('--cwd', '-C', help='Change the directory relative to which TradeDangerous will try to access files such as the .db, etc.', type=str, required=False)

subparsers = parser.add_subparsers(dest='subparser', title='Commands')

Expand Down Expand Up @@ -1019,6 +1020,18 @@ def main():
if args.detail and args.quiet:
raise CommandLineError("'--detail' (-v) and '--quiet' (-q) are mutually exclusive.")

# If a directory was specified, relocate to it.
# Otherwise, try to chdir to
if args.dir:
os.chdir(args.dir)
else:
if sys.argv[0]:
cwdPath = pathlib.Path('.').resolve()
exePath = pathlib.Path(sys.argv[0]).parent.resolve()
if cwdPath != exePath:
if args.debug: print("# cwd at launch was: {}, changing to {} to match trade.py".format(cwdPath, exePath))
os.chdir(str(exePath))

# load the database
tdb = TradeDB(debug=args.debug, dbFilename=args.db)

Expand Down

0 comments on commit e34d1d3

Please sign in to comment.