-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a TradeEnv base for CommandEnv
This facilities the old "t = TradeDB()" behavior, e.g. ``` Meanwhile it also slightly simplified CommandEnv from tradedb import * tdb = TradeDB() # or specify arguments from tradeenv import * tenv = TradeEnv(debug=1, dbFilename='test.db') tdb = TradeDB(tenv) ```
- Loading branch information
Showing
4 changed files
with
62 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class TradeEnv(object): | ||
""" | ||
Container for a TradeDangerous "environment", which is a | ||
collection of operational parameters. | ||
""" | ||
|
||
def __init__(self, properties=None, **kwargs): | ||
properties = properties or type('Properties', (), dict()) | ||
|
||
self._props = properties | ||
for arg, value in kwargs.items(): | ||
setattr(self, arg, value) | ||
|
||
|
||
def __getattr__(self, key, default=None): | ||
""" Fall back to _props when accessing attributes. """ | ||
try: | ||
return getattr(self._props, key, default) | ||
except AttributeError: | ||
return default | ||
|
||
|
||
def DEBUG(self, debugLevel, outText, *args, **kwargs): | ||
""" | ||
Output text to stderr on the condition that | ||
the current debug setting is higher than debugLevel | ||
""" | ||
if self.debug > debugLevel: | ||
print('#', outText.format(*args, **kwargs)) | ||
|