1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

666 Commits

Author SHA1 Message Date
Athanasius
ab281bca5a Implement msvcrt.locking() under win32
NB: The locked file *must* be opened at top level in order for the file
handle to not get cleaned up, which also removes the locks.
2021-01-18 21:09:11 +00:00
Athanasius
937a38f0b5 Remove extraneous enforce_single_instance() code & add opening of journal lock file 2021-01-18 21:09:10 +00:00
Athanasius
4689666b13 Strip out old win32 only window handle checking code. 2021-01-18 21:08:15 +00:00
Athanasius
c67b1b76f7 Move argsparse code to top & do rename enforce_single_instance() -> no_other_instance_running()
1. We need the args available at the top.
2. In `develop` we'd renamed `enforce_single_instance()` to
   `no_other_instance_running()` so that it's obvious it's a function
   returning a boolean, rather than the function that does the
   enforcement.
2021-01-18 14:48:17 +00:00
Athanasius
c3663d8be8 Move the 'duplicate' constants into a new constants.py
1. So now they're only defined in one place.
2. config.py does an import of them, and `from config import ...` then
   chains through, so no need to update other users.
3. No need to ' # noqa E402' the killswitch/config imports now.
2021-01-18 14:43:45 +00:00
Athanasius
778668f680 Add --suppress-dupe-process-popup and move enforce_single_instance() call after 2021-01-18 14:35:46 +00:00
Athanasius
08f1f3e7d9 EDMarketConnector: call config.set_shutdown() in AppWindow.onexit() 2021-01-11 15:37:47 +00:00
Athanasius
e51bde44ef Shutdown: re-order the top level calls
1. The updater is in a thread/DLL and we don't want that firing part way
  through shutdown, so it gets asked to stop first.
2. Then plugins, so they're out of the way and we won't have already
  stopped something they might rely on.
3. Hotkey after that to head off the user triggering something via them.
4. Now stop the programmatic input from Journal files (including
   Status.json).
5. Frontier auth handling.
6. And then anything else.
2021-01-08 15:44:06 +00:00
Athanasius
be18f36e54 EDMarketConnector: Bail in AppWindow.journal_entry if monitor.thread is None
monitor.thread should only be none when there's a <<JournalEvent>> to
process if we're in shutdown, in which case we do *not* want to be
processing journal events.
2021-01-08 14:56:22 +00:00
Athanasius
91e6583326
Merge pull request #812 from A-UNDERSCORE-D/fix/808-log-in-property-func
Added support for logging from properties
2021-01-05 14:27:59 +00:00
A_D
1cb876c594
Added support for logging from properties
This is some best effort support for using logging in properties.

This works by using the (as suggested by reporter) inspect
`getattr_static` method, and failing that (as it can possibly fail),
wrapping a `getattr` in a try/catch for a RecursionError--don't want to
catch other things, probably best if that explodes on its own.

From there as the `property` object will not have location information,
we rebuild as best we can to an approximation of what the path would be.
With a healthy dash of defensive programming "Just in case".

I don't think that this will have any adverse effects to other logging
methods, as all the new code should only be touched if we hit a property
object.

Closes #808
2020-12-21 12:39:45 +02:00
Athanasius
d903d80410 Make 'Shutting down...' text translatable. 2020-12-15 14:49:22 +00:00
Athanasius
5cc4a6e80b EDMarketConnector: Add detailed logging to shutdown sequence 2020-12-08 16:14:06 +00:00
Athanasius
2b60220365 EDMarketConnector: popup for "already running"
* This also refactors code around so that isort and flake8 are happy
  about the module level imports.
2020-12-08 16:06:50 +00:00
A_D
d650db5a1a Added name mangling support to EDMCContextFilter
Python name mangling is more about name collisions than actually making
things private.

This commit adds a check to resolve mangled names to their runtime
names, and adds a just-in-case default to fetching the attribute.

Fixes #764
2020-12-08 15:59:40 +00:00
Athanasius
582b981afa Locale: Be even more paranoid about setting UTF-8 encoding
* Only set if not on win32, or if we are and a known good version of
 Windows 10 (or later).
2020-10-14 19:15:48 +01:00
Athanasius
58bf8466ae locale: Remove conditional on locale setting & comments cleanup
* We're using try/except so can just attempt the setting of a UTF-8
  encoding.  In cases where it doesn't work we'll have some obvious log
  output to help diagnose any issues it causes later.

* Cleaned up the comments to be more 'why' than 'what'.
2020-10-06 16:16:21 +01:00
Athanasius
b235684dd6 Only attempt locale changes if *not* running frozen on win32.
Any running from source, or on a non-win32 platform will attempt to
force UTF-8 encoding.

For frozen win32 we'll rely on the windows manifest setting.  On too-old
versions of Windows we'll have to ensure all code works with non-UTF-8
encodings.
2020-10-06 15:16:15 +01:00
Athanasius
fb21cdfa94 Add reporting of Windows version at startup. 2020-10-06 15:03:51 +01:00
Athanasius
3063b237b6 Locale: Use LC_CTYPE as source of language for setting UTF-8 encoding
See #725 - LC_ALL is actually invalid here, but is allowed in Python
3.7.9, but not in later 3.8.x.
2020-10-01 11:00:11 +01:00
Athanasius
611db09fd0 Re-order imports so stdout/err redirect works for logging too.
Else the StreamHandler gets created with old stdout/err and causes
py2exe to attempt to write log file to CWD, which doesn't work when
installed.
2020-09-28 14:04:51 +01:00
Athanasius
9e6e718e23 Logging: Document trace/TRACE workaround & expand other docs. 2020-09-28 11:02:13 +01:00
Athanasius
1aba1a0596 Trace: Change several calls from debug to trace. 2020-09-23 22:07:18 +01:00
Athanasius
3c0ac76f90 Trace: Add support to EDMC.py & misc cleanups
* EDMC: Add --trace (to match EDMarketConnector.py) and TRACE as option to
  --loglevel.
* EDMC: docstrings added.
* EDMCLogging: Set logger name based on if GUI or CLI.
* EDMarketConnector:
  * Re-order imports.
  * Misc. formatting cleanups.
  * f-strings not .format().
  * Removed un-necessary "# noqa: N806" comments.
2020-09-23 17:38:38 +01:00
Athanasius
46e3b3aff8 Implement a TRACE level of logging.
For things that are too spammy for DEBUG, but we might need them
sometimes.
2020-09-23 15:58:19 +01:00
Athanasius
85d45aadd7 Place detailed logging for "Location" events.
To try and track down what's happening with #713
2020-09-23 11:45:48 +01:00
Athanasius
c1584d06fa EDMarketConnector.py: Tweak setting of UTF-8.
"UTF-8" is the official name, although it results in the same "utf8"
afterwards in this case.
2020-09-21 10:58:33 +01:00
Athanasius
8b5e5e73de Locale: More detailed login at startup around changes
As we might run into some special cases with users we need to log in
more detail what the locale is around our changes.

NB: Also contains some misc. PyCharm-enacted formatting changes, white
space, wrapping etc.
2020-09-15 10:28:28 +01:00
Athanasius
52dcd3b28a Use tkinter.filedialog on win32, because we now fix locale encoding
tkinter ends up calling something where utf8 characters won't work
because of the windows encoding, e.g. cp1252.

We can't set encoding just for the dialogs, as it's not thread safe.  So
we'll just set it at startup instead.  Utilising:

	locale.setlocale(locale.LC_ALL, '')

to get things set up initially, so we can properly retrieve the language
to go with the encoding on the subsequent setlocale() call.
2020-09-14 15:16:26 +01:00
Athanasius
cd24db88a9 UI Scaling: Size the Scale bar as per our startup value
If we use the last configured value then the width of the Scale bar
changes as per the user's last setting, even though they might not have
yet restarted for all the rest of the UI to resize.
2020-09-11 11:14:19 +01:00
Athanasius
0a5bbad55b UI Scaling: Change our %age scaling to be relative to base tk-scaling
So if at startup tk-scaling is 1.33 then a user configured 200(%) will
set it to 2.66 for this run.

* Low end of scale bar set to 10, not 0, because now 0 makes absolutely
  no sense.
* In theory the width of the scale bar, in pixels, is now also correctly
  scaled.
2020-09-11 09:26:01 +01:00
Athanasius
575acb3006 Log locale settings at start & ask in bug template. 2020-09-10 17:52:08 +01:00
Athanasius
f2ab8f0fd1 UI Scaling: Switch to using integers to avoid tk bug
Using a Tk.DoubleVar() with a locale where a comma is used as the
decimals separator leads to internal tk code recording values with the
comma but then other tk code not accepting that back, so it always
thinks the value is zero and the scale slider can't be moved.

Ref: https://stackoverflow.com/questions/45289237/tkinter-scale-slider-with-float-values-doesnt-work-with-locale-of-language-that

* Change to storing as a REG_DWORD under 'ui_scale' not 'ui_scaling'.
* Change all the code, except the call to *set* the tk scaling to use an
  integer, with 100 = 100%, i.e. equivalent to the old 1.0.
* Update strings slightly, so translations will need updating too.

NB: The theme.default_ui_scale value for plugin authors to query is
still the float that tk returns.
2020-09-10 16:54:14 +01:00
Athanasius
b4d7d56222 Startup: Log application and Python version, extra in debug.
* appversion and sys.version logged at INFO.
* At DEBUG: platform, argv[0], exec_prefix, executable, sys.path
2020-09-10 10:14:58 +01:00
Athanasius
1446796eb8 UI Scaling: Store pre-fiddling default in theme.default_ui_scale
This is in case anything needs to know the ratio between what was the
default and what we then set it to.
2020-09-09 16:18:23 +01:00
Athanasius
f25c743d14 Logging: Move stdout/stderr redirect to before logging can be run
If anything does `import logging` it's likely to grab a copy of
sys.stderr before we redirect it meaning things aren't properly
redirected when we start logging.

So put the redirect as early as possible in EDMarketConnector.py.

This will need a test implemented to be sure it's not accidentally
broken by addition of an import before this.
2020-09-09 15:26:08 +01:00
Athanasius
94607bf55f UI Scaling: Use a tk.Scale instead, allowing for finer grained setting.
* NB: Windows Registry has no type for 'Float', so we use a string.
* We now store '0.0' to mean 'default'.
2020-09-09 13:31:36 +01:00
Athanasius
1850354b8d UI Scaling: Implement a 'default' option
* If no ui_scaling yet set, set it to 'default'.
* 'default' added to dropdown choices.

Note that you still need an application restart for this to take effect.
2020-09-08 12:27:57 +01:00
Athanasius
09add21a1a Logging: DEBUG always to rotated files, configured level to stdout/err
* EDMCLogging.Logger.get_streamhandler() method to get the
  logger_channel so prefs.py can call setLevel() on it.
* The top-level Logger level is always DEBUG.
* The RotatingFileHandler level is always DEBUG.
* The StreamHandler level is as configured by the user.
* EDMCLogging now creates a singleton of EDMCLogging.Logger and its
  associated Logger.
* plug.py tweaked to only import EDMCLogging where it's needed for
  getting/creating plugin loggers, else `import logging`.
2020-09-08 10:03:16 +01:00
Athanasius
d940357854 EDMarketConnector.py: Blank line at the end. 2020-09-07 14:44:09 +01:00
Athanasius
10c3fec4f8 Logging: Set configured loglevel on creation 2020-09-07 14:40:55 +01:00
Athanasius
c3fbd1164e Logging: Implement additional logging to rotated set of files.
* All logging duplicated into %TEMP%/{appname}/{logger_name}.log
* These are handled by the RotatingFileHandler, currently set to 1MiB
  per file and 10 backup files.
* Do *NOT* setLevel() on the handlers, as we want to control the level
  up at the logger instead.  This would have caused the CL and GUI
  selection of loglevel to NOT have any effect (hidden by default having
  been DEBUG).
* EDMarketConnector.py now INFO logs its startup and exit.
2020-09-07 14:17:49 +01:00
Athanasius
bebe162071 logging: Now setting loglevel from Settings, and loading at start 2020-09-06 18:29:26 +01:00
Athanasius
c126251246 "Not Python 3.x" popup message sub-substitutions fixed.
string.format() doesn't assign to string, so actually need to do that.
2020-08-27 11:30:13 +01:00
Athanasius
98b6d4db38 Plugins "Not Python 3.x": Hacky escaping fix so translations work 2020-08-27 11:30:05 +01:00
Athanasius
3b87df17af Tweak EDMarketConnector.py startup so the redirect is first
* Don't want any output until the redirect is done when running frozen.
* Make the line buffering in the redirect more obvious.
2020-07-29 15:02:47 +01:00
Athanasius
4ecb4f573a 2 lines after def test_logging() 2020-07-29 15:02:47 +01:00
Athanasius
589bc0b5f1 Cover all cases with inspect
* <module> works.
* top-level function in <module> works, presumably also any other file.
* Call from within classes works.
* Extra, commented out, test cases in EDMarketConnector.py
2020-07-29 15:02:47 +01:00
Athanasius
a5b7bea2ca Move comment to line above if 2020-07-27 15:16:23 +01:00
Athanasius
9face638fe Minor cleanups all done.
Only remaining are:

 * TAE001 too few type annotations
 * Multiple "Cognitive complexity is too high" / "is too complex"
2020-07-27 13:00:59 +01:00