1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-27 14:02:13 +03:00

693 Commits

Author SHA1 Message Date
Athanasius
1663238cd0 Tweak comment about 'not locked' meaning doing edmc:// checks 2021-03-05 15:25:01 +00:00
Athanasius
f449286983 Implement retry of locking when journal dir changed.
In case the user does have another EDMC instance running that they need
to kill first.
2021-03-05 15:08:13 +00:00
Athanasius
e9c31c3293 Implement releasing of monitor.JournalLock()
* Implement JournalLock.release_lock().
* Renamed other methods to remove journaldir_ prefix.
* Slightly tweak the code flow for obtaining the lock.
* Implement JournalLock.update_lock(), called from AppWindow.postprefs().
2021-03-05 12:45:22 +00:00
Athanasius
c0e7be98f8 Move journal locking code into new monitor.JournalLock class 2021-03-05 12:03:54 +00:00
Athanasius
9b1b34f273
Merge pull request #857 from EDCD/enhancement/856-CL-arg-force-local-webserver
Add `--force-localserver-for-auth` CL arg to EDMarketConnector
2021-01-23 09:05:36 +00:00
Athanasius
b0f52b3d55 'import fcntl' failing means we need to lie about no other instances. 2021-01-22 14:15:32 +00:00
Athanasius
3b2b658881 Add --force-localserver-for-auth CL arg to EDMarketConnector 2021-01-22 13:11:42 +00:00
Athanasius
11b1c436a7 seek(0) before sys.stdout.truncate()
Without this we only truncate to where the file was when we did the
stdout/err redirect.

What I observed was it truncated out the "journal locking" output, but
not anything from a prior run of the program.
2021-01-22 13:10:03 +00:00
Athanasius
831367c30b Need to flush the journal dir lock file contents after write. 2021-01-20 14:45:09 +00:00
Athanasius
b3e4eafb14 Properly document the l_param passed to enumwindowsproc() 2021-01-19 20:40:56 +00:00
Athanasius
479bfe58eb Log truncate outside the 'else' & misc logging cleanups and comments
* The "truncate the stdout redirect" code was erroneously inside the
  else of a try.
* Added some comments about exceptions found on Linux when unable to
  open the journals_dir lock file
* Changed 'assuming another process running' logging to not split lines.
* "Couldn't open <journal lock file>" isn't inside no_other_instances()
  so made the message more obvious.
2021-01-19 12:39:32 +00:00
Athanasius
45619622af Catch when we can't open the journal_dir lockfile 2021-01-19 12:27:55 +00:00
Athanasius
0530eecc52 Fully set up logging early, and use it in no_other_instance() checks 2021-01-19 12:21:07 +00:00
Athanasius
7ed90aee83 Comment EnumWindows()/enumwindowsproc() to document function. 2021-01-19 11:54:17 +00:00
Athanasius
f86f1ac188 imports tweaks to pass isort 2021-01-18 22:27:53 +00:00
Athanasius
d2490673f4 Add some noqa: C901 & remove old SIGTERM -> stack trace
* We're not going to refactor those 'complex' sections any time soon, so
  clean up flake8 output for now.
* No-one still uses "send SIGTERM to see a stack trace".
2021-01-18 22:25:11 +00:00
Athanasius
2be09a5db1 Add back the "restore/foreground the existing window" code 2021-01-18 22:20:01 +00:00
Athanasius
35a476f209 Comments added, some noqa and split a line 2021-01-18 22:18:54 +00:00
Athanasius
1714219c17 Split enumwindowsproc() conditional into multiple lines 2021-01-18 21:54:45 +00:00
Athanasius
a75f5b9130 Move sys.stdout redirect to top.
* In `develop` config import will set up logging, so let's head that off
  at the pass and put the redirect right at the top.
* Also moved the EDMCLogging import to right after the config import's
  new position, to emulate `develop` behaviour.
* We *append* on the initial open of the redirect log file.  Then once
  we're sure we're the only process we truncate this.
2021-01-18 21:40:18 +00:00
Athanasius
820d481ca9 Restore old "another window with this handle?" code for edmc://auth
The edmc://auth catch/forward code relies on the old "is there another
window with this handle already?" check, so need to reinstate that code
*after* the lock check in order to forward the message.
2021-01-18 21:28:07 +00:00
Athanasius
377eef9c2b config import needs to be up top for now & misc
* The end of the win32/else conditional was identical, so only do that
  write to the successfully locked file in one place.

* No need to go out of `__main__` only to go straight back in.
2021-01-18 21:15:52 +00:00
Athanasius
397eda8d3e Catch only 'ImportError' for fcntl & 'Exception' for fcntl.flock() 2021-01-18 21:09:12 +00:00
Athanasius
bf2a10f88b Catch only 'Exception' off mvscrt.locking()
* It *should* only be a PermissionError, although the docs actually say
  the 'higher' OSError.  This way we will always catch whatever it is.
* The print uses {e!r} so as to make it explicit what the type of the
  exception is.
2021-01-18 21:09:12 +00:00
Athanasius
dbba1d24c7 Minor cleanups: Correct filename for lockfile, ...
* The variable is journal_dir_lockfile not lockfile.
* Typehint on journal_dir (likely not needed in `develop` as config.py
  is cleaned up there).
* Tweak the per-platform prints
2021-01-18 21:09:11 +00:00
Athanasius
0263dc628b Added some fcntl-based locking code for !win32
* If fcntl can't be imported it will just let things slide.
2021-01-18 21:09:11 +00:00
Athanasius
5c09ef78f8 Add comment as to why the file open is done at top level 2021-01-18 21:09:11 +00:00
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