tradedangerous 10.16.9__tar.gz → 10.16.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tradedangerous might be problematic. Click here for more details.

Files changed (97) hide show
  1. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/PKG-INFO +1 -1
  2. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/cache.py +2 -2
  3. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/eddblink_plug.py +6 -6
  4. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/spansh_plug.py +1 -1
  5. tradedangerous-10.16.11/tradedangerous/tradeenv.py +198 -0
  6. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/version.py +1 -1
  7. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous.egg-info/PKG-INFO +1 -1
  8. tradedangerous-10.16.9/tradedangerous/tradeenv.py +0 -131
  9. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/LICENSE +0 -0
  10. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/README.md +0 -0
  11. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/pyproject.toml +0 -0
  12. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/setup.cfg +0 -0
  13. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/setup.py +0 -0
  14. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_bootstrap_commands.py +0 -0
  15. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_bootstrap_plugins.py +0 -0
  16. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_cache.py +0 -0
  17. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_commands.py +0 -0
  18. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_fs.py +0 -0
  19. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_peek.py +0 -0
  20. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_tools.py +0 -0
  21. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_trade.py +0 -0
  22. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_trade_run.py +0 -0
  23. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tests/test_utils.py +0 -0
  24. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/__init__.py +0 -0
  25. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/cli.py +0 -0
  26. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/TEMPLATE.py +0 -0
  27. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/__init__.py +0 -0
  28. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/buildcache_cmd.py +0 -0
  29. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/buy_cmd.py +0 -0
  30. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/commandenv.py +0 -0
  31. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/exceptions.py +0 -0
  32. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/export_cmd.py +0 -0
  33. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/import_cmd.py +0 -0
  34. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/local_cmd.py +0 -0
  35. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/market_cmd.py +0 -0
  36. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/nav_cmd.py +0 -0
  37. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/olddata_cmd.py +0 -0
  38. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/parsing.py +0 -0
  39. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/rares_cmd.py +0 -0
  40. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/run_cmd.py +0 -0
  41. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/sell_cmd.py +0 -0
  42. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/shipvendor_cmd.py +0 -0
  43. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/station_cmd.py +0 -0
  44. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/trade_cmd.py +0 -0
  45. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/update_cmd.py +0 -0
  46. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/commands/update_gui.py +0 -0
  47. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/corrections.py +0 -0
  48. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/csvexport.py +0 -0
  49. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/edscupdate.py +0 -0
  50. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/edsmupdate.py +0 -0
  51. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/formatting.py +0 -0
  52. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/fs.py +0 -0
  53. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/gui.py +0 -0
  54. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/jsonprices.py +0 -0
  55. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/mapping.py +0 -0
  56. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/mfd/__init__.py +0 -0
  57. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/mfd/saitek/__init__.py +0 -0
  58. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/mfd/saitek/directoutput.py +0 -0
  59. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/mfd/saitek/x52pro.py +0 -0
  60. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/checkpricebounds.py +0 -0
  61. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/clipboard.py +0 -0
  62. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/coord64.py +0 -0
  63. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/derp-sentinel.py +0 -0
  64. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/diff-system-csvs.py +0 -0
  65. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/eddb.py +0 -0
  66. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/eddn.py +0 -0
  67. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/edsc.py +0 -0
  68. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/edsm.py +0 -0
  69. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/importeddbstats.py +0 -0
  70. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/prices-json-exp.py +0 -0
  71. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/misc/progress.py +0 -0
  72. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/__init__.py +0 -0
  73. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/edapi_plug.py +0 -0
  74. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/edcd_plug.py +0 -0
  75. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/edmc_batch_plug.py +0 -0
  76. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/journal_plug.py +0 -0
  77. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/plugins/netlog_plug.py +0 -0
  78. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/prices.py +0 -0
  79. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/submit-distances.py +0 -0
  80. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/templates/Added.csv +0 -0
  81. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/templates/Category.csv +0 -0
  82. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/templates/RareItem.csv +0 -0
  83. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/templates/TradeDangerous.sql +0 -0
  84. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/tools.py +0 -0
  85. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/trade.py +0 -0
  86. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/tradecalc.py +0 -0
  87. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/tradedb.py +0 -0
  88. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/tradeexcept.py +0 -0
  89. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/tradegui.py +0 -0
  90. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/transfers.py +0 -0
  91. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous/utils.py +0 -0
  92. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous.egg-info/SOURCES.txt +0 -0
  93. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous.egg-info/dependency_links.txt +0 -0
  94. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous.egg-info/entry_points.txt +0 -0
  95. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous.egg-info/not-zip-safe +0 -0
  96. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous.egg-info/requires.txt +0 -0
  97. {tradedangerous-10.16.9 → tradedangerous-10.16.11}/tradedangerous.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tradedangerous
3
- Version: 10.16.9
3
+ Version: 10.16.11
4
4
  Summary: Trade-Dangerous is a set of powerful trading tools for Elite Dangerous, organized around one of the most powerful trade run optimizers available.
5
5
  Home-page: https://github.com/eyeonus/Trade-Dangerous
6
6
  Author: eyeonus
@@ -919,7 +919,7 @@ def buildCache(tdb, tdenv):
919
919
 
920
920
  tdenv.NOTE(
921
921
  "Rebuilding cache file: this may take a few moments.",
922
- file = sys.stderr
922
+ stderr=True,
923
923
  )
924
924
 
925
925
  dbPath = tdb.dbPath
@@ -963,7 +963,7 @@ def buildCache(tdb, tdenv):
963
963
  tdenv.NOTE(
964
964
  "Missing \"{}\" file - no price data.",
965
965
  pricesPath,
966
- file = sys.stderr,
966
+ stderr=True,
967
967
  )
968
968
 
969
969
  tempDB.commit()
@@ -179,6 +179,7 @@ class ImportPlugin(plugins.ImportPluginBase):
179
179
 
180
180
  self.tdenv.NOTE("Downloading file '{}'.", path)
181
181
  transfers.download(self.tdenv, url, localPath)
182
+ os.utime(localPath, (dumpModded, dumpModded))
182
183
  return True
183
184
 
184
185
  def purgeSystems(self):
@@ -469,10 +470,6 @@ class ImportPlugin(plugins.ImportPluginBase):
469
470
 
470
471
  # Download required files and update tables.
471
472
  buildCache = False
472
- if self.getOption("purge"):
473
- self.purgeSystems()
474
- self.commit()
475
-
476
473
  if self.getOption("upgrade"):
477
474
  if self.downloadFile(self.upgradesPath) or self.getOption("force"):
478
475
  self.downloadFile(self.FDevOutfittingPath)
@@ -512,14 +509,17 @@ class ImportPlugin(plugins.ImportPluginBase):
512
509
  if buildCache:
513
510
  cache.buildCache(self.tdb, self.tdenv)
514
511
 
512
+ if self.getOption("purge"):
513
+ self.purgeSystems()
514
+ # self.commit()
515
+
515
516
  if self.getOption("listings"):
516
517
  if self.downloadFile(self.listingsPath) or self.getOption("force"):
517
518
  self.importListings(self.listingsPath)
518
519
  if self.downloadFile(self.liveListingsPath) or self.getOption("force"):
519
520
  self.importListings(self.liveListingsPath)
520
521
 
521
- self.commit()
522
-
522
+ # self.commit()
523
523
  self.tdb.close()
524
524
 
525
525
  if self.getOption("listings"):
@@ -218,7 +218,7 @@ class ImportPlugin(plugins.ImportPluginBase):
218
218
  self.execute('COMMIT')
219
219
  self.tdb.close()
220
220
  # Need to make sure cached tables are updated
221
- for table in [ "Item", "Station", "System", "StationItem" ]:
221
+ for table in [ "Item", "Station", "System" ]:
222
222
  _, path = csvexport.exportTableToFile( self.tdb, self.tdenv, table )
223
223
 
224
224
  self.print(
@@ -0,0 +1,198 @@
1
+ # The runtime environment TD tools are expected to run with is encapsulated
2
+ # into a single object, the TradeEnv. See TradeEnv docstring for more.
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import sys
7
+ import traceback
8
+ import typing
9
+ from contextlib import contextmanager
10
+
11
+ # Import some utilities from the 'rich' library that provide ways to colorize and animate
12
+ # the console output, along with other useful features.
13
+ # If the user has 'EXCEPTIONS' defined to something in the environment, then we can
14
+ # immediately benefit from beautified stacktraces.
15
+ from rich.console import Console
16
+ from rich.traceback import install as install_rich_traces
17
+
18
+
19
+ if typing.TYPE_CHECKING:
20
+ from typing import Any, Dict, Iterator
21
+
22
+
23
+ _ROOT = os.path.abspath(os.path.dirname(__file__))
24
+
25
+
26
+ # Create a single instance of the console for everyone to use, unless they really
27
+ # want to do something unusual.
28
+ CONSOLE = Console()
29
+ STDERR = Console(stderr=True)
30
+
31
+ if os.getenv("EXCEPTIONS"):
32
+ # This makes call stacks show additional context and do syntax highlighting
33
+ # that can turn reading a callstack from hours into seconds.
34
+ install_rich_traces(console=STDERR, show_locals=False, extra_lines=1)
35
+
36
+
37
+ class TradeEnv:
38
+ """
39
+ Container for a TradeDangerous "environment", which is a collection of operational parameters.
40
+
41
+ To print debug lines, use DEBUG<N>, e.g. DEBUG0, which takes a format() string and parameters, e.g.
42
+
43
+ DEBUG1("hello, {world}{}", "!", world="world")
44
+
45
+ is equivalent to:
46
+
47
+ if tdenv.debug >= 1:
48
+ print("#hello, {world}{}".format(
49
+ "!", world="world"
50
+ ))
51
+
52
+ Use "NOTE" to print remarks which can be disabled with -q.
53
+ """
54
+
55
+ defaults = {
56
+ 'debug': 0,
57
+ 'detail': 0,
58
+ 'quiet': 0,
59
+ 'color': False,
60
+ 'dataDir': os.environ.get('TD_DATA') or os.path.join(os.getcwd(), 'data'),
61
+ 'csvDir': os.environ.get('TD_CSV') or os.environ.get('TD_DATA') or os.path.join(os.getcwd(), 'data'),
62
+ 'tmpDir': os.environ.get('TD_TMP') or os.path.join(os.getcwd(), 'tmp'),
63
+ 'templateDir': os.path.join(_ROOT, 'templates'),
64
+ 'cwDir': os.getcwd(),
65
+ 'console': CONSOLE,
66
+ 'stderr': STDERR,
67
+ }
68
+
69
+ encoding = sys.stdout.encoding
70
+
71
+ if str(sys.stdout.encoding).upper() != 'UTF-8':
72
+ def uprint(self, *args, stderr: bool = False, style: str = None, **kwargs) -> None:
73
+ """ unicode-handling print: when the stdout stream is not utf-8 supporting,
74
+ we do a little extra io work to ensure users don't get confusing unicode
75
+ errors. When the output stream *is* utf-8, tradeenv replaces this method
76
+ with a less expensive method.
77
+ :param stderr: report to stderr instead of stdout
78
+ :param style: specify a 'rich' console style to use when the stream supports it
79
+ """
80
+ console = self.stderr if stderr else self.console
81
+ try:
82
+ # Attempt to print; the 'file' argument isn't spuported by rich, so we'll
83
+ # need to fall-back on old print when someone specifies it.
84
+ console.print(*args, style=style, **kwargs)
85
+
86
+ except UnicodeEncodeError as e:
87
+ # Characters in the output couldn't be translated to unicode.
88
+ if not self.quiet:
89
+ self.stderr.print(
90
+ "[orange3][bold]CAUTION: Your terminal/console couldn't handle some "
91
+ "text I tried to print."
92
+ )
93
+ if 'EXCEPTIONS' in os.environ:
94
+ traceback.print_exc()
95
+ else:
96
+ self.stderr.print(e)
97
+
98
+ # Try to translate each ary into a viable stirng using utf error-replacement.
99
+ strs = [
100
+ str(arg)
101
+ .encode(TradeEnv.encoding, errors="replace")
102
+ .decode(TradeEnv.encoding)
103
+ for arg in args
104
+ ]
105
+ console.print(*strs, style=style, **kwargs)
106
+
107
+ else:
108
+ def uprint(self, *args, stderr: bool = False, style: str = None, **kwargs) -> None:
109
+ """ unicode-handling print: when the stdout stream is not utf-8 supporting,
110
+ this method is replaced with one that tries to provide users better support
111
+ when a unicode error appears in the wild.
112
+
113
+ :param file: [optional] stream to write to (disables styles/rich support)
114
+ :param style: [optional] specify a rich style for the output text
115
+ """
116
+ console = self.stderr if stderr else self.console
117
+ console.print(*args, style=style, **kwargs)
118
+
119
+
120
+ def __init__(self, properties: Optional[Union[argparse.Namespace, Dict]] = None, **kwargs) -> None:
121
+ # Inject the defaults into ourselves in a dict-like way
122
+ self.__dict__.update(self.defaults)
123
+
124
+ # If properties is a namespace, extract the dictionary; otherwise use it as-is
125
+ if properties and hasattr(properties, '__dict__'): # which arparse.Namespace has
126
+ properties = properties.__dict__
127
+ # Merge into our dictionary
128
+ self.__dict__.update(properties or {})
129
+
130
+ # Merge the kwargs dictionary
131
+ self.__dict__.update(kwargs or {})
132
+
133
+ # When debugging has been enabled on startup, enable slightly more
134
+ # verbose rich backtraces.
135
+ if self.__dict__['debug']:
136
+ install_rich_traces(console=STDERR, show_locals=True, extra_lines=2)
137
+
138
+ def __getattr__(self, key: str) -> Any:
139
+ """ Return the default for attributes we don't have """
140
+
141
+ # The first time the DEBUG attribute is referenced, register a method for it.
142
+ if key.startswith("DEBUG"):
143
+
144
+ # Self-assembling DEBUGN functions
145
+ def __DEBUG_ENABLED(outText, *args, **kwargs):
146
+ # Give debug output a less contrasted color.
147
+ self.console.print(f"[dim]#{outText.format(*args, **kwargs)}[/dim]")
148
+
149
+ def __DEBUG_DISABLED(*args, **kwargs):
150
+ pass
151
+
152
+ # Tried to call a .DEBUG<N> function which hasn't
153
+ # been called before; create a stub.
154
+ debugLevel = int(key[5:])
155
+ if self.debug > debugLevel:
156
+ debugFn = __DEBUG_ENABLED
157
+ else:
158
+ debugFn = __DEBUG_DISABLED
159
+ setattr(self, key, debugFn)
160
+ return debugFn
161
+
162
+ if key == "NOTE":
163
+
164
+ def __NOTE_ENABLED(outText, *args, stderr: bool = False, **kwargs):
165
+ self.uprint(
166
+ "NOTE:", str(outText).format(*args, **kwargs),
167
+ style="bold",
168
+ stderr=stderr,
169
+ )
170
+
171
+ def __NOTE_DISABLED(*args, **kwargs):
172
+ pass
173
+
174
+ # Tried to call "NOTE" but it hasn't been called yet,
175
+ if not self.quiet:
176
+ noteFn = __NOTE_ENABLED
177
+ else:
178
+ noteFn = __NOTE_DISABLED
179
+ setattr(self, key, noteFn)
180
+ return noteFn
181
+
182
+ if key == "WARN":
183
+
184
+ def _WARN_ENABLED(outText, *args, stderr: bool = False, **kwargs):
185
+ self.uprint(
186
+ "WARNING:", str(outText).format(*args, **kwargs),
187
+ style="orange3",
188
+ stderr=stderr,
189
+ )
190
+
191
+ def _WARN_DISABLED(*args, **kwargs):
192
+ pass
193
+
194
+ noteFn = _WARN_DISABLED if self.quiet > 1 else _WARN_ENABLED
195
+ setattr(self, key, noteFn)
196
+ return noteFn
197
+
198
+ return None
@@ -12,5 +12,5 @@
12
12
  """just keeper of current version"""
13
13
 
14
14
  # TODO: remember to update tests when version changes
15
- __version__ = '10.16.9'
15
+ __version__ = '10.16.11'
16
16
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tradedangerous
3
- Version: 10.16.9
3
+ Version: 10.16.11
4
4
  Summary: Trade-Dangerous is a set of powerful trading tools for Elite Dangerous, organized around one of the most powerful trade run optimizers available.
5
5
  Home-page: https://github.com/eyeonus/Trade-Dangerous
6
6
  Author: eyeonus
@@ -1,131 +0,0 @@
1
- from __future__ import absolute_import, with_statement, print_function, division, unicode_literals
2
-
3
- import os
4
- import traceback
5
- import sys
6
- _ROOT = os.path.abspath(os.path.dirname(__file__))
7
-
8
-
9
- class TradeEnv(object):
10
- """
11
- Container for a TradeDangerous "environment", which is a
12
- collection of operational parameters.
13
-
14
- To print debug lines, use DEBUG<N>, e.g. DEBUG0, which
15
- takes a format() string and parameters, e.g.
16
-
17
- DEBUG1("hello, {world}{}", "!", world="world")
18
-
19
- is equivalent to:
20
-
21
- if tdenv.debug >= 1:
22
- print("#hello, {world}{}".format(
23
- "!", world="world"
24
- ))
25
-
26
- Use "NOTE" to print remarks which can be disabled with -q.
27
- """
28
-
29
- defaults = {
30
- 'debug': 0,
31
- 'detail': 0,
32
- 'quiet': 0,
33
- 'color': False,
34
- 'dataDir': os.environ.get('TD_DATA') or os.path.join(os.getcwd(), 'data'),
35
- 'csvDir': os.environ.get('TD_CSV') or os.environ.get('TD_DATA') or os.path.join(os.getcwd(), 'data'),
36
- 'tmpDir': os.environ.get('TD_TMP') or os.path.join(os.getcwd(), 'tmp'),
37
- 'templateDir': os.path.join(_ROOT, 'templates'),
38
- 'cwDir': os.getcwd()
39
- }
40
-
41
- encoding = sys.stdout.encoding
42
- if str(sys.stdout.encoding).upper() != 'UTF-8':
43
-
44
- def uprint(self, *args, **kwargs):
45
- try:
46
- print(*args, **kwargs)
47
- except UnicodeEncodeError as e:
48
- if not self.quiet:
49
- print(
50
- "CAUTION: Your terminal/console couldn't handle some "
51
- "text I tried to print."
52
- )
53
- if 'EXCEPTIONS' in os.environ:
54
- traceback.print_exc()
55
- else:
56
- print(str(e))
57
- strs = [
58
- str(arg).
59
- encode(TradeEnv.encoding, errors = 'replace').
60
- decode(TradeEnv.encoding)
61
- for arg in args
62
- ]
63
- print(*strs, **kwargs)
64
-
65
- else:
66
- uprint = print
67
-
68
- def __init__(self, properties = None, **kwargs):
69
- properties = properties or dict()
70
- self.__dict__.update(self.defaults)
71
- if properties:
72
- self.__dict__.update(properties.__dict__)
73
- if kwargs:
74
- self.__dict__.update(kwargs)
75
-
76
- def __getattr__(self, key):
77
- """ Return the default for attributes we don't have """
78
- if key.startswith("DEBUG"):
79
-
80
- # Self-assembling DEBUGN functions
81
- def __DEBUG_ENABLED(outText, *args, **kwargs):
82
- print('#', outText.format(*args, **kwargs))
83
-
84
- def __DEBUG_DISABLED(*args, **kwargs):
85
- pass
86
-
87
- # Tried to call a .DEBUG<N> function which hasn't
88
- # been called before; create a stub.
89
- debugLevel = int(key[5:])
90
- if self.debug > debugLevel:
91
- debugFn = __DEBUG_ENABLED
92
- else:
93
- debugFn = __DEBUG_DISABLED
94
- setattr(self, key, debugFn)
95
- return debugFn
96
-
97
- if key == "NOTE":
98
-
99
- def __NOTE_ENABLED(outText, *args, file = None, **kwargs):
100
- self.uprint(
101
- "NOTE:", str(outText).format(*args, **kwargs),
102
- file = file,
103
- )
104
-
105
- def __NOTE_DISABLED(*args, **kwargs):
106
- pass
107
-
108
- # Tried to call "NOTE" but it hasn't been called yet,
109
- if not self.quiet:
110
- noteFn = __NOTE_ENABLED
111
- else:
112
- noteFn = __NOTE_DISABLED
113
- setattr(self, key, noteFn)
114
- return noteFn
115
-
116
- if key == "WARN":
117
-
118
- def _WARN_ENABLED(outText, *args, file = None, **kwargs):
119
- self.uprint(
120
- "WARNING:", str(outText).format(*args, **kwargs),
121
- file = file
122
- )
123
-
124
- def _WARN_DISABLED(*args, **kwargs):
125
- pass
126
-
127
- noteFn = _WARN_DISABLED if self.quiet > 1 else _WARN_ENABLED
128
- setattr(self, key, noteFn)
129
- return noteFn
130
-
131
- return None