Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
orphu committed Aug 8, 2015
2 parents 6c6a1f0 + 81090cb commit b3c478b
Show file tree
Hide file tree
Showing 12 changed files with 28,696 additions and 13,748 deletions.
30 changes: 30 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v7.3.2 Jul 30 2015
. (kfsone) Alternate fix for edapi.

v7.3.1 Jul 21 2015:
. (kfsone) Fix for edapi.

Jul 07 2015:
. (kfsone) Fixed division by zero in transfers.py with empty file

v7.3.0 Jul 05 2015:
. (ahamid/kfsone) "fromfile" support for command options:
- All commands will now look for a "fromfile" specifying default arguments
for that command .tdrc_{cmd} e.g .tdrc_nav or .tdrc_shipvendor,
- One argument-position per line, "--ly 20" is two lines but "--ly=20" is one,
- The fromfile argument is replaced with the arguments in the file,
- Looks in the current directory and then your user directory,
- You can also use your own fromfile as an argument prefixed with a '+':
trade.py nav +myfrom.txt
. (Fred Deschenes) "buy" now supports categories e.g.
trade.py buy --near sol metals,food
- to find food cartridges, use foodc or "food cartridges",

Jun 20 2015:
. (kfsone) Lots of new systems (until EDSC broke),
. (kfsone) Minor optimizations,
. (kfsone) Tweaks to edscupdate,

v7.2.1 Jun 16 2015:
. (maddavo) Lot of cleanup

v7.2.0 Jun 14 2015:
. (Orphu) Created an import plugin that uses Frontier's Mobile API,
- See README.md for more help,
Expand Down
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ Other options are "parameters" which take a value, for example `--from Sol` woul

In the list below, you'll see `--detail` and `-v` listed together. This indicates that `-v` is the short-form for `--detail`.

##Filing under D for Default
You can store preferred/default arguments/options in text files called "fromfiles". Each command automatically looks for a file called ".tdrc_<command>", so for the shipvendor
command it looks for ".tdrc_shipvendor". Note the leading '.'. You can also specify your own "fromfiles". See "Fromfiles" below for more details.


##Basic Usage:

trade.py command arguments
Expand Down Expand Up @@ -1035,7 +1040,7 @@ Finds stations that are selling / where you can buy, a named list of items or sh
[--near N] [--ly-per N] [--avoid PLACES]
[--pad-size PSML?] [--black-market | --bm]
[--one-stop | -1]
item [item item,item …]
category|item [category|item category|item,category|item,category|item …]
ship [ship ship,ship …]

###Options:
Expand Down Expand Up @@ -1101,7 +1106,8 @@ Finds stations that are selling / where you can buy, a named list of items or sh

###Example:

trade.py buy --near achenar food
trade.py buy --near achenar food (finds all items in food category)
trade.py buy --near achenar foodcart (finds food cartridges)
trade.py buy asp
trade.py buy --near achenar food,clothing,scrap --one-stop
trade.py buy --near achenar type6,type7 -1
Expand Down Expand Up @@ -1308,6 +1314,53 @@ This command looks for known rare items within the space around a specified syst
ANY NA/Libby Orbital Any Na Coffee 1,790 170.32 11 ? ?


#Fromfiles: Options in a can
A "fromfile" is a plain text file with TD command line options. For instance,
you could create a file for each ship specifying the --ly, --cap, --empty, etc.

You specify a fromfile on the command line by prefixing the filename with a '+'

So if you want to read "sidewinder.tdf" you would type

trade.py nav +sidewinder.tdf

Of course, that's a lot to type, and we're trying to be lazy, so just go ahead
and call the file "sw" :)

trade.py nav +sw

##Contents of a fromfile
A fromfile is simple: each line must correspond to one position on the
command line. So, "--empty-ly 30" becomes *two lines* while "--ly=20" is one.

--empty-ly
30
--ly=20

##Default defaults: .tdrc files
Each TD command automatically looks for a file called ".tdrc_<command>", e.g.
".tdrc_shipvendor". Note the leading dot. If this file exists, the options are
read at the start of the command line.

So if you have the following .tdrc_nav

--empty-ly
30
--ly=20
-v

and you type:

trade.py nav sol waruts -vv -ly=21

TD will behave as though you gave the command line:

trade.py nav --empty-ly 30 --ly=20 -v sol waruts -vv --ly=21

Which is equivalent to:

trade.py nav --empty-ly 30 sol waruts -vvv --ly=21

#Adding or Changing Price Data
##Experimental GUI in 6.0
As of v6.0 I've added an experimental GUI for updating prices. I'm still working out some of the issues, in particular you currently have to manually size and scroll the window.
Expand Down
23 changes: 20 additions & 3 deletions commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def addArguments(group, options, required, topGroup=None):
group.add_argument(*(option.args), nargs='?', **(option.kwargs))


def _findFromFile(cmd, prefix='.tdrc'):
if cmd:
# check the current directory, fall back to home
filename = '{}_{}'.format(prefix, cmd)
for dirname in '.', os.path.expanduser('~'):
cmdPath = pathlib.Path(dirname) / filename
if cmdPath.exists():
return cmdPath.resolve()
return None


class CommandIndex(object):
def usage(self, argv):
"""
Expand Down Expand Up @@ -121,7 +132,7 @@ def usage(self, argv):
return text


def parse(self, argv):
def parse(self, argv, fromfile_prefix='+'):
if len(argv) <= 1 or argv[1] == '--help' or argv[1] == '-h':
raise exceptions.UsageError(
"TradeDangerous provides a set of trade database "
Expand Down Expand Up @@ -168,7 +179,8 @@ def error(self, message):
add_help=False,
epilog='Use {prog} {cmd} -h for more help'.format(
prog=argv[0], cmd=argv[1]
)
),
fromfile_prefix_chars=fromfile_prefix,
)
parser.set_defaults(_editing=False)
parsing.registerParserHelpers(parser)
Expand Down Expand Up @@ -223,7 +235,12 @@ def error(self, message):
default=None, dest='maxSystemLinkLy',
)

fromfilePath = _findFromFile(cmdModule.name)
if fromfilePath:
argv.insert(2, '{}{}'.format(fromfile_prefix, fromfilePath))
properties = parser.parse_args(argv[1:])

return CommandEnv(properties, argv, cmdModule)
parsed = CommandEnv(properties, argv, cmdModule)
parsed.DEBUG0("Command line was: {}", argv)

return parsed
22 changes: 21 additions & 1 deletion commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,28 @@ def get_lookup_list(cmdenv, tdb):
names = [
name for names in cmdenv.name for name in names.split(',')
]
queries, mode = {}, None
# We only support searching for one type of purchase a time: ship or item.
# Our first match is open ended, but once we have matched one type of
# thing, the remaining arguments are all sourced from the same pool.
# Thus: [food, cobra, metals] is illegal but [metals, hydrogen] is legal.
mode = None

queries = {}
for name in names:
if mode is not SHIP_MODE:
# Either no mode selected yet or we are in ITEM_MODE.
# Consider categories first.
try:
category = tdb.lookupCategory(name)
for item in category.items:
names.append(item.name())
queries[item.ID] = item
mode = ITEM_MODE
continue
except LookupError:
pass

# Item names secondary.
try:
item = tdb.lookupItem(name)
cmdenv.DEBUG0("Looking up item {} (#{})", item.name(), item.ID)
Expand All @@ -114,6 +133,7 @@ def get_lookup_list(cmdenv, tdb):
)
pass

# Either no mode selected yet or we are in SHIP_MODE.
try:
ship = tdb.lookupShip(name)
cmdenv.DEBUG0("Looking up ship {} (#{})", ship.name(), ship.ID)
Expand Down
Loading

0 comments on commit b3c478b

Please sign in to comment.