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

612 Commits

Author SHA1 Message Date
Athanasius
c1fdd27020 EDMarketConnector: More typing, and removal of retry_for_shipyard()
* retry_for_shipyard() was only called by itself (for further retry),
  and tried to call self.eddn.export_shipyard() which doesn't even
  exist.
  I suspect this has been unused code since the EDDN code was extracted
  out into an internal plugin.
* self.drag_offset given proper typing.
* All functions have at least some typing now.  Left the 'event' Tk
  arguments bare as mypy seems to infer without complaint.
2021-04-01 14:45:43 +01:00
Athanasius
5d8e2a80af EDMarketConnector: noqa CCR001
Some of our code is just cognitively complex.
2021-04-01 14:45:43 +01:00
Athanasius
58787bc65e EDMarketConnector: Final type annotation fixups.
* Ignore Tkinter 'name' complaints.  I've opened
  <https://github.com/python/typeshed/issues/4658> to get this
  fixed in typeshed.
* If checking `import update` so it's available.
* Don't annotate journal_event 'event' arg, as it's passed through Tk
  events mechanism, so let mypy infer it.
2021-04-01 14:45:43 +01:00
Athanasius
aafc419124 EDMarketConnector: Initialise self.updater with type, but None value
This allows the type to be known, but leaves the proper setting of the
value until later (after UI creation).
2021-04-01 14:45:43 +01:00
Athanasius
a038b30855 EDMarketConnector: Remove call to deprecated config.getpassword() 2021-04-01 14:45:43 +01:00
Athanasius
55f1e11f0b EDMarketConnector: Correct __init__ master type & misc 2021-04-01 14:45:43 +01:00
Athanasius
97f3af2568 EDMarketConnector: Refactor of getandsend() and journal_event() 2021-04-01 14:45:43 +01:00
Athanasius
da9e406e81 EDMarketConnector: Convert debug data dump to f-string & misc
* docstring indent on Class A.
* Minor white space adjustments.
2021-04-01 14:45:43 +01:00
Athanasius
8a3fa50c97 EDMarketConnector: Pass on docstrings & Misc.
* Removed a couple of E501 ignores tagged as now un-necessary.
2021-04-01 14:45:43 +01:00
Athanasius
2ddea7d4f1 Log when we detect edmc:// arg and attempt ShellExecute()
This is the code path for when something ignores the ddeexec registry
key and instead invokes EDMarketConnector.exe with the edmc://...
argument directly.

Our response is to try ShellExecute() to invoke the DDE path instead.
If the DDE path isn't set up (registry key
`Computer\HKEY_CLASSES_ROOT\edmc\shell\open\ddeexec` not present and
correct), then this will cause a loop of repeatedly invoking
EDMarketConnector.exe.

That key is inserted by the installer.  The only reasons for it to not
be there would be something blocking the installer from creating it or
something removing it after install.
2021-03-18 10:13:15 +00:00
Athanasius
d6e7cbce16 Suppress already_running_popup() if we have args.edmc 2021-03-18 09:54:24 +00:00
Athanasius
d9734a759d Specify 'edmc' argument to argparse
Else it complains that the Frontier Auth callback argument is an error.
2021-03-18 09:39:53 +00:00
Athanasius
2da5e0a666
Merge pull request #915 from A-UNDERSCORE-D/fix/908/capidata-not-dict
Ensured that CAPIData objects are JSON Serialisable
2021-03-15 17:14:08 +00:00
A_D
fbe3e7a6e5
Ensured that CAPIData objects are JSON Serialisable
While it isnt directly an issue in main (right now), the fix applies
here forward, so we may as well do it here and not deal with a headache
later.
2021-03-15 18:53:20 +02:00
Athanasius
4f524a0a35 Add extra logging for Frontier Auth, especially via edmc:// 2021-03-15 12:07:39 +00:00
Athanasius
60c67723ca Change JournalLock.obtain_lock() return to an Enum.
This way we can tell the difference between:

1. This process obtained the lock.
2. Another process has the lock.
3. We couldn't get the lock due to not being able to open the lock file
   read-write.

Case 3 is currently also returned if the configured journal directory
doesn't exist.  This will be the case on any MacOS system that never had
the game running.  Likely given the OS hasn't been supported for the
game in years now.
2021-03-13 22:32:33 +00:00
Athanasius
a6939c77d9 Backport of fix/891/force-localserver-for-auth_fix-journallock-import
* Move JournalLock into its own file.
2021-03-09 12:37:59 +00:00
Athanasius
67a91cf7d1 CAPI: Handle when we get no 'commander' in returned data.
I was testing the new Steam or Epic CAPI auth.  My EGS account hasn't
yet been used, so has no commander attached.  EDMC thinks the auth has
succeeded in this case, but hitting 'Update' causes it to error because
the returned data is empty.

So, add some checks for lack of 'commander' key and a specific message
"CAPI: No commander data returned" for status line.

Without this there's a KeyError exception thrown, causing the status
line to just get 'commander' in it, which isn't helpful.
2021-03-06 18:54:18 +00:00
Athanasius
e430c3b350 Refactor old no_other_instance_running() into handle_edmc_callback_or_foregrounding()
The actual duplicate process checks *used* to be done in this function,
but no longer are.  Instead it's now specifically performing the "is
this an edmc:// auth callback?" check, including the foreground of the
extant process if needs be.
2021-03-05 15:57:53 +00:00
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