From 82d6aa78399b825bcfb80774c06f10c1bb60e1e0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Oct 2020 15:20:53 +0100 Subject: [PATCH 001/727] Add docs/Windows-Manifest.md --- docs/Windows-Manifest.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 docs/Windows-Manifest.md diff --git a/docs/Windows-Manifest.md b/docs/Windows-Manifest.md new file mode 100644 index 00000000..68136778 --- /dev/null +++ b/docs/Windows-Manifest.md @@ -0,0 +1,21 @@ +# Introduction + +There are some attributes that can be set on a Windows executable via a +manifest. This is a section in the executable. The easiest way to set +this is to include an XML-format .manifest file at build time. + +## Build time + +We specify .manifest files in setup.py. + +## Editing or changing a manifest + +You can use the `mt.exe` from your Windows SDK +e.g. "c:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\mt.exe" +to inspect or change an executable's manifest. + +To set a whole new manifest: + +1. Make a copy of the relevant manifest file, e.g. `EDMarketConnector.manifest`. +1. Edit this file. +1. Run mt.exe thus: `mt.exe -manifest EDMarketConnector-new.manifest -outputresource:EDMarketConnector.exe`. From 06524aa789c8afab7e558192ecec5ef6bc8ae8da Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2020 11:18:09 +0000 Subject: [PATCH 002/727] Bump flake8 from 3.8.3 to 3.8.4 Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.8.3 to 3.8.4. - [Release notes](https://gitlab.com/pycqa/flake8/tags) - [Commits](https://gitlab.com/pycqa/flake8/compare/3.8.3...3.8.4) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index e2ea8f11..0f2ba9ad 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ # Static analysis tools -flake8==3.8.3 +flake8==3.8.4 flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.2.3 From 1fc249a37b4f11e6e1fb3e2c9d965b29b791b6a4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2020 11:18:08 +0000 Subject: [PATCH 003/727] Bump isort from 5.5.2 to 5.5.4 Bumps [isort](https://github.com/pycqa/isort) from 5.5.2 to 5.5.4. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.5.2...5.5.4) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 0f2ba9ad..c55f259a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.2.3 flake8-docstrings==1.5.0 -isort==5.5.2 +isort==5.5.4 flake8-isort==4.0.0 flake8-json==19.8.0 flake8-noqa==1.0.5 From 8fe11a15ad30fef30b17821cc032ec1faa3960d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Oct 2020 06:31:28 +0000 Subject: [PATCH 004/727] Bump isort from 5.5.4 to 5.5.5 Bumps [isort](https://github.com/pycqa/isort) from 5.5.4 to 5.5.5. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.5.4...5.5.5) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index c55f259a..8ad7934f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.2.3 flake8-docstrings==1.5.0 -isort==5.5.4 +isort==5.5.5 flake8-isort==4.0.0 flake8-json==19.8.0 flake8-noqa==1.0.5 From cab2e0fe2edcb57c673a5acba42a6cb12df736a8 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:30:05 +0000 Subject: [PATCH 005/727] requirements.txt: Bump certifi to the latest: 2020.6.20 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a7079592..ff058bc8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -certifi==2019.9.11 +certifi==2020.6.20 requests==2.25.1 watchdog==0.10.3 # argh==0.26.2 watchdog dep From 3598a529d15ed4d2a644555490fc35d3b5961dc5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 13:43:50 +0100 Subject: [PATCH 006/727] setup.py: Trial without naming `requests` in packages. --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index e3868777..7a44f787 100755 --- a/setup.py +++ b/setup.py @@ -119,7 +119,6 @@ elif sys.platform=='win32': {'dist_dir': dist_dir, 'optimize': 2, 'packages': [ - 'requests', 'sqlite3', # Included for plugins ], 'includes': [ From 161ccc04b1cc8165004fe1a2248b8c5a3c23d5f1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 16:22:46 +0100 Subject: [PATCH 007/727] setup.py: No need to manually include sqlite3.dll now --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 7a44f787..64a55807 100755 --- a/setup.py +++ b/setup.py @@ -147,7 +147,6 @@ elif sys.platform=='win32': 'systems.p', '%s.VisualElementsManifest.xml' % APPNAME, '%s.ico' % APPNAME, - '%s/DLLs/sqlite3.dll' % (sys.base_prefix), 'EDMarketConnector - TRACE.bat', 'EDMarketConnector - localserver-auth.bat', ]), From b702f4a43015710196800c4cfae6c45224c23ed7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:30:59 +0000 Subject: [PATCH 008/727] WXS: Add additional Python 3.8 files to installer. Confirmed an installer generated with this both installs and has working .exe. --- EDMarketConnector.wxs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index f0545442..48fc1f22 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -113,12 +113,18 @@ + + + + + + @@ -128,6 +134,12 @@ + + + + + + @@ -140,6 +152,9 @@ + + + @@ -167,6 +182,9 @@ + + + @@ -179,8 +197,8 @@ - - + + @@ -543,15 +561,20 @@ + + + + + @@ -569,17 +592,17 @@ + - - + - + From 095c45df8f48c7dbd24befb45302dd5c9ea7d9b3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:33:17 +0000 Subject: [PATCH 009/727] Releasing.md: Update for Python 3.8.6 and py2exe 0.10.x. * Also put `--user` on the example `pip install` line. --- docs/Releasing.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 846324e2..8e50d73a 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -31,13 +31,14 @@ You will need several pieces of software installed, or the files from their auto-select some others). NB: If you have need to uninstall this it's "Windows Software Development Kit - Windows 10.0.18362.1" in "Apps & Features", *not* "Windows SDK AddOn". -1. [Python](https://python.org): 32-bit version of Python 3.7 for Windows. - [v3.7.9](https://www.python.org/downloads/release/python-379/) is the most +1. [Python](https://python.org): 32-bit version of Python 3.8 for Windows. + [v3.8.6](https://www.python.org/downloads/release/python-386/) is the most recently tested version. You need the `Windows x86 executable installer` file, for the 32-bit version. -1. [py2exe](https://github.com/albertosottile/py2exe) - Now available via PyPi, - so will be picked up with the `pip install` below. Latest tested as per - `requirements-dev.txt`. +1. [py2exe](https://github.com/albertosottile/py2exe) - Install the python + module. You will need at least the [pre-release of 0.10.0.1](https://bintray.com/alby128/py2exe/py2exe/0.10.0.1#files) + as we found 0.10.0.0 still had an issue with certifi and cacert.pem. + 1. You'll now need to 'pip install' several python modules. 1. Ensure you have `pip` installed. If needs be see @@ -270,6 +271,9 @@ without errors. Finally, uninstall your current version of ED Market Connector and re-install using the newly generated `EDMarketConnector_win_4.0.2.msi` file. Check the resulting installation does work (the installer will run the program for you). +If it doesn't then check if there are any files, particularly `.dll` or `.pyd` +files in `dist.win32` that aren't yet specified in the `EDMarketConnector.wxs` +file, i.e. they're not packaged into the installer. Update `edmarketconnector.xml` once more to set the `length=` attribute of the enclosure to match the file size of the `EDMarketConnector_win_4.0.2.msi` file. From 8f721cf06e2826fe420ba05b9cb0ab7296ee497b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 16:47:48 +0100 Subject: [PATCH 010/727] PLUGINS.md: Update to mention using Python 3.8 post-4.1.x * Also adjusted links to information/examples to not be the bad 'here' form. --- PLUGINS.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 6bfb4290..071e655f 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -641,11 +641,13 @@ plugin folder to append ".disabled". Eg, Disabled and enabled plugins are listed on the "Plugins" Settings tab -## Migration +## Migration from Python 2.7 -Starting with pre-release 3.5 EDMC uses Python **3.7**. The first full -release under Python 3.7 was 4.0.0.0. This is a brief outline of the steps -required to migrate a plugin from earlier versions of EDMC: +Starting with pre-release 3.5 EDMC used Python 3.7. The first full +release under Python 3.7 was 4.0.0.0. The 4.1.x series was the last to use +Python 3.7, with releases moving on to latest Python 3.8.x after that. +This is a brief outline of the steps required to migrate a plugin from earlier +versions of EDMC: - Rename the function `plugin_start` to `plugin_start3(plugin_dir)`. Plugins without a `plugin_start3` function are listed as disabled on EDMC's @@ -658,12 +660,14 @@ required to migrate a plugin from earlier versions of EDMC: the correct number of arguments. Older versions of this app were tolerant of missing arguments in these function declarations. -- Port the code to Python 3.7. The [2to3](https://docs.python.org/3/library/2to3.html) - tool can automate much of this work. +- Port the code to Python 3.7 or 3.8 as appropriate. The + [2to3](https://docs.python.org/3/library/2to3.html) + tool can automate much of this work. Depending on the complexity of the plugin it may be feasible to make it -compatible with both EDMC 3.4 + Python 2.7 and EDMC 3.5 + Python 3.7. +compatible with both EDMC 3.4 + Python 2.7 and EDMC 3.5 + Python 3.7/3.8. -[Here's](https://python-future.org/compatible_idioms.html) a guide on writing -Python 2/3 compatible code and [here's](https://github.com/Marginal/HabZone/commit/3c41cd41d5ad81ef36aab40e967e3baf77b4bd06) -an example of the changes required for a simple plugin. +You might find [compatible idioms](https://python-future.org/compatible_idioms.html), +a guide on writing Python 2/3 compatible code, useful. There's also [an + example of changes required for a simple plugin](https://github.com/Marginal/HabZone/commit/3c41cd41d5ad81ef36aab40e967e3baf77b4bd06) +. From 8ceca8912e37bd6764f77993d83d58e671b7b19d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 16:51:24 +0100 Subject: [PATCH 011/727] PLUGINS.md: Reference Releasing.md for currently supported Python version --- PLUGINS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PLUGINS.md b/PLUGINS.md index 071e655f..34f3831a 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -9,6 +9,9 @@ wiki. ## Writing a Plugin +Check [Releasing.md](docs/Releasing.md#environment) to be sure of the current +version of Python that we've tested against. + Plugins are loaded when EDMC starts up. Each plugin has it's own folder in the `plugins` directory: @@ -646,6 +649,7 @@ Disabled and enabled plugins are listed on the "Plugins" Settings tab Starting with pre-release 3.5 EDMC used Python 3.7. The first full release under Python 3.7 was 4.0.0.0. The 4.1.x series was the last to use Python 3.7, with releases moving on to latest Python 3.8.x after that. + This is a brief outline of the steps required to migrate a plugin from earlier versions of EDMC: From 818466a3cf10cfcb6b03b11cced8c7359d23ab24 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 16:54:27 +0100 Subject: [PATCH 012/727] Releasing.md: Update example full python path * Python 3.8 now. * And reference the centrally installed location, not the one under %LOCALAPPDATA%. --- docs/Releasing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 8e50d73a..5dcfc206 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -232,9 +232,9 @@ else you might need this, which assumes correct python.exe is in your PATH: python.exe setup.py py2exe -else you'll have to specify the path to python.exe: +else you'll have to specify the path to python.exe, e.g.: - "%LOCALAPPDATA%\Programs\Python\Python37-32\python.exe" setup.py py2exe + "C:\Program Files (x86)\Python38-32\python.exe" setup.py py2exe Output will be something like (`...` denoting parts elided for brevity): From 6600d1a78ae7851fa173028e086ee6a8c99a61db Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 17:15:36 +0100 Subject: [PATCH 013/727] GitHub Workflow: Update to Python 3.8 --- .github/workflows/pr-annotate-with-flake8.yml | 4 ++-- .github/workflows/pr-checks.yml | 4 ++-- .github/workflows/push-checks.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-annotate-with-flake8.yml b/.github/workflows/pr-annotate-with-flake8.yml index f293a9fc..93209cc8 100644 --- a/.github/workflows/pr-annotate-with-flake8.yml +++ b/.github/workflows/pr-annotate-with-flake8.yml @@ -61,11 +61,11 @@ jobs: ################################################################## # Get Python set up ################################################################## - - name: Set up Python 3.7 + - name: Set up Python 3.8 if: ${{ env.PYFILES != '' }} uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.8 ################################################################## ################################################################## diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 2afeba77..055ee6a0 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -45,10 +45,10 @@ jobs: #################################################################### # Get Python set up #################################################################### - - name: Set up Python 3.7 + - name: Set up Python 3.8 uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index b6ad01a5..2ab55d45 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -20,10 +20,10 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set up Python 3.7 + - name: Set up Python 3.8 uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip From c88f634ec19728be69d5949e65d35d0453d83198 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 17:27:09 +0100 Subject: [PATCH 014/727] Releasing.md: py2exe 0.10.0.1 now released so reference it. --- docs/Releasing.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 5dcfc206..67bc9cc0 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -36,9 +36,8 @@ You will need several pieces of software installed, or the files from their recently tested version. You need the `Windows x86 executable installer` file, for the 32-bit version. 1. [py2exe](https://github.com/albertosottile/py2exe) - Install the python - module. You will need at least the [pre-release of 0.10.0.1](https://bintray.com/alby128/py2exe/py2exe/0.10.0.1#files) - as we found 0.10.0.0 still had an issue with certifi and cacert.pem. - + module. You will need at least [version 0.10.0.1](https://github.com/albertosottile/py2exe/releases/tag/v0.10.0.1), +specifically [py2exe-0.10.0.1-cp38-none-win32.whl](https://github.com/albertosottile/py2exe/releases/download/v0.10.0.1/py2exe-0.10.0.1-cp38-none-win32.whl). 1. You'll now need to 'pip install' several python modules. 1. Ensure you have `pip` installed. If needs be see @@ -234,7 +233,7 @@ else you might need this, which assumes correct python.exe is in your PATH: else you'll have to specify the path to python.exe, e.g.: - "C:\Program Files (x86)\Python38-32\python.exe" setup.py py2exe + "C:\Program Files \(x86)\Python38-32\python.exe" setup.py py2exe Output will be something like (`...` denoting parts elided for brevity): From 9c0b690095a1a4605bfd053e23da18d746142c6c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:33:58 +0000 Subject: [PATCH 015/727] requirements: Reference py2exe via git URL@tag --- requirements-dev.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 8ad7934f..3af1c7f8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -20,8 +20,12 @@ autopep8==1.5.4 grip==4.5.2 # Packaging -# We only need py2exe on windows. -py2exe==0.10.0.2; sys_platform == 'win32' +# This isn't available via 'pip install', but is via git@tag +# Refs: +# +# +#py2exe==0.10.0.1 +git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe # All of the normal requirements -r requirements.txt From 49b6e22ca180569aa654f2ca8d312536b2f9b5c7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 19:04:56 +0100 Subject: [PATCH 016/727] requirements: py2exe only on win32 platform --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 3af1c7f8..ee289366 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -25,7 +25,7 @@ grip==4.5.2 # # #py2exe==0.10.0.1 -git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe +git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe; sys_platform == 'win32' # All of the normal requirements -r requirements.txt From 3a0423381f66d521bcef2fc0282670ec6d7e8451 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 14:45:39 +0100 Subject: [PATCH 017/727] Version to 4.2.0-beta1 to distinguish Python 3.8 builds * I don't want to be checking something against 4.1.x releases when my last build was with Python 3.8. # Conflicts: # config.py # Conflicts: # config.py # Conflicts: # config.py --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index b07aa20a..1e9340c9 100644 --- a/config.py +++ b/config.py @@ -13,7 +13,7 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '4.2.7' # -rc1+a872b5f' +appversion = '4.2.0-beta1' #-rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) copyright = u'© 2015-2019 Jonathan Harris, 2020-2021 EDCD' From 41cb4c24ceec0fa041b41a898c6bfacb5b07c521 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 12:02:17 +0100 Subject: [PATCH 018/727] setup.py: Bump SDKPATH to use 19041 (Windows 10 2004) Kit. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 64a55807..165c01ed 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ macdeveloperid = None # Windows paths WIXPATH = r'C:\Program Files (x86)\WiX Toolset v3.11\bin' -SDKPATH = r'C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x86' +SDKPATH = r'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86' # OSX paths SPARKLE = '/Library/Frameworks/Sparkle.framework' From bc5f805b5a501b6cc6e468b22e935ccce3927593 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:35:44 +0000 Subject: [PATCH 019/727] setup.py: isorted imports & de-caps config variables * Test build exhibited no issues. --- setup.py | 136 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 53 deletions(-) diff --git a/setup.py b/setup.py index 165c01ed..23a54ffe 100755 --- a/setup.py +++ b/setup.py @@ -1,28 +1,25 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -This is a setup.py script generated by py2applet +Script to build to .exe and .msi package. -Usage: - python setup.py py2app +.exe build is via py2exe on win32. +.msi packaging utilises Windows SDK. """ -from distutils.core import setup import codecs import os -from os.path import exists, isdir, join import platform import re import shutil import sys +from distutils.core import setup +from os.path import exists, isdir, join from tempfile import gettempdir + import semantic_version -from config import appname as APPNAME, applongname as APPLONGNAME, appcmdname as APPCMDNAME, appversion as VERSION, copyright as COPYRIGHT -from config import update_feed, update_interval - -if sys.version_info[0:2] != (3, 7): - raise AssertionError(f'Unexpected python version {sys.version}') +from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval if sys.platform=='win32': assert platform.architecture()[0]=='32bit', 'Assumes a Python built for 32bit' @@ -34,8 +31,8 @@ else: assert False, 'Unsupported platform %s' % sys.platform # Split version, as py2exe wants the 'base' for version -semver = semantic_version.Version.coerce(VERSION) -BASEVERSION = str(semver.truncate('patch')) +semver = semantic_version.Version.coerce(appversion) +BASEappversion = str(semver.truncate('patch')) if dist_dir and len(dist_dir)>1 and isdir(dist_dir): shutil.rmtree(dist_dir) @@ -66,7 +63,7 @@ if sys.platform=='darwin': APP = 'EDMarketConnector.py' APPCMD = 'EDMC.py' -SHORTVERSION = ''.join(VERSION.split('.')[:3]) +SHORTappversion = ''.join(appversion.split('.')[:3]) PLUGINS = [ 'plugins/coriolis.py', 'plugins/eddb.py', 'plugins/eddn.py', 'plugins/edsm.py', 'plugins/edsy.py', 'plugins/inara.py' ] if sys.platform=='darwin': @@ -83,26 +80,26 @@ if sys.platform=='darwin': ], 'frameworks': [ 'Sparkle.framework' ], 'excludes': [ 'distutils', '_markerlib', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ], - 'iconfile': '%s.icns' % APPNAME, + 'iconfile': '%s.icns' % appname, 'include_plugins': [('plugins', x) for x in PLUGINS], 'resources': [ 'commodity.csv', 'rare_commodity.csv', 'snd_good.wav', 'snd_bad.wav', 'modules.p', 'ships.p', 'stations.p', 'systems.p'], 'site_packages': False, 'plist': { - 'CFBundleName': APPLONGNAME, - 'CFBundleIdentifier': 'uk.org.marginal.%s' % APPNAME.lower(), + 'CFBundleName': applongname, + 'CFBundleIdentifier': 'uk.org.marginal.%s' % appname.lower(), 'CFBundleLocalizations': sorted(set([x[:-len('.lproj')] for x in os.listdir(join(SPARKLE, 'Resources')) if x.endswith('.lproj')]) | set([x[:-len('.strings')] for x in os.listdir('L10n') if x.endswith('.strings')])), # https://github.com/sparkle-project/Sparkle/issues/238 - 'CFBundleShortVersionString': VERSION, - 'CFBundleVersion': VERSION, + 'CFBundleShortVersionString': appversion, + 'CFBundleVersion': appversion, 'CFBundleURLTypes': [ { 'CFBundleTypeRole': 'Viewer', - 'CFBundleURLName': 'uk.org.marginal.%s.URLScheme' % APPNAME.lower(), + 'CFBundleURLName': 'uk.org.marginal.%s.URLScheme' % appname.lower(), 'CFBundleURLSchemes': ['edmc'], } ], 'LSMinimumSystemVersion': '10.10', 'NSAppleScriptEnabled': True, - 'NSHumanReadableCopyright': COPYRIGHT, + 'NSHumanReadableCopyright': copyright, 'SUEnableAutomaticChecks': True, 'SUShowReleaseNotes': True, 'SUAllowsAutomaticUpdates': False, @@ -145,8 +142,8 @@ elif sys.platform=='win32': 'ships.p', 'stations.p', 'systems.p', - '%s.VisualElementsManifest.xml' % APPNAME, - '%s.ico' % APPNAME, + '%s.VisualElementsManifest.xml' % appname, + '%s.ico' % appname, 'EDMarketConnector - TRACE.bat', 'EDMarketConnector - localserver-auth.bat', ]), @@ -155,26 +152,26 @@ elif sys.platform=='win32': ] setup( - name = APPLONGNAME, - version = VERSION, - windows = [ {'dest_base': APPNAME, + name = applongname, + version = appversion, + windows = [ {'dest_base': appname, 'script': APP, - 'icon_resources': [(0, '%s.ico' % APPNAME)], + 'icon_resources': [(0, '%s.ico' % appname)], 'company_name': 'EDCD', # WinSparkle - 'product_name': APPNAME, # WinSparkle - 'version': BASEVERSION, - 'product_version': VERSION, - 'copyright': COPYRIGHT, - 'other_resources': [(24, 1, open(APPNAME+'.manifest').read())], + 'product_name': appname, # WinSparkle + 'version': BASEappversion, + 'product_version': appversion, + 'copyright': copyright, + 'other_resources': [(24, 1, open(appname+'.manifest').read())], } ], - console = [ {'dest_base': APPCMDNAME, + console = [ {'dest_base': appcmdname, 'script': APPCMD, 'company_name': 'EDCD', - 'product_name': APPNAME, - 'version': BASEVERSION, - 'product_version': VERSION, - 'copyright': COPYRIGHT, - 'other_resources': [(24, 1, open(APPCMDNAME+'.manifest').read())], + 'product_name': appname, + 'version': BASEappversion, + 'product_version': appversion, + 'copyright': copyright, + 'other_resources': [(24, 1, open(appcmdname+'.manifest').read())], } ], data_files = DATA_FILES, options = OPTIONS, @@ -182,42 +179,75 @@ setup( PKG = None if sys.platform == 'darwin': - if isdir('%s/%s.app' % (dist_dir, APPLONGNAME)): # from CFBundleName - os.rename('%s/%s.app' % (dist_dir, APPLONGNAME), '%s/%s.app' % (dist_dir, APPNAME)) + if isdir('%s/%s.app' % (dist_dir, applongname)): # from CFBundleName + os.rename('%s/%s.app' % (dist_dir, applongname), '%s/%s.app' % (dist_dir, appname)) # Generate OSX-style localization files for x in os.listdir('L10n'): if x.endswith('.strings'): lang = x[:-len('.strings')] - path = '%s/%s.app/Contents/Resources/%s.lproj' % (dist_dir, APPNAME, lang) + path = '%s/%s.app/Contents/Resources/%s.lproj' % (dist_dir, appname, lang) os.mkdir(path) codecs.open('%s/Localizable.strings' % path, 'w', 'utf-16').write(codecs.open('L10n/%s' % x, 'r', 'utf-8').read()) if macdeveloperid: - os.system('codesign --deep -v -s "Developer ID Application: %s" %s/%s.app' % (macdeveloperid, dist_dir, APPNAME)) + os.system('codesign --deep -v -s "Developer ID Application: %s" %s/%s.app' % (macdeveloperid, dist_dir, appname)) # Make zip for distribution, preserving signature - PKG = '%s_mac_%s.zip' % (APPNAME, VERSION) - os.system('cd %s; ditto -ck --keepParent --sequesterRsrc %s.app ../%s; cd ..' % (dist_dir, APPNAME, PKG)) + PKG = '%s_mac_%s.zip' % (appname, appversion) + os.system('cd %s; ditto -ck --keepParent --sequesterRsrc %s.app ../%s; cd ..' % (dist_dir, appname, PKG)) elif sys.platform == 'win32': - os.system(r'"%s\candle.exe" -out %s\ %s.wxs' % (WIXPATH, dist_dir, APPNAME)) - if not exists('%s/%s.wixobj' % (dist_dir, APPNAME)): - raise AssertionError('No %s/%s.wixobj: candle.exe failed?' % (dist_dir, APPNAME)) + os.system(r'"%s\candle.exe" -out %s\ %s.wxs' % (WIXPATH, dist_dir, appname)) + if not exists('%s/%s.wixobj' % (dist_dir, appname)): + raise AssertionError('No %s/%s.wixobj: candle.exe failed?' % (dist_dir, appname)) - PKG = '%s_win_%s.msi' % (APPNAME, VERSION) + PKG = '%s_win_%s.msi' % (appname, appversion) import subprocess - os.system(r'"%s\light.exe" -sacl -spdb -sw1076 %s\%s.wixobj -out %s' % (WIXPATH, dist_dir, APPNAME, PKG)) + os.system(r'"%s\light.exe" -sacl -spdb -sw1076 %s\%s.wixobj -out %s' % (WIXPATH, dist_dir, appname, PKG)) if not exists(PKG): raise AssertionError('light.exe failed, no %s' % (PKG)) # Seriously, this is how you make Windows Installer use the user's display language for its dialogs. What a crock. # http://www.geektieguy.com/2010/03/13/create-a-multi-lingual-multi-language-msi-using-wix-and-custom-build-scripts - lcids = [int(x) for x in re.search(r'Languages\s*=\s*"(.+?)"', open('%s.wxs' % APPNAME).read()).group(1).split(',')] + lcids = [int(x) for x in re.search(r'Languages\s*=\s*"(.+?)"', open('%s.wxs' % appname).read()).group(1).split(',')] assert lcids[0]==1033, 'Default language is %d, should be 1033 (en_US)' % lcids[0] - shutil.copyfile(PKG, join(gettempdir(), '%s_1033.msi' % APPNAME)) + shutil.copyfile(PKG, join(gettempdir(), '%s_1033.msi' % appname)) for lcid in lcids[1:]: - shutil.copyfile(join(gettempdir(), '%s_1033.msi' % APPNAME), join(gettempdir(), '%s_%d.msi' % (APPNAME, lcid))) - os.system(r'cscript /nologo "%s\WiLangId.vbs" %s\%s_%d.msi Product %d' % (SDKPATH, gettempdir(), APPNAME, lcid, lcid)) # Don't care about codepage because the displayed strings come from msiexec not our msi - os.system(r'"%s\MsiTran.Exe" -g %s\%s_1033.msi %s\%s_%d.msi %s\%d.mst' % (SDKPATH, gettempdir(), APPNAME, gettempdir(), APPNAME, lcid, gettempdir(), lcid)) + shutil.copyfile(join(gettempdir(), '%s_1033.msi' % appname), join(gettempdir(), '%s_%d.msi' % (appname, lcid))) + os.system(r'cscript /nologo "%s\WiLangId.vbs" %s\%s_%d.msi Product %d' % (SDKPATH, gettempdir(), appname, lcid, lcid)) # Don't care about codepage because the displayed strings come from msiexec not our msi + os.system(r'"%s\MsiTran.Exe" -g %s\%s_1033.msi %s\%s_%d.msi %s\%d.mst' % (SDKPATH, gettempdir(), appname, gettempdir(), appname, lcid, gettempdir(), lcid)) os.system(r'cscript /nologo "%s\WiSubStg.vbs" %s %s\%d.mst %d' % (SDKPATH, PKG, gettempdir(), lcid, lcid)) else: raise AssertionError('Unsupported platform') + +if not exists(PKG): + raise AssertionError('No %s found prior to appcast' % (PKG)) +# Make appcast entry +appcast = open('appcast_%s_%s.xml' % (sys.platform=='darwin' and 'mac' or 'win', appversion), 'w') +appcast.write(''' +\t\t +\t\t\tRelease {appversion} +\t\t\t +\t\t\t\t{STYLE} +

Release {appversion}

+
    + +
+\t\t\t\t]]> +\t\t\t
+\t\t\t +\t\t
+'''.format(appversion=appversion, + STYLE='{}'.format( + sys.platform=='win32' and 'body { font-family:"Segoe UI","Tahoma"; font-size: 75%; } h2 { font-family:"Segoe UI","Tahoma"; font-size: 105%; }' + or 'h2 { font-size: 105%; }'), + PKG=PKG, + OS=''.format(sys.platform=='win32' and 'windows"\n\t\t\t\tsparkle:installerArguments="/passive LAUNCH=yes' or 'macos'), + LENGTH=os.stat(PKG).st_size) +) From b417745e7ea83e01f35b4d893afeba9181fa8ffb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 12:28:10 +0100 Subject: [PATCH 020/727] setup.py: darwin OPTIONS & misc formatting --- setup.py | 159 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 104 insertions(+), 55 deletions(-) diff --git a/setup.py b/setup.py index 23a54ffe..aaaa4a85 100755 --- a/setup.py +++ b/setup.py @@ -16,25 +16,26 @@ import sys from distutils.core import setup from os.path import exists, isdir, join from tempfile import gettempdir +from typing import Set import semantic_version from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval -if sys.platform=='win32': - assert platform.architecture()[0]=='32bit', 'Assumes a Python built for 32bit' - import py2exe +if sys.platform == 'win32': + assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit' + import py2exe # noqa: F401 # Yes, this *is* used dist_dir = 'dist.win32' -elif sys.platform=='darwin': +elif sys.platform == 'darwin': dist_dir = 'dist.macosx' else: - assert False, 'Unsupported platform %s' % sys.platform + assert False, f'Unsupported platform {sys.platform}' # Split version, as py2exe wants the 'base' for version semver = semantic_version.Version.coerce(appversion) BASEappversion = str(semver.truncate('patch')) -if dist_dir and len(dist_dir)>1 and isdir(dist_dir): +if dist_dir and len(dist_dir) > 1 and isdir(dist_dir): shutil.rmtree(dist_dir) # "Developer ID Application" name for signing @@ -47,67 +48,115 @@ SDKPATH = r'C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86' # OSX paths SPARKLE = '/Library/Frameworks/Sparkle.framework' -# Patch py2app recipe enumerator to skip the sip recipe since it's too enthusiastic - we'll list additional Qt modules explicitly -if sys.platform=='darwin': - from py2app import recipes +if sys.platform == 'darwin': + # Patch py2app recipe enumerator to skip the sip recipe since it's too + # enthusiastic - we'll list additional Qt modules explicitly import py2app.build_app - def iterRecipes(module=recipes): + from py2app import recipes + + def iter_recipes(module=recipes): + """Enumerate recipes via alternate method.""" for name in dir(module): - if name.startswith('_') or name=='sip': + if name.startswith('_') or name == 'sip': continue check = getattr(getattr(module, name), 'check', None) if check is not None: yield (name, check) - py2app.build_app.iterRecipes = iterRecipes + + py2app.build_app.iterRecipes = iter_recipes APP = 'EDMarketConnector.py' APPCMD = 'EDMC.py' SHORTappversion = ''.join(appversion.split('.')[:3]) -PLUGINS = [ 'plugins/coriolis.py', 'plugins/eddb.py', 'plugins/eddn.py', 'plugins/edsm.py', 'plugins/edsy.py', 'plugins/inara.py' ] +PLUGINS = [ + 'plugins/coriolis.py', + 'plugins/eddb.py', + 'plugins/eddn.py', + 'plugins/edsm.py', + 'plugins/edsy.py', + 'plugins/inara.py', +] -if sys.platform=='darwin': - OPTIONS = { 'py2app': - {'dist_dir': dist_dir, - 'optimize': 2, - 'packages': [ - 'requests', - 'sqlite3', # Included for plugins - ], - 'includes': [ - 'shutil', # Included for plugins - 'zipfile', # Included for plugins - ], - 'frameworks': [ 'Sparkle.framework' ], - 'excludes': [ 'distutils', '_markerlib', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ], - 'iconfile': '%s.icns' % appname, - 'include_plugins': [('plugins', x) for x in PLUGINS], - 'resources': [ 'commodity.csv', 'rare_commodity.csv', 'snd_good.wav', 'snd_bad.wav', 'modules.p', 'ships.p', 'stations.p', 'systems.p'], - 'site_packages': False, - 'plist': { - 'CFBundleName': applongname, - 'CFBundleIdentifier': 'uk.org.marginal.%s' % appname.lower(), - 'CFBundleLocalizations': sorted(set([x[:-len('.lproj')] for x in os.listdir(join(SPARKLE, 'Resources')) if x.endswith('.lproj')]) | set([x[:-len('.strings')] for x in os.listdir('L10n') if x.endswith('.strings')])), # https://github.com/sparkle-project/Sparkle/issues/238 - 'CFBundleShortVersionString': appversion, - 'CFBundleVersion': appversion, - 'CFBundleURLTypes': [ - { - 'CFBundleTypeRole': 'Viewer', - 'CFBundleURLName': 'uk.org.marginal.%s.URLScheme' % appname.lower(), - 'CFBundleURLSchemes': ['edmc'], - } - ], - 'LSMinimumSystemVersion': '10.10', - 'NSAppleScriptEnabled': True, - 'NSHumanReadableCopyright': copyright, - 'SUEnableAutomaticChecks': True, - 'SUShowReleaseNotes': True, - 'SUAllowsAutomaticUpdates': False, - 'SUFeedURL': update_feed, - 'SUScheduledCheckInterval': update_interval, - }, - 'graph': True, # output dependency graph in dist - } +if sys.platform == 'darwin': + def get_cfbundle_localizations() -> Set: + """ + Build a set of the localisation files. + + See https://github.com/sparkle-project/Sparkle/issues/238 + """ + return sorted( + ( + [x[:-len('.lproj')] for x in os.listdir(join(SPARKLE, 'Resources')) if x.endswith('.lproj')] + ) | ( + [x[:-len('.strings')] for x in os.listdir('L10n') if x.endswith('.strings')] + ) + ) + + OPTIONS = { + 'py2app': { + 'dist_dir': dist_dir, + 'optimize': 2, + 'packages': [ + 'requests', + 'sqlite3', # Included for plugins + ], + 'includes': [ + 'shutil', # Included for plugins + 'zipfile', # Included for plugins + ], + 'frameworks': [ + 'Sparkle.framework' + ], + 'excludes': [ + 'distutils', + '_markerlib', + 'PIL', + 'pkg_resources', + 'simplejson', + 'unittest' + ], + 'iconfile': f'{appname}.icns', + 'include_plugins': [ + ('plugins', x) for x in PLUGINS + ], + 'resources': [ + 'commodity.csv', + 'rare_commodity.csv', + 'snd_good.wav', + 'snd_bad.wav', + 'modules.p', + 'ships.p', + 'stations.p', + 'systems.p' + ], + 'site_packages': False, + 'plist': { + 'CFBundleName': applongname, + 'CFBundleIdentifier': f'uk.org.marginal.{appname.lower()}', + 'CFBundleLocalizations': get_cfbundle_localizations(), + 'CFBundleShortVersionString': appversion, + 'CFBundleVersion': appversion, + 'CFBundleURLTypes': [ + { + 'CFBundleTypeRole': 'Viewer', + 'CFBundleURLName': f'uk.org.marginal.{appname.lower()}.URLScheme', + 'CFBundleURLSchemes': [ + 'edmc' + ], + } + ], + 'LSMinimumSystemVersion': '10.10', + 'NSAppleScriptEnabled': True, + 'NSHumanReadableCopyright': copyright, + 'SUEnableAutomaticChecks': True, + 'SUShowReleaseNotes': True, + 'SUAllowsAutomaticUpdates': False, + 'SUFeedURL': update_feed, + 'SUScheduledCheckInterval': update_interval, + }, + 'graph': True, # output dependency graph in dist + } } DATA_FILES = [] From 03c97299c4743973cb12e53c8b50b00ce948e729 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 12:30:35 +0100 Subject: [PATCH 021/727] setup.py: win32 OPTIONS and DATA_FILES formatting --- setup.py | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index aaaa4a85..b4615ac6 100755 --- a/setup.py +++ b/setup.py @@ -160,27 +160,36 @@ if sys.platform == 'darwin': } DATA_FILES = [] -elif sys.platform=='win32': - OPTIONS = { 'py2exe': - {'dist_dir': dist_dir, - 'optimize': 2, - 'packages': [ - 'sqlite3', # Included for plugins - ], - 'includes': [ - 'dataclasses', - 'shutil', # Included for plugins - 'timeout_session', - 'zipfile', # Included for plugins - ], - 'excludes': [ 'distutils', '_markerlib', 'optparse', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ], - } +elif sys.platform == 'win32': + OPTIONS = { + 'py2exe': { + 'dist_dir': dist_dir, + 'optimize': 2, + 'packages': [ + 'sqlite3', # Included for plugins + ], + 'includes': [ + 'dataclasses', + 'shutil', # Included for plugins + 'timeout_session', + 'zipfile', # Included for plugins + ], + 'excludes': [ + 'distutils', + '_markerlib', + 'optparse', + 'PIL', + 'pkg_resources', + 'simplejson', + 'unittest' + ], + } } DATA_FILES = [ ('', [ 'WinSparkle.dll', - 'WinSparkle.pdb', # For debugging - don't include in package + 'WinSparkle.pdb', # For debugging - don't include in package 'EUROCAPS.TTF', 'Changelog.md', 'commodity.csv', @@ -191,12 +200,12 @@ elif sys.platform=='win32': 'ships.p', 'stations.p', 'systems.p', - '%s.VisualElementsManifest.xml' % appname, - '%s.ico' % appname, + f'{appname}.VisualElementsManifest.xml', + f'{appname}.ico', 'EDMarketConnector - TRACE.bat', 'EDMarketConnector - localserver-auth.bat', ]), - ('L10n', [join('L10n',x) for x in os.listdir('L10n') if x.endswith('.strings')]), + ('L10n', [join('L10n', x) for x in os.listdir('L10n') if x.endswith('.strings')]), ('plugins', PLUGINS), ] From 697fcf83efd3fbf2bec0668ebd654ca7cbe2f420 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 12:34:10 +0100 Subject: [PATCH 022/727] setup.py: Format setup() call. --- setup.py | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index b4615ac6..bede954d 100755 --- a/setup.py +++ b/setup.py @@ -210,29 +210,35 @@ elif sys.platform == 'win32': ] setup( - name = applongname, - version = appversion, - windows = [ {'dest_base': appname, - 'script': APP, - 'icon_resources': [(0, '%s.ico' % appname)], - 'company_name': 'EDCD', # WinSparkle - 'product_name': appname, # WinSparkle - 'version': BASEappversion, - 'product_version': appversion, - 'copyright': copyright, - 'other_resources': [(24, 1, open(appname+'.manifest').read())], - } ], - console = [ {'dest_base': appcmdname, - 'script': APPCMD, - 'company_name': 'EDCD', - 'product_name': appname, - 'version': BASEappversion, - 'product_version': appversion, - 'copyright': copyright, - 'other_resources': [(24, 1, open(appcmdname+'.manifest').read())], - } ], - data_files = DATA_FILES, - options = OPTIONS, + name=applongname, + version=appversion, + windows=[ + { + 'dest_base': appname, + 'script': APP, + 'icon_resources': [(0, f'{appname}.ico')], + 'company_name': 'EDCD', # Used by WinSparkle + 'product_name': appname, # Used by WinSparkle + 'version': BASEappversion, + 'product_version': appversion, + 'copyright': copyright, + 'other_resources': [(24, 1, open(f'{appname}.manifest').read())], + } + ], + console=[ + { + 'dest_base': appcmdname, + 'script': APPCMD, + 'company_name': 'EDCD', + 'product_name': appname, + 'version': BASEappversion, + 'product_version': appversion, + 'copyright': copyright, + 'other_resources': [(24, 1, open(f'{appcmdname}.manifest').read())], + } + ], + data_files=DATA_FILES, + options=OPTIONS, ) PKG = None From f7d18c12df873223c55bbf7c6fdbf54ff2172c16 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 12:34:45 +0100 Subject: [PATCH 023/727] setup.py: Rename BASEappversion -> base_appversion. --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index bede954d..c2e45bfd 100755 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ else: # Split version, as py2exe wants the 'base' for version semver = semantic_version.Version.coerce(appversion) -BASEappversion = str(semver.truncate('patch')) +base_appversion = str(semver.truncate('patch')) if dist_dir and len(dist_dir) > 1 and isdir(dist_dir): shutil.rmtree(dist_dir) @@ -219,7 +219,7 @@ setup( 'icon_resources': [(0, f'{appname}.ico')], 'company_name': 'EDCD', # Used by WinSparkle 'product_name': appname, # Used by WinSparkle - 'version': BASEappversion, + 'version': base_appversion, 'product_version': appversion, 'copyright': copyright, 'other_resources': [(24, 1, open(f'{appname}.manifest').read())], @@ -231,7 +231,7 @@ setup( 'script': APPCMD, 'company_name': 'EDCD', 'product_name': appname, - 'version': BASEappversion, + 'version': base_appversion, 'product_version': appversion, 'copyright': copyright, 'other_resources': [(24, 1, open(f'{appcmdname}.manifest').read())], From a013ad19ba40f4189744722c4182075bc696701e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 12:40:58 +0100 Subject: [PATCH 024/727] setup.py: Format darwin packaging code. --- setup.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index c2e45bfd..be2678b4 100755 --- a/setup.py +++ b/setup.py @@ -243,22 +243,28 @@ setup( PKG = None if sys.platform == 'darwin': - if isdir('%s/%s.app' % (dist_dir, applongname)): # from CFBundleName - os.rename('%s/%s.app' % (dist_dir, applongname), '%s/%s.app' % (dist_dir, appname)) + if isdir(f'{dist_dir}/{applongname}.app'): # from CFBundleName + os.rename(f'{dist_dir}/{applongname}.app', f'{dist_dir}/{appname}.app') # Generate OSX-style localization files for x in os.listdir('L10n'): if x.endswith('.strings'): lang = x[:-len('.strings')] - path = '%s/%s.app/Contents/Resources/%s.lproj' % (dist_dir, appname, lang) + path = f'{dist_dir}/{appname}.app/Contents/Resources/{lang}.lproj' os.mkdir(path) - codecs.open('%s/Localizable.strings' % path, 'w', 'utf-16').write(codecs.open('L10n/%s' % x, 'r', 'utf-8').read()) + codecs.open( + f'{path}/Localizable.strings', + 'w', + 'utf-16' + ).write(codecs.open(f'L10n/{x}', 'r', 'utf-8').read()) if macdeveloperid: - os.system('codesign --deep -v -s "Developer ID Application: %s" %s/%s.app' % (macdeveloperid, dist_dir, appname)) + os.system(f'codesign --deep -v -s "Developer ID Application: {macdeveloperid}" {dist_dir}/{appname}.app') + # Make zip for distribution, preserving signature - PKG = '%s_mac_%s.zip' % (appname, appversion) - os.system('cd %s; ditto -ck --keepParent --sequesterRsrc %s.app ../%s; cd ..' % (dist_dir, appname, PKG)) + PKG = f'{appname}_mac_{appversion}.zip' + os.system(f'cd {dist_dir}; ditto -ck --keepParent --sequesterRsrc {appname}.app ../{PKG}; cd ..') + elif sys.platform == 'win32': os.system(r'"%s\candle.exe" -out %s\ %s.wxs' % (WIXPATH, dist_dir, appname)) if not exists('%s/%s.wixobj' % (dist_dir, appname)): From f3433382c3382095618bb1881aaeb7ba98e0245a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 12:56:24 +0100 Subject: [PATCH 025/727] setup.py: Formatting in win32 packaging. --- setup.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index be2678b4..b85ec2f2 100755 --- a/setup.py +++ b/setup.py @@ -266,26 +266,37 @@ if sys.platform == 'darwin': os.system(f'cd {dist_dir}; ditto -ck --keepParent --sequesterRsrc {appname}.app ../{PKG}; cd ..') elif sys.platform == 'win32': - os.system(r'"%s\candle.exe" -out %s\ %s.wxs' % (WIXPATH, dist_dir, appname)) - if not exists('%s/%s.wixobj' % (dist_dir, appname)): - raise AssertionError('No %s/%s.wixobj: candle.exe failed?' % (dist_dir, appname)) + os.system(f'"{WIXPATH}\\candle.exe" -out {dist_dir}\\ {appname}.wxs') + + if not exists(f'{dist_dir}/{appname}.wixobj'): + raise AssertionError(f'No {dist_dir}/{appname}.wixobj: candle.exe failed?') + + PKG = f'{appname}_win_{appversion}.msi' + os.system(f'"{WIXPATH}\\light.exe" -sacl -spdb -sw1076 {dist_dir}\\{appname}.wixobj -out {PKG}') - PKG = '%s_win_%s.msi' % (appname, appversion) - import subprocess - os.system(r'"%s\light.exe" -sacl -spdb -sw1076 %s\%s.wixobj -out %s' % (WIXPATH, dist_dir, appname, PKG)) if not exists(PKG): - raise AssertionError('light.exe failed, no %s' % (PKG)) + raise AssertionError(f'light.exe failed, no {PKG}') # Seriously, this is how you make Windows Installer use the user's display language for its dialogs. What a crock. # http://www.geektieguy.com/2010/03/13/create-a-multi-lingual-multi-language-msi-using-wix-and-custom-build-scripts - lcids = [int(x) for x in re.search(r'Languages\s*=\s*"(.+?)"', open('%s.wxs' % appname).read()).group(1).split(',')] - assert lcids[0]==1033, 'Default language is %d, should be 1033 (en_US)' % lcids[0] - shutil.copyfile(PKG, join(gettempdir(), '%s_1033.msi' % appname)) + lcids = [ + int(x) for x in re.search( + r'Languages\s*=\s*"(.+?)"', + open(f'{appname}.wxs').read() + ).group(1).split(',') + ] + assert lcids[0] == 1033, f'Default language is {lcids[0]}, should be 1033 (en_US)' + shutil.copyfile(PKG, join(gettempdir(), f'{appname}_1033.msi')) for lcid in lcids[1:]: - shutil.copyfile(join(gettempdir(), '%s_1033.msi' % appname), join(gettempdir(), '%s_%d.msi' % (appname, lcid))) - os.system(r'cscript /nologo "%s\WiLangId.vbs" %s\%s_%d.msi Product %d' % (SDKPATH, gettempdir(), appname, lcid, lcid)) # Don't care about codepage because the displayed strings come from msiexec not our msi - os.system(r'"%s\MsiTran.Exe" -g %s\%s_1033.msi %s\%s_%d.msi %s\%d.mst' % (SDKPATH, gettempdir(), appname, gettempdir(), appname, lcid, gettempdir(), lcid)) - os.system(r'cscript /nologo "%s\WiSubStg.vbs" %s %s\%d.mst %d' % (SDKPATH, PKG, gettempdir(), lcid, lcid)) + shutil.copyfile( + join(gettempdir(), f'{appname}_1033.msi'), + join(gettempdir(), f'{appname}_{lcid}.msi') + ) + # Don't care about codepage because the displayed strings come from msiexec not our msi + os.system(f'cscript /nologo "{SDKPATH}\\WiLangId.vbs" {gettempdir()}\\{appname}_{lcid}.msi Product {lcid}') + os.system(f'"{SDKPATH}\\MsiTran.Exe" -g {gettempdir()}\\{appname}_1033.msi {gettempdir()}\\{appname}_{lcid}.msi {gettempdir()}\\{lcid}.mst') # noqa: E501 # Not going to get shorter + os.system(f'cscript /nologo "{SDKPATH}\\WiSubStg.vbs" {PKG} {gettempdir()}\\{lcid}.mst {lcid}') + else: raise AssertionError('Unsupported platform') From e999dd68003f1239038461a62555e0e196c76865 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 13:15:51 +0100 Subject: [PATCH 026/727] setup.py: appcast file & PKG -> package_filename rename --- setup.py | 59 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/setup.py b/setup.py index b85ec2f2..b6fc55df 100755 --- a/setup.py +++ b/setup.py @@ -26,8 +26,10 @@ if sys.platform == 'win32': assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit' import py2exe # noqa: F401 # Yes, this *is* used dist_dir = 'dist.win32' + elif sys.platform == 'darwin': dist_dir = 'dist.macosx' + else: assert False, f'Unsupported platform {sys.platform}' @@ -241,7 +243,7 @@ setup( options=OPTIONS, ) -PKG = None +package_filename = None if sys.platform == 'darwin': if isdir(f'{dist_dir}/{applongname}.app'): # from CFBundleName os.rename(f'{dist_dir}/{applongname}.app', f'{dist_dir}/{appname}.app') @@ -262,8 +264,8 @@ if sys.platform == 'darwin': os.system(f'codesign --deep -v -s "Developer ID Application: {macdeveloperid}" {dist_dir}/{appname}.app') # Make zip for distribution, preserving signature - PKG = f'{appname}_mac_{appversion}.zip' - os.system(f'cd {dist_dir}; ditto -ck --keepParent --sequesterRsrc {appname}.app ../{PKG}; cd ..') + package_filename = f'{appname}_mac_{appversion}.zip' + os.system(f'cd {dist_dir}; ditto -ck --keepParent --sequesterRsrc {appname}.app ../{package_filename}; cd ..') elif sys.platform == 'win32': os.system(f'"{WIXPATH}\\candle.exe" -out {dist_dir}\\ {appname}.wxs') @@ -271,11 +273,11 @@ elif sys.platform == 'win32': if not exists(f'{dist_dir}/{appname}.wixobj'): raise AssertionError(f'No {dist_dir}/{appname}.wixobj: candle.exe failed?') - PKG = f'{appname}_win_{appversion}.msi' - os.system(f'"{WIXPATH}\\light.exe" -sacl -spdb -sw1076 {dist_dir}\\{appname}.wixobj -out {PKG}') + package_filename = f'{appname}_win_{appversion}.msi' + os.system(f'"{WIXPATH}\\light.exe" -sacl -spdb -sw1076 {dist_dir}\\{appname}.wixobj -out {package_filename}') - if not exists(PKG): - raise AssertionError(f'light.exe failed, no {PKG}') + if not exists(package_filename): + raise AssertionError(f'light.exe failed, no {package_filename}') # Seriously, this is how you make Windows Installer use the user's display language for its dialogs. What a crock. # http://www.geektieguy.com/2010/03/13/create-a-multi-lingual-multi-language-msi-using-wix-and-custom-build-scripts @@ -286,7 +288,7 @@ elif sys.platform == 'win32': ).group(1).split(',') ] assert lcids[0] == 1033, f'Default language is {lcids[0]}, should be 1033 (en_US)' - shutil.copyfile(PKG, join(gettempdir(), f'{appname}_1033.msi')) + shutil.copyfile(package_filename, join(gettempdir(), f'{appname}_1033.msi')) for lcid in lcids[1:]: shutil.copyfile( join(gettempdir(), f'{appname}_1033.msi'), @@ -295,21 +297,36 @@ elif sys.platform == 'win32': # Don't care about codepage because the displayed strings come from msiexec not our msi os.system(f'cscript /nologo "{SDKPATH}\\WiLangId.vbs" {gettempdir()}\\{appname}_{lcid}.msi Product {lcid}') os.system(f'"{SDKPATH}\\MsiTran.Exe" -g {gettempdir()}\\{appname}_1033.msi {gettempdir()}\\{appname}_{lcid}.msi {gettempdir()}\\{lcid}.mst') # noqa: E501 # Not going to get shorter - os.system(f'cscript /nologo "{SDKPATH}\\WiSubStg.vbs" {PKG} {gettempdir()}\\{lcid}.mst {lcid}') + os.system(f'cscript /nologo "{SDKPATH}\\WiSubStg.vbs" {package_filename} {gettempdir()}\\{lcid}.mst {lcid}') else: raise AssertionError('Unsupported platform') -if not exists(PKG): - raise AssertionError('No %s found prior to appcast' % (PKG)) +if not exists(package_filename): + raise AssertionError(f'No {package_filename} found prior to appcast') + # Make appcast entry -appcast = open('appcast_%s_%s.xml' % (sys.platform=='darwin' and 'mac' or 'win', appversion), 'w') -appcast.write(''' +appcast = open(f'appcast_{sys.platform == "darwin" and "mac" or "win"}_{appversion}.xml', 'w') + +if sys.platform == 'win32': + style = 'body { font-family:"Segoe UI","Tahoma"; font-size: 75%; } h2 { font-family:"Segoe UI","Tahoma"; font-size: 105%; }' + package_os = 'windows"\n\t\t\t\tsparkle:installerArguments="/passive LAUNCH=yes' + +elif sys.platform == 'darwin': + style = 'h2 { font-size: 105%; }' + package_os = 'macos' + +else: + raise AssertionError(f'Unknown platform for appcast {sys.platform}') + +length = os.stat(package_filename).st_size + +appcast.write(f''' \t\t \t\t\tRelease {appversion} \t\t\t \t\t\t\t{STYLE} +

Release {appversion}

    @@ -317,18 +334,12 @@ appcast.write(''' \t\t\t\t]]> \t\t\t \t\t\t \t\t -'''.format(appversion=appversion, - STYLE='{}'.format( - sys.platform=='win32' and 'body { font-family:"Segoe UI","Tahoma"; font-size: 75%; } h2 { font-family:"Segoe UI","Tahoma"; font-size: 105%; }' - or 'h2 { font-size: 105%; }'), - PKG=PKG, - OS=''.format(sys.platform=='win32' and 'windows"\n\t\t\t\tsparkle:installerArguments="/passive LAUNCH=yes' or 'macos'), - LENGTH=os.stat(PKG).st_size) +''' ) From 9177f9e2295077754f9933138ee9d119376bfbc1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 13:16:34 +0100 Subject: [PATCH 027/727] setup.py: Check python version at start --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index b6fc55df..5c310115 100755 --- a/setup.py +++ b/setup.py @@ -22,6 +22,9 @@ import semantic_version from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval +if sys.version_info[0:2] != (3, 8): + raise AssertionError(f'Unexpected python version {sys.version}') + if sys.platform == 'win32': assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit' import py2exe # noqa: F401 # Yes, this *is* used From a0c3fd04fd6a41c7bbb40493f19a0b3794fcabbc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:36:29 +0000 Subject: [PATCH 028/727] requirements.txt: Bump certifi to the latest: 2020.6.20 --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index ff058bc8..508df246 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.6.20 -requests==2.25.1 -watchdog==0.10.3 +requests>=2.11.1 +watchdog>=0.8.3 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From 44bea3468dea386bb38c96d27517017cf1d1e079 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:37:38 +0000 Subject: [PATCH 029/727] setup.py: Trial without naming `requests` in packages. --- setup.py | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/setup.py b/setup.py index 5c310115..366aa20b 100755 --- a/setup.py +++ b/setup.py @@ -165,30 +165,21 @@ if sys.platform == 'darwin': } DATA_FILES = [] -elif sys.platform == 'win32': - OPTIONS = { - 'py2exe': { - 'dist_dir': dist_dir, - 'optimize': 2, - 'packages': [ - 'sqlite3', # Included for plugins - ], - 'includes': [ - 'dataclasses', - 'shutil', # Included for plugins - 'timeout_session', - 'zipfile', # Included for plugins - ], - 'excludes': [ - 'distutils', - '_markerlib', - 'optparse', - 'PIL', - 'pkg_resources', - 'simplejson', - 'unittest' - ], - } +elif sys.platform=='win32': + OPTIONS = { 'py2exe': + {'dist_dir': dist_dir, + 'optimize': 2, + 'packages': [ + 'sqlite3', # Included for plugins + ], + 'includes': [ + 'dataclasses', + 'shutil', # Included for plugins + 'timeout_session', + 'zipfile', # Included for plugins + ], + 'excludes': [ 'distutils', '_markerlib', 'optparse', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ], + } } DATA_FILES = [ From 54f797ada8b05be9c65b7072d92fbc0fc5f3e414 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:38:20 +0000 Subject: [PATCH 030/727] setup.py: No need to manually include sqlite3.dll now --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 366aa20b..8ddf4d32 100755 --- a/setup.py +++ b/setup.py @@ -196,8 +196,8 @@ elif sys.platform=='win32': 'ships.p', 'stations.p', 'systems.p', - f'{appname}.VisualElementsManifest.xml', - f'{appname}.ico', + '%s.VisualElementsManifest.xml' % APPNAME, + '%s.ico' % APPNAME, 'EDMarketConnector - TRACE.bat', 'EDMarketConnector - localserver-auth.bat', ]), From 3e54e1f0157e8303773a1b40db04ec0370388974 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:39:32 +0000 Subject: [PATCH 031/727] Releasing.md: Update for Python 3.8.6 and py2exe 0.10.x. * Also put `--user` on the example `pip install` line. --- docs/Releasing.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 67bc9cc0..3b8fbc1c 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -36,15 +36,17 @@ You will need several pieces of software installed, or the files from their recently tested version. You need the `Windows x86 executable installer` file, for the 32-bit version. 1. [py2exe](https://github.com/albertosottile/py2exe) - Install the python - module. You will need at least [version 0.10.0.1](https://github.com/albertosottile/py2exe/releases/tag/v0.10.0.1), -specifically [py2exe-0.10.0.1-cp38-none-win32.whl](https://github.com/albertosottile/py2exe/releases/download/v0.10.0.1/py2exe-0.10.0.1-cp38-none-win32.whl). + module. You will need at least the [pre-release of 0.10.0.1](https://bintray.com/alby128/py2exe/py2exe/0.10.0.1#files) + as we found 0.10.0.0 still had an issue with certifi and cacert.pem. + 1. You'll now need to 'pip install' several python modules. 1. Ensure you have `pip` installed. If needs be see [Installing pip](https://pip.pypa.io/en/stable/installing/) 1. The easiest way is to utilise the `requirements-dev.txt` file: `python -m pip install --user -r requirements-dev.txt`. This will install - all dependencies plus anything required for development. + all dependencies plus anything required for development *other than + py2exe, see above*. 1. Else check the contents of both `requirements.txt` and `requirements-dev.txt`, and ensure the modules listed there are installed as per the version requirements. From 1b4ee4f3dd9dcc44b8f6267fac07e8b8c2405cbb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:40:49 +0000 Subject: [PATCH 032/727] PLUGINS.md: Update to mention using Python 3.8 post-4.1.x * Also adjusted links to information/examples to not be the bad 'here' form. --- PLUGINS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/PLUGINS.md b/PLUGINS.md index 34f3831a..95fd3c84 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -649,7 +649,6 @@ Disabled and enabled plugins are listed on the "Plugins" Settings tab Starting with pre-release 3.5 EDMC used Python 3.7. The first full release under Python 3.7 was 4.0.0.0. The 4.1.x series was the last to use Python 3.7, with releases moving on to latest Python 3.8.x after that. - This is a brief outline of the steps required to migrate a plugin from earlier versions of EDMC: From 1563e5073346a90038ceea66b0550890fd4de9f6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 16:51:24 +0100 Subject: [PATCH 033/727] PLUGINS.md: Reference Releasing.md for currently supported Python version --- PLUGINS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PLUGINS.md b/PLUGINS.md index 95fd3c84..34f3831a 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -649,6 +649,7 @@ Disabled and enabled plugins are listed on the "Plugins" Settings tab Starting with pre-release 3.5 EDMC used Python 3.7. The first full release under Python 3.7 was 4.0.0.0. The 4.1.x series was the last to use Python 3.7, with releases moving on to latest Python 3.8.x after that. + This is a brief outline of the steps required to migrate a plugin from earlier versions of EDMC: From 77939ad48eaadb8330672d5620d9f48d191ea680 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:41:42 +0000 Subject: [PATCH 034/727] Releasing.md: Update example full python path * Python 3.8 now. * And reference the centrally installed location, not the one under %LOCALAPPDATA%. --- docs/Releasing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 3b8fbc1c..607026ba 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -235,7 +235,7 @@ else you might need this, which assumes correct python.exe is in your PATH: else you'll have to specify the path to python.exe, e.g.: - "C:\Program Files \(x86)\Python38-32\python.exe" setup.py py2exe + "C:\Program Files (x86)\Python38-32\python.exe" setup.py py2exe Output will be something like (`...` denoting parts elided for brevity): From 753b5c59d39786d2d0d3b322c6104ffe34302da8 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 17:27:09 +0100 Subject: [PATCH 035/727] Releasing.md: py2exe 0.10.0.1 now released so reference it. --- docs/Releasing.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 607026ba..48b14ab9 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -36,9 +36,8 @@ You will need several pieces of software installed, or the files from their recently tested version. You need the `Windows x86 executable installer` file, for the 32-bit version. 1. [py2exe](https://github.com/albertosottile/py2exe) - Install the python - module. You will need at least the [pre-release of 0.10.0.1](https://bintray.com/alby128/py2exe/py2exe/0.10.0.1#files) - as we found 0.10.0.0 still had an issue with certifi and cacert.pem. - + module. You will need at least [version 0.10.0.1](https://github.com/albertosottile/py2exe/releases/tag/v0.10.0.1), +specifically [py2exe-0.10.0.1-cp38-none-win32.whl](https://github.com/albertosottile/py2exe/releases/download/v0.10.0.1/py2exe-0.10.0.1-cp38-none-win32.whl). 1. You'll now need to 'pip install' several python modules. 1. Ensure you have `pip` installed. If needs be see @@ -235,7 +234,7 @@ else you might need this, which assumes correct python.exe is in your PATH: else you'll have to specify the path to python.exe, e.g.: - "C:\Program Files (x86)\Python38-32\python.exe" setup.py py2exe + "C:\Program Files \(x86)\Python38-32\python.exe" setup.py py2exe Output will be something like (`...` denoting parts elided for brevity): From 9b828fe9b2c0502836270947462d113217ba9785 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:42:32 +0000 Subject: [PATCH 036/727] requirements: Reference py2exe via git URL@tag --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ee289366..3af1c7f8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -25,7 +25,7 @@ grip==4.5.2 # # #py2exe==0.10.0.1 -git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe; sys_platform == 'win32' +git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe # All of the normal requirements -r requirements.txt From a6779d7292a9bedb62d5c6ffbfdb0d3884d7764c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Oct 2020 19:04:56 +0100 Subject: [PATCH 037/727] requirements: py2exe only on win32 platform --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 3af1c7f8..ee289366 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -25,7 +25,7 @@ grip==4.5.2 # # #py2exe==0.10.0.1 -git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe +git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe; sys_platform == 'win32' # All of the normal requirements -r requirements.txt From a8313e3661447bd045ffcadaaa1c498a4ce61332 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 13:19:15 +0100 Subject: [PATCH 038/727] setup.py: Reformat appcast style multi-line --- setup.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 8ddf4d32..38e54231 100755 --- a/setup.py +++ b/setup.py @@ -303,7 +303,15 @@ if not exists(package_filename): appcast = open(f'appcast_{sys.platform == "darwin" and "mac" or "win"}_{appversion}.xml', 'w') if sys.platform == 'win32': - style = 'body { font-family:"Segoe UI","Tahoma"; font-size: 75%; } h2 { font-family:"Segoe UI","Tahoma"; font-size: 105%; }' + style = '''body { + font-family:"Segoe UI","Tahoma"; + font-size: 75%; +} +h2 { + font-family:"Segoe UI","Tahoma"; + font-size: 105%; +} +''' package_os = 'windows"\n\t\t\t\tsparkle:installerArguments="/passive LAUNCH=yes' elif sys.platform == 'darwin': @@ -335,5 +343,4 @@ appcast.write(f''' \t\t\t\ttype="application/octet-stream" \t\t\t/> \t\t -''' -) +''') From 7d4bef686cfff5a63046a82256cd05324c3df01d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 13:32:38 +0100 Subject: [PATCH 039/727] Releasing.md: Update to Windows SDK 19041 --- docs/Releasing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 48b14ab9..5fdf0831 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -25,11 +25,11 @@ You will need several pieces of software installed, or the files from their into your checkout of the EDMC git files. 1. [Windows SDK](https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk/). This is needed for the internationalisation support in EDMC. - [Windows 10 SDK, version 1903 (10.0.18362.1)](https://go.microsoft.com/fwlink/?linkid=2083338) + [Windows 10 SDK, version 2004 (10.0.19041.0)](https://go.microsoft.com/fwlink/p/?linkid=2120843) is the most recently tested version. Technically you only need the following components: `MSI Tools`, `Windows SDK for Desktop C++ x86 Apps` (which will auto-select some others). NB: If you have need to uninstall this it's - "Windows Software Development Kit - Windows 10.0.18362.1" in + "Windows Software Development Kit - Windows 10.0.19041.1" in "Apps & Features", *not* "Windows SDK AddOn". 1. [Python](https://python.org): 32-bit version of Python 3.8 for Windows. [v3.8.6](https://www.python.org/downloads/release/python-386/) is the most From db40197f808b6749625c65601f366784f9be3f38 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 13:44:14 +0100 Subject: [PATCH 040/727] requirements-dev.txt: Add mypy and safety --- requirements-dev.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index ee289366..2c4c57eb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -11,7 +11,9 @@ flake8-noqa==1.0.5 flake8-polyfill==1.0.2 flake8-use-fstring==1.1 +mypy==0.782 pep8-naming==0.11.1 +safety==1.9.0 # Code formatting tools autopep8==1.5.4 From 1297ba9c0d7d90527b26328565037f8eaf9d438a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 13:53:24 +0100 Subject: [PATCH 041/727] setup.py: typing cleanups * I didn't go looking for darwin 'py2app' docs to find the possible return types of py2app.recipes['member']['check'], so 'Any' will have to do. * re.search may return None, which then doesn't have .group(), so mypy complains. Just tell it to ignore that code. --- setup.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 38e54231..afd33481 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ import sys from distutils.core import setup from os.path import exists, isdir, join from tempfile import gettempdir -from typing import Set +from typing import Any, Generator, Set import semantic_version @@ -59,7 +59,8 @@ if sys.platform == 'darwin': import py2app.build_app from py2app import recipes - def iter_recipes(module=recipes): + # NB: 'Any' is because I don't have MacOS docs + def iter_recipes(module=recipes) -> Generator[str, Any]: """Enumerate recipes via alternate method.""" for name in dir(module): if name.startswith('_') or name == 'sip': @@ -276,7 +277,7 @@ elif sys.platform == 'win32': # Seriously, this is how you make Windows Installer use the user's display language for its dialogs. What a crock. # http://www.geektieguy.com/2010/03/13/create-a-multi-lingual-multi-language-msi-using-wix-and-custom-build-scripts lcids = [ - int(x) for x in re.search( + int(x) for x in re.search( # type: ignore r'Languages\s*=\s*"(.+?)"', open(f'{appname}.wxs').read() ).group(1).split(',') From 5201777d9d4fc23b06104ef601e3f40d8bea2194 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Oct 2020 06:35:39 +0000 Subject: [PATCH 042/727] Bump isort from 5.5.5 to 5.6.1 Bumps [isort](https://github.com/pycqa/isort) from 5.5.5 to 5.6.1. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.5.5...5.6.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 2c4c57eb..226611bd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.2.3 flake8-docstrings==1.5.0 -isort==5.5.5 +isort==5.6.1 flake8-isort==4.0.0 flake8-json==19.8.0 flake8-noqa==1.0.5 From 550ee394e3d5bce0ae710be7f0316c76c20f733c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 21:50:32 +0100 Subject: [PATCH 043/727] setup.py: Convert one f-string to rf-string. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index afd33481..9de2f127 100755 --- a/setup.py +++ b/setup.py @@ -263,7 +263,7 @@ if sys.platform == 'darwin': os.system(f'cd {dist_dir}; ditto -ck --keepParent --sequesterRsrc {appname}.app ../{package_filename}; cd ..') elif sys.platform == 'win32': - os.system(f'"{WIXPATH}\\candle.exe" -out {dist_dir}\\ {appname}.wxs') + os.system(rf'"{WIXPATH}\candle.exe" -out {dist_dir}\ {appname}.wxs') if not exists(f'{dist_dir}/{appname}.wixobj'): raise AssertionError(f'No {dist_dir}/{appname}.wixobj: candle.exe failed?') From 6c9045ba135ae8766567f76486e42d8e75d0ee34 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 9 Oct 2020 15:23:51 +0100 Subject: [PATCH 044/727] setup.py: Convert to rf'' strings, no need to escape backslashes. --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 9de2f127..b04bd6a7 100755 --- a/setup.py +++ b/setup.py @@ -269,7 +269,7 @@ elif sys.platform == 'win32': raise AssertionError(f'No {dist_dir}/{appname}.wixobj: candle.exe failed?') package_filename = f'{appname}_win_{appversion}.msi' - os.system(f'"{WIXPATH}\\light.exe" -sacl -spdb -sw1076 {dist_dir}\\{appname}.wixobj -out {package_filename}') + os.system(rf'"{WIXPATH}\light.exe" -sacl -spdb -sw1076 {dist_dir}\{appname}.wixobj -out {package_filename}') if not exists(package_filename): raise AssertionError(f'light.exe failed, no {package_filename}') @@ -290,9 +290,9 @@ elif sys.platform == 'win32': join(gettempdir(), f'{appname}_{lcid}.msi') ) # Don't care about codepage because the displayed strings come from msiexec not our msi - os.system(f'cscript /nologo "{SDKPATH}\\WiLangId.vbs" {gettempdir()}\\{appname}_{lcid}.msi Product {lcid}') - os.system(f'"{SDKPATH}\\MsiTran.Exe" -g {gettempdir()}\\{appname}_1033.msi {gettempdir()}\\{appname}_{lcid}.msi {gettempdir()}\\{lcid}.mst') # noqa: E501 # Not going to get shorter - os.system(f'cscript /nologo "{SDKPATH}\\WiSubStg.vbs" {package_filename} {gettempdir()}\\{lcid}.mst {lcid}') + os.system(rf'cscript /nologo "{SDKPATH}\WiLangId.vbs" {gettempdir()}\{appname}_{lcid}.msi Product {lcid}') + os.system(rf'"{SDKPATH}\MsiTran.Exe" -g {gettempdir()}\{appname}_1033.msi {gettempdir()}\{appname}_{lcid}.msi {gettempdir()}\{lcid}.mst') # noqa: E501 # Not going to get shorter + os.system(rf'cscript /nologo "{SDKPATH}\WiSubStg.vbs" {package_filename} {gettempdir()}\{lcid}.mst {lcid}') else: raise AssertionError('Unsupported platform') From 68406f82cf8216a2495bf9d34accee9e27dbd915 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 07:07:38 +0000 Subject: [PATCH 045/727] Bump isort from 5.6.1 to 5.6.3 Bumps [isort](https://github.com/pycqa/isort) from 5.6.1 to 5.6.3. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.6.1...5.6.3) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 226611bd..6c8fef38 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.2.3 flake8-docstrings==1.5.0 -isort==5.6.1 +isort==5.6.3 flake8-isort==4.0.0 flake8-json==19.8.0 flake8-noqa==1.0.5 From 3e6998cfbe8941acc845fd3f89af7b8f086c80de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 07:07:38 +0000 Subject: [PATCH 046/727] Bump mypy from 0.782 to 0.790 Bumps [mypy](https://github.com/python/mypy) from 0.782 to 0.790. - [Release notes](https://github.com/python/mypy/releases) - [Commits](https://github.com/python/mypy/compare/v0.782...v0.790) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6c8fef38..3ce38021 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -11,7 +11,7 @@ flake8-noqa==1.0.5 flake8-polyfill==1.0.2 flake8-use-fstring==1.1 -mypy==0.782 +mypy==0.790 pep8-naming==0.11.1 safety==1.9.0 From 8a3fa50c971b5e73688f17c96f450fe59a1dacad Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:44:30 +0000 Subject: [PATCH 047/727] EDMarketConnector: Pass on docstrings & Misc. * Removed a couple of E501 ignores tagged as now un-necessary. --- EDMarketConnector.py | 177 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 162 insertions(+), 15 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index ce97f9e3..52171150 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +"""Entry point for the main GUI application.""" import argparse import html @@ -271,6 +272,8 @@ SHIPYARD_HTML_TEMPLATE = """ class AppWindow(object): + """Define the main application window.""" + # Tkinter Event types EVENT_KEYPRESS = 2 EVENT_BUTTON = 4 @@ -294,7 +297,7 @@ class AppWindow(object): self.w.wm_iconbitmap(default='EDMarketConnector.ico') else: self.w.tk.call('wm', 'iconphoto', self.w, '-default', - tk.PhotoImage(file=join(config.respath, 'EDMarketConnector.png'))) # noqa: E501 + tk.PhotoImage(file=join(config.respath, 'EDMarketConnector.png'))) self.theme_icon = tk.PhotoImage( data='R0lGODlhFAAQAMZQAAoKCQoKCgsKCQwKCQsLCgwLCg4LCQ4LCg0MCg8MCRAMCRANChINCREOChIOChQPChgQChgRCxwTCyYVCSoXCS0YCTkdCTseCT0fCTsjDU0jB0EnDU8lB1ElB1MnCFIoCFMoCEkrDlkqCFwrCGEuCWIuCGQvCFs0D1w1D2wyCG0yCF82D182EHE0CHM0CHQ1CGQ5EHU2CHc3CHs4CH45CIA6CIE7CJdECIdLEolMEohQE5BQE41SFJBTE5lUE5pVE5RXFKNaFKVbFLVjFbZkFrxnFr9oFsNqFsVrF8RsFshtF89xF9NzGNh1GNl2GP+KG////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEKAH8ALAAAAAAUABAAAAeegAGCgiGDhoeIRDiIjIZGKzmNiAQBQxkRTU6am0tPCJSGShuSAUcLoIIbRYMFra4FAUgQAQCGJz6CDQ67vAFJJBi0hjBBD0w9PMnJOkAiJhaIKEI7HRoc19ceNAolwbWDLD8uAQnl5ga1I9CHEjEBAvDxAoMtFIYCBy+kFDKHAgM3ZtgYSLAGgwkp3pEyBOJCC2ELB31QATGioAoVAwEAOw==') # noqa: E501 self.theme_minimize = tk.BitmapImage( @@ -346,7 +349,7 @@ class AppWindow(object): self.button.grid(row=row, columnspan=2, sticky=tk.NSEW) self.theme_button.grid(row=row, columnspan=2, sticky=tk.NSEW) theme.register_alternate((self.button, self.theme_button, self.theme_button), - {'row': row, 'columnspan': 2, 'sticky': tk.NSEW}) # noqa: E501 + {'row': row, 'columnspan': 2, 'sticky': tk.NSEW}) self.status.grid(columnspan=2, sticky=tk.EW) self.button.bind('', self.getandsend) theme.button_bind(self.theme_button, self.getandsend) @@ -540,8 +543,8 @@ class AppWindow(object): self.postprefs(False) # Companion login happens in callback from monitor - # callback after the Preferences dialog is applied def postprefs(self, dologin=True): + """Perform necessary actions after the Preferences dialog is applied.""" self.prefsdialog = None self.set_labels() # in case language has changed @@ -563,8 +566,8 @@ class AppWindow(object): if dologin and monitor.cmdr: self.login() # Login if not already logged in with this Cmdr - # set main window labels, e.g. after language change def set_labels(self): + """Set main window labels, e.g. after language change.""" self.cmdr_label['text'] = _('Cmdr') + ':' # Main window # Multicrew role label in main window self.ship_label['text'] = (monitor.state['Captain'] and _('Role') or _('Ship')) + ':' # Main window @@ -608,35 +611,50 @@ class AppWindow(object): self.edit_menu.entryconfigure(0, label=_('Copy')) # As in Copy and Paste def login(self): + """Initiate CAPI/Frontier login and set other necessary state.""" if not self.status['text']: self.status['text'] = _('Logging in...') + self.button['state'] = self.theme_button['state'] = tk.DISABLED + if platform == 'darwin': self.view_menu.entryconfigure(0, state=tk.DISABLED) # Status self.file_menu.entryconfigure(0, state=tk.DISABLED) # Save Raw Data + else: self.file_menu.entryconfigure(0, state=tk.DISABLED) # Status self.file_menu.entryconfigure(1, state=tk.DISABLED) # Save Raw Data + self.w.update_idletasks() try: if companion.session.login(monitor.cmdr, monitor.is_beta): # Successfully authenticated with the Frontier website self.status['text'] = _('Authentication successful') + if platform == 'darwin': self.view_menu.entryconfigure(0, state=tk.NORMAL) # Status self.file_menu.entryconfigure(0, state=tk.NORMAL) # Save Raw Data + else: self.file_menu.entryconfigure(0, state=tk.NORMAL) # Status self.file_menu.entryconfigure(1, state=tk.NORMAL) # Save Raw Data + except (companion.CredentialsError, companion.ServerError, companion.ServerLagging) as e: self.status['text'] = str(e) + except Exception as e: logger.debug('Frontier CAPI Auth', exc_info=e) self.status['text'] = str(e) + self.cooldown() - def getandsend(self, event=None, retrying=False): # noqa: C901 + def getandsend(self, event=None, retrying=False): + """ + Perform CAPI data retrieval and associated actions. + This can be triggered by hitting the main UI 'Update' button, + automatically on docking, or due to a retry. + """ auto_update = not event play_sound = (auto_update or int(event.type) == self.EVENT_VIRTUAL) and not config.getint('hotkey_mute') play_bad = False @@ -695,7 +713,6 @@ class AppWindow(object): raise companion.ServerLagging() else: - if __debug__: # Recording if isdir('dump'): with open('dump/{system}{station}.{timestamp}.json'.format( @@ -731,19 +748,23 @@ class AppWindow(object): # but the server hosting the Companion API hasn't caught up self.status['text'] = _("You're not docked at a station!") play_bad = True + # Ignore possibly missing shipyard info elif (config.getint('output') & config.OUT_MKT_EDDN) \ and not (data['lastStarport'].get('commodities') or data['lastStarport'].get('modules')): if not self.status['text']: self.status['text'] = _("Station doesn't have anything!") + elif not data['lastStarport'].get('commodities'): if not self.status['text']: self.status['text'] = _("Station doesn't have a market!") + elif config.getint('output') & (config.OUT_MKT_CSV | config.OUT_MKT_TD): # Fixup anomalies in the commodity data fixed = companion.fixup(data) if config.getint('output') & config.OUT_MKT_CSV: commodity.export(fixed, COMMODITY_CSV) + if config.getint('output') & config.OUT_MKT_TD: td.export(fixed) @@ -754,6 +775,7 @@ class AppWindow(object): if retrying: self.status['text'] = str(e) play_bad = True + else: # Retry once if Companion server is unresponsive self.w.after(int(SERVER_RETRY * 1000), lambda: self.getandsend(event, True)) @@ -772,32 +794,44 @@ class AppWindow(object): if not self.status['text']: # no errors self.status['text'] = strftime(_('Last updated at %H:%M:%S'), localtime(querytime)) + if play_sound and play_bad: hotkeymgr.play_bad() self.cooldown() + # TODO: This has no users other than itself. def retry_for_shipyard(self, tries): - # Try again to get shipyard data and send to EDDN. Don't report errors if can't get or send the data. + """ + Try again to get shipyard data and send to EDDN. + + Don't report errors if can't get or send the data. + """ try: data = companion.session.station() if data['commander'].get('docked'): if data.get('lastStarport', {}).get('ships'): report = 'Success' + else: report = 'Failure' + else: report = 'Undocked!' + logger.debug(f'Retry for shipyard - {report}') if not data['commander'].get('docked'): # might have un-docked while we were waiting for retry in which case station data is unreliable pass + elif (data.get('lastSystem', {}).get('name') == monitor.system and data.get('lastStarport', {}).get('name') == monitor.station and data.get('lastStarport', {}).get('ships', {}).get('shipyard_list')): self.eddn.export_shipyard(data, monitor.is_beta) + elif tries > 1: # bogus data - retry self.w.after(int(SERVER_RETRY * 1000), lambda: self.retry_for_shipyard(tries - 1)) + except Exception: pass @@ -925,7 +959,13 @@ class AppWindow(object): # cAPI auth def auth(self, event=None): - logger.debug('Received "<>') + """ + Handle Frontier auth callback. + + This is the callback function for the CompanionAuthEvent Tk event. + It is triggered by the event() function of class GenericProtocolHandler + in protocol.py. + """ try: companion.session.auth_callback() # Successfully authenticated with the Frontier website @@ -947,8 +987,12 @@ class AppWindow(object): self.cooldown() - # Handle Status event def dashboard_event(self, event): + """ + Handle DashBoardEvent tk event. + + Event is sent by code in dashboard.py. + """ entry = dashboard.status if entry: # Currently we don't do anything with these events @@ -958,8 +1002,8 @@ class AppWindow(object): if not config.getint('hotkey_mute'): hotkeymgr.play_bad() - # Display asynchronous error from plugin def plugin_error(self, event=None): + """Display asynchronous error from plugin.""" if plug.last_error.get('msg'): self.status['text'] = plug.last_error['msg'] self.w.update_idletasks() @@ -967,6 +1011,7 @@ class AppWindow(object): hotkeymgr.play_bad() def shipyard_url(self, shipname): + """Despatch a ship URL to the configured handler.""" if not bool(config.getint("use_alt_shipyard_open")): return plug.invoke(config.get('shipyard_provider'), 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) @@ -985,17 +1030,21 @@ class AppWindow(object): return f'file://localhost/{file_name}' def system_url(self, system): + """Despatch a system URL to the configured handler.""" return plug.invoke(config.get('system_provider'), 'EDSM', 'system_url', monitor.system) def station_url(self, station): + """Despatch a station URL to the configured handler.""" return plug.invoke(config.get('station_provider'), 'eddb', 'station_url', monitor.system, monitor.station) def cooldown(self): + """Display and update the cooldown timer for 'Update' button.""" if time() < self.holdofftime: # Update button in main window self.button['text'] = self.theme_button['text'] \ = _('cooldown {SS}s').format(SS=int(self.holdofftime - time())) self.w.after(1000, self.cooldown) + else: self.button['text'] = self.theme_button['text'] = _('Update') # Update button in main window self.button['state'] = self.theme_button['state'] = (monitor.cmdr and @@ -1005,29 +1054,37 @@ class AppWindow(object): tk.NORMAL or tk.DISABLED) def ontop_changed(self, event=None): + """Set main window 'on top' state as appropriate.""" config.set('always_ontop', self.always_ontop.get()) self.w.wm_attributes('-topmost', self.always_ontop.get()) def copy(self, event=None): + """Copy system, and possible station, name to clipboard.""" if monitor.system: self.w.clipboard_clear() self.w.clipboard_append(monitor.station and f'{monitor.system},{monitor.station}' or monitor.system) def help_general(self, event=None): + """Open Wiki Help page in browser.""" webbrowser.open('https://github.com/EDCD/EDMarketConnector/wiki') def help_privacy(self, event=None): + """Open Wiki Privacy page in browser.""" webbrowser.open('https://github.com/EDCD/EDMarketConnector/wiki/Privacy-Policy') def help_releases(self, event=None): + """Open Releases page in browser.""" webbrowser.open('https://github.com/EDCD/EDMarketConnector/releases') class HelpAbout(tk.Toplevel): + """The applications Help > About popup.""" + showing = False def __init__(self, parent): if self.__class__.showing: return + self.__class__.showing = True tk.Toplevel.__init__(self, parent) @@ -1100,14 +1157,17 @@ class AppWindow(object): logger.info(f'Current version is {appversion}') def apply(self): + """Close the window.""" self._destroy() def _destroy(self): + """Set parent window's topmost appropriately as we close.""" self.parent.wm_attributes('-topmost', config.getint('always_ontop') and 1 or 0) self.destroy() self.__class__.showing = False def save_raw(self): + """Save newly acquired CAPI data in the configured file.""" self.status['text'] = _('Fetching data...') self.w.update_idletasks() @@ -1115,12 +1175,16 @@ class AppWindow(object): data = companion.session.station() self.status['text'] = '' default_extension: str = '' + if platform == 'darwin': default_extension = '.json' + last_system: str = data.get("lastSystem", {}).get("name", "Unknown") last_starport: str = '' + if data['commander'].get('docked'): last_starport = '.' + data.get('lastStarport', {}).get('name', 'Unknown') + timestamp: str = strftime('%Y-%m-%dT%H.%M.%S', localtime()) f = tkinter.filedialog.asksaveasfilename(parent=self.w, defaultextension=default_extension, @@ -1134,15 +1198,16 @@ class AppWindow(object): indent=2, sort_keys=True, separators=(',', ': ')).encode('utf-8')) + except companion.ServerError as e: self.status['text'] = str(e) + except Exception as e: logger.debug('"other" exception', exc_info=e) self.status['text'] = str(e) def onexit(self, event=None): - config.set_shutdown() # Signal we're in shutdown now. - + """Application shutdown procedure.""" # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 if platform != 'darwin' or self.w.winfo_rooty() > 0: x, y = self.w.geometry().split('+')[1:3] # e.g. '212x170+2881+1267' @@ -1189,50 +1254,129 @@ class AppWindow(object): logger.info('Destroying app window...') self.w.destroy() - logger.info('Done.') - - def drag_start(self, event) -> None: + def drag_start(self, event): """Initiate dragging the window.""" self.drag_offset = (event.x_root - self.w.winfo_rootx(), event.y_root - self.w.winfo_rooty()) def drag_continue(self, event): + """Continued handling of window drag.""" if self.drag_offset: offset_x = event.x_root - self.drag_offset[0] offset_y = event.y_root - self.drag_offset[1] self.w.geometry(f'+{offset_x:d}+{offset_y:d}') def drag_end(self, event): + """Handle end of window dragging.""" self.drag_offset = None def oniconify(self, event=None): + """Handle iconification of the application.""" self.w.overrideredirect(0) # Can't iconize while overrideredirect self.w.iconify() self.w.update_idletasks() # Size and windows styles get recalculated here self.w.wait_visibility() # Need main window to be re-created before returning theme.active = None # So theme will be re-applied on map + # TODO: Confirm this is unused and remove. def onmap(self, event=None): + """Perform a now unused function.""" if event.widget == self.w: theme.apply(self.w) def onenter(self, event=None): + """Handle when our window gains focus.""" + # TODO: This assumes that 1) transparent is at least 2, 2) there are + # no new themes added after that. if config.getint('theme') > 1: self.w.attributes("-transparentcolor", '') self.blank_menubar.grid_remove() self.theme_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) def onleave(self, event=None): + """Handle when our window loses focus.""" + # TODO: This assumes that 1) transparent is at least 2, 2) there are + # no new themes added after that. if config.getint('theme') > 1 and event.widget == self.w: self.w.attributes("-transparentcolor", 'grey4') self.theme_menubar.grid_remove() self.blank_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) +def enforce_single_instance() -> None: + """ + Ensure only one copy of the app is running under this user account. + + OSX does this automatically. + """ + # TODO: Linux implementation + if platform == 'win32': + import ctypes + from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR + + EnumWindows = ctypes.windll.user32.EnumWindows # noqa: N806 + GetClassName = ctypes.windll.user32.GetClassNameW # noqa: N806 + GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int] + GetWindowText = ctypes.windll.user32.GetWindowTextW # noqa: N806 + GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int] + GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW # noqa: N806 + GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 + + SW_RESTORE = 9 # noqa: N806 + SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow # noqa: N806 + ShowWindow = ctypes.windll.user32.ShowWindow # noqa: N806 + ShowWindowAsync = ctypes.windll.user32.ShowWindowAsync # noqa: N806 + + COINIT_MULTITHREADED = 0 # noqa: N806,F841 + COINIT_APARTMENTTHREADED = 0x2 # noqa: N806 + COINIT_DISABLE_OLE1DDE = 0x4 # noqa: N806 + CoInitializeEx = ctypes.windll.ole32.CoInitializeEx # noqa: N806 + + ShellExecute = ctypes.windll.shell32.ShellExecuteW # noqa: N806 + ShellExecute.argtypes = [HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT] + + def window_title(h): + if h: + text_length = GetWindowTextLength(h) + 1 + buf = ctypes.create_unicode_buffer(text_length) + if GetWindowText(h, buf, text_length): + return buf.value + + return None + + @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) + def enumwindowsproc(window_handle, l_param): + # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 + cls = ctypes.create_unicode_buffer(257) + if GetClassName(window_handle, cls, 257) \ + and cls.value == 'TkTopLevel' \ + and window_title(window_handle) == applongname \ + and GetProcessHandleFromHwnd(window_handle): + # If GetProcessHandleFromHwnd succeeds then the app is already running as this user + if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): + # Browser invoked us directly with auth response. Forward the response to the other app instance. + CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) + # Wait for it to be responsive to avoid ShellExecute recursing + ShowWindow(window_handle, SW_RESTORE) + ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) + + else: + ShowWindowAsync(window_handle, SW_RESTORE) + SetForegroundWindow(window_handle) + + sys.exit(0) + + return True + + EnumWindows(enumwindowsproc, 0) + + def test_logging(): + """Simple test of top level logging.""" logger.debug('Test from EDMarketConnector.py top-level test_logging()') def log_locale(prefix: str) -> None: + """Log all of the current local settings.""" logger.debug(f'''Locale: {prefix} Locale LC_COLLATE: {locale.getlocale(locale.LC_COLLATE)} Locale LC_CTYPE: {locale.getlocale(locale.LC_CTYPE)} @@ -1311,8 +1455,10 @@ sys.path: {sys.path}''' # test_logging() class A(object): + """Simple top-level class.""" class B(object): + """Simple second-level class.""" def __init__(self): logger.debug('A call from A.B.__init__') @@ -1352,6 +1498,7 @@ sys.path: {sys.path}''' app = AppWindow(root) def messagebox_not_py3(): + """Display message about plugins not updated for Python 3.x.""" plugins_not_py3_last = config.getint('plugins_not_py3_last') or 0 if (plugins_not_py3_last + 86400) < int(time()) and len(plug.PLUGINS_not_py3): # Yes, this is horribly hacky so as to be sure we match the key From da9e406e812ddc45b2504ad525b3ed4ade1cca25 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:46:41 +0000 Subject: [PATCH 048/727] EDMarketConnector: Convert debug data dump to f-string & misc * docstring indent on Class A. * Minor white space adjustments. --- EDMarketConnector.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 52171150..0d4d0e50 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -715,11 +715,17 @@ class AppWindow(object): else: if __debug__: # Recording if isdir('dump'): - with open('dump/{system}{station}.{timestamp}.json'.format( - system=data['lastSystem']['name'], - station=data['commander'].get('docked') and '.' + data['lastStarport']['name'] or '', - timestamp=strftime('%Y-%m-%dT%H.%M.%S', localtime())), 'wb') as h: - h.write(json.dumps(dict(data), + system = data['lastSystem']['name'] + + if data['commander'].get('docked'): + station = f'.{data["lastStarport"]["name"]}' + + else: + station = '' + + timestamp = strftime('%Y-%m-%dT%H.%M.%S', localtime()) + with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: + h.write(json.dumps(data, ensure_ascii=False, indent=2, sort_keys=True, @@ -1458,7 +1464,7 @@ sys.path: {sys.path}''' """Simple top-level class.""" class B(object): - """Simple second-level class.""" + """Simple second-level class.""" def __init__(self): logger.debug('A call from A.B.__init__') From a4422c206509c323ba6b2f670ab2f1ef6e708a98 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 13:42:30 +0100 Subject: [PATCH 049/727] pre-commit: Update config as per cleanup/config.py --- .pre-commit-config.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 581989af..07f78664 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 + rev: '' hooks: - id: check-merge-conflict - id: debug-statements @@ -58,10 +58,8 @@ repos: language: system default_language_version: - python: python3.7 + python: python3.8 default_stages: [ commit, push ] #files: '([^\.].+/)*.py' - -exclude: cp37-setup-new.py From 97f3af256894c88e431429cbc4e45a8fbf9c4bb1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 14:19:46 +0100 Subject: [PATCH 050/727] EDMarketConnector: Refactor of getandsend() and journal_event() --- EDMarketConnector.py | 151 ++++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 58 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 0d4d0e50..b1ca41c0 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -14,7 +14,7 @@ from os import chdir, environ from os.path import dirname, isdir, join from sys import platform from time import localtime, strftime, time -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Mapping from constants import applongname, appname, protocolhandler_redirect @@ -648,7 +648,61 @@ class AppWindow(object): self.cooldown() - def getandsend(self, event=None, retrying=False): + def dump_capi_data(self, data): + """Dump CAPI data to file for examination.""" + if isdir('dump'): + system = data['lastSystem']['name'] + + if data['commander'].get('docked'): + station = f'.{data["lastStarport"]["name"]}' + + else: + station = '' + + timestamp = strftime('%Y-%m-%dT%H.%M.%S', localtime()) + with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: + h.write(json.dumps(data, + ensure_ascii=False, + indent=2, + sort_keys=True, + separators=(',', ': ')).encode('utf-8')) + + def export_market_data(self, data: Mapping[str, Any]) -> bool: + """ + Export CAPI market data. + + :return: True if all OK, else False to trigger play_bad in caller. + """ + if config.getint('output') & (config.OUT_STATION_ANY): + if not data['commander'].get('docked'): + if not self.status['text']: + # Signal as error because the user might actually be docked + # but the server hosting the Companion API hasn't caught up + self.status['text'] = _("You're not docked at a station!") + return False + + # Ignore possibly missing shipyard info + elif (config.getint('output') & config.OUT_MKT_EDDN) \ + and not (data['lastStarport'].get('commodities') or data['lastStarport'].get('modules')): + if not self.status['text']: + self.status['text'] = _("Station doesn't have anything!") + + elif not data['lastStarport'].get('commodities'): + if not self.status['text']: + self.status['text'] = _("Station doesn't have a market!") + + elif config.getint('output') & (config.OUT_MKT_CSV | config.OUT_MKT_TD): + # Fixup anomalies in the commodity data + fixed = companion.fixup(data) + if config.getint('output') & config.OUT_MKT_CSV: + commodity.export(fixed, COMMODITY_CSV) + + if config.getint('output') & config.OUT_MKT_TD: + td.export(fixed) + + return True + + def getandsend(self, event=None, retrying=False): # noqa: C901 """ Perform CAPI data retrieval and associated actions. @@ -672,9 +726,12 @@ class AppWindow(object): self.status['text'] = '' if play_sound and (self.holdofftime - time()) < companion.holdoff * 0.75: hotkeymgr.play_bad() # Don't play sound in first few seconds to prevent repeats + return + elif play_sound: hotkeymgr.play_good() + self.status['text'] = _('Fetching data...') self.button['state'] = self.theme_button['state'] = tk.DISABLED self.w.update_idletasks() @@ -714,22 +771,7 @@ class AppWindow(object): else: if __debug__: # Recording - if isdir('dump'): - system = data['lastSystem']['name'] - - if data['commander'].get('docked'): - station = f'.{data["lastStarport"]["name"]}' - - else: - station = '' - - timestamp = strftime('%Y-%m-%dT%H.%M.%S', localtime()) - with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: - h.write(json.dumps(data, - ensure_ascii=False, - indent=2, - sort_keys=True, - separators=(',', ': ')).encode('utf-8')) + self.dump_capi_data(data) if not monitor.state['ShipType']: # Started game in SRV or fighter self.ship['text'] = companion.ship_map.get(data['ship']['name'].lower(), data['ship']['name']) @@ -747,32 +789,8 @@ class AppWindow(object): play_bad = True # Export market data - if config.getint('output') & (config.OUT_STATION_ANY): - if not data['commander'].get('docked'): - if not self.status['text']: - # Signal as error because the user might actually be docked - # but the server hosting the Companion API hasn't caught up - self.status['text'] = _("You're not docked at a station!") - play_bad = True - - # Ignore possibly missing shipyard info - elif (config.getint('output') & config.OUT_MKT_EDDN) \ - and not (data['lastStarport'].get('commodities') or data['lastStarport'].get('modules')): - if not self.status['text']: - self.status['text'] = _("Station doesn't have anything!") - - elif not data['lastStarport'].get('commodities'): - if not self.status['text']: - self.status['text'] = _("Station doesn't have a market!") - - elif config.getint('output') & (config.OUT_MKT_CSV | config.OUT_MKT_TD): - # Fixup anomalies in the commodity data - fixed = companion.fixup(data) - if config.getint('output') & config.OUT_MKT_CSV: - commodity.export(fixed, COMMODITY_CSV) - - if config.getint('output') & config.OUT_MKT_TD: - td.export(fixed) + if not self.export_market_data(data): + play_bad = True self.holdofftime = querytime + companion.holdoff @@ -851,7 +869,11 @@ class AppWindow(object): """ def crewroletext(role): - # Return translated crew role. Needs to be dynamic to allow for changing language. + """ + Return translated crew role. + + Needs to be dynamic to allow for changing language. + """ return { None: '', 'Idle': '', @@ -876,17 +898,27 @@ class AppWindow(object): self.cmdr['text'] = f'{monitor.cmdr} / {monitor.state["Captain"]}' self.ship_label['text'] = _('Role') + ':' # Multicrew role label in main window self.ship.configure(state=tk.NORMAL, text=crewroletext(monitor.state['Role']), url=None) + elif monitor.cmdr: if monitor.group: self.cmdr['text'] = f'{monitor.cmdr} / {monitor.group}' + else: self.cmdr['text'] = monitor.cmdr + self.ship_label['text'] = _('Ship') + ':' # Main window - self.ship.configure( - text=monitor.state['ShipName'] - or companion.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) - or '', - url=self.shipyard_url) + + if monitor.state['ShipName']: + ship_text = monitor.state['ShipName'] + + else: + ship_text = companion.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) + + if not ship_text: + ship_text = '' + + self.ship.configure(text=ship_text, url=self.shipyard_url) + else: self.cmdr['text'] = '' self.ship_label['text'] = _('Ship') + ':' # Main window @@ -910,6 +942,7 @@ class AppWindow(object): 'Synthesis', 'JoinACrew'): self.status['text'] = '' # Periodically clear any old error + self.w.update_idletasks() # Companion login @@ -924,11 +957,13 @@ class AppWindow(object): if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started: logger.info('Startup or LoadGame event') + # Disable WinSparkle automatic update checks, IFF configured to do so when in-game if config.getint('disable_autoappupdatecheckingame') and 1: self.updater.setAutomaticUpdatesCheck(False) logger.info('Monitor: Disable WinSparkle automatic update checks') - # Can start dashboard monitoring + + # Can't start dashboard monitoring if not dashboard.start(self.w, monitor.started): logger.info("Can't start Status monitoring") @@ -937,7 +972,6 @@ class AppWindow(object): and config.getint('output') & config.OUT_SHIP: monitor.export_ship() - # Plugins err = plug.notify_journal_entry(monitor.cmdr, monitor.is_beta, monitor.system, @@ -950,11 +984,13 @@ class AppWindow(object): hotkeymgr.play_bad() # Auto-Update after docking, but not if auth callback is pending - if entry['event'] in ('StartUp', 'Location', 'Docked') \ - and monitor.station \ - and not config.getint('output') & config.OUT_MKT_MANUAL \ - and config.getint('output') & config.OUT_STATION_ANY \ - and companion.session.state != companion.Session.STATE_AUTH: + if ( + entry['event'] in ('StartUp', 'Location', 'Docked') + and monitor.station + and not config.getint('output') & config.OUT_MKT_MANUAL + and config.getint('output') & config.OUT_STATION_ANY + and companion.session.state != companion.Session.STATE_AUTH + ): self.w.after(int(SERVER_RETRY * 1000), self.getandsend) if entry['event'] == 'ShutDown': @@ -963,7 +999,6 @@ class AppWindow(object): self.updater.setAutomaticUpdatesCheck(True) logger.info('Monitor: Enable WinSparkle automatic update checks') - # cAPI auth def auth(self, event=None): """ Handle Frontier auth callback. From 55f1e11f0b335f3df8cdd9d7963d3f5b30b0c076 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:48:29 +0000 Subject: [PATCH 051/727] EDMarketConnector: Correct __init__ master type & misc --- EDMarketConnector.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b1ca41c0..4518f946 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -279,7 +279,7 @@ class AppWindow(object): EVENT_BUTTON = 4 EVENT_VIRTUAL = 35 - def __init__(self, master): # noqa: C901 + def __init__(self, master: tk.Tk): # noqa: C901 # TODO - can possibly factor something out self.holdofftime = config.getint('querytime') + companion.holdoff @@ -295,9 +295,12 @@ class AppWindow(object): if platform != 'darwin': if platform == 'win32': self.w.wm_iconbitmap(default='EDMarketConnector.ico') + else: self.w.tk.call('wm', 'iconphoto', self.w, '-default', tk.PhotoImage(file=join(config.respath, 'EDMarketConnector.png'))) + + # TODO: Export to files and merge from them in future ? self.theme_icon = tk.PhotoImage( data='R0lGODlhFAAQAMZQAAoKCQoKCgsKCQwKCQsLCgwLCg4LCQ4LCg0MCg8MCRAMCRANChINCREOChIOChQPChgQChgRCxwTCyYVCSoXCS0YCTkdCTseCT0fCTsjDU0jB0EnDU8lB1ElB1MnCFIoCFMoCEkrDlkqCFwrCGEuCWIuCGQvCFs0D1w1D2wyCG0yCF82D182EHE0CHM0CHQ1CGQ5EHU2CHc3CHs4CH45CIA6CIE7CJdECIdLEolMEohQE5BQE41SFJBTE5lUE5pVE5RXFKNaFKVbFLVjFbZkFrxnFr9oFsNqFsVrF8RsFshtF89xF9NzGNh1GNl2GP+KG////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEKAH8ALAAAAAAUABAAAAeegAGCgiGDhoeIRDiIjIZGKzmNiAQBQxkRTU6am0tPCJSGShuSAUcLoIIbRYMFra4FAUgQAQCGJz6CDQ67vAFJJBi0hjBBD0w9PMnJOkAiJhaIKEI7HRoc19ceNAolwbWDLD8uAQnl5ga1I9CHEjEBAvDxAoMtFIYCBy+kFDKHAgM3ZtgYSLAGgwkp3pEyBOJCC2ELB31QATGioAoVAwEAOw==') # noqa: E501 self.theme_minimize = tk.BitmapImage( @@ -395,7 +398,8 @@ class AppWindow(object): self.w.createcommand("::tk::mac::ReopenApplication", self.w.deiconify) # click on app in dock = restore self.w.protocol("WM_DELETE_WINDOW", self.w.withdraw) # close button shouldn't quit app self.w.resizable(tk.FALSE, tk.FALSE) # Can't be only resizable on one axis - else: + + else: # win32 or linux self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) self.file_menu.add_command(command=lambda: stats.StatsDialog(self)) self.file_menu.add_command(command=self.save_raw) From a038b308557dd266440ad077da84e0503ecfd189 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:49:13 +0000 Subject: [PATCH 052/727] EDMarketConnector: Remove call to deprecated config.getpassword() --- EDMarketConnector.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 4518f946..18932c62 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -224,6 +224,7 @@ if TYPE_CHECKING: """Fake the l10n translation functions for typing.""" return x + if getattr(sys, 'frozen', False): # Under py2exe sys.path[0] is the executable name if platform == 'win32': @@ -532,11 +533,6 @@ class AppWindow(object): self.updater = update.Updater(tkroot=self.w, provider='internal') self.updater.checkForUpdates() # Sparkle / WinSparkle does this automatically for packaged apps - try: - config.get_password('') # Prod SecureStorage on Linux to initialise - except RuntimeError: - pass - # Migration from <= 3.30 for username in config.get('fdev_usernames') or []: config.delete_password(username) From aafc419124abd81abe3e463642976d8d96e643ce Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 14:43:53 +0100 Subject: [PATCH 053/727] 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). --- EDMarketConnector.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 18932c62..1499ef54 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -361,6 +361,10 @@ class AppWindow(object): for child in frame.winfo_children(): child.grid_configure(padx=5, pady=(platform != 'win32' or isinstance(child, tk.Frame)) and 2 or 0) + # The type needs defining for adding the menu entry, but won't be + # properly set until later + self.updater: update.Updater = None + self.menubar = tk.Menu() if platform == 'darwin': # Can't handle (de)iconify if topmost is set, so suppress iconify button From 58787bc65e98f9c09f275b8adb7020686459a33e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 15:46:26 +0100 Subject: [PATCH 054/727] EDMarketConnector: Final type annotation fixups. * Ignore Tkinter 'name' complaints. I've opened 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. --- EDMarketConnector.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 1499ef54..e3a87f5e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -218,6 +218,7 @@ if __name__ == '__main__': # noqa: C901 # isort: off if TYPE_CHECKING: from logging import trace, TRACE # type: ignore # noqa: F401 + import update # isort: on def _(x: str) -> str: @@ -309,7 +310,7 @@ class AppWindow(object): self.theme_close = tk.BitmapImage( data='#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e,\n 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c,\n 0x1c, 0x38, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00 };\n') # noqa: E501 - frame = tk.Frame(self.w, name=appname.lower()) + frame = tk.Frame(self.w, name=appname.lower()) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 frame.grid(sticky=tk.NSEW) frame.columnconfigure(1, weight=1) @@ -323,8 +324,8 @@ class AppWindow(object): self.system_label.grid(row=3, column=0, sticky=tk.W) self.station_label.grid(row=4, column=0, sticky=tk.W) - self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr') - self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship') + self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system') self.station = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.station_url, name='station') @@ -347,7 +348,7 @@ class AppWindow(object): # Update button in main window self.button = ttk.Button(frame, text=_('Update'), width=28, default=tk.ACTIVE, state=tk.DISABLED) self.theme_button = tk.Label(frame, width=32 if platform == 'darwin' else 28, state=tk.DISABLED) - self.status = tk.Label(frame, name='status', anchor=tk.W) + self.status = tk.Label(frame, name='status', anchor=tk.W) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 row = frame.grid_size()[1] self.button.grid(row=row, columnspan=2, sticky=tk.NSEW) @@ -364,7 +365,7 @@ class AppWindow(object): # The type needs defining for adding the menu entry, but won't be # properly set until later self.updater: update.Updater = None - + self.menubar = tk.Menu() if platform == 'darwin': # Can't handle (de)iconify if topmost is set, so suppress iconify button @@ -373,23 +374,23 @@ class AppWindow(object): root.call('tk::unsupported::MacWindowStyle', 'style', root, 'document', 'closeBox resizable') # https://www.tcl.tk/man/tcl/TkCmd/menu.htm - self.system_menu = tk.Menu(self.menubar, name='apple') + self.system_menu = tk.Menu(self.menubar, name='apple') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system_menu.add_command(command=lambda: self.w.call('tk::mac::standardAboutPanel')) self.system_menu.add_command(command=lambda: self.updater.checkForUpdates()) self.menubar.add_cascade(menu=self.system_menu) - self.file_menu = tk.Menu(self.menubar, name='file') + self.file_menu = tk.Menu(self.menubar, name='file') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.file_menu.add_command(command=self.save_raw) self.menubar.add_cascade(menu=self.file_menu) - self.edit_menu = tk.Menu(self.menubar, name='edit') + self.edit_menu = tk.Menu(self.menubar, name='edit') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.edit_menu.add_command(accelerator='Command-c', state=tk.DISABLED, command=self.copy) self.menubar.add_cascade(menu=self.edit_menu) self.w.bind('', self.copy) - self.view_menu = tk.Menu(self.menubar, name='view') + self.view_menu = tk.Menu(self.menubar, name='view') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.view_menu.add_command(command=lambda: stats.StatsDialog(self)) self.menubar.add_cascade(menu=self.view_menu) - window_menu = tk.Menu(self.menubar, name='window') + window_menu = tk.Menu(self.menubar, name='window') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.menubar.add_cascade(menu=window_menu) - self.help_menu = tk.Menu(self.menubar, name='help') + self.help_menu = tk.Menu(self.menubar, name='help') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.w.createcommand("::tk::mac::ShowHelp", self.help_general) self.help_menu.add_command(command=self.help_privacy) self.help_menu.add_command(command=self.help_releases) @@ -405,17 +406,17 @@ class AppWindow(object): self.w.resizable(tk.FALSE, tk.FALSE) # Can't be only resizable on one axis else: # win32 or linux - self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) + self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=False) self.file_menu.add_command(command=lambda: stats.StatsDialog(self)) self.file_menu.add_command(command=self.save_raw) self.file_menu.add_command(command=lambda: prefs.PreferencesDialog(self.w, self.postprefs)) self.file_menu.add_separator() self.file_menu.add_command(command=self.onexit) self.menubar.add_cascade(menu=self.file_menu) - self.edit_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) + self.edit_menu = tk.Menu(self.menubar, tearoff=False) self.edit_menu.add_command(accelerator='Ctrl+C', state=tk.DISABLED, command=self.copy) self.menubar.add_cascade(menu=self.edit_menu) - self.help_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) + self.help_menu = tk.Menu(self.menubar, tearoff=False) self.help_menu.add_command(command=self.help_general) self.help_menu.add_command(command=self.help_privacy) self.help_menu.add_command(command=self.help_releases) @@ -426,7 +427,7 @@ class AppWindow(object): if platform == 'win32': # Must be added after at least one "real" menu entry self.always_ontop = tk.BooleanVar(value=config.getint('always_ontop')) - self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) + self.system_menu = tk.Menu(self.menubar, name='system', tearoff=False) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system_menu.add_separator() self.system_menu.add_checkbutton(label=_('Always on top'), variable=self.always_ontop, @@ -864,7 +865,7 @@ class AppWindow(object): pass # Handle event(s) from the journal - def journal_event(self, event: str): # noqa: C901 + def journal_event(self, event): # noqa: C901 """ Handle a Journal event passed through event queue from monitor.py. From 5d8e2a80af2448e5530aae10706f37e58e5b94d6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 16:00:07 +0100 Subject: [PATCH 055/727] EDMarketConnector: noqa CCR001 Some of our code is just cognitively complex. --- EDMarketConnector.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index e3a87f5e..fdad0f9f 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -281,7 +281,7 @@ class AppWindow(object): EVENT_BUTTON = 4 EVENT_VIRTUAL = 35 - def __init__(self, master: tk.Tk): # noqa: C901 # TODO - can possibly factor something out + def __init__(self, master: tk.Tk): # noqa: C901, CCR001 # TODO - can possibly factor something out self.holdofftime = config.getint('querytime') + companion.holdoff @@ -672,7 +672,7 @@ class AppWindow(object): sort_keys=True, separators=(',', ': ')).encode('utf-8')) - def export_market_data(self, data: Mapping[str, Any]) -> bool: + def export_market_data(self, data: Mapping[str, Any]) -> bool: # noqa: CCR001 """ Export CAPI market data. @@ -707,7 +707,7 @@ class AppWindow(object): return True - def getandsend(self, event=None, retrying=False): # noqa: C901 + def getandsend(self, event=None, retrying=False): # noqa: C901, CCR001 """ Perform CAPI data retrieval and associated actions. @@ -830,7 +830,7 @@ class AppWindow(object): self.cooldown() # TODO: This has no users other than itself. - def retry_for_shipyard(self, tries): + def retry_for_shipyard(self, tries): # noqa: CCR001 """ Try again to get shipyard data and send to EDDN. @@ -865,7 +865,7 @@ class AppWindow(object): pass # Handle event(s) from the journal - def journal_event(self, event): # noqa: C901 + def journal_event(self, event): # noqa: C901, CCR001 """ Handle a Journal event passed through event queue from monitor.py. @@ -1212,7 +1212,7 @@ class AppWindow(object): self.destroy() self.__class__.showing = False - def save_raw(self): + def save_raw(self): # noqa: CCR001 """Save newly acquired CAPI data in the configured file.""" self.status['text'] = _('Fetching data...') self.w.update_idletasks() @@ -1348,7 +1348,7 @@ class AppWindow(object): self.blank_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) -def enforce_single_instance() -> None: +def enforce_single_instance() -> None: # noqa: CCR001 """ Ensure only one copy of the app is running under this user account. From 5b7876a22b74b7c3612d3cf9052471445d3e6bed Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 16:20:30 +0100 Subject: [PATCH 056/727] pre-commit: Try local flake8 --- .pre-commit-config.yaml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f78664..5c325e4b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,11 +14,20 @@ repos: # hooks: # - id: autopep8 -# flake8 --show-source -- repo: https://gitlab.com/pycqa/flake8 - rev: '' - hooks: - - id: flake8 +### # flake8 --show-source +### - repo: https://gitlab.com/pycqa/flake8 +### rev: '' +### hooks: +### - id: flake8 +# +# Try using local flake8 +- repo: local + hooks: + - id: flake8 + name: flake8 + entry: flake8 + language: system + types: [ python ] - repo: https://github.com/pre-commit/pygrep-hooks rev: '' From c1fdd270200615a582f4e76da62904fa2f699044 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 16:37:12 +0100 Subject: [PATCH 057/727] 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. --- EDMarketConnector.py | 101 ++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 68 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index fdad0f9f..1ea22601 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -14,7 +14,7 @@ from os import chdir, environ from os.path import dirname, isdir, join from sys import platform from time import localtime, strftime, time -from typing import TYPE_CHECKING, Any, Mapping +from typing import TYPE_CHECKING, Any, Mapping, Tuple, Union from constants import applongname, appname, protocolhandler_redirect @@ -447,7 +447,7 @@ class AppWindow(object): image=self.theme_icon, cursor='fleur', anchor=tk.W, compound=tk.LEFT) theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW) - self.drag_offset = None + self.drag_offset: Tuple[Union[None, int], Union[None, int]] = (None, None) theme_titlebar.bind('', self.drag_start) theme_titlebar.bind('', self.drag_continue) theme_titlebar.bind('', self.drag_end) @@ -548,7 +548,7 @@ class AppWindow(object): self.postprefs(False) # Companion login happens in callback from monitor - def postprefs(self, dologin=True): + def postprefs(self, dologin: bool = True): """Perform necessary actions after the Preferences dialog is applied.""" self.prefsdialog = None self.set_labels() # in case language has changed @@ -653,7 +653,7 @@ class AppWindow(object): self.cooldown() - def dump_capi_data(self, data): + def dump_capi_data(self, data: Mapping[str, Any]): """Dump CAPI data to file for examination.""" if isdir('dump'): system = data['lastSystem']['name'] @@ -707,7 +707,7 @@ class AppWindow(object): return True - def getandsend(self, event=None, retrying=False): # noqa: C901, CCR001 + def getandsend(self, event=None, retrying: bool = False): # noqa: C901, CCR001 """ Perform CAPI data retrieval and associated actions. @@ -829,41 +829,6 @@ class AppWindow(object): self.cooldown() - # TODO: This has no users other than itself. - def retry_for_shipyard(self, tries): # noqa: CCR001 - """ - Try again to get shipyard data and send to EDDN. - - Don't report errors if can't get or send the data. - """ - try: - data = companion.session.station() - if data['commander'].get('docked'): - if data.get('lastStarport', {}).get('ships'): - report = 'Success' - - else: - report = 'Failure' - - else: - report = 'Undocked!' - - logger.debug(f'Retry for shipyard - {report}') - if not data['commander'].get('docked'): - # might have un-docked while we were waiting for retry in which case station data is unreliable - pass - - elif (data.get('lastSystem', {}).get('name') == monitor.system and - data.get('lastStarport', {}).get('name') == monitor.station and - data.get('lastStarport', {}).get('ships', {}).get('shipyard_list')): - self.eddn.export_shipyard(data, monitor.is_beta) - - elif tries > 1: # bogus data - retry - self.w.after(int(SERVER_RETRY * 1000), lambda: self.retry_for_shipyard(tries - 1)) - - except Exception: - pass - # Handle event(s) from the journal def journal_event(self, event): # noqa: C901, CCR001 """ @@ -873,7 +838,7 @@ class AppWindow(object): :return: """ - def crewroletext(role): + def crewroletext(role: str) -> str: """ Return translated crew role. @@ -1004,7 +969,7 @@ class AppWindow(object): self.updater.setAutomaticUpdatesCheck(True) logger.info('Monitor: Enable WinSparkle automatic update checks') - def auth(self, event=None): + def auth(self, event=None) -> None: """ Handle Frontier auth callback. @@ -1033,7 +998,7 @@ class AppWindow(object): self.cooldown() - def dashboard_event(self, event): + def dashboard_event(self, event) -> None: """ Handle DashBoardEvent tk event. @@ -1048,7 +1013,7 @@ class AppWindow(object): if not config.getint('hotkey_mute'): hotkeymgr.play_bad() - def plugin_error(self, event=None): + def plugin_error(self, event=None) -> None: """Display asynchronous error from plugin.""" if plug.last_error.get('msg'): self.status['text'] = plug.last_error['msg'] @@ -1056,7 +1021,7 @@ class AppWindow(object): if not config.getint('hotkey_mute'): hotkeymgr.play_bad() - def shipyard_url(self, shipname): + def shipyard_url(self, shipname: str) -> str: """Despatch a ship URL to the configured handler.""" if not bool(config.getint("use_alt_shipyard_open")): return plug.invoke(config.get('shipyard_provider'), 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) @@ -1075,15 +1040,15 @@ class AppWindow(object): return f'file://localhost/{file_name}' - def system_url(self, system): + def system_url(self, system: str) -> str: """Despatch a system URL to the configured handler.""" return plug.invoke(config.get('system_provider'), 'EDSM', 'system_url', monitor.system) - def station_url(self, station): + def station_url(self, station: str) -> str: """Despatch a station URL to the configured handler.""" return plug.invoke(config.get('station_provider'), 'eddb', 'station_url', monitor.system, monitor.station) - def cooldown(self): + def cooldown(self) -> None: """Display and update the cooldown timer for 'Update' button.""" if time() < self.holdofftime: # Update button in main window @@ -1099,26 +1064,26 @@ class AppWindow(object): monitor.system and tk.NORMAL or tk.DISABLED) - def ontop_changed(self, event=None): + def ontop_changed(self, event=None) -> None: """Set main window 'on top' state as appropriate.""" config.set('always_ontop', self.always_ontop.get()) self.w.wm_attributes('-topmost', self.always_ontop.get()) - def copy(self, event=None): + def copy(self, event=None) -> None: """Copy system, and possible station, name to clipboard.""" if monitor.system: self.w.clipboard_clear() self.w.clipboard_append(monitor.station and f'{monitor.system},{monitor.station}' or monitor.system) - def help_general(self, event=None): + def help_general(self, event=None) -> None: """Open Wiki Help page in browser.""" webbrowser.open('https://github.com/EDCD/EDMarketConnector/wiki') - def help_privacy(self, event=None): + def help_privacy(self, event=None) -> None: """Open Wiki Privacy page in browser.""" webbrowser.open('https://github.com/EDCD/EDMarketConnector/wiki/Privacy-Policy') - def help_releases(self, event=None): + def help_releases(self, event=None) -> None: """Open Releases page in browser.""" webbrowser.open('https://github.com/EDCD/EDMarketConnector/releases') @@ -1127,7 +1092,7 @@ class AppWindow(object): showing = False - def __init__(self, parent): + def __init__(self, parent: tk.Tk): if self.__class__.showing: return @@ -1202,17 +1167,17 @@ class AppWindow(object): logger.info(f'Current version is {appversion}') - def apply(self): + def apply(self) -> None: """Close the window.""" self._destroy() - def _destroy(self): + def _destroy(self) -> None: """Set parent window's topmost appropriately as we close.""" self.parent.wm_attributes('-topmost', config.getint('always_ontop') and 1 or 0) self.destroy() self.__class__.showing = False - def save_raw(self): # noqa: CCR001 + def save_raw(self) -> None: # noqa: CCR001 """Save newly acquired CAPI data in the configured file.""" self.status['text'] = _('Fetching data...') self.w.update_idletasks() @@ -1252,7 +1217,7 @@ class AppWindow(object): logger.debug('"other" exception', exc_info=e) self.status['text'] = str(e) - def onexit(self, event=None): + def onexit(self, event=None) -> None: """Application shutdown procedure.""" # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 if platform != 'darwin' or self.w.winfo_rooty() > 0: @@ -1300,22 +1265,22 @@ class AppWindow(object): logger.info('Destroying app window...') self.w.destroy() - def drag_start(self, event): + def drag_start(self, event) -> None: """Initiate dragging the window.""" self.drag_offset = (event.x_root - self.w.winfo_rootx(), event.y_root - self.w.winfo_rooty()) - def drag_continue(self, event): + def drag_continue(self, event) -> None: """Continued handling of window drag.""" - if self.drag_offset: + if self.drag_offset[0]: offset_x = event.x_root - self.drag_offset[0] offset_y = event.y_root - self.drag_offset[1] self.w.geometry(f'+{offset_x:d}+{offset_y:d}') - def drag_end(self, event): + def drag_end(self, event) -> None: """Handle end of window dragging.""" - self.drag_offset = None + self.drag_offset = (None, None) - def oniconify(self, event=None): + def oniconify(self, event=None) -> None: """Handle iconification of the application.""" self.w.overrideredirect(0) # Can't iconize while overrideredirect self.w.iconify() @@ -1324,12 +1289,12 @@ class AppWindow(object): theme.active = None # So theme will be re-applied on map # TODO: Confirm this is unused and remove. - def onmap(self, event=None): + def onmap(self, event=None) -> None: """Perform a now unused function.""" if event.widget == self.w: theme.apply(self.w) - def onenter(self, event=None): + def onenter(self, event=None) -> None: """Handle when our window gains focus.""" # TODO: This assumes that 1) transparent is at least 2, 2) there are # no new themes added after that. @@ -1338,7 +1303,7 @@ class AppWindow(object): self.blank_menubar.grid_remove() self.theme_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) - def onleave(self, event=None): + def onleave(self, event=None) -> None: """Handle when our window loses focus.""" # TODO: This assumes that 1) transparent is at least 2, 2) there are # no new themes added after that. @@ -1416,7 +1381,7 @@ def enforce_single_instance() -> None: # noqa: CCR001 EnumWindows(enumwindowsproc, 0) -def test_logging(): +def test_logging() -> None: """Simple test of top level logging.""" logger.debug('Test from EDMarketConnector.py top-level test_logging()') From e5e0eb037302aa50807aa517b6fa9fff482f4ea7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 17:06:11 +0100 Subject: [PATCH 058/727] EDMarketConnector: Revert to tearoff=tk.FALSE And added `# type: ignore` comments. This is a mess. On the tkinter side it *is* an int, default 0. But enough python stuff has assumed it's a bool for typeshed to define that tearoff should be. It doesn't match, mypy complains. --- EDMarketConnector.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 1ea22601..a2d0a37d 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -406,17 +406,17 @@ class AppWindow(object): self.w.resizable(tk.FALSE, tk.FALSE) # Can't be only resizable on one axis else: # win32 or linux - self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=False) + self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) # type: ignore self.file_menu.add_command(command=lambda: stats.StatsDialog(self)) self.file_menu.add_command(command=self.save_raw) self.file_menu.add_command(command=lambda: prefs.PreferencesDialog(self.w, self.postprefs)) self.file_menu.add_separator() self.file_menu.add_command(command=self.onexit) self.menubar.add_cascade(menu=self.file_menu) - self.edit_menu = tk.Menu(self.menubar, tearoff=False) + self.edit_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) # type: ignore self.edit_menu.add_command(accelerator='Ctrl+C', state=tk.DISABLED, command=self.copy) self.menubar.add_cascade(menu=self.edit_menu) - self.help_menu = tk.Menu(self.menubar, tearoff=False) + self.help_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) # type: ignore self.help_menu.add_command(command=self.help_general) self.help_menu.add_command(command=self.help_privacy) self.help_menu.add_command(command=self.help_releases) @@ -427,7 +427,7 @@ class AppWindow(object): if platform == 'win32': # Must be added after at least one "real" menu entry self.always_ontop = tk.BooleanVar(value=config.getint('always_ontop')) - self.system_menu = tk.Menu(self.menubar, name='system', tearoff=False) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system_menu.add_separator() self.system_menu.add_checkbutton(label=_('Always on top'), variable=self.always_ontop, From 07c7639345693a1cb3b8a88a5a89672a2b71137a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 17:12:45 +0100 Subject: [PATCH 059/727] EDMarketConnector: Switch to Optional[int] rather than Union... --- EDMarketConnector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index a2d0a37d..02976bd9 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -14,7 +14,7 @@ from os import chdir, environ from os.path import dirname, isdir, join from sys import platform from time import localtime, strftime, time -from typing import TYPE_CHECKING, Any, Mapping, Tuple, Union +from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple from constants import applongname, appname, protocolhandler_redirect @@ -447,7 +447,7 @@ class AppWindow(object): image=self.theme_icon, cursor='fleur', anchor=tk.W, compound=tk.LEFT) theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW) - self.drag_offset: Tuple[Union[None, int], Union[None, int]] = (None, None) + self.drag_offset: Tuple[Optional[int], Optional[int]] = (None, None) theme_titlebar.bind('', self.drag_start) theme_titlebar.bind('', self.drag_continue) theme_titlebar.bind('', self.drag_end) From 4ac9e9010e2f4d59a246cf344fdbec7e6307d2c6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 17:15:44 +0100 Subject: [PATCH 060/727] EDMarketConnector: Two minor cleanups. journal_event & dashboard_event * journal_event() annotate the noqa complexity comment. * dashboard_event() convert to 'bail early' to save indentiation. --- EDMarketConnector.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 02976bd9..4d466ee3 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -829,8 +829,7 @@ class AppWindow(object): self.cooldown() - # Handle event(s) from the journal - def journal_event(self, event): # noqa: C901, CCR001 + def journal_event(self, event): # noqa: C901, CCR001 # Currently not easily broken up. """ Handle a Journal event passed through event queue from monitor.py. @@ -1004,14 +1003,16 @@ class AppWindow(object): Event is sent by code in dashboard.py. """ + if not dashboard.status: + return + entry = dashboard.status - if entry: - # Currently we don't do anything with these events - err = plug.notify_dashboard_entry(monitor.cmdr, monitor.is_beta, entry) - if err: - self.status['text'] = err - if not config.getint('hotkey_mute'): - hotkeymgr.play_bad() + # Currently we don't do anything with these events + err = plug.notify_dashboard_entry(monitor.cmdr, monitor.is_beta, entry) + if err: + self.status['text'] = err + if not config.getint('hotkey_mute'): + hotkeymgr.play_bad() def plugin_error(self, event=None) -> None: """Display asynchronous error from plugin.""" From 6ae6efaee9d6089aff9db4a0ad5593b29bd5283a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 17:20:05 +0100 Subject: [PATCH 061/727] EDMarketConnector: Annotate save_raw() complexity noqa --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 4d466ee3..fc95a2ff 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1178,7 +1178,7 @@ class AppWindow(object): self.destroy() self.__class__.showing = False - def save_raw(self) -> None: # noqa: CCR001 + def save_raw(self) -> None: # noqa: CCR001 # Not easily broken up. """Save newly acquired CAPI data in the configured file.""" self.status['text'] = _('Fetching data...') self.w.update_idletasks() From b2629286b4667ce7e81af889a0683cd72afa5ebf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 15:49:32 +0100 Subject: [PATCH 062/727] config.py: top-level docstring, import order, minor edits --- config.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 1e9340c9..d60fe841 100644 --- a/config.py +++ b/config.py @@ -1,9 +1,17 @@ +""" +Code dealing with the configuration of the program. + +On Windows this uses the Registry to store values in a flat manner. +Linux uses a file, but for commonality it's still a flat data structure. +""" + import numbers import sys import warnings from os import getenv, makedirs, mkdir, pardir -from os.path import expanduser, dirname, exists, isdir, join, normpath +from os.path import dirname, expanduser, isdir, join, normpath from sys import platform + import semantic_version from constants import applongname, appname @@ -13,7 +21,7 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '4.2.0-beta1' #-rc1+a872b5f' +appversion = '4.2.0-beta1' # -rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) copyright = u'© 2015-2019 Jonathan Harris, 2020-2021 EDCD' @@ -22,10 +30,10 @@ update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases update_interval = 8*60*60 -if platform=='darwin': +if platform == 'darwin': from Foundation import NSBundle, NSUserDefaults, NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSDocumentDirectory, NSLibraryDirectory, NSUserDomainMask -elif platform=='win32': +elif platform == 'win32': import ctypes from ctypes.wintypes import * import uuid From c3150dae76565614cffbb927e73d1b303541ec16 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 15:58:52 +0100 Subject: [PATCH 063/727] config.py: More import clean & misc. --- config.py | 74 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/config.py b/config.py index d60fe841..aa49f3cc 100644 --- a/config.py +++ b/config.py @@ -31,17 +31,20 @@ update_interval = 8*60*60 if platform == 'darwin': - from Foundation import NSBundle, NSUserDefaults, NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSDocumentDirectory, NSLibraryDirectory, NSUserDomainMask + from Foundation import ( + NSApplicationSupportDirectory, NSBundle, NSDocumentDirectory, NSSearchPathForDirectoriesInDomains, + NSUserDefaults, NSUserDomainMask + ) elif platform == 'win32': import ctypes - from ctypes.wintypes import * import uuid + from ctypes.wintypes import DWORD, HANDLE, LONG, HKEY, LPCWSTR, LPCVOID - FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') + FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') - FOLDERID_Profile = uuid.UUID('{5E6C858F-0E22-4760-9AFE-EA3317B67173}') - FOLDERID_SavedGames = uuid.UUID('{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}') + FOLDERID_Profile = uuid.UUID('{5E6C858F-0E22-4760-9AFE-EA3317B67173}') + FOLDERID_SavedGames = uuid.UUID('{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}') SHGetKnownFolderPath = ctypes.windll.shell32.SHGetKnownFolderPath SHGetKnownFolderPath.argtypes = [ctypes.c_char_p, DWORD, HANDLE, ctypes.POINTER(ctypes.c_wchar_p)] @@ -50,17 +53,19 @@ elif platform == 'win32': CoTaskMemFree.argtypes = [ctypes.c_void_p] # winreg in Python <= 3.7.4 handles REG_MULTI_SZ incorrectly, so do this instead. https://bugs.python.org/issue32587 - HKEY_CURRENT_USER = 0x80000001 - KEY_ALL_ACCESS = 0x000F003F - REG_CREATED_NEW_KEY = 0x00000001 + HKEY_CURRENT_USER = 0x80000001 + KEY_ALL_ACCESS = 0x000F003F + REG_CREATED_NEW_KEY = 0x00000001 REG_OPENED_EXISTING_KEY = 0x00000002 - REG_SZ = 1 + REG_SZ = 1 REG_DWORD = 4 REG_MULTI_SZ = 7 RegCreateKeyEx = ctypes.windll.advapi32.RegCreateKeyExW RegCreateKeyEx.restype = LONG - RegCreateKeyEx.argtypes = [HKEY, LPCWSTR, DWORD, LPCVOID, DWORD, DWORD, LPCVOID, ctypes.POINTER(HKEY), ctypes.POINTER(DWORD)] + RegCreateKeyEx.argtypes = [ + HKEY, LPCWSTR, DWORD, LPCVOID, DWORD, DWORD, LPCVOID, ctypes.POINTER(HKEY), ctypes.POINTER(DWORD) + ] RegOpenKeyEx = ctypes.windll.advapi32.RegOpenKeyExW RegOpenKeyEx.restype = LONG @@ -90,39 +95,40 @@ elif platform == 'win32': RegDeleteValue.restype = LONG RegDeleteValue.argtypes = [HKEY, LPCWSTR] - def KnownFolderPath(guid): + def known_folder_path(guid): + """Look up a Windows GUID to actual folder path name.""" buf = ctypes.c_wchar_p() if SHGetKnownFolderPath(ctypes.create_string_buffer(guid.bytes_le), 0, 0, ctypes.byref(buf)): return None - retval = buf.value # copy data - CoTaskMemFree(buf) # and free original + retval = buf.value # copy data + CoTaskMemFree(buf) # and free original return retval - -elif platform=='linux': +elif platform == 'linux': import codecs from configparser import RawConfigParser class Config(object): + """Object that holds all configuration data.""" - OUT_MKT_EDDN = 1 - # OUT_MKT_BPC = 2 # No longer supported - OUT_MKT_TD = 4 - OUT_MKT_CSV = 8 - OUT_SHIP = 16 - # OUT_SHIP_EDS = 16 # Replaced by OUT_SHIP - # OUT_SYS_FILE = 32 # No longer supported - # OUT_STAT = 64 # No longer available + OUT_MKT_EDDN = 1 + # OUT_MKT_BPC = 2 # No longer supported + OUT_MKT_TD = 4 + OUT_MKT_CSV = 8 + OUT_SHIP = 16 + # OUT_SHIP_EDS = 16 # Replaced by OUT_SHIP + # OUT_SYS_FILE = 32 # No longer supported + # OUT_STAT = 64 # No longer available # OUT_SHIP_CORIOLIS = 128 # Replaced by OUT_SHIP - OUT_STATION_ANY = OUT_MKT_EDDN|OUT_MKT_TD|OUT_MKT_CSV - # OUT_SYS_EDSM = 256 # Now a plugin - # OUT_SYS_AUTO = 512 # Now always automatic - OUT_MKT_MANUAL = 1024 - OUT_SYS_EDDN = 2048 - OUT_SYS_DELAY = 4096 + OUT_STATION_ANY = OUT_MKT_EDDN|OUT_MKT_TD|OUT_MKT_CSV + # OUT_SYS_EDSM = 256 # Now a plugin + # OUT_SYS_AUTO = 512 # Now always automatic + OUT_MKT_MANUAL = 1024 + OUT_SYS_EDDN = 2048 + OUT_SYS_DELAY = 4096 - if platform=='darwin': + if platform == 'darwin': def __init__(self): self.__in_shutdown = False # Is the application currently shutting down ? @@ -220,7 +226,7 @@ class Config(object): self.__in_shutdown = False # Is the application currently shutting down ? self.__auth_force_localserver = False # Should we use localhost for auth callback ? - self.app_dir = join(KnownFolderPath(FOLDERID_LocalAppData), appname) + self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) if not isdir(self.app_dir): mkdir(self.app_dir) @@ -231,9 +237,9 @@ class Config(object): self.internal_plugin_dir = join(dirname(getattr(sys, 'frozen', False) and sys.executable or __file__), u'plugins') # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 - self.home = KnownFolderPath(FOLDERID_Profile) or u'\\' + self.home = known_folder_path(FOLDERID_Profile) or u'\\' - journaldir = KnownFolderPath(FOLDERID_SavedGames) + journaldir = known_folder_path(FOLDERID_SavedGames) self.default_journal_dir = journaldir and join(journaldir, 'Frontier Developments', 'Elite Dangerous') or None self.respath = dirname(getattr(sys, 'frozen', False) and sys.executable or __file__) @@ -260,7 +266,7 @@ class Config(object): RegCloseKey(sparklekey) if not self.get('outdir') or not isdir(self.get('outdir')): - self.set('outdir', KnownFolderPath(FOLDERID_Documents) or self.home) + self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) def get(self, key): typ = DWORD() From 07fd4dc6341ec7b507af1129c4ffc27e332ab1c6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 16:01:47 +0100 Subject: [PATCH 064/727] config.py: ctypes import order --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index aa49f3cc..be655896 100644 --- a/config.py +++ b/config.py @@ -39,7 +39,7 @@ if platform == 'darwin': elif platform == 'win32': import ctypes import uuid - from ctypes.wintypes import DWORD, HANDLE, LONG, HKEY, LPCWSTR, LPCVOID + from ctypes.wintypes import DWORD, HANDLE, HKEY, LONG, LPCVOID, LPCWSTR FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') From fcb7685d71a16ee84cd612d31b951540462d935b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 11:56:40 +0100 Subject: [PATCH 065/727] config.py: darwin Config class code cleanup # Conflicts: # config.py --- config.py | 77 +++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/config.py b/config.py index be655896..492ad396 100644 --- a/config.py +++ b/config.py @@ -11,6 +11,7 @@ import warnings from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform +from typing import Union import semantic_version @@ -121,20 +122,19 @@ class Config(object): # OUT_SYS_FILE = 32 # No longer supported # OUT_STAT = 64 # No longer available # OUT_SHIP_CORIOLIS = 128 # Replaced by OUT_SHIP - OUT_STATION_ANY = OUT_MKT_EDDN|OUT_MKT_TD|OUT_MKT_CSV - # OUT_SYS_EDSM = 256 # Now a plugin - # OUT_SYS_AUTO = 512 # Now always automatic + OUT_STATION_ANY = OUT_MKT_EDDN | OUT_MKT_TD | OUT_MKT_CSV + # OUT_SYS_EDSM = 256 # Now a plugin + # OUT_SYS_AUTO = 512 # Now always automatic OUT_MKT_MANUAL = 1024 OUT_SYS_EDDN = 2048 OUT_SYS_DELAY = 4096 - if platform == 'darwin': + if platform == 'darwin': # noqa: C901 # It's gating *all* the functions def __init__(self): - self.__in_shutdown = False # Is the application currently shutting down ? - self.__auth_force_localserver = False # Should we use localhost for auth callback ? - - self.app_dir = join(NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname) + self.app_dir = join( + NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname + ) if not isdir(self.app_dir): mkdir(self.app_dir) @@ -142,67 +142,66 @@ class Config(object): if not isdir(self.plugin_dir): mkdir(self.plugin_dir) - self.internal_plugin_dir = getattr(sys, 'frozen', False) and normpath(join(dirname(sys.executable), pardir, 'Library', 'plugins')) or join(dirname(__file__), 'plugins') + if getattr(sys, 'frozen', False): + self.internal_plugin_dir = normpath(join(dirname(sys.executable), pardir, 'Library', 'plugins')) + self.respath = normpath(join(dirname(sys.executable), pardir, 'Resources')) + self.identifier = NSBundle.mainBundle().bundleIdentifier() - self.default_journal_dir = join(NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], 'Frontier Developments', 'Elite Dangerous') + else: + self.internal_plugin_dir = join(dirname(__file__), 'plugins') + self.respath = dirname(__file__) + # Don't use Python's settings if interactive + self.identifier = f'uk.org.marginal.{appname.lower()}' + NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier + self.default_journal_dir = join( + NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], + 'Frontier Developments', + 'Elite Dangerous' + ) self.home = expanduser('~') - self.respath = getattr(sys, 'frozen', False) and normpath(join(dirname(sys.executable), pardir, 'Resources')) or dirname(__file__) - - if not getattr(sys, 'frozen', False): - # Don't use Python's settings if interactive - self.identifier = 'uk.org.marginal.%s' % appname.lower() - NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier - else: - self.identifier = NSBundle.mainBundle().bundleIdentifier() self.defaults = NSUserDefaults.standardUserDefaults() - self.settings = dict(self.defaults.persistentDomainForName_(self.identifier) or {}) # make writeable + self.settings = dict(self.defaults.persistentDomainForName_(self.identifier) or {}) # make writeable # Check out_dir exists if not self.get('outdir') or not isdir(self.get('outdir')): self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) - def get(self, key): + def get(self, key: str) -> Union[None, list, str]: + """Look up a non-int configuration value.""" val = self.settings.get(key) if val is None: return None elif isinstance(val, str): return str(val) elif hasattr(val, '__iter__'): - return list(val) # make writeable + return list(val) # make writeable else: return None - def get_str(self, key): - return self.get(key) - - def get_list(self, key): - return self.get(key) - - def get_bool(self, key): - return self.get(key) - - def getint(self, key): + def getint(self, key: str) -> int: + """Look up an integer configuraiton value.""" try: - return int(self.settings.get(key, 0)) # should already be int, but check by casting + return int(self.settings.get(key, 0)) # should already be int, but check by casting except: return 0 - def get_int(self, key): - return self.getint(key) - - def set(self, key, val): + def set(self, key: str, val: Union[int, str]) -> None: + """Set value on the specified configuration key.""" self.settings[key] = val - def delete(self, key): + def delete(self, key: str) -> None: + """Delete the specified configuration key.""" self.settings.pop(key, None) - def save(self): + def save(self) -> None: + """Save current configuration to disk.""" self.defaults.setPersistentDomain_forName_(self.settings, self.identifier) self.defaults.synchronize() - def close(self): + def close(self) -> None: + """Close the configuration.""" self.save() self.defaults = None From 854c79c0706748d0f8da47b1fd3469bab8d8e0ce Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 16:18:58 +0100 Subject: [PATCH 066/727] config.py: Log exception type from darwin getint() * Also sets up `logger`. --- config.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 492ad396..47c516eb 100644 --- a/config.py +++ b/config.py @@ -5,6 +5,7 @@ On Windows this uses the Registry to store values in a flat manner. Linux uses a file, but for commonality it's still a flat data structure. """ +import logging import numbers import sys import warnings @@ -30,6 +31,11 @@ copyright = u'© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' update_interval = 8*60*60 +if getenv("EDMC_NO_UI"): + logger = logging.getLogger(appcmdname) + +else: + logger = logging.getLogger(appname) if platform == 'darwin': from Foundation import ( @@ -184,7 +190,8 @@ class Config(object): """Look up an integer configuraiton value.""" try: return int(self.settings.get(key, 0)) # should already be int, but check by casting - except: + except Exception as e: + logger.debug('The exception type is ...', exc_info=e) return 0 def set(self, key: str, val: Union[int, str]) -> None: From b7f41796c9a888e646e836faa5610c8fe31bde16 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:51:12 +0000 Subject: [PATCH 067/727] config.py: win32 Config class cleanup --- config.py | 148 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 102 insertions(+), 46 deletions(-) diff --git a/config.py b/config.py index 47c516eb..20cd38c7 100644 --- a/config.py +++ b/config.py @@ -175,7 +175,7 @@ class Config(object): self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) def get(self, key: str) -> Union[None, list, str]: - """Look up a non-int configuration value.""" + """Look up a string configuration value.""" val = self.settings.get(key) if val is None: return None @@ -187,7 +187,7 @@ class Config(object): return None def getint(self, key: str) -> int: - """Look up an integer configuraiton value.""" + """Look up an integer configuration value.""" try: return int(self.settings.get(key, 0)) # should already be int, but check by casting except Exception as e: @@ -212,26 +212,9 @@ class Config(object): self.save() self.defaults = None - def set_shutdown(self): - self.__in_shutdown = True - - @property - def shutting_down(self) -> bool: - return self.__in_shutdown - - def set_auth_force_localserver(self): - self.__auth_force_localserver = True - - @property - def auth_force_localserver(self) -> bool: - return self.__auth_force_localserver - - elif platform=='win32': + elif platform == 'win32': def __init__(self): - self.__in_shutdown = False # Is the application currently shutting down ? - self.__auth_force_localserver = False # Should we use localhost for auth callback ? - self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) if not isdir(self.app_dir): mkdir(self.app_dir) @@ -240,82 +223,155 @@ class Config(object): if not isdir(self.plugin_dir): mkdir(self.plugin_dir) - self.internal_plugin_dir = join(dirname(getattr(sys, 'frozen', False) and sys.executable or __file__), u'plugins') + if getattr(sys, 'frozen', False): + self.internal_plugin_dir = join(dirname(sys.executable), 'plugins') + self.respath = dirname(sys.executable) + + else: + self.internal_plugin_dir = join(dirname(__file__), 'plugins') + self.respath = dirname(__file__) # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 - self.home = known_folder_path(FOLDERID_Profile) or u'\\' + self.home = known_folder_path(FOLDERID_Profile) or r'\\' journaldir = known_folder_path(FOLDERID_SavedGames) - self.default_journal_dir = journaldir and join(journaldir, 'Frontier Developments', 'Elite Dangerous') or None + if journaldir: + self.default_journal_dir = join(journaldir, 'Frontier Developments', 'Elite Dangerous') - self.respath = dirname(getattr(sys, 'frozen', False) and sys.executable or __file__) + else: + self.default_journal_dir = None self.identifier = applongname - self.hkey = HKEY() disposition = DWORD() - if RegCreateKeyEx(HKEY_CURRENT_USER, r'Software\Marginal\EDMarketConnector', 0, None, 0, KEY_ALL_ACCESS, None, ctypes.byref(self.hkey), ctypes.byref(disposition)): + if RegCreateKeyEx( + HKEY_CURRENT_USER, + r'Software\Marginal\EDMarketConnector', + 0, + None, + 0, + KEY_ALL_ACCESS, + None, + ctypes.byref(self.hkey), + ctypes.byref(disposition) + ): raise Exception() # set WinSparkle defaults - https://github.com/vslavik/winsparkle/wiki/Registry-Settings edcdhkey = HKEY() - if RegCreateKeyEx(HKEY_CURRENT_USER, r'Software\EDCD\EDMarketConnector', 0, None, 0, KEY_ALL_ACCESS, None, ctypes.byref(edcdhkey), ctypes.byref(disposition)): + if RegCreateKeyEx( + HKEY_CURRENT_USER, + r'Software\EDCD\EDMarketConnector', + 0, + None, + 0, + KEY_ALL_ACCESS, + None, + ctypes.byref(edcdhkey), + ctypes.byref(disposition) + ): raise Exception() sparklekey = HKEY() - if not RegCreateKeyEx(edcdhkey, 'WinSparkle', 0, None, 0, KEY_ALL_ACCESS, None, ctypes.byref(sparklekey), ctypes.byref(disposition)): + if not RegCreateKeyEx( + edcdhkey, + 'WinSparkle', + 0, + None, + 0, + KEY_ALL_ACCESS, + None, + ctypes.byref(sparklekey), + ctypes.byref(disposition) + ): if disposition.value == REG_CREATED_NEW_KEY: buf = ctypes.create_unicode_buffer('1') - RegSetValueEx(sparklekey, 'CheckForUpdates', 0, 1, buf, len(buf)*2) + RegSetValueEx(sparklekey, 'CheckForUpdates', 0, 1, buf, len(buf) * 2) + buf = ctypes.create_unicode_buffer(str(update_interval)) - RegSetValueEx(sparklekey, 'UpdateInterval', 0, 1, buf, len(buf)*2) + RegSetValueEx(sparklekey, 'UpdateInterval', 0, 1, buf, len(buf) * 2) RegCloseKey(sparklekey) if not self.get('outdir') or not isdir(self.get('outdir')): self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) def get(self, key): - typ = DWORD() - size = DWORD() - if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), None, ctypes.byref(size)) or typ.value not in [REG_SZ, REG_MULTI_SZ]: + """Look up a string configuration value.""" + key_type = DWORD() + key_size = DWORD() + # Only strings are handled here. + if ( + key_type.value not in [REG_SZ, REG_MULTI_SZ] + or RegQueryValueEx( + self.hkey, + key, + 0, + ctypes.byref(key_type), + None, + ctypes.byref(key_size) + ) + ): return None - buf = ctypes.create_unicode_buffer(int(size.value / 2)) - if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), buf, ctypes.byref(size)): + + buf = ctypes.create_unicode_buffer(int(key_size.value / 2)) + if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(key_type), buf, ctypes.byref(key_size)): return None - elif typ.value == REG_MULTI_SZ: - return [x for x in ctypes.wstring_at(buf, len(buf)-2).split(u'\x00')] + + elif key_type.value == REG_MULTI_SZ: + return list(ctypes.wstring_at(buf, len(buf)-2).split(u'\x00')) + else: return str(buf.value) def getint(self, key): - typ = DWORD() - size = DWORD(4) - val = DWORD() - if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), ctypes.byref(val), ctypes.byref(size)) or typ.value != REG_DWORD: + """Look up an integer configuration value.""" + key_type = DWORD() + key_size = DWORD(4) + key_val = DWORD() + if ( + key_type.value != REG_DWORD + or RegQueryValueEx( + self.hkey, + key, + 0, + ctypes.byref(key_type), + ctypes.byref(key_val), + ctypes.byref(key_size) + ) + ): return 0 + else: - return val.value + return key_val.value def set(self, key, val): + """Set value on the specified configuration key.""" if isinstance(val, str): buf = ctypes.create_unicode_buffer(val) RegSetValueEx(self.hkey, key, 0, REG_SZ, buf, len(buf)*2) + elif isinstance(val, numbers.Integral): RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4) - elif hasattr(val, '__iter__'): # iterable - stringval = u'\x00'.join([str(x) or u' ' for x in val] + [u'']) # null terminated non-empty strings - buf = ctypes.create_unicode_buffer(stringval) + + elif hasattr(val, '__iter__'): + # null terminated non-empty strings + string_val = u'\x00'.join([str(x) or u' ' for x in val] + [u'']) + buf = ctypes.create_unicode_buffer(string_val) RegSetValueEx(self.hkey, key, 0, REG_MULTI_SZ, buf, len(buf)*2) + else: raise NotImplementedError() def delete(self, key): + """Delete the specified configuration key.""" RegDeleteValue(self.hkey, key) def save(self): - pass # Redundant since registry keys are written immediately + """Save current configuration to disk.""" + pass # Redundant since registry keys are written immediately def close(self): + """Close the configuration.""" RegCloseKey(self.hkey) self.hkey = None From 93dc1a988a764a2163d90d3141e88c1921f9b70c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:51:53 +0000 Subject: [PATCH 068/727] config.py: linux Config class & overall typing * This changes the test in set() from hasattr(val, '__iter__') to isinstance(val, list) as the passed values *should* be lists for that case. --- config.py | 94 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/config.py b/config.py index 20cd38c7..8563e9d9 100644 --- a/config.py +++ b/config.py @@ -12,7 +12,7 @@ import warnings from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import Union +from typing import Iterable, Union import semantic_version @@ -194,7 +194,7 @@ class Config(object): logger.debug('The exception type is ...', exc_info=e) return 0 - def set(self, key: str, val: Union[int, str]) -> None: + def set(self, key: str, val: Union[int, str, list]) -> None: """Set value on the specified configuration key.""" self.settings[key] = val @@ -295,7 +295,7 @@ class Config(object): if not self.get('outdir') or not isdir(self.get('outdir')): self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) - def get(self, key): + def get(self, key: str) -> Union[None, list, str]: """Look up a string configuration value.""" key_type = DWORD() key_size = DWORD() @@ -323,7 +323,7 @@ class Config(object): else: return str(buf.value) - def getint(self, key): + def getint(self, key: str) -> int: """Look up an integer configuration value.""" key_type = DWORD() key_size = DWORD(4) @@ -344,7 +344,7 @@ class Config(object): else: return key_val.value - def set(self, key, val): + def set(self, key: str, val: Union[int, str, list]) -> None: """Set value on the specified configuration key.""" if isinstance(val, str): buf = ctypes.create_unicode_buffer(val) @@ -353,7 +353,7 @@ class Config(object): elif isinstance(val, numbers.Integral): RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4) - elif hasattr(val, '__iter__'): + elif isinstance(val, list): # null terminated non-empty strings string_val = u'\x00'.join([str(x) or u' ' for x in val] + [u'']) buf = ctypes.create_unicode_buffer(string_val) @@ -362,35 +362,20 @@ class Config(object): else: raise NotImplementedError() - def delete(self, key): + def delete(self, key: str) -> None: """Delete the specified configuration key.""" RegDeleteValue(self.hkey, key) - def save(self): + def save(self) -> None: """Save current configuration to disk.""" pass # Redundant since registry keys are written immediately - def close(self): + def close(self) -> None: """Close the configuration.""" RegCloseKey(self.hkey) self.hkey = None - def set_shutdown(self): - self.__in_shutdown = True - - @property - def shutting_down(self) -> bool: - return self.__in_shutdown - - def set_auth_force_localserver(self): - self.__auth_force_localserver = True - - @property - def auth_force_localserver(self) -> bool: - return self.__auth_force_localserver - - elif platform=='linux': - + elif platform == 'linux': SECTION = 'config' def __init__(self): @@ -407,65 +392,77 @@ class Config(object): mkdir(self.plugin_dir) self.internal_plugin_dir = join(dirname(__file__), 'plugins') - self.default_journal_dir = None - self.home = expanduser('~') - self.respath = dirname(__file__) + self.identifier = f'uk.org.marginal.{appname.lower()}' - self.identifier = 'uk.org.marginal.%s' % appname.lower() - - self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname) + self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, f'{appname}.ini') if not isdir(dirname(self.filename)): makedirs(dirname(self.filename)) - self.config = RawConfigParser(comment_prefixes = ('#',)) + self.config = RawConfigParser(comment_prefixes=('#',)) try: with codecs.open(self.filename, 'r') as h: self.config.read_file(h) - except: + + except Exception as e: + logger.debug('config section not yet present', exc_info=e) self.config.add_section(self.SECTION) if not self.get('outdir') or not isdir(self.get('outdir')): self.set('outdir', expanduser('~')) - def get(self, key): + def get(self, key: str) -> Union[None, list, str]: + """Look up a string configuration value.""" try: val = self.config.get(self.SECTION, key) - if u'\n' in val: # list - # ConfigParser drops the last entry if blank, so we add a spurious ';' entry in set() and remove it here + if u'\n' in val: # list + # ConfigParser drops the last entry if blank, + # so we add a spurious ';' entry in set() and remove it here assert val.split('\n')[-1] == ';', val.split('\n') return [self._unescape(x) for x in val.split(u'\n')[:-1]] else: return self._unescape(val) - except: + + except Exception as e: + logger.debug('And the exception type is...', exc_info=e) return None - def getint(self, key): + def getint(self, key: str) -> int: + """Look up an integer configuration value.""" try: return self.config.getint(self.SECTION, key) - except: + + except Exception as e: + logger.debug('And the exception type is...', exc_info=e) return 0 - def set(self, key, val): + def set(self, key: str, val: Union[int, str, list]) -> None: + """Set value on the specified configuration key.""" if isinstance(val, bool): self.config.set(self.SECTION, key, val and '1' or '0') + elif isinstance(val, str) or isinstance(val, numbers.Integral): self.config.set(self.SECTION, key, self._escape(val)) - elif hasattr(val, '__iter__'): # iterable + + elif isinstance(val, list): self.config.set(self.SECTION, key, u'\n'.join([self._escape(x) for x in val] + [u';'])) + else: raise NotImplementedError() - def delete(self, key): + def delete(self, key: str) -> None: + """Delete the specified configuration key.""" self.config.remove_option(self.SECTION, key) - def save(self): + def save(self) -> None: + """Save current configuration to disk.""" with codecs.open(self.filename, 'w', 'utf-8') as h: self.config.write(h) - def close(self): + def close(self) -> None: + """Close the configuration.""" self.save() self.config = None @@ -484,9 +481,11 @@ class Config(object): return self.__auth_force_localserver def _escape(self, val): + """Escape a string for storage.""" return str(val).replace(u'\\', u'\\\\').replace(u'\n', u'\\n').replace(u';', u'\\;') def _unescape(self, val): + """Un-escape a string from storage.""" chars = list(val) i = 0 while i < len(chars): @@ -497,21 +496,24 @@ class Config(object): i += 1 return u''.join(chars) - else: # ??? - + else: def __init__(self): raise NotImplementedError('Implement me') # Common def get_password(self, account): + """Legacy password retrieval.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning) def set_password(self, account, password): + """Legacy password setting.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning) def delete_password(self, account): + """Legacy password deletion.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning) + # singleton config = Config() From f356d9c1d1ec585d9bfc0a51b2eb9bb6696a9a77 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 17:25:41 +0100 Subject: [PATCH 069/727] config.py: No need for typing.Iterable --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 8563e9d9..bbd4c3b9 100644 --- a/config.py +++ b/config.py @@ -12,7 +12,7 @@ import warnings from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import Iterable, Union +from typing import Union import semantic_version From 0274c98e50f0cf90ade3675d6fa7d031ff5a44fa Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Oct 2020 17:27:13 +0100 Subject: [PATCH 070/727] config.py: Convert darwin test to isinstance(val, list) as well --- config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index bbd4c3b9..a6574652 100644 --- a/config.py +++ b/config.py @@ -179,10 +179,13 @@ class Config(object): val = self.settings.get(key) if val is None: return None + elif isinstance(val, str): return str(val) - elif hasattr(val, '__iter__'): + + elif isinstance(val, list): return list(val) # make writeable + else: return None From cb795b22307c16e2049eecc2c8084b8c8a9a0a94 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:52:31 +0000 Subject: [PATCH 071/727] config.py: Remove u-prefix from strings. More specific Exceptions * u-prefix is un-necessary, remove it. * We should get ValueError in some cases, so catch it first. * Change debug log for if linux config file not yet present. --- config.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index a6574652..9e4fa377 100644 --- a/config.py +++ b/config.py @@ -26,7 +26,7 @@ appcmdname = 'EDMC' appversion = '4.2.0-beta1' # -rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) -copyright = u'© 2015-2019 Jonathan Harris, 2020-2021 EDCD' +copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' update_interval = 8*60*60 @@ -193,6 +193,11 @@ class Config(object): """Look up an integer configuration value.""" try: return int(self.settings.get(key, 0)) # should already be int, but check by casting + + except ValueError as e: + logger.error(f"Failed to int({key=})", exc_info=e) + return 0 + except Exception as e: logger.debug('The exception type is ...', exc_info=e) return 0 @@ -321,7 +326,7 @@ class Config(object): return None elif key_type.value == REG_MULTI_SZ: - return list(ctypes.wstring_at(buf, len(buf)-2).split(u'\x00')) + return list(ctypes.wstring_at(buf, len(buf)-2).split('\x00')) else: return str(buf.value) @@ -358,7 +363,7 @@ class Config(object): elif isinstance(val, list): # null terminated non-empty strings - string_val = u'\x00'.join([str(x) or u' ' for x in val] + [u'']) + string_val = '\x00'.join([str(x) or ' ' for x in val] + ['']) buf = ctypes.create_unicode_buffer(string_val) RegSetValueEx(self.hkey, key, 0, REG_MULTI_SZ, buf, len(buf)*2) @@ -410,7 +415,7 @@ class Config(object): self.config.read_file(h) except Exception as e: - logger.debug('config section not yet present', exc_info=e) + logger.debug('Reading config failed, assuming we\'re making a new one...', exc_info=e) self.config.add_section(self.SECTION) if not self.get('outdir') or not isdir(self.get('outdir')): @@ -420,11 +425,11 @@ class Config(object): """Look up a string configuration value.""" try: val = self.config.get(self.SECTION, key) - if u'\n' in val: # list + if '\n' in val: # list # ConfigParser drops the last entry if blank, # so we add a spurious ';' entry in set() and remove it here assert val.split('\n')[-1] == ';', val.split('\n') - return [self._unescape(x) for x in val.split(u'\n')[:-1]] + return [self._unescape(x) for x in val.split('\n')[:-1]] else: return self._unescape(val) @@ -437,6 +442,10 @@ class Config(object): try: return self.config.getint(self.SECTION, key) + except ValueError as e: + logger.error(f"Failed to int({key=})", exc_info=e) + return 0 + except Exception as e: logger.debug('And the exception type is...', exc_info=e) return 0 @@ -450,7 +459,7 @@ class Config(object): self.config.set(self.SECTION, key, self._escape(val)) elif isinstance(val, list): - self.config.set(self.SECTION, key, u'\n'.join([self._escape(x) for x in val] + [u';'])) + self.config.set(self.SECTION, key, '\n'.join([self._escape(x) for x in val] + [';'])) else: raise NotImplementedError() @@ -485,7 +494,7 @@ class Config(object): def _escape(self, val): """Escape a string for storage.""" - return str(val).replace(u'\\', u'\\\\').replace(u'\n', u'\\n').replace(u';', u'\\;') + return str(val).replace('\\', '\\\\').replace('\n', '\\n').replace(';', '\\;') def _unescape(self, val): """Un-escape a string from storage.""" @@ -497,7 +506,7 @@ class Config(object): if chars[i] == 'n': chars[i] = '\n' i += 1 - return u''.join(chars) + return ''.join(chars) else: def __init__(self): From 1e24c297e024c79f60b237720816476ce4ac62b7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 17:29:24 +0100 Subject: [PATCH 072/727] config.py: Don't need to sub-class object --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 9e4fa377..f0afe917 100644 --- a/config.py +++ b/config.py @@ -116,7 +116,7 @@ elif platform == 'linux': from configparser import RawConfigParser -class Config(object): +class Config(): """Object that holds all configuration data.""" OUT_MKT_EDDN = 1 From 61a714513e0800d6eae2209e887e555f627e2a74 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:53:06 +0000 Subject: [PATCH 073/727] config.py: Final function type annotations --- config.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/config.py b/config.py index f0afe917..2ebf8b34 100644 --- a/config.py +++ b/config.py @@ -12,7 +12,7 @@ import warnings from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import Union +from typing import Optional, Union import semantic_version @@ -102,7 +102,7 @@ elif platform == 'win32': RegDeleteValue.restype = LONG RegDeleteValue.argtypes = [HKEY, LPCWSTR] - def known_folder_path(guid): + def known_folder_path(guid: uuid.UUID) -> Optional[str]: """Look up a Windows GUID to actual folder path name.""" buf = ctypes.c_wchar_p() if SHGetKnownFolderPath(ctypes.create_string_buffer(guid.bytes_le), 0, 0, ctypes.byref(buf)): @@ -478,25 +478,11 @@ class Config(): self.save() self.config = None - def set_shutdown(self): - self.__in_shutdown = True - - @property - def shutting_down(self) -> bool: - return self.__in_shutdown - - def set_auth_force_localserver(self): - self.__auth_force_localserver = True - - @property - def auth_force_localserver(self) -> bool: - return self.__auth_force_localserver - - def _escape(self, val): + def _escape(self, val: str) -> str: """Escape a string for storage.""" return str(val).replace('\\', '\\\\').replace('\n', '\\n').replace(';', '\\;') - def _unescape(self, val): + def _unescape(self, val: str) -> str: """Un-escape a string from storage.""" chars = list(val) i = 0 @@ -514,15 +500,15 @@ class Config(): # Common - def get_password(self, account): + def get_password(self, account: str) -> None: """Legacy password retrieval.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning) - def set_password(self, account, password): + def set_password(self, account: str, password: str) -> None: """Legacy password setting.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning) - def delete_password(self, account): + def delete_password(self, account: str) -> None: """Legacy password deletion.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning) From 2f35275024c16c1f67cbeec1b2b5a2c85e333556 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 17:50:23 +0100 Subject: [PATCH 074/727] config.py: Revert conditional orders for Windows Registry gets I failed to realise the values I'd moved earlier in the conditional were being passed by reference to the ctypes call. Thus they had initial values only upon test, rather than the 'returned' values as they should. This caused no values to be loaded from the Registry! --- config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 2ebf8b34..72c92522 100644 --- a/config.py +++ b/config.py @@ -309,8 +309,7 @@ class Config(): key_size = DWORD() # Only strings are handled here. if ( - key_type.value not in [REG_SZ, REG_MULTI_SZ] - or RegQueryValueEx( + RegQueryValueEx( self.hkey, key, 0, @@ -318,6 +317,7 @@ class Config(): None, ctypes.byref(key_size) ) + or key_type.value not in [REG_SZ, REG_MULTI_SZ] ): return None @@ -337,8 +337,7 @@ class Config(): key_size = DWORD(4) key_val = DWORD() if ( - key_type.value != REG_DWORD - or RegQueryValueEx( + RegQueryValueEx( self.hkey, key, 0, @@ -346,6 +345,7 @@ class Config(): ctypes.byref(key_val), ctypes.byref(key_size) ) + or key_type.value != REG_DWORD ): return 0 From c13caa22ef1a1b1f07f7bb261f6a8909b2c97e5c Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 2 Oct 2020 09:04:26 +0200 Subject: [PATCH 075/727] sorted imports, manually formatted some super long lines --- stats.py | 232 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 139 insertions(+), 93 deletions(-) diff --git a/stats.py b/stats.py index c8b3daa0..bbc65a8a 100644 --- a/stats.py +++ b/stats.py @@ -1,27 +1,33 @@ -from collections import OrderedDict import csv -from sys import platform -from functools import partial import time +from collections import OrderedDict +from functools import partial +from sys import platform +from typing import TYPE_CHECKING + if __debug__: from traceback import print_exc import tkinter as tk from tkinter import ttk -import myNotebook as nb import companion +import myNotebook as nb from companion import ship_map from l10n import Locale from monitor import monitor -import prefs + +if TYPE_CHECKING: + def _(x: str) -> str: ... if platform=='win32': import ctypes from ctypes.wintypes import * try: CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition - CalculatePopupWindowPosition.argtypes = [ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT)] + CalculatePopupWindowPosition.argtypes = [ + ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT) + ] GetParent = ctypes.windll.user32.GetParent GetParent.argtypes = [HWND] GetWindowRect = ctypes.windll.user32.GetWindowRect @@ -37,99 +43,99 @@ def status(data): [_('Loan'), str(data['commander'].get('debt', 0))], # Cmdr stats ] - RANKS = [ # in output order - (_('Combat') , 'combat'), # Ranking - (_('Trade') , 'trade'), # Ranking - (_('Explorer') , 'explore'), # Ranking - (_('CQC') , 'cqc'), # Ranking - (_('Federation') , 'federation'), # Ranking - (_('Empire') , 'empire'), # Ranking - (_('Powerplay') , 'power'), # Ranking - # ??? , 'crime'), # Ranking - # ??? , 'service'), # Ranking + RANKS = [ # in output order + (_('Combat') , 'combat'), # Ranking + (_('Trade') , 'trade'), # Ranking + (_('Explorer') , 'explore'), # Ranking + (_('CQC') , 'cqc'), # Ranking + (_('Federation') , 'federation'), # Ranking + (_('Empire') , 'empire'), # Ranking + (_('Powerplay') , 'power'), # Ranking + # ??? , 'crime'), # Ranking + # ??? , 'service'), # Ranking ] RANK_NAMES = { # http://elite-dangerous.wikia.com/wiki/Pilots_Federation#Ranks - 'combat' : [_('Harmless'), # Combat rank - _('Mostly Harmless'), # Combat rank - _('Novice'), # Combat rank - _('Competent'), # Combat rank - _('Expert'), # Combat rank - _('Master'), # Combat rank - _('Dangerous'), # Combat rank - _('Deadly'), # Combat rank - _('Elite')], # Top rank - 'trade' : [_('Penniless'), # Trade rank - _('Mostly Penniless'), # Trade rank - _('Peddler'), # Trade rank - _('Dealer'), # Trade rank - _('Merchant'), # Trade rank - _('Broker'), # Trade rank - _('Entrepreneur'), # Trade rank - _('Tycoon'), # Trade rank - _('Elite')], # Top rank - 'explore' : [_('Aimless'), # Explorer rank - _('Mostly Aimless'), # Explorer rank - _('Scout'), # Explorer rank - _('Surveyor'), # Explorer rank - _('Trailblazer'), # Explorer rank - _('Pathfinder'), # Explorer rank - _('Ranger'), # Explorer rank - _('Pioneer'), # Explorer rank - _('Elite')], # Top rank - 'cqc' : [_('Helpless'), # CQC rank - _('Mostly Helpless'), # CQC rank - _('Amateur'), # CQC rank - _('Semi Professional'), # CQC rank - _('Professional'), # CQC rank - _('Champion'), # CQC rank - _('Hero'), # CQC rank - _('Gladiator'), # CQC rank - _('Elite')], # Top rank + 'combat' : [_('Harmless'), # Combat rank + _('Mostly Harmless'), # Combat rank + _('Novice'), # Combat rank + _('Competent'), # Combat rank + _('Expert'), # Combat rank + _('Master'), # Combat rank + _('Dangerous'), # Combat rank + _('Deadly'), # Combat rank + _('Elite')], # Top rank + 'trade' : [_('Penniless'), # Trade rank + _('Mostly Penniless'), # Trade rank + _('Peddler'), # Trade rank + _('Dealer'), # Trade rank + _('Merchant'), # Trade rank + _('Broker'), # Trade rank + _('Entrepreneur'), # Trade rank + _('Tycoon'), # Trade rank + _('Elite')], # Top rank + 'explore' : [_('Aimless'), # Explorer rank + _('Mostly Aimless'), # Explorer rank + _('Scout'), # Explorer rank + _('Surveyor'), # Explorer rank + _('Trailblazer'), # Explorer rank + _('Pathfinder'), # Explorer rank + _('Ranger'), # Explorer rank + _('Pioneer'), # Explorer rank + _('Elite')], # Top rank + 'cqc' : [_('Helpless'), # CQC rank + _('Mostly Helpless'), # CQC rank + _('Amateur'), # CQC rank + _('Semi Professional'), # CQC rank + _('Professional'), # CQC rank + _('Champion'), # CQC rank + _('Hero'), # CQC rank + _('Gladiator'), # CQC rank + _('Elite')], # Top rank # http://elite-dangerous.wikia.com/wiki/Federation#Ranks - 'federation' : [_('None'), # No rank - _('Recruit'), # Federation rank - _('Cadet'), # Federation rank - _('Midshipman'), # Federation rank - _('Petty Officer'), # Federation rank - _('Chief Petty Officer'), # Federation rank - _('Warrant Officer'), # Federation rank - _('Ensign'), # Federation rank - _('Lieutenant'), # Federation rank - _('Lieutenant Commander'), # Federation rank - _('Post Commander'), # Federation rank - _('Post Captain'), # Federation rank - _('Rear Admiral'), # Federation rank - _('Vice Admiral'), # Federation rank - _('Admiral')], # Federation rank + 'federation' : [_('None'), # No rank + _('Recruit'), # Federation rank + _('Cadet'), # Federation rank + _('Midshipman'), # Federation rank + _('Petty Officer'), # Federation rank + _('Chief Petty Officer'), # Federation rank + _('Warrant Officer'), # Federation rank + _('Ensign'), # Federation rank + _('Lieutenant'), # Federation rank + _('Lieutenant Commander'), # Federation rank + _('Post Commander'), # Federation rank + _('Post Captain'), # Federation rank + _('Rear Admiral'), # Federation rank + _('Vice Admiral'), # Federation rank + _('Admiral')], # Federation rank # http://elite-dangerous.wikia.com/wiki/Empire#Ranks - 'empire' : [_('None'), # No rank - _('Outsider'), # Empire rank - _('Serf'), # Empire rank - _('Master'), # Empire rank - _('Squire'), # Empire rank - _('Knight'), # Empire rank - _('Lord'), # Empire rank - _('Baron'), # Empire rank - _('Viscount'), # Empire rank - _('Count'), # Empire rank - _('Earl'), # Empire rank - _('Marquis'), # Empire rank - _('Duke'), # Empire rank - _('Prince'), # Empire rank - _('King')], # Empire rank + 'empire' : [_('None'), # No rank + _('Outsider'), # Empire rank + _('Serf'), # Empire rank + _('Master'), # Empire rank + _('Squire'), # Empire rank + _('Knight'), # Empire rank + _('Lord'), # Empire rank + _('Baron'), # Empire rank + _('Viscount'), # Empire rank + _('Count'), # Empire rank + _('Earl'), # Empire rank + _('Marquis'), # Empire rank + _('Duke'), # Empire rank + _('Prince'), # Empire rank + _('King')], # Empire rank # http://elite-dangerous.wikia.com/wiki/Ratings - 'power' : [_('None'), # No rank - _('Rating 1'), # Power rank - _('Rating 2'), # Power rank - _('Rating 3'), # Power rank - _('Rating 4'), # Power rank - _('Rating 5')], # Power rank + 'power' : [_('None'), # No rank + _('Rating 1'), # Power rank + _('Rating 2'), # Power rank + _('Rating 3'), # Power rank + _('Rating 4'), # Power rank + _('Rating 5')], # Power rank } ranks = data['commander'].get('rank', {}) @@ -153,7 +159,6 @@ def export_status(data, filename): # Returns id,name,shipName,system,station,value def ships(data): - ships = companion.listify(data.get('ships')) current = data['commander'].get('currentShipId') @@ -162,10 +167,35 @@ def ships(data): if not data['commander'].get('docked'): # Set current system, not last docked - return ([ (str(ships[0]['id']), ship_map.get(ships[0]['name'].lower(), ships[0]['name']), ships[0].get('shipName', ''), data['lastSystem']['name'], '', str(ships[0]['value']['total'])) ] + - [ (str(ship['id']), ship_map.get(ship['name'].lower(), ship['name']), ship.get('shipName', ''), ship['starsystem']['name'], ship['station']['name'], str(ship['value']['total'])) for ship in ships[1:] if ship]) + return ( + [( + str(ships[0]['id']), + ship_map.get(ships[0]['name'].lower(), + ships[0]['name']), + ships[0].get('shipName', ''), + data['lastSystem']['name'], + '', str(ships[0]['value']['total']) + )] + + [( + str(ship['id']), ship_map.get(ship['name'].lower(), + ship['name']), + ship.get('shipName', ''), + ship['starsystem']['name'], + ship['station']['name'], + str(ship['value']['total'])) for ship in ships[1:] if ship + ]) + + return [ + ( + str(ship['id']), + ship_map.get(ship['name'].lower(), ship['name']), + ship.get('shipName', ''), + ship['starsystem']['name'], + ship['station']['name'], + str(ship['value']['total']) + ) for ship in ships if ship + ] - return [ (str(ship['id']), ship_map.get(ship['name'].lower(), ship['name']), ship.get('shipName', ''), ship['starsystem']['name'], ship['station']['name'], str(ship['value']['total'])) for ship in ships if ship] def export_ships(data, filename): h = csv.writer(open(filename, 'w')) @@ -190,9 +220,11 @@ class StatsDialog(): try: data = companion.session.profile() + except companion.ServerError as e: self.status['text'] = str(e) return + except Exception as e: if __debug__: print_exc() self.status['text'] = str(e) @@ -200,10 +232,18 @@ class StatsDialog(): if not data.get('commander') or not data['commander'].get('name','').strip(): self.status['text'] = _("Who are you?!") # Shouldn't happen - elif not data.get('lastSystem') or not data['lastSystem'].get('name','').strip() or not data.get('lastStarport') or not data['lastStarport'].get('name','').strip(): + + elif ( + not data.get('lastSystem') + or not data['lastSystem'].get('name','').strip() + or not data.get('lastStarport') + or not data['lastStarport'].get('name','').strip() + ): self.status['text'] = _("Where are you?!") # Shouldn't happen + elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip(): self.status['text'] = _("What are you flying?!") # Shouldn't happen + else: self.status['text'] = '' StatsResults(self.parent, data) @@ -242,8 +282,10 @@ class StatsResults(tk.Toplevel): page = self.addpage(notebook) for thing in stats[1:3]: self.addpagerow(page, [thing[0], self.credits(int(thing[1]))]) # assumes things two and three are money + for thing in stats[3:]: self.addpagerow(page, thing) + ttk.Frame(page).grid(pady=5) # bottom spacer notebook.add(page, text=_('Status')) # Status dialog title @@ -257,6 +299,7 @@ class StatsResults(tk.Toplevel): shiplist = ships(data) for thing in shiplist: self.addpagerow(page, list(thing[1:-1]) + [self.credits(int(thing[-1]))]) # skip id, last item is money + ttk.Frame(page).grid(pady=5) # bottom spacer notebook.add(page, text=_('Ships')) # Status dialog title @@ -286,6 +329,7 @@ class StatsResults(tk.Toplevel): page.columnconfigure(0, weight=1) if header: self.addpageheader(page, header, align=align) + return page def addpageheader(self, parent, header, align=None): @@ -301,8 +345,10 @@ class StatsResults(tk.Toplevel): if i == 0: label.grid(padx=10, sticky=tk.W) row = parent.grid_size()[1]-1 + elif align is None and i == len(content) - 1: # Assumes last column right justified if unspecified label.grid(row=row, column=i, padx=10, sticky=tk.E) + else: label.grid(row=row, column=i, padx=10, sticky=align or tk.W) From a25ea9dfa9c1eb2e40db355e3528f65b2036ec6e Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 2 Oct 2020 09:32:59 +0200 Subject: [PATCH 076/727] autoformatted code --- stats.py | 280 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 147 insertions(+), 133 deletions(-) diff --git a/stats.py b/stats.py index bbc65a8a..af7a55cb 100644 --- a/stats.py +++ b/stats.py @@ -1,7 +1,4 @@ import csv -import time -from collections import OrderedDict -from functools import partial from sys import platform from typing import TYPE_CHECKING @@ -20,7 +17,7 @@ from monitor import monitor if TYPE_CHECKING: def _(x: str) -> str: ... -if platform=='win32': +if platform == 'win32': import ctypes from ctypes.wintypes import * try: @@ -32,110 +29,125 @@ if platform=='win32': GetParent.argtypes = [HWND] GetWindowRect = ctypes.windll.user32.GetWindowRect GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] - except: # Not supported under Wine 4.0 + except: # Not supported under Wine 4.0 CalculatePopupWindowPosition = None + def status(data): # StatsResults assumes these three things are first - res = [ [_('Cmdr'), data['commander']['name']], - [_('Balance'), str(data['commander'].get('credits', 0))], # Cmdr stats - [_('Loan'), str(data['commander'].get('debt', 0))], # Cmdr stats + res = [ + [_('Cmdr'), data['commander']['name']], + [_('Balance'), str(data['commander'].get('credits', 0))], # Cmdr stats + [_('Loan'), str(data['commander'].get('debt', 0))], # Cmdr stats ] RANKS = [ # in output order - (_('Combat') , 'combat'), # Ranking - (_('Trade') , 'trade'), # Ranking - (_('Explorer') , 'explore'), # Ranking - (_('CQC') , 'cqc'), # Ranking - (_('Federation') , 'federation'), # Ranking - (_('Empire') , 'empire'), # Ranking - (_('Powerplay') , 'power'), # Ranking - # ??? , 'crime'), # Ranking - # ??? , 'service'), # Ranking + (_('Combat'), 'combat'), # Ranking + (_('Trade'), 'trade'), # Ranking + (_('Explorer'), 'explore'), # Ranking + (_('CQC'), 'cqc'), # Ranking + (_('Federation'), 'federation'), # Ranking + (_('Empire'), 'empire'), # Ranking + (_('Powerplay'), 'power'), # Ranking + # ??? , 'crime'), # Ranking + # ??? , 'service'), # Ranking ] RANK_NAMES = { - # http://elite-dangerous.wikia.com/wiki/Pilots_Federation#Ranks - 'combat' : [_('Harmless'), # Combat rank - _('Mostly Harmless'), # Combat rank - _('Novice'), # Combat rank - _('Competent'), # Combat rank - _('Expert'), # Combat rank - _('Master'), # Combat rank - _('Dangerous'), # Combat rank - _('Deadly'), # Combat rank - _('Elite')], # Top rank - 'trade' : [_('Penniless'), # Trade rank - _('Mostly Penniless'), # Trade rank - _('Peddler'), # Trade rank - _('Dealer'), # Trade rank - _('Merchant'), # Trade rank - _('Broker'), # Trade rank - _('Entrepreneur'), # Trade rank - _('Tycoon'), # Trade rank - _('Elite')], # Top rank - 'explore' : [_('Aimless'), # Explorer rank - _('Mostly Aimless'), # Explorer rank - _('Scout'), # Explorer rank - _('Surveyor'), # Explorer rank - _('Trailblazer'), # Explorer rank - _('Pathfinder'), # Explorer rank - _('Ranger'), # Explorer rank - _('Pioneer'), # Explorer rank - _('Elite')], # Top rank - 'cqc' : [_('Helpless'), # CQC rank - _('Mostly Helpless'), # CQC rank - _('Amateur'), # CQC rank - _('Semi Professional'), # CQC rank - _('Professional'), # CQC rank - _('Champion'), # CQC rank - _('Hero'), # CQC rank - _('Gladiator'), # CQC rank - _('Elite')], # Top rank + 'combat': [ + _('Harmless'), # Combat rank + _('Mostly Harmless'), # Combat rank + _('Novice'), # Combat rank + _('Competent'), # Combat rank + _('Expert'), # Combat rank + _('Master'), # Combat rank + _('Dangerous'), # Combat rank + _('Deadly'), # Combat rank + _('Elite'), # Top rank + ], + 'trade': [ + _('Penniless'), # Trade rank + _('Mostly Penniless'), # Trade rank + _('Peddler'), # Trade rank + _('Dealer'), # Trade rank + _('Merchant'), # Trade rank + _('Broker'), # Trade rank + _('Entrepreneur'), # Trade rank + _('Tycoon'), # Trade rank + _('Elite') # Top rank + ], + 'explore': [ + _('Aimless'), # Explorer rank + _('Mostly Aimless'), # Explorer rank + _('Scout'), # Explorer rank + _('Surveyor'), # Explorer rank + _('Trailblazer'), # Explorer rank + _('Pathfinder'), # Explorer rank + _('Ranger'), # Explorer rank + _('Pioneer'), # Explorer rank + _('Elite') # Top rank + ], + 'cqc': [ + _('Helpless'), # CQC rank + _('Mostly Helpless'), # CQC rank + _('Amateur'), # CQC rank + _('Semi Professional'), # CQC rank + _('Professional'), # CQC rank + _('Champion'), # CQC rank + _('Hero'), # CQC rank + _('Gladiator'), # CQC rank + _('Elite') # Top rank + ], # http://elite-dangerous.wikia.com/wiki/Federation#Ranks - 'federation' : [_('None'), # No rank - _('Recruit'), # Federation rank - _('Cadet'), # Federation rank - _('Midshipman'), # Federation rank - _('Petty Officer'), # Federation rank - _('Chief Petty Officer'), # Federation rank - _('Warrant Officer'), # Federation rank - _('Ensign'), # Federation rank - _('Lieutenant'), # Federation rank - _('Lieutenant Commander'), # Federation rank - _('Post Commander'), # Federation rank - _('Post Captain'), # Federation rank - _('Rear Admiral'), # Federation rank - _('Vice Admiral'), # Federation rank - _('Admiral')], # Federation rank + 'federation': [ + _('None'), # No rank + _('Recruit'), # Federation rank + _('Cadet'), # Federation rank + _('Midshipman'), # Federation rank + _('Petty Officer'), # Federation rank + _('Chief Petty Officer'), # Federation rank + _('Warrant Officer'), # Federation rank + _('Ensign'), # Federation rank + _('Lieutenant'), # Federation rank + _('Lieutenant Commander'), # Federation rank + _('Post Commander'), # Federation rank + _('Post Captain'), # Federation rank + _('Rear Admiral'), # Federation rank + _('Vice Admiral'), # Federation rank + _('Admiral') # Federation rank + ], # http://elite-dangerous.wikia.com/wiki/Empire#Ranks - 'empire' : [_('None'), # No rank - _('Outsider'), # Empire rank - _('Serf'), # Empire rank - _('Master'), # Empire rank - _('Squire'), # Empire rank - _('Knight'), # Empire rank - _('Lord'), # Empire rank - _('Baron'), # Empire rank - _('Viscount'), # Empire rank - _('Count'), # Empire rank - _('Earl'), # Empire rank - _('Marquis'), # Empire rank - _('Duke'), # Empire rank - _('Prince'), # Empire rank - _('King')], # Empire rank + 'empire': [ + _('None'), # No rank + _('Outsider'), # Empire rank + _('Serf'), # Empire rank + _('Master'), # Empire rank + _('Squire'), # Empire rank + _('Knight'), # Empire rank + _('Lord'), # Empire rank + _('Baron'), # Empire rank + _('Viscount'), # Empire rank + _('Count'), # Empire rank + _('Earl'), # Empire rank + _('Marquis'), # Empire rank + _('Duke'), # Empire rank + _('Prince'), # Empire rank + _('King') # Empire rank + ], # http://elite-dangerous.wikia.com/wiki/Ratings - 'power' : [_('None'), # No rank - _('Rating 1'), # Power rank - _('Rating 2'), # Power rank - _('Rating 3'), # Power rank - _('Rating 4'), # Power rank - _('Rating 5')], # Power rank + 'power': [ + _('None'), # No rank + _('Rating 1'), # Power rank + _('Rating 2'), # Power rank + _('Rating 3'), # Power rank + _('Rating 4'), # Power rank + _('Rating 5') # Power rank + ], } ranks = data['commander'].get('rank', {}) @@ -144,8 +156,9 @@ def status(data): names = RANK_NAMES[thing] if isinstance(rank, int): res.append([title, rank < len(names) and names[rank] or ('Rank %d' % rank)]) + else: - res.append([title, _('None')]) # No rank + res.append([title, _('None')]) # No rank return res @@ -163,27 +176,26 @@ def ships(data): current = data['commander'].get('currentShipId') if isinstance(current, int) and current < len(ships) and ships[current]: - ships.insert(0, ships.pop(current)) # Put current ship first + ships.insert(0, ships.pop(current)) # Put current ship first if not data['commander'].get('docked'): # Set current system, not last docked return ( [( - str(ships[0]['id']), - ship_map.get(ships[0]['name'].lower(), - ships[0]['name']), - ships[0].get('shipName', ''), - data['lastSystem']['name'], - '', str(ships[0]['value']['total']) - )] + - [( - str(ship['id']), ship_map.get(ship['name'].lower(), - ship['name']), - ship.get('shipName', ''), - ship['starsystem']['name'], - ship['station']['name'], - str(ship['value']['total'])) for ship in ships[1:] if ship - ]) + str(ships[0]['id']), + ship_map.get(ships[0]['name'].lower(), + ships[0]['name']), + ships[0].get('shipName', ''), + data['lastSystem']['name'], + '', str(ships[0]['value']['total']) + )] + + [( + str(ship['id']), ship_map.get(ship['name'].lower(), ship['name']), + ship.get('shipName', ''), + ship['starsystem']['name'], + ship['station']['name'], + str(ship['value']['total'])) for ship in ships[1:] if ship + ]) return [ ( @@ -205,7 +217,6 @@ def export_ships(data, filename): class StatsDialog(): - def __init__(self, app): self.parent = app.w self.status = app.status @@ -226,23 +237,24 @@ class StatsDialog(): return except Exception as e: - if __debug__: print_exc() + if __debug__: + print_exc() self.status['text'] = str(e) return - if not data.get('commander') or not data['commander'].get('name','').strip(): + if not data.get('commander') or not data['commander'].get('name', '').strip(): self.status['text'] = _("Who are you?!") # Shouldn't happen elif ( not data.get('lastSystem') - or not data['lastSystem'].get('name','').strip() + or not data['lastSystem'].get('name', '').strip() or not data.get('lastStarport') - or not data['lastStarport'].get('name','').strip() + or not data['lastStarport'].get('name', '').strip() ): self.status['text'] = _("Where are you?!") # Shouldn't happen - elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip(): - self.status['text'] = _("What are you flying?!") # Shouldn't happen + elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name', '').strip(): + self.status['text'] = _("What are you flying?!") # Shouldn't happen else: self.status['text'] = '' @@ -250,27 +262,27 @@ class StatsDialog(): class StatsResults(tk.Toplevel): - def __init__(self, parent, data): tk.Toplevel.__init__(self, parent) self.parent = parent stats = status(data) - self.title(' '.join(stats[0])) # assumes first thing is player name + self.title(' '.join(stats[0])) # assumes first thing is player name if parent.winfo_viewable(): self.transient(parent) # position over parent - if platform!='darwin' or parent.winfo_rooty()>0: # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 + if platform != 'darwin' or parent.winfo_rooty() > 0: # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 self.geometry("+%d+%d" % (parent.winfo_rootx(), parent.winfo_rooty())) # remove decoration self.resizable(tk.FALSE, tk.FALSE) - if platform=='win32': + if platform == 'win32': self.attributes('-toolwindow', tk.TRUE) - elif platform=='darwin': + + elif platform == 'darwin': # http://wiki.tcl.tk/13428 parent.call('tk::unsupported::MacWindowStyle', 'style', self, 'utility') @@ -281,7 +293,7 @@ class StatsResults(tk.Toplevel): page = self.addpage(notebook) for thing in stats[1:3]: - self.addpagerow(page, [thing[0], self.credits(int(thing[1]))]) # assumes things two and three are money + self.addpagerow(page, [thing[0], self.credits(int(thing[1]))]) # assumes things two and three are money for thing in stats[3:]: self.addpagerow(page, thing) @@ -290,24 +302,25 @@ class StatsResults(tk.Toplevel): notebook.add(page, text=_('Status')) # Status dialog title page = self.addpage(notebook, [ - _('Ship'), # Status dialog subtitle + _('Ship'), # Status dialog subtitle '', - _('System'), # Main window - _('Station'), # Status dialog subtitle - _('Value'), # Status dialog subtitle - CR value of ship + _('System'), # Main window + _('Station'), # Status dialog subtitle + _('Value'), # Status dialog subtitle - CR value of ship ]) + shiplist = ships(data) for thing in shiplist: - self.addpagerow(page, list(thing[1:-1]) + [self.credits(int(thing[-1]))]) # skip id, last item is money + self.addpagerow(page, list(thing[1:-1]) + [self.credits(int(thing[-1]))]) # skip id, last item is money ttk.Frame(page).grid(pady=5) # bottom spacer notebook.add(page, text=_('Ships')) # Status dialog title - if platform!='darwin': + if platform != 'darwin': buttonframe = ttk.Frame(frame) - buttonframe.grid(padx=10, pady=(0,10), sticky=tk.NSEW) + buttonframe.grid(padx=10, pady=(0, 10), sticky=tk.NSEW) buttonframe.columnconfigure(0, weight=1) - ttk.Label(buttonframe).grid(row=0, column=0) # spacer + ttk.Label(buttonframe).grid(row=0, column=0) # spacer ttk.Button(buttonframe, text='OK', command=self.destroy).grid(row=0, column=1, sticky=tk.E) # wait for window to appear on screen before calling grab_set @@ -318,9 +331,11 @@ class StatsResults(tk.Toplevel): if platform == 'win32' and CalculatePopupWindowPosition: position = RECT() GetWindowRect(GetParent(self.winfo_id()), position) - if CalculatePopupWindowPosition(POINT(parent.winfo_rootx(), parent.winfo_rooty()), - SIZE(position.right - position.left, position.bottom - position.top), - 0x10000, None, position): + if CalculatePopupWindowPosition( + POINT(parent.winfo_rootx(), parent.winfo_rooty()), + SIZE(position.right - position.left, position.bottom - position.top), + 0x10000, None, position + ): self.geometry("+%d+%d" % (position.left, position.top)) def addpage(self, parent, header=[], align=None): @@ -346,7 +361,7 @@ class StatsResults(tk.Toplevel): label.grid(padx=10, sticky=tk.W) row = parent.grid_size()[1]-1 - elif align is None and i == len(content) - 1: # Assumes last column right justified if unspecified + elif align is None and i == len(content) - 1: # Assumes last column right justified if unspecified label.grid(row=row, column=i, padx=10, sticky=tk.E) else: @@ -354,4 +369,3 @@ class StatsResults(tk.Toplevel): def credits(self, value): return Locale.stringFromNumber(value, 0) + ' Cr' - From c7e0850ea1bc406cdc009f899f0c5bbfb1a92b00 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 2 Oct 2020 09:37:09 +0200 Subject: [PATCH 077/727] removed star import --- stats.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/stats.py b/stats.py index af7a55cb..d51db95a 100644 --- a/stats.py +++ b/stats.py @@ -19,7 +19,10 @@ if TYPE_CHECKING: if platform == 'win32': import ctypes - from ctypes.wintypes import * + from ctypes.wintypes import HWND, POINT, RECT, SIZE, UINT + if TYPE_CHECKING: + import ctypes.windll # type: ignore + try: CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition CalculatePopupWindowPosition.argtypes = [ @@ -29,7 +32,8 @@ if platform == 'win32': GetParent.argtypes = [HWND] GetWindowRect = ctypes.windll.user32.GetWindowRect GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] - except: # Not supported under Wine 4.0 + + except Exception: # Not supported under Wine 4.0 CalculatePopupWindowPosition = None @@ -333,7 +337,8 @@ class StatsResults(tk.Toplevel): GetWindowRect(GetParent(self.winfo_id()), position) if CalculatePopupWindowPosition( POINT(parent.winfo_rootx(), parent.winfo_rooty()), - SIZE(position.right - position.left, position.bottom - position.top), + # - is evidently supported on the C side + SIZE(position.right - position.left, position.bottom - position.top), # type: ignore 0x10000, None, position ): self.geometry("+%d+%d" % (position.left, position.top)) From 84a093a7e31355a2bc45b75728f6ef9c12ae7675 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 7 Oct 2020 13:26:31 +0200 Subject: [PATCH 078/727] replaced string formatting with interpolation --- stats.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stats.py b/stats.py index d51db95a..f6d79f67 100644 --- a/stats.py +++ b/stats.py @@ -21,7 +21,7 @@ if platform == 'win32': import ctypes from ctypes.wintypes import HWND, POINT, RECT, SIZE, UINT if TYPE_CHECKING: - import ctypes.windll # type: ignore + import ctypes.windll # type: ignore # Fake this into existing, its really a magic dll thing try: CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition @@ -159,7 +159,7 @@ def status(data): rank = ranks.get(thing) names = RANK_NAMES[thing] if isinstance(rank, int): - res.append([title, rank < len(names) and names[rank] or ('Rank %d' % rank)]) + res.append([title, names[rank] if rank < len(names) else f'Rank {rank}']) else: res.append([title, _('None')]) # No rank @@ -279,7 +279,7 @@ class StatsResults(tk.Toplevel): # position over parent if platform != 'darwin' or parent.winfo_rooty() > 0: # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 - self.geometry("+%d+%d" % (parent.winfo_rootx(), parent.winfo_rooty())) + self.geometry(f"+{parent.winfo_rootx()}+{parent.winfo_rooty()}") # remove decoration self.resizable(tk.FALSE, tk.FALSE) @@ -322,7 +322,7 @@ class StatsResults(tk.Toplevel): if platform != 'darwin': buttonframe = ttk.Frame(frame) - buttonframe.grid(padx=10, pady=(0, 10), sticky=tk.NSEW) + buttonframe.grid(padx=10, pady=(0, 10), sticky=tk.NSEW) # type: ignore # the tuple is supported buttonframe.columnconfigure(0, weight=1) ttk.Label(buttonframe).grid(row=0, column=0) # spacer ttk.Button(buttonframe, text='OK', command=self.destroy).grid(row=0, column=1, sticky=tk.E) @@ -341,7 +341,7 @@ class StatsResults(tk.Toplevel): SIZE(position.right - position.left, position.bottom - position.top), # type: ignore 0x10000, None, position ): - self.geometry("+%d+%d" % (position.left, position.top)) + self.geometry(f"+{position.left}+{position.top}") def addpage(self, parent, header=[], align=None): page = nb.Frame(parent) From 53c6f85124dab1a00a95c2fb79fc9971a0e69acf Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 7 Oct 2020 15:20:32 +0200 Subject: [PATCH 079/727] Fixed (im)possible UnboundLocalExceptions --- stats.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stats.py b/stats.py index f6d79f67..2db41c0b 100644 --- a/stats.py +++ b/stats.py @@ -360,6 +360,7 @@ class StatsResults(tk.Toplevel): self.addpagerow(parent, ['']) def addpagerow(self, parent, content, align=None): + row = -1 # To silence unbound warnings for i in range(len(content)): label = nb.Label(parent, text=content[i]) if i == 0: From d1e2e2b1f382ee6e25d42d1d1d25bb27dcae7f10 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 7 Oct 2020 15:22:50 +0200 Subject: [PATCH 080/727] Removed uneeded list comprehensions --- stats.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stats.py b/stats.py index 2db41c0b..1e96a560 100644 --- a/stats.py +++ b/stats.py @@ -171,7 +171,7 @@ def export_status(data, filename): h = csv.writer(open(filename, 'w')) h.writerow(['Category', 'Value']) for thing in status(data): - h.writerow([x for x in thing]) + h.writerow(list(thing)) # Returns id,name,shipName,system,station,value @@ -217,7 +217,7 @@ def export_ships(data, filename): h = csv.writer(open(filename, 'w')) h.writerow(['Id', 'Ship', 'Name', 'System', 'Station', 'Value']) for thing in ships(data): - h.writerow([x for x in thing]) + h.writerow(list(thing)) class StatsDialog(): From 3b4d56b842a73d6fa09a5491b287294c697b2496 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 7 Oct 2020 16:37:23 +0200 Subject: [PATCH 081/727] Added docstrings, type annotations This looks quite large, but it makes no code changes other than docstrings and type annotations. Along with a small code style fix. --- stats.py | 146 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 108 insertions(+), 38 deletions(-) diff --git a/stats.py b/stats.py index 1e96a560..af2a758e 100644 --- a/stats.py +++ b/stats.py @@ -1,6 +1,10 @@ +"""CMDR Status information.""" import csv from sys import platform -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, Sequence, Tuple, cast + +if TYPE_CHECKING: + from EDMarketConnector import AppWindow if __debug__: from traceback import print_exc @@ -9,7 +13,7 @@ import tkinter as tk from tkinter import ttk import companion -import myNotebook as nb +import myNotebook as nb # noqa: N813 from companion import ship_map from l10n import Locale from monitor import monitor @@ -37,8 +41,13 @@ if platform == 'win32': CalculatePopupWindowPosition = None -def status(data): +def status(data: Dict[str, Any]) -> List[List[str]]: + """ + Get the current status of the cmdr referred to by data. + :param data: Data to generate status from + :return: Status information about the given cmdr + """ # StatsResults assumes these three things are first res = [ [_('Cmdr'), data['commander']['name']], @@ -46,7 +55,8 @@ def status(data): [_('Loan'), str(data['commander'].get('debt', 0))], # Cmdr stats ] - RANKS = [ # in output order + RANKS = [ # noqa: N806 # Its a constant, just needs to be updated at runtime + # in output order (_('Combat'), 'combat'), # Ranking (_('Trade'), 'trade'), # Ranking (_('Explorer'), 'explore'), # Ranking @@ -58,7 +68,7 @@ def status(data): # ??? , 'service'), # Ranking ] - RANK_NAMES = { + RANK_NAMES = { # noqa: N806 # Its a constant, just needs to be updated at runtime # http://elite-dangerous.wikia.com/wiki/Pilots_Federation#Ranks 'combat': [ _('Harmless'), # Combat rank @@ -167,39 +177,60 @@ def status(data): return res -def export_status(data, filename): +def export_status(data: Dict[str, Any], filename: AnyStr) -> None: + """ + Export status data to a CSV file. + + :param data: The data to generate the file from + :param filename: The target file + """ + # TODO: Context manager h = csv.writer(open(filename, 'w')) h.writerow(['Category', 'Value']) for thing in status(data): h.writerow(list(thing)) -# Returns id,name,shipName,system,station,value -def ships(data): - ships = companion.listify(data.get('ships')) - current = data['commander'].get('currentShipId') +def ships(companion_data: Dict[str, Any]) -> List[Tuple[str, str, str, str, str, str]]: + # TODO: Replace this with a NamedTuple + """ + Return a list of 5 tuples of ship information. + + :param data: [description] + :return: A 5 tuple of strings containing: Ship ID, Ship Type Name (internal), Ship Name, System, Station, and Value + """ + ships: List[Dict[str, Any]] = companion.listify(cast(list, companion_data.get('ships'))) + current = companion_data['commander'].get('currentShipId') if isinstance(current, int) and current < len(ships) and ships[current]: ships.insert(0, ships.pop(current)) # Put current ship first - if not data['commander'].get('docked'): + if not companion_data['commander'].get('docked'): + out: List[Tuple[str, str, str, str, str, str]] = [] # Set current system, not last docked - return ( - [( + out.append( + ( str(ships[0]['id']), - ship_map.get(ships[0]['name'].lower(), - ships[0]['name']), - ships[0].get('shipName', ''), - data['lastSystem']['name'], - '', str(ships[0]['value']['total']) - )] + - [( - str(ship['id']), ship_map.get(ship['name'].lower(), ship['name']), + ship_map.get(ships[0]['name'].lower(), ships[0]['name']), + str(ships[0].get('shipName', '')), + companion_data['lastSystem']['name'], + '', + str(ships[0]['value']['total']) + ) + ) + + out.extend( + ( + str(ship['id']), + ship_map.get(ship['name'].lower(), ship['name']), ship.get('shipName', ''), ship['starsystem']['name'], ship['station']['name'], - str(ship['value']['total'])) for ship in ships[1:] if ship - ]) + str(ship['value']['total']) + ) for ship in ships[1:] if ship + ) + + return out return [ ( @@ -209,24 +240,34 @@ def ships(data): ship['starsystem']['name'], ship['station']['name'], str(ship['value']['total']) - ) for ship in ships if ship + ) for ship in ships if ship is not None ] -def export_ships(data, filename): +def export_ships(companion_data: Dict[str, Any], filename: AnyStr) -> None: + """ + Export the current ships to a CSV file. + + :param companion_data: Data from which to generate the ship list + :param filename: The target file + """ + # TODO: context manager h = csv.writer(open(filename, 'w')) h.writerow(['Id', 'Ship', 'Name', 'System', 'Station', 'Value']) - for thing in ships(data): + for thing in ships(companion_data): h.writerow(list(thing)) class StatsDialog(): - def __init__(self, app): - self.parent = app.w + """Status dialog containing all of the current cmdr's stats.""" + + def __init__(self, app: 'AppWindow') -> None: + self.parent: tk.Tk = app.w self.status = app.status self.showstats() - def showstats(self): + def showstats(self) -> None: + """Show the status window for the current cmdr.""" if not monitor.cmdr: return @@ -266,7 +307,9 @@ class StatsDialog(): class StatsResults(tk.Toplevel): - def __init__(self, parent, data): + """Status window.""" + + def __init__(self, parent: tk.Tk, data: Dict[str, Any]) -> None: tk.Toplevel.__init__(self, parent) self.parent = parent @@ -314,8 +357,9 @@ class StatsResults(tk.Toplevel): ]) shiplist = ships(data) - for thing in shiplist: - self.addpagerow(page, list(thing[1:-1]) + [self.credits(int(thing[-1]))]) # skip id, last item is money + for ship_data in shiplist: + # skip id, last item is money + self.addpagerow(page, list(ship_data[1:-1]) + [self.credits(int(ship_data[-1]))]) ttk.Frame(page).grid(pady=5) # bottom spacer notebook.add(page, text=_('Ships')) # Status dialog title @@ -343,7 +387,16 @@ class StatsResults(tk.Toplevel): ): self.geometry(f"+{position.left}+{position.top}") - def addpage(self, parent, header=[], align=None): + def addpage(self, parent, header: List[str] = [], align: Optional[str] = None) -> tk.Frame: + # TODO: mutable defaults is no beauno. + """ + Add a page to the StatsResults screen. + + :param parent: The parent widget to put this under + :param header: The headers for the table, defaults to [] + :param align: Alignment to use for this page, defaults to None + :return: The Frame that was created + """ page = nb.Frame(parent) page.grid(pady=10, sticky=tk.NSEW) page.columnconfigure(0, weight=1) @@ -352,14 +405,29 @@ class StatsResults(tk.Toplevel): return page - def addpageheader(self, parent, header, align=None): + def addpageheader(self, parent: tk.Frame, header: Sequence[str], align: Optional[str] = None) -> None: + """ + Add the column headers to the page, followed by a separator. + + :param parent: The parent widget to add this to + :param header: The headers to add to the page + :param align: The alignment of the page, defaults to None + """ self.addpagerow(parent, header, align=align) ttk.Separator(parent, orient=tk.HORIZONTAL).grid(columnspan=len(header), padx=10, pady=2, sticky=tk.EW) - def addpagespacer(self, parent): + def addpagespacer(self, parent) -> None: + """Add a spacer to the page.""" self.addpagerow(parent, ['']) - def addpagerow(self, parent, content, align=None): + def addpagerow(self, parent: tk.Frame, content: Sequence[str], align: Optional[str] = None): + """ + Add a single row to parent. + + :param parent: The widget to add the data to + :param content: The columns of the row to add + :param align: The alignment of the data, defaults to tk.W + """ row = -1 # To silence unbound warnings for i in range(len(content)): label = nb.Label(parent, text=content[i]) @@ -373,5 +441,7 @@ class StatsResults(tk.Toplevel): else: label.grid(row=row, column=i, padx=10, sticky=align or tk.W) - def credits(self, value): - return Locale.stringFromNumber(value, 0) + ' Cr' + def credits(self, value: int) -> str: + """Localised string of given int, including a trailing ` Cr`.""" + # TODO: Locale is a class, this calls an instance method on it with an int as its `self` + return Locale.stringFromNumber(value, 0) + ' Cr' # type: ignore From ad8fdd763a8a217b0899acb06c16ad9dfca91ed9 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 9 Oct 2020 17:21:05 +0200 Subject: [PATCH 082/727] made ships() return a List of NamedTuples This way, we can access items without remembing indexes, if needed --- stats.py | 85 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/stats.py b/stats.py index af2a758e..5c555217 100644 --- a/stats.py +++ b/stats.py @@ -1,7 +1,7 @@ """CMDR Status information.""" import csv from sys import platform -from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, Sequence, Tuple, cast +from typing import NamedTuple, TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, Sequence, Tuple, Union, cast if TYPE_CHECKING: from EDMarketConnector import AppWindow @@ -184,15 +184,25 @@ def export_status(data: Dict[str, Any], filename: AnyStr) -> None: :param data: The data to generate the file from :param filename: The target file """ - # TODO: Context manager - h = csv.writer(open(filename, 'w')) - h.writerow(['Category', 'Value']) - for thing in status(data): - h.writerow(list(thing)) + with open(filename, 'w') as f: + h = csv.writer(f) + h.writerow(('Category', 'Value')) + for thing in status(data): + h.writerow(list(thing)) -def ships(companion_data: Dict[str, Any]) -> List[Tuple[str, str, str, str, str, str]]: - # TODO: Replace this with a NamedTuple +class ShipRet(NamedTuple): + """ShipRet is a NamedTuple containing the return data from stats.ships.""" + + id: str + type: str + name: str + system: str + station: str + value: str + + +def ships(companion_data: Dict[str, Any]) -> List[ShipRet]: """ Return a list of 5 tuples of ship information. @@ -206,40 +216,37 @@ def ships(companion_data: Dict[str, Any]) -> List[Tuple[str, str, str, str, str, ships.insert(0, ships.pop(current)) # Put current ship first if not companion_data['commander'].get('docked'): - out: List[Tuple[str, str, str, str, str, str]] = [] + out: List[ShipRet] = [] # Set current system, not last docked - out.append( - ( - str(ships[0]['id']), - ship_map.get(ships[0]['name'].lower(), ships[0]['name']), - str(ships[0].get('shipName', '')), - companion_data['lastSystem']['name'], - '', - str(ships[0]['value']['total']) - ) - ) - + out.append(ShipRet( + id=str(ships[0]['id']), + type=ship_map.get(ships[0]['name'].lower(), ships[0]['name']), + name=str(ships[0].get('shipName', '')), + system=companion_data['lastSystem']['name'], + station='', + value=str(ships[0]['value']['total']) + )) out.extend( - ( - str(ship['id']), - ship_map.get(ship['name'].lower(), ship['name']), - ship.get('shipName', ''), - ship['starsystem']['name'], - ship['station']['name'], - str(ship['value']['total']) + ShipRet( + id=str(ship['id']), + type=ship_map.get(ship['name'].lower(), ship['name']), + name=ship.get('shipName', ''), + system=ship['starsystem']['name'], + station=ship['station']['name'], + value=str(ship['value']['total']) ) for ship in ships[1:] if ship ) return out return [ - ( - str(ship['id']), - ship_map.get(ship['name'].lower(), ship['name']), - ship.get('shipName', ''), - ship['starsystem']['name'], - ship['station']['name'], - str(ship['value']['total']) + ShipRet( + id=str(ship['id']), + type=ship_map.get(ship['name'].lower(), ship['name']), + name=ship.get('shipName', ''), + system=ship['starsystem']['name'], + station=ship['station']['name'], + value=str(ship['value']['total']) ) for ship in ships if ship is not None ] @@ -251,11 +258,11 @@ def export_ships(companion_data: Dict[str, Any], filename: AnyStr) -> None: :param companion_data: Data from which to generate the ship list :param filename: The target file """ - # TODO: context manager - h = csv.writer(open(filename, 'w')) - h.writerow(['Id', 'Ship', 'Name', 'System', 'Station', 'Value']) - for thing in ships(companion_data): - h.writerow(list(thing)) + with open(filename, 'w') as f: + h = csv.writer(f) + h.writerow(['Id', 'Ship', 'Name', 'System', 'Station', 'Value']) + for thing in ships(companion_data): + h.writerow(list(thing)) class StatsDialog(): From ecd13b094bc9a4ff3c9f125f77088677acddf1f3 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 9 Oct 2020 17:24:14 +0200 Subject: [PATCH 083/727] Removed mutable default --- stats.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stats.py b/stats.py index 5c555217..436dc0c0 100644 --- a/stats.py +++ b/stats.py @@ -394,16 +394,18 @@ class StatsResults(tk.Toplevel): ): self.geometry(f"+{position.left}+{position.top}") - def addpage(self, parent, header: List[str] = [], align: Optional[str] = None) -> tk.Frame: - # TODO: mutable defaults is no beauno. + def addpage(self, parent, header: List[str] = None, align: Optional[str] = None) -> tk.Frame: """ Add a page to the StatsResults screen. :param parent: The parent widget to put this under - :param header: The headers for the table, defaults to [] + :param header: The headers for the table, defaults to an empty list :param align: Alignment to use for this page, defaults to None :return: The Frame that was created """ + if header is None: + header = [] + page = nb.Frame(parent) page.grid(pady=10, sticky=tk.NSEW) page.columnconfigure(0, weight=1) From 7f5bfa36f0a3130ebfac6da74ab8d3f088eaea0f Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 9 Oct 2020 23:27:58 +0200 Subject: [PATCH 084/727] added logging of exception --- stats.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stats.py b/stats.py index 436dc0c0..1c126d30 100644 --- a/stats.py +++ b/stats.py @@ -6,9 +6,6 @@ from typing import NamedTuple, TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, if TYPE_CHECKING: from EDMarketConnector import AppWindow -if __debug__: - from traceback import print_exc - import tkinter as tk from tkinter import ttk @@ -17,6 +14,9 @@ import myNotebook as nb # noqa: N813 from companion import ship_map from l10n import Locale from monitor import monitor +import EDMCLogging + +logger = EDMCLogging.get_main_logger() if TYPE_CHECKING: def _(x: str) -> str: ... @@ -289,8 +289,7 @@ class StatsDialog(): return except Exception as e: - if __debug__: - print_exc() + logger.exception("error while attempting to show status") self.status['text'] = str(e) return From 2819c9200608e1a4c9f0ebacdb8a62d0a5507d89 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 12 Oct 2020 19:52:31 +0200 Subject: [PATCH 085/727] Removed tabs --- stats.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stats.py b/stats.py index 1c126d30..4d90229d 100644 --- a/stats.py +++ b/stats.py @@ -268,9 +268,9 @@ def export_ships(companion_data: Dict[str, Any], filename: AnyStr) -> None: class StatsDialog(): """Status dialog containing all of the current cmdr's stats.""" - def __init__(self, app: 'AppWindow') -> None: - self.parent: tk.Tk = app.w - self.status = app.status + def __init__(self, parent: tk.Tk, status: tk.Label) -> None: + self.parent: tk.Tk = parent + self.status = status self.showstats() def showstats(self) -> None: @@ -294,7 +294,7 @@ class StatsDialog(): return if not data.get('commander') or not data['commander'].get('name', '').strip(): - self.status['text'] = _("Who are you?!") # Shouldn't happen + self.status['text'] = _("Who are you?!") # Shouldn't happen elif ( not data.get('lastSystem') @@ -302,7 +302,7 @@ class StatsDialog(): or not data.get('lastStarport') or not data['lastStarport'].get('name', '').strip() ): - self.status['text'] = _("Where are you?!") # Shouldn't happen + self.status['text'] = _("Where are you?!") # Shouldn't happen elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name', '').strip(): self.status['text'] = _("What are you flying?!") # Shouldn't happen @@ -351,15 +351,15 @@ class StatsResults(tk.Toplevel): for thing in stats[3:]: self.addpagerow(page, thing) - ttk.Frame(page).grid(pady=5) # bottom spacer - notebook.add(page, text=_('Status')) # Status dialog title + ttk.Frame(page).grid(pady=5) # bottom spacer + notebook.add(page, text=_('Status')) # Status dialog title page = self.addpage(notebook, [ - _('Ship'), # Status dialog subtitle + _('Ship'), # Status dialog subtitle '', _('System'), # Main window _('Station'), # Status dialog subtitle - _('Value'), # Status dialog subtitle - CR value of ship + _('Value'), # Status dialog subtitle - CR value of ship ]) shiplist = ships(data) @@ -367,8 +367,8 @@ class StatsResults(tk.Toplevel): # skip id, last item is money self.addpagerow(page, list(ship_data[1:-1]) + [self.credits(int(ship_data[-1]))]) - ttk.Frame(page).grid(pady=5) # bottom spacer - notebook.add(page, text=_('Ships')) # Status dialog title + ttk.Frame(page).grid(pady=5) # bottom spacer + notebook.add(page, text=_('Ships')) # Status dialog title if platform != 'darwin': buttonframe = ttk.Frame(frame) From fe26359170336b3f177447e1fd2b80209d76a614 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 12 Oct 2020 19:54:30 +0200 Subject: [PATCH 086/727] passed only what was needed to StatsDialog passing the entire AppWindow just made a mess of typing --- EDMarketConnector.py | 7 +++---- stats.py | 10 +++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index fc95a2ff..2d1104e5 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -386,7 +386,7 @@ class AppWindow(object): self.menubar.add_cascade(menu=self.edit_menu) self.w.bind('', self.copy) self.view_menu = tk.Menu(self.menubar, name='view') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 - self.view_menu.add_command(command=lambda: stats.StatsDialog(self)) + self.view_menu.add_command(command=lambda: stats.StatsDialog(self.w, self.status)) self.menubar.add_cascade(menu=self.view_menu) window_menu = tk.Menu(self.menubar, name='window') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.menubar.add_cascade(menu=window_menu) @@ -404,10 +404,9 @@ class AppWindow(object): self.w.createcommand("::tk::mac::ReopenApplication", self.w.deiconify) # click on app in dock = restore self.w.protocol("WM_DELETE_WINDOW", self.w.withdraw) # close button shouldn't quit app self.w.resizable(tk.FALSE, tk.FALSE) # Can't be only resizable on one axis - - else: # win32 or linux + else: self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=tk.FALSE) # type: ignore - self.file_menu.add_command(command=lambda: stats.StatsDialog(self)) + self.file_menu.add_command(command=lambda: stats.StatsDialog(self.w, self.status)) self.file_menu.add_command(command=self.save_raw) self.file_menu.add_command(command=lambda: prefs.PreferencesDialog(self.w, self.postprefs)) self.file_menu.add_separator() diff --git a/stats.py b/stats.py index 4d90229d..4f05b538 100644 --- a/stats.py +++ b/stats.py @@ -1,20 +1,16 @@ """CMDR Status information.""" import csv -from sys import platform -from typing import NamedTuple, TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, Sequence, Tuple, Union, cast - -if TYPE_CHECKING: - from EDMarketConnector import AppWindow - import tkinter as tk +from sys import platform from tkinter import ttk +from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, NamedTuple, Optional, Sequence, cast import companion +import EDMCLogging import myNotebook as nb # noqa: N813 from companion import ship_map from l10n import Locale from monitor import monitor -import EDMCLogging logger = EDMCLogging.get_main_logger() From 18c0ea82a01818416c504b624a86c1779ffcebb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2020 06:38:01 +0000 Subject: [PATCH 087/727] Bump isort from 5.6.3 to 5.6.4 Bumps [isort](https://github.com/pycqa/isort) from 5.6.3 to 5.6.4. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.6.3...5.6.4) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 3ce38021..40ffd612 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.2.3 flake8-docstrings==1.5.0 -isort==5.6.3 +isort==5.6.4 flake8-isort==4.0.0 flake8-json==19.8.0 flake8-noqa==1.0.5 From ddb53a6ca1584227a23e6a8b78c4839519ddc77a Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 16 Oct 2020 08:48:20 +0200 Subject: [PATCH 088/727] Added type checker magic to make TRACE work Relatively simple. Because all of our loggers are created out of EDMCLogging, we can create a fake type in EDMCLogging that inherits from logging.Logger but also defines a trace method. Once that is done, we just have to annotate our methods to get loggers with the new type, cast all of the returns, and suddenly we no longer have any complaints about logger.trace. This doesn't _actually_ change any behaviour at runtime, and logging.Logger.trace and logging.TRACE will continue to be broken, but those are used far less than logger.trace is used throughout the codebase, and therefore I think we can live with `# type: ignore` comments everywhere --- EDMCLogging.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index c0898941..b52c0ab7 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -43,7 +43,7 @@ import pathlib import tempfile # So that any warning about accessing a protected member is only in one place. from sys import _getframe as getframe -from typing import Tuple +from typing import TYPE_CHECKING, Tuple, cast from config import appcmdname, appname, config @@ -83,6 +83,15 @@ logging.Logger.trace = lambda self, message, *args, **kwargs: self._log( # type **kwargs ) +if TYPE_CHECKING: + # Fake type that we can use here to tell type checkers that trace exists + class LoggerMixin(logging.Logger): + """LoggerMixin is a fake class that tells type checkers that trace exists on a given type.""" + + def trace(self, message, *args, **kwargs) -> None: + """Fake trace method.""" + return self._log(LEVEL_TRACE, message, args, **kwargs) + class Logger: """ @@ -147,13 +156,13 @@ class Logger: self.logger_channel_rotating.setFormatter(self.logger_formatter) self.logger.addHandler(self.logger_channel_rotating) - def get_logger(self) -> logging.Logger: + def get_logger(self) -> 'LoggerMixin': """ Obtain the self.logger of the class instance. Not to be confused with logging.getLogger(). """ - return self.logger + return cast('LoggerMixin', self.logger) def get_streamhandler(self) -> logging.Handler: """ @@ -186,7 +195,7 @@ class Logger: logger.trace("Not changing log level because it's TRACE") # type: ignore -def get_plugin_logger(plugin_name: str, loglevel: int = _default_loglevel) -> logging.Logger: +def get_plugin_logger(plugin_name: str, loglevel: int = _default_loglevel) -> 'LoggerMixin': """ Return a logger suitable for a plugin. @@ -222,7 +231,7 @@ def get_plugin_logger(plugin_name: str, loglevel: int = _default_loglevel) -> lo plugin_logger.addFilter(EDMCContextFilter()) - return plugin_logger + return cast('LoggerMixin', plugin_logger) class EDMCContextFilter(logging.Filter): @@ -449,14 +458,14 @@ class EDMCContextFilter(logging.Filter): return module_name -def get_main_logger() -> logging.Logger: +def get_main_logger() -> 'LoggerMixin': """Return the correct logger for how the program is being run.""" if not os.getenv("EDMC_NO_UI"): # GUI app being run - return logging.getLogger(appname) + return cast('LoggerMixin', logging.getLogger(appname)) else: # Must be the CLI - return logging.getLogger(appcmdname) + return cast(LoggerMixin, logging.getLogger(appcmdname)) # Singleton @@ -470,4 +479,4 @@ else: base_logger_name = appcmdname edmclogger = Logger(base_logger_name, loglevel=loglevel) -logger = edmclogger.get_logger() +logger: 'LoggerMixin' = edmclogger.get_logger() From 7efd1a5aaa69399af4a733d6114901a897d87c91 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Oct 2020 20:51:15 +0100 Subject: [PATCH 089/727] EDMarketConnector: Log when we exit because 'already running' --- EDMarketConnector.py | 1 + 1 file changed, 1 insertion(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 2d1104e5..485c5553 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1374,6 +1374,7 @@ def enforce_single_instance() -> None: # noqa: CCR001 ShowWindowAsync(window_handle, SW_RESTORE) SetForegroundWindow(window_handle) + logger.info(f'A running {applongname} process was found, exiting.') sys.exit(0) return True From 4c9cf9ed659df6f08c9c7e328d756413913a3595 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:53:56 +0000 Subject: [PATCH 090/727] Logging: Add osthreadid, and add process, thread and osthreadid to format * It looks like in Python 3.8 the %(thread)d is the native OS thread ID anyway, but let's keep osthreadid anyway. --- EDMCLogging.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index b52c0ab7..8445a9fe 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -43,7 +43,8 @@ import pathlib import tempfile # So that any warning about accessing a protected member is only in one place. from sys import _getframe as getframe -from typing import TYPE_CHECKING, Tuple, cast +from threading import get_native_id as thread_native_id +from typing import Tuple from config import appcmdname, appname, config @@ -127,7 +128,7 @@ class Logger: # This should be affected by the user configured log level self.logger_channel.setLevel(loglevel) - self.logger_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(module)s.%(qualname)s:%(lineno)d: %(message)s') # noqa: E501 + self.logger_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(process)d:%(thread)d:%(osthreadid)d %(module)s.%(qualname)s:%(lineno)d: %(message)s') # noqa: E501 self.logger_formatter.default_time_format = '%Y-%m-%d %H:%M:%S' self.logger_formatter.default_msec_format = '%s.%03d' @@ -251,6 +252,7 @@ class EDMCContextFilter(logging.Filter): logging.Formatter() as you can use just this no matter if there is a class involved or not, so you get a nice clean: .[.classB....]. + 3. osthreadid = OS level thread ID. If we fail to be able to properly set either then: @@ -275,10 +277,12 @@ class EDMCContextFilter(logging.Filter): if getattr(record, 'qualname', None) is None: setattr(record, 'qualname', qualname) + setattr(record, 'osthreadid', thread_native_id()) + return True - @classmethod # noqa: CCR001 - this is as refactored as is sensible - def caller_attributes(cls, module_name: str = '') -> Tuple[str, str, str]: + @classmethod + def caller_attributes(cls, module_name: str = '') -> Tuple[str, str, str]: # noqa: CCR001, E501 # this is as refactored as is sensible """ Determine extra or changed fields for the caller. From 45ab19b6b1ef5893a8c7978266cb50ebe5d77b0c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Oct 2020 12:21:15 +0100 Subject: [PATCH 091/727] Log when we detect browser running us again to pass Auth response. --- EDMarketConnector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 485c5553..8d581c35 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1364,7 +1364,8 @@ def enforce_single_instance() -> None: # noqa: CCR001 and GetProcessHandleFromHwnd(window_handle): # If GetProcessHandleFromHwnd succeeds then the app is already running as this user if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): - # Browser invoked us directly with auth response. Forward the response to the other app instance. + logger.debug('Browser invoked us directly with auth response. ' + 'Forwarding the response to the other app instance.') CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) # Wait for it to be responsive to avoid ShellExecute recursing ShowWindow(window_handle, SW_RESTORE) From d0ee0b114839e7ed4305a6bf894ae9382c695c02 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:55:07 +0000 Subject: [PATCH 092/727] EDMarketConnector: Add detailed logging to shutdown sequence --- EDMarketConnector.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 8d581c35..08070efb 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1225,46 +1225,39 @@ class AppWindow(object): config.set('geometry', f'+{x}+{y}') # Let the user know we're shutting down. - self.status['text'] = _('Shutting down...') + self.status['text'] = 'Shutting down...' self.w.update_idletasks() logger.info('Starting shutdown procedures...') - # First so it doesn't interrupt us - logger.info('Closing update checker...') - self.updater.close() + logger.info('Closing protocol handler...') + protocolhandler.close() - # Earlier than anything else so plugin code can't interfere *and* it - # won't still be running in a manner that might rely on something - # we'd otherwise have already stopped. - logger.info('Notifying plugins to stop...') - plug.notify_stop() - - # Handling of application hotkeys now so the user can't possible cause - # an issue via triggering one. logger.info('Unregistering hotkey manager...') hotkeymgr.unregister() - # Now the main programmatic input methods logger.info('Closing dashboard...') dashboard.close() logger.info('Closing journal monitor...') monitor.close() - # Frontier auth/CAPI handling - logger.info('Closing protocol handler...') - protocolhandler.close() + logger.info('Notifying plugins to stop...') + plug.notify_stop() + + logger.info('Closing update checker...') + self.updater.close() logger.info('Closing Frontier CAPI sessions...') companion.session.close() - # Now anything else. logger.info('Closing config...') config.close() logger.info('Destroying app window...') self.w.destroy() + logger.info('Done.') + def drag_start(self, event) -> None: """Initiate dragging the window.""" self.drag_offset = (event.x_root - self.w.winfo_rootx(), event.y_root - self.w.winfo_rooty()) From d5b2f32d1889c788fb4b720fd17f2c58fb6ac6da Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:56:02 +0000 Subject: [PATCH 093/727] protocol.py: Add logging to protocol shutdown sequence # Conflicts: # protocol.py --- protocol.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/protocol.py b/protocol.py index dcaa8b99..5fe41bb6 100644 --- a/protocol.py +++ b/protocol.py @@ -1,15 +1,19 @@ # edmc: protocol handler for cAPI authorisation +import logging import threading import urllib.request, urllib.error, urllib.parse import sys +from os import getenv -from config import appname, config -from constants import protocolhandler_redirect -from EDMCLogging import get_main_logger +from config import appname, appcmdname -logger = get_main_logger() +if getenv("EDMC_NO_UI"): + logger = logging.getLogger(appcmdname) + +else: + logger = logging.getLogger(appname) if sys.platform == 'win32': from ctypes import * @@ -237,10 +241,18 @@ else: # Linux / Run from source def close(self): thread = self.thread if thread: + logger.debug('Thread') self.thread = None + if self.httpd: + logger.info('Shutting down httpd') self.httpd.shutdown() - thread.join() # Wait for it to quit + + logger.info('Joining thread') + thread.join() # Wait for it to quit + + else: + logger.debug('No thread') def worker(self): self.httpd.serve_forever() From c5a57e8a438cb342aa324962413eba4d41cd2acc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Oct 2020 13:12:44 +0100 Subject: [PATCH 094/727] protocol.py: Log *end* of protocolhandler.close() --- protocol.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protocol.py b/protocol.py index 5fe41bb6..aa0ffeee 100644 --- a/protocol.py +++ b/protocol.py @@ -254,6 +254,8 @@ else: # Linux / Run from source else: logger.debug('No thread') + logger.debug('Done') + def worker(self): self.httpd.serve_forever() From a47b9cfa8d461e13748d39bc54fd817120e4f3d4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Oct 2020 14:33:20 +0100 Subject: [PATCH 095/727] hotkey: Detailed logging in HotKeyMgr.unregister() --- hotkey.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/hotkey.py b/hotkey.py index 9b261ccc..10bfa831 100644 --- a/hotkey.py +++ b/hotkey.py @@ -1,11 +1,17 @@ # -*- coding: utf-8 -*- -import os -from os.path import dirname, join, normpath -import sys +import logging +from os import getenv +from os.path import join from sys import platform -from config import config +from config import appcmdname, appname, config + +if getenv("EDMC_NO_UI"): + logger = logging.getLogger(appcmdname) + +else: + logger = logging.getLogger(appname) if platform == 'darwin': @@ -296,19 +302,31 @@ elif platform == 'win32': def register(self, root, keycode, modifiers): self.root = root + if self.thread: self.unregister() + if keycode or modifiers: self.thread = threading.Thread(target = self.worker, name = 'Hotkey "%x:%x"' % (keycode,modifiers), args = (keycode,modifiers)) self.thread.daemon = True self.thread.start() def unregister(self): + """Unregister the hotkey handling.""" thread = self.thread + if thread: + logger.debug('Thread is/was running') self.thread = None + logger.debug('Telling thread WM_QUIT') PostThreadMessage(thread.ident, WM_QUIT, 0, 0) - thread.join() # Wait for it to unregister hotkey and quit + logger.debug('Joining thread') + thread.join() # Wait for it to unregister hotkey and quit + + else: + logger.debug('No thread') + + logger.debug('Done.') def worker(self, keycode, modifiers): From 9cff84327db21b116c0ea3e5b03b48243435117a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Oct 2020 14:36:28 +0100 Subject: [PATCH 096/727] hotkey: Detailed logging in HotKeyMgr.register() --- hotkey.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hotkey.py b/hotkey.py index 10bfa831..7ee96cdc 100644 --- a/hotkey.py +++ b/hotkey.py @@ -301,15 +301,20 @@ elif platform == 'win32': atexit.register(self.unregister) def register(self, root, keycode, modifiers): + """Register the hotkey handler.""" self.root = root if self.thread: + logger.debug('Was already registered, unregistering...') self.unregister() if keycode or modifiers: - self.thread = threading.Thread(target = self.worker, name = 'Hotkey "%x:%x"' % (keycode,modifiers), args = (keycode,modifiers)) + logger.debug('Creating thread worker...') + self.thread = threading.Thread(target=self.worker, name=f'Hotkey "{keycode}:{modifiers}"', args=(keycode, modifiers)) self.thread.daemon = True + logger.debug('Starting thread worker...') self.thread.start() + logger.debug('Done.') def unregister(self): """Unregister the hotkey handling.""" From 99e2dfb62a49c817603aae73dfa48bde68a7b04d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:56:51 +0000 Subject: [PATCH 097/727] hotkey: Detailed logging in HotKeyMgr.worker() # Conflicts: # hotkey.py --- hotkey.py | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/hotkey.py b/hotkey.py index 7ee96cdc..3e677851 100644 --- a/hotkey.py +++ b/hotkey.py @@ -194,7 +194,7 @@ elif platform == 'win32': import atexit import ctypes - from ctypes.wintypes import * + from ctypes.wintypes import DWORD, HWND, LONG, LPWSTR, MSG, ULONG, WORD import threading import winsound @@ -334,37 +334,55 @@ elif platform == 'win32': logger.debug('Done.') def worker(self, keycode, modifiers): - + """Handle hotkeys.""" + logger.debug('Begin...') # Hotkey must be registered by the thread that handles it - if not RegisterHotKey(None, 1, modifiers|MOD_NOREPEAT, keycode): + if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode): + logger.debug("We're not the right thread?") self.thread = None return - fake = INPUT(INPUT_KEYBOARD, INPUT_union(ki = KEYBDINPUT(keycode, keycode, 0, 0, None))) + fake = INPUT(INPUT_KEYBOARD, INPUT_union(ki=KEYBDINPUT(keycode, keycode, 0, 0, None))) msg = MSG() + logger.debug('Entering GetMessage() loop...') while GetMessage(ctypes.byref(msg), None, 0, 0) != 0: + logger.debug('Got message') if msg.message == WM_HOTKEY: - if config.getint('hotkey_always') or WindowTitle(GetForegroundWindow()).startswith('Elite - Dangerous'): - if not config.shutting_down: - self.root.event_generate('<>', when="tail") + logger.debug('WM_HOTKEY') + + if ( + config.getint('hotkey_always') + or WindowTitle(GetForegroundWindow()).startswith('Elite - Dangerous') + ): + logger.debug('Sending event <>') + self.root.event_generate('<>', when="tail") + else: - # Pass the key on + logger.debug('Passing key on') UnregisterHotKey(None, 1) SendInput(1, fake, ctypes.sizeof(INPUT)) - if not RegisterHotKey(None, 1, modifiers|MOD_NOREPEAT, keycode): + if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode): + logger.debug("We aren't registered for this ?") break elif msg.message == WM_SND_GOOD: - winsound.PlaySound(self.snd_good, winsound.SND_MEMORY) # synchronous + logger.debug('WM_SND_GOOD') + winsound.PlaySound(self.snd_good, winsound.SND_MEMORY) # synchronous + elif msg.message == WM_SND_BAD: - winsound.PlaySound(self.snd_bad, winsound.SND_MEMORY) # synchronous + logger.debug('WM_SND_BAD') + winsound.PlaySound(self.snd_bad, winsound.SND_MEMORY) # synchronous + else: + logger.debug('Something else') TranslateMessage(ctypes.byref(msg)) DispatchMessage(ctypes.byref(msg)) + logger.debug('Exited GetMessage() loop.') UnregisterHotKey(None, 1) self.thread = None + logger.debug('Done.') def acquire_start(self): pass From fd19ac337ada30a5c5c4910a1dfcc108741117fb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:57:46 +0000 Subject: [PATCH 098/727] dashboard: Detailed logging Dashboard .stop() & .close() # Conflicts: # dashboard.py --- dashboard.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/dashboard.py b/dashboard.py index 4259dccb..06d05826 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,13 +1,20 @@ import json from calendar import timegm +from os import getenv from os.path import isdir, isfile, join, getsize from sys import platform import time -from config import config -from EDMCLogging import get_main_logger +if __debug__: + from traceback import print_exc -logger = get_main_logger() +from config import appcmdname, appname, config + +if getenv("EDMC_NO_UI"): + logger = logging.getLogger(appcmdname) + +else: + logger = logging.getLogger(appname) if platform=='darwin': from watchdog.observers import Observer @@ -77,22 +84,38 @@ class Dashboard(FileSystemEventHandler): return True def stop(self): + """Stop monitoring dashboard.""" logger.debug('Stopping monitoring Dashboard') - self.currentdir = None + if self.observed: + logger.debug('Was observed') self.observed = None + logger.debug('Unscheduling all observer') self.observer.unschedule_all() + logger.debug('Done.') + self.status = {} + logger.debug('Done.') def close(self): + """Close down dashboard.""" + logger.debug('Calling self.stop()') self.stop() + if self.observer: + logger.debug('Calling self.observer.stop()') self.observer.stop() + logger.debug('Done') + if self.observer: + logger.debug('Joining self.observer...') self.observer.join() + logger.debug('Done') self.observer = None + logger.debug('Done.') + def poll(self, first_time=False): if not self.currentdir: # Stopped From 137c66048a46b151aee3d9f93a3d878992022723 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:58:26 +0000 Subject: [PATCH 099/727] dashboard: Remove print_exc use (logger.exception instead) # Conflicts: # dashboard.py --- dashboard.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dashboard.py b/dashboard.py index 06d05826..123046dc 100644 --- a/dashboard.py +++ b/dashboard.py @@ -5,9 +5,6 @@ from os.path import isdir, isfile, join, getsize from sys import platform import time -if __debug__: - from traceback import print_exc - from config import appcmdname, appname, config if getenv("EDMC_NO_UI"): @@ -32,7 +29,7 @@ else: # Status.json handler class Dashboard(FileSystemEventHandler): - _POLL = 1 # Fallback polling interval + _POLL = 1 # Fallback polling interval def __init__(self): FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog @@ -144,17 +141,20 @@ class Dashboard(FileSystemEventHandler): try: with open(join(self.currentdir, 'Status.json'), 'rb') as h: data = h.read().strip() - if data: # Can be empty if polling while the file is being re-written + + if data: # Can be empty if polling while the file is being re-written entry = json.loads(data) # Status file is shared between beta and live. So filter out status not in this game session. - if (timegm(time.strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ')) >= self.session_start and - self.status != entry): + if ( + timegm(time.strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ')) >= self.session_start + and self.status != entry + ): self.status = entry self.root.event_generate('<>', when="tail") - except Exception: - logger.exception('Reading Status.json') + except Exception as e: + logger.exception('Processing Status.json') # singleton dashboard = Dashboard() From c47688227bfb7122dac57d03fbab0b1e536203b5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:59:15 +0000 Subject: [PATCH 100/727] dashboard: Detailed logging Dashboard.start() # Conflicts: # dashboard.py --- dashboard.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dashboard.py b/dashboard.py index 123046dc..dc0dcd15 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,4 +1,5 @@ import json +import logging from calendar import timegm from os import getenv from os.path import isdir, isfile, join, getsize @@ -40,16 +41,21 @@ class Dashboard(FileSystemEventHandler): self.status = {} # Current status for communicating status back to main thread def start(self, root, started): + """Start monitoring of Journal directory.""" + logger.debug('Starting...') self.root = root self.session_start = started logdir = config.get('journaldir') or config.default_journal_dir if not logdir or not isdir(logdir): + logger.info(f"No logdir, or it isn't a directory: {logdir=}") self.stop() return False if self.currentdir and self.currentdir != logdir: + logger.debug(f"{self.currentdir=} != {logdir=}") self.stop() + self.currentdir = logdir # Set up a watchdog observer. @@ -58,25 +64,31 @@ class Dashboard(FileSystemEventHandler): # any non-standard logdir might be on a network drive and poll instead. polling = platform != 'win32' if not polling and not self.observer: + logger.debug('Setting up observer...') self.observer = Observer() self.observer.daemon = True self.observer.start() + logger.debug('Done') + elif polling and self.observer: + logger.debug('Using polling, stopping observer...') self.observer.stop() self.observer = None + logger.debug('Done') if not self.observed and not polling: + logger.debug('Starting observer...') self.observed = self.observer.schedule(self, self.currentdir) + logger.debug('Done') - if polling: - logger.debug(f'Polling Dashboard "{self.currentdir}"') - else: - logger.debug(f'Monitoring Dashboard "{self.currentdir}"') + logger.info(f'{polling and "Polling" or "Monitoring"} Dashboard "{self.currentdir}"') # Even if we're not intending to poll, poll at least once to process pre-existing # data and to check whether the watchdog thread has crashed due to events not # being supported on this filesystem. + logger.debug('Polling once to process pre-existing data, and check whether watchdog thread crashed...') self.root.after(int(self._POLL * 1000/2), self.poll, True) + logger.debug('Done.') return True From 7ebf2a553adaf8c2a1fb132e70b358a4cc0e0adc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Oct 2020 15:12:18 +0100 Subject: [PATCH 101/727] monitor: Detailed logging EDLogs.close() --- monitor.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 8dc4b4ca..ad182314 100644 --- a/monitor.py +++ b/monitor.py @@ -214,13 +214,23 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.thread = None # Orphan the worker thread - will terminate at next poll def close(self): + """Close journal monitoring.""" + logger.debug('Calling self.stop()...') self.stop() - if self.observer: - self.observer.stop() + logger.debug('Done') if self.observer: + logger.debug('Calling self.observer.stop()...') + self.observer.stop() + logger.debug('Done') + + if self.observer: + logger.debug('Joining self.observer thread...') self.observer.join() self.observer = None + logger.debug('Done') + + logger.debug('Done.') def running(self): return self.thread and self.thread.is_alive() From 4a84d9c3416f2f3bec50aaca51ef690d20530652 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 12:59:58 +0000 Subject: [PATCH 102/727] monitor: Detailed logging EDLogs.stop() # Conflicts: # monitor.py --- monitor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monitor.py b/monitor.py index ad182314..1d6a1c2b 100644 --- a/monitor.py +++ b/monitor.py @@ -191,6 +191,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return True def stop(self): + """Stop journal monitoring.""" logger.debug('Stopping monitoring Journal') self.currentdir = None @@ -207,12 +208,17 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.coordinates = None self.systemaddress = None self.is_beta = False + if self.observed: + logger.debug('self.observed: Calling unschedule_all()') self.observed = None self.observer.unschedule_all() + logger.debug('Done') self.thread = None # Orphan the worker thread - will terminate at next poll + logger.debug('Done.') + def close(self): """Close journal monitoring.""" logger.debug('Calling self.stop()...') From 9be7f14573c3716e64254c1424655caee7779a36 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 11:53:31 +0100 Subject: [PATCH 103/727] monitor.py: Detailed logging EDLogs.start() --- monitor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 1d6a1c2b..dc3c3fb7 100644 --- a/monitor.py +++ b/monitor.py @@ -126,10 +126,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below } def start(self, root: 'tkinter.Tk'): + """Start journal monitoring.""" + logger.debug('Begin...') self.root = root journal_dir = config.get('journaldir') or config.default_journal_dir if journal_dir is None: + logger.debug('journal_dir was None, setting ""') journal_dir = '' # TODO(A_D): this is ignored for type checking due to all the different types config.get returns @@ -168,26 +171,34 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # any non-standard logdir might be on a network drive and poll instead. polling = bool(config.get('journaldir')) and platform != 'win32' if not polling and not self.observer: + logger.debug('Not polling, no observer, starting an observer...') self.observer = Observer() self.observer.daemon = True self.observer.start() + logger.debug('Done') elif polling and self.observer: + logger.debug('Polling, but observer, so stopping observer...') self.observer.stop() self.observer = None + logger.debug('Done') if not self.observed and not polling: + logger.debug('Not observed and not polling, setting observed...') self.observed = self.observer.schedule(self, self.currentdir) + logger.debug('Done') logger.info(f'{"Polling" if polling else "Monitoring"} Journal Folder: "{self.currentdir}"') logger.info(f'Start Journal File: "{self.logfile}"') if not self.running(): - logger.debug('Starting Journal worker') + logger.debug('Starting Journal worker thread...') self.thread = threading.Thread(target=self.worker, name='Journal worker') self.thread.daemon = True self.thread.start() + logger.debug('Done') + logger.debug('Done.') return True def stop(self): From abfde733624951d6a9790553b2f96c4c9f9c5e62 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 11:53:47 +0100 Subject: [PATCH 104/727] dashboard, hotkey, protocol: Use EDMCLogging.get_main_logger() It does the EDMC/EDMarketConnector check. --- dashboard.py | 12 +++--------- hotkey.py | 11 +++-------- protocol.py | 12 +++--------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/dashboard.py b/dashboard.py index dc0dcd15..04cb7f15 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,18 +1,12 @@ import json -import logging -from calendar import timegm -from os import getenv from os.path import isdir, isfile, join, getsize from sys import platform import time -from config import appcmdname, appname, config +from config import config +from EDMCLogging import get_main_logger -if getenv("EDMC_NO_UI"): - logger = logging.getLogger(appcmdname) - -else: - logger = logging.getLogger(appname) +logger = get_main_logger() if platform=='darwin': from watchdog.observers import Observer diff --git a/hotkey.py b/hotkey.py index 3e677851..966975a4 100644 --- a/hotkey.py +++ b/hotkey.py @@ -1,17 +1,12 @@ # -*- coding: utf-8 -*- -import logging -from os import getenv from os.path import join from sys import platform -from config import appcmdname, appname, config +from config import config +from EDMCLogging import get_main_logger -if getenv("EDMC_NO_UI"): - logger = logging.getLogger(appcmdname) - -else: - logger = logging.getLogger(appname) +logger = get_main_logger() if platform == 'darwin': diff --git a/protocol.py b/protocol.py index aa0ffeee..0caa6a68 100644 --- a/protocol.py +++ b/protocol.py @@ -1,19 +1,13 @@ # edmc: protocol handler for cAPI authorisation -import logging import threading import urllib.request, urllib.error, urllib.parse import sys -from os import getenv -from config import appname, appcmdname +from EDMCLogging import get_main_logger -if getenv("EDMC_NO_UI"): - logger = logging.getLogger(appcmdname) - -else: - logger = logging.getLogger(appname) +logger = get_main_logger() if sys.platform == 'win32': from ctypes import * @@ -254,7 +248,7 @@ else: # Linux / Run from source else: logger.debug('No thread') - logger.debug('Done') + logger.debug('Done.') def worker(self): self.httpd.serve_forever() From 8b3785cdf7713ab4edd8421daf9bb829ad7089fb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 12:02:41 +0100 Subject: [PATCH 105/727] monitor.py: Detailed logging EDLogs.worker() --- monitor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index dc3c3fb7..94486d6e 100644 --- a/monitor.py +++ b/monitor.py @@ -286,6 +286,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below else: loghandle = None + logger.debug('Now at end of latest file.') + self.game_was_running = self.game_running() if self.live: @@ -321,6 +323,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # watch, but that may have unforseen differences in behaviour. emitter = self.observed and self.observer._emitter_for_watch[self.observed] # Note: Uses undocumented attribute + logger.debug('Entering loop...') while True: # Check whether new log file started, e.g. client (re)started. @@ -383,8 +386,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if self.game_was_running: if not self.game_running(): logger.info('Detected exit from game, synthesising ShutDown event') + timestamp = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) self.event_queue.append( - '{{ "timestamp":"{}", "event":"ShutDown" }}'.format(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())) + f'{{ "timestamp":"{timestamp}", "event":"ShutDown" }}' ) if not config.shutting_down: @@ -395,6 +399,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below else: self.game_was_running = self.game_running() + logger.debug('Done.') + def parse_entry(self, line: str): # TODO(A_D): a bunch of these can be simplified to use if itertools.product and filters if line is None: From 983e4d7acb6ac38d997adf14abcaca0b27632fbb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 12:07:09 +0100 Subject: [PATCH 106/727] plugins/eddn: Detailed stop logging. --- plugins/eddn.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 464eae46..223272db 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -111,13 +111,13 @@ class EDDN: self.replayfile.flush() def close(self): - """ - close closes the replay file - """ + """Close the replay file.""" + logger.debug('Closing replayfile...') if self.replayfile: self.replayfile.close() self.replayfile = None + logger.debug('Done.') def send(self, cmdr: str, msg: Mapping[str, Any]) -> None: """ @@ -619,7 +619,10 @@ def prefs_changed(cmdr: str, is_beta: bool) -> None: def plugin_stop() -> None: + """Handle stopping this plugin.""" + logger.debug('Calling this.eddn.close()') this.eddn.close() + logger.debug('Done.') def journal_entry( # noqa: C901 From 8aac704fa199dddf83a7adb577e775323ca8d786 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 12:13:06 +0100 Subject: [PATCH 107/727] plugins/edsm: start/stop detailed logging. --- plugins/edsm.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/edsm.py b/plugins/edsm.py index e9fbd46c..c9351148 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -143,9 +143,11 @@ def plugin_start3(plugin_dir: str) -> str: config.delete('edsm_autoopen') config.delete('edsm_historical') + logger.debug('Starting worker thread...') this.thread = Thread(target=worker, name='EDSM worker') this.thread.daemon = True this.thread.start() + logger.debug('Done.') return 'EDSM' @@ -158,13 +160,15 @@ def plugin_app(parent: tk.Tk) -> None: def plugin_stop() -> None: - """Plugin exit hook.""" + """Stop this plugin.""" + logger.debug('Signalling queue to close...') # Signal thread to close and wait for it this.queue.put(None) this.thread.join() this.thread = None # Suppress 'Exception ignored in: ' errors # TODO: this is bad. this._IMG_KNOWN = this._IMG_UNKNOWN = this._IMG_NEW = this._IMG_ERROR = None + logger.debug('Done.') def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame: @@ -485,10 +489,11 @@ def cmdr_data(data: Mapping[str, Any], is_beta: bool) -> None: # Worker thread def worker() -> None: """ - Upload worker. + Handle uploading events to EDSM API. Processes `this.queue` until the queued item is None. """ + logger.debug('Starting...') pending = [] # Unsent events closing = False @@ -496,7 +501,9 @@ def worker() -> None: item: Optional[Tuple[str, Mapping[str, Any]]] = this.queue.get() if item: (cmdr, entry) = item + else: + logger.debug('Empty queue message, setting closing = True') closing = True # Try to send any unsent events before we close retrying = 0 @@ -618,8 +625,11 @@ def worker() -> None: plug.show_error(_("Error: Can't connect to EDSM")) if closing: + logger.debug('closing, so returning.') return + logger.debug('Done.') + def should_send(entries: List[Mapping[str, Any]]) -> bool: """ From 9b09d8bd07142a398b41482e8e270f952ba11b23 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 12:50:19 +0100 Subject: [PATCH 108/727] plugins/inara: Close down logging & Remove unused this.queue. * The new_worker/NewThis doesn't currently have a mechanism to ask the new_worker to exit. It's relying on being a daemon thread and dying once all non-daemon (i.e. main) threads have exited. --- plugins/inara.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 47eaf6dd..576383aa 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -5,10 +5,8 @@ import json import sys import time import tkinter as tk -# For new impl from collections import OrderedDict, defaultdict, deque from operator import itemgetter -from queue import Queue from threading import Lock, Thread from typing import ( TYPE_CHECKING, Any, AnyStr, Callable, Deque, Dict, List, Mapping, MutableMapping, NamedTuple, Optional @@ -39,7 +37,6 @@ CREDIT_RATIO = 1.05 # Update credits if they change by 5% over the course of a this: Any = sys.modules[__name__] # For holding module globals this.session = timeout_session.new_session() -this.queue = Queue() # Items to be sent to Inara by worker thread this.lastlocation = None # eventData from the last Commander's Flight Log event this.lastship = None # eventData from the last addCommanderShip or setCommanderShip event @@ -164,10 +161,16 @@ def station_url(system_name: str, station_name: str) -> str: def plugin_start3(plugin_dir: str) -> str: - """Plugin start Hook.""" + """ + Start this plugin. + + Start the worker thread to handle sending to Inara API. + """ + logger.debug('Starting worker thread...') this.thread = Thread(target=new_worker, name='Inara worker') this.thread.daemon = True this.thread.start() + logger.debug('Done.') return 'Inara' @@ -182,13 +185,15 @@ def plugin_app(parent: tk.Tk) -> None: def plugin_stop() -> None: """Plugin shutdown hook.""" - # Signal thread to close and wait for it - this.queue.put(None) - # this.thread.join() - # this.thread = None + logger.debug('We have no way to ask new_worker to stop, but...') + # The Newthis/new_worker doesn't have a method to ask the new_worker to + # stop. We're relying on it being a daemon thread and thus exiting when + # there are no non-daemon (i.e. main) threads running. this.timer_run = False + logger.debug('Done.') + def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame: """Plugin Preferences UI hook.""" @@ -1189,12 +1194,14 @@ def new_add_event( def new_worker(): """ - Queue worker. + Handle sending events to the Inara API. Will only ever send one message per WORKER_WAIT_TIME, regardless of status. """ + logger.debug('Starting...') while True: events = get_events() + for creds, event_list in events.items(): if not event_list: continue @@ -1216,6 +1223,8 @@ def new_worker(): time.sleep(WORKER_WAIT_TIME) + logger.debug('Done.') + def get_events(clear: bool = True) -> Dict[Credentials, List[Event]]: """ From 404f1fa641554b25e4431e2a0d161417268018eb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 19:57:16 +0100 Subject: [PATCH 109/727] dashboard: No need for except var if unused. --- dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard.py b/dashboard.py index 04cb7f15..f117514b 100644 --- a/dashboard.py +++ b/dashboard.py @@ -159,7 +159,7 @@ class Dashboard(FileSystemEventHandler): self.status = entry self.root.event_generate('<>', when="tail") - except Exception as e: + except Exception: logger.exception('Processing Status.json') # singleton From 3a57128e287e4c551a82b260faa940b7f0a9bfcd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 20:00:03 +0100 Subject: [PATCH 110/727] EDMarketConnector: Care about "are we already running?" check 1) Don't log in this check, we're a different process. 2) But we've stomped the plain log file already! 3) Python 3.8.6 seems to not like sys.exit(0) from that ctypes code, so `return False` instead and check the return from EnumWindows(). --- EDMarketConnector.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 08070efb..5ad83f88 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1357,8 +1357,8 @@ def enforce_single_instance() -> None: # noqa: CCR001 and GetProcessHandleFromHwnd(window_handle): # If GetProcessHandleFromHwnd succeeds then the app is already running as this user if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): - logger.debug('Browser invoked us directly with auth response. ' - 'Forwarding the response to the other app instance.') + # logger.debug('Browser invoked us directly with auth response. ' + # 'Forwarding the response to the other app instance.') CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) # Wait for it to be responsive to avoid ShellExecute recursing ShowWindow(window_handle, SW_RESTORE) @@ -1368,12 +1368,13 @@ def enforce_single_instance() -> None: # noqa: CCR001 ShowWindowAsync(window_handle, SW_RESTORE) SetForegroundWindow(window_handle) - logger.info(f'A running {applongname} process was found, exiting.') - sys.exit(0) + # logger.info(f'A running {applongname} process was found, exiting.') + return False return True - EnumWindows(enumwindowsproc, 0) + if not EnumWindows(enumwindowsproc, 0): + sys.exit(0) def test_logging() -> None: From 248493c16a00fa42dd3b03cfe3a183dbca683a68 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 13:01:00 +0000 Subject: [PATCH 111/727] EDMarketConnector: Change 'no other .exe runnig?' checks * This is now done even before the stdout/err redirect. * The function is now called no_other_instance_running() to make the conditional use of it read more naturally. * For now this *append* logs to the plain log file. **BUT** any subsequent write by the already-running process will be over the top of this, so a future commit will use a popup instead. # Conflicts: # EDMarketConnector.py --- EDMarketConnector.py | 188 ++++++++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 75 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 5ad83f88..63d7b5f9 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -18,9 +18,96 @@ from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple from constants import applongname, appname, protocolhandler_redirect -# config will now cause an appname logger to be set up, so we need the -# console redirect before this -if __name__ == '__main__': +# TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup +# TODO: Move enforce_single_instance() call here ? But then how do we notify +# the user if they already have a process ? +# We could propagate what that found all the way up and then do the stderr/out redirect +# in a non-truncate manner. Need to double-check the existing process won't then overwrite +# due to its seek position. +def no_other_instance_running() -> bool: # noqa: CCR001 + """ + Ensure only one copy of the app is running under this user account. + + OSX does this automatically. + + :returns: True if we are the single instance, else False. + """ + # TODO: Linux implementation + if platform == 'win32': + import ctypes + from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR + + EnumWindows = ctypes.windll.user32.EnumWindows # noqa: N806 + GetClassName = ctypes.windll.user32.GetClassNameW # noqa: N806 + GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int] + GetWindowText = ctypes.windll.user32.GetWindowTextW # noqa: N806 + GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int] + GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW # noqa: N806 + GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 + + SW_RESTORE = 9 # noqa: N806 + SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow # noqa: N806 + ShowWindow = ctypes.windll.user32.ShowWindow # noqa: N806 + ShowWindowAsync = ctypes.windll.user32.ShowWindowAsync # noqa: N806 + + COINIT_MULTITHREADED = 0 # noqa: N806,F841 + COINIT_APARTMENTTHREADED = 0x2 # noqa: N806 + COINIT_DISABLE_OLE1DDE = 0x4 # noqa: N806 + CoInitializeEx = ctypes.windll.ole32.CoInitializeEx # noqa: N806 + + ShellExecute = ctypes.windll.shell32.ShellExecuteW # noqa: N806 + ShellExecute.argtypes = [HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT] + + def window_title(h): + if h: + text_length = GetWindowTextLength(h) + 1 + buf = ctypes.create_unicode_buffer(text_length) + if GetWindowText(h, buf, text_length): + return buf.value + + return None + + @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) + def enumwindowsproc(window_handle, l_param): + # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 + cls = ctypes.create_unicode_buffer(257) + if GetClassName(window_handle, cls, 257) \ + and cls.value == 'TkTopLevel' \ + and window_title(window_handle) == applongname \ + and GetProcessHandleFromHwnd(window_handle): + # If GetProcessHandleFromHwnd succeeds then the app is already running as this user + if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): + CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) + # Wait for it to be responsive to avoid ShellExecute recursing + ShowWindow(window_handle, SW_RESTORE) + ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) + + else: + ShowWindowAsync(window_handle, SW_RESTORE) + SetForegroundWindow(window_handle) + + return False + + return True + + return EnumWindows(enumwindowsproc, 0) + +if __name__ == "__main__": + if not no_other_instance_running(): + # There's a copy already running. We want to inform the user by + # **appending** to the log file, not truncating it. + if getattr(sys, 'frozen', False): + # By default py2exe tries to write log to dirname(sys.executable) which fails when installed + import tempfile + + # unbuffered not allowed for text in python3, so use `1 for line buffering + sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='a', buffering=1) + + # Logging isn't set up yet + print("An EDMarketConnector.exe process was already running, exiting.") + + sys.exit(0) + # Keep this as the very first code run to be as sure as possible of no # output until after this redirect is done, if needed. if getattr(sys, 'frozen', False): @@ -1306,77 +1393,6 @@ class AppWindow(object): self.blank_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) -def enforce_single_instance() -> None: # noqa: CCR001 - """ - Ensure only one copy of the app is running under this user account. - - OSX does this automatically. - """ - # TODO: Linux implementation - if platform == 'win32': - import ctypes - from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR - - EnumWindows = ctypes.windll.user32.EnumWindows # noqa: N806 - GetClassName = ctypes.windll.user32.GetClassNameW # noqa: N806 - GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int] - GetWindowText = ctypes.windll.user32.GetWindowTextW # noqa: N806 - GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int] - GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW # noqa: N806 - GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 - - SW_RESTORE = 9 # noqa: N806 - SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow # noqa: N806 - ShowWindow = ctypes.windll.user32.ShowWindow # noqa: N806 - ShowWindowAsync = ctypes.windll.user32.ShowWindowAsync # noqa: N806 - - COINIT_MULTITHREADED = 0 # noqa: N806,F841 - COINIT_APARTMENTTHREADED = 0x2 # noqa: N806 - COINIT_DISABLE_OLE1DDE = 0x4 # noqa: N806 - CoInitializeEx = ctypes.windll.ole32.CoInitializeEx # noqa: N806 - - ShellExecute = ctypes.windll.shell32.ShellExecuteW # noqa: N806 - ShellExecute.argtypes = [HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT] - - def window_title(h): - if h: - text_length = GetWindowTextLength(h) + 1 - buf = ctypes.create_unicode_buffer(text_length) - if GetWindowText(h, buf, text_length): - return buf.value - - return None - - @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) - def enumwindowsproc(window_handle, l_param): - # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 - cls = ctypes.create_unicode_buffer(257) - if GetClassName(window_handle, cls, 257) \ - and cls.value == 'TkTopLevel' \ - and window_title(window_handle) == applongname \ - and GetProcessHandleFromHwnd(window_handle): - # If GetProcessHandleFromHwnd succeeds then the app is already running as this user - if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): - # logger.debug('Browser invoked us directly with auth response. ' - # 'Forwarding the response to the other app instance.') - CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) - # Wait for it to be responsive to avoid ShellExecute recursing - ShowWindow(window_handle, SW_RESTORE) - ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) - - else: - ShowWindowAsync(window_handle, SW_RESTORE) - SetForegroundWindow(window_handle) - - # logger.info(f'A running {applongname} process was found, exiting.') - return False - - return True - - if not EnumWindows(enumwindowsproc, 0): - sys.exit(0) - - def test_logging() -> None: """Simple test of top level logging.""" logger.debug('Test from EDMarketConnector.py top-level test_logging()') @@ -1394,7 +1410,29 @@ Locale LC_TIME: {locale.getlocale(locale.LC_TIME)}''' # Run the app -if __name__ == "__main__": # noqa C901 +if __name__ == "__main__": + # Command-line arguments + parser = argparse.ArgumentParser( + prog=appname, + description="Utilises Elite Dangerous Journal files and the Frontier " + "Companion API (CAPI) service to gather data about a " + "player's state and actions to upload to third-party sites " + "such as EDSM, Inara.cz and EDDB." + ) + + parser.add_argument('--trace', + help='Set the Debug logging loglevel to TRACE', + action='store_true', + ) + + args = parser.parse_args() + + if args.trace: + logger.setLevel(logging.TRACE) + edmclogger.set_channels_loglevel(logging.TRACE) + else: + edmclogger.set_channels_loglevel(logging.DEBUG) + logger.info(f'Startup v{appversion} : Running on Python v{sys.version}') logger.debug(f'''Platform: {sys.platform} {sys.platform == "win32" and sys.getwindowsversion()} argv[0]: {sys.argv[0]} From c6083a26431ff8b530bae10776f22766a475608e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 13:01:43 +0000 Subject: [PATCH 112/727] EDMarketConnector: Minor comments changes # Conflicts: # EDMarketConnector.py --- EDMarketConnector.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 63d7b5f9..cd764e05 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -18,12 +18,6 @@ from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple from constants import applongname, appname, protocolhandler_redirect -# TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup -# TODO: Move enforce_single_instance() call here ? But then how do we notify -# the user if they already have a process ? -# We could propagate what that found all the way up and then do the stderr/out redirect -# in a non-truncate manner. Need to double-check the existing process won't then overwrite -# due to its seek position. def no_other_instance_running() -> bool: # noqa: CCR001 """ Ensure only one copy of the app is running under this user account. From bc3269f2f8a99fd5b34e8a3acb545aea0f886e42 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Oct 2020 12:49:30 +0100 Subject: [PATCH 113/727] EDMarketConnector: popup for "already running" * This also refactors code around so that isort and flake8 are happy about the module level imports. --- EDMarketConnector.py | 166 +++++++++++++++++++++++++------------------ 1 file changed, 96 insertions(+), 70 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index cd764e05..fffb6d00 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -18,75 +18,96 @@ from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple from constants import applongname, appname, protocolhandler_redirect -def no_other_instance_running() -> bool: # noqa: CCR001 - """ - Ensure only one copy of the app is running under this user account. - - OSX does this automatically. - - :returns: True if we are the single instance, else False. - """ - # TODO: Linux implementation - if platform == 'win32': - import ctypes - from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR - - EnumWindows = ctypes.windll.user32.EnumWindows # noqa: N806 - GetClassName = ctypes.windll.user32.GetClassNameW # noqa: N806 - GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int] - GetWindowText = ctypes.windll.user32.GetWindowTextW # noqa: N806 - GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int] - GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW # noqa: N806 - GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 - - SW_RESTORE = 9 # noqa: N806 - SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow # noqa: N806 - ShowWindow = ctypes.windll.user32.ShowWindow # noqa: N806 - ShowWindowAsync = ctypes.windll.user32.ShowWindowAsync # noqa: N806 - - COINIT_MULTITHREADED = 0 # noqa: N806,F841 - COINIT_APARTMENTTHREADED = 0x2 # noqa: N806 - COINIT_DISABLE_OLE1DDE = 0x4 # noqa: N806 - CoInitializeEx = ctypes.windll.ole32.CoInitializeEx # noqa: N806 - - ShellExecute = ctypes.windll.shell32.ShellExecuteW # noqa: N806 - ShellExecute.argtypes = [HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT] - - def window_title(h): - if h: - text_length = GetWindowTextLength(h) + 1 - buf = ctypes.create_unicode_buffer(text_length) - if GetWindowText(h, buf, text_length): - return buf.value - - return None - - @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) - def enumwindowsproc(window_handle, l_param): - # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 - cls = ctypes.create_unicode_buffer(257) - if GetClassName(window_handle, cls, 257) \ - and cls.value == 'TkTopLevel' \ - and window_title(window_handle) == applongname \ - and GetProcessHandleFromHwnd(window_handle): - # If GetProcessHandleFromHwnd succeeds then the app is already running as this user - if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): - CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) - # Wait for it to be responsive to avoid ShellExecute recursing - ShowWindow(window_handle, SW_RESTORE) - ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) - - else: - ShowWindowAsync(window_handle, SW_RESTORE) - SetForegroundWindow(window_handle) - - return False - - return True - - return EnumWindows(enumwindowsproc, 0) - if __name__ == "__main__": + def no_other_instance_running() -> bool: # noqa: CCR001 + """ + Ensure only one copy of the app is running under this user account. + + OSX does this automatically. + + :returns: True if we are the single instance, else False. + """ + # TODO: Linux implementation + if platform == 'win32': + import ctypes + from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR + + EnumWindows = ctypes.windll.user32.EnumWindows # noqa: N806 + GetClassName = ctypes.windll.user32.GetClassNameW # noqa: N806 + GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int] + GetWindowText = ctypes.windll.user32.GetWindowTextW # noqa: N806 + GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int] + GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW # noqa: N806 + GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 + + SW_RESTORE = 9 # noqa: N806 + SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow # noqa: N806 + ShowWindow = ctypes.windll.user32.ShowWindow # noqa: N806 + ShowWindowAsync = ctypes.windll.user32.ShowWindowAsync # noqa: N806 + + COINIT_MULTITHREADED = 0 # noqa: N806,F841 + COINIT_APARTMENTTHREADED = 0x2 # noqa: N806 + COINIT_DISABLE_OLE1DDE = 0x4 # noqa: N806 + CoInitializeEx = ctypes.windll.ole32.CoInitializeEx # noqa: N806 + + ShellExecute = ctypes.windll.shell32.ShellExecuteW # noqa: N806 + ShellExecute.argtypes = [HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT] + + def window_title(h): + if h: + text_length = GetWindowTextLength(h) + 1 + buf = ctypes.create_unicode_buffer(text_length) + if GetWindowText(h, buf, text_length): + return buf.value + + return None + + @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) + def enumwindowsproc(window_handle, l_param): + # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 + cls = ctypes.create_unicode_buffer(257) + if GetClassName(window_handle, cls, 257) \ + and cls.value == 'TkTopLevel' \ + and window_title(window_handle) == applongname \ + and GetProcessHandleFromHwnd(window_handle): + # If GetProcessHandleFromHwnd succeeds then the app is already running as this user + if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): + CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) + # Wait for it to be responsive to avoid ShellExecute recursing + ShowWindow(window_handle, SW_RESTORE) + ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) + + else: + ShowWindowAsync(window_handle, SW_RESTORE) + SetForegroundWindow(window_handle) + + return False + + return True + + return EnumWindows(enumwindowsproc, 0) + + return True + + def already_running_popup(): + """Create the "already running" popup.""" + import tkinter as tk + from tkinter import ttk + + root = tk.Tk(className=appname.lower()) + + frame = tk.Frame(root) + frame.grid(row=1, column=0, sticky=tk.NSEW) + + label = tk.Label(frame) + label['text'] = 'An EDMarketConnector.exe process was already running, exiting.' + label.grid(row=1, column=0, sticky=tk.NSEW) + + button = ttk.Button(frame, text='OK', command=lambda: sys.exit(0)) + button.grid(row=2, column=0, sticky=tk.S) + + root.mainloop() + if not no_other_instance_running(): # There's a copy already running. We want to inform the user by # **appending** to the log file, not truncating it. @@ -97,9 +118,15 @@ if __name__ == "__main__": # unbuffered not allowed for text in python3, so use `1 for line buffering sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='a', buffering=1) - # Logging isn't set up yet + # Logging isn't set up yet. + # We'll keep this print, but it will be over-written by any subsequent + # write by the already-running process. print("An EDMarketConnector.exe process was already running, exiting.") + # To be sure the user knows, we need a popup + already_running_popup() + # If the user closes the popup with the 'X', not the 'OK' button we'll + # reach here. sys.exit(0) # Keep this as the very first code run to be as sure as possible of no @@ -306,7 +333,6 @@ if TYPE_CHECKING: """Fake the l10n translation functions for typing.""" return x - if getattr(sys, 'frozen', False): # Under py2exe sys.path[0] is the executable name if platform == 'win32': From 9f45960fe3d054544a062112d728b77cf9f1e529 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Oct 2020 12:55:27 +0100 Subject: [PATCH 114/727] dashboard: Reinstate "from calendar import timegm" This was inadvertently removed in 102fe809783141394ee31a30158c5ed81ea4d996 --- dashboard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dashboard.py b/dashboard.py index f117514b..7fef3a9f 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,4 +1,5 @@ import json +from calendar import timegm from os.path import isdir, isfile, join, getsize from sys import platform import time From fbd924d5aa3778de6f9a828866aebca6dcfb3dde Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 23 Sep 2020 15:06:16 +0200 Subject: [PATCH 115/727] Added CAPIData class Currently it is simply a dict subclass that does some of the cleanup required to make everything happy. In future it will be changed to be a NamedTuple or similar that can be typed --- companion.py | 73 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/companion.py b/companion.py index 36fb62cb..d1a35c6d 100644 --- a/companion.py +++ b/companion.py @@ -7,8 +7,10 @@ protocol used for the callback. """ import base64 +import collections import csv import hashlib +import json import numbers import os import random @@ -20,7 +22,7 @@ from email.utils import parsedate # TODO: see https://github.com/EDCD/EDMarketConnector/issues/569 from http.cookiejar import LWPCookieJar # noqa: F401 - No longer needed but retained in case plugins use it from os.path import join -from typing import TYPE_CHECKING, Any, Dict, List, NewType, Union +from typing import TYPE_CHECKING, Any, Dict, List, Union, cast import requests @@ -31,11 +33,16 @@ from protocol import protocolhandler logger = get_main_logger() if TYPE_CHECKING: - _ = lambda x: x # noqa: E731 # to make flake8 stop complaining that the hacked in _ method doesnt exist + def _(x): return x # noqa: E731 # to make flake8 stop complaining that the hacked in _ method doesnt exist + + UserDict = collections.UserDict[str, Any] # indicate to our type checkers what this generic class holds normally +else: + UserDict = collections.UserDict # type: ignore # Otherwise simply use the actual class + # Define custom type for the dicts that hold CAPI data -CAPIData = NewType('CAPIData', Dict) +# CAPIData = NewType('CAPIData', Dict) holdoff = 60 # be nice timeout = 10 # requests timeout @@ -117,6 +124,52 @@ ship_map = { } +class CAPIData(UserDict): + """CAPI Response.""" + + def __init__(self, data: Union[str, Dict[str, Any], 'CAPIData', None] = None) -> None: + if data is None: + super().__init__() + elif isinstance(data, str): + super().__init__(json.loads(data)) + else: + super().__init__(data) + + self.original_data = self.data.copy() # Just in case + + self.check_modules_ships() + + def check_modules_ships(self) -> None: + modules: Dict[str, Any] = self.data['lastStarport'].get('modules') + if modules is None or not isinstance(modules, dict): + if modules is None: + logger.debug('modules was None. FC or Damaged Station?') + + elif isinstance(modules, list): + if len(modules) == 0: + logger.debug('modules is empty list. Damaged Station?') + + else: + logger.error(f'modules is non-empty list: {modules!r}') + + else: + logger.error(f'modules was not None, a list, or a dict! type: {type(modules)}, content: {modules}') + + # Set a safe value + self.data['lastStarport']['modules'] = modules = {} + + ships: Dict[str, Any] = self.data['lastStarport'].get('ships') + if ships is None or not isinstance(ships, dict): + if ships is None: + logger.debug('ships was None') + + else: + logger.error(f'ships was neither None nor a Dict! type: {type(ships)}, content: {ships}') + + # Set a safe value + self.data['lastStarport']['ships'] = {'shipyard_list': {}, 'unavailable_list': []} + + def listify(thing: Union[List, Dict]) -> List: """ Convert actual JSON array or int-indexed dict into a Python list. @@ -231,7 +284,7 @@ class Auth(object): logger.debug(f'Trying for "{self.cmdr}"') self.verifier = None - cmdrs = config.get('cmdrs') + cmdrs = cast(List[str], config.get('cmdrs')) logger.debug(f'Cmdrs: {cmdrs}') idx = cmdrs.index(self.cmdr) @@ -321,7 +374,7 @@ class Auth(object): data = r.json() if r.status_code == requests.codes.ok: logger.info(f'Frontier CAPI Auth: New token for \"{self.cmdr}\"') - cmdrs = config.get('cmdrs') + cmdrs = cast(List[str], config.get('cmdrs')) idx = cmdrs.index(self.cmdr) tokens = config.get('fdev_apikeys') or [] tokens = tokens + [''] * (len(cmdrs) - len(tokens)) @@ -350,9 +403,9 @@ class Auth(object): def invalidate(cmdr: str) -> None: """Invalidate Refresh Token for specified Commander.""" logger.info(f'Frontier CAPI Auth: Invalidated token for "{cmdr}"') - cmdrs = config.get('cmdrs') + cmdrs = cast(List[str], config.get('cmdrs')) idx = cmdrs.index(cmdr) - tokens = config.get('fdev_apikeys') or [] + tokens = cast(List[str], config.get('fdev_apikeys') or []) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) tokens[idx] = '' config.set('fdev_apikeys', tokens) @@ -499,7 +552,7 @@ class Session(object): try: r.raise_for_status() # Typically 403 "Forbidden" on token expiry - data = r.json() # May also fail here if token expired since response is empty + data = CAPIData(r.json()) # May also fail here if token expired since response is empty except (requests.HTTPError, ValueError) as e: logger.exception('Frontier CAPI Auth: GET ') @@ -670,14 +723,14 @@ def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully datacopy = data.copy() datacopy['lastStarport'] = data['lastStarport'].copy() datacopy['lastStarport']['commodities'] = commodities - return CAPIData(datacopy) + return datacopy def ship(data: CAPIData) -> CAPIData: """Construct a subset of the received data describing the current ship.""" def filter_ship(d: CAPIData) -> CAPIData: """Filter provided ship data.""" - filtered: CAPIData = CAPIData({}) + filtered = CAPIData() for k, v in d.items(): if not v: pass # just skip empty fields for brevity From bd670b7ff18842f705723118d5886bbc1372a305 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 13:02:50 +0000 Subject: [PATCH 116/727] Updated plugins to expect that CAPI data is safe # Conflicts: # plugins/eddn.py --- plugins/eddb.py | 3 +- plugins/eddn.py | 84 ++++++++++-------------------------------------- plugins/edsm.py | 3 +- plugins/inara.py | 3 +- 4 files changed, 23 insertions(+), 70 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index c0ef35fc..f61ae017 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -23,6 +23,7 @@ # +from companion import CAPIData import sys from typing import Any, Optional, TYPE_CHECKING import requests @@ -125,7 +126,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.station_link.update_idletasks() -def cmdr_data(data, is_beta): +def cmdr_data(data: CAPIData, is_beta): # Always store initially, even if we're not the *current* system provider. if not this.station_marketid and data['commander']['docked']: this.station_marketid = data['lastStarport']['id'] diff --git a/plugins/eddn.py b/plugins/eddn.py index 223272db..243b6beb 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -17,7 +17,7 @@ from typing import Sequence, TextIO import requests import myNotebook as nb # noqa: N813 -from companion import category_map +from companion import CAPIData, category_map from config import applongname, appversion, config from EDMCLogging import get_main_logger from myNotebook import Frame @@ -238,6 +238,7 @@ Msg:\n{msg}''' :param data: a dict containing the starport data :param is_beta: whether or not we're currently in beta mode """ + commodities: List[OrderedDictT[str, Any]] = [] for commodity in data['lastStarport'].get('commodities') or []: # Check 'marketable' and 'not prohibited' @@ -289,33 +290,7 @@ Msg:\n{msg}''' this.commodities = commodities - def safe_modules_and_ships(self, data: Mapping[str, Any]) -> Tuple[Dict, Dict]: - modules: Dict[str, Any] = data['lastStarport'].get('modules') - if modules is None or not isinstance(modules, dict): - if modules is None: - logger.debug('modules was None. FC or Damaged Station?') - elif isinstance(modules, list): - if len(modules) == 0: - logger.debug('modules is empty list. FC or Damaged Station?') - else: - logger.error(f'modules is non-empty list: {modules!r}') - else: - logger.error(f'modules was not None, a list, or a dict! type = {type(modules)}') - # Set a safe value - modules = {} - - ships: Dict[str, Any] = data['lastStarport'].get('ships') - if ships is None or not isinstance(ships, dict): - if ships is None: - logger.debug('ships was None') - else: - logger.error(f'ships was neither None nor a Dict! Type = {type(ships)}') - # Set a safe value - ships = {'shipyard_list': {}, 'unavailable_list': []} - - return modules, ships - - def export_outfitting(self, data: Mapping[str, Any], is_beta: bool) -> None: + def export_outfitting(self, data: CAPIData, is_beta: bool) -> None: """ export_outfitting updates EDDN with the current (lastStarport) station's outfitting options, if any. Once the send is complete, this.outfitting is updated with the given data. @@ -323,25 +298,25 @@ Msg:\n{msg}''' :param data: dict containing the outfitting data :param is_beta: whether or not we're currently in beta mode """ - modules, ships = self.safe_modules_and_ships(data) # Horizons flag - will hit at least Int_PlanetApproachSuite other than at engineer bases ("Colony"), # prison or rescue Megaships, or under Pirate Attack etc horizons: bool = is_horizons( data['lastStarport'].get('economies', {}), - modules, - ships + data['lastStarport']['modules'], + data['lastStarport']['ships'] ) to_search: Iterator[Mapping[str, Any]] = filter( lambda m: self.MODULE_RE.search(m['name']) and m.get('sku') in (None, HORIZ_SKU) and m['name'] != 'Int_PlanetApproachSuite', - modules.values() + data['lastStarport']['modules'].values() ) outfitting: List[str] = sorted( self.MODULE_RE.sub(lambda match: match.group(0).capitalize(), mod['name'].lower()) for mod in to_search ) + # Don't send empty modules list - schema won't allow it if outfitting and this.outfitting != (horizons, outfitting): self.send(data['commander']['name'], { @@ -358,7 +333,7 @@ Msg:\n{msg}''' this.outfitting = (horizons, outfitting) - def export_shipyard(self, data: Dict[str, Any], is_beta: bool) -> None: + def export_shipyard(self, data: CAPIData, is_beta: bool) -> None: """ export_shipyard updates EDDN with the current (lastStarport) station's outfitting options, if any. once the send is complete, this.shipyard is updated to the new data. @@ -366,11 +341,12 @@ Msg:\n{msg}''' :param data: dict containing the shipyard data :param is_beta: whether or not we are in beta mode """ - modules, ships = self.safe_modules_and_ships(data) + + ships = data['lastStarport']['ships'] horizons: bool = is_horizons( data['lastStarport'].get('economies', {}), - modules, + data['lastStarport']['modules'], ships ) @@ -773,7 +749,7 @@ def journal_entry( # noqa: C901 return str(e) -def cmdr_data(data: Mapping[str, Any], is_beta: bool) -> str: +def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: if data['commander'].get('docked') and config.getint('output') & config.OUT_MKT_EDDN: try: if this.marketId != data['lastStarport']['id']: @@ -806,34 +782,8 @@ MAP_STR_ANY = Mapping[str, Any] def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY) -> bool: - economies_colony = False - modules_horizons = False - ship_horizons = False - - if isinstance(economies, dict): - economies_colony = any(economy['name'] == 'Colony' for economy in economies.values()) - - else: - logger.error(f'economies type is {type(economies)}') - - if isinstance(modules, dict): - modules_horizons = any(module.get('sku') == HORIZ_SKU for module in modules.values()) - - else: - logger.error(f'modules type is {type(modules)}') - - if isinstance(ships, dict): - if ships.get('shipyard_list') is not None: - if isinstance(ships.get('shipyard_list'), dict): - ship_horizons = any(ship.get('sku') == HORIZ_SKU for ship in ships['shipyard_list'].values()) - - else: - logger.debug('ships["shipyard_list"] is not dict - FC or Damaged Station?') - - else: - logger.debug('ships["shipyard_list"] is None - FC or Damaged Station?') - - else: - logger.error(f'ships type is {type(ships)}') - - return economies_colony or modules_horizons or ship_horizons + return ( + any(economy['name'] == 'Colony' for economy in economies.values()) or + any(module.get('sku') == HORIZ_SKU for module in modules.values()) or + any(ship.get('sku') == HORIZ_SKU for ship in ships.get('shipyard_list', {}).values()) + ) diff --git a/plugins/edsm.py b/plugins/edsm.py index c9351148..ce2b40b3 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -9,6 +9,7 @@ # 4) Ensure the EDSM API call(back) for setting the image at end of system # text is always fired. i.e. CAPI cmdr_data() processing. +from companion import CAPIData import json import sys import tkinter as tk @@ -442,7 +443,7 @@ Queueing: {entry!r}''' # Update system data -def cmdr_data(data: Mapping[str, Any], is_beta: bool) -> None: +def cmdr_data(data: CAPIData, is_beta: bool) -> None: """CAPI Entry Hook.""" system = data['lastSystem']['name'] diff --git a/plugins/inara.py b/plugins/inara.py index 576383aa..5abcf2ec 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1,5 +1,6 @@ """Inara Sync.""" +from companion import CAPIData import dataclasses import json import sys @@ -1037,7 +1038,7 @@ def journal_entry( this.station_link.update_idletasks() -def cmdr_data(data, is_beta): +def cmdr_data(data: CAPIData, is_beta): """CAPI event hook.""" this.cmdr = data['commander']['name'] From 6ec24157f27b653d7d0968b9bb9f5aecaf23530f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 16 Oct 2020 15:36:48 +0100 Subject: [PATCH 117/727] CAPIData: Only call self.check_modules_ships() if lastStarport present * The companion Session.query is called for *all* CAPI endpoints and only the /profile one will return lastStartport data, which is where ships/modules are if present, so only do these checks if we see lastStarport. --- companion.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/companion.py b/companion.py index d1a35c6d..7d6bbe36 100644 --- a/companion.py +++ b/companion.py @@ -137,7 +137,9 @@ class CAPIData(UserDict): self.original_data = self.data.copy() # Just in case - self.check_modules_ships() + # Only the /profile end point has star port, and thus ships/modules. + if self.data.get('lastStarport'): + self.check_modules_ships() def check_modules_ships(self) -> None: modules: Dict[str, Any] = self.data['lastStarport'].get('modules') From df238c3e95606c89e4a0b7da40e2c9a8ca7205ba Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 21 Oct 2020 14:26:30 +0100 Subject: [PATCH 118/727] Bump py2exe to 0.10.0.2 NB: Possibly due to the git tag form I had to 'pip install --user --upgrade -r requirements-dev.txt` to get it to upgrade. --- requirements-dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 40ffd612..cd885fcd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,8 +26,8 @@ grip==4.5.2 # Refs: # # -#py2exe==0.10.0.1 -git+https://github.com/albertosottile/py2exe.git@v0.10.0.1#egg=py2exe; sys_platform == 'win32' +#py2exe==0.10.0.2 +git+https://github.com/albertosottile/py2exe.git@v0.10.0.2#egg=py2exe; sys_platform == 'win32' # All of the normal requirements -r requirements.txt From bdb3387df3c2bcdb3be1eba58eea918977320f4c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Oct 2020 07:25:06 +0000 Subject: [PATCH 119/727] Bump flake8-comprehensions from 3.2.3 to 3.3.0 Bumps [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions) from 3.2.3 to 3.3.0. - [Release notes](https://github.com/adamchainz/flake8-comprehensions/releases) - [Changelog](https://github.com/adamchainz/flake8-comprehensions/blob/master/HISTORY.rst) - [Commits](https://github.com/adamchainz/flake8-comprehensions/compare/3.2.3...3.3.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index cd885fcd..754fe585 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,7 +2,7 @@ flake8==3.8.4 flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 -flake8-comprehensions==3.2.3 +flake8-comprehensions==3.3.0 flake8-docstrings==1.5.0 isort==5.6.4 flake8-isort==4.0.0 From 0f3ba584e9e46571e2b6163741dad7c792cd79a2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 26 Oct 2020 13:27:07 +0000 Subject: [PATCH 120/727] requirements: py2exe now available from pypi, so no need for VCS --- requirements-dev.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 754fe585..46d6928c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -22,12 +22,8 @@ autopep8==1.5.4 grip==4.5.2 # Packaging -# This isn't available via 'pip install', but is via git@tag -# Refs: -# -# -#py2exe==0.10.0.2 -git+https://github.com/albertosottile/py2exe.git@v0.10.0.2#egg=py2exe; sys_platform == 'win32' +# We only need py2exe on windows. +py2exe==0.10.0.2; sys_platform == 'win32' # All of the normal requirements -r requirements.txt From cb678522d7d7879cf44e4c66de55cd1ae17147b0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 26 Oct 2020 13:49:13 +0000 Subject: [PATCH 121/727] Releasing: py2exe via pip / requirements-dev.txt now. --- docs/Releasing.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 5fdf0831..97934c34 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -35,17 +35,16 @@ You will need several pieces of software installed, or the files from their [v3.8.6](https://www.python.org/downloads/release/python-386/) is the most recently tested version. You need the `Windows x86 executable installer` file, for the 32-bit version. -1. [py2exe](https://github.com/albertosottile/py2exe) - Install the python - module. You will need at least [version 0.10.0.1](https://github.com/albertosottile/py2exe/releases/tag/v0.10.0.1), -specifically [py2exe-0.10.0.1-cp38-none-win32.whl](https://github.com/albertosottile/py2exe/releases/download/v0.10.0.1/py2exe-0.10.0.1-cp38-none-win32.whl). +1. [py2exe](https://github.com/albertosottile/py2exe) - Now available via PyPi, + so will be picked up with the `pip install` below. Latest tested as per + `requirements-dev.txt`. 1. You'll now need to 'pip install' several python modules. 1. Ensure you have `pip` installed. If needs be see [Installing pip](https://pip.pypa.io/en/stable/installing/) 1. The easiest way is to utilise the `requirements-dev.txt` file: `python -m pip install --user -r requirements-dev.txt`. This will install - all dependencies plus anything required for development *other than - py2exe, see above*. + all dependencies plus anything required for development. 1. Else check the contents of both `requirements.txt` and `requirements-dev.txt`, and ensure the modules listed there are installed as per the version requirements. From 3e96184ba5c2bf553628b1438cf7576678c5e5ac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Nov 2020 07:25:58 +0000 Subject: [PATCH 122/727] Bump certifi from 2020.6.20 to 2020.11.8 Bumps [certifi](https://github.com/certifi/python-certifi) from 2020.6.20 to 2020.11.8. - [Release notes](https://github.com/certifi/python-certifi/releases) - [Commits](https://github.com/certifi/python-certifi/compare/2020.06.20...2020.11.08) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 508df246..1a94b1a6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -certifi==2020.6.20 +certifi==2020.11.8 requests>=2.11.1 watchdog>=0.8.3 # argh==0.26.2 watchdog dep From 80ac14756d0177d066efd5c8d82dfaffe612a622 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Nov 2020 07:25:55 +0000 Subject: [PATCH 123/727] Bump py2exe from 0.10.0.2 to 0.10.1.0 Bumps [py2exe](https://github.com/py2exe/py2exe) from 0.10.0.2 to 0.10.1.0. - [Release notes](https://github.com/py2exe/py2exe/releases) - [Changelog](https://github.com/py2exe/py2exe/blob/master/ChangeLog) - [Commits](https://github.com/py2exe/py2exe/compare/v0.10.0.2...v0.10.1.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 46d6928c..cf58bb20 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -23,7 +23,7 @@ grip==4.5.2 # Packaging # We only need py2exe on windows. -py2exe==0.10.0.2; sys_platform == 'win32' +py2exe==0.10.1.0; sys_platform == 'win32' # All of the normal requirements -r requirements.txt From 8bc119c834f4eece551dc6881dc857034d259977 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Dec 2020 06:32:58 +0000 Subject: [PATCH 124/727] Bump flake8-json from 19.8.0 to 20.12.1 Bumps [flake8-json](https://gitlab.com/pycqa/flake8-json) from 19.8.0 to 20.12.1. - [Release notes](https://gitlab.com/pycqa/flake8-json/tags) - [Commits](https://gitlab.com/pycqa/flake8-json/compare/19.8.0...20.12.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index cf58bb20..5bbe39f5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ flake8-comprehensions==3.3.0 flake8-docstrings==1.5.0 isort==5.6.4 flake8-isort==4.0.0 -flake8-json==19.8.0 +flake8-json==20.12.1 flake8-noqa==1.0.5 flake8-polyfill==1.0.2 flake8-use-fstring==1.1 From 7bdbcd5538916e2e76659ecaca2b975f73c3aa6b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Dec 2020 07:43:54 +0000 Subject: [PATCH 125/727] Bump certifi from 2020.11.8 to 2020.12.5 Bumps [certifi](https://github.com/certifi/python-certifi) from 2020.11.8 to 2020.12.5. - [Release notes](https://github.com/certifi/python-certifi/releases) - [Commits](https://github.com/certifi/python-certifi/compare/2020.11.08...2020.12.05) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1a94b1a6..53cacec1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -certifi==2020.11.8 +certifi==2020.12.5 requests>=2.11.1 watchdog>=0.8.3 # argh==0.26.2 watchdog dep From d847fb8bc10fb4c583bb8d7994269ed502543d17 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 8 Dec 2020 18:51:00 +0200 Subject: [PATCH 126/727] Removed appcast, only upload msi installer --- setup.py | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/setup.py b/setup.py index b04bd6a7..f131f8f2 100755 --- a/setup.py +++ b/setup.py @@ -296,52 +296,3 @@ elif sys.platform == 'win32': else: raise AssertionError('Unsupported platform') - -if not exists(package_filename): - raise AssertionError(f'No {package_filename} found prior to appcast') - -# Make appcast entry -appcast = open(f'appcast_{sys.platform == "darwin" and "mac" or "win"}_{appversion}.xml', 'w') - -if sys.platform == 'win32': - style = '''body { - font-family:"Segoe UI","Tahoma"; - font-size: 75%; -} -h2 { - font-family:"Segoe UI","Tahoma"; - font-size: 105%; -} -''' - package_os = 'windows"\n\t\t\t\tsparkle:installerArguments="/passive LAUNCH=yes' - -elif sys.platform == 'darwin': - style = 'h2 { font-size: 105%; }' - package_os = 'macos' - -else: - raise AssertionError(f'Unknown platform for appcast {sys.platform}') - -length = os.stat(package_filename).st_size - -appcast.write(f''' -\t\t -\t\t\tRelease {appversion} -\t\t\t -\t\t\t\t{style} -

    Release {appversion}

    -
      - -
    -\t\t\t\t]]> -\t\t\t
    -\t\t\t -\t\t
    -''') From 7e094df6c4e8d66ebc03f47de77db04e0f1acaff Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 8 Dec 2020 17:02:58 +0000 Subject: [PATCH 127/727] Switch to Python 3.8.6 for windows builds on GitHub --- .github/workflows/windows-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index bd695779..f040f24b 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: "3.7.9" + python-version: "3.8.6" architecture: "x86" - name: Install python tools From c69cc77682c29c679c986d97585ea2e10ee84941 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 13:03:56 +0000 Subject: [PATCH 128/727] Added auto-annotation to both checks This works based on telling github how to understand the flake8 output # Conflicts: # .github/workflows/push-checks.yml --- .github/workflows/pr-annotate-with-flake8.yml | 80 ------------------- .github/workflows/pr-checks.yml | 13 +-- .github/workflows/push-checks.yml | 15 ++-- 3 files changed, 13 insertions(+), 95 deletions(-) delete mode 100644 .github/workflows/pr-annotate-with-flake8.yml diff --git a/.github/workflows/pr-annotate-with-flake8.yml b/.github/workflows/pr-annotate-with-flake8.yml deleted file mode 100644 index 93209cc8..00000000 --- a/.github/workflows/pr-annotate-with-flake8.yml +++ /dev/null @@ -1,80 +0,0 @@ -# This workflow will: -# -# 1. Store some github context in env vars. -# 2. Only checkout if base and head ref owners are the same. -# 3. Check if any *.py files are in the diff. -# 4. Only then install python and perform the annotation with flake8. -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: PR-annotate-flake8 - -on: - pull_request: - branches: [ develop ] - -jobs: - flake8_annotate: - runs-on: ubuntu-18.04 - - steps: - ################################################################## - # Check if the base and head repos are the same, if not we won't - # be able to add annotations. - ################################################################## - - name: Check head and base repo same - env: - BASE_REPO_OWNER: ${{github.event.pull_request.base.repo.owner.login}} - HEAD_REPO_OWNER: ${{github.event.pull_request.head.repo.owner.login}} - BASE_REF: ${{github.base_ref}} - run: | - # Just to be running something - env - ################################################################## - - ################################################################## - # Perform the checkout - ################################################################## - - name: Checkout - if: ${{ github.event.pull_request.base.repo.owner.login == github.event.pull_request.head.repo.owner.login }} - uses: actions/checkout@v2 - with: - fetch-depth: 0 - ################################################################## - - ################################################################## - # flake8-your-pr 'fails' if no *.py files changed - # So we check if any were affected and store that in env - ################################################################## - - name: Check for PY files - if: ${{ github.event.pull_request.base.repo.owner.login == github.event.pull_request.head.repo.owner.login }} - run: | - # Checkout might not have happened. - if [ ! -d ".git" ]; then exit 0 ; fi - # Get a list of files ending with ".py", stuff in environment. - # We don't rely on exit status because Workflows run with - # "set -e" so any failure in a pipe is total failure. - PYFILES=$(git diff --name-only "refs/remotes/origin/${BASE_REF}" -- | egrep '.py$' || true) - # Use magic output to store in env for rest of workflow - echo "::set-env name=PYFILES::${PYFILES}" - ################################################################## - - ################################################################## - # Get Python set up - ################################################################## - - name: Set up Python 3.8 - if: ${{ env.PYFILES != '' }} - uses: actions/setup-python@v2 - with: - python-version: 3.8 - ################################################################## - - ################################################################## - # Perform the annotation - ################################################################## - - name: Annotate with Flake8 - # Only if at least one *.py file was affected - if: ${{ env.PYFILES != '' }} - uses: "tayfun/flake8-your-pr@master" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ################################################################## diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 055ee6a0..f7d8418f 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -52,18 +52,13 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 + pip wheel install flake8 if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; elif [ -f requirements.txt ]; then pip install -r requirements.txt ; fi #################################################################### - #################################################################### - # Show full github context to aid debugging. - #################################################################### - - name: Show github context - run: | - env - cat $GITHUB_EVENT_PATH - #################################################################### + # Have issues be annotated on run + - name: Setup flake8 annotations + uses: rbialon/flake8-annotations@v1 #################################################################### # Lint with flake8 diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index 2ab55d45..b976c8bb 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -9,8 +9,8 @@ name: Push-Checks on: push: - branches: [ main ] - + branches: [ develop ] + jobs: build: @@ -27,16 +27,19 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest wheel + pip install wheel flake8 pytest if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi + + - name: Setup flake8 annotations + uses: rbialon/flake8-annotations@v1 + - name: Lint with flake8 env: ROOT_SHA: ${{github.base_ref}} - run: | - DATA=$(jq --raw-output .before $GITHUB_EVENT_PATH) + DATA=$(jq .before $GITHUB_EVENT_PATH) # stop the build if there are Python syntax errors or undefined names, ignore existing git diff "$DATA" | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --diff # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - git diff "$DATA" | flake8 . --count --exit-zero --statistics --diff + git diff "$DATA" | flake8 . --count --statistics --diff From 1c80578fef5cb2bdcd6e6a14fd47aac81546a4ef Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 9 Dec 2020 19:33:56 +0200 Subject: [PATCH 129/727] Fixed backwards pip install command --- .github/workflows/pr-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index f7d8418f..8572f5ac 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -52,7 +52,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip wheel install flake8 + pip install wheel flake8 if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; elif [ -f requirements.txt ]; then pip install -r requirements.txt ; fi #################################################################### From c2faad1eb7a7ad3168fb5fbf0b889ff129adc7e9 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 9 Dec 2020 19:46:45 +0200 Subject: [PATCH 130/727] Removed uneeded whitespace --- .github/workflows/push-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index b976c8bb..149e95af 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -10,7 +10,7 @@ name: Push-Checks on: push: branches: [ develop ] - + jobs: build: From 4a9fe077f9336699761652a98a1dc8331f3bbbdb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Dec 2020 07:29:57 +0000 Subject: [PATCH 131/727] Bump flake8-comprehensions from 3.3.0 to 3.3.1 Bumps [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/adamchainz/flake8-comprehensions/releases) - [Changelog](https://github.com/adamchainz/flake8-comprehensions/blob/master/HISTORY.rst) - [Commits](https://github.com/adamchainz/flake8-comprehensions/compare/3.3.0...3.3.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 5bbe39f5..06da0c14 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,7 +2,7 @@ flake8==3.8.4 flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 -flake8-comprehensions==3.3.0 +flake8-comprehensions==3.3.1 flake8-docstrings==1.5.0 isort==5.6.4 flake8-isort==4.0.0 From 3d19d26edd063d06ef8b45eb7225df365695f8ce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Dec 2020 07:29:58 +0000 Subject: [PATCH 132/727] Bump safety from 1.9.0 to 1.10.0 Bumps [safety](https://github.com/pyupio/safety) from 1.9.0 to 1.10.0. - [Release notes](https://github.com/pyupio/safety/releases) - [Changelog](https://github.com/pyupio/safety/blob/master/HISTORY.rst) - [Commits](https://github.com/pyupio/safety/compare/1.9.0...1.10.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 06da0c14..d3fbb7dd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,7 +13,7 @@ flake8-use-fstring==1.1 mypy==0.790 pep8-naming==0.11.1 -safety==1.9.0 +safety==1.10.0 # Code formatting tools autopep8==1.5.4 From bbcf5c9daac12b7110f652661636c6f494e3d00d Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 13 Nov 2020 08:23:02 +0200 Subject: [PATCH 133/727] Removed unknown error log, added defaults --- config.py | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/config.py b/config.py index 72c92522..39ae3ce1 100644 --- a/config.py +++ b/config.py @@ -5,6 +5,7 @@ On Windows this uses the Registry to store values in a flat manner. Linux uses a file, but for commonality it's still a flat data structure. """ +from configparser import NoOptionError import logging import numbers import sys @@ -174,11 +175,11 @@ class Config(): if not self.get('outdir') or not isdir(self.get('outdir')): self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) - def get(self, key: str) -> Union[None, list, str]: + def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: """Look up a string configuration value.""" val = self.settings.get(key) if val is None: - return None + return default elif isinstance(val, str): return str(val) @@ -187,20 +188,20 @@ class Config(): return list(val) # make writeable else: - return None + return default - def getint(self, key: str) -> int: + def getint(self, key: str, default: int = 0) -> int: """Look up an integer configuration value.""" try: - return int(self.settings.get(key, 0)) # should already be int, but check by casting + return int(self.settings.get(key, default)) # should already be int, but check by casting except ValueError as e: logger.error(f"Failed to int({key=})", exc_info=e) - return 0 + return default except Exception as e: logger.debug('The exception type is ...', exc_info=e) - return 0 + return default def set(self, key: str, val: Union[int, str, list]) -> None: """Set value on the specified configuration key.""" @@ -303,7 +304,7 @@ class Config(): if not self.get('outdir') or not isdir(self.get('outdir')): self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) - def get(self, key: str) -> Union[None, list, str]: + def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: """Look up a string configuration value.""" key_type = DWORD() key_size = DWORD() @@ -319,11 +320,11 @@ class Config(): ) or key_type.value not in [REG_SZ, REG_MULTI_SZ] ): - return None + return default buf = ctypes.create_unicode_buffer(int(key_size.value / 2)) if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(key_type), buf, ctypes.byref(key_size)): - return None + return default elif key_type.value == REG_MULTI_SZ: return list(ctypes.wstring_at(buf, len(buf)-2).split('\x00')) @@ -331,7 +332,7 @@ class Config(): else: return str(buf.value) - def getint(self, key: str) -> int: + def getint(self, key: str, default: int = 0) -> int: """Look up an integer configuration value.""" key_type = DWORD() key_size = DWORD(4) @@ -347,7 +348,7 @@ class Config(): ) or key_type.value != REG_DWORD ): - return 0 + return default else: return key_val.value @@ -421,7 +422,7 @@ class Config(): if not self.get('outdir') or not isdir(self.get('outdir')): self.set('outdir', expanduser('~')) - def get(self, key: str) -> Union[None, list, str]: + def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: """Look up a string configuration value.""" try: val = self.config.get(self.SECTION, key) @@ -433,22 +434,29 @@ class Config(): else: return self._unescape(val) + except NoOptionError: + logger.debug(f'attempted to get key {key} that does not exist') + return default + except Exception as e: logger.debug('And the exception type is...', exc_info=e) - return None + return default - def getint(self, key: str) -> int: + def getint(self, key: str, default: int = 0) -> int: """Look up an integer configuration value.""" try: return self.config.getint(self.SECTION, key) except ValueError as e: logger.error(f"Failed to int({key=})", exc_info=e) - return 0 - except Exception as e: - logger.debug('And the exception type is...', exc_info=e) - return 0 + except NoOptionError: + logger.debug(f'attempted to get key {key} that does not exist') + + except Exception: + logger.exception(f'unexpected exception while attempting to access {key}') + + return default def set(self, key: str, val: Union[int, str, list]) -> None: """Set value on the specified configuration key.""" From 8104359a725b4ecc33e58f6c9eee50545a1afe1d Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 13 Nov 2020 08:26:16 +0200 Subject: [PATCH 134/727] Resolved mypy windll errors --- config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 39ae3ce1..9f58825b 100644 --- a/config.py +++ b/config.py @@ -5,15 +5,17 @@ On Windows this uses the Registry to store values in a flat manner. Linux uses a file, but for commonality it's still a flat data structure. """ -from configparser import NoOptionError +# spell-checker: words HKEY FOLDERID wchar wstring edcdhkey + import logging import numbers import sys import warnings +from configparser import NoOptionError from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import Optional, Union +from typing import TYPE_CHECKING, Optional, Union import semantic_version @@ -48,6 +50,8 @@ elif platform == 'win32': import ctypes import uuid from ctypes.wintypes import DWORD, HANDLE, HKEY, LONG, LPCVOID, LPCWSTR + if TYPE_CHECKING: + import ctypes.windll # type: ignore FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') From 6a159c0a257d7c47d8023e35b4cfef76e1bc8b3f Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 15 Nov 2020 13:23:23 +0200 Subject: [PATCH 135/727] Added Abstract config class The abstract class will be implemented by per-platform subclasses, which will be set as the singleton at the end of development. --- config.py | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 255 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 9f58825b..4297106c 100644 --- a/config.py +++ b/config.py @@ -7,15 +7,19 @@ Linux uses a file, but for commonality it's still a flat data structure. # spell-checker: words HKEY FOLDERID wchar wstring edcdhkey +import abc +import functools import logging import numbers +import pathlib import sys import warnings +from abc import abstractmethod from configparser import NoOptionError from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union import semantic_version @@ -121,6 +125,256 @@ elif platform == 'linux': from configparser import RawConfigParser +class AbstractConfig(abc.ABC): + """Abstract root class of all platform specific Config implementations.""" + + OUT_MKT_EDDN = 1 + # OUT_MKT_BPC = 2 # No longer supported + OUT_MKT_TD = 4 + OUT_MKT_CSV = 8 + OUT_SHIP = 16 + # OUT_SHIP_EDS = 16 # Replaced by OUT_SHIP + # OUT_SYS_FILE = 32 # No longer supported + # OUT_STAT = 64 # No longer available + # OUT_SHIP_CORIOLIS = 128 # Replaced by OUT_SHIP + OUT_STATION_ANY = OUT_MKT_EDDN | OUT_MKT_TD | OUT_MKT_CSV + # OUT_SYS_EDSM = 256 # Now a plugin + # OUT_SYS_AUTO = 512 # Now always automatic + OUT_MKT_MANUAL = 1024 + OUT_SYS_EDDN = 2048 + OUT_SYS_DELAY = 4096 + + app_dir: pathlib.Path + plugin_dir: pathlib.Path + internal_plugin_dir: pathlib.Path + respath: pathlib.Path + home: pathlib.Path + default_journal_dir: Optional[pathlib.Path] + + def __init__(self) -> None: + self.home = pathlib.Path.home() + + def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: + """ + Get the requested key, or a default. + + :param key: the key to get + :param default: the default to return if the key does not exist, defaults to None + :return: the data or the default + """ + warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type')) + if (l := self.get_list(key, None)) is not None: + return l + + elif (s := self.get_str(key, None)) is not None: + return s + + return default + + @abstractmethod + def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + """See get.""" + raise NotImplementedError + + @abstractmethod + def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + """See get.""" + raise NotImplementedError + + def getint(self, key: str, default: int = 0) -> int: + """See get.""" + warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead')) + return self.get_int(key, default) + + @abstractmethod + def get_int(self, key: str, default: int = 0) -> int: + """See get.""" + raise NotImplementedError + + @abstractmethod + def set(self, key: str, val: Union[int, str, List[str]]) -> None: + """Set the given key to the given data.""" + ... + + @abstractmethod + def save(self) -> None: + """Save the current configuration.""" + raise NotImplementedError + + @abstractmethod + def close(self): + """Close this config and release any associated resources.""" + raise NotImplementedError + + +class WinConfig(AbstractConfig): + """Implementation of AbstractConfig for windows.""" + + def __init__(self) -> None: + super().__init__() + # if sys.platform != 'win32': + # raise ValueError(f'Do not use WinConfig on {sys.platform}') + self.app_dir = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname + self.app_dir.mkdir(exist_ok=True) + + self.plugin_dir = self.app_dir / 'plugins' + self.plugin_dir.mkdir(exist_ok=True) + + if getattr(sys, 'frozen', False): + self.respath = pathlib.Path(dirname(sys.executable)) + self.internal_plugin_dir = self.respath / 'plugins' + + else: + self.respath = pathlib.Path(dirname(__file__)) + self.internal_plugin_dir = self.respath / 'plugins' + + self.home = pathlib.Path.home() + + journal_dir_str = known_folder_path(FOLDERID_SavedGames) + journaldir = pathlib.Path(journal_dir_str) if journal_dir_str is not None else None + self.default_journal_dir = None + if journaldir is not None: + self.default_journal_dir = journaldir / 'Frontier Developments' / 'Elite Dangerous' + + create_key_defaults = functools.partial( + winreg.CreateKeyEx, + key=winreg.HKEY_CURRENT_USER, + access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY, + ) + + try: + self.__reg_handle: winreg.HKEYType = create_key_defaults( + subkey=r'Software\Marginal\EDMarketConnector' + ) + edcd_handle: winreg.HKEYType = create_key_defaults(subkey=r'Software\EDCD\EDMarketConnector') + winsparkle_reg: winreg.HKEYType = winreg.CreateKeyEx( + edcd_handle, 'WinSparkle', access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY + ) + + except OSError: + logger.exception('could not create required registry keys') + raise + + # set WinSparkle defaults - https://github.com/vslavik/winsparkle/wiki/Registry-Settings + winreg.SetValueEx( + winsparkle_reg, 'UpdateInterval', REG_RESERVED_ALWAYS_ZERO, winreg.REG_SZ, str(update_interval) + ) + + try: + winreg.QueryValueEx(winsparkle_reg, 'CheckForUpdates') + except FileNotFoundError: + # Key doesnt exist, set it to a default + winreg.SetValueEx(winsparkle_reg, 'CheckForUpdates', REG_RESERVED_ALWAYS_ZERO, winreg.REG_SZ, '1') + + winsparkle_reg.Close() + edcd_handle.Close() + + self.identifier = applongname + if (outdir_str := self.get_str('outdir')) is None or not isdir(outdir_str): + docs = known_folder_path(FOLDERID_Documents) + self.set('outdir', docs if docs is not None else str(self.home)) + + def __get_regentry(self, key: str) -> Union[None, list, str, int]: + """Access the registry for the raw entry.""" + try: + value, _type = winreg.QueryValueEx(self.__reg_handle, key) + except FileNotFoundError: + # Key doesn't exist + return None + + if _type not in (winreg.REG_SZ, winreg.REG_MULTI_SZ, winreg.REG_DWORD): + logger.warning(f'registry key {key=} returned unknown type {_type=} {value=}') + return None + + # The type returned is actually as we'd expect for each of these. The casts are here for type checkers and + # For programmers who want to actually know what is going on + if _type == winreg.REG_SZ: + return str(value) + elif _type == winreg.REG_DWORD: + return int(value) + + return list(value) + + def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + """ + Return the string represented by the key, or the default if it does not exist. + + :param key: the key to access + :param default: the default to return when the key does not exist, defaults to None + :raises ValueError: when the key is not a string type + :return: the requested data, or the default + """ + res = self.__get_regentry(key) + if res is None: + return default + elif not isinstance(res, str): + raise ValueError(f'Data from registry is not a string: {type(res)=} {res=}') + + return res + + def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + """ + Return the list found at the given key, or the default if none exists. + + :param key: The key to access + :param default: Default to return when the key does not exist, defaults to None + :raises ValueError: When the data at the given key is not a list + :return: the requested data or the default + """ + res = self.__get_regentry(key) + if res is None: + return default + elif not isinstance(res, list): + raise ValueError(f'Data from registry is not a list: {type(res)=} {res}') + + return res + + def get_int(self, key: str, default: int = 0) -> int: + """ + Return the int found at the given key, or the default if none exists. + + :param key: The key to access + :param default: Default to return when the key does not exist, defaults to 0 + :raises ValueError: If the data returned is of an unexpected type + :return: the data requested or the default + """ + res = self.__get_regentry(key) + if res is None: + return default + + if not isinstance(res, int): + raise ValueError(f'Data from registry is not an int: {type(res)=} {res}') + + return res + + def set(self, key: str, val: Union[int, str, List[str]]) -> None: + reg_type = None + if isinstance(val, str): + reg_type = winreg.REG_SZ + winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, winreg.REG_SZ, val) + + elif isinstance(val, int): # The original code checked for numbers.Integral, I dont think that is needed. + reg_type = winreg.REG_DWORD + + elif isinstance(val, list): + reg_type = winreg.REG_MULTI_SZ + + else: + raise ValueError(f'Unexpected type for value {type(val)=}') + + # Its complaining about the list, it works, tested on windows, ignored. + winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore + + def save(self) -> None: + """Save the configuration.""" + # Not required as reg keys are flushed on write + pass + + def close(self): + """Close the config file.""" + self.__reg_handle.Close() + + class Config(): """Object that holds all configuration data.""" From 6b464432bf100a6b9dcc525259510a98c974fdec Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 16 Nov 2020 04:35:02 +0200 Subject: [PATCH 136/727] Simplified __get_registry logic. Added Docstrings --- config.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 4297106c..d7b15259 100644 --- a/config.py +++ b/config.py @@ -282,18 +282,17 @@ class WinConfig(AbstractConfig): # Key doesn't exist return None - if _type not in (winreg.REG_SZ, winreg.REG_MULTI_SZ, winreg.REG_DWORD): - logger.warning(f'registry key {key=} returned unknown type {_type=} {value=}') - return None - # The type returned is actually as we'd expect for each of these. The casts are here for type checkers and # For programmers who want to actually know what is going on if _type == winreg.REG_SZ: return str(value) elif _type == winreg.REG_DWORD: return int(value) - - return list(value) + elif _type == winreg.REG_MULTI_SZ: + return list(value) + else: + logger.warning(f'registry key {key=} returned unknown type {_type=} {value=}') + return None def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: """ @@ -348,6 +347,14 @@ class WinConfig(AbstractConfig): return res def set(self, key: str, val: Union[int, str, List[str]]) -> None: + """ + Set sets the given key to the given value. + + :param key: The key to set the value to + :param val: The value to set the key + :raises ValueError: On an invalid type + :raises OSError: On any internal failure to the registry + """ reg_type = None if isinstance(val, str): reg_type = winreg.REG_SZ From 482c502f526d206f6b330c4b79e32208c3fc92ce Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 17 Nov 2020 11:50:21 +0200 Subject: [PATCH 137/727] Added darwin config implementation --- config.py | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 160 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index d7b15259..ba26106d 100644 --- a/config.py +++ b/config.py @@ -19,7 +19,7 @@ from configparser import NoOptionError from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import TYPE_CHECKING, List, Optional, Union +from typing import TYPE_CHECKING, Dict, List, Optional, Union import semantic_version @@ -45,7 +45,7 @@ else: logger = logging.getLogger(appname) if platform == 'darwin': - from Foundation import ( + from Foundation import ( # type: ignore NSApplicationSupportDirectory, NSBundle, NSDocumentDirectory, NSSearchPathForDirectoriesInDomains, NSUserDefaults, NSUserDomainMask ) @@ -53,6 +53,7 @@ if platform == 'darwin': elif platform == 'win32': import ctypes import uuid + import winreg from ctypes.wintypes import DWORD, HANDLE, HKEY, LONG, LPCVOID, LPCWSTR if TYPE_CHECKING: import ctypes.windll # type: ignore @@ -77,6 +78,8 @@ elif platform == 'win32': REG_DWORD = 4 REG_MULTI_SZ = 7 + REG_RESERVED_ALWAYS_ZERO = 0 + RegCreateKeyEx = ctypes.windll.advapi32.RegCreateKeyExW RegCreateKeyEx.restype = LONG RegCreateKeyEx.argtypes = [ @@ -194,7 +197,16 @@ class AbstractConfig(abc.ABC): @abstractmethod def set(self, key: str, val: Union[int, str, List[str]]) -> None: """Set the given key to the given data.""" - ... + raise NotImplementedError + + @abstractmethod + def delete(self, key: str) -> None: + """ + Delete the given key from the config. + + :param key: The key to delete + """ + raise NotImplementedError @abstractmethod def save(self) -> None: @@ -202,7 +214,7 @@ class AbstractConfig(abc.ABC): raise NotImplementedError @abstractmethod - def close(self): + def close(self) -> None: """Close this config and release any associated resources.""" raise NotImplementedError @@ -211,9 +223,6 @@ class WinConfig(AbstractConfig): """Implementation of AbstractConfig for windows.""" def __init__(self) -> None: - super().__init__() - # if sys.platform != 'win32': - # raise ValueError(f'Do not use WinConfig on {sys.platform}') self.app_dir = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname self.app_dir.mkdir(exist_ok=True) @@ -262,8 +271,9 @@ class WinConfig(AbstractConfig): try: winreg.QueryValueEx(winsparkle_reg, 'CheckForUpdates') + except FileNotFoundError: - # Key doesnt exist, set it to a default + # Key doesn't exist, set it to a default winreg.SetValueEx(winsparkle_reg, 'CheckForUpdates', REG_RESERVED_ALWAYS_ZERO, winreg.REG_SZ, '1') winsparkle_reg.Close() @@ -286,10 +296,13 @@ class WinConfig(AbstractConfig): # For programmers who want to actually know what is going on if _type == winreg.REG_SZ: return str(value) + elif _type == winreg.REG_DWORD: return int(value) + elif _type == winreg.REG_MULTI_SZ: return list(value) + else: logger.warning(f'registry key {key=} returned unknown type {_type=} {value=}') return None @@ -306,6 +319,7 @@ class WinConfig(AbstractConfig): res = self.__get_regentry(key) if res is None: return default + elif not isinstance(res, str): raise ValueError(f'Data from registry is not a string: {type(res)=} {res=}') @@ -323,6 +337,7 @@ class WinConfig(AbstractConfig): res = self.__get_regentry(key) if res is None: return default + elif not isinstance(res, list): raise ValueError(f'Data from registry is not a list: {type(res)=} {res}') @@ -382,6 +397,142 @@ class WinConfig(AbstractConfig): self.__reg_handle.Close() +class MacConfig(AbstractConfig): + """MacConfig is the implementation of AbstractConfig for Darwin based OSes.""" + + def __init__(self) -> None: + super().__init__() + support_path = pathlib.Path( + NSSearchPathForDirectoriesInDomains( + NSApplicationSupportDirectory, NSUserDomainMask, True + )[0] + ) + + self.app_dir = support_path / appname + self.app_dir.mkdir(exist_ok=True) + + self.plugin_dir = self.app_dir / 'plugins' + self.plugin_dir.mkdir(exist_ok=True) + + # Bundle IDs identify a singled app though out a system + + if getattr(sys, 'frozen', False): + exe_dir = pathlib.Path(sys.executable).parent + self.internal_plugin_dir = exe_dir.parent / 'Library' / 'plugins' + self.respath = exe_dir.parent / 'Resources' + self.identifier = NSBundle.mainBundle().bundleIdentifier() + + else: + file_dir = pathlib.Path(__file__).parent + self.internal_plugin_dir = file_dir / 'plugins' + self.respath = file_dir + + self.identifier = f'uk.org.marginal.{appname.lower()}' + NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier + + self.default_journal_dir = support_path / 'Frontier Developments' / 'Elite Dangerous' + self._defaults = NSUserDefaults.standardUserDefaults() + self._settings: Dict[str, Union[int, str, list]] = dict( + self._defaults.persistentDomainForName_(self.identifier) or {} + ) # make writeable + + if (out_dir := self.get_str('out_dir')) is None or not pathlib.Path(out_dir).exists(): + self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) + + def __raw_get(self, key: str) -> Union[None, list, str, int]: + res = self._settings.get(key) + if isinstance(res, list): + return list(res) + + return res + + def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + """ + Return the string represented by the key, or the default if it does not exist. + + :param key: the key to access + :param default: the default to return when the key does not exist, defaults to None + :raises ValueError: when the key is not a string type + :return: the requested data, or the default + """ + res = self.__raw_get(key) + if res is None: + return default + + if not isinstance(res, str): + raise ValueError(f'unexpected data returned from __raw_get: {type(res)=} {res}') + + return res + + def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + """ + Return the list found at the given key, or the default if none exists. + + :param key: The key to access + :param default: Default to return when the key does not exist, defaults to None + :raises ValueError: When the data at the given key is not a list + :return: the requested data or the default + """ + res = self.__raw_get(key) + if res is None: + return default + + elif not isinstance(res, list): + raise ValueError(f'__raw_get returned unexpected type {type(res)=} {res!r}') + + return res + + def get_int(self, key: str, default: int = 0) -> int: + """ + Return the int found at the given key, or the default if none exists. + + :param key: The key to access + :param default: Default to return when the key does not exist, defaults to 0 + :raises ValueError: If the data returned is of an unexpected type + :return: the data requested or the default + """ + res = self.__raw_get(key) + if res is None: + return default + + elif not isinstance(res, (str, int)): + raise ValueError(f'__raw_get returned unexpected type {type(res)=} {res!r}') + + try: + return int(res) + + except ValueError as e: + logger.error(f'__raw_get returned {res!r} which cannot be parsed to an int: {e}') + return default + + def set(self, key: str, val: Union[int, str, List[str]]) -> None: + """ + Set sets the given key to the given value. + + :param key: The key to set the value to + :param val: The value to set the key + """ + self._settings[key] = val + + def delete(self, key: str) -> None: + """ + Delete the given key from the config. + + :param key: the key to delete + """ + del self._settings[key] + + def save(self) -> None: + """Save the configuration.""" + self._defaults.setPersistentDomain_forName_(self._settings, self.identifier) + self._defaults.synchronize() + + def close(self) -> None: + """Close the configuration.""" + self.save() + self._defaults = None + + class Config(): """Object that holds all configuration data.""" @@ -437,7 +588,7 @@ class Config(): self.settings = dict(self.defaults.persistentDomainForName_(self.identifier) or {}) # make writeable # Check out_dir exists - if not self.get('outdir') or not isdir(self.get('outdir')): + if not self.get('outdir') or not isdir(str(self.get('outdir'))): self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: From e3807648f7a6f41f60946016239ba26471629729 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 18 Nov 2020 11:18:53 +0200 Subject: [PATCH 138/727] Added linux AbstractConfig implementation --- config.py | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index ba26106d..0ebcb851 100644 --- a/config.py +++ b/config.py @@ -11,11 +11,12 @@ import abc import functools import logging import numbers +import os import pathlib import sys import warnings from abc import abstractmethod -from configparser import NoOptionError +from configparser import ConfigParser, NoOptionError from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform @@ -533,6 +534,126 @@ class MacConfig(AbstractConfig): self._defaults = None +class LinuxConfig(AbstractConfig): + """Linux implementation of AbstractConfig.""" + + SECTION = 'config' + + def __init__(self) -> None: + # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html + xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser() + self.app_dir = xdg_data_home / appname + self.app_dir.mkdir(exist_ok=True, parents=True) + + self.plugin_dir = self.app_dir / 'plugins' + self.plugin_dir.mkdir(exist_ok=True) + + self.respath = pathlib.Path(__file__).parent + + self.internal_plugin_dir = self.respath / 'plugins' + self.default_journal_dir = None + self.identifier = f'uk.org.marginal.{appname.lower()}' # TODO: Unused? + + config_home = pathlib.Path(os.getenv('XDG_CONFIG_HOME', default='~/.config')).expanduser() + + self.filename = config_home / appname / f'{appname}.ini' + self.filename.mkdir(exist_ok=True, parents=True) + + self.config: Optional[ConfigParser] = ConfigParser(comment_prefixes=('#',), interpolation=None) + + try: + self.config.read(self.filename) + except Exception as e: + logger.debug(f'Error occurred while reading in file. Assuming that we are creating a new one: {e}') + self.config.add_section(self.SECTION) + + if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir(): + self.set('outdir', str(self.home)) + + # TODO: I dislike this, would rather use a sane config file format. But here we are. + self.__unescape_table = str.maketrans({'\\n': '\n', '\\\\': '\\', '\\;': ';'}) + self.__escape_table = str.maketrans({'\n': '\\n', '\\': '\\\\', ';': '\\;'}) + + def __raw_get(self, key: str) -> Optional[str]: + if self.config is None: + raise ValueError('Attempt to use a closed config') + + return self.config[self.SECTION].get(key) + + def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + data = self.__raw_get(key) + if data is None: + return default + + if '\n' in data: + raise ValueError('asked for string, got list') + + return data.translate(self.__unescape_table) + + def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + data = self.__raw_get(key) + + if data is None: + return default + + split = data.split('\n') + if split[-1] != ';': + raise ValueError('Encoded list does not have trailer sentinel') + + return [s.translate(self.__unescape_table) for s in split[:-1]] + + def get_int(self, key: str, default: int = 0) -> int: + data = self.__raw_get(key) + + if data is None: + return default + + try: + return int(data) + + except ValueError as e: + raise ValueError(f'requested {key=} as int cannot be converted to int') from e + + def set(self, key: str, val: Union[int, str, List[str]]) -> None: + if self.config is None: + raise ValueError('attempt to use a closed config') + + to_set: Optional[str] = None + if isinstance(val, bool): + to_set = str(int(val)) + + elif isinstance(val, str): + to_set = val.translate(self.__escape_table) + + elif isinstance(val, int): + to_set = str(val) + + elif isinstance(val, list): + to_set = '\n'.join(s.translate(self.__escape_table) for s in val + [';']) + + else: + raise NotImplementedError(f'value of type {type(val)} is not supported') + + self.config.set(self.SECTION, key, to_set) + + def delete(self, key: str) -> None: + if self.config is None: + raise ValueError('attempt to use a closed config') + + self.config.remove_option(self.SECTION, key) + + def save(self) -> None: + if self.config is None: + raise ValueError('attempt to use a closed config') + + with open(self.filename, 'w', encoding='utf-8') as f: + self.config.write(f) + + def close(self) -> None: + self.save() + self.config = None + + class Config(): """Object that holds all configuration data.""" From 0367dd8ba03dbb32bd45a2cf10472ac2517b4efd Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 18 Nov 2020 11:19:42 +0200 Subject: [PATCH 139/727] Added legacy password subsystem to AbstractConfig --- config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config.py b/config.py index 0ebcb851..ce04d7e4 100644 --- a/config.py +++ b/config.py @@ -219,6 +219,18 @@ class AbstractConfig(abc.ABC): """Close this config and release any associated resources.""" raise NotImplementedError + def get_password(self, account: str) -> None: + """Legacy password retrieval.""" + warnings.warn("password subsystem is no longer supported", DeprecationWarning) + + def set_password(self, account: str, password: str) -> None: + """Legacy password setting.""" + warnings.warn("password subsystem is no longer supported", DeprecationWarning) + + def delete_password(self, account: str) -> None: + """Legacy password deletion.""" + warnings.warn("password subsystem is no longer supported", DeprecationWarning) + class WinConfig(AbstractConfig): """Implementation of AbstractConfig for windows.""" From 36f80d6b152d5a4d1b395724b7a90c1b65e713ca Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 18 Nov 2020 11:42:46 +0200 Subject: [PATCH 140/727] Updated docstrings, added bool support --- config.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index ce04d7e4..6923bea3 100644 --- a/config.py +++ b/config.py @@ -155,15 +155,18 @@ class AbstractConfig(abc.ABC): home: pathlib.Path default_journal_dir: Optional[pathlib.Path] + identifier: str + def __init__(self) -> None: self.home = pathlib.Path.home() - def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: + def get(self, key: str, default: Union[None, list, str, bool, int] = None) -> Union[None, list, str, bool, int]: """ Get the requested key, or a default. :param key: the key to get :param default: the default to return if the key does not exist, defaults to None + :raises OSError: on windows, if a registry error occurs. :return: the data or the default """ warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type')) @@ -173,26 +176,76 @@ class AbstractConfig(abc.ABC): elif (s := self.get_str(key, None)) is not None: return s + elif (b := self.get_bool(key, None)) is not None: + return b + + elif (i := self.get_int(key, None)) is not None: + return i + return default @abstractmethod def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: - """See get.""" + """ + Get the list referred to by the given key if it exists, or the default. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to None + :raises ValueError: If an internal error occurs getting or converting a value + :raises OSError: on windows, if a registry error occurs. + :return: The requested data or the default + """ raise NotImplementedError @abstractmethod def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: - """See get.""" + """ + Get the string referred to by the given key if it exists, or the default. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to None + :raises ValueError: If an internal error occurs getting or converting a value + :raises OSError: on windows, if a registry error occurs. + :return: The requested data or the default + """ raise NotImplementedError - def getint(self, key: str, default: int = 0) -> int: - """See get.""" + @abstractmethod + def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + """ + Get the bool referred to by the given key if it exists, or the default. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to None + :raises ValueError: If an internal error occurs getting or converting a value + :raises OSError: on windows, if a registry error occurs. + :return: The requested data or the default + """ + raise NotImplementedError + + def getint(self, key: str, default: Optional[int] = 0) -> Optional[int]: + """ + Getint is a Deprecated getter method. + + See get_int for its replacement. + :raises OSError: on windows, if a registry error occurs. + """ warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead')) return self.get_int(key, default) @abstractmethod - def get_int(self, key: str, default: int = 0) -> int: - """See get.""" + def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: + """ + Get the int referred to by key if it exists in the config. + + For legacy reasons, the default is 0 and not None. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to 0 + :raises ValueError: if the internal representation of this key cannot be converted to an int + :raises OSError: on windows, if a registry error occurs. + :return: The requested data or the default + """ raise NotImplementedError @abstractmethod @@ -206,12 +259,17 @@ class AbstractConfig(abc.ABC): Delete the given key from the config. :param key: The key to delete + :raises OSError: on windows, if a registry error occurs. """ raise NotImplementedError @abstractmethod def save(self) -> None: - """Save the current configuration.""" + """ + Save the current configuration. + + :raises OSError: on windows, if a registry error occurs. + """ raise NotImplementedError @abstractmethod @@ -356,7 +414,7 @@ class WinConfig(AbstractConfig): return res - def get_int(self, key: str, default: int = 0) -> int: + def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: """ Return the int found at the given key, or the default if none exists. @@ -495,7 +553,7 @@ class MacConfig(AbstractConfig): return res - def get_int(self, key: str, default: int = 0) -> int: + def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: """ Return the int found at the given key, or the default if none exists. @@ -614,7 +672,7 @@ class LinuxConfig(AbstractConfig): return [s.translate(self.__unescape_table) for s in split[:-1]] - def get_int(self, key: str, default: int = 0) -> int: + def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: data = self.__raw_get(key) if data is None: From 54023725e99914beeaac3ec3782fd88c8a95d6a0 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 18 Nov 2020 13:02:09 +0200 Subject: [PATCH 141/727] Made sure to catch exceptions in get() The various get_* functions vary in implementation, but some raise a ValueError when they are used with a key of the wrong type. This catches that ValueError when hunting for a valid type. --- config.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/config.py b/config.py index 6923bea3..e1c875aa 100644 --- a/config.py +++ b/config.py @@ -15,12 +15,13 @@ import os import pathlib import sys import warnings +import contextlib from abc import abstractmethod from configparser import ConfigParser, NoOptionError from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import TYPE_CHECKING, Dict, List, Optional, Union +from typing import Any, Callable, TYPE_CHECKING, Dict, List, Optional, Type, TypeVar, Union import semantic_version @@ -129,6 +130,9 @@ elif platform == 'linux': from configparser import RawConfigParser +_T = TypeVar('_T') + + class AbstractConfig(abc.ABC): """Abstract root class of all platform specific Config implementations.""" @@ -160,6 +164,22 @@ class AbstractConfig(abc.ABC): def __init__(self) -> None: self.home = pathlib.Path.home() + @staticmethod + def _suppress_call( + func: Callable[..., _T], exceptions: Union[Type[BaseException], List[Type[BaseException]]] = Exception, + *args: Any, **kwargs: Any + ) -> Optional[_T]: + if exceptions is None: + exceptions = [Exception] + + if not isinstance(exceptions, list): + exceptions = [exceptions] + + with contextlib.suppress(*exceptions): # type: ignore # it works fine, mypy + return func(*args, **kwargs) + + return None + def get(self, key: str, default: Union[None, list, str, bool, int] = None) -> Union[None, list, str, bool, int]: """ Get the requested key, or a default. @@ -170,16 +190,16 @@ class AbstractConfig(abc.ABC): :return: the data or the default """ warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type')) - if (l := self.get_list(key, None)) is not None: + if (l := self._suppress_call(self.get_list, ValueError, key, None)) is not None: return l - elif (s := self.get_str(key, None)) is not None: + elif (s := self._suppress_call(self.get_str, ValueError, key, None)) is not None: return s - elif (b := self.get_bool(key, None)) is not None: + elif (b := self._suppress_call(self.get_bool, ValueError, key, None)) is not None: return b - elif (i := self.get_int(key, None)) is not None: + elif (i := self._suppress_call(self.get_int, ValueError, key, None)) is not None: return i return default From 7f53230a95b8d02accc4084299741e608c3cd8e8 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 22 Nov 2020 16:10:10 +0200 Subject: [PATCH 142/727] Cleaned up imports --- config.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/config.py b/config.py index e1c875aa..90eb8600 100644 --- a/config.py +++ b/config.py @@ -8,20 +8,16 @@ Linux uses a file, but for commonality it's still a flat data structure. # spell-checker: words HKEY FOLDERID wchar wstring edcdhkey import abc +import contextlib import functools import logging -import numbers import os import pathlib import sys import warnings -import contextlib from abc import abstractmethod -from configparser import ConfigParser, NoOptionError -from os import getenv, makedirs, mkdir, pardir -from os.path import dirname, expanduser, isdir, join, normpath from sys import platform -from typing import Any, Callable, TYPE_CHECKING, Dict, List, Optional, Type, TypeVar, Union +from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Type, TypeVar, Union import semantic_version @@ -126,8 +122,7 @@ elif platform == 'win32': return retval elif platform == 'linux': - import codecs - from configparser import RawConfigParser + from configparser import ConfigParser _T = TypeVar('_T') From 55585342e1e3508659a61b3d8345bf0432de4efe Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 22 Nov 2020 16:10:37 +0200 Subject: [PATCH 143/727] Added disable bool for winsparkle checks --- config.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 90eb8600..c4bc3064 100644 --- a/config.py +++ b/config.py @@ -341,13 +341,32 @@ class WinConfig(AbstractConfig): self.__reg_handle: winreg.HKEYType = create_key_defaults( subkey=r'Software\Marginal\EDMarketConnector' ) + if do_winsparkle: + self.__setup_winsparkle() + + except OSError: + logger.exception('could not create required registry keys') + raise + + self.identifier = applongname + if (outdir_str := self.get_str('outdir')) is None or not pathlib.Path(outdir_str).is_dir(): + docs = known_folder_path(FOLDERID_Documents) + self.set('outdir', docs if docs is not None else str(self.home)) + + def __setup_winsparkle(self): + create_key_defaults = functools.partial( + winreg.CreateKeyEx, + key=winreg.HKEY_CURRENT_USER, + access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY, + ) + try: edcd_handle: winreg.HKEYType = create_key_defaults(subkey=r'Software\EDCD\EDMarketConnector') winsparkle_reg: winreg.HKEYType = winreg.CreateKeyEx( edcd_handle, 'WinSparkle', access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY ) except OSError: - logger.exception('could not create required registry keys') + logger.exception('could not open winsparkle handle') raise # set WinSparkle defaults - https://github.com/vslavik/winsparkle/wiki/Registry-Settings From 3e1a3aaf9c4a7d278597557e8d7989155081506c Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 22 Nov 2020 16:11:31 +0200 Subject: [PATCH 144/727] Added bool support to LinuxConfig --- config.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index c4bc3064..5b92a25b 100644 --- a/config.py +++ b/config.py @@ -642,8 +642,12 @@ class LinuxConfig(AbstractConfig): """Linux implementation of AbstractConfig.""" SECTION = 'config' + # TODO: I dislike this, would rather use a sane config file format. But here we are. + __unescape_lut = {'\\': '\\', 'n': '\n', ';': ';', 'r': '\r', '#': '#'} + __escape_lut = {'\\': '\\', '\n': 'n', ';': ';', '\r': 'r'} - def __init__(self) -> None: + def __init__(self, filename: Optional[str] = None) -> None: + super().__init__() # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser() self.app_dir = xdg_data_home / appname @@ -661,7 +665,10 @@ class LinuxConfig(AbstractConfig): config_home = pathlib.Path(os.getenv('XDG_CONFIG_HOME', default='~/.config')).expanduser() self.filename = config_home / appname / f'{appname}.ini' - self.filename.mkdir(exist_ok=True, parents=True) + if filename is not None: + self.filename = pathlib.Path(filename) + + self.filename.parent.mkdir(exist_ok=True, parents=True) self.config: Optional[ConfigParser] = ConfigParser(comment_prefixes=('#',), interpolation=None) @@ -718,6 +725,16 @@ class LinuxConfig(AbstractConfig): except ValueError as e: raise ValueError(f'requested {key=} as int cannot be converted to int') from e + def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + if self.config is None: + raise ValueError('attempt to use a closed config') + + data = self.__raw_get(key) + if data is None: + return default + + return bool(int(data)) + def set(self, key: str, val: Union[int, str, List[str]]) -> None: if self.config is None: raise ValueError('attempt to use a closed config') From 4eaf7175a0ba7b7bae6b527f93c4bb00a662209c Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 22 Nov 2020 16:12:11 +0200 Subject: [PATCH 145/727] Reimplemented string escaping on LinuxConfig --- config.py | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index 5b92a25b..6a19be99 100644 --- a/config.py +++ b/config.py @@ -681,9 +681,44 @@ class LinuxConfig(AbstractConfig): if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir(): self.set('outdir', str(self.home)) - # TODO: I dislike this, would rather use a sane config file format. But here we are. - self.__unescape_table = str.maketrans({'\\n': '\n', '\\\\': '\\', '\\;': ';'}) - self.__escape_table = str.maketrans({'\n': '\\n', '\\': '\\\\', ';': '\\;'}) + def __escape(self, s: str) -> str: + """ + Escape the string using self.__escape_lut. + + This does NOT support multi-character escapes + """ + out = "" + for c in s: + if c not in self.__escape_lut: + out += c + continue + + out += '\\' + self.__escape_lut[c] + + return out + + def __unescape(self, s: str) -> str: + out: List[str] = [] + i = 0 + while i < len(s): + c = s[i] + if c != '\\': + out.append(c) + i += 1 + continue + + # We have a backslash, check what its escaping + if i == len(s)-1: + raise ValueError('Escaped string has unescaped trailer') + + unescaped = self.__unescape_lut.get(s[i+1]) + if unescaped is None: + raise ValueError(f'Unknown escape: \\ {s[i+1]}') + + out.append(unescaped) + i += 2 + + return "".join(out) def __raw_get(self, key: str) -> Optional[str]: if self.config is None: @@ -699,7 +734,7 @@ class LinuxConfig(AbstractConfig): if '\n' in data: raise ValueError('asked for string, got list') - return data.translate(self.__unescape_table) + return self.__unescape(data) def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: data = self.__raw_get(key) @@ -711,7 +746,7 @@ class LinuxConfig(AbstractConfig): if split[-1] != ';': raise ValueError('Encoded list does not have trailer sentinel') - return [s.translate(self.__unescape_table) for s in split[:-1]] + return list(map(self.__unescape, split[:-1])) def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: data = self.__raw_get(key) @@ -744,13 +779,13 @@ class LinuxConfig(AbstractConfig): to_set = str(int(val)) elif isinstance(val, str): - to_set = val.translate(self.__escape_table) + to_set = self.__escape(val) elif isinstance(val, int): to_set = str(val) elif isinstance(val, list): - to_set = '\n'.join(s.translate(self.__escape_table) for s in val + [';']) + to_set = '\n'.join([self.__escape(s) for s in val] + [';']) else: raise NotImplementedError(f'value of type {type(val)} is not supported') From b3cc94031b0e8732b7dd9a031e76d15865a6a00d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 13:05:12 +0000 Subject: [PATCH 146/727] Removed old config code # Conflicts: # config.py --- config.py | 412 ++---------------------------------------------------- 1 file changed, 9 insertions(+), 403 deletions(-) diff --git a/config.py b/config.py index 6a19be99..371b0234 100644 --- a/config.py +++ b/config.py @@ -810,409 +810,15 @@ class LinuxConfig(AbstractConfig): self.config = None -class Config(): - """Object that holds all configuration data.""" - - OUT_MKT_EDDN = 1 - # OUT_MKT_BPC = 2 # No longer supported - OUT_MKT_TD = 4 - OUT_MKT_CSV = 8 - OUT_SHIP = 16 - # OUT_SHIP_EDS = 16 # Replaced by OUT_SHIP - # OUT_SYS_FILE = 32 # No longer supported - # OUT_STAT = 64 # No longer available - # OUT_SHIP_CORIOLIS = 128 # Replaced by OUT_SHIP - OUT_STATION_ANY = OUT_MKT_EDDN | OUT_MKT_TD | OUT_MKT_CSV - # OUT_SYS_EDSM = 256 # Now a plugin - # OUT_SYS_AUTO = 512 # Now always automatic - OUT_MKT_MANUAL = 1024 - OUT_SYS_EDDN = 2048 - OUT_SYS_DELAY = 4096 - - if platform == 'darwin': # noqa: C901 # It's gating *all* the functions - - def __init__(self): - self.app_dir = join( - NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname - ) - if not isdir(self.app_dir): - mkdir(self.app_dir) - - self.plugin_dir = join(self.app_dir, 'plugins') - if not isdir(self.plugin_dir): - mkdir(self.plugin_dir) - - if getattr(sys, 'frozen', False): - self.internal_plugin_dir = normpath(join(dirname(sys.executable), pardir, 'Library', 'plugins')) - self.respath = normpath(join(dirname(sys.executable), pardir, 'Resources')) - self.identifier = NSBundle.mainBundle().bundleIdentifier() - - else: - self.internal_plugin_dir = join(dirname(__file__), 'plugins') - self.respath = dirname(__file__) - # Don't use Python's settings if interactive - self.identifier = f'uk.org.marginal.{appname.lower()}' - NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier - - self.default_journal_dir = join( - NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], - 'Frontier Developments', - 'Elite Dangerous' - ) - self.home = expanduser('~') - - self.defaults = NSUserDefaults.standardUserDefaults() - self.settings = dict(self.defaults.persistentDomainForName_(self.identifier) or {}) # make writeable - - # Check out_dir exists - if not self.get('outdir') or not isdir(str(self.get('outdir'))): - self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) - - def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: - """Look up a string configuration value.""" - val = self.settings.get(key) - if val is None: - return default - - elif isinstance(val, str): - return str(val) - - elif isinstance(val, list): - return list(val) # make writeable - - else: - return default - - def getint(self, key: str, default: int = 0) -> int: - """Look up an integer configuration value.""" - try: - return int(self.settings.get(key, default)) # should already be int, but check by casting - - except ValueError as e: - logger.error(f"Failed to int({key=})", exc_info=e) - return default - - except Exception as e: - logger.debug('The exception type is ...', exc_info=e) - return default - - def set(self, key: str, val: Union[int, str, list]) -> None: - """Set value on the specified configuration key.""" - self.settings[key] = val - - def delete(self, key: str) -> None: - """Delete the specified configuration key.""" - self.settings.pop(key, None) - - def save(self) -> None: - """Save current configuration to disk.""" - self.defaults.setPersistentDomain_forName_(self.settings, self.identifier) - self.defaults.synchronize() - - def close(self) -> None: - """Close the configuration.""" - self.save() - self.defaults = None - - elif platform == 'win32': - - def __init__(self): - self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) - if not isdir(self.app_dir): - mkdir(self.app_dir) - - self.plugin_dir = join(self.app_dir, 'plugins') - if not isdir(self.plugin_dir): - mkdir(self.plugin_dir) - - if getattr(sys, 'frozen', False): - self.internal_plugin_dir = join(dirname(sys.executable), 'plugins') - self.respath = dirname(sys.executable) - - else: - self.internal_plugin_dir = join(dirname(__file__), 'plugins') - self.respath = dirname(__file__) - - # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 - self.home = known_folder_path(FOLDERID_Profile) or r'\\' - - journaldir = known_folder_path(FOLDERID_SavedGames) - if journaldir: - self.default_journal_dir = join(journaldir, 'Frontier Developments', 'Elite Dangerous') - - else: - self.default_journal_dir = None - - self.identifier = applongname - self.hkey = HKEY() - disposition = DWORD() - if RegCreateKeyEx( - HKEY_CURRENT_USER, - r'Software\Marginal\EDMarketConnector', - 0, - None, - 0, - KEY_ALL_ACCESS, - None, - ctypes.byref(self.hkey), - ctypes.byref(disposition) - ): - raise Exception() - - # set WinSparkle defaults - https://github.com/vslavik/winsparkle/wiki/Registry-Settings - edcdhkey = HKEY() - if RegCreateKeyEx( - HKEY_CURRENT_USER, - r'Software\EDCD\EDMarketConnector', - 0, - None, - 0, - KEY_ALL_ACCESS, - None, - ctypes.byref(edcdhkey), - ctypes.byref(disposition) - ): - raise Exception() - - sparklekey = HKEY() - if not RegCreateKeyEx( - edcdhkey, - 'WinSparkle', - 0, - None, - 0, - KEY_ALL_ACCESS, - None, - ctypes.byref(sparklekey), - ctypes.byref(disposition) - ): - if disposition.value == REG_CREATED_NEW_KEY: - buf = ctypes.create_unicode_buffer('1') - RegSetValueEx(sparklekey, 'CheckForUpdates', 0, 1, buf, len(buf) * 2) - - buf = ctypes.create_unicode_buffer(str(update_interval)) - RegSetValueEx(sparklekey, 'UpdateInterval', 0, 1, buf, len(buf) * 2) - RegCloseKey(sparklekey) - - if not self.get('outdir') or not isdir(self.get('outdir')): - self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) - - def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: - """Look up a string configuration value.""" - key_type = DWORD() - key_size = DWORD() - # Only strings are handled here. - if ( - RegQueryValueEx( - self.hkey, - key, - 0, - ctypes.byref(key_type), - None, - ctypes.byref(key_size) - ) - or key_type.value not in [REG_SZ, REG_MULTI_SZ] - ): - return default - - buf = ctypes.create_unicode_buffer(int(key_size.value / 2)) - if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(key_type), buf, ctypes.byref(key_size)): - return default - - elif key_type.value == REG_MULTI_SZ: - return list(ctypes.wstring_at(buf, len(buf)-2).split('\x00')) - - else: - return str(buf.value) - - def getint(self, key: str, default: int = 0) -> int: - """Look up an integer configuration value.""" - key_type = DWORD() - key_size = DWORD(4) - key_val = DWORD() - if ( - RegQueryValueEx( - self.hkey, - key, - 0, - ctypes.byref(key_type), - ctypes.byref(key_val), - ctypes.byref(key_size) - ) - or key_type.value != REG_DWORD - ): - return default - - else: - return key_val.value - - def set(self, key: str, val: Union[int, str, list]) -> None: - """Set value on the specified configuration key.""" - if isinstance(val, str): - buf = ctypes.create_unicode_buffer(val) - RegSetValueEx(self.hkey, key, 0, REG_SZ, buf, len(buf)*2) - - elif isinstance(val, numbers.Integral): - RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4) - - elif isinstance(val, list): - # null terminated non-empty strings - string_val = '\x00'.join([str(x) or ' ' for x in val] + ['']) - buf = ctypes.create_unicode_buffer(string_val) - RegSetValueEx(self.hkey, key, 0, REG_MULTI_SZ, buf, len(buf)*2) - - else: - raise NotImplementedError() - - def delete(self, key: str) -> None: - """Delete the specified configuration key.""" - RegDeleteValue(self.hkey, key) - - def save(self) -> None: - """Save current configuration to disk.""" - pass # Redundant since registry keys are written immediately - - def close(self) -> None: - """Close the configuration.""" - RegCloseKey(self.hkey) - self.hkey = None - - elif platform == 'linux': - SECTION = 'config' - - def __init__(self): - self.__in_shutdown = False # Is the application currently shutting down ? - self.__auth_force_localserver = False # Should we use localhost for auth callback ? - - # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html - self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname) - if not isdir(self.app_dir): - makedirs(self.app_dir) - - self.plugin_dir = join(self.app_dir, 'plugins') - if not isdir(self.plugin_dir): - mkdir(self.plugin_dir) - - self.internal_plugin_dir = join(dirname(__file__), 'plugins') - self.default_journal_dir = None - self.home = expanduser('~') - self.respath = dirname(__file__) - self.identifier = f'uk.org.marginal.{appname.lower()}' - - self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, f'{appname}.ini') - if not isdir(dirname(self.filename)): - makedirs(dirname(self.filename)) - - self.config = RawConfigParser(comment_prefixes=('#',)) - try: - with codecs.open(self.filename, 'r') as h: - self.config.read_file(h) - - except Exception as e: - logger.debug('Reading config failed, assuming we\'re making a new one...', exc_info=e) - self.config.add_section(self.SECTION) - - if not self.get('outdir') or not isdir(self.get('outdir')): - self.set('outdir', expanduser('~')) - - def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: - """Look up a string configuration value.""" - try: - val = self.config.get(self.SECTION, key) - if '\n' in val: # list - # ConfigParser drops the last entry if blank, - # so we add a spurious ';' entry in set() and remove it here - assert val.split('\n')[-1] == ';', val.split('\n') - return [self._unescape(x) for x in val.split('\n')[:-1]] - else: - return self._unescape(val) - - except NoOptionError: - logger.debug(f'attempted to get key {key} that does not exist') - return default - - except Exception as e: - logger.debug('And the exception type is...', exc_info=e) - return default - - def getint(self, key: str, default: int = 0) -> int: - """Look up an integer configuration value.""" - try: - return self.config.getint(self.SECTION, key) - - except ValueError as e: - logger.error(f"Failed to int({key=})", exc_info=e) - - except NoOptionError: - logger.debug(f'attempted to get key {key} that does not exist') - - except Exception: - logger.exception(f'unexpected exception while attempting to access {key}') - - return default - - def set(self, key: str, val: Union[int, str, list]) -> None: - """Set value on the specified configuration key.""" - if isinstance(val, bool): - self.config.set(self.SECTION, key, val and '1' or '0') - - elif isinstance(val, str) or isinstance(val, numbers.Integral): - self.config.set(self.SECTION, key, self._escape(val)) - - elif isinstance(val, list): - self.config.set(self.SECTION, key, '\n'.join([self._escape(x) for x in val] + [';'])) - - else: - raise NotImplementedError() - - def delete(self, key: str) -> None: - """Delete the specified configuration key.""" - self.config.remove_option(self.SECTION, key) - - def save(self) -> None: - """Save current configuration to disk.""" - with codecs.open(self.filename, 'w', 'utf-8') as h: - self.config.write(h) - - def close(self) -> None: - """Close the configuration.""" - self.save() - self.config = None - - def _escape(self, val: str) -> str: - """Escape a string for storage.""" - return str(val).replace('\\', '\\\\').replace('\n', '\\n').replace(';', '\\;') - - def _unescape(self, val: str) -> str: - """Un-escape a string from storage.""" - chars = list(val) - i = 0 - while i < len(chars): - if chars[i] == '\\': - chars.pop(i) - if chars[i] == 'n': - chars[i] = '\n' - i += 1 - return ''.join(chars) - +def get_config(*args, **kwargs) -> AbstractConfig: + if sys.platform == "darwin": + return MacConfig(*args, **kwargs) + elif sys.platform == "win32": + return WinConfig(*args, **kwargs) + elif sys.platform == "linux": + return LinuxConfig(*args, **kwargs) else: - def __init__(self): - raise NotImplementedError('Implement me') - - # Common - - def get_password(self, account: str) -> None: - """Legacy password retrieval.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) - - def set_password(self, account: str, password: str) -> None: - """Legacy password setting.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) - - def delete_password(self, account: str) -> None: - """Legacy password deletion.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) + raise ValueError(f'Unknown platform: {sys.platform=}') -# singleton -config = Config() +config = get_config() From 0e339111f1976bee95ec4a15c285ab270889fc5f Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 22 Nov 2020 16:13:47 +0200 Subject: [PATCH 147/727] Made sure to grab the correct dir for paths on windows --- config.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/config.py b/config.py index 371b0234..2364f519 100644 --- a/config.py +++ b/config.py @@ -308,7 +308,7 @@ class AbstractConfig(abc.ABC): class WinConfig(AbstractConfig): """Implementation of AbstractConfig for windows.""" - def __init__(self) -> None: + def __init__(self, do_winsparkle=True) -> None: self.app_dir = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname self.app_dir.mkdir(exist_ok=True) @@ -316,11 +316,11 @@ class WinConfig(AbstractConfig): self.plugin_dir.mkdir(exist_ok=True) if getattr(sys, 'frozen', False): - self.respath = pathlib.Path(dirname(sys.executable)) + self.respath = pathlib.Path(sys.executable).parent self.internal_plugin_dir = self.respath / 'plugins' else: - self.respath = pathlib.Path(dirname(__file__)) + self.respath = pathlib.Path(__file__).parent self.internal_plugin_dir = self.respath / 'plugins' self.home = pathlib.Path.home() @@ -384,11 +384,6 @@ class WinConfig(AbstractConfig): winsparkle_reg.Close() edcd_handle.Close() - self.identifier = applongname - if (outdir_str := self.get_str('outdir')) is None or not isdir(outdir_str): - docs = known_folder_path(FOLDERID_Documents) - self.set('outdir', docs if docs is not None else str(self.home)) - def __get_regentry(self, key: str) -> Union[None, list, str, int]: """Access the registry for the raw entry.""" try: From a5140f0be2ee70c00d7529f1d542f0f35b88bcb1 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 22 Nov 2020 16:14:05 +0200 Subject: [PATCH 148/727] Replaced getenv with os.getenv --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 2364f519..2ac94077 100644 --- a/config.py +++ b/config.py @@ -36,7 +36,7 @@ copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' update_interval = 8*60*60 -if getenv("EDMC_NO_UI"): +if os.getenv("EDMC_NO_UI"): logger = logging.getLogger(appcmdname) else: From 63c3c55b9b30898283058b3ce5be4892a86c9949 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 22 Nov 2020 16:19:41 +0200 Subject: [PATCH 149/727] Cleaned up windows imports --- config.py | 50 ++++---------------------------------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/config.py b/config.py index 2ac94077..87c30f3c 100644 --- a/config.py +++ b/config.py @@ -52,10 +52,13 @@ elif platform == 'win32': import ctypes import uuid import winreg - from ctypes.wintypes import DWORD, HANDLE, HKEY, LONG, LPCVOID, LPCWSTR + from ctypes.wintypes import DWORD, HANDLE if TYPE_CHECKING: import ctypes.windll # type: ignore + REG_RESERVED_ALWAYS_ZERO = 0 + + # This is the only way to do this from python without external deps (which do this anyway). FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') FOLDERID_Profile = uuid.UUID('{5E6C858F-0E22-4760-9AFE-EA3317B67173}') @@ -67,51 +70,6 @@ elif platform == 'win32': CoTaskMemFree = ctypes.windll.ole32.CoTaskMemFree CoTaskMemFree.argtypes = [ctypes.c_void_p] - # winreg in Python <= 3.7.4 handles REG_MULTI_SZ incorrectly, so do this instead. https://bugs.python.org/issue32587 - HKEY_CURRENT_USER = 0x80000001 - KEY_ALL_ACCESS = 0x000F003F - REG_CREATED_NEW_KEY = 0x00000001 - REG_OPENED_EXISTING_KEY = 0x00000002 - REG_SZ = 1 - REG_DWORD = 4 - REG_MULTI_SZ = 7 - - REG_RESERVED_ALWAYS_ZERO = 0 - - RegCreateKeyEx = ctypes.windll.advapi32.RegCreateKeyExW - RegCreateKeyEx.restype = LONG - RegCreateKeyEx.argtypes = [ - HKEY, LPCWSTR, DWORD, LPCVOID, DWORD, DWORD, LPCVOID, ctypes.POINTER(HKEY), ctypes.POINTER(DWORD) - ] - - RegOpenKeyEx = ctypes.windll.advapi32.RegOpenKeyExW - RegOpenKeyEx.restype = LONG - RegOpenKeyEx.argtypes = [HKEY, LPCWSTR, DWORD, DWORD, ctypes.POINTER(HKEY)] - - RegCloseKey = ctypes.windll.advapi32.RegCloseKey - RegCloseKey.restype = LONG - RegCloseKey.argtypes = [HKEY] - - RegQueryValueEx = ctypes.windll.advapi32.RegQueryValueExW - RegQueryValueEx.restype = LONG - RegQueryValueEx.argtypes = [HKEY, LPCWSTR, LPCVOID, ctypes.POINTER(DWORD), LPCVOID, ctypes.POINTER(DWORD)] - - RegSetValueEx = ctypes.windll.advapi32.RegSetValueExW - RegSetValueEx.restype = LONG - RegSetValueEx.argtypes = [HKEY, LPCWSTR, LPCVOID, DWORD, LPCVOID, DWORD] - - RegCopyTree = ctypes.windll.advapi32.RegCopyTreeW - RegCopyTree.restype = LONG - RegCopyTree.argtypes = [HKEY, LPCWSTR, HKEY] - - RegDeleteKey = ctypes.windll.advapi32.RegDeleteTreeW - RegDeleteKey.restype = LONG - RegDeleteKey.argtypes = [HKEY, LPCWSTR] - - RegDeleteValue = ctypes.windll.advapi32.RegDeleteValueW - RegDeleteValue.restype = LONG - RegDeleteValue.argtypes = [HKEY, LPCWSTR] - def known_folder_path(guid: uuid.UUID) -> Optional[str]: """Look up a Windows GUID to actual folder path name.""" buf = ctypes.c_wchar_p() From 82fc4b56f7eff44de5d853922a66a294891ec4c9 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:00:34 +0200 Subject: [PATCH 150/727] Added bool to valid set args --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 87c30f3c..f88ba316 100644 --- a/config.py +++ b/config.py @@ -222,7 +222,7 @@ class AbstractConfig(abc.ABC): raise NotImplementedError @abstractmethod - def set(self, key: str, val: Union[int, str, List[str]]) -> None: + def set(self, key: str, val: Union[int, str, List[str], bool]) -> None: """Set the given key to the given data.""" raise NotImplementedError From 9e1bb0a2a2d1e5885d3491ab42ae3658bef70102 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:01:14 +0200 Subject: [PATCH 151/727] Added bool support to WinConfig --- config.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index f88ba316..ba1063a6 100644 --- a/config.py +++ b/config.py @@ -419,7 +419,22 @@ class WinConfig(AbstractConfig): return res - def set(self, key: str, val: Union[int, str, List[str]]) -> None: + def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + """ + Return the bool found at the given key, or the default if none exists. + + :param key: The key to access + :param default: Default to return when key does not exist, defaults to None + :raises ValueError: If the data returned is of an unexpected type + :return: The data requested or the default + """ + res = self.get_int(key) + if res is None: + return default + + return bool(res) + + def set(self, key: str, val: Union[int, str, List[str], bool]) -> None: """ Set sets the given key to the given value. @@ -439,6 +454,10 @@ class WinConfig(AbstractConfig): elif isinstance(val, list): reg_type = winreg.REG_MULTI_SZ + elif isinstance(val, bool): + reg_type = winreg.REG_DWORD + val = int(val) + else: raise ValueError(f'Unexpected type for value {type(val)=}') From bb431b83c14673ed9343a59939d8d2ecaa5c4bb7 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:01:27 +0200 Subject: [PATCH 152/727] Added bool support to MacConfig --- config.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index ba1063a6..d6ab45b3 100644 --- a/config.py +++ b/config.py @@ -582,7 +582,17 @@ class MacConfig(AbstractConfig): logger.error(f'__raw_get returned {res!r} which cannot be parsed to an int: {e}') return default - def set(self, key: str, val: Union[int, str, List[str]]) -> None: + def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + res = self.__raw_get(key) + if res is None: + return default + + elif not isinstance(res, bool): + raise ValueError(f'__raw_get returned unexpected type {type(res)=} {res!r}') + + return res + + def set(self, key: str, val: Union[int, str, List[str], bool]) -> None: """ Set sets the given key to the given value. From c72c1be4da7ad9765ce771616865cb87d1801d7d Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:15:00 +0200 Subject: [PATCH 153/727] Added testing libraries --- requirements-dev.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index d3fbb7dd..c73ff026 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -25,5 +25,11 @@ grip==4.5.2 # We only need py2exe on windows. py2exe==0.10.1.0; sys_platform == 'win32' +# Testing +pytest==6.1.2 +pytest-cov==2.10.1 # Pytest code coverage support +coverage[toml]==5.3 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs + + # All of the normal requirements -r requirements.txt From 9c3de53a3b0ddccd003bcb4852b76459d6f199fc Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:17:16 +0200 Subject: [PATCH 154/727] Added config tests --- tests/_old_config.py | 500 +++++++++++++++++++++++++++++++++++++++++++ tests/test_config.py | 187 ++++++++++++++++ 2 files changed, 687 insertions(+) create mode 100644 tests/_old_config.py create mode 100644 tests/test_config.py diff --git a/tests/_old_config.py b/tests/_old_config.py new file mode 100644 index 00000000..197ca9f8 --- /dev/null +++ b/tests/_old_config.py @@ -0,0 +1,500 @@ +import numbers +import sys +import warnings +from configparser import NoOptionError +from os import getenv, mkdir, pardir, makedirs +from os.path import dirname, expanduser, isdir, join, normpath +from sys import platform +from typing import TYPE_CHECKING, Optional, Union + +from config import applongname, appname, update_interval +from EDMCLogging import get_main_logger + +logger = get_main_logger() + +if platform == 'darwin': + from Foundation import ( # type: ignore + NSApplicationSupportDirectory, NSBundle, NSDocumentDirectory, NSSearchPathForDirectoriesInDomains, + NSUserDefaults, NSUserDomainMask + ) + +elif platform == 'win32': + import ctypes + import uuid + from ctypes.wintypes import DWORD, HANDLE, HKEY, LONG, LPCVOID, LPCWSTR + if TYPE_CHECKING: + import ctypes.windll # type: ignore + + FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') + FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') + FOLDERID_Profile = uuid.UUID('{5E6C858F-0E22-4760-9AFE-EA3317B67173}') + FOLDERID_SavedGames = uuid.UUID('{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}') + + SHGetKnownFolderPath = ctypes.windll.shell32.SHGetKnownFolderPath + SHGetKnownFolderPath.argtypes = [ctypes.c_char_p, DWORD, HANDLE, ctypes.POINTER(ctypes.c_wchar_p)] + + CoTaskMemFree = ctypes.windll.ole32.CoTaskMemFree + CoTaskMemFree.argtypes = [ctypes.c_void_p] + + # winreg in Python <= 3.7.4 handles REG_MULTI_SZ incorrectly, so do this instead. https://bugs.python.org/issue32587 + HKEY_CURRENT_USER = 0x80000001 + KEY_ALL_ACCESS = 0x000F003F + REG_CREATED_NEW_KEY = 0x00000001 + REG_OPENED_EXISTING_KEY = 0x00000002 + REG_SZ = 1 + REG_DWORD = 4 + REG_MULTI_SZ = 7 + + REG_RESERVED_ALWAYS_ZERO = 0 + + RegCreateKeyEx = ctypes.windll.advapi32.RegCreateKeyExW + RegCreateKeyEx.restype = LONG + RegCreateKeyEx.argtypes = [ + HKEY, LPCWSTR, DWORD, LPCVOID, DWORD, DWORD, LPCVOID, ctypes.POINTER(HKEY), ctypes.POINTER(DWORD) + ] + + RegOpenKeyEx = ctypes.windll.advapi32.RegOpenKeyExW + RegOpenKeyEx.restype = LONG + RegOpenKeyEx.argtypes = [HKEY, LPCWSTR, DWORD, DWORD, ctypes.POINTER(HKEY)] + + RegCloseKey = ctypes.windll.advapi32.RegCloseKey + RegCloseKey.restype = LONG + RegCloseKey.argtypes = [HKEY] + + RegQueryValueEx = ctypes.windll.advapi32.RegQueryValueExW + RegQueryValueEx.restype = LONG + RegQueryValueEx.argtypes = [HKEY, LPCWSTR, LPCVOID, ctypes.POINTER(DWORD), LPCVOID, ctypes.POINTER(DWORD)] + + RegSetValueEx = ctypes.windll.advapi32.RegSetValueExW + RegSetValueEx.restype = LONG + RegSetValueEx.argtypes = [HKEY, LPCWSTR, LPCVOID, DWORD, LPCVOID, DWORD] + + RegCopyTree = ctypes.windll.advapi32.RegCopyTreeW + RegCopyTree.restype = LONG + RegCopyTree.argtypes = [HKEY, LPCWSTR, HKEY] + + RegDeleteKey = ctypes.windll.advapi32.RegDeleteTreeW + RegDeleteKey.restype = LONG + RegDeleteKey.argtypes = [HKEY, LPCWSTR] + + RegDeleteValue = ctypes.windll.advapi32.RegDeleteValueW + RegDeleteValue.restype = LONG + RegDeleteValue.argtypes = [HKEY, LPCWSTR] + + def known_folder_path(guid: uuid.UUID) -> Optional[str]: + """Look up a Windows GUID to actual folder path name.""" + buf = ctypes.c_wchar_p() + if SHGetKnownFolderPath(ctypes.create_string_buffer(guid.bytes_le), 0, 0, ctypes.byref(buf)): + return None + retval = buf.value # copy data + CoTaskMemFree(buf) # and free original + return retval + +elif platform == 'linux': + import codecs + from configparser import RawConfigParser + + +class OldConfig(): + """Object that holds all configuration data.""" + + OUT_MKT_EDDN = 1 + # OUT_MKT_BPC = 2 # No longer supported + OUT_MKT_TD = 4 + OUT_MKT_CSV = 8 + OUT_SHIP = 16 + # OUT_SHIP_EDS = 16 # Replaced by OUT_SHIP + # OUT_SYS_FILE = 32 # No longer supported + # OUT_STAT = 64 # No longer available + # OUT_SHIP_CORIOLIS = 128 # Replaced by OUT_SHIP + OUT_STATION_ANY = OUT_MKT_EDDN | OUT_MKT_TD | OUT_MKT_CSV + # OUT_SYS_EDSM = 256 # Now a plugin + # OUT_SYS_AUTO = 512 # Now always automatic + OUT_MKT_MANUAL = 1024 + OUT_SYS_EDDN = 2048 + OUT_SYS_DELAY = 4096 + + if platform == 'darwin': # noqa: C901 # It's gating *all* the functions + + def __init__(self): + self.app_dir = join( + NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname + ) + if not isdir(self.app_dir): + mkdir(self.app_dir) + + self.plugin_dir = join(self.app_dir, 'plugins') + if not isdir(self.plugin_dir): + mkdir(self.plugin_dir) + + if getattr(sys, 'frozen', False): + self.internal_plugin_dir = normpath(join(dirname(sys.executable), pardir, 'Library', 'plugins')) + self.respath = normpath(join(dirname(sys.executable), pardir, 'Resources')) + self.identifier = NSBundle.mainBundle().bundleIdentifier() + + else: + self.internal_plugin_dir = join(dirname(__file__), 'plugins') + self.respath = dirname(__file__) + # Don't use Python's settings if interactive + self.identifier = f'uk.org.marginal.{appname.lower()}' + NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier + + self.default_journal_dir = join( + NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], + 'Frontier Developments', + 'Elite Dangerous' + ) + self.home = expanduser('~') + + self.defaults = NSUserDefaults.standardUserDefaults() + self.settings = dict(self.defaults.persistentDomainForName_(self.identifier) or {}) # make writeable + + # Check out_dir exists + if not self.get('outdir') or not isdir(str(self.get('outdir'))): + self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) + + def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: + """Look up a string configuration value.""" + val = self.settings.get(key) + if val is None: + return default + + elif isinstance(val, str): + return str(val) + + elif isinstance(val, list): + return list(val) # make writeable + + else: + return default + + def getint(self, key: str, default: int = 0) -> int: + """Look up an integer configuration value.""" + try: + return int(self.settings.get(key, default)) # should already be int, but check by casting + + except ValueError as e: + logger.error(f"Failed to int({key=})", exc_info=e) + return default + + except Exception as e: + logger.debug('The exception type is ...', exc_info=e) + return default + + def set(self, key: str, val: Union[int, str, list]) -> None: + """Set value on the specified configuration key.""" + self.settings[key] = val + + def delete(self, key: str) -> None: + """Delete the specified configuration key.""" + self.settings.pop(key, None) + + def save(self) -> None: + """Save current configuration to disk.""" + self.defaults.setPersistentDomain_forName_(self.settings, self.identifier) + self.defaults.synchronize() + + def close(self) -> None: + """Close the configuration.""" + self.save() + self.defaults = None + + elif platform == 'win32': + + def __init__(self): + self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) + if not isdir(self.app_dir): + mkdir(self.app_dir) + + self.plugin_dir = join(self.app_dir, 'plugins') + if not isdir(self.plugin_dir): + mkdir(self.plugin_dir) + + if getattr(sys, 'frozen', False): + self.internal_plugin_dir = join(dirname(sys.executable), 'plugins') + self.respath = dirname(sys.executable) + + else: + self.internal_plugin_dir = join(dirname(__file__), 'plugins') + self.respath = dirname(__file__) + + # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 + self.home = known_folder_path(FOLDERID_Profile) or r'\\' + + journaldir = known_folder_path(FOLDERID_SavedGames) + if journaldir: + self.default_journal_dir = join(journaldir, 'Frontier Developments', 'Elite Dangerous') + + else: + self.default_journal_dir = None + + self.identifier = applongname + self.hkey = HKEY() + disposition = DWORD() + if RegCreateKeyEx( + HKEY_CURRENT_USER, + r'Software\Marginal\EDMarketConnector', + 0, + None, + 0, + KEY_ALL_ACCESS, + None, + ctypes.byref(self.hkey), + ctypes.byref(disposition) + ): + raise Exception() + + # set WinSparkle defaults - https://github.com/vslavik/winsparkle/wiki/Registry-Settings + edcdhkey = HKEY() + if RegCreateKeyEx( + HKEY_CURRENT_USER, + r'Software\EDCD\EDMarketConnector', + 0, + None, + 0, + KEY_ALL_ACCESS, + None, + ctypes.byref(edcdhkey), + ctypes.byref(disposition) + ): + raise Exception() + + sparklekey = HKEY() + if not RegCreateKeyEx( + edcdhkey, + 'WinSparkle', + 0, + None, + 0, + KEY_ALL_ACCESS, + None, + ctypes.byref(sparklekey), + ctypes.byref(disposition) + ): + if disposition.value == REG_CREATED_NEW_KEY: + buf = ctypes.create_unicode_buffer('1') + RegSetValueEx(sparklekey, 'CheckForUpdates', 0, 1, buf, len(buf) * 2) + + buf = ctypes.create_unicode_buffer(str(update_interval)) + RegSetValueEx(sparklekey, 'UpdateInterval', 0, 1, buf, len(buf) * 2) + RegCloseKey(sparklekey) + + if not self.get('outdir') or not isdir(self.get('outdir')): + self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) + + def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: + """Look up a string configuration value.""" + key_type = DWORD() + key_size = DWORD() + # Only strings are handled here. + if ( + RegQueryValueEx( + self.hkey, + key, + 0, + ctypes.byref(key_type), + None, + ctypes.byref(key_size) + ) + or key_type.value not in [REG_SZ, REG_MULTI_SZ] + ): + return default + + buf = ctypes.create_unicode_buffer(int(key_size.value / 2)) + if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(key_type), buf, ctypes.byref(key_size)): + return default + + elif key_type.value == REG_MULTI_SZ: + return list(ctypes.wstring_at(buf, len(buf)-2).split('\x00')) + + else: + return str(buf.value) + + def getint(self, key: str, default: int = 0) -> int: + """Look up an integer configuration value.""" + key_type = DWORD() + key_size = DWORD(4) + key_val = DWORD() + if ( + RegQueryValueEx( + self.hkey, + key, + 0, + ctypes.byref(key_type), + ctypes.byref(key_val), + ctypes.byref(key_size) + ) + or key_type.value != REG_DWORD + ): + return default + + else: + return key_val.value + + def set(self, key: str, val: Union[int, str, list]) -> None: + """Set value on the specified configuration key.""" + if isinstance(val, str): + buf = ctypes.create_unicode_buffer(val) + RegSetValueEx(self.hkey, key, 0, REG_SZ, buf, len(buf)*2) + + elif isinstance(val, numbers.Integral): + RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4) + + elif isinstance(val, list): + # null terminated non-empty strings + string_val = '\x00'.join([str(x) or ' ' for x in val] + ['']) + buf = ctypes.create_unicode_buffer(string_val) + RegSetValueEx(self.hkey, key, 0, REG_MULTI_SZ, buf, len(buf)*2) + + else: + raise NotImplementedError() + + def delete(self, key: str) -> None: + """Delete the specified configuration key.""" + RegDeleteValue(self.hkey, key) + + def save(self) -> None: + """Save current configuration to disk.""" + pass # Redundant since registry keys are written immediately + + def close(self) -> None: + """Close the configuration.""" + RegCloseKey(self.hkey) + self.hkey = None + + elif platform == 'linux': + SECTION = 'config' + + def __init__(self): + + # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html + self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname) + if not isdir(self.app_dir): + makedirs(self.app_dir) + + self.plugin_dir = join(self.app_dir, 'plugins') + if not isdir(self.plugin_dir): + mkdir(self.plugin_dir) + + self.internal_plugin_dir = join(dirname(__file__), 'plugins') + self.default_journal_dir = None + self.home = expanduser('~') + self.respath = dirname(__file__) + self.identifier = f'uk.org.marginal.{appname.lower()}' + + self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, f'{appname}.ini') + if not isdir(dirname(self.filename)): + makedirs(dirname(self.filename)) + + self.config = RawConfigParser(comment_prefixes=('#',)) + try: + with codecs.open(self.filename, 'r') as h: + self.config.read_file(h) + + except Exception as e: + logger.debug('Reading config failed, assuming we\'re making a new one...', exc_info=e) + self.config.add_section(self.SECTION) + + if not self.get('outdir') or not isdir(self.get('outdir')): + self.set('outdir', expanduser('~')) + + def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: + """Look up a string configuration value.""" + try: + val = self.config.get(self.SECTION, key) + if '\n' in val: # list + # ConfigParser drops the last entry if blank, + # so we add a spurious ';' entry in set() and remove it here + assert val.split('\n')[-1] == ';', val.split('\n') + return [self._unescape(x) for x in val.split('\n')[:-1]] + else: + return self._unescape(val) + + except NoOptionError: + logger.debug(f'attempted to get key {key} that does not exist') + return default + + except Exception as e: + logger.debug('And the exception type is...', exc_info=e) + return default + + def getint(self, key: str, default: int = 0) -> int: + """Look up an integer configuration value.""" + try: + return self.config.getint(self.SECTION, key) + + except ValueError as e: + logger.error(f"Failed to int({key=})", exc_info=e) + + except NoOptionError: + logger.debug(f'attempted to get key {key} that does not exist') + + except Exception: + logger.exception(f'unexpected exception while attempting to access {key}') + + return default + + def set(self, key: str, val: Union[int, str, list]) -> None: + """Set value on the specified configuration key.""" + if isinstance(val, bool): + self.config.set(self.SECTION, key, val and '1' or '0') + + elif isinstance(val, str) or isinstance(val, numbers.Integral): + self.config.set(self.SECTION, key, self._escape(val)) + + elif isinstance(val, list): + self.config.set(self.SECTION, key, '\n'.join([self._escape(x) for x in val] + [';'])) + + else: + raise NotImplementedError() + + def delete(self, key: str) -> None: + """Delete the specified configuration key.""" + self.config.remove_option(self.SECTION, key) + + def save(self) -> None: + """Save current configuration to disk.""" + with codecs.open(self.filename, 'w', 'utf-8') as h: + self.config.write(h) + + def close(self) -> None: + """Close the configuration.""" + self.save() + self.config = None + + def _escape(self, val: str) -> str: + """Escape a string for storage.""" + return str(val).replace('\\', '\\\\').replace('\n', '\\n').replace(';', '\\;') + + def _unescape(self, val: str) -> str: + """Un-escape a string from storage.""" + chars = list(val) + i = 0 + while i < len(chars): + if chars[i] == '\\': + chars.pop(i) + if chars[i] == 'n': + chars[i] = '\n' + i += 1 + return ''.join(chars) + + else: + def __init__(self): + raise NotImplementedError('Implement me') + + # Common + + def get_password(self, account: str) -> None: + """Legacy password retrieval.""" + warnings.warn("password subsystem is no longer supported", DeprecationWarning) + + def set_password(self, account: str, password: str) -> None: + """Legacy password setting.""" + warnings.warn("password subsystem is no longer supported", DeprecationWarning) + + def delete_password(self, account: str) -> None: + """Legacy password deletion.""" + warnings.warn("password subsystem is no longer supported", DeprecationWarning) + + +old_config = OldConfig() diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 00000000..c61c70d0 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,187 @@ +"""Test the config system.""" +from __future__ import annotations + +import contextlib +import itertools +import pathlib +import random +import string +import sys +from typing import Any, List, cast + +import pytest +from pytest import mark + +# isort: split + +sys.path += [str(pathlib.Path(__file__).parent.parent.resolve()), "."] +print(sys.path) + +from _old_config import old_config # noqa: E402 + +from config import LinuxConfig, config # noqa: E402 + + +def _fuzz_list(length: int) -> List[str]: + out = [] + for _ in range(length): + out.append(_fuzz_generators[str](random.randint(0, 1337))) + + return cast(List[str], out) + + +_fuzz_generators = { # Type annotating this would be a nightmare. + int: lambda i: random.randint(min(0, i), max(0, i)), + # This doesn't cover unicode, or random bytes. Use them at your own peril + str: lambda l: "".join(random.choice(string.ascii_letters + string.digits + '\r\n') for _ in range(l)), + bool: lambda _: bool(random.choice((True, False))), + list: _fuzz_list, +} + + +def _get_fuzz(_type: Any, num_values=50, value_length=(0, 10)) -> list: + return [_fuzz_generators[_type](random.randint(*value_length)) for _ in range(num_values)] + + +int_tests = [0, 1, 2, 3, (1 << 32)-1, -1337] + +string_tests = [ + "test", "", "this\nis\na\ntest", "orange sidewinder", "needs \\ more backslashes\\", "\\; \\n", r"\\\\ \\\\; \\\\n", + r"entry with escapes \\ \\; \\n" +] + +list_tests = [ + ["test"], + ["multiple", "entries"], + ["multiple", "entries", "with", "", "blanks"], + ["entry", "that ends", "in a", ""], + ["entry with \n", "newlines\nin", "weird\nplaces"], + [r"entry with escapes \\ \\; \\n"], + [r"\\\\ \\\\; \\\\n"] +] +bool_tests = [True, False] + +big_int = 1 << 64 + + +def _make_params(args: List[Any], id_name: str = 'random_test_{i}'): + return [pytest.param(x, id=id_name.format(i=i)) for i, x in enumerate(args)] + + +def _build_test_list(static_data, random_data, random_id_name='random_test_{i}'): + return itertools.chain(static_data, _make_params(random_data, id_name=random_id_name)) + + +class TestNewConfig: + """Test the new config with an array of hand picked and random data.""" + + @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, value_length=(-big_int, big_int)))) + def test_ints(self, i): + """Save int and then unpack it again.""" + name = f"int_test_{i}" + config.set(name, i) + assert i == config.get_int(name) + config.delete(name) + + @mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512)))) + def test_string(self, string: str): + """Save a string and then ask for it back.""" + name = f'str_test_{hash(string)}' + config.set(name, string) + assert string == config.get_str(name) + config.delete(name) + + @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) + def test_list(self, lst: List[str]): + """Save a list and then ask for it back.""" + name = f'list_test_{ hash("".join(lst)) }' + config.set(name, lst) + assert lst == config.get_list(name) + + config.delete(name) + + @mark.parametrize('b', bool_tests) + def test_bool(self, b): + """Save a bool and ask for it back.""" + name = str(b) + config.set(name, b) + assert b == config.get_bool(name) + config.delete(name) + + +class TestOldNewConfig: + """Tests going through the old config and out the new config.""" + + KEY_PREFIX = 'oldnew_' + + def teardown_method(self): + """ + Teardown for all config tests to save out configs. + + It is expected that tests have cleaned up whatever keys they have aded. + This is here to ensure that a save out happens for configs that need it. + """ + old_config.save() + config.save() + + def __update_linuxconfig(self): + """On linux config uses ConfigParser, which doesn't update from disk changes. Force the update here.""" + if isinstance(config, LinuxConfig) and config.config is not None: + config.config.read(config.filename) + + @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, 50, (-(1 << 32), 1 << 32)))) + def test_int(self, i: int) -> None: + """Save an int though the old config, recall it using the new config.""" + name = self.KEY_PREFIX + f'int_{i}' + old_config.set(name, i) + old_config.save() + + self.__update_linuxconfig() + + res = config.get_int(name) + with contextlib.ExitStack() as stack: + stack.callback(config.delete, name) + stack.callback(old_config.delete, name) + assert res == i + + @mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512)))) + def test_string(self, string: str) -> None: + string = string.replace("\r", "") # The old config does _not_ support \r in its entries. We do. + name = self.KEY_PREFIX + f'string_{hash(string)}' + old_config.set(name, string) + old_config.save() + + self.__update_linuxconfig() + + res = config.get_str(name) + with contextlib.ExitStack() as stack: + stack.callback(config.delete, name) + stack.callback(old_config.delete, name) + assert res == string + + @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) + def test_list(self, lst): + lst = [x.replace("\r", "") for x in lst] + name = self.KEY_PREFIX + f'list_test_{ hash("".join(lst)) }' + old_config.set(name, lst) + old_config.save() + + self.__update_linuxconfig() + + res = config.get_list(name) + with contextlib.ExitStack() as stack: + stack.callback(config.delete, name) + stack.callback(old_config.delete, name) + assert res == lst + + @mark.skipif(sys.platform == 'win32', reason="Old Windows config does not support bool types") + @mark.parametrize("b", bool_tests) + def test_bool(self, b): + name = str(b) + old_config.set(name, b) + old_config.save() + self.__update_linuxconfig() + with contextlib.ExitStack() as stack: + stack.callback(config.delete, name) + stack.callback(old_config.delete, name) + assert config.get_bool(name) == b From dcd142af152298919d545b34a143c45597071f37 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:17:56 +0200 Subject: [PATCH 155/727] Added configuration for tests --- pyproject.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 5b2d299b..1739e2f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,9 @@ max_line_length = 120 [tool.isort] multi_line_output = 5 line_length = 119 + +[tool.pytest.ini_options] +testpaths = ["tests"] # Search for tests in tests/ + +[tool.coverage.run] +omit = ["venv/*"] # when running pytest --cov, dont report coverage in venv directories \ No newline at end of file From 0ca9e81ecaa2f02391707a52bdc43aa0d664b410 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:28:44 +0200 Subject: [PATCH 156/727] Final fixups for WinConfig Added delete method Fixed missing sub_key arg to CreateKeyEx --- config.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index d6ab45b3..615aff9f 100644 --- a/config.py +++ b/config.py @@ -297,7 +297,7 @@ class WinConfig(AbstractConfig): try: self.__reg_handle: winreg.HKEYType = create_key_defaults( - subkey=r'Software\Marginal\EDMarketConnector' + sub_key=r'Software\Marginal\EDMarketConnector' ) if do_winsparkle: self.__setup_winsparkle() @@ -318,9 +318,9 @@ class WinConfig(AbstractConfig): access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY, ) try: - edcd_handle: winreg.HKEYType = create_key_defaults(subkey=r'Software\EDCD\EDMarketConnector') + edcd_handle: winreg.HKEYType = create_key_defaults(sub_key=r'Software\EDCD\EDMarketConnector') winsparkle_reg: winreg.HKEYType = winreg.CreateKeyEx( - edcd_handle, 'WinSparkle', access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY + edcd_handle, sub_key='WinSparkle', access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY ) except OSError: @@ -464,6 +464,9 @@ class WinConfig(AbstractConfig): # Its complaining about the list, it works, tested on windows, ignored. winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore + def delete(self, key: str) -> None: + winreg.DeleteValue(self.__reg_handle, key) + def save(self) -> None: """Save the configuration.""" # Not required as reg keys are flushed on write From 2de89674241b020e2574e890fa5a654c30a130b1 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:38:33 +0200 Subject: [PATCH 157/727] Delete keys only once unless on linux --- tests/test_config.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index c61c70d0..105d22d5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -124,6 +124,11 @@ class TestOldNewConfig: old_config.save() config.save() + def cleanup_entry(self, entry: str): + config.delete(entry) + if sys.platform == 'linux': + old_config.delete(entry) + def __update_linuxconfig(self): """On linux config uses ConfigParser, which doesn't update from disk changes. Force the update here.""" if isinstance(config, LinuxConfig) and config.config is not None: @@ -140,8 +145,7 @@ class TestOldNewConfig: res = config.get_int(name) with contextlib.ExitStack() as stack: - stack.callback(config.delete, name) - stack.callback(old_config.delete, name) + stack.callback(self.cleanup_entry, name) assert res == i @mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512)))) @@ -155,8 +159,7 @@ class TestOldNewConfig: res = config.get_str(name) with contextlib.ExitStack() as stack: - stack.callback(config.delete, name) - stack.callback(old_config.delete, name) + stack.callback(self.cleanup_entry, name) assert res == string @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) @@ -170,8 +173,7 @@ class TestOldNewConfig: res = config.get_list(name) with contextlib.ExitStack() as stack: - stack.callback(config.delete, name) - stack.callback(old_config.delete, name) + stack.callback(self.cleanup_entry, name) assert res == lst @mark.skipif(sys.platform == 'win32', reason="Old Windows config does not support bool types") @@ -182,6 +184,5 @@ class TestOldNewConfig: old_config.save() self.__update_linuxconfig() with contextlib.ExitStack() as stack: - stack.callback(config.delete, name) - stack.callback(old_config.delete, name) + stack.callback(self.cleanup_entry, name) assert config.get_bool(name) == b From a85a3d356a914e8826adc45818e7982ec74dd11d Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:50:07 +0200 Subject: [PATCH 158/727] Added warning on windows for large ints --- config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.py b/config.py index 615aff9f..02c2b706 100644 --- a/config.py +++ b/config.py @@ -449,6 +449,8 @@ class WinConfig(AbstractConfig): winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, winreg.REG_SZ, val) elif isinstance(val, int): # The original code checked for numbers.Integral, I dont think that is needed. + if val > 0xFFFFFFFF or val < 0: + warnings.warn(f'Value of {val} is either too large or negative. This will cause issues.') reg_type = winreg.REG_DWORD elif isinstance(val, list): From f8bc7290fe7c49e6cd259755305016f76a88ac2f Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:50:25 +0200 Subject: [PATCH 159/727] Made sure we dont test with big ints on windows --- tests/test_config.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index 105d22d5..28c0bb3a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -61,7 +61,7 @@ list_tests = [ ] bool_tests = [True, False] -big_int = 1 << 64 +big_int = int(0xFFFFFFFF) # 32 bit int def _make_params(args: List[Any], id_name: str = 'random_test_{i}'): @@ -78,6 +78,9 @@ class TestNewConfig: @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, value_length=(-big_int, big_int)))) def test_ints(self, i): """Save int and then unpack it again.""" + if sys.platform == 'win32': + i = abs(i) + name = f"int_test_{i}" config.set(name, i) assert i == config.get_int(name) @@ -134,9 +137,12 @@ class TestOldNewConfig: if isinstance(config, LinuxConfig) and config.config is not None: config.config.read(config.filename) - @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, 50, (-(1 << 32), 1 << 32)))) + @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, 50, (-big_int, big_int)))) def test_int(self, i: int) -> None: """Save an int though the old config, recall it using the new config.""" + if sys.platform == 'win32': + i = abs(i) + name = self.KEY_PREFIX + f'int_{i}' old_config.set(name, i) old_config.save() From 9fd1da1819a05bff079dcdecc1722133cedd00ed Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 08:57:49 +0200 Subject: [PATCH 160/727] Added space workaround to test_list --- tests/test_config.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 28c0bb3a..3ce889b2 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -170,7 +170,12 @@ class TestOldNewConfig: @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) def test_list(self, lst): - lst = [x.replace("\r", "") for x in lst] + lst = [x.replace("\r", "") for x in lst] # OldConfig on linux fails to store these correctly + if sys.platform == 'win32': + # old conf on windows replaces empty entries with spaces as a workaround for a bug. New conf does not + # So insert those spaces here, to ensure that it works otherwise. + lst = [e if len(e) > 0 else ' ' for e in lst] + name = self.KEY_PREFIX + f'list_test_{ hash("".join(lst)) }' old_config.set(name, lst) old_config.save() From 640bda0d0e03084491366d8e255b20dc5526a355 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 09:11:12 +0200 Subject: [PATCH 161/727] Disabled mypy in old_config --- tests/_old_config.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/_old_config.py b/tests/_old_config.py index 197ca9f8..b1609975 100644 --- a/tests/_old_config.py +++ b/tests/_old_config.py @@ -2,7 +2,7 @@ import numbers import sys import warnings from configparser import NoOptionError -from os import getenv, mkdir, pardir, makedirs +from os import getenv, makedirs, mkdir, pardir from os.path import dirname, expanduser, isdir, join, normpath from sys import platform from typing import TYPE_CHECKING, Optional, Union @@ -202,7 +202,7 @@ class OldConfig(): elif platform == 'win32': def __init__(self): - self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) + self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) # type: ignore # Not going to change if not isdir(self.app_dir): mkdir(self.app_dir) @@ -279,7 +279,7 @@ class OldConfig(): RegSetValueEx(sparklekey, 'UpdateInterval', 0, 1, buf, len(buf) * 2) RegCloseKey(sparklekey) - if not self.get('outdir') or not isdir(self.get('outdir')): + if not self.get('outdir') or not isdir(self.get('outdir')): # type: ignore # Not going to change self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: @@ -395,7 +395,7 @@ class OldConfig(): logger.debug('Reading config failed, assuming we\'re making a new one...', exc_info=e) self.config.add_section(self.SECTION) - if not self.get('outdir') or not isdir(self.get('outdir')): + if not self.get('outdir') or not isdir(self.get('outdir')): # type: ignore # Not going to change self.set('outdir', expanduser('~')) def get(self, key: str, default: Union[None, list, str] = None) -> Union[None, list, str]: @@ -437,10 +437,10 @@ class OldConfig(): def set(self, key: str, val: Union[int, str, list]) -> None: """Set value on the specified configuration key.""" if isinstance(val, bool): - self.config.set(self.SECTION, key, val and '1' or '0') + self.config.set(self.SECTION, key, val and '1' or '0') # type: ignore # Not going to change elif isinstance(val, str) or isinstance(val, numbers.Integral): - self.config.set(self.SECTION, key, self._escape(val)) + self.config.set(self.SECTION, key, self._escape(val)) # type: ignore # Not going to change elif isinstance(val, list): self.config.set(self.SECTION, key, '\n'.join([self._escape(x) for x in val] + [';'])) From e84373822c0b829d16dcaa0ee121677724fa9cbd Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 09:18:00 +0200 Subject: [PATCH 162/727] Finished docstrings --- config.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index 02c2b706..4e575b49 100644 --- a/config.py +++ b/config.py @@ -58,7 +58,7 @@ elif platform == 'win32': REG_RESERVED_ALWAYS_ZERO = 0 - # This is the only way to do this from python without external deps (which do this anyway). + # This is the only way to do this from python without external dependencies (which do this anyway). FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') FOLDERID_Profile = uuid.UUID('{5E6C858F-0E22-4760-9AFE-EA3317B67173}') @@ -467,6 +467,12 @@ class WinConfig(AbstractConfig): winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore def delete(self, key: str) -> None: + """ + Delete the given key from the config. + + :param key: The key to delete + :raises OSError: if a registry error occurs. + """ winreg.DeleteValue(self.__reg_handle, key) def save(self) -> None: @@ -588,6 +594,14 @@ class MacConfig(AbstractConfig): return default def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + """ + Get the bool referred to by the given key if it exists, or the default. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to None + :raises ValueError: If an internal error occurs getting or converting a value + :return: The requested data or the default + """ res = self.__raw_get(key) if res is None: return default @@ -714,6 +728,14 @@ class LinuxConfig(AbstractConfig): return self.config[self.SECTION].get(key) def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + """ + Get the string referred to by the given key if it exists, or the default. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to None + :raises ValueError: If an internal error occurs getting or converting a value + :return: The requested data or the default + """ data = self.__raw_get(key) if data is None: return default @@ -724,6 +746,14 @@ class LinuxConfig(AbstractConfig): return self.__unescape(data) def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + """ + Get the list referred to by the given key if it exists, or the default. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to None + :raises ValueError: If an internal error occurs getting or converting a value + :return: The requested data or the default + """ data = self.__raw_get(key) if data is None: @@ -736,6 +766,16 @@ class LinuxConfig(AbstractConfig): return list(map(self.__unescape, split[:-1])) def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: + """ + Get the int referred to by key if it exists in the config. + + For legacy reasons, the default is 0 and not None. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to 0 + :raises ValueError: if the internal representation of this key cannot be converted to an int + :return: The requested data or the default + """ data = self.__raw_get(key) if data is None: @@ -748,6 +788,14 @@ class LinuxConfig(AbstractConfig): raise ValueError(f'requested {key=} as int cannot be converted to int') from e def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + """ + Get the bool referred to by the given key if it exists, or the default. + + :param key: The key to search for + :param default: Default to return if the key does not exist, defaults to None + :raises ValueError: If an internal error occurs getting or converting a value + :return: The requested data or the default + """ if self.config is None: raise ValueError('attempt to use a closed config') @@ -758,6 +806,7 @@ class LinuxConfig(AbstractConfig): return bool(int(data)) def set(self, key: str, val: Union[int, str, List[str]]) -> None: + """Set the given key to the given data.""" if self.config is None: raise ValueError('attempt to use a closed config') @@ -780,12 +829,18 @@ class LinuxConfig(AbstractConfig): self.config.set(self.SECTION, key, to_set) def delete(self, key: str) -> None: + """ + Delete the given key from the config. + + :param key: The key to delete + """ if self.config is None: raise ValueError('attempt to use a closed config') self.config.remove_option(self.SECTION, key) def save(self) -> None: + """Save the current configuration.""" if self.config is None: raise ValueError('attempt to use a closed config') @@ -793,11 +848,12 @@ class LinuxConfig(AbstractConfig): self.config.write(f) def close(self) -> None: + """Close this config and release any associated resources.""" self.save() self.config = None -def get_config(*args, **kwargs) -> AbstractConfig: +def _get_config(*args, **kwargs) -> AbstractConfig: if sys.platform == "darwin": return MacConfig(*args, **kwargs) elif sys.platform == "win32": @@ -808,4 +864,4 @@ def get_config(*args, **kwargs) -> AbstractConfig: raise ValueError(f'Unknown platform: {sys.platform=}') -config = get_config() +config = _get_config() From 18f4e494067dee1633e3b2d55e031c522a001052 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 09:20:15 +0200 Subject: [PATCH 163/727] Final type annotations --- tests/test_config.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index 3ce889b2..b2af9a3c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -7,7 +7,7 @@ import pathlib import random import string import sys -from typing import Any, List, cast +from typing import Any, Iterable, List, cast import pytest from pytest import mark @@ -64,11 +64,11 @@ bool_tests = [True, False] big_int = int(0xFFFFFFFF) # 32 bit int -def _make_params(args: List[Any], id_name: str = 'random_test_{i}'): +def _make_params(args: List[Any], id_name: str = 'random_test_{i}') -> list: return [pytest.param(x, id=id_name.format(i=i)) for i, x in enumerate(args)] -def _build_test_list(static_data, random_data, random_id_name='random_test_{i}'): +def _build_test_list(static_data, random_data, random_id_name='random_test_{i}') -> Iterable: return itertools.chain(static_data, _make_params(random_data, id_name=random_id_name)) @@ -76,7 +76,7 @@ class TestNewConfig: """Test the new config with an array of hand picked and random data.""" @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, value_length=(-big_int, big_int)))) - def test_ints(self, i): + def test_ints(self, i: int) -> None: """Save int and then unpack it again.""" if sys.platform == 'win32': i = abs(i) @@ -87,7 +87,7 @@ class TestNewConfig: config.delete(name) @mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512)))) - def test_string(self, string: str): + def test_string(self, string: str) -> None: """Save a string and then ask for it back.""" name = f'str_test_{hash(string)}' config.set(name, string) @@ -95,7 +95,7 @@ class TestNewConfig: config.delete(name) @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) - def test_list(self, lst: List[str]): + def test_list(self, lst: List[str]) -> None: """Save a list and then ask for it back.""" name = f'list_test_{ hash("".join(lst)) }' config.set(name, lst) @@ -104,7 +104,7 @@ class TestNewConfig: config.delete(name) @mark.parametrize('b', bool_tests) - def test_bool(self, b): + def test_bool(self, b: bool) -> None: """Save a bool and ask for it back.""" name = str(b) config.set(name, b) @@ -117,7 +117,7 @@ class TestOldNewConfig: KEY_PREFIX = 'oldnew_' - def teardown_method(self): + def teardown_method(self) -> None: """ Teardown for all config tests to save out configs. @@ -127,12 +127,13 @@ class TestOldNewConfig: old_config.save() config.save() - def cleanup_entry(self, entry: str): + def cleanup_entry(self, entry: str) -> None: + """Remove the given key, on both sides if on linux.""" config.delete(entry) if sys.platform == 'linux': old_config.delete(entry) - def __update_linuxconfig(self): + def __update_linuxconfig(self) -> None: """On linux config uses ConfigParser, which doesn't update from disk changes. Force the update here.""" if isinstance(config, LinuxConfig) and config.config is not None: config.config.read(config.filename) @@ -156,6 +157,7 @@ class TestOldNewConfig: @mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512)))) def test_string(self, string: str) -> None: + """Save a string though the old config, recall it using the new config.""" string = string.replace("\r", "") # The old config does _not_ support \r in its entries. We do. name = self.KEY_PREFIX + f'string_{hash(string)}' old_config.set(name, string) @@ -169,7 +171,8 @@ class TestOldNewConfig: assert res == string @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) - def test_list(self, lst): + def test_list(self, lst: List[str]) -> None: + """Save a list though the old config, recall it using the new config.""" lst = [x.replace("\r", "") for x in lst] # OldConfig on linux fails to store these correctly if sys.platform == 'win32': # old conf on windows replaces empty entries with spaces as a workaround for a bug. New conf does not @@ -189,7 +192,8 @@ class TestOldNewConfig: @mark.skipif(sys.platform == 'win32', reason="Old Windows config does not support bool types") @mark.parametrize("b", bool_tests) - def test_bool(self, b): + def test_bool(self, b: bool) -> None: + """Save a bool though the old config, recall it using the new config.""" name = str(b) old_config.set(name, b) old_config.save() From 7135c3be9cefd38b59e722ebc3568be23c28b382 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 09:21:19 +0200 Subject: [PATCH 164/727] Missing newline --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1739e2f1..35ab26e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,4 +9,4 @@ line_length = 119 testpaths = ["tests"] # Search for tests in tests/ [tool.coverage.run] -omit = ["venv/*"] # when running pytest --cov, dont report coverage in venv directories \ No newline at end of file +omit = ["venv/*"] # when running pytest --cov, dont report coverage in venv directories From 8a81caeb8b4004552a5c6801e6e0929fea803475 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 23 Nov 2020 09:30:14 +0200 Subject: [PATCH 165/727] Ensured that we save and reload the config --- tests/test_config.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index b2af9a3c..8fa179c5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -75,6 +75,11 @@ def _build_test_list(static_data, random_data, random_id_name='random_test_{i}') class TestNewConfig: """Test the new config with an array of hand picked and random data.""" + def __update_linuxconfig(self) -> None: + """On linux config uses ConfigParser, which doesn't update from disk changes. Force the update here.""" + if isinstance(config, LinuxConfig) and config.config is not None: + config.config.read(config.filename) + @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, value_length=(-big_int, big_int)))) def test_ints(self, i: int) -> None: """Save int and then unpack it again.""" @@ -83,6 +88,8 @@ class TestNewConfig: name = f"int_test_{i}" config.set(name, i) + config.save() + self.__update_linuxconfig() assert i == config.get_int(name) config.delete(name) @@ -91,6 +98,8 @@ class TestNewConfig: """Save a string and then ask for it back.""" name = f'str_test_{hash(string)}' config.set(name, string) + config.save() + self.__update_linuxconfig() assert string == config.get_str(name) config.delete(name) @@ -99,6 +108,10 @@ class TestNewConfig: """Save a list and then ask for it back.""" name = f'list_test_{ hash("".join(lst)) }' config.set(name, lst) + + config.save() + self.__update_linuxconfig() + assert lst == config.get_list(name) config.delete(name) @@ -108,6 +121,8 @@ class TestNewConfig: """Save a bool and ask for it back.""" name = str(b) config.set(name, b) + config.save() + self.__update_linuxconfig() assert b == config.get_bool(name) config.delete(name) From a9c705c0cf7a4ac382a71c65d9c5ca3fdc0241c7 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 21 Dec 2020 14:07:18 +0200 Subject: [PATCH 166/727] Removed Optionals from method definitions It makes typing far easier --- config.py | 122 ++++++++++++++---------------------------------------- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/config.py b/config.py index 4e575b49..deef56c6 100644 --- a/config.py +++ b/config.py @@ -58,7 +58,7 @@ elif platform == 'win32': REG_RESERVED_ALWAYS_ZERO = 0 - # This is the only way to do this from python without external dependencies (which do this anyway). + # This is the only way to do this from python without external deps (which do this anyway). FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') FOLDERID_Profile = uuid.UUID('{5E6C858F-0E22-4760-9AFE-EA3317B67173}') @@ -133,7 +133,7 @@ class AbstractConfig(abc.ABC): return None - def get(self, key: str, default: Union[None, list, str, bool, int] = None) -> Union[None, list, str, bool, int]: + def get(self, key: str, default: Union[list, str, bool, int] = None) -> Union[list, str, bool, int]: """ Get the requested key, or a default. @@ -155,10 +155,10 @@ class AbstractConfig(abc.ABC): elif (i := self._suppress_call(self.get_int, ValueError, key, None)) is not None: return i - return default + return default # type: ignore @abstractmethod - def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + def get_list(self, key: str, default: list = None) -> list: """ Get the list referred to by the given key if it exists, or the default. @@ -171,7 +171,7 @@ class AbstractConfig(abc.ABC): raise NotImplementedError @abstractmethod - def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + def get_str(self, key: str, default: str = None) -> str: """ Get the string referred to by the given key if it exists, or the default. @@ -184,7 +184,7 @@ class AbstractConfig(abc.ABC): raise NotImplementedError @abstractmethod - def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + def get_bool(self, key: str, default: bool = None) -> bool: """ Get the bool referred to by the given key if it exists, or the default. @@ -196,7 +196,7 @@ class AbstractConfig(abc.ABC): """ raise NotImplementedError - def getint(self, key: str, default: Optional[int] = 0) -> Optional[int]: + def getint(self, key: str, default: int = 0) -> int: """ Getint is a Deprecated getter method. @@ -207,7 +207,7 @@ class AbstractConfig(abc.ABC): return self.get_int(key, default) @abstractmethod - def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: + def get_int(self, key: str, default: int = 0) -> int: """ Get the int referred to by key if it exists in the config. @@ -365,7 +365,7 @@ class WinConfig(AbstractConfig): logger.warning(f'registry key {key=} returned unknown type {_type=} {value=}') return None - def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + def get_str(self, key: str, default: str = None) -> str: """ Return the string represented by the key, or the default if it does not exist. @@ -376,14 +376,14 @@ class WinConfig(AbstractConfig): """ res = self.__get_regentry(key) if res is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default elif not isinstance(res, str): raise ValueError(f'Data from registry is not a string: {type(res)=} {res=}') return res - def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + def get_list(self, key: str, default: list = None) -> list: """ Return the list found at the given key, or the default if none exists. @@ -394,14 +394,14 @@ class WinConfig(AbstractConfig): """ res = self.__get_regentry(key) if res is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default elif not isinstance(res, list): raise ValueError(f'Data from registry is not a list: {type(res)=} {res}') return res - def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: + def get_int(self, key: str, default: int = 0) -> int: """ Return the int found at the given key, or the default if none exists. @@ -419,7 +419,7 @@ class WinConfig(AbstractConfig): return res - def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: + def get_bool(self, key: str, default: bool = None) -> bool: """ Return the bool found at the given key, or the default if none exists. @@ -430,7 +430,7 @@ class WinConfig(AbstractConfig): """ res = self.get_int(key) if res is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default return bool(res) @@ -449,8 +449,6 @@ class WinConfig(AbstractConfig): winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, winreg.REG_SZ, val) elif isinstance(val, int): # The original code checked for numbers.Integral, I dont think that is needed. - if val > 0xFFFFFFFF or val < 0: - warnings.warn(f'Value of {val} is either too large or negative. This will cause issues.') reg_type = winreg.REG_DWORD elif isinstance(val, list): @@ -467,12 +465,6 @@ class WinConfig(AbstractConfig): winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore def delete(self, key: str) -> None: - """ - Delete the given key from the config. - - :param key: The key to delete - :raises OSError: if a registry error occurs. - """ winreg.DeleteValue(self.__reg_handle, key) def save(self) -> None: @@ -534,7 +526,7 @@ class MacConfig(AbstractConfig): return res - def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: + def get_str(self, key: str, default: str = None) -> str: """ Return the string represented by the key, or the default if it does not exist. @@ -545,14 +537,14 @@ class MacConfig(AbstractConfig): """ res = self.__raw_get(key) if res is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default if not isinstance(res, str): raise ValueError(f'unexpected data returned from __raw_get: {type(res)=} {res}') return res - def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: + def get_list(self, key: str, default: list = None) -> list: """ Return the list found at the given key, or the default if none exists. @@ -563,14 +555,14 @@ class MacConfig(AbstractConfig): """ res = self.__raw_get(key) if res is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default elif not isinstance(res, list): raise ValueError(f'__raw_get returned unexpected type {type(res)=} {res!r}') return res - def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: + def get_int(self, key: str, default: int = 0) -> int: """ Return the int found at the given key, or the default if none exists. @@ -591,20 +583,12 @@ class MacConfig(AbstractConfig): except ValueError as e: logger.error(f'__raw_get returned {res!r} which cannot be parsed to an int: {e}') - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default - def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: - """ - Get the bool referred to by the given key if it exists, or the default. - - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to None - :raises ValueError: If an internal error occurs getting or converting a value - :return: The requested data or the default - """ + def get_bool(self, key: str, default: bool = None) -> bool: res = self.__raw_get(key) if res is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default elif not isinstance(res, bool): raise ValueError(f'__raw_get returned unexpected type {type(res)=} {res!r}') @@ -727,37 +711,21 @@ class LinuxConfig(AbstractConfig): return self.config[self.SECTION].get(key) - def get_str(self, key: str, default: Optional[str] = None) -> Optional[str]: - """ - Get the string referred to by the given key if it exists, or the default. - - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to None - :raises ValueError: If an internal error occurs getting or converting a value - :return: The requested data or the default - """ + def get_str(self, key: str, default: str = None) -> str: data = self.__raw_get(key) if data is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default if '\n' in data: raise ValueError('asked for string, got list') return self.__unescape(data) - def get_list(self, key: str, default: Optional[list] = None) -> Optional[list]: - """ - Get the list referred to by the given key if it exists, or the default. - - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to None - :raises ValueError: If an internal error occurs getting or converting a value - :return: The requested data or the default - """ + def get_list(self, key: str, default: list = None) -> list: data = self.__raw_get(key) if data is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default split = data.split('\n') if split[-1] != ';': @@ -765,17 +733,7 @@ class LinuxConfig(AbstractConfig): return list(map(self.__unescape, split[:-1])) - def get_int(self, key: str, default: Optional[int] = 0) -> Optional[int]: - """ - Get the int referred to by key if it exists in the config. - - For legacy reasons, the default is 0 and not None. - - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to 0 - :raises ValueError: if the internal representation of this key cannot be converted to an int - :return: The requested data or the default - """ + def get_int(self, key: str, default: int = 0) -> int: data = self.__raw_get(key) if data is None: @@ -787,26 +745,17 @@ class LinuxConfig(AbstractConfig): except ValueError as e: raise ValueError(f'requested {key=} as int cannot be converted to int') from e - def get_bool(self, key: str, default: Optional[bool] = None) -> Optional[bool]: - """ - Get the bool referred to by the given key if it exists, or the default. - - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to None - :raises ValueError: If an internal error occurs getting or converting a value - :return: The requested data or the default - """ + def get_bool(self, key: str, default: bool = None) -> bool: if self.config is None: raise ValueError('attempt to use a closed config') data = self.__raw_get(key) if data is None: - return default + return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default return bool(int(data)) def set(self, key: str, val: Union[int, str, List[str]]) -> None: - """Set the given key to the given data.""" if self.config is None: raise ValueError('attempt to use a closed config') @@ -829,18 +778,12 @@ class LinuxConfig(AbstractConfig): self.config.set(self.SECTION, key, to_set) def delete(self, key: str) -> None: - """ - Delete the given key from the config. - - :param key: The key to delete - """ if self.config is None: raise ValueError('attempt to use a closed config') self.config.remove_option(self.SECTION, key) def save(self) -> None: - """Save the current configuration.""" if self.config is None: raise ValueError('attempt to use a closed config') @@ -848,12 +791,11 @@ class LinuxConfig(AbstractConfig): self.config.write(f) def close(self) -> None: - """Close this config and release any associated resources.""" self.save() self.config = None -def _get_config(*args, **kwargs) -> AbstractConfig: +def get_config(*args, **kwargs) -> AbstractConfig: if sys.platform == "darwin": return MacConfig(*args, **kwargs) elif sys.platform == "win32": @@ -864,4 +806,4 @@ def _get_config(*args, **kwargs) -> AbstractConfig: raise ValueError(f'Unknown platform: {sys.platform=}') -config = _get_config() +config = get_config() From 25852997c56ee9dc9dea883a37cb30803872f8e2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 11:57:17 +0100 Subject: [PATCH 167/727] Updated all source to use new config methods # Conflicts: # monitor.py --- EDMC.py | 6 ++-- EDMCLogging.py | 2 +- commodity.py | 4 +-- companion.py | 13 ++++---- dashboard.py | 2 +- docs/examples/click_counter/load.py | 2 +- edshipyard.py | 8 ++--- hotkey.py | 4 +-- loadout.py | 8 ++--- monitor.py | 28 ++++------------ outfitting.py | 2 +- plugins/coriolis.py | 2 +- plugins/eddb.py | 8 ++--- plugins/eddn.py | 20 +++++------ plugins/edsm.py | 39 +++++++++++----------- plugins/inara.py | 26 +++++++-------- prefs.py | 52 ++++++++++++++--------------- shipyard.py | 2 +- td.py | 4 +-- theme.py | 14 ++++---- 20 files changed, 116 insertions(+), 130 deletions(-) diff --git a/EDMC.py b/EDMC.py index 04701313..55a1a3fd 100755 --- a/EDMC.py +++ b/EDMC.py @@ -189,7 +189,7 @@ sys.path: {sys.path}''' # Get state from latest Journal file logger.debug('Getting state from latest journal file') try: - logdir = config.get('journaldir') or config.default_journal_dir + logdir = config.get_str('journaldir', str(config.default_journal_dir)) logger.debug(f'logdir = "{logdir}"') logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)), key=lambda x: x.split('.')[1:]) @@ -215,7 +215,7 @@ sys.path: {sys.path}''' # Get data from Companion API if args.p: logger.debug(f'Attempting to use commander "{args.p}"') - cmdrs = config.get('cmdrs') or [] + cmdrs = config.get_list('cmdrs', []) if args.p in cmdrs: idx = cmdrs.index(args.p) @@ -231,7 +231,7 @@ sys.path: {sys.path}''' else: logger.debug(f'Attempting to use commander "{monitor.cmdr}" from Journal File') - cmdrs = config.get('cmdrs') or [] + cmdrs = config.get_list('cmdrs', []) if monitor.cmdr not in cmdrs: raise companion.CredentialsError() diff --git a/EDMCLogging.py b/EDMCLogging.py index 8445a9fe..068d7225 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -473,7 +473,7 @@ def get_main_logger() -> 'LoggerMixin': # Singleton -loglevel = config.get('loglevel') +loglevel = config.get_str('loglevel') if not loglevel: loglevel = logging.INFO diff --git a/commodity.py b/commodity.py index fec7d2b7..1ee86055 100644 --- a/commodity.py +++ b/commodity.py @@ -20,7 +20,7 @@ bracketmap = { def export(data, kind=COMMODITY_DEFAULT, filename=None): - querytime = config.getint('querytime') or int(time.time()) + querytime = config.get_int('querytime') or int(time.time()) if not filename: filename = '{system}.{starport}.{time}.{kind}'.format( @@ -29,7 +29,7 @@ def export(data, kind=COMMODITY_DEFAULT, filename=None): time=time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)), kind='csv' ) - filename = join(config.get('outdir'), filename) + filename = join(config.get_str('outdir'), filename) if kind == COMMODITY_CSV: sep = ';' # BUG: for fixing later after cleanup diff --git a/companion.py b/companion.py index 7d6bbe36..36639f3f 100644 --- a/companion.py +++ b/companion.py @@ -40,7 +40,6 @@ else: UserDict = collections.UserDict # type: ignore # Otherwise simply use the actual class - # Define custom type for the dicts that hold CAPI data # CAPIData = NewType('CAPIData', Dict) @@ -286,13 +285,13 @@ class Auth(object): logger.debug(f'Trying for "{self.cmdr}"') self.verifier = None - cmdrs = cast(List[str], config.get('cmdrs')) + cmdrs = cast(List[str], config.get_list('cmdrs', [])) logger.debug(f'Cmdrs: {cmdrs}') idx = cmdrs.index(self.cmdr) logger.debug(f'idx = {idx}') - tokens = config.get('fdev_apikeys') or [] + tokens = cast('List[str]', config.get_list('fdev_apikeys', [])) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) if tokens[idx]: logger.debug('We have a refresh token for that idx') @@ -376,9 +375,9 @@ class Auth(object): data = r.json() if r.status_code == requests.codes.ok: logger.info(f'Frontier CAPI Auth: New token for \"{self.cmdr}\"') - cmdrs = cast(List[str], config.get('cmdrs')) + cmdrs = cast(List[str], config.get_list('cmdrs', [])) idx = cmdrs.index(self.cmdr) - tokens = config.get('fdev_apikeys') or [] + tokens = cast(List[str], config.get_list('fdev_apikeys', [])) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) tokens[idx] = data.get('refresh_token', '') config.set('fdev_apikeys', tokens) @@ -405,9 +404,9 @@ class Auth(object): def invalidate(cmdr: str) -> None: """Invalidate Refresh Token for specified Commander.""" logger.info(f'Frontier CAPI Auth: Invalidated token for "{cmdr}"') - cmdrs = cast(List[str], config.get('cmdrs')) + cmdrs = cast(List[str], config.get_list('cmdrs', [])) idx = cmdrs.index(cmdr) - tokens = cast(List[str], config.get('fdev_apikeys') or []) + tokens = cast(List[str], config.get_list('fdev_apikeys', [])) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) tokens[idx] = '' config.set('fdev_apikeys', tokens) diff --git a/dashboard.py b/dashboard.py index 7fef3a9f..530e4b3b 100644 --- a/dashboard.py +++ b/dashboard.py @@ -41,7 +41,7 @@ class Dashboard(FileSystemEventHandler): self.root = root self.session_start = started - logdir = config.get('journaldir') or config.default_journal_dir + logdir = config.get_str('journaldir', str(config.default_journal_dir)) if not logdir or not isdir(logdir): logger.info(f"No logdir, or it isn't a directory: {logdir=}") self.stop() diff --git a/docs/examples/click_counter/load.py b/docs/examples/click_counter/load.py index 02403f2f..ff9b449d 100644 --- a/docs/examples/click_counter/load.py +++ b/docs/examples/click_counter/load.py @@ -26,7 +26,7 @@ class ClickCounter: def __init__(self) -> None: # Be sure to use names that wont collide in our config variables - self.click_count: Optional[tk.StringVar] = tk.StringVar(value=str(config.getint('click_counter_count'))) + self.click_count: Optional[tk.StringVar] = tk.StringVar(value=str(config.get_int('click_counter_count'))) logger.info("ClickCounter instantiated") def on_load(self) -> str: diff --git a/edshipyard.py b/edshipyard.py index f3ce48a4..dd80ffda 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -74,7 +74,7 @@ def export(data, filename=None): return ret + ' ' - querytime = config.getint('querytime') or int(time.time()) + querytime = config.get_int('querytime') or int(time.time()) loadout = defaultdict(list) mass = 0.0 @@ -199,14 +199,14 @@ def export(data, filename=None): # Look for last ship of this type ship = companion.ship_file_name(data['ship'].get('shipName'), data['ship']['name']) regexp = re.compile(re.escape(ship) + r'\.\d{4}-\d\d-\d\dT\d\d\.\d\d\.\d\d\.txt') - oldfiles = sorted([x for x in os.listdir(config.get('outdir')) if regexp.match(x)]) + oldfiles = sorted([x for x in os.listdir(config.get_str('outdir')) if regexp.match(x)]) if oldfiles: - with open(join(config.get('outdir'), oldfiles[-1]), 'rU') as h: + with open(join(config.get_str('outdir'), oldfiles[-1]), 'rU') as h: if h.read() == string: return # same as last time - don't write # Write - filename = join(config.get('outdir'), '{}.{}.txt'.format( + filename = join(config.get_str('outdir'), '{}.{}.txt'.format( ship, time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime))) ) diff --git a/hotkey.py b/hotkey.py index 966975a4..5165e0b9 100644 --- a/hotkey.py +++ b/hotkey.py @@ -113,7 +113,7 @@ if platform == 'darwin': def _handler(self, event): # use event.charactersIgnoringModifiers to handle composing characters like Alt-e if (event.modifierFlags() & HotkeyMgr.MODIFIERMASK) == self.modifiers and ord(event.charactersIgnoringModifiers()[0]) == self.keycode: - if config.getint('hotkey_always'): + if config.get_int('hotkey_always'): self.activated = True else: # Only trigger if game client is front process front = NSWorkspace.sharedWorkspace().frontmostApplication() @@ -347,7 +347,7 @@ elif platform == 'win32': logger.debug('WM_HOTKEY') if ( - config.getint('hotkey_always') + config.get_int('hotkey_always') or WindowTitle(GetForegroundWindow()).startswith('Elite - Dangerous') ): logger.debug('Sending event <>') diff --git a/loadout.py b/loadout.py index 6814c18f..85c4f0f8 100644 --- a/loadout.py +++ b/loadout.py @@ -22,15 +22,15 @@ def export(data, filename=None): # Look for last ship of this type ship = companion.ship_file_name(data['ship'].get('shipName'), data['ship']['name']) regexp = re.compile(re.escape(ship) + '\.\d\d\d\d\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt') - oldfiles = sorted([x for x in os.listdir(config.get('outdir')) if regexp.match(x)]) + oldfiles = sorted([x for x in os.listdir(config.get_str('outdir')) if regexp.match(x)]) if oldfiles: - with open(join(config.get('outdir'), oldfiles[-1]), 'rU') as h: + with open(join(config.get_str('outdir'), oldfiles[-1]), 'rU') as h: if h.read() == string: return # same as last time - don't write - querytime = config.getint('querytime') or int(time.time()) + querytime = config.get_int('querytime') or int(time.time()) # Write - filename = join(config.get('outdir'), '%s.%s.txt' % (ship, time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))) + filename = join(config.get_str('outdir'), '%s.%s.txt' % (ship, time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))) with open(filename, 'wt') as h: h.write(string) diff --git a/monitor.py b/monitor.py index 94486d6e..637bcb95 100644 --- a/monitor.py +++ b/monitor.py @@ -129,7 +129,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below """Start journal monitoring.""" logger.debug('Begin...') self.root = root - journal_dir = config.get('journaldir') or config.default_journal_dir + journal_dir = config.get_str('journaldir', str(config.default_journal_dir)) if journal_dir is None: logger.debug('journal_dir was None, setting ""') @@ -169,7 +169,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # File system events are unreliable/non-existent over network drives on Linux. # We can't easily tell whether a path points to a network drive, so assume # any non-standard logdir might be on a network drive and poll instead. - polling = bool(config.get('journaldir')) and platform != 'win32' + polling = bool(config.get_str('journaldir')) and platform != 'win32' if not polling and not self.observer: logger.debug('Not polling, no observer, starting an observer...') self.observer = Observer() @@ -1023,29 +1023,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below ship = ship_file_name(self.state['ShipName'], self.state['ShipType']) regexp = re.compile(re.escape(ship) + r'\.\d{4}\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt') - oldfiles = sorted((x for x in listdir(config.get('outdir')) if regexp.match(x))) # type: ignore + oldfiles = sorted((x for x in listdir(config.get_str('outdir')) if regexp.match(x))) # type: ignore if oldfiles: - try: - with open(join(config.get('outdir'), oldfiles[-1]), 'rU', encoding='utf-8') as h: # type: ignore - if h.read() == string: - return # same as last time - don't write - - except UnicodeError: - logger.exception("UnicodeError reading old ship loadout with utf-8 encoding, trying without...") - try: - with open(join(config.get('outdir'), oldfiles[-1]), 'rU') as h: # type: ignore - if h.read() == string: - return # same as last time - don't write - - except OSError: - logger.exception("OSError reading old ship loadout default encoding.") - - except OSError: - logger.exception("OSError reading old ship loadout with default encoding") + with open(join(config.get_str('outdir'), oldfiles[-1]), 'rU') as h: # type: ignore + if h.read() == string: + return # same as last time - don't write # Write filename = join( # type: ignore - config.get('outdir'), '{}.{}.txt'.format(ship, strftime('%Y-%m-%dT%H.%M.%S', localtime(time()))) + config.get_str('outdir'), '{}.{}.txt'.format(ship, strftime('%Y-%m-%dT%H.%M.%S', localtime(time()))) ) try: diff --git a/outfitting.py b/outfitting.py index 061cb4f3..1670f06b 100644 --- a/outfitting.py +++ b/outfitting.py @@ -509,7 +509,7 @@ def lookup(module, ship_map, entitled=False): def export(data, filename): - querytime = config.getint('querytime') or int(time.time()) + querytime = config.get_int('querytime') or int(time.time()) assert data['lastSystem'].get('name') assert data['lastStarport'].get('name') diff --git a/plugins/coriolis.py b/plugins/coriolis.py index 21077886..36ccde27 100644 --- a/plugins/coriolis.py +++ b/plugins/coriolis.py @@ -8,7 +8,7 @@ import io # Migrate settings from <= 3.01 from config import config -if not config.get('shipyard_provider') and config.getint('shipyard'): +if not config.get_str('shipyard_provider') and config.get_int('shipyard'): config.set('shipyard_provider', 'Coriolis') config.delete('shipyard') diff --git a/plugins/eddb.py b/plugins/eddb.py index f61ae017..12ebc8ed 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -104,14 +104,14 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.station_marketid = None # Only actually change URLs if we are current provider. - if config.get('system_provider') == 'eddb': + if config.get_str('system_provider') == 'eddb': this.system_link['text'] = this.system # Do *NOT* set 'url' here, as it's set to a function that will call # through correctly. We don't want a static string. this.system_link.update_idletasks() # But only actually change the URL if we are current station provider. - if config.get('station_provider') == 'eddb': + if config.get_str('station_provider') == 'eddb': text = this.station if not text: if this.system_population is not None and this.system_population > 0: @@ -139,13 +139,13 @@ def cmdr_data(data: CAPIData, is_beta): this.station = data['lastStarport']['name'] # Override standard URL functions - if config.get('system_provider') == 'eddb': + if config.get_str('system_provider') == 'eddb': this.system_link['text'] = this.system # Do *NOT* set 'url' here, as it's set to a function that will call # through correctly. We don't want a static string. this.system_link.update_idletasks() - if config.get('station_provider') == 'eddb': + if config.get_str('station_provider') == 'eddb': if data['commander']['docked']: this.station_link['text'] = this.station diff --git a/plugins/eddn.py b/plugins/eddn.py index 243b6beb..8faed4fd 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -305,7 +305,7 @@ Msg:\n{msg}''' data['lastStarport'].get('economies', {}), data['lastStarport']['modules'], data['lastStarport']['ships'] - ) + ) to_search: Iterator[Mapping[str, Any]] = filter( lambda m: self.MODULE_RE.search(m['name']) and m.get('sku') in (None, HORIZ_SKU) and @@ -348,7 +348,7 @@ Msg:\n{msg}''' data['lastStarport'].get('economies', {}), data['lastStarport']['modules'], ships - ) + ) shipyard: List[Mapping[str, Any]] = sorted( itertools.chain( @@ -495,7 +495,7 @@ Msg:\n{msg}''' if ( entry['event'] == 'Docked' or (entry['event'] == 'Location' and entry['Docked']) or not - (config.getint('output') & config.OUT_SYS_DELAY) + (config.get_int('output') & config.OUT_SYS_DELAY) ): self.parent.after(self.REPLAYPERIOD, self.sendreplay) # Try to send this and previous entries @@ -531,11 +531,11 @@ def plugin_prefs(parent, cmdr: str, is_beta: bool) -> Frame: PADX = 10 # noqa: N806 BUTTONX = 12 # noqa: N806 # indent Checkbuttons and Radiobuttons - if prefsVersion.shouldSetDefaults('0.0.0.0', not bool(config.getint('output'))): + if prefsVersion.shouldSetDefaults('0.0.0.0', not bool(config.get_int('output'))): output: int = (config.OUT_MKT_EDDN | config.OUT_SYS_EDDN) # default settings else: - output: int = config.getint('output') + output = config.get_int('output') eddnframe = nb.Frame(parent) @@ -587,7 +587,7 @@ def prefsvarchanged(event=None) -> None: def prefs_changed(cmdr: str, is_beta: bool) -> None: config.set( 'output', - (config.getint('output') & (config.OUT_MKT_TD | config.OUT_MKT_CSV | config.OUT_SHIP | config.OUT_MKT_MANUAL)) + + (config.get_int('output') & (config.OUT_MKT_TD | config.OUT_MKT_CSV | config.OUT_SHIP | config.OUT_MKT_MANUAL)) + (this.eddn_station.get() and config.OUT_MKT_EDDN) + (this.eddn_system.get() and config.OUT_SYS_EDDN) + (this.eddn_delay.get() and config.OUT_SYS_DELAY) @@ -645,7 +645,7 @@ def journal_entry( # noqa: C901 this.planet = None # Send interesting events to EDDN, but not when on a crew - if (config.getint('output') & config.OUT_SYS_EDDN and not state['Captain'] and + if (config.get_int('output') & config.OUT_SYS_EDDN and not state['Captain'] and (entry['event'] in ('Location', 'FSDJump', 'Docked', 'Scan', 'SAASignalsFound', 'CarrierJump')) and ('StarPos' in entry or this.coordinates)): @@ -719,7 +719,7 @@ def journal_entry( # noqa: C901 logger.debug('Failed in export_journal_entry', exc_info=e) return str(e) - elif (config.getint('output') & config.OUT_MKT_EDDN and not state['Captain'] and + elif (config.get_int('output') & config.OUT_MKT_EDDN and not state['Captain'] and entry['event'] in ('Market', 'Outfitting', 'Shipyard')): # Market.json, Outfitting.json or Shipyard.json to process @@ -728,7 +728,7 @@ def journal_entry( # noqa: C901 this.commodities = this.outfitting = this.shipyard = None this.marketId = entry['MarketID'] - path = pathlib.Path(str(config.get('journaldir') or config.default_journal_dir)) / f'{entry["event"]}.json' + path = pathlib.Path(str(config.get_str('journaldir') or config.default_journal_dir)) / f'{entry["event"]}.json' with path.open('rb') as f: entry = json.load(f) if entry['event'] == 'Market': @@ -750,7 +750,7 @@ def journal_entry( # noqa: C901 def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: - if data['commander'].get('docked') and config.getint('output') & config.OUT_MKT_EDDN: + if data['commander'].get('docked') and config.get_int('output') & config.OUT_MKT_EDDN: try: if this.marketId != data['lastStarport']['id']: this.commodities = this.outfitting = this.shipyard = None diff --git a/plugins/edsm.py b/plugins/edsm.py index ce2b40b3..1fd43a60 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -15,7 +15,7 @@ import sys import tkinter as tk from queue import Queue from threading import Thread -from typing import TYPE_CHECKING, Any, List, Mapping, MutableMapping, Optional, Tuple +from typing import TYPE_CHECKING, Any, List, Mapping, MutableMapping, Optional, Tuple, cast import requests @@ -124,20 +124,20 @@ def plugin_start3(plugin_dir: str) -> str: this._IMG_ERROR = tk.PhotoImage(data=IMG_ERR_B64) # BBC Mode 5 '?' # Migrate old settings - if not config.get('edsm_cmdrs'): - if isinstance(config.get('cmdrs'), list) and config.get('edsm_usernames') and config.get('edsm_apikeys'): + if not config.get_list('edsm_cmdrs'): + if isinstance(config.get_list('cmdrs'), list) and config.get_list('edsm_usernames') and config.get_list('edsm_apikeys'): # Migrate <= 2.34 settings - config.set('edsm_cmdrs', config.get('cmdrs')) + config.set('edsm_cmdrs', config.get_list('cmdrs')) - elif config.get('edsm_cmdrname'): + elif config.get_list('edsm_cmdrname'): # Migrate <= 2.25 settings. edsm_cmdrs is unknown at this time - config.set('edsm_usernames', [config.get('edsm_cmdrname') or '']) - config.set('edsm_apikeys', [config.get('edsm_apikey') or '']) + config.set('edsm_usernames', [config.get_str('edsm_cmdrname') or '']) + config.set('edsm_apikeys', [config.get_str('edsm_apikey') or '']) config.delete('edsm_cmdrname') config.delete('edsm_apikey') - if config.getint('output') & 256: + if config.get_int('output') & 256: # Migrate <= 2.34 setting config.set('edsm_out', 1) @@ -189,7 +189,7 @@ def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame: underline=True ).grid(columnspan=2, padx=PADX, sticky=tk.W) # Don't translate - this.log = tk.IntVar(value=config.getint('edsm_out') and 1) + this.log = tk.IntVar(value=config.get_int('edsm_out') and 1) this.log_button = nb.Checkbutton( frame, text=_('Send flight log and Cmdr status to EDSM'), variable=this.log, command=prefsvarchanged ) @@ -289,9 +289,10 @@ def prefs_changed(cmdr: str, is_beta: bool) -> None: if cmdr and not is_beta: # TODO: remove this when config is rewritten. - cmdrs: List[str] = list(config.get('edsm_cmdrs') or []) - usernames: List[str] = list(config.get('edsm_usernames') or []) - apikeys: List[str] = list(config.get('edsm_apikeys') or []) + cmdrs: List[str] = config.get_list('edsm_cmdrs', []) + usernames: List[str] = config.get_list('edsm_usernames', []) + apikeys: List[str] = config.get_list('edsm_apikeys', []) + if cmdr in cmdrs: idx = cmdrs.index(cmdr) usernames.extend([''] * (1 + idx - len(usernames))) @@ -319,15 +320,15 @@ def credentials(cmdr: str) -> Optional[Tuple[str, str]]: if not cmdr: return None - cmdrs = config.get('edsm_cmdrs') + cmdrs = config.get_list('edsm_cmdrs') if not cmdrs: # Migrate from <= 2.25 cmdrs = [cmdr] config.set('edsm_cmdrs', cmdrs) - if cmdr in cmdrs and config.get('edsm_usernames') and config.get('edsm_apikeys'): + if cmdr in cmdrs and config.get_list('edsm_usernames') and config.get_list('edsm_apikeys'): idx = cmdrs.index(cmdr) - return (config.get('edsm_usernames')[idx], config.get('edsm_apikeys')[idx]) + return (config.get_list('edsm_usernames')[idx], config.get_list('edsm_apikeys')[idx]) else: return None @@ -364,7 +365,7 @@ entry: {entry!r}''' this.station = None this.station_marketid = None - if config.get('station_provider') == 'EDSM': + if config.get_str('station_provider') == 'EDSM': to_set = this.station if not this.station: if this.system_population and this.system_population > 0: @@ -410,7 +411,7 @@ entry: {entry!r}''' # Send interesting events to EDSM if ( - config.getint('edsm_out') and not is_beta and not this.multicrew and credentials(cmdr) and + config.get_int('edsm_out') and not is_beta and not this.multicrew and credentials(cmdr) and entry['event'] not in this.discardedEvents ): # Introduce transient states into the event @@ -460,13 +461,13 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> None: # TODO: Fire off the EDSM API call to trigger the callback for the icons - if config.get('system_provider') == 'EDSM': + if config.get_str('system_provider') == 'EDSM': this.system_link['text'] = this.system # Do *NOT* set 'url' here, as it's set to a function that will call # through correctly. We don't want a static string. this.system_link.update_idletasks() - if config.get('station_provider') == 'EDSM': + if config.get_str('station_provider') == 'EDSM': if data['commander']['docked']: this.station_link['text'] = this.station diff --git a/plugins/inara.py b/plugins/inara.py index 5abcf2ec..92d3d661 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -209,7 +209,7 @@ def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame: frame, text='Inara', background=nb.Label().cget('background'), url='https://inara.cz/', underline=True ).grid(columnspan=2, padx=PADX, sticky=tk.W) # Don't translate - this.log = tk.IntVar(value=config.getint('inara_out') and 1) + this.log = tk.IntVar(value=config.get_int('inara_out') and 1) this.log_button = nb.Checkbutton( frame, text=_('Send flight log and Cmdr status to Inara'), variable=this.log, command=prefsvarchanged ) @@ -271,14 +271,14 @@ def prefsvarchanged(): def prefs_changed(cmdr: str, is_beta: bool) -> None: """Preferences window closed hook.""" - changed = config.getint('inara_out') != this.log.get() + changed = config.get_int('inara_out') != this.log.get() config.set('inara_out', this.log.get()) if cmdr and not is_beta: this.cmdr = cmdr this.FID = None - cmdrs = config.get('inara_cmdrs') or [] - apikeys = config.get('inara_apikeys') or [] + cmdrs = config.get_list('inara_cmdrs', []) + apikeys = config.get_list('inara_apikeys', []) if cmdr in cmdrs: idx = cmdrs.index(cmdr) apikeys.extend([''] * (1 + idx - len(apikeys))) @@ -309,9 +309,9 @@ def credentials(cmdr: str) -> Optional[str]: if not cmdr: return None - cmdrs = config.get('inara_cmdrs') or [] - if cmdr in cmdrs and config.get('inara_apikeys'): - return config.get('inara_apikeys')[cmdrs.index(cmdr)] + cmdrs = config.get_list('inara_cmdrs', []) + if cmdr in cmdrs and config.get_list('inara_apikeys'): + return config.get_list('inara_apikeys')[cmdrs.index(cmdr)] else: return None @@ -377,7 +377,7 @@ def journal_entry( this.station = None this.station_marketid = None - if config.getint('inara_out') and not is_beta and not this.multicrew and credentials(cmdr): + if config.get_int('inara_out') and not is_beta and not this.multicrew and credentials(cmdr): current_creds = Credentials(this.cmdr, this.FID, str(credentials(this.cmdr))) try: # Dump starting state to Inara @@ -1018,13 +1018,13 @@ def journal_entry( this.newuser = False # Only actually change URLs if we are current provider. - if config.get('system_provider') == 'Inara': + if config.get_str('system_provider') == 'Inara': this.system_link['text'] = this.system # Do *NOT* set 'url' here, as it's set to a function that will call # through correctly. We don't want a static string. this.system_link.update_idletasks() - if config.get('station_provider') == 'Inara': + if config.get_str('station_provider') == 'Inara': to_set: str = cast(str, this.station) if not to_set: if this.system_population is not None and this.system_population > 0: @@ -1053,13 +1053,13 @@ def cmdr_data(data: CAPIData, is_beta): this.station = data['lastStarport']['name'] # Override standard URL functions - if config.get('system_provider') == 'Inara': + if config.get_str('system_provider') == 'Inara': this.system_link['text'] = this.system # Do *NOT* set 'url' here, as it's set to a function that will call # through correctly. We don't want a static string. this.system_link.update_idletasks() - if config.get('station_provider') == 'Inara': + if config.get_str('station_provider') == 'Inara': if data['commander']['docked']: this.station_link['text'] = this.station @@ -1073,7 +1073,7 @@ def cmdr_data(data: CAPIData, is_beta): # through correctly. We don't want a static string. this.station_link.update_idletasks() - if config.getint('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr): + if config.get_int('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr): if not (CREDIT_RATIO > this.lastcredits / data['commander']['credits'] > 1/CREDIT_RATIO): new_this.filter_events( Credentials(this.cmdr, this.FID, str(credentials(this.cmdr))), diff --git a/prefs.py b/prefs.py index e9c3afab..7bfb697c 100644 --- a/prefs.py +++ b/prefs.py @@ -85,7 +85,7 @@ class PrefsVersion: """ # config.get('PrefsVersion') is the version preferences we last saved for - pv = config.getint('PrefsVersion') + pv = config.get_int('PrefsVersion') # If no PrefsVersion yet exists then return oldTest if not pv: return oldTest @@ -326,11 +326,11 @@ class PreferencesDialog(tk.Toplevel): output_frame = nb.Frame(root_notebook) output_frame.columnconfigure(0, weight=1) - if prefsVersion.shouldSetDefaults('0.0.0.0', not bool(config.getint('output'))): + if prefsVersion.shouldSetDefaults('0.0.0.0', not bool(config.get_int('output'))): output = config.OUT_SHIP # default settings else: - output = config.getint('output') + output = config.get_int('output') row = AutoInc(start=1) @@ -376,7 +376,7 @@ class PreferencesDialog(tk.Toplevel): self.out_auto_button.grid(columnspan=2, padx=self.BUTTONX, pady=(5, 0), sticky=tk.W, row=row.get()) self.outdir = tk.StringVar() - self.outdir.set(str(config.get('outdir'))) + self.outdir.set(str(config.get_str('outdir'))) self.outdir_label = nb.Label(output_frame, text=_('File location')+':') # Section heading in settings # Type ignored due to incorrect type annotation. a 2 tuple does padding for each side self.outdir_label.grid(padx=self.PADX, pady=(5, 0), sticky=tk.W, row=row.get()) # type: ignore @@ -407,7 +407,7 @@ class PreferencesDialog(tk.Toplevel): row = AutoInc(start=1) self.logdir = tk.StringVar() - self.logdir.set(str(config.get('journaldir') or config.default_journal_dir or '')) + self.logdir.set(str(config.get_str('journaldir') or config.default_journal_dir or '')) self.logdir_entry = nb.Entry(config_frame, takefocus=False) # Location of the new Journal file in E:D 2.2 @@ -431,7 +431,7 @@ class PreferencesDialog(tk.Toplevel): config_frame, text=_('Default'), command=self.logdir_reset, - state=tk.NORMAL if config.get('journaldir') else tk.DISABLED + state=tk.NORMAL if config.get_str('journaldir') else tk.DISABLED ).grid(column=2, pady=self.PADY, sticky=tk.EW, row=row.get()) if platform in ('darwin', 'win32'): @@ -439,10 +439,10 @@ class PreferencesDialog(tk.Toplevel): columnspan=4, padx=self.PADX, pady=self.PADY*4, sticky=tk.EW, row=row.get() ) - self.hotkey_code = config.getint('hotkey_code') - self.hotkey_mods = config.getint('hotkey_mods') - self.hotkey_only = tk.IntVar(value=not config.getint('hotkey_always')) - self.hotkey_play = tk.IntVar(value=not config.getint('hotkey_mute')) + self.hotkey_code = config.get_int('hotkey_code') + self.hotkey_mods = config.get_int('hotkey_mods') + self.hotkey_only = tk.IntVar(value=not config.get_int('hotkey_always')) + self.hotkey_play = tk.IntVar(value=not config.get_int('hotkey_mute')) nb.Label( config_frame, text=_('Keyboard shortcut') if # Hotkey/Shortcut settings prompt on OSX @@ -509,7 +509,7 @@ class PreferencesDialog(tk.Toplevel): ttk.Separator(config_frame, orient=tk.HORIZONTAL).grid( columnspan=4, padx=self.PADX, pady=self.PADY*4, sticky=tk.EW, row=row.get() ) - self.disable_autoappupdatecheckingame = tk.IntVar(value=config.getint('disable_autoappupdatecheckingame')) + self.disable_autoappupdatecheckingame = tk.IntVar(value=config.get_int('disable_autoappupdatecheckingame')) self.disable_autoappupdatecheckingame_btn = nb.Checkbutton( config_frame, text=_('Disable Automatic Application Updates Check when in-game'), @@ -531,8 +531,8 @@ class PreferencesDialog(tk.Toplevel): with row as cur_row: self.shipyard_provider = tk.StringVar( value=str( - config.get('shipyard_provider') in plug.provides('shipyard_url') - and config.get('shipyard_provider') or 'EDSY') + config.get_str('shipyard_provider') in plug.provides('shipyard_url') + and config.get_str('shipyard_provider', 'EDSY')) ) # Setting to decide which ship outfitting website to link to - either E:D Shipyard or Coriolis nb.Label(config_frame, text=_('Shipyard')).grid(padx=self.PADX, pady=2*self.PADY, sticky=tk.W, row=cur_row) @@ -543,7 +543,7 @@ class PreferencesDialog(tk.Toplevel): self.shipyard_button.configure(width=15) self.shipyard_button.grid(column=1, sticky=tk.W, row=cur_row) # Option for alternate URL opening - self.alt_shipyard_open = tk.IntVar(value=config.getint('use_alt_shipyard_open')) + self.alt_shipyard_open = tk.IntVar(value=config.get_int('use_alt_shipyard_open')) self.alt_shipyard_open_btn = nb.Checkbutton( config_frame, text=_('Use alternate URL method'), @@ -554,7 +554,7 @@ class PreferencesDialog(tk.Toplevel): self.alt_shipyard_open_btn.grid(column=2, sticky=tk.W, row=cur_row) with row as cur_row: - system_provider = config.get('system_provider') + system_provider = config.get_str('system_provider') self.system_provider = tk.StringVar( value=str(system_provider if system_provider in plug.provides('system_url') else 'EDSM') ) @@ -571,7 +571,7 @@ class PreferencesDialog(tk.Toplevel): self.system_button.grid(column=1, sticky=tk.W, row=cur_row) with row as cur_row: - station_provider = config.get('station_provider') + station_provider = config.get_str('station_provider') self.station_provider = tk.StringVar( value=str(station_provider if station_provider in plug.provides('station_url') else 'eddb') ) @@ -599,7 +599,7 @@ class PreferencesDialog(tk.Toplevel): text=_('Log Level') ).grid(padx=self.PADX, pady=2*self.PADY, sticky=tk.W, row=cur_row) - current_loglevel = config.get('loglevel') + current_loglevel = config.get_str('loglevel') if not current_loglevel: current_loglevel = logging.getLevelName(logging.INFO) @@ -628,10 +628,10 @@ class PreferencesDialog(tk.Toplevel): def __setup_appearance_tab(self, notebook: Notebook) -> None: self.languages = Translations.available_names() # Appearance theme and language setting - self.lang = tk.StringVar(value=self.languages.get(config.get('language'), _('Default'))) - self.always_ontop = tk.BooleanVar(value=bool(config.getint('always_ontop'))) - self.theme = tk.IntVar(value=config.getint('theme')) - self.theme_colors = [config.get('dark_text'), config.get('dark_highlight')] + self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default'))) + self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) + self.theme = tk.IntVar(value=config.get_int('theme')) + self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')] self.theme_prompts = [ _('Normal text'), # Dark theme color setting _('Highlighted text'), # Dark theme color setting @@ -715,7 +715,7 @@ class PreferencesDialog(tk.Toplevel): ) self.ui_scale = tk.IntVar() - self.ui_scale.set(config.getint('ui_scale')) + self.ui_scale.set(config.get_int('ui_scale')) self.uiscale_bar = tk.Scale( appearance_frame, variable=self.ui_scale, # TODO: intvar, but annotated as DoubleVar @@ -897,7 +897,7 @@ class PreferencesDialog(tk.Toplevel): def browsecallback(hwnd, uMsg, lParam, lpData): # set initial folder if uMsg == BFFM_INITIALIZED and lpData: - ctypes.windll.user32.SendMessageW(hwnd, BFFM_SETSELECTION, 1, lpData); + ctypes.windll.user32.SendMessageW(hwnd, BFFM_SETSELECTION, 1, lpData) return 0 browseInfo = BROWSEINFO() @@ -1084,7 +1084,7 @@ class PreferencesDialog(tk.Toplevel): (self.out_csv.get() and config.OUT_MKT_CSV) + (config.OUT_MKT_MANUAL if not self.out_auto.get() else 0) + (self.out_ship.get() and config.OUT_SHIP) + - (config.getint('output') & (config.OUT_MKT_EDDN | config.OUT_SYS_EDDN | config.OUT_SYS_DELAY)) + (config.get_int('output') & (config.OUT_MKT_EDDN | config.OUT_SYS_EDDN | config.OUT_SYS_DELAY)) ) config.set( @@ -1113,7 +1113,7 @@ class PreferencesDialog(tk.Toplevel): lang_codes = {v: k for k, v in self.languages.items()} # Codes by name config.set('language', lang_codes.get(self.lang.get()) or '') # or '' used here due to Default being None above - Translations.install(config.get('language') or None) # type: ignore # This sets self in weird ways. + Translations.install(config.get_str('language') or None) # type: ignore # This sets self in weird ways. config.set('ui_scale', self.ui_scale.get()) config.set('always_ontop', self.always_ontop.get()) @@ -1136,7 +1136,7 @@ class PreferencesDialog(tk.Toplevel): self.after_cancel(self.cmdrchanged_alarm) self.cmdrchanged_alarm = None - self.parent.wm_attributes('-topmost', 1 if config.getint('always_ontop') else 0) + self.parent.wm_attributes('-topmost', 1 if config.get_int('always_ontop') else 0) self.destroy() if platform == 'darwin': diff --git a/shipyard.py b/shipyard.py index fe31d33e..ba25a55c 100644 --- a/shipyard.py +++ b/shipyard.py @@ -8,7 +8,7 @@ from config import config def export(data, filename): - querytime = config.getint('querytime') or int(time.time()) + querytime = config.get_int('querytime', int(time.time())) assert data['lastSystem'].get('name') assert data['lastStarport'].get('name') diff --git a/td.py b/td.py index ba4e5465..956371e2 100644 --- a/td.py +++ b/td.py @@ -22,9 +22,9 @@ stockbracketmap = { 0: '-', def export(data): - querytime = config.getint('querytime') or int(time.time()) + querytime = config.get_int('querytime', int(time.time())) - filename = join(config.get('outdir'), '%s.%s.%s.prices' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))) + filename = join(config.get_str('outdir'), '%s.%s.%s.prices' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))) timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(data['timestamp'], '%Y-%m-%dT%H:%M:%SZ')) diff --git a/theme.py b/theme.py index d56b7798..26cff4f3 100644 --- a/theme.py +++ b/theme.py @@ -207,21 +207,21 @@ class _Theme(object): style.theme_use('clam') # Default dark theme colors - if not config.get('dark_text'): + if not config.get_str('dark_text'): config.set('dark_text', '#ff8000') # "Tangerine" in OSX color picker - if not config.get('dark_highlight'): + if not config.get_str('dark_highlight'): config.set('dark_highlight', 'white') if theme: # Dark - (r, g, b) = root.winfo_rgb(config.get('dark_text')) + (r, g, b) = root.winfo_rgb(config.get_str('dark_text')) self.current = { 'background' : 'grey4', # OSX inactive dark titlebar color - 'foreground' : config.get('dark_text'), - 'activebackground' : config.get('dark_text'), + 'foreground' : config.get_str('dark_text'), + 'activebackground' : config.get_str('dark_text'), 'activeforeground' : 'grey4', 'disabledforeground' : '#%02x%02x%02x' % (int(r/384), int(g/384), int(b/384)), - 'highlight' : config.get('dark_highlight'), + 'highlight' : config.get_str('dark_highlight'), # Font only supports Latin 1 / Supplement / Extended, and a few General Punctuation and Mathematical Operators 'font' : (theme > 1 and not 0x250 < ord(_('Cmdr')[0]) < 0x3000 and tkFont.Font(family='Euro Caps', size=10, weight=tkFont.NORMAL) or @@ -309,7 +309,7 @@ class _Theme(object): # Apply configured theme def apply(self, root): - theme = config.getint('theme') + theme = config.get_int('theme') self._colors(root, theme) # Apply colors From fd51ee5d053a676c6b252dac623306c10c231541 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:05:59 +0000 Subject: [PATCH 168/727] Updated EDMarketConnector.py to new config # Conflicts: # EDMarketConnector.py --- EDMarketConnector.py | 100 ++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index fffb6d00..b0c69557 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -14,7 +14,7 @@ from os import chdir, environ from os.path import dirname, isdir, join from sys import platform from time import localtime, strftime, time -from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple +from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple, cast from constants import applongname, appname, protocolhandler_redirect @@ -390,7 +390,7 @@ class AppWindow(object): def __init__(self, master: tk.Tk): # noqa: C901, CCR001 # TODO - can possibly factor something out - self.holdofftime = config.getint('querytime') + companion.holdoff + self.holdofftime = cast(int, config.get_int('querytime', 0)) + companion.holdoff self.w = master self.w.title(applongname) @@ -532,7 +532,7 @@ class AppWindow(object): self.menubar.add_cascade(menu=self.help_menu) if platform == 'win32': # Must be added after at least one "real" menu entry - self.always_ontop = tk.BooleanVar(value=config.getint('always_ontop')) + self.always_ontop = tk.BooleanVar(value=cast(int, config.get_int('always_ontop'))) self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system_menu.add_separator() self.system_menu.add_checkbutton(label=_('Always on top'), @@ -593,13 +593,13 @@ class AppWindow(object): self.w.resizable(tk.TRUE, tk.FALSE) # update geometry - if config.get('geometry'): - match = re.match('\+([\-\d]+)\+([\-\d]+)', config.get('geometry')) # noqa: W605 + if config.get_str('geometry'): + match = re.match(r'\+([\-\d]+)\+([\-\d]+)', config.get_str('geometry')) # noqa: W605 if match: if platform == 'darwin': # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 if int(match.group(2)) >= 0: - self.w.geometry(config.get('geometry')) + self.w.geometry(config.get_str('geometry')) elif platform == 'win32': # Check that the titlebar will be at least partly on screen import ctypes @@ -609,10 +609,10 @@ class AppWindow(object): MONITOR_DEFAULTTONULL = 0 # noqa: N806 if ctypes.windll.user32.MonitorFromPoint(POINT(int(match.group(1)) + 16, int(match.group(2)) + 16), MONITOR_DEFAULTTONULL): - self.w.geometry(config.get('geometry')) + self.w.geometry(config.get_str('geometry')) else: - self.w.geometry(config.get('geometry')) - self.w.attributes('-topmost', config.getint('always_ontop') and 1 or 0) + self.w.geometry(config.get_str('geometry')) + self.w.attributes('-topmost', config.get_int('always_ontop') and 1 or 0) theme.register(frame) theme.apply(self.w) @@ -645,7 +645,7 @@ class AppWindow(object): self.updater.checkForUpdates() # Sparkle / WinSparkle does this automatically for packaged apps # Migration from <= 3.30 - for username in config.get('fdev_usernames') or []: + for username in config.get_list('fdev_usernames', []): config.delete_password(username) config.delete('fdev_usernames') config.delete('username') @@ -665,7 +665,7 @@ class AppWindow(object): self.station.configure(url=self.station_url) # (Re-)install hotkey monitoring - hotkeymgr.register(self.w, config.getint('hotkey_code'), config.getint('hotkey_mods')) + hotkeymgr.register(self.w, config.get_int('hotkey_code'), config.get_int('hotkey_mods')) # Update Journal lock if needs be. journal_lock.update_lock(self.w) @@ -784,7 +784,7 @@ class AppWindow(object): :return: True if all OK, else False to trigger play_bad in caller. """ - if config.getint('output') & (config.OUT_STATION_ANY): + if config.get_int('output') & (config.OUT_STATION_ANY): if not data['commander'].get('docked'): if not self.status['text']: # Signal as error because the user might actually be docked @@ -793,7 +793,7 @@ class AppWindow(object): return False # Ignore possibly missing shipyard info - elif (config.getint('output') & config.OUT_MKT_EDDN) \ + elif (config.get_int('output') & config.OUT_MKT_EDDN) \ and not (data['lastStarport'].get('commodities') or data['lastStarport'].get('modules')): if not self.status['text']: self.status['text'] = _("Station doesn't have anything!") @@ -802,13 +802,13 @@ class AppWindow(object): if not self.status['text']: self.status['text'] = _("Station doesn't have a market!") - elif config.getint('output') & (config.OUT_MKT_CSV | config.OUT_MKT_TD): + elif config.get_int('output') & (config.OUT_MKT_CSV | config.OUT_MKT_TD): # Fixup anomalies in the commodity data fixed = companion.fixup(data) - if config.getint('output') & config.OUT_MKT_CSV: + if config.get_int('output') & config.OUT_MKT_CSV: commodity.export(fixed, COMMODITY_CSV) - if config.getint('output') & config.OUT_MKT_TD: + if config.get_int('output') & config.OUT_MKT_TD: td.export(fixed) return True @@ -821,7 +821,7 @@ class AppWindow(object): automatically on docking, or due to a retry. """ auto_update = not event - play_sound = (auto_update or int(event.type) == self.EVENT_VIRTUAL) and not config.getint('hotkey_mute') + play_sound = (auto_update or int(event.type) == self.EVENT_VIRTUAL) and not config.get_int('hotkey_mute') play_bad = False if not monitor.cmdr or not monitor.mode or monitor.state['Captain'] or not monitor.system: @@ -1022,8 +1022,8 @@ class AppWindow(object): # Companion login if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'] and monitor.cmdr: - if not config.get('cmdrs') or monitor.cmdr not in config.get('cmdrs'): - config.set('cmdrs', (config.get('cmdrs') or []) + [monitor.cmdr]) + if not config.get_list('cmdrs') or monitor.cmdr not in config.get_list('cmdrs'): + config.set('cmdrs', config.get_list('cmdrs', []) + [monitor.cmdr]) self.login() if not entry['event'] or not monitor.mode: @@ -1034,7 +1034,7 @@ class AppWindow(object): logger.info('Startup or LoadGame event') # Disable WinSparkle automatic update checks, IFF configured to do so when in-game - if config.getint('disable_autoappupdatecheckingame') and 1: + if config.get_int('disable_autoappupdatecheckingame') and 1: self.updater.setAutomaticUpdatesCheck(False) logger.info('Monitor: Disable WinSparkle automatic update checks') @@ -1044,7 +1044,7 @@ class AppWindow(object): # Export loadout if entry['event'] == 'Loadout' and not monitor.state['Captain'] \ - and config.getint('output') & config.OUT_SHIP: + and config.get_int('output') & config.OUT_SHIP: monitor.export_ship() err = plug.notify_journal_entry(monitor.cmdr, @@ -1055,15 +1055,15 @@ class AppWindow(object): monitor.state) if err: self.status['text'] = err - if not config.getint('hotkey_mute'): + if not config.get_int('hotkey_mute'): hotkeymgr.play_bad() # Auto-Update after docking, but not if auth callback is pending if ( entry['event'] in ('StartUp', 'Location', 'Docked') and monitor.station - and not config.getint('output') & config.OUT_MKT_MANUAL - and config.getint('output') & config.OUT_STATION_ANY + and not config.get_int('output') & config.OUT_MKT_MANUAL + and config.get_int('output') & config.OUT_STATION_ANY and companion.session.state != companion.Session.STATE_AUTH ): self.w.after(int(SERVER_RETRY * 1000), self.getandsend) @@ -1117,7 +1117,7 @@ class AppWindow(object): err = plug.notify_dashboard_entry(monitor.cmdr, monitor.is_beta, entry) if err: self.status['text'] = err - if not config.getint('hotkey_mute'): + if not config.get_int('hotkey_mute'): hotkeymgr.play_bad() def plugin_error(self, event=None) -> None: @@ -1125,17 +1125,17 @@ class AppWindow(object): if plug.last_error.get('msg'): self.status['text'] = plug.last_error['msg'] self.w.update_idletasks() - if not config.getint('hotkey_mute'): + if not config.get_int('hotkey_mute'): hotkeymgr.play_bad() def shipyard_url(self, shipname: str) -> str: """Despatch a ship URL to the configured handler.""" - if not bool(config.getint("use_alt_shipyard_open")): - return plug.invoke(config.get('shipyard_provider'), 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) + if not bool(config.get_int("use_alt_shipyard_open")): + return plug.invoke(config.get_str('shipyard_provider'), 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) # Avoid file length limits if possible - provider = config.get('shipyard_provider') or 'EDSY' - target = plug.invoke(config.get('shipyard_provider'), 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) + provider = config.get_str('shipyard_provider', 'EDSY') + target = plug.invoke(provider, 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) file_name = join(config.app_dir, "last_shipyard.html") with open(file_name, 'w') as f: @@ -1149,11 +1149,11 @@ class AppWindow(object): def system_url(self, system: str) -> str: """Despatch a system URL to the configured handler.""" - return plug.invoke(config.get('system_provider'), 'EDSM', 'system_url', monitor.system) + return plug.invoke(config.get_str('system_provider'), 'EDSM', 'system_url', monitor.system) def station_url(self, station: str) -> str: """Despatch a station URL to the configured handler.""" - return plug.invoke(config.get('station_provider'), 'eddb', 'station_url', monitor.system, monitor.station) + return plug.invoke(config.get_str('station_provider'), 'eddb', 'station_url', monitor.system, monitor.station) def cooldown(self) -> None: """Display and update the cooldown timer for 'Update' button.""" @@ -1280,7 +1280,7 @@ class AppWindow(object): def _destroy(self) -> None: """Set parent window's topmost appropriately as we close.""" - self.parent.wm_attributes('-topmost', config.getint('always_ontop') and 1 or 0) + self.parent.wm_attributes('-topmost', config.get_int('always_ontop') and 1 or 0) self.destroy() self.__class__.showing = False @@ -1304,18 +1304,22 @@ class AppWindow(object): last_starport = '.' + data.get('lastStarport', {}).get('name', 'Unknown') timestamp: str = strftime('%Y-%m-%dT%H.%M.%S', localtime()) - f = tkinter.filedialog.asksaveasfilename(parent=self.w, - defaultextension=default_extension, - filetypes=[('JSON', '.json'), ('All Files', '*')], - initialdir=config.get('outdir'), - initialfile=f'{last_system}{last_starport}.{timestamp}') + f = tkinter.filedialog.asksaveasfilename( + parent=self.w, + defaultextension=default_extension, + filetypes=[('JSON', '.json'), ('All Files', '*')], + initialdir=config.get_str('outdir'), + initialfile=f'{last_system}{last_starport}.{timestamp}' + ) if f: with open(f, 'wb') as h: - h.write(json.dumps(dict(data), - ensure_ascii=False, - indent=2, - sort_keys=True, - separators=(',', ': ')).encode('utf-8')) + h.write(json.dumps( + data, + ensure_ascii=False, + indent=2, + sort_keys=True, + separators=(',', ': ')).encode('utf-8') + ) except companion.ServerError as e: self.status['text'] = str(e) @@ -1398,7 +1402,7 @@ class AppWindow(object): """Handle when our window gains focus.""" # TODO: This assumes that 1) transparent is at least 2, 2) there are # no new themes added after that. - if config.getint('theme') > 1: + if config.get_int('theme') > 1: self.w.attributes("-transparentcolor", '') self.blank_menubar.grid_remove() self.theme_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) @@ -1407,7 +1411,7 @@ class AppWindow(object): """Handle when our window loses focus.""" # TODO: This assumes that 1) transparent is at least 2, 2) there are # no new themes added after that. - if config.getint('theme') > 1 and event.widget == self.w: + if config.get_int('theme') > 1 and event.widget == self.w: self.w.attributes("-transparentcolor", 'grey4') self.theme_menubar.grid_remove() self.blank_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) @@ -1543,7 +1547,7 @@ sys.path: {sys.path}''' # Plain, not via `logger` print(f'{applongname} {appversion}') - Translations.install(config.get('language') or None) # Can generate errors so wait til log set up + Translations.install(config.get_str('language')) # Can generate errors so wait til log set up root = tk.Tk(className=appname.lower()) @@ -1551,7 +1555,7 @@ sys.path: {sys.path}''' """ We scale the UI relative to what we find tk-scaling is on startup. """ - ui_scale = config.getint('ui_scale') + ui_scale = config.get_int('ui_scale') # NB: This *also* catches a literal 0 value to re-set to the default 100 if not ui_scale: ui_scale = 100 @@ -1564,7 +1568,7 @@ sys.path: {sys.path}''' def messagebox_not_py3(): """Display message about plugins not updated for Python 3.x.""" - plugins_not_py3_last = config.getint('plugins_not_py3_last') or 0 + plugins_not_py3_last = config.get_int('plugins_not_py3_last') or 0 if (plugins_not_py3_last + 86400) < int(time()) and len(plug.PLUGINS_not_py3): # Yes, this is horribly hacky so as to be sure we match the key # that we told Translators to use. From dc793e62c4a419bc9a83eee4782202581e061212 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 21 Dec 2020 14:31:05 +0200 Subject: [PATCH 169/727] Updated plugin docs with new config info --- PLUGINS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 34f3831a..3ec5751c 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -220,8 +220,8 @@ title will be the value that you returned from `plugin_start3`. Use widgets from EDMC's myNotebook.py for the correct look-and-feel. You can be notified when the settings dialog is closed so you can save your settings. -You can use `set()`, `get()` and `getint()` from EDMC's `config.config` object -to retrieve your plugin's settings in a platform-independent way. +You can use `set()` and `get_$type()` (where type is one of: `int`, `bool`, `str`, `list`) from EDMC's +`config.config` object to retrieve your plugin's settings in a platform-independent way. **Be sure to use a unique prefix for any settings you save so as not to clash with core EDMC or other plugins.** @@ -248,7 +248,7 @@ def plugin_prefs(parent: nb.Notebook, cmdr: str, is_beta: bool) -> Optional[tk.F Return a TK Frame for adding to the EDMC settings dialog. """ global my_setting - my_setting = tk.IntVar(value=config.getint("MyPluginSetting")) # Retrieve saved value from config + my_setting = tk.IntVar(value=config.get_int("MyPluginSetting")) # Retrieve saved value from config frame = nb.Frame(parent) nb.Label(frame, text="Hello").grid() nb.Label(frame, text="Commander").grid() From f76e5d331ecf11a4ee95a7625cbaffe09bf7bc07 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 22 Dec 2020 20:07:12 +0200 Subject: [PATCH 170/727] Removed cast calls --- EDMarketConnector.py | 20 ++++++++++---------- companion.py | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b0c69557..aa4e39fc 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -390,7 +390,7 @@ class AppWindow(object): def __init__(self, master: tk.Tk): # noqa: C901, CCR001 # TODO - can possibly factor something out - self.holdofftime = cast(int, config.get_int('querytime', 0)) + companion.holdoff + self.holdofftime = config.get_int('querytime', 0) + companion.holdoff self.w = master self.w.title(applongname) @@ -532,13 +532,13 @@ class AppWindow(object): self.menubar.add_cascade(menu=self.help_menu) if platform == 'win32': # Must be added after at least one "real" menu entry - self.always_ontop = tk.BooleanVar(value=cast(int, config.get_int('always_ontop'))) - self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.always_ontop = tk.BooleanVar(value=config.get_int('always_ontop'))) + self.system_menu=tk.Menu(self.menubar, name = 'system', tearoff = tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system_menu.add_separator() - self.system_menu.add_checkbutton(label=_('Always on top'), - variable=self.always_ontop, - command=self.ontop_changed) # Appearance setting - self.menubar.add_cascade(menu=self.system_menu) + self.system_menu.add_checkbutton(label = _('Always on top'), + variable = self.always_ontop, + command = self.ontop_changed) # Appearance setting + self.menubar.add_cascade(menu = self.system_menu) self.w.bind('', self.copy) self.w.protocol("WM_DELETE_WINDOW", self.onexit) theme.register(self.menubar) # menus and children aren't automatically registered @@ -547,9 +547,9 @@ class AppWindow(object): theme.register(self.help_menu) # Alternate title bar and menu for dark theme - self.theme_menubar = tk.Frame(frame) - self.theme_menubar.columnconfigure(2, weight=1) - theme_titlebar = tk.Label(self.theme_menubar, text=applongname, + self.theme_menubar=tk.Frame(frame) + self.theme_menubar.columnconfigure(2, weight = 1) + theme_titlebar=tk.Label(self.theme_menubar, text = applongname, image=self.theme_icon, cursor='fleur', anchor=tk.W, compound=tk.LEFT) theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW) diff --git a/companion.py b/companion.py index 36639f3f..7c2432dd 100644 --- a/companion.py +++ b/companion.py @@ -285,13 +285,13 @@ class Auth(object): logger.debug(f'Trying for "{self.cmdr}"') self.verifier = None - cmdrs = cast(List[str], config.get_list('cmdrs', [])) + cmdrs = config.get_list('cmdrs', []) logger.debug(f'Cmdrs: {cmdrs}') idx = cmdrs.index(self.cmdr) logger.debug(f'idx = {idx}') - tokens = cast('List[str]', config.get_list('fdev_apikeys', [])) + tokens = config.get_list('fdev_apikeys', []) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) if tokens[idx]: logger.debug('We have a refresh token for that idx') @@ -375,9 +375,9 @@ class Auth(object): data = r.json() if r.status_code == requests.codes.ok: logger.info(f'Frontier CAPI Auth: New token for \"{self.cmdr}\"') - cmdrs = cast(List[str], config.get_list('cmdrs', [])) + cmdrs = config.get_list('cmdrs', []) idx = cmdrs.index(self.cmdr) - tokens = cast(List[str], config.get_list('fdev_apikeys', [])) + tokens = config.get_list('fdev_apikeys', []) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) tokens[idx] = data.get('refresh_token', '') config.set('fdev_apikeys', tokens) @@ -404,9 +404,9 @@ class Auth(object): def invalidate(cmdr: str) -> None: """Invalidate Refresh Token for specified Commander.""" logger.info(f'Frontier CAPI Auth: Invalidated token for "{cmdr}"') - cmdrs = cast(List[str], config.get_list('cmdrs', [])) + cmdrs = config.get_list('cmdrs', []) idx = cmdrs.index(cmdr) - tokens = cast(List[str], config.get_list('fdev_apikeys', [])) + tokens = config.get_list('fdev_apikeys', []) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) tokens[idx] = '' config.set('fdev_apikeys', tokens) From 278480b99ff786516048b43e8bdbb6fe5b74cc9c Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 22 Dec 2020 20:17:28 +0200 Subject: [PATCH 171/727] replaced ors with defaults in config usage --- EDMC.py | 6 +++--- EDMarketConnector.py | 8 ++++---- commodity.py | 2 +- companion.py | 12 ++++++------ dashboard.py | 2 +- edshipyard.py | 2 +- loadout.py | 2 +- monitor.py | 2 +- outfitting.py | 2 +- plugins/eddn.py | 2 +- plugins/edsm.py | 10 +++++----- plugins/inara.py | 6 +++--- prefs.py | 20 +++++++++++--------- shipyard.py | 2 +- td.py | 2 +- 15 files changed, 41 insertions(+), 39 deletions(-) diff --git a/EDMC.py b/EDMC.py index 55a1a3fd..b684a8ae 100755 --- a/EDMC.py +++ b/EDMC.py @@ -189,7 +189,7 @@ sys.path: {sys.path}''' # Get state from latest Journal file logger.debug('Getting state from latest journal file') try: - logdir = config.get_str('journaldir', str(config.default_journal_dir)) + logdir = config.get_str('journaldir', default=str(config.default_journal_dir)) logger.debug(f'logdir = "{logdir}"') logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)), key=lambda x: x.split('.')[1:]) @@ -215,7 +215,7 @@ sys.path: {sys.path}''' # Get data from Companion API if args.p: logger.debug(f'Attempting to use commander "{args.p}"') - cmdrs = config.get_list('cmdrs', []) + cmdrs = config.get_list('cmdrs', default=[]) if args.p in cmdrs: idx = cmdrs.index(args.p) @@ -231,7 +231,7 @@ sys.path: {sys.path}''' else: logger.debug(f'Attempting to use commander "{monitor.cmdr}" from Journal File') - cmdrs = config.get_list('cmdrs', []) + cmdrs = config.get_list('cmdrs', default=[]) if monitor.cmdr not in cmdrs: raise companion.CredentialsError() diff --git a/EDMarketConnector.py b/EDMarketConnector.py index aa4e39fc..60dd0733 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -390,7 +390,7 @@ class AppWindow(object): def __init__(self, master: tk.Tk): # noqa: C901, CCR001 # TODO - can possibly factor something out - self.holdofftime = config.get_int('querytime', 0) + companion.holdoff + self.holdofftime = config.get_int('querytime', default=0) + companion.holdoff self.w = master self.w.title(applongname) @@ -645,7 +645,7 @@ class AppWindow(object): self.updater.checkForUpdates() # Sparkle / WinSparkle does this automatically for packaged apps # Migration from <= 3.30 - for username in config.get_list('fdev_usernames', []): + for username in config.get_list('fdev_usernames', default=[]): config.delete_password(username) config.delete('fdev_usernames') config.delete('username') @@ -1023,7 +1023,7 @@ class AppWindow(object): # Companion login if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'] and monitor.cmdr: if not config.get_list('cmdrs') or monitor.cmdr not in config.get_list('cmdrs'): - config.set('cmdrs', config.get_list('cmdrs', []) + [monitor.cmdr]) + config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr]) self.login() if not entry['event'] or not monitor.mode: @@ -1568,7 +1568,7 @@ sys.path: {sys.path}''' def messagebox_not_py3(): """Display message about plugins not updated for Python 3.x.""" - plugins_not_py3_last = config.get_int('plugins_not_py3_last') or 0 + plugins_not_py3_last = config.get_int('plugins_not_py3_last', default=0) if (plugins_not_py3_last + 86400) < int(time()) and len(plug.PLUGINS_not_py3): # Yes, this is horribly hacky so as to be sure we match the key # that we told Translators to use. diff --git a/commodity.py b/commodity.py index 1ee86055..c384d127 100644 --- a/commodity.py +++ b/commodity.py @@ -20,7 +20,7 @@ bracketmap = { def export(data, kind=COMMODITY_DEFAULT, filename=None): - querytime = config.get_int('querytime') or int(time.time()) + querytime = config.get_int('querytime', default=int(time.time())) if not filename: filename = '{system}.{starport}.{time}.{kind}'.format( diff --git a/companion.py b/companion.py index 7c2432dd..bdbca243 100644 --- a/companion.py +++ b/companion.py @@ -285,13 +285,13 @@ class Auth(object): logger.debug(f'Trying for "{self.cmdr}"') self.verifier = None - cmdrs = config.get_list('cmdrs', []) + cmdrs = config.get_list('cmdrs', default=[]) logger.debug(f'Cmdrs: {cmdrs}') idx = cmdrs.index(self.cmdr) logger.debug(f'idx = {idx}') - tokens = config.get_list('fdev_apikeys', []) + tokens = config.get_list('fdev_apikeys', default=[]) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) if tokens[idx]: logger.debug('We have a refresh token for that idx') @@ -375,9 +375,9 @@ class Auth(object): data = r.json() if r.status_code == requests.codes.ok: logger.info(f'Frontier CAPI Auth: New token for \"{self.cmdr}\"') - cmdrs = config.get_list('cmdrs', []) + cmdrs = config.get_list('cmdrs', default=[]) idx = cmdrs.index(self.cmdr) - tokens = config.get_list('fdev_apikeys', []) + tokens = config.get_list('fdev_apikeys', default=[]) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) tokens[idx] = data.get('refresh_token', '') config.set('fdev_apikeys', tokens) @@ -404,9 +404,9 @@ class Auth(object): def invalidate(cmdr: str) -> None: """Invalidate Refresh Token for specified Commander.""" logger.info(f'Frontier CAPI Auth: Invalidated token for "{cmdr}"') - cmdrs = config.get_list('cmdrs', []) + cmdrs = config.get_list('cmdrs', default=[]) idx = cmdrs.index(cmdr) - tokens = config.get_list('fdev_apikeys', []) + tokens = config.get_list('fdev_apikeys', default=[]) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) tokens[idx] = '' config.set('fdev_apikeys', tokens) diff --git a/dashboard.py b/dashboard.py index 530e4b3b..372cdf01 100644 --- a/dashboard.py +++ b/dashboard.py @@ -41,7 +41,7 @@ class Dashboard(FileSystemEventHandler): self.root = root self.session_start = started - logdir = config.get_str('journaldir', str(config.default_journal_dir)) + logdir = config.get_str('journaldir', default=str(config.default_journal_dir)) if not logdir or not isdir(logdir): logger.info(f"No logdir, or it isn't a directory: {logdir=}") self.stop() diff --git a/edshipyard.py b/edshipyard.py index dd80ffda..0a642810 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -74,7 +74,7 @@ def export(data, filename=None): return ret + ' ' - querytime = config.get_int('querytime') or int(time.time()) + querytime = config.get_int('querytime', default=int(time.time())) loadout = defaultdict(list) mass = 0.0 diff --git a/loadout.py b/loadout.py index 85c4f0f8..8eb90448 100644 --- a/loadout.py +++ b/loadout.py @@ -28,7 +28,7 @@ def export(data, filename=None): if h.read() == string: return # same as last time - don't write - querytime = config.get_int('querytime') or int(time.time()) + querytime = config.get_int('querytime', default=int(time.time())) # Write filename = join(config.get_str('outdir'), '%s.%s.txt' % (ship, time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))) diff --git a/monitor.py b/monitor.py index 637bcb95..d602d05a 100644 --- a/monitor.py +++ b/monitor.py @@ -129,7 +129,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below """Start journal monitoring.""" logger.debug('Begin...') self.root = root - journal_dir = config.get_str('journaldir', str(config.default_journal_dir)) + journal_dir = config.get_str('journaldir', default=str(config.default_journal_dir)) if journal_dir is None: logger.debug('journal_dir was None, setting ""') diff --git a/outfitting.py b/outfitting.py index 1670f06b..11249a1c 100644 --- a/outfitting.py +++ b/outfitting.py @@ -509,7 +509,7 @@ def lookup(module, ship_map, entitled=False): def export(data, filename): - querytime = config.get_int('querytime') or int(time.time()) + querytime = config.get_int('querytime', default=int(time.time())) assert data['lastSystem'].get('name') assert data['lastStarport'].get('name') diff --git a/plugins/eddn.py b/plugins/eddn.py index 8faed4fd..cbaab84c 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -728,7 +728,7 @@ def journal_entry( # noqa: C901 this.commodities = this.outfitting = this.shipyard = None this.marketId = entry['MarketID'] - path = pathlib.Path(str(config.get_str('journaldir') or config.default_journal_dir)) / f'{entry["event"]}.json' + path = pathlib.Path(config.get_str('journaldir', str(config.default_journal_dir))) / f'{entry["event"]}.json' with path.open('rb') as f: entry = json.load(f) if entry['event'] == 'Market': diff --git a/plugins/edsm.py b/plugins/edsm.py index 1fd43a60..751b0884 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -131,8 +131,8 @@ def plugin_start3(plugin_dir: str) -> str: elif config.get_list('edsm_cmdrname'): # Migrate <= 2.25 settings. edsm_cmdrs is unknown at this time - config.set('edsm_usernames', [config.get_str('edsm_cmdrname') or '']) - config.set('edsm_apikeys', [config.get_str('edsm_apikey') or '']) + config.set('edsm_usernames', [config.get_str('edsm_cmdrname', default='')]) + config.set('edsm_apikeys', [config.get_str('edsm_apikey', default='')]) config.delete('edsm_cmdrname') config.delete('edsm_apikey') @@ -289,9 +289,9 @@ def prefs_changed(cmdr: str, is_beta: bool) -> None: if cmdr and not is_beta: # TODO: remove this when config is rewritten. - cmdrs: List[str] = config.get_list('edsm_cmdrs', []) - usernames: List[str] = config.get_list('edsm_usernames', []) - apikeys: List[str] = config.get_list('edsm_apikeys', []) + cmdrs: List[str] = config.get_list('edsm_cmdrs', default=[]) + usernames: List[str] = config.get_list('edsm_usernames', default=[]) + apikeys: List[str] = config.get_list('edsm_apikeys', default=[]) if cmdr in cmdrs: idx = cmdrs.index(cmdr) diff --git a/plugins/inara.py b/plugins/inara.py index 92d3d661..0db096c0 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -277,8 +277,8 @@ def prefs_changed(cmdr: str, is_beta: bool) -> None: if cmdr and not is_beta: this.cmdr = cmdr this.FID = None - cmdrs = config.get_list('inara_cmdrs', []) - apikeys = config.get_list('inara_apikeys', []) + cmdrs = config.get_list('inara_cmdrs', default=[]) + apikeys = config.get_list('inara_apikeys', default=[]) if cmdr in cmdrs: idx = cmdrs.index(cmdr) apikeys.extend([''] * (1 + idx - len(apikeys))) @@ -309,7 +309,7 @@ def credentials(cmdr: str) -> Optional[str]: if not cmdr: return None - cmdrs = config.get_list('inara_cmdrs', []) + cmdrs = config.get_list('inara_cmdrs', default=[]) if cmdr in cmdrs and config.get_list('inara_apikeys'): return config.get_list('inara_apikeys')[cmdrs.index(cmdr)] diff --git a/prefs.py b/prefs.py index 7bfb697c..2f7b3854 100644 --- a/prefs.py +++ b/prefs.py @@ -195,14 +195,15 @@ elif platform == 'win32': pass # https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115 - BIF_RETURNONLYFSDIRS = 0x00000001 - BIF_USENEWUI = 0x00000050 - BFFM_INITIALIZED = 1 - BFFM_SETSELECTION = 0x00000467 + BIF_RETURNONLYFSDIRS = 0x00000001 + BIF_USENEWUI = 0x00000050 + BFFM_INITIALIZED = 1 + BFFM_SETSELECTION = 0x00000467 BrowseCallbackProc = ctypes.WINFUNCTYPE(ctypes.c_int, HWND, ctypes.c_uint, LPARAM, LPARAM) class BROWSEINFO(ctypes.Structure): - _fields_ = [("hwndOwner", HWND), ("pidlRoot", LPVOID), ("pszDisplayName", LPWSTR), ("lpszTitle", LPCWSTR), ("ulFlags", UINT), ("lpfn", BrowseCallbackProc), ("lParam", LPCWSTR), ("iImage", ctypes.c_int)] + _fields_ = [("hwndOwner", HWND), ("pidlRoot", LPVOID), ("pszDisplayName", LPWSTR), ("lpszTitle", LPCWSTR), + ("ulFlags", UINT), ("lpfn", BrowseCallbackProc), ("lParam", LPCWSTR), ("iImage", ctypes.c_int)] CalculatePopupWindowPosition = None if not is_wine: @@ -407,7 +408,8 @@ class PreferencesDialog(tk.Toplevel): row = AutoInc(start=1) self.logdir = tk.StringVar() - self.logdir.set(str(config.get_str('journaldir') or config.default_journal_dir or '')) + default = str(config.default_journal_dir) if config.default_journal_dir is not None else '' + self.logdir.set(str(config.get_str('journaldir', default=default))) self.logdir_entry = nb.Entry(config_frame, takefocus=False) # Location of the new Journal file in E:D 2.2 @@ -532,7 +534,7 @@ class PreferencesDialog(tk.Toplevel): self.shipyard_provider = tk.StringVar( value=str( config.get_str('shipyard_provider') in plug.provides('shipyard_url') - and config.get_str('shipyard_provider', 'EDSY')) + and config.get_str('shipyard_provider', default='EDSY')) ) # Setting to decide which ship outfitting website to link to - either E:D Shipyard or Coriolis nb.Label(config_frame, text=_('Shipyard')).grid(padx=self.PADX, pady=2*self.PADY, sticky=tk.W, row=cur_row) @@ -628,7 +630,7 @@ class PreferencesDialog(tk.Toplevel): def __setup_appearance_tab(self, notebook: Notebook) -> None: self.languages = Translations.available_names() # Appearance theme and language setting - self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default'))) + self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), default=_('Default'))) self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) self.theme = tk.IntVar(value=config.get_int('theme')) self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')] @@ -1113,7 +1115,7 @@ class PreferencesDialog(tk.Toplevel): lang_codes = {v: k for k, v in self.languages.items()} # Codes by name config.set('language', lang_codes.get(self.lang.get()) or '') # or '' used here due to Default being None above - Translations.install(config.get_str('language') or None) # type: ignore # This sets self in weird ways. + Translations.install(config.get_str('language', default=None)) # type: ignore # This sets self in weird ways. config.set('ui_scale', self.ui_scale.get()) config.set('always_ontop', self.always_ontop.get()) diff --git a/shipyard.py b/shipyard.py index ba25a55c..6659ab99 100644 --- a/shipyard.py +++ b/shipyard.py @@ -8,7 +8,7 @@ from config import config def export(data, filename): - querytime = config.get_int('querytime', int(time.time())) + querytime = config.get_int('querytime', default=int(time.time())) assert data['lastSystem'].get('name') assert data['lastStarport'].get('name') diff --git a/td.py b/td.py index 956371e2..799d68ec 100644 --- a/td.py +++ b/td.py @@ -22,7 +22,7 @@ stockbracketmap = { 0: '-', def export(data): - querytime = config.get_int('querytime', int(time.time())) + querytime = config.get_int('querytime', default=int(time.time())) filename = join(config.get_str('outdir'), '%s.%s.%s.prices' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))) From a68468d7cedd8be02e8f2629de988bc6a13db6ef Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 06:22:40 +0200 Subject: [PATCH 172/727] Updated wording in plugins docs --- PLUGINS.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 3ec5751c..7fe3e390 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -220,8 +220,9 @@ title will be the value that you returned from `plugin_start3`. Use widgets from EDMC's myNotebook.py for the correct look-and-feel. You can be notified when the settings dialog is closed so you can save your settings. -You can use `set()` and `get_$type()` (where type is one of: `int`, `bool`, `str`, `list`) from EDMC's -`config.config` object to retrieve your plugin's settings in a platform-independent way. +You can use `set()` and `get_$type()` (where type is one of: `int`, `bool`, `str`, `list`) from EDMC's +`config.config` object to retrieve your plugin's settings in a platform-independent way. Previously this was done with +a single set and two get methods, the new methods provide better type safety. **Be sure to use a unique prefix for any settings you save so as not to clash with core EDMC or other plugins.** From bfe114ba106b7937886a71f15cbac6b2c3376a0b Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 06:26:04 +0200 Subject: [PATCH 173/727] Removed extranious parens --- EDMarketConnector.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 60dd0733..fe18cdcd 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -532,13 +532,13 @@ class AppWindow(object): self.menubar.add_cascade(menu=self.help_menu) if platform == 'win32': # Must be added after at least one "real" menu entry - self.always_ontop = tk.BooleanVar(value=config.get_int('always_ontop'))) - self.system_menu=tk.Menu(self.menubar, name = 'system', tearoff = tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.always_ontop = tk.BooleanVar(value=config.get_bool('always_ontop')) + self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system_menu.add_separator() - self.system_menu.add_checkbutton(label = _('Always on top'), - variable = self.always_ontop, - command = self.ontop_changed) # Appearance setting - self.menubar.add_cascade(menu = self.system_menu) + self.system_menu.add_checkbutton(label=_('Always on top'), + variable=self.always_ontop, + command=self.ontop_changed) # Appearance setting + self.menubar.add_cascade(menu=self.system_menu) self.w.bind('', self.copy) self.w.protocol("WM_DELETE_WINDOW", self.onexit) theme.register(self.menubar) # menus and children aren't automatically registered @@ -547,9 +547,9 @@ class AppWindow(object): theme.register(self.help_menu) # Alternate title bar and menu for dark theme - self.theme_menubar=tk.Frame(frame) - self.theme_menubar.columnconfigure(2, weight = 1) - theme_titlebar=tk.Label(self.theme_menubar, text = applongname, + self.theme_menubar = tk.Frame(frame) + self.theme_menubar.columnconfigure(2, weight=1) + theme_titlebar = tk.Label(self.theme_menubar, text=applongname, image=self.theme_icon, cursor='fleur', anchor=tk.W, compound=tk.LEFT) theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW) @@ -612,6 +612,7 @@ class AppWindow(object): self.w.geometry(config.get_str('geometry')) else: self.w.geometry(config.get_str('geometry')) + self.w.attributes('-topmost', config.get_int('always_ontop') and 1 or 0) theme.register(frame) From a1576e9979990d5488ad6d8cda2fb1bde5cba30a Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 06:40:25 +0200 Subject: [PATCH 174/727] Fixed missing default keyword arg --- EDMarketConnector.py | 2 +- plugins/eddn.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index fe18cdcd..cbd68902 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1135,7 +1135,7 @@ class AppWindow(object): return plug.invoke(config.get_str('shipyard_provider'), 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) # Avoid file length limits if possible - provider = config.get_str('shipyard_provider', 'EDSY') + provider = config.get_str('shipyard_provider', default='EDSY') target = plug.invoke(provider, 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) file_name = join(config.app_dir, "last_shipyard.html") diff --git a/plugins/eddn.py b/plugins/eddn.py index cbaab84c..b3d51cd3 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -728,7 +728,8 @@ def journal_entry( # noqa: C901 this.commodities = this.outfitting = this.shipyard = None this.marketId = entry['MarketID'] - path = pathlib.Path(config.get_str('journaldir', str(config.default_journal_dir))) / f'{entry["event"]}.json' + path = pathlib.Path(config.get_str('journaldir', default=str( + config.default_journal_dir))) / f'{entry["event"]}.json' with path.open('rb') as f: entry = json.load(f) if entry['event'] == 'Market': From e50c1ec93673d750af63fcd399b4c1aa7050097b Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 12:23:25 +0200 Subject: [PATCH 175/727] Defaults on get_ functions now require kwargs --- config.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/config.py b/config.py index deef56c6..e64dbe88 100644 --- a/config.py +++ b/config.py @@ -158,7 +158,7 @@ class AbstractConfig(abc.ABC): return default # type: ignore @abstractmethod - def get_list(self, key: str, default: list = None) -> list: + def get_list(self, key: str, *, default: list = None) -> list: """ Get the list referred to by the given key if it exists, or the default. @@ -171,7 +171,7 @@ class AbstractConfig(abc.ABC): raise NotImplementedError @abstractmethod - def get_str(self, key: str, default: str = None) -> str: + def get_str(self, key: str, *, default: str = None) -> str: """ Get the string referred to by the given key if it exists, or the default. @@ -184,7 +184,7 @@ class AbstractConfig(abc.ABC): raise NotImplementedError @abstractmethod - def get_bool(self, key: str, default: bool = None) -> bool: + def get_bool(self, key: str, *, default: bool = None) -> bool: """ Get the bool referred to by the given key if it exists, or the default. @@ -196,7 +196,7 @@ class AbstractConfig(abc.ABC): """ raise NotImplementedError - def getint(self, key: str, default: int = 0) -> int: + def getint(self, key: str, *, default: int = 0) -> int: """ Getint is a Deprecated getter method. @@ -207,7 +207,7 @@ class AbstractConfig(abc.ABC): return self.get_int(key, default) @abstractmethod - def get_int(self, key: str, default: int = 0) -> int: + def get_int(self, key: str, *, default: int = 0) -> int: """ Get the int referred to by key if it exists in the config. @@ -365,7 +365,7 @@ class WinConfig(AbstractConfig): logger.warning(f'registry key {key=} returned unknown type {_type=} {value=}') return None - def get_str(self, key: str, default: str = None) -> str: + def get_str(self, key: str, *, default: str = None) -> str: """ Return the string represented by the key, or the default if it does not exist. @@ -383,7 +383,7 @@ class WinConfig(AbstractConfig): return res - def get_list(self, key: str, default: list = None) -> list: + def get_list(self, key: str, *, default: list = None) -> list: """ Return the list found at the given key, or the default if none exists. @@ -401,7 +401,7 @@ class WinConfig(AbstractConfig): return res - def get_int(self, key: str, default: int = 0) -> int: + def get_int(self, key: str, *, default: int = 0) -> int: """ Return the int found at the given key, or the default if none exists. @@ -419,7 +419,7 @@ class WinConfig(AbstractConfig): return res - def get_bool(self, key: str, default: bool = None) -> bool: + def get_bool(self, key: str, *, default: bool = None) -> bool: """ Return the bool found at the given key, or the default if none exists. @@ -526,7 +526,7 @@ class MacConfig(AbstractConfig): return res - def get_str(self, key: str, default: str = None) -> str: + def get_str(self, key: str, *, default: str = None) -> str: """ Return the string represented by the key, or the default if it does not exist. @@ -544,7 +544,7 @@ class MacConfig(AbstractConfig): return res - def get_list(self, key: str, default: list = None) -> list: + def get_list(self, key: str, *, default: list = None) -> list: """ Return the list found at the given key, or the default if none exists. @@ -562,7 +562,7 @@ class MacConfig(AbstractConfig): return res - def get_int(self, key: str, default: int = 0) -> int: + def get_int(self, key: str, *, default: int = 0) -> int: """ Return the int found at the given key, or the default if none exists. @@ -585,7 +585,7 @@ class MacConfig(AbstractConfig): logger.error(f'__raw_get returned {res!r} which cannot be parsed to an int: {e}') return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default - def get_bool(self, key: str, default: bool = None) -> bool: + def get_bool(self, key: str, *, default: bool = None) -> bool: res = self.__raw_get(key) if res is None: return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default @@ -711,7 +711,7 @@ class LinuxConfig(AbstractConfig): return self.config[self.SECTION].get(key) - def get_str(self, key: str, default: str = None) -> str: + def get_str(self, key: str, *, default: str = None) -> str: data = self.__raw_get(key) if data is None: return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default @@ -721,7 +721,7 @@ class LinuxConfig(AbstractConfig): return self.__unescape(data) - def get_list(self, key: str, default: list = None) -> list: + def get_list(self, key: str, *, default: list = None) -> list: data = self.__raw_get(key) if data is None: @@ -733,7 +733,7 @@ class LinuxConfig(AbstractConfig): return list(map(self.__unescape, split[:-1])) - def get_int(self, key: str, default: int = 0) -> int: + def get_int(self, key: str, *, default: int = 0) -> int: data = self.__raw_get(key) if data is None: @@ -745,7 +745,7 @@ class LinuxConfig(AbstractConfig): except ValueError as e: raise ValueError(f'requested {key=} as int cannot be converted to int') from e - def get_bool(self, key: str, default: bool = None) -> bool: + def get_bool(self, key: str, *, default: bool = None) -> bool: if self.config is None: raise ValueError('attempt to use a closed config') From fad193eff19631c25fe4ea3399f999a51521741f Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 12:24:11 +0200 Subject: [PATCH 176/727] Added clarifying comment --- config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.py b/config.py index e64dbe88..c5684988 100644 --- a/config.py +++ b/config.py @@ -36,6 +36,8 @@ copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' update_interval = 8*60*60 +# This must be done here in order to avoid an import cycle with EDMCLogging. +# Other code should use EDMCLogging.get_main_logger if os.getenv("EDMC_NO_UI"): logger = logging.getLogger(appcmdname) From 42a0c058ea3cdab60d20821e6865c190d36fc652 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 12:24:56 +0200 Subject: [PATCH 177/727] Fixed bool usage --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index cbd68902..f35882bb 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -532,7 +532,7 @@ class AppWindow(object): self.menubar.add_cascade(menu=self.help_menu) if platform == 'win32': # Must be added after at least one "real" menu entry - self.always_ontop = tk.BooleanVar(value=config.get_bool('always_ontop')) + self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 self.system_menu.add_separator() self.system_menu.add_checkbutton(label=_('Always on top'), From a6f3d4a382646551b5313e4b5ae5ac460d01b6da Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 12:51:03 +0200 Subject: [PATCH 178/727] Added optional exception handler --- config.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/config.py b/config.py index c5684988..3d39dec0 100644 --- a/config.py +++ b/config.py @@ -229,7 +229,7 @@ class AbstractConfig(abc.ABC): raise NotImplementedError @abstractmethod - def delete(self, key: str) -> None: + def delete(self, key: str, *, suppress=False) -> None: """ Delete the given key from the config. @@ -466,8 +466,14 @@ class WinConfig(AbstractConfig): # Its complaining about the list, it works, tested on windows, ignored. winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore - def delete(self, key: str) -> None: - winreg.DeleteValue(self.__reg_handle, key) + def delete(self, key: str, *, suppress=False) -> None: + try: + winreg.DeleteValue(self.__reg_handle, key) + except OSError: + if suppress: + return + + raise def save(self) -> None: """Save the configuration.""" @@ -606,7 +612,7 @@ class MacConfig(AbstractConfig): """ self._settings[key] = val - def delete(self, key: str) -> None: + def delete(self, key: str, *, suppress=False) -> None: """ Delete the given key from the config. @@ -779,7 +785,7 @@ class LinuxConfig(AbstractConfig): self.config.set(self.SECTION, key, to_set) - def delete(self, key: str) -> None: + def delete(self, key: str, *, suppress=False) -> None: if self.config is None: raise ValueError('attempt to use a closed config') From 87df8d8ab8a724c4b7b9a027e7a2bd5e1a819073 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 12:55:47 +0200 Subject: [PATCH 179/727] suppressed exceptions in migration code --- plugins/coriolis.py | 2 +- plugins/edsm.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/coriolis.py b/plugins/coriolis.py index 36ccde27..89504173 100644 --- a/plugins/coriolis.py +++ b/plugins/coriolis.py @@ -11,7 +11,7 @@ from config import config if not config.get_str('shipyard_provider') and config.get_int('shipyard'): config.set('shipyard_provider', 'Coriolis') -config.delete('shipyard') +config.delete('shipyard', suppress=True) def plugin_start3(_): diff --git a/plugins/edsm.py b/plugins/edsm.py index 751b0884..566f910b 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -134,15 +134,15 @@ def plugin_start3(plugin_dir: str) -> str: config.set('edsm_usernames', [config.get_str('edsm_cmdrname', default='')]) config.set('edsm_apikeys', [config.get_str('edsm_apikey', default='')]) - config.delete('edsm_cmdrname') - config.delete('edsm_apikey') + config.delete('edsm_cmdrname', suppress=True) + config.delete('edsm_apikey', suppress=True) if config.get_int('output') & 256: # Migrate <= 2.34 setting config.set('edsm_out', 1) - config.delete('edsm_autoopen') - config.delete('edsm_historical') + config.delete('edsm_autoopen', suppress=True) + config.delete('edsm_historical', suppress=True) logger.debug('Starting worker thread...') this.thread = Thread(target=worker, name='EDSM worker') From 59c14e604606532576c73a3070eb1e7bdfd1e926 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 13:07:23 +0200 Subject: [PATCH 180/727] Suppressed exceptions in EDMarketConnector.py --- EDMarketConnector.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index f35882bb..4f582e9f 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -648,10 +648,10 @@ class AppWindow(object): # Migration from <= 3.30 for username in config.get_list('fdev_usernames', default=[]): config.delete_password(username) - config.delete('fdev_usernames') - config.delete('username') - config.delete('password') - config.delete('logdir') + config.delete('fdev_usernames', suppress=True) + config.delete('username', suppress=True) + config.delete('password', suppress=True) + config.delete('logdir', suppress=True) self.postprefs(False) # Companion login happens in callback from monitor From d95db448e8bbb9948f1ad929f1aa4736cb25a66f Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 13:12:34 +0200 Subject: [PATCH 181/727] Fixed getint not passing default arg --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 3d39dec0..3652ddeb 100644 --- a/config.py +++ b/config.py @@ -206,7 +206,7 @@ class AbstractConfig(abc.ABC): :raises OSError: on windows, if a registry error occurs. """ warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead')) - return self.get_int(key, default) + return self.get_int(key, default=default) @abstractmethod def get_int(self, key: str, *, default: int = 0) -> int: From 48427a770d6333d97266bcb823f22e662252bb63 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 13:32:30 +0200 Subject: [PATCH 182/727] Updated monitor to support '' configured journal dir --- monitor.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/monitor.py b/monitor.py index d602d05a..793789f9 100644 --- a/monitor.py +++ b/monitor.py @@ -129,11 +129,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below """Start journal monitoring.""" logger.debug('Begin...') self.root = root - journal_dir = config.get_str('journaldir', default=str(config.default_journal_dir)) + journal_dir = config.get_str('journaldir') - if journal_dir is None: - logger.debug('journal_dir was None, setting ""') - journal_dir = '' + if journal_dir == '' or journal_dir is None: + journal_dir = str(config.default_journal_dir) # TODO(A_D): this is ignored for type checking due to all the different types config.get returns # When that is refactored, remove the magic comment From 1b7ad1f7e956f8b5225222de9c2cf380257814f3 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 13:32:48 +0200 Subject: [PATCH 183/727] un-optionaled config.default_journal_dir --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 3652ddeb..362cb266 100644 --- a/config.py +++ b/config.py @@ -112,7 +112,7 @@ class AbstractConfig(abc.ABC): internal_plugin_dir: pathlib.Path respath: pathlib.Path home: pathlib.Path - default_journal_dir: Optional[pathlib.Path] + default_journal_dir: pathlib.Path identifier: str From e3def21683afabf653112b8ffca1eedada5426f7 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 14:31:46 +0200 Subject: [PATCH 184/727] Made sure to handle an empty journal dir in the config --- EDMC.py | 3 +++ dashboard.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/EDMC.py b/EDMC.py index b684a8ae..849c9a98 100755 --- a/EDMC.py +++ b/EDMC.py @@ -190,6 +190,9 @@ sys.path: {sys.path}''' logger.debug('Getting state from latest journal file') try: logdir = config.get_str('journaldir', default=str(config.default_journal_dir)) + if not logdir: + logdir = str(config.default_journal_dir) + logger.debug(f'logdir = "{logdir}"') logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)), key=lambda x: x.split('.')[1:]) diff --git a/dashboard.py b/dashboard.py index 372cdf01..d0ef8575 100644 --- a/dashboard.py +++ b/dashboard.py @@ -42,6 +42,9 @@ class Dashboard(FileSystemEventHandler): self.session_start = started logdir = config.get_str('journaldir', default=str(config.default_journal_dir)) + if logdir == '': + logdir = str(config.default_journal_dir) + if not logdir or not isdir(logdir): logger.info(f"No logdir, or it isn't a directory: {logdir=}") self.stop() From 1e56f0046e2c3a689d3ccc90e2b5594bf3b04444 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 24 Dec 2020 15:15:05 +0200 Subject: [PATCH 185/727] Empty journal dir workaround --- plugins/eddn.py | 8 ++++++-- prefs.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index b3d51cd3..b19227cf 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -728,8 +728,12 @@ def journal_entry( # noqa: C901 this.commodities = this.outfitting = this.shipyard = None this.marketId = entry['MarketID'] - path = pathlib.Path(config.get_str('journaldir', default=str( - config.default_journal_dir))) / f'{entry["event"]}.json' + journaldir = config.get_str('journaldir') + if journaldir is None or journaldir == '': + journaldir = str(config.default_journal_dir) + + path = pathlib.Path(journaldir) / f'{entry["event"]}.json' + with path.open('rb') as f: entry = json.load(f) if entry['event'] == 'Market': diff --git a/prefs.py b/prefs.py index 2f7b3854..4a84fa5f 100644 --- a/prefs.py +++ b/prefs.py @@ -409,7 +409,11 @@ class PreferencesDialog(tk.Toplevel): self.logdir = tk.StringVar() default = str(config.default_journal_dir) if config.default_journal_dir is not None else '' - self.logdir.set(str(config.get_str('journaldir', default=default))) + logdir = config.get_str('journaldir') + if logdir is None or logdir == '': + logdir = default + + self.logdir.set(logdir) self.logdir_entry = nb.Entry(config_frame, takefocus=False) # Location of the new Journal file in E:D 2.2 From 47353cca3895c74aec1c68a002b77a3109130ffb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Dec 2020 06:26:44 +0000 Subject: [PATCH 186/727] Bump pytest from 6.1.2 to 6.2.1 Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.1.2 to 6.2.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.1.2...6.2.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index c73ff026..63f5bbd0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,7 +26,7 @@ grip==4.5.2 py2exe==0.10.1.0; sys_platform == 'win32' # Testing -pytest==6.1.2 +pytest==6.2.1 pytest-cov==2.10.1 # Pytest code coverage support coverage[toml]==5.3 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs From 09b9404307dc6253b8603f0608bef9aabf72d3c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Dec 2020 09:13:22 +0000 Subject: [PATCH 187/727] Bump coverage[toml] from 5.3 to 5.3.1 Bumps [coverage[toml]](https://github.com/nedbat/coveragepy) from 5.3 to 5.3.1. - [Release notes](https://github.com/nedbat/coveragepy/releases) - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst) - [Commits](https://github.com/nedbat/coveragepy/compare/coverage-5.3...coverage-5.3.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 63f5bbd0..2fdfe0c1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -28,7 +28,7 @@ py2exe==0.10.1.0; sys_platform == 'win32' # Testing pytest==6.2.1 pytest-cov==2.10.1 # Pytest code coverage support -coverage[toml]==5.3 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +coverage[toml]==5.3.1 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs # All of the normal requirements From e7ece1ea52f2813a13626751e45811835bb1485c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 31 Dec 2020 05:54:06 +0000 Subject: [PATCH 188/727] Bump isort from 5.6.4 to 5.7.0 Bumps [isort](https://github.com/pycqa/isort) from 5.6.4 to 5.7.0. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.6.4...5.7.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 2fdfe0c1..1d62ff99 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ flake8-annotations-coverage==0.0.4 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.3.1 flake8-docstrings==1.5.0 -isort==5.6.4 +isort==5.7.0 flake8-isort==4.0.0 flake8-json==20.12.1 flake8-noqa==1.0.5 From 374d96e767c5b309992f7e72dc02e15aee454a52 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 30 Dec 2020 20:58:52 +0200 Subject: [PATCH 189/727] Fixed unquoted LoggerMixin cast --- EDMCLogging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 068d7225..171907ba 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -469,7 +469,7 @@ def get_main_logger() -> 'LoggerMixin': return cast('LoggerMixin', logging.getLogger(appname)) else: # Must be the CLI - return cast(LoggerMixin, logging.getLogger(appcmdname)) + return cast('LoggerMixin', logging.getLogger(appcmdname)) # Singleton From 42834e583c510f420a8bee676eb8e059961f8799 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Jan 2021 07:29:07 +0000 Subject: [PATCH 190/727] Bump safety from 1.10.0 to 1.10.1 Bumps [safety](https://github.com/pyupio/safety) from 1.10.0 to 1.10.1. - [Release notes](https://github.com/pyupio/safety/releases) - [Changelog](https://github.com/pyupio/safety/blob/master/HISTORY.rst) - [Commits](https://github.com/pyupio/safety/compare/1.10.0...1.10.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 1d62ff99..70d01a85 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,7 +13,7 @@ flake8-use-fstring==1.1 mypy==0.790 pep8-naming==0.11.1 -safety==1.10.0 +safety==1.10.1 # Code formatting tools autopep8==1.5.4 From b80c51bf78499e38b6b1a7b61832c5586a6b7613 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 11:10:25 +0200 Subject: [PATCH 191/727] auto-formatted code --- l10n.py | 58 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/l10n.py b/l10n.py index 7a181f8d..bab9f038 100755 --- a/l10n.py +++ b/l10n.py @@ -3,18 +3,18 @@ # Localization with gettext is a pain on non-Unix systems. Use OSX-style strings files instead. # +import builtins import codecs -from collections import OrderedDict +import locale import numbers import os -from os.path import basename, dirname, exists, isfile, isdir, join, normpath import re import sys +from collections import OrderedDict +from os.path import basename, dirname, exists, isdir, isfile, join, normpath from sys import platform from traceback import print_exc -import builtins -import locale try: locale.setlocale(locale.LC_ALL, '') except: @@ -39,7 +39,7 @@ elif platform == 'win32': MUI_LANGUAGE_ID = 4 MUI_LANGUAGE_NAME = 8 GetUserPreferredUILanguages = ctypes.windll.kernel32.GetUserPreferredUILanguages - GetUserPreferredUILanguages.argtypes = [ DWORD, ctypes.POINTER(ctypes.c_ulong), LPCVOID, ctypes.POINTER(ctypes.c_ulong) ] + GetUserPreferredUILanguages.argtypes = [DWORD, ctypes.POINTER(ctypes.c_ulong), LPCVOID, ctypes.POINTER(ctypes.c_ulong)] GetUserPreferredUILanguages.restype = BOOL LOCALE_NAME_USER_DEFAULT = None @@ -50,20 +50,20 @@ elif platform == 'win32': class Translations(object): - FALLBACK = 'en' # strings in this code are in English + FALLBACK = 'en' # strings in this code are in English FALLBACK_NAME = 'English' - TRANS_RE = re.compile(r'\s*"((?:[^"]|(?:\"))+)"\s*=\s*"((?:[^"]|(?:\"))+)"\s*;\s*$') + TRANS_RE = re.compile(r'\s*"((?:[^"]|(?:\"))+)"\s*=\s*"((?:[^"]|(?:\"))+)"\s*;\s*$') COMMENT_RE = re.compile(r'\s*/\*.*\*/\s*$') - def __init__(self): - self.translations = { None: {} } + self.translations = {None: {}} def install_dummy(self): # For when translation is not desired or not available - self.translations = { None: {} } - builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') # Promote strings to Unicode for consistency + self.translations = {None: {}} + builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace( + u'{CR}', u'\n') # Promote strings to Unicode for consistency def install(self, lang=None): available = self.available() @@ -76,16 +76,16 @@ class Translations(object): if preferred in available: lang = preferred elif '-'.join(components[0:2]) in available: - lang = '-'.join(components[0:2]) # language-script + lang = '-'.join(components[0:2]) # language-script elif components[0] in available: - lang = components[0] # just base language + lang = components[0] # just base language if lang: break if lang not in self.available(): self.install_dummy() else: - self.translations = { None: self.contents(lang) } + self.translations = {None: self.contents(lang)} for plugin in os.listdir(config.plugin_dir): plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) if isdir(plugin_path): @@ -112,7 +112,7 @@ class Translations(object): elif __debug__ and not Translations.COMMENT_RE.match(line): print('Bad translation: %s' % line.strip()) if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: - translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing + translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing return translations def translate(self, x, context=None): @@ -131,7 +131,7 @@ class Translations(object): # Returns list of available language codes def available(self): path = self.respath() - if getattr(sys, 'frozen', False) and platform=='darwin': + if getattr(sys, 'frozen', False) and platform == 'darwin': available = set([x[:-len('.lproj')] for x in os.listdir(path) if x.endswith('.lproj') and isfile(join(x, 'Localizable.strings'))]) else: available = set([x[:-len('.strings')] for x in os.listdir(path) if x.endswith('.strings')]) @@ -140,16 +140,16 @@ class Translations(object): # Available language names by code def available_names(self): names = OrderedDict([ - (None, _('Default')), # Appearance theme and language setting + (None, _('Default')), # Appearance theme and language setting ]) names.update(sorted([(lang, self.contents(lang).get(LANGUAGE_ID, lang)) for lang in self.available()] + [(Translations.FALLBACK, Translations.FALLBACK_NAME)], - key=lambda x: x[1])) # Sort by name + key=lambda x: x[1])) # Sort by name return names def respath(self): if getattr(sys, 'frozen', False): - if platform=='darwin': + if platform == 'darwin': return normpath(join(dirname(sys.executable), os.pardir, 'Resources')) else: return join(dirname(sys.executable), LOCALISATION_DIR) @@ -167,7 +167,7 @@ class Translations(object): except: print_exc() return None - elif getattr(sys, 'frozen', False) and platform=='darwin': + elif getattr(sys, 'frozen', False) and platform == 'darwin': return codecs.open(join(self.respath(), '%s.lproj' % lang, 'Localizable.strings'), 'r', 'utf-16') else: return codecs.open(join(self.respath(), '%s.strings' % lang), 'r', 'utf-8') @@ -176,7 +176,7 @@ class Translations(object): class Locale(object): def __init__(self): - if platform=='darwin': + if platform == 'darwin': self.int_formatter = NSNumberFormatter.alloc().init() self.int_formatter.setNumberStyle_(NSNumberFormatterDecimalStyle) self.float_formatter = NSNumberFormatter.alloc().init() @@ -206,7 +206,7 @@ class Locale(object): def numberFromString(self, string): # Uses the current system locale, irrespective of language choice. # Returns None if the string is not parsable, otherwise an integer or float. - if platform=='darwin': + if platform == 'darwin': return self.float_formatter.numberFromString_(string) else: try: @@ -222,10 +222,10 @@ class Locale(object): # script is a capitalized 4 alpha ISO 15924 code and region is an uppercase 2 alpha ISO 3166 code def preferredLanguages(self): - if platform=='darwin': + if platform == 'darwin': return NSLocale.preferredLanguages() - elif platform=='win32': + elif platform == 'win32': def wszarray_to_list(array): offset = 0 @@ -245,9 +245,10 @@ class Locale(object): return wszarray_to_list(buf) return [] - else: # POSIX + else: # POSIX lang = locale.getlocale()[0] - return lang and [lang.replace('_','-')] or [] + return lang and [lang.replace('_', '-')] or [] + # singletons Locale = Locale() @@ -258,7 +259,7 @@ Translations = Translations() # parsing is limited - only single ' or " delimited strings, and only one string per line if __name__ == "__main__": import re - regexp = re.compile(r'''_\([ur]?(['"])(((? Date: Mon, 26 Oct 2020 11:14:40 +0200 Subject: [PATCH 192/727] Fixed overlong lines --- l10n.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/l10n.py b/l10n.py index bab9f038..9b82e206 100755 --- a/l10n.py +++ b/l10n.py @@ -14,6 +14,10 @@ from collections import OrderedDict from os.path import basename, dirname, exists, isdir, isfile, join, normpath from sys import platform from traceback import print_exc +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + def _(x: str) -> str: ... try: locale.setlocale(locale.LC_ALL, '') @@ -39,7 +43,10 @@ elif platform == 'win32': MUI_LANGUAGE_ID = 4 MUI_LANGUAGE_NAME = 8 GetUserPreferredUILanguages = ctypes.windll.kernel32.GetUserPreferredUILanguages - GetUserPreferredUILanguages.argtypes = [DWORD, ctypes.POINTER(ctypes.c_ulong), LPCVOID, ctypes.POINTER(ctypes.c_ulong)] + GetUserPreferredUILanguages.argtypes = [ + DWORD, ctypes.POINTER(ctypes.c_ulong), LPCVOID, ctypes.POINTER(ctypes.c_ulong) + ] + GetUserPreferredUILanguages.restype = BOOL LOCALE_NAME_USER_DEFAULT = None @@ -108,7 +115,8 @@ class Translations(object): if line.strip(): match = Translations.TRANS_RE.match(line) if match: - translations[match.group(1).replace(r'\"', u'"')] = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') + to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') + translations[match.group(1).replace(r'\"', u'"')] = to_set elif __debug__ and not Translations.COMMENT_RE.match(line): print('Bad translation: %s' % line.strip()) if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: @@ -132,7 +140,10 @@ class Translations(object): def available(self): path = self.respath() if getattr(sys, 'frozen', False) and platform == 'darwin': - available = set([x[:-len('.lproj')] for x in os.listdir(path) if x.endswith('.lproj') and isfile(join(x, 'Localizable.strings'))]) + available = set([ + x[:-len('.lproj')] for x in os.listdir(path) + if x.endswith('.lproj') and isfile(join(x, 'Localizable.strings')) + ]) else: available = set([x[:-len('.strings')] for x in os.listdir(path) if x.endswith('.strings')]) return available @@ -239,9 +250,16 @@ class Locale(object): num = ctypes.c_ulong() size = ctypes.c_ulong(0) - if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), None, ctypes.byref(size)) and size.value): + if ( + GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), None, ctypes.byref(size)) + and size.value + ): buf = ctypes.create_unicode_buffer(size.value) - if GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), ctypes.byref(buf), ctypes.byref(size)): + if ( + GetUserPreferredUILanguages( + MUI_LANGUAGE_NAME, ctypes.byref(num), ctypes.byref(buf), ctypes.byref(size) + ) + ): return wszarray_to_list(buf) return [] @@ -262,14 +280,18 @@ if __name__ == "__main__": regexp = re.compile(r'''_\([ur]?(['"])(((? Date: Mon, 26 Oct 2020 11:18:42 +0200 Subject: [PATCH 193/727] Removed modulo formatters --- l10n.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/l10n.py b/l10n.py index 9b82e206..c1ad0552 100755 --- a/l10n.py +++ b/l10n.py @@ -99,7 +99,7 @@ class Translations(object): try: self.translations[plugin] = self.contents(lang, plugin_path) except UnicodeDecodeError as e: - print('Malformed file %s.strings in plugin %s: %s' % (lang, plugin, e)) + print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') except: print_exc() builtins.__dict__['_'] = self.translate @@ -118,7 +118,7 @@ class Translations(object): to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') translations[match.group(1).replace(r'\"', u'"')] = to_set elif __debug__ and not Translations.COMMENT_RE.match(line): - print('Bad translation: %s' % line.strip()) + print(f'Bad translation: {line.strip()}') if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing return translations @@ -128,12 +128,12 @@ class Translations(object): context = context[len(config.plugin_dir)+1:].split(os.sep)[0] if __debug__: if self.translations[None] and context not in self.translations: - print('No translations for "%s"' % context) + print(f'No translations for {context!r}') return self.translations.get(context, {}).get(x) or self.translate(x) else: if __debug__: if self.translations[None] and x not in self.translations[None]: - print('Missing translation: "%s"' % x) + print(f'Missing translation: {x!r}') return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') # Returns list of available language codes @@ -171,7 +171,7 @@ class Translations(object): def file(self, lang, plugin_path=None): if plugin_path: - f = join(plugin_path, '%s.strings' % lang) + f = join(plugin_path, f'{lang}.strings') if exists(f): try: return codecs.open(f, 'r', 'utf-8') @@ -179,9 +179,9 @@ class Translations(object): print_exc() return None elif getattr(sys, 'frozen', False) and platform == 'darwin': - return codecs.open(join(self.respath(), '%s.lproj' % lang, 'Localizable.strings'), 'r', 'utf-16') + return codecs.open(join(self.respath(), f'{lang}.lproj', 'Localizable.strings'), 'r', 'utf-16') else: - return codecs.open(join(self.respath(), '%s.strings' % lang), 'r', 'utf-8') + return codecs.open(join(self.respath(), f'{lang}.strings'), 'r', 'utf-8') class Locale(object): @@ -290,15 +290,15 @@ if __name__ == "__main__": match = regexp.search(line) if match and not seen.get(match.group(2)): # only record first commented instance of a string seen[match.group(2)] = ( - (match.group(4) and (match.group(4)[1:].strip()) + '. ' or '') + '[%s]' % basename(f) + (match.group(4) and (match.group(4)[1:].strip()) + '. ' or '') + f'[{basename(f)}]' ) if seen: if not isdir(LOCALISATION_DIR): os.mkdir(LOCALISATION_DIR) template = codecs.open(join(LOCALISATION_DIR, 'en.template'), 'w', 'utf-8') - template.write('/* Language name */\n"%s" = "%s";\n\n' % (LANGUAGE_ID, 'English')) + template.write(f'/* Language name */\n"{LANGUAGE_ID}" = "English";\n\n') for thing in sorted(seen, key=str.lower): if seen[thing]: - template.write('/* %s */\n' % (seen[thing])) - template.write('"%s" = "%s";\n\n' % (thing, thing)) + template.write(f'/* {seen[thing]} */\n') + template.write(f'"{thing}" = "{thing}";\n\n') template.close() From 3ba8be5bf7579346f82141d266eb7a6b0cca167e Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 11:22:17 +0200 Subject: [PATCH 194/727] Removed unneeded list comprehensions --- l10n.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/l10n.py b/l10n.py index c1ad0552..ecefd24e 100755 --- a/l10n.py +++ b/l10n.py @@ -140,12 +140,12 @@ class Translations(object): def available(self): path = self.respath() if getattr(sys, 'frozen', False) and platform == 'darwin': - available = set([ + available = { x[:-len('.lproj')] for x in os.listdir(path) if x.endswith('.lproj') and isfile(join(x, 'Localizable.strings')) - ]) + } else: - available = set([x[:-len('.strings')] for x in os.listdir(path) if x.endswith('.strings')]) + available = {x[:-len('.strings')] for x in os.listdir(path) if x.endswith('.strings')} return available # Available language names by code @@ -279,10 +279,11 @@ if __name__ == "__main__": import re regexp = re.compile(r'''_\([ur]?(['"])(((? Date: Mon, 26 Oct 2020 13:30:00 +0200 Subject: [PATCH 195/727] Removed bare excepts --- l10n.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/l10n.py b/l10n.py index ecefd24e..cbd00d9b 100755 --- a/l10n.py +++ b/l10n.py @@ -21,7 +21,7 @@ if TYPE_CHECKING: try: locale.setlocale(locale.LC_ALL, '') -except: +except Exception: # Locale env variables incorrect or locale package not installed/configured on Linux, mysterious reasons on Windows print("Can't set locale!") @@ -100,7 +100,7 @@ class Translations(object): self.translations[plugin] = self.contents(lang, plugin_path) except UnicodeDecodeError as e: print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') - except: + except Exception: print_exc() builtins.__dict__['_'] = self.translate @@ -175,7 +175,7 @@ class Translations(object): if exists(f): try: return codecs.open(f, 'r', 'utf-8') - except: + except Exception: print_exc() return None elif getattr(sys, 'frozen', False) and platform == 'darwin': @@ -220,12 +220,12 @@ class Locale(object): if platform == 'darwin': return self.float_formatter.numberFromString_(string) else: - try: + try: # TODO: This is awful. return locale.atoi(string) - except: + except Exception: try: return locale.atof(string) - except: + except Exception: return None # Returns list of preferred language codes in RFC4646 format i.e. "lang[-script][-region]" From 08bba395a9239128acf33be073241ec5250c29c1 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 13:30:34 +0200 Subject: [PATCH 196/727] Removed star import --- l10n.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/l10n.py b/l10n.py index cbd00d9b..7b6f8b29 100755 --- a/l10n.py +++ b/l10n.py @@ -37,7 +37,9 @@ if platform == 'darwin': elif platform == 'win32': import ctypes - from ctypes.wintypes import * + from ctypes.wintypes import BOOL, DWORD, LPCVOID, LPCWSTR, LPWSTR + if TYPE_CHECKING: + import ctypes.windll # type: ignore # Magic to make linters not complain that windll is special # https://msdn.microsoft.com/en-us/library/windows/desktop/dd318124%28v=vs.85%29.aspx MUI_LANGUAGE_ID = 4 From 20eee4c6c12208f3b3647b16cc32a68ef7fd4f96 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 13:32:42 +0200 Subject: [PATCH 197/727] Cleaned up multiline statement --- l10n.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/l10n.py b/l10n.py index 7b6f8b29..4f2e32cd 100755 --- a/l10n.py +++ b/l10n.py @@ -155,9 +155,11 @@ class Translations(object): names = OrderedDict([ (None, _('Default')), # Appearance theme and language setting ]) - names.update(sorted([(lang, self.contents(lang).get(LANGUAGE_ID, lang)) for lang in self.available()] + - [(Translations.FALLBACK, Translations.FALLBACK_NAME)], - key=lambda x: x[1])) # Sort by name + names.update(sorted( + [(lang, self.contents(lang).get(LANGUAGE_ID, lang)) for lang in self.available()] + # type: ignore + [(Translations.FALLBACK, Translations.FALLBACK_NAME)], + key=lambda x: x[1] + )) # Sort by name return names def respath(self): From d9f91cf9dc656102847f5efad46a95e677e24b97 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 13:43:59 +0200 Subject: [PATCH 198/727] Added whitespace around scope changes --- l10n.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/l10n.py b/l10n.py index 4f2e32cd..bc9384b8 100755 --- a/l10n.py +++ b/l10n.py @@ -21,6 +21,7 @@ if TYPE_CHECKING: try: locale.setlocale(locale.LC_ALL, '') + except Exception: # Locale env variables incorrect or locale package not installed/configured on Linux, mysterious reasons on Windows print("Can't set locale!") @@ -33,7 +34,9 @@ LOCALISATION_DIR = 'L10n' if platform == 'darwin': - from Foundation import NSLocale, NSNumberFormatter, NSNumberFormatterDecimalStyle + from Foundation import ( # type: ignore # exists on Darwin + NSLocale, NSNumberFormatter, NSNumberFormatterDecimalStyle + ) elif platform == 'win32': import ctypes @@ -71,28 +74,31 @@ class Translations(object): def install_dummy(self): # For when translation is not desired or not available self.translations = {None: {}} - builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace( - u'{CR}', u'\n') # Promote strings to Unicode for consistency + # Promote strings to Unicode for consistency + builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') def install(self, lang=None): available = self.available() available.add(Translations.FALLBACK) - if not lang: # Choose the default language for preferred in Locale.preferredLanguages(): components = preferred.split('-') if preferred in available: lang = preferred + elif '-'.join(components[0:2]) in available: lang = '-'.join(components[0:2]) # language-script + elif components[0] in available: lang = components[0] # just base language + if lang: break if lang not in self.available(): self.install_dummy() + else: self.translations = {None: self.contents(lang)} for plugin in os.listdir(config.plugin_dir): @@ -100,10 +106,13 @@ class Translations(object): if isdir(plugin_path): try: self.translations[plugin] = self.contents(lang, plugin_path) + except UnicodeDecodeError as e: print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') + except Exception: print_exc() + builtins.__dict__['_'] = self.translate def contents(self, lang, plugin_path=None): @@ -112,6 +121,7 @@ class Translations(object): h = self.file(lang, plugin_path) if not h: return {} + else: for line in h: if line.strip(): @@ -119,10 +129,13 @@ class Translations(object): if match: to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') translations[match.group(1).replace(r'\"', u'"')] = to_set + elif __debug__ and not Translations.COMMENT_RE.match(line): print(f'Bad translation: {line.strip()}') + if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing + return translations def translate(self, x, context=None): @@ -131,11 +144,14 @@ class Translations(object): if __debug__: if self.translations[None] and context not in self.translations: print(f'No translations for {context!r}') + return self.translations.get(context, {}).get(x) or self.translate(x) + else: if __debug__: if self.translations[None] and x not in self.translations[None]: print(f'Missing translation: {x!r}') + return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') # Returns list of available language codes @@ -146,8 +162,10 @@ class Translations(object): x[:-len('.lproj')] for x in os.listdir(path) if x.endswith('.lproj') and isfile(join(x, 'Localizable.strings')) } + else: available = {x[:-len('.strings')] for x in os.listdir(path) if x.endswith('.strings')} + return available # Available language names by code @@ -160,16 +178,20 @@ class Translations(object): [(Translations.FALLBACK, Translations.FALLBACK_NAME)], key=lambda x: x[1] )) # Sort by name + return names def respath(self): if getattr(sys, 'frozen', False): if platform == 'darwin': return normpath(join(dirname(sys.executable), os.pardir, 'Resources')) + else: return join(dirname(sys.executable), LOCALISATION_DIR) + elif __file__: return join(dirname(__file__), LOCALISATION_DIR) + else: return LOCALISATION_DIR @@ -179,11 +201,15 @@ class Translations(object): if exists(f): try: return codecs.open(f, 'r', 'utf-8') + except Exception: print_exc() + return None + elif getattr(sys, 'frozen', False) and platform == 'darwin': return codecs.open(join(self.respath(), f'{lang}.lproj', 'Localizable.strings'), 'r', 'utf-16') + else: return codecs.open(join(self.respath(), f'{lang}.strings'), 'r', 'utf-8') @@ -205,16 +231,20 @@ class Locale(object): # places if the input is a float, or none if the input is an int. if decimals == 0 and not isinstance(number, numbers.Integral): number = int(round(number)) + if platform == 'darwin': if not decimals and isinstance(number, numbers.Integral): return self.int_formatter.stringFromNumber_(number) + else: self.float_formatter.setMinimumFractionDigits_(decimals or 5) self.float_formatter.setMaximumFractionDigits_(decimals or 5) return self.float_formatter.stringFromNumber_(number) + else: if not decimals and isinstance(number, numbers.Integral): return locale.format('%d', number, True) + else: return locale.format('%.*f', (decimals or 5, number), True) @@ -223,12 +253,15 @@ class Locale(object): # Returns None if the string is not parsable, otherwise an integer or float. if platform == 'darwin': return self.float_formatter.numberFromString_(string) + else: try: # TODO: This is awful. return locale.atoi(string) + except Exception: try: return locale.atof(string) + except Exception: return None @@ -249,6 +282,7 @@ class Locale(object): if sz: yield sz offset += len(sz)+1 + else: break @@ -265,6 +299,7 @@ class Locale(object): ) ): return wszarray_to_list(buf) + return [] else: # POSIX @@ -300,10 +335,13 @@ if __name__ == "__main__": if seen: if not isdir(LOCALISATION_DIR): os.mkdir(LOCALISATION_DIR) + template = codecs.open(join(LOCALISATION_DIR, 'en.template'), 'w', 'utf-8') template.write(f'/* Language name */\n"{LANGUAGE_ID}" = "English";\n\n') for thing in sorted(seen, key=str.lower): if seen[thing]: template.write(f'/* {seen[thing]} */\n') + template.write(f'"{thing}" = "{thing}";\n\n') + template.close() From 7a0339a2569fe41457c0c170dc9df2078d6147a5 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 6 Nov 2020 21:13:56 +0200 Subject: [PATCH 199/727] Added docstrings --- l10n.py | 72 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/l10n.py b/l10n.py index bc9384b8..bffa9f4a 100755 --- a/l10n.py +++ b/l10n.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -# -# Localization with gettext is a pain on non-Unix systems. Use OSX-style strings files instead. -# +"""Localization with gettext is a pain on non-Unix systems. Use OSX-style strings files instead.""" import builtins import codecs @@ -72,12 +70,21 @@ class Translations(object): self.translations = {None: {}} def install_dummy(self): - # For when translation is not desired or not available + """ + Install a dummy translation function. + + Use when translation is not desired or not available + """ self.translations = {None: {}} # Promote strings to Unicode for consistency - builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') + builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') def install(self, lang=None): + """ + Install the translation function to the _ builtin. + + :param lang: The language to translate to, defaults to the preferred language + """ available = self.available() available.add(Translations.FALLBACK) if not lang: @@ -116,6 +123,7 @@ class Translations(object): builtins.__dict__['_'] = self.translate def contents(self, lang, plugin_path=None): + """Get all the translations from a translation file.""" assert lang in self.available() translations = {} h = self.file(lang, plugin_path) @@ -139,6 +147,13 @@ class Translations(object): return translations def translate(self, x, context=None): + """ + Translate the given string to the current lang. + + :param x: The string to translate + :param context: ????, defaults to None + :return: The translated string + """ if context: context = context[len(config.plugin_dir)+1:].split(os.sep)[0] if __debug__: @@ -154,8 +169,8 @@ class Translations(object): return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') - # Returns list of available language codes def available(self): + """Return a list of available language codes.""" path = self.respath() if getattr(sys, 'frozen', False) and platform == 'darwin': available = { @@ -168,8 +183,8 @@ class Translations(object): return available - # Available language names by code def available_names(self): + """Available language names by code.""" names = OrderedDict([ (None, _('Default')), # Appearance theme and language setting ]) @@ -182,6 +197,7 @@ class Translations(object): return names def respath(self): + """Path to localisation files.""" if getattr(sys, 'frozen', False): if platform == 'darwin': return normpath(join(dirname(sys.executable), os.pardir, 'Resources')) @@ -196,6 +212,13 @@ class Translations(object): return LOCALISATION_DIR def file(self, lang, plugin_path=None): + """ + Open the given lang file for reading. + + :param lang: The lang file to open + :param plugin_path: path to plugins dir, to check for plugin based lang files, defaults to None + :return: the opened file (Note: This should be closed when done) + """ if plugin_path: f = join(plugin_path, f'{lang}.strings') if exists(f): @@ -207,6 +230,7 @@ class Translations(object): return None + # TODO: python open() supports encoding elif getattr(sys, 'frozen', False) and platform == 'darwin': return codecs.open(join(self.respath(), f'{lang}.lproj', 'Localizable.strings'), 'r', 'utf-16') @@ -215,6 +239,7 @@ class Translations(object): class Locale(object): + """Locale holds a few utility methods to convert data to and from localized versions.""" def __init__(self): if platform == 'darwin': @@ -226,9 +251,15 @@ class Locale(object): self.float_formatter.setMaximumFractionDigits_(5) def stringFromNumber(self, number, decimals=None): - # Uses the current system locale, irrespective of language choice. - # Unless `decimals` is specified, the number will be formatted with 5 decimal - # places if the input is a float, or none if the input is an int. + """ + Convert a number to a string. + + Uses the current system locale, irrespective of language choice. + + :param number: The number to stringify + :param decimals: The number of decimals to return, defaults to 5 if the given number is a float, otherwise None + :return: the stringified number + """ if decimals == 0 and not isinstance(number, numbers.Integral): number = int(round(number)) @@ -249,8 +280,13 @@ class Locale(object): return locale.format('%.*f', (decimals or 5, number), True) def numberFromString(self, string): - # Uses the current system locale, irrespective of language choice. - # Returns None if the string is not parsable, otherwise an integer or float. + """ + Convert a string to a number using the system locale. + + Note that this uses the current SYSTEM locale regardless of set language. + :param string: The string to convert + :return: None if the string cannot be parsed, otherwise an int or float dependant on input data. + """ if platform == 'darwin': return self.float_formatter.numberFromString_(string) @@ -265,11 +301,17 @@ class Locale(object): except Exception: return None - # Returns list of preferred language codes in RFC4646 format i.e. "lang[-script][-region]" - # Where lang is a lowercase 2 alpha ISO 639-1 or 3 alpha ISO 639-2 code, - # script is a capitalized 4 alpha ISO 15924 code and region is an uppercase 2 alpha ISO 3166 code def preferredLanguages(self): + """ + Return a list of preferred language codes. + Returned data is in RFC4646 format (i.e. "lang[-script][-region]") + Where lang is a lowercase 2 alpha ISO 693-1 or 3 alpha ISO 693-2 code + Where script is a capitalized 4 alpha ISO 15924 code + Where region is an uppercase 2 alpha ISO 3166 code + + :return: The preferred language list + """ if platform == 'darwin': return NSLocale.preferredLanguages() From 07735bbff9c8a0deeee061cd54b4a11eb6e2ecfb Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 6 Nov 2020 21:42:12 +0200 Subject: [PATCH 200/727] Renamed Translations and Locale Previously at the end of l10n.py, the classes Translation and Locale were overwritten with singleton instances of their types. This is both bad practice and makes type checkers want to stab people. This change should not affect any external code as the names they got for Translations and Locale were the instances anyway. --- l10n.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/l10n.py b/l10n.py index bffa9f4a..7f4ac65d 100755 --- a/l10n.py +++ b/l10n.py @@ -58,7 +58,7 @@ elif platform == 'win32': GetNumberFormatEx.restype = ctypes.c_int -class Translations(object): +class _Translations: FALLBACK = 'en' # strings in this code are in English FALLBACK_NAME = 'English' @@ -86,7 +86,7 @@ class Translations(object): :param lang: The language to translate to, defaults to the preferred language """ available = self.available() - available.add(Translations.FALLBACK) + available.add(_Translations.FALLBACK) if not lang: # Choose the default language for preferred in Locale.preferredLanguages(): @@ -133,12 +133,12 @@ class Translations(object): else: for line in h: if line.strip(): - match = Translations.TRANS_RE.match(line) + match = _Translations.TRANS_RE.match(line) if match: to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') translations[match.group(1).replace(r'\"', u'"')] = to_set - elif __debug__ and not Translations.COMMENT_RE.match(line): + elif __debug__ and not _Translations.COMMENT_RE.match(line): print(f'Bad translation: {line.strip()}') if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: @@ -190,7 +190,7 @@ class Translations(object): ]) names.update(sorted( [(lang, self.contents(lang).get(LANGUAGE_ID, lang)) for lang in self.available()] + # type: ignore - [(Translations.FALLBACK, Translations.FALLBACK_NAME)], + [(_Translations.FALLBACK, _Translations.FALLBACK_NAME)], key=lambda x: x[1] )) # Sort by name @@ -238,7 +238,7 @@ class Translations(object): return codecs.open(join(self.respath(), f'{lang}.strings'), 'r', 'utf-8') -class Locale(object): +class _Locale: """Locale holds a few utility methods to convert data to and from localized versions.""" def __init__(self): @@ -350,8 +350,8 @@ class Locale(object): # singletons -Locale = Locale() -Translations = Translations() +Locale = _Locale() +Translations = _Translations() # generate template strings file - like xgettext From 13184a49b298afd598354b6dba1e218e52e5b753 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 6 Nov 2020 21:44:43 +0200 Subject: [PATCH 201/727] Added type annotations --- l10n.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/l10n.py b/l10n.py index 7f4ac65d..4f4af96c 100755 --- a/l10n.py +++ b/l10n.py @@ -8,11 +8,12 @@ import numbers import os import re import sys +from codecs import StreamReaderWriter from collections import OrderedDict from os.path import basename, dirname, exists, isdir, isfile, join, normpath from sys import platform from traceback import print_exc -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Set, Union if TYPE_CHECKING: def _(x: str) -> str: ... @@ -66,10 +67,10 @@ class _Translations: TRANS_RE = re.compile(r'\s*"((?:[^"]|(?:\"))+)"\s*=\s*"((?:[^"]|(?:\"))+)"\s*;\s*$') COMMENT_RE = re.compile(r'\s*/\*.*\*/\s*$') - def __init__(self): - self.translations = {None: {}} + def __init__(self) -> None: + self.translations: Dict[Optional[str], Dict[Any, Any]] = {None: {}} - def install_dummy(self): + def install_dummy(self) -> None: """ Install a dummy translation function. @@ -79,7 +80,7 @@ class _Translations: # Promote strings to Unicode for consistency builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') - def install(self, lang=None): + def install(self, lang: Optional[str] = None) -> None: """ Install the translation function to the _ builtin. @@ -107,6 +108,7 @@ class _Translations: self.install_dummy() else: + # TODO: replace this Any, Any when contents() is annotated self.translations = {None: self.contents(lang)} for plugin in os.listdir(config.plugin_dir): plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) @@ -122,7 +124,7 @@ class _Translations: builtins.__dict__['_'] = self.translate - def contents(self, lang, plugin_path=None): + def contents(self, lang: str, plugin_path: Optional[str] = None) -> Dict[str, str]: """Get all the translations from a translation file.""" assert lang in self.available() translations = {} @@ -146,12 +148,12 @@ class _Translations: return translations - def translate(self, x, context=None): + def translate(self, x: str, context: Optional[str] = None) -> str: """ Translate the given string to the current lang. :param x: The string to translate - :param context: ????, defaults to None + :param context: Whether or not to search the given directory for translation files, defaults to None :return: The translated string """ if context: @@ -169,7 +171,7 @@ class _Translations: return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') - def available(self): + def available(self) -> Set[str]: """Return a list of available language codes.""" path = self.respath() if getattr(sys, 'frozen', False) and platform == 'darwin': @@ -183,7 +185,7 @@ class _Translations: return available - def available_names(self): + def available_names(self) -> Dict[Optional[str], str]: """Available language names by code.""" names = OrderedDict([ (None, _('Default')), # Appearance theme and language setting @@ -196,7 +198,7 @@ class _Translations: return names - def respath(self): + def respath(self) -> str: # TODO: PathLike """Path to localisation files.""" if getattr(sys, 'frozen', False): if platform == 'darwin': @@ -211,11 +213,11 @@ class _Translations: else: return LOCALISATION_DIR - def file(self, lang, plugin_path=None): + def file(self, lang: str, plugin_path: Optional[str] = None) -> Optional[StreamReaderWriter]: """ Open the given lang file for reading. - :param lang: The lang file to open + :param lang: The lang file to open (just the name of the lang) :param plugin_path: path to plugins dir, to check for plugin based lang files, defaults to None :return: the opened file (Note: This should be closed when done) """ @@ -241,7 +243,7 @@ class _Translations: class _Locale: """Locale holds a few utility methods to convert data to and from localized versions.""" - def __init__(self): + def __init__(self) -> None: if platform == 'darwin': self.int_formatter = NSNumberFormatter.alloc().init() self.int_formatter.setNumberStyle_(NSNumberFormatterDecimalStyle) @@ -250,7 +252,7 @@ class _Locale: self.float_formatter.setMinimumFractionDigits_(5) self.float_formatter.setMaximumFractionDigits_(5) - def stringFromNumber(self, number, decimals=None): + def stringFromNumber(self, number: Union[float, int], decimals: int = None) -> str: """ Convert a number to a string. @@ -260,6 +262,8 @@ class _Locale: :param decimals: The number of decimals to return, defaults to 5 if the given number is a float, otherwise None :return: the stringified number """ + + # TODO: decimals = decimals if decimals is not None else 5 if decimals == 0 and not isinstance(number, numbers.Integral): number = int(round(number)) @@ -279,7 +283,7 @@ class _Locale: else: return locale.format('%.*f', (decimals or 5, number), True) - def numberFromString(self, string): + def numberFromString(self, string: str) -> Union[int, float, None]: """ Convert a string to a number using the system locale. @@ -301,7 +305,7 @@ class _Locale: except Exception: return None - def preferredLanguages(self): + def preferredLanguages(self) -> Iterable[str]: """ Return a list of preferred language codes. @@ -359,7 +363,7 @@ Translations = _Translations() if __name__ == "__main__": import re regexp = re.compile(r'''_\([ur]?(['"])(((? Date: Fri, 6 Nov 2020 21:54:25 +0200 Subject: [PATCH 202/727] Fixed some static type issues --- l10n.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/l10n.py b/l10n.py index 4f4af96c..fb6a8b06 100755 --- a/l10n.py +++ b/l10n.py @@ -13,7 +13,7 @@ from collections import OrderedDict from os.path import basename, dirname, exists, isdir, isfile, join, normpath from sys import platform from traceback import print_exc -from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Set, Union +from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Set, Union, cast if TYPE_CHECKING: def _(x: str) -> str: ... @@ -68,7 +68,7 @@ class _Translations: COMMENT_RE = re.compile(r'\s*/\*.*\*/\s*$') def __init__(self) -> None: - self.translations: Dict[Optional[str], Dict[Any, Any]] = {None: {}} + self.translations: Dict[Optional[str], Dict[str, str]] = {None: {}} def install_dummy(self) -> None: """ @@ -80,7 +80,7 @@ class _Translations: # Promote strings to Unicode for consistency builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') - def install(self, lang: Optional[str] = None) -> None: + def install(self, lang: str = None) -> None: """ Install the translation function to the _ builtin. @@ -108,13 +108,12 @@ class _Translations: self.install_dummy() else: - # TODO: replace this Any, Any when contents() is annotated - self.translations = {None: self.contents(lang)} + self.translations = {None: self.contents(cast(str, lang))} for plugin in os.listdir(config.plugin_dir): plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) if isdir(plugin_path): try: - self.translations[plugin] = self.contents(lang, plugin_path) + self.translations[plugin] = self.contents(cast(str, lang), plugin_path) except UnicodeDecodeError as e: print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') @@ -262,8 +261,8 @@ class _Locale: :param decimals: The number of decimals to return, defaults to 5 if the given number is a float, otherwise None :return: the stringified number """ + decimals = decimals if decimals is not None else 5 - # TODO: decimals = decimals if decimals is not None else 5 if decimals == 0 and not isinstance(number, numbers.Integral): number = int(round(number)) @@ -272,8 +271,8 @@ class _Locale: return self.int_formatter.stringFromNumber_(number) else: - self.float_formatter.setMinimumFractionDigits_(decimals or 5) - self.float_formatter.setMaximumFractionDigits_(decimals or 5) + self.float_formatter.setMinimumFractionDigits_(decimals) + self.float_formatter.setMaximumFractionDigits_(decimals) return self.float_formatter.stringFromNumber_(number) else: @@ -281,7 +280,7 @@ class _Locale: return locale.format('%d', number, True) else: - return locale.format('%.*f', (decimals or 5, number), True) + return locale.format('%.*f', (decimals, number), True) # type: ignore # It ends up working out def numberFromString(self, string: str) -> Union[int, float, None]: """ From 4ede555c13a1da8572fed690c30434cd0f27dbb4 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 7 Nov 2020 15:52:42 +0200 Subject: [PATCH 203/727] Refactored return based logic A good chunk of the logic in here was returning from branches but still using else/elif/except branches to do an alternate behaviour. --- l10n.py | 148 +++++++++++++++++++++++++------------------------------- 1 file changed, 66 insertions(+), 82 deletions(-) diff --git a/l10n.py b/l10n.py index fb6a8b06..d9fcce63 100755 --- a/l10n.py +++ b/l10n.py @@ -10,10 +10,11 @@ import re import sys from codecs import StreamReaderWriter from collections import OrderedDict +from contextlib import suppress from os.path import basename, dirname, exists, isdir, isfile, join, normpath from sys import platform from traceback import print_exc -from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Set, Union, cast +from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, Union, cast if TYPE_CHECKING: def _(x: str) -> str: ... @@ -106,22 +107,22 @@ class _Translations: if lang not in self.available(): self.install_dummy() + return - else: - self.translations = {None: self.contents(cast(str, lang))} - for plugin in os.listdir(config.plugin_dir): - plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) - if isdir(plugin_path): - try: - self.translations[plugin] = self.contents(cast(str, lang), plugin_path) + self.translations = {None: self.contents(cast(str, lang))} + for plugin in os.listdir(config.plugin_dir): + plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) + if isdir(plugin_path): + try: + self.translations[plugin] = self.contents(cast(str, lang), plugin_path) - except UnicodeDecodeError as e: - print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') + except UnicodeDecodeError as e: + print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') - except Exception: - print_exc() + except Exception: + print_exc() - builtins.__dict__['_'] = self.translate + builtins.__dict__['_'] = self.translate def contents(self, lang: str, plugin_path: Optional[str] = None) -> Dict[str, str]: """Get all the translations from a translation file.""" @@ -131,16 +132,15 @@ class _Translations: if not h: return {} - else: - for line in h: - if line.strip(): - match = _Translations.TRANS_RE.match(line) - if match: - to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') - translations[match.group(1).replace(r'\"', u'"')] = to_set + for line in h: + if line.strip(): + match = _Translations.TRANS_RE.match(line) + if match: + to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') + translations[match.group(1).replace(r'\"', u'"')] = to_set - elif __debug__ and not _Translations.COMMENT_RE.match(line): - print(f'Bad translation: {line.strip()}') + elif __debug__ and not _Translations.COMMENT_RE.match(line): + print(f'Bad translation: {line.strip()}') if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing @@ -163,12 +163,11 @@ class _Translations: return self.translations.get(context, {}).get(x) or self.translate(x) - else: - if __debug__: - if self.translations[None] and x not in self.translations[None]: - print(f'Missing translation: {x!r}') + if __debug__: + if self.translations[None] and x not in self.translations[None]: + print(f'Missing translation: {x!r}') - return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') + return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') def available(self) -> Set[str]: """Return a list of available language codes.""" @@ -186,11 +185,11 @@ class _Translations: def available_names(self) -> Dict[Optional[str], str]: """Available language names by code.""" - names = OrderedDict([ + names: Dict[Optional[str], str] = OrderedDict([ (None, _('Default')), # Appearance theme and language setting ]) names.update(sorted( - [(lang, self.contents(lang).get(LANGUAGE_ID, lang)) for lang in self.available()] + # type: ignore + [(lang, self.contents(lang).get(LANGUAGE_ID, lang)) for lang in self.available()] + [(_Translations.FALLBACK, _Translations.FALLBACK_NAME)], key=lambda x: x[1] )) # Sort by name @@ -203,14 +202,12 @@ class _Translations: if platform == 'darwin': return normpath(join(dirname(sys.executable), os.pardir, 'Resources')) - else: - return join(dirname(sys.executable), LOCALISATION_DIR) + return join(dirname(sys.executable), LOCALISATION_DIR) elif __file__: return join(dirname(__file__), LOCALISATION_DIR) - else: - return LOCALISATION_DIR + return LOCALISATION_DIR def file(self, lang: str, plugin_path: Optional[str] = None) -> Optional[StreamReaderWriter]: """ @@ -235,8 +232,7 @@ class _Translations: elif getattr(sys, 'frozen', False) and platform == 'darwin': return codecs.open(join(self.respath(), f'{lang}.lproj', 'Localizable.strings'), 'r', 'utf-16') - else: - return codecs.open(join(self.respath(), f'{lang}.strings'), 'r', 'utf-8') + return codecs.open(join(self.respath(), f'{lang}.strings'), 'r', 'utf-8') class _Locale: @@ -270,17 +266,15 @@ class _Locale: if not decimals and isinstance(number, numbers.Integral): return self.int_formatter.stringFromNumber_(number) - else: - self.float_formatter.setMinimumFractionDigits_(decimals) - self.float_formatter.setMaximumFractionDigits_(decimals) - return self.float_formatter.stringFromNumber_(number) + self.float_formatter.setMinimumFractionDigits_(decimals) + self.float_formatter.setMaximumFractionDigits_(decimals) + return self.float_formatter.stringFromNumber_(number) + + if not decimals and isinstance(number, numbers.Integral): + return locale.format('%d', number, True) else: - if not decimals and isinstance(number, numbers.Integral): - return locale.format('%d', number, True) - - else: - return locale.format('%.*f', (decimals, number), True) # type: ignore # It ends up working out + return locale.format('%.*f', (decimals, number), True) # type: ignore # It ends up working out def numberFromString(self, string: str) -> Union[int, float, None]: """ @@ -293,16 +287,13 @@ class _Locale: if platform == 'darwin': return self.float_formatter.numberFromString_(string) - else: - try: # TODO: This is awful. - return locale.atoi(string) + with suppress(ValueError): + return locale.atoi(string) - except Exception: - try: - return locale.atof(string) + with suppress(ValueError): + return locale.atof(string) - except Exception: - return None + return None def preferredLanguages(self) -> Iterable[str]: """ @@ -318,39 +309,32 @@ class _Locale: if platform == 'darwin': return NSLocale.preferredLanguages() - elif platform == 'win32': - - def wszarray_to_list(array): - offset = 0 - while offset < len(array): - sz = ctypes.wstring_at(ctypes.addressof(array) + offset*2) - if sz: - yield sz - offset += len(sz)+1 - - else: - break - - num = ctypes.c_ulong() - size = ctypes.c_ulong(0) - if ( - GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), None, ctypes.byref(size)) - and size.value - ): - buf = ctypes.create_unicode_buffer(size.value) - if ( - GetUserPreferredUILanguages( - MUI_LANGUAGE_NAME, ctypes.byref(num), ctypes.byref(buf), ctypes.byref(size) - ) - ): - return wszarray_to_list(buf) - - return [] - - else: # POSIX + elif platform != 'win32': + # POSIX lang = locale.getlocale()[0] return lang and [lang.replace('_', '-')] or [] + def wszarray_to_list(array): + offset = 0 + while offset < len(array): + sz = ctypes.wstring_at(ctypes.addressof(array) + offset*2) + if sz: + yield sz + offset += len(sz)+1 + + else: + break + + num = ctypes.c_ulong() + size = ctypes.c_ulong(0) + if GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), None, ctypes.byref(size)) and size.value: + buf = ctypes.create_unicode_buffer(size.value) + + if GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), ctypes.byref(buf), ctypes.byref(size)): + return wszarray_to_list(buf) + + return [] + # singletons Locale = _Locale() From e44039cfdd7d2e7c291f8fbc1087d553c438d8ba Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 7 Nov 2020 16:07:34 +0200 Subject: [PATCH 204/727] Replaced prints with logging --- l10n.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/l10n.py b/l10n.py index d9fcce63..a30f5905 100755 --- a/l10n.py +++ b/l10n.py @@ -13,7 +13,6 @@ from collections import OrderedDict from contextlib import suppress from os.path import basename, dirname, exists, isdir, isfile, join, normpath from sys import platform -from traceback import print_exc from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, Union, cast if TYPE_CHECKING: @@ -27,6 +26,10 @@ except Exception: print("Can't set locale!") from config import config +from EDMCLogging import get_main_logger + +logger = get_main_logger() + # Language name LANGUAGE_ID = '!Language' @@ -117,10 +120,10 @@ class _Translations: self.translations[plugin] = self.contents(cast(str, lang), plugin_path) except UnicodeDecodeError as e: - print(f'Malformed file {lang}.strings in plugin {plugin}: {e}') + logger.warning(f'Malformed file {lang}.strings in plugin {plugin}: {e}') except Exception: - print_exc() + logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}') builtins.__dict__['_'] = self.translate @@ -139,8 +142,8 @@ class _Translations: to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') translations[match.group(1).replace(r'\"', u'"')] = to_set - elif __debug__ and not _Translations.COMMENT_RE.match(line): - print(f'Bad translation: {line.strip()}') + elif not _Translations.COMMENT_RE.match(line): + logger.debug(f'Bad translation: {line.strip()}') if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing @@ -157,15 +160,13 @@ class _Translations: """ if context: context = context[len(config.plugin_dir)+1:].split(os.sep)[0] - if __debug__: - if self.translations[None] and context not in self.translations: - print(f'No translations for {context!r}') + if self.translations[None] and context not in self.translations: + logger.debug(f'No translations for {context!r}') return self.translations.get(context, {}).get(x) or self.translate(x) - if __debug__: - if self.translations[None] and x not in self.translations[None]: - print(f'Missing translation: {x!r}') + if self.translations[None] and x not in self.translations[None]: + logger.debug(f'Missing translation: {x!r}') return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') @@ -224,7 +225,7 @@ class _Translations: return codecs.open(f, 'r', 'utf-8') except Exception: - print_exc() + logger.exception(f'could not open {f}') return None From 6687dcbfefe45f7f2b4862825d8e15dd8815f923 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 7 Nov 2020 16:24:19 +0200 Subject: [PATCH 205/727] Made respath use pathlib paths --- l10n.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/l10n.py b/l10n.py index a30f5905..87d9cfbc 100755 --- a/l10n.py +++ b/l10n.py @@ -6,6 +6,8 @@ import codecs import locale import numbers import os +from os import PathLike +import pathlib import re import sys from codecs import StreamReaderWriter @@ -197,18 +199,18 @@ class _Translations: return names - def respath(self) -> str: # TODO: PathLike + def respath(self) -> PathLike: """Path to localisation files.""" if getattr(sys, 'frozen', False): if platform == 'darwin': - return normpath(join(dirname(sys.executable), os.pardir, 'Resources')) + return (pathlib.Path(sys.executable).parents[0] / os.pardir / 'Resources').resolve() - return join(dirname(sys.executable), LOCALISATION_DIR) + return pathlib.Path(dirname(sys.executable)) / LOCALISATION_DIR elif __file__: - return join(dirname(__file__), LOCALISATION_DIR) + return pathlib.Path(__file__).parents[0] / LOCALISATION_DIR - return LOCALISATION_DIR + return pathlib.Path(LOCALISATION_DIR) def file(self, lang: str, plugin_path: Optional[str] = None) -> Optional[StreamReaderWriter]: """ From ac7a1fa63e0bb386d3de5b57738f038e46638188 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 7 Nov 2020 16:37:28 +0200 Subject: [PATCH 206/727] Replaced codecs.open with builtin open In py2, open() did not support encodings, in py3 it does --- l10n.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/l10n.py b/l10n.py index 87d9cfbc..37c56db5 100755 --- a/l10n.py +++ b/l10n.py @@ -2,20 +2,17 @@ """Localization with gettext is a pain on non-Unix systems. Use OSX-style strings files instead.""" import builtins -import codecs import locale import numbers import os -from os import PathLike import pathlib import re import sys -from codecs import StreamReaderWriter from collections import OrderedDict from contextlib import suppress -from os.path import basename, dirname, exists, isdir, isfile, join, normpath +from os.path import basename, dirname, exists, isdir, isfile, join from sys import platform -from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, Union, cast +from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, TextIO, Union, cast if TYPE_CHECKING: def _(x: str) -> str: ... @@ -199,7 +196,7 @@ class _Translations: return names - def respath(self) -> PathLike: + def respath(self) -> pathlib.Path: """Path to localisation files.""" if getattr(sys, 'frozen', False): if platform == 'darwin': @@ -212,7 +209,7 @@ class _Translations: return pathlib.Path(LOCALISATION_DIR) - def file(self, lang: str, plugin_path: Optional[str] = None) -> Optional[StreamReaderWriter]: + def file(self, lang: str, plugin_path: Optional[str] = None) -> Optional[TextIO]: """ Open the given lang file for reading. @@ -224,18 +221,17 @@ class _Translations: f = join(plugin_path, f'{lang}.strings') if exists(f): try: - return codecs.open(f, 'r', 'utf-8') + return open(f, 'r', encoding='utf-8') except Exception: logger.exception(f'could not open {f}') return None - # TODO: python open() supports encoding elif getattr(sys, 'frozen', False) and platform == 'darwin': - return codecs.open(join(self.respath(), f'{lang}.lproj', 'Localizable.strings'), 'r', 'utf-16') + return (self.respath() / f'{lang}.lproj' / 'Localizable.strings').open('r', encoding='utf-16') - return codecs.open(join(self.respath(), f'{lang}.strings'), 'r', 'utf-8') + return (self.respath() / f'{lang}.strings').open('r', encoding='utf-8') class _Locale: @@ -352,10 +348,11 @@ if __name__ == "__main__": seen: Dict[str, str] = {} for f in ( # TODO: need to be sorted and then concatted like this? sorted(x for x in os.listdir('.') if x.endswith('.py')) + - sorted(join('plugins', x) for x in isdir('plugins') - and os.listdir('plugins') or [] if x.endswith('.py')) + sorted( + join('plugins', x) for x in isdir('plugins') and os.listdir('plugins') or [] if x.endswith('.py') + ) ): - with codecs.open(f, 'r', 'utf-8') as h: + with open(f, 'r', encoding='utf-8') as h: lineno = 0 for line in h: lineno += 1 @@ -368,7 +365,7 @@ if __name__ == "__main__": if not isdir(LOCALISATION_DIR): os.mkdir(LOCALISATION_DIR) - template = codecs.open(join(LOCALISATION_DIR, 'en.template'), 'w', 'utf-8') + template = open(join(LOCALISATION_DIR, 'en.template'), 'w', encoding='utf-8') template.write(f'/* Language name */\n"{LANGUAGE_ID}" = "English";\n\n') for thing in sorted(seen, key=str.lower): if seen[thing]: From b5282fc8ead7efc5838c706c2a8618925fd0b129 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 7 Nov 2020 16:49:37 +0200 Subject: [PATCH 207/727] Deprecated camelCase methods Python prefers snake_case methods and camelCase classes. This replaces some camelCase methods with snake_case variants, and has the original names raise a DeprecationWarning before calling the snake_case versions --- PLUGINS.md | 4 ++-- l10n.py | 21 +++++++++++++++++---- stats.py | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 7fe3e390..9c685055 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -227,7 +227,7 @@ a single set and two get methods, the new methods provide better type safety. **Be sure to use a unique prefix for any settings you save so as not to clash with core EDMC or other plugins.** -Use `numberFromString()` from EDMC's `l10n.Locale` object to parse input +Use `number_from_string()` from EDMC's `l10n.Locale` object to parse input numbers in a locale-independent way. Note that in the following example the function signature defines that it @@ -288,7 +288,7 @@ For a more complicated item create a tk.Frame widget and populate it with other ttk widgets. Return `None` if you just want to use this as a callback after the main window and all other plugins are initialised. -You can use `stringFromNumber()` from EDMC's `l10n.Locale` object to format +You can use `string_from_number()` from EDMC's `l10n.Locale` object to format numbers in your widgets in a locale-independent way. ```python diff --git a/l10n.py b/l10n.py index 37c56db5..009a6e4c 100755 --- a/l10n.py +++ b/l10n.py @@ -13,6 +13,7 @@ from contextlib import suppress from os.path import basename, dirname, exists, isdir, isfile, join from sys import platform from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, TextIO, Union, cast +import warnings if TYPE_CHECKING: def _(x: str) -> str: ... @@ -93,7 +94,7 @@ class _Translations: available.add(_Translations.FALLBACK) if not lang: # Choose the default language - for preferred in Locale.preferredLanguages(): + for preferred in Locale.preferred_languages(): components = preferred.split('-') if preferred in available: lang = preferred @@ -246,7 +247,19 @@ class _Locale: self.float_formatter.setMinimumFractionDigits_(5) self.float_formatter.setMaximumFractionDigits_(5) - def stringFromNumber(self, number: Union[float, int], decimals: int = None) -> str: + def stringFromNumber(self, number: Union[float, int], decimals: int = None) -> str: # noqa: N802 + warnings.warn(DeprecationWarning('use _Locale.string_from_number instead.')) + return self.stringFromNumber(number, decimals) + + def numberFromString(self, string: str) -> Union[int, float, None]: # noqa: N802 + warnings.warn(DeprecationWarning('use _Locale.number_from_string instead.')) + return self.numberFromString(string) + + def preferredLanguages(self) -> Iterable[str]: # noqa: N802 + warnings.warn(DeprecationWarning('use _Locale.preferred_languages instead.')) + return self.preferred_languages() + + def string_from_number(self, number: Union[float, int], decimals: int = None) -> str: """ Convert a number to a string. @@ -275,7 +288,7 @@ class _Locale: else: return locale.format('%.*f', (decimals, number), True) # type: ignore # It ends up working out - def numberFromString(self, string: str) -> Union[int, float, None]: + def number_from_string(self, string: str) -> Union[int, float, None]: """ Convert a string to a number using the system locale. @@ -294,7 +307,7 @@ class _Locale: return None - def preferredLanguages(self) -> Iterable[str]: + def preferred_languages(self) -> Iterable[str]: """ Return a list of preferred language codes. diff --git a/stats.py b/stats.py index 4f05b538..f0cac5b8 100644 --- a/stats.py +++ b/stats.py @@ -448,4 +448,4 @@ class StatsResults(tk.Toplevel): def credits(self, value: int) -> str: """Localised string of given int, including a trailing ` Cr`.""" # TODO: Locale is a class, this calls an instance method on it with an int as its `self` - return Locale.stringFromNumber(value, 0) + ' Cr' # type: ignore + return Locale.string_from_number(value, 0) + ' Cr' # type: ignore From 7a7b5821dfb6520e33ea9571c286ca6fa30e3222 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 7 Nov 2020 16:56:41 +0200 Subject: [PATCH 208/727] refactored trinary logic --- l10n.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/l10n.py b/l10n.py index 009a6e4c..cbc54004 100755 --- a/l10n.py +++ b/l10n.py @@ -8,12 +8,12 @@ import os import pathlib import re import sys +import warnings from collections import OrderedDict from contextlib import suppress from os.path import basename, dirname, exists, isdir, isfile, join from sys import platform from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, TextIO, Union, cast -import warnings if TYPE_CHECKING: def _(x: str) -> str: ... @@ -361,9 +361,7 @@ if __name__ == "__main__": seen: Dict[str, str] = {} for f in ( # TODO: need to be sorted and then concatted like this? sorted(x for x in os.listdir('.') if x.endswith('.py')) + - sorted( - join('plugins', x) for x in isdir('plugins') and os.listdir('plugins') or [] if x.endswith('.py') - ) + sorted(join('plugins', x) for x in (os.listdir('plugins') if isdir('plugins') else []) if x.endswith('.py')) ): with open(f, 'r', encoding='utf-8') as h: lineno = 0 From 63dd6418b9d8ab766a1fc3276c57c8d1551969e1 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 7 Nov 2020 16:58:14 +0200 Subject: [PATCH 209/727] removed unicode strings --- l10n.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/l10n.py b/l10n.py index cbc54004..bb79a3b5 100755 --- a/l10n.py +++ b/l10n.py @@ -82,7 +82,7 @@ class _Translations: """ self.translations = {None: {}} # Promote strings to Unicode for consistency - builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') + builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n') def install(self, lang: str = None) -> None: """ @@ -139,8 +139,8 @@ class _Translations: if line.strip(): match = _Translations.TRANS_RE.match(line) if match: - to_set = match.group(2).replace(r'\"', u'"').replace(u'{CR}', u'\n') - translations[match.group(1).replace(r'\"', u'"')] = to_set + to_set = match.group(2).replace(r'\"', '"').replace('{CR}', '\n') + translations[match.group(1).replace(r'\"', '"')] = to_set elif not _Translations.COMMENT_RE.match(line): logger.debug(f'Bad translation: {line.strip()}') @@ -168,7 +168,7 @@ class _Translations: if self.translations[None] and x not in self.translations[None]: logger.debug(f'Missing translation: {x!r}') - return self.translations[None].get(x) or str(x).replace(r'\"', u'"').replace(u'{CR}', u'\n') + return self.translations[None].get(x) or str(x).replace(r'\"', '"').replace('{CR}', '\n') def available(self) -> Set[str]: """Return a list of available language codes.""" From 1a563653dabac84ede580847ed7a02644d7f285d Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 31 Dec 2020 18:47:23 +0200 Subject: [PATCH 210/727] Missed a place to use pathlib.Path() --- l10n.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/l10n.py b/l10n.py index bb79a3b5..7556a40d 100755 --- a/l10n.py +++ b/l10n.py @@ -219,15 +219,15 @@ class _Translations: :return: the opened file (Note: This should be closed when done) """ if plugin_path: - f = join(plugin_path, f'{lang}.strings') - if exists(f): - try: - return open(f, 'r', encoding='utf-8') + f = pathlib.Path(plugin_path) / f'{lang}.strings' + if not f.exists(): + return None - except Exception: - logger.exception(f'could not open {f}') + try: + return f.open('r', encoding='utf-8') - return None + except OSError: + logger.exception(f'could not open {f}') elif getattr(sys, 'frozen', False) and platform == 'darwin': return (self.respath() / f'{lang}.lproj' / 'Localizable.strings').open('r', encoding='utf-16') From db06bc82aff2142a8bafbdd6eed311498c2f4261 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 31 Dec 2020 18:49:36 +0200 Subject: [PATCH 211/727] Resolved PR comments --- l10n.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/l10n.py b/l10n.py index 7556a40d..eca31792 100755 --- a/l10n.py +++ b/l10n.py @@ -18,6 +18,7 @@ from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, TextIO, Union, if TYPE_CHECKING: def _(x: str) -> str: ... +# Note that this is also done in EDMarketConnector.py, and thus removing this here may not have a desired effect try: locale.setlocale(locale.LC_ALL, '') @@ -81,7 +82,6 @@ class _Translations: Use when translation is not desired or not available """ self.translations = {None: {}} - # Promote strings to Unicode for consistency builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n') def install(self, lang: str = None) -> None: @@ -128,7 +128,7 @@ class _Translations: builtins.__dict__['_'] = self.translate def contents(self, lang: str, plugin_path: Optional[str] = None) -> Dict[str, str]: - """Get all the translations from a translation file.""" + """Load all the translations from a translation file.""" assert lang in self.available() translations = {} h = self.file(lang, plugin_path) @@ -249,17 +249,17 @@ class _Locale: def stringFromNumber(self, number: Union[float, int], decimals: int = None) -> str: # noqa: N802 warnings.warn(DeprecationWarning('use _Locale.string_from_number instead.')) - return self.stringFromNumber(number, decimals) + return self.string_from_number(number, decimals) # type: ignore def numberFromString(self, string: str) -> Union[int, float, None]: # noqa: N802 warnings.warn(DeprecationWarning('use _Locale.number_from_string instead.')) - return self.numberFromString(string) + return self.number_from_string(string) def preferredLanguages(self) -> Iterable[str]: # noqa: N802 warnings.warn(DeprecationWarning('use _Locale.preferred_languages instead.')) return self.preferred_languages() - def string_from_number(self, number: Union[float, int], decimals: int = None) -> str: + def string_from_number(self, number: Union[float, int], decimals: int = 5) -> str: """ Convert a number to a string. @@ -269,8 +269,6 @@ class _Locale: :param decimals: The number of decimals to return, defaults to 5 if the given number is a float, otherwise None :return: the stringified number """ - decimals = decimals if decimals is not None else 5 - if decimals == 0 and not isinstance(number, numbers.Integral): number = int(round(number)) From 54c8558d35acedb87eb1496fc85598737ad12588 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 3 Jan 2021 21:25:07 +0200 Subject: [PATCH 212/727] Added comment to EDMarketConnectory.py Covers the locale magic in l10n.py --- EDMarketConnector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 4f582e9f..0b3276f3 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1473,6 +1473,9 @@ sys.path: {sys.path}''' # Trying to set a UTF-8 encoding on those older versions will fail with # locale.Error: unsupported locale setting # but we do need to make the attempt for when we're running from source. + # + # Note that this locale magic is partially done in l10n.py as well. So + # removing or modifying this may or may not have the desired effect. log_locale('Initial Locale') try: From dbc357ebcde9c6be2758db1bfa6de5a202c0b56a Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 3 Jan 2021 21:33:01 +0200 Subject: [PATCH 213/727] Dont overwrite template files when generating new ones --- l10n.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/l10n.py b/l10n.py index eca31792..5e285adc 100755 --- a/l10n.py +++ b/l10n.py @@ -11,7 +11,7 @@ import sys import warnings from collections import OrderedDict from contextlib import suppress -from os.path import basename, dirname, exists, isdir, isfile, join +from os.path import basename, dirname, isdir, isfile, join from sys import platform from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, TextIO, Union, cast @@ -357,7 +357,7 @@ if __name__ == "__main__": import re regexp = re.compile(r'''_\([ur]?(['"])(((? Date: Mon, 4 Jan 2021 19:33:30 +0200 Subject: [PATCH 214/727] Fixed creating en.template.new as a dir --- l10n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n.py b/l10n.py index 5e285adc..3a4ca53b 100755 --- a/l10n.py +++ b/l10n.py @@ -372,7 +372,7 @@ if __name__ == "__main__": ) if seen: target_path = pathlib.Path(LOCALISATION_DIR) / 'en.template.new' - target_path.mkdir(exist_ok=True) + target_path.parent.mkdir(exist_ok=True) with target_path.open('w', encoding='utf-8') as target_file: target_file.write(f'/* Language name */\n"{LANGUAGE_ID}" = "English";\n\n') for thing in sorted(seen, key=str.lower): From 903ec3d5582a5a7bd93332f2b2b5797270b9c8e4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:06:57 +0000 Subject: [PATCH 215/727] Added mention of deprecated methods # Conflicts: # PLUGINS.md --- PLUGINS.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 9c685055..9d5c2917 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -230,11 +230,9 @@ with core EDMC or other plugins.** Use `number_from_string()` from EDMC's `l10n.Locale` object to parse input numbers in a locale-independent way. -Note that in the following example the function signature defines that it -returns `Optional[tk.Frame]` only because we need to allow for `None` if -something goes wrong with the creation of the frame (the calling code checks -this). You absolutely need to return the `nb.Frame()` instance that you get -as in the code below. +Note that the old CamelCase versions of `number_from_string` and `string_from_number` do still exist, +but are deprecated. They will continue to work, but will throw warnings. + ```python import tkinter as tk from tkinter import ttk From 92d9185b43262de89fdd628df076b9cc322a1916 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:08:02 +0000 Subject: [PATCH 216/727] EDMCLogging: Revert to Python 3.8+ walrus operator * Re-order an import to make isort happy * Mark caller_attributes() as ignoring C901 as well # Conflicts: # EDMCLogging.py --- EDMCLogging.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 171907ba..35f50411 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -44,7 +44,7 @@ import tempfile # So that any warning about accessing a protected member is only in one place. from sys import _getframe as getframe from threading import get_native_id as thread_native_id -from typing import Tuple +from typing import TYPE_CHECKING, Tuple, cast from config import appcmdname, appname, config @@ -282,7 +282,7 @@ class EDMCContextFilter(logging.Filter): return True @classmethod - def caller_attributes(cls, module_name: str = '') -> Tuple[str, str, str]: # noqa: CCR001, E501 # this is as refactored as is sensible + def caller_attributes(cls, module_name: str = '') -> Tuple[str, str, str]: # noqa: CCR001, E501, C901 # this is as refactored as is sensible """ Determine extra or changed fields for the caller. @@ -322,11 +322,8 @@ class EDMCContextFilter(logging.Filter): if frame_class: # See https://en.wikipedia.org/wiki/Name_mangling#Python for how name mangling works. - # For more detail, see _Py_Mangle in CPython's Python/compile.c. - name = frame_info.function - class_name = frame_class.__class__.__name__.lstrip("_") - if name.startswith("__") and not name.endswith("__") and class_name: - name = f'_{class_name}{frame_info.function}' + if (name := frame_info.function).startswith("__") and not name.endswith("__"): + name = f'_{frame_class.__class__.__name__}{frame_info.function}' # Find __qualname__ of the caller fn = inspect.getattr_static(frame_class, name, None) From b3b72a05a8d1c6c1213a57ee1d98cea3290b6b47 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 21 Dec 2020 14:44:39 +0000 Subject: [PATCH 217/727] PLUGINS.md: Be explicit about why plugin_prefs(...) -> Optional[tk.Frame] --- PLUGINS.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 9d5c2917..f98a125a 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -228,10 +228,15 @@ a single set and two get methods, the new methods provide better type safety. with core EDMC or other plugins.** Use `number_from_string()` from EDMC's `l10n.Locale` object to parse input -numbers in a locale-independent way. +numbers in a locale-independent way. NB: the old CamelCase versions of +`number_from_string` and `string_from_number` do still exist, but arexi +deprecated. They will continue to work, but will throw warnings. -Note that the old CamelCase versions of `number_from_string` and `string_from_number` do still exist, -but are deprecated. They will continue to work, but will throw warnings. +Note that in the following example the function signature defines that it +returns `Optional[tk.Frame]` only because we need to allow for `None` if +something goes wrong with the creation of the frame (the calling code checks +this). You absolutely need to return the `nb.Frame()` instance that you get +as in the code below. ```python import tkinter as tk From 2ff06c15ab69becee9c0e4d442178a6ef5bc6e31 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 17:11:18 +0200 Subject: [PATCH 218/727] Fix double quoted strings in workflow --- .github/workflows/push-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index 149e95af..93776c4f 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -37,7 +37,7 @@ jobs: env: ROOT_SHA: ${{github.base_ref}} run: | - DATA=$(jq .before $GITHUB_EVENT_PATH) + DATA=$(jq --raw-output .before $GITHUB_EVENT_PATH) # stop the build if there are Python syntax errors or undefined names, ignore existing git diff "$DATA" | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --diff From 965493ffed74212e6d2d8381ecb933a5310c2f48 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 17:41:38 +0200 Subject: [PATCH 219/727] Silenced flake8 warning --- l10n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n.py b/l10n.py index 3a4ca53b..404dfc69 100755 --- a/l10n.py +++ b/l10n.py @@ -84,7 +84,7 @@ class _Translations: self.translations = {None: {}} builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n') - def install(self, lang: str = None) -> None: + def install(self, lang: str = None) -> None: # noqa: CCR001 """ Install the translation function to the _ builtin. From 281f66c7c1d5fb8154f1e909bba0cb1d13a31d73 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 17:42:13 +0200 Subject: [PATCH 220/727] Stringified plugin_dir for len check --- l10n.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/l10n.py b/l10n.py index 404dfc69..6b9b1494 100755 --- a/l10n.py +++ b/l10n.py @@ -159,7 +159,8 @@ class _Translations: :return: The translated string """ if context: - context = context[len(config.plugin_dir)+1:].split(os.sep)[0] + # TODO: There is probably a better way to go about this now. + context = context[len(str(config.plugin_dir))+1:].split(os.sep)[0] if self.translations[None] and context not in self.translations: logger.debug(f'No translations for {context!r}') From ed7d79c2f7114de732cdf07b6df214d22cd9eb60 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 4 Nov 2020 17:42:58 +0200 Subject: [PATCH 221/727] Added UI transparency option --- EDMarketConnector.py | 7 +++++++ prefs.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 0b3276f3..4daa26e8 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1598,6 +1598,13 @@ sys.path: {sys.path}''' ) config.set('plugins_not_py3_last', int(time())) + # UI Transparency + ui_transparency = config.getint('ui_transparency') + if ui_transparency == 0: + ui_transparency = 100 + + root.wm_attributes('-alpha', ui_transparency / 100) + root.after(0, messagebox_not_py3) root.mainloop() diff --git a/prefs.py b/prefs.py index 4a84fa5f..bc5c38ed 100644 --- a/prefs.py +++ b/prefs.py @@ -739,9 +739,42 @@ class PreferencesDialog(tk.Toplevel): text=_('100 means Default{CR}Restart Required for{CR}changes to take effect!') ).grid(column=3, padx=self.PADX, pady=2*self.PADY, sticky=tk.E, row=cur_row) + # Transparency slider + ttk.Separator(appearance_frame, orient=tk.HORIZONTAL).grid( + columnspan=4, padx=self.PADX, pady=self.PADY*4, sticky=tk.EW, row=row.get() + ) + + with row as cur_row: + nb.Label(appearance_frame, text="Main window transparency").grid( + padx=self.PADX, pady=self.PADY*2, sticky=tk.W, row=cur_row + ) + self.transparency = tk.IntVar() + self.transparency.set(config.getint('ui_transparency') or 100) # Default to 100 for users + self.transparency_bar = tk.Scale( + appearance_frame, + variable=self.transparency, + orient=tk.HORIZONTAL, + length=300 * (float(theme.startup_ui_scale) / 100.0 * theme.default_ui_scale), # type: ignore # runtime + from_=100, + to=5, + tickinterval=10, + resolution=5, + command=lambda _: self.parent.wm_attributes("-alpha", self.transparency.get() / 100) + ) + + nb.Label(appearance_frame, text="100 means fully opaque.\nWindow is updated in real time").grid( + column=3, + padx=self.PADX, + pady=self.PADY*2, + sticky=tk.E, + row=cur_row + ) + + self.transparency_bar.grid(column=1, sticky=tk.W, row=cur_row) + # Always on top ttk.Separator(appearance_frame, orient=tk.HORIZONTAL).grid( - columnspan=3, padx=self.PADX, pady=self.PADY*4, sticky=tk.EW, row=row.get() + columnspan=4, padx=self.PADX, pady=self.PADY*4, sticky=tk.EW, row=row.get() ) self.ontop_button = nb.Checkbutton( @@ -1122,6 +1155,7 @@ class PreferencesDialog(tk.Toplevel): Translations.install(config.get_str('language', default=None)) # type: ignore # This sets self in weird ways. config.set('ui_scale', self.ui_scale.get()) + config.set('ui_transparency', self.transparency.get()) config.set('always_ontop', self.always_ontop.get()) config.set('theme', self.theme.get()) config.set('dark_text', self.theme_colors[0]) From 5235019d2ab851fa91ff8c8dd1f40750eb8cf546 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 4 Nov 2020 17:54:30 +0200 Subject: [PATCH 222/727] Added warning Using transparency options on windows may cause unexpected behaviour --- prefs.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/prefs.py b/prefs.py index bc5c38ed..1004a993 100644 --- a/prefs.py +++ b/prefs.py @@ -762,7 +762,14 @@ class PreferencesDialog(tk.Toplevel): command=lambda _: self.parent.wm_attributes("-alpha", self.transparency.get() / 100) ) - nb.Label(appearance_frame, text="100 means fully opaque.\nWindow is updated in real time").grid( + nb.Label( + appearance_frame, + text=( + "100 means fully opaque.\n" + "Window is updated in real time\n" + "do NOT use this with the transparent theme on windows" + ) + ).grid( column=3, padx=self.PADX, pady=self.PADY*2, From 0258d881ea8f12edc1bcce5c8b850707b02a54d7 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 6 Nov 2020 02:48:17 +0200 Subject: [PATCH 223/727] Localised options --- L10n/en.template | 6 ++++++ prefs.py | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index ef8f7399..b92ccc26 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -1,3 +1,9 @@ +/* Label for 'UI Transparency' option in [prefs.py]*/ +"Main window transparency" = "Main window transparency"; + +/* Warning next to 'UI Transparency' slider */ +"100 means fully opaque.{CR}Window is updated in real time{CR}do NOT use this with the transparent theme on windows" = "100 means fully opaque.{CR}Window is updated in real time{CR}do NOT use this with the transparent theme on windows"; + /* Label for 'UI Scaling' option [prefs.py] */ "UI Scale Percentage" = "UI Scale Percentage"; diff --git a/prefs.py b/prefs.py index 1004a993..bf7955ba 100644 --- a/prefs.py +++ b/prefs.py @@ -745,14 +745,14 @@ class PreferencesDialog(tk.Toplevel): ) with row as cur_row: - nb.Label(appearance_frame, text="Main window transparency").grid( + nb.Label(appearance_frame, text=_("Main window transparency")).grid( padx=self.PADX, pady=self.PADY*2, sticky=tk.W, row=cur_row ) self.transparency = tk.IntVar() self.transparency.set(config.getint('ui_transparency') or 100) # Default to 100 for users self.transparency_bar = tk.Scale( appearance_frame, - variable=self.transparency, + variable=self.transparency, # type: ignore # Its accepted as an intvar orient=tk.HORIZONTAL, length=300 * (float(theme.startup_ui_scale) / 100.0 * theme.default_ui_scale), # type: ignore # runtime from_=100, @@ -764,11 +764,11 @@ class PreferencesDialog(tk.Toplevel): nb.Label( appearance_frame, - text=( - "100 means fully opaque.\n" - "Window is updated in real time\n" + text=_( + "100 means fully opaque.{CR}" + "Window is updated in real time{CR}" "do NOT use this with the transparent theme on windows" - ) + ).format(CR='\n') ).grid( column=3, padx=self.PADX, From 2a9ac882cd7c921929cabc12cf023500b95eacd4 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 6 Nov 2020 16:20:58 +0200 Subject: [PATCH 224/727] Added reset UI flag Resets the ui theme to default and the transparency to default --- EDMarketConnector - reset-ui.bat | 1 + EDMarketConnector.py | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 EDMarketConnector - reset-ui.bat diff --git a/EDMarketConnector - reset-ui.bat b/EDMarketConnector - reset-ui.bat new file mode 100644 index 00000000..01db6dfb --- /dev/null +++ b/EDMarketConnector - reset-ui.bat @@ -0,0 +1 @@ +EDMarketConnector.exe --reset-ui diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 4daa26e8..72d26f7e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1445,10 +1445,17 @@ if __name__ == "__main__": "such as EDSM, Inara.cz and EDDB." ) - parser.add_argument('--trace', - help='Set the Debug logging loglevel to TRACE', - action='store_true', - ) + parser.add_argument( + '--trace', + help='Set the Debug logging loglevel to TRACE', + action='store_true', + ) + + parser.add_argument( + '--reset-ui', + help='reset UI theme and transparency to defaults', + action='store_true' + ) args = parser.parse_args() @@ -1466,6 +1473,11 @@ executable: {sys.executable} sys.path: {sys.path}''' ) + if args.reset_ui: + config.set('theme', 0) # 'Default' theme uses ID 0 + config.set('ui_transparency', 100) # 100 is completely opaque + logger.info('reset theme and transparency to default.') + # We prefer a UTF-8 encoding gets set, but older Windows versions have # issues with this. From Windows 10 1903 onwards we can rely on the # manifest ActiveCodePage to set this, but that is silently ignored on From 4692a98f0478f808c92c034fcde11d0deb8f55b1 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 6 Nov 2020 16:24:10 +0200 Subject: [PATCH 225/727] Removed warning from transparency slider --- L10n/en.template | 4 ++-- prefs.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index b92ccc26..1d4f4e07 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -1,8 +1,8 @@ /* Label for 'UI Transparency' option in [prefs.py]*/ "Main window transparency" = "Main window transparency"; -/* Warning next to 'UI Transparency' slider */ -"100 means fully opaque.{CR}Window is updated in real time{CR}do NOT use this with the transparent theme on windows" = "100 means fully opaque.{CR}Window is updated in real time{CR}do NOT use this with the transparent theme on windows"; +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 means fully opaque.{CR}Window is updated in real time"; /* Label for 'UI Scaling' option [prefs.py] */ "UI Scale Percentage" = "UI Scale Percentage"; diff --git a/prefs.py b/prefs.py index bf7955ba..1fe7d3b6 100644 --- a/prefs.py +++ b/prefs.py @@ -766,8 +766,7 @@ class PreferencesDialog(tk.Toplevel): appearance_frame, text=_( "100 means fully opaque.{CR}" - "Window is updated in real time{CR}" - "do NOT use this with the transparent theme on windows" + "Window is updated in real time" ).format(CR='\n') ).grid( column=3, From f7890a460bcd2b2aea4a08c391e4dc3c8af22eb6 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 13 Oct 2020 19:55:40 +0200 Subject: [PATCH 226/727] Added killswitch library Killswitch exists to allow us to disable features causing issues in specific versions remotely. The system is designed to support plugins, where they can request their own killswitch list by querying any web file that follows our format (docs to be added), and using the returned KillSwitchSet to check for disabled features. --- killswitch.py | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 killswitch.py diff --git a/killswitch.py b/killswitch.py new file mode 100644 index 00000000..3847b88a --- /dev/null +++ b/killswitch.py @@ -0,0 +1,150 @@ +"""Fetch kill switches from EDMC Repo.""" +from typing import Dict, List, NamedTuple, Optional, Union, cast + +import requests +import semantic_version + +import config +import EDMCLogging + +logger = EDMCLogging.get_main_logger() + +# DEFAULT_KILLSWITCH_URL = 'https://github.com/EDCD/EDMarketConnector' +DEFAULT_KILLSWITCH_URL = 'http://127.0.0.1:8080/killswitches.json' + +_current_version: semantic_version.Version = semantic_version.Version(config.appversion) + + +class KillSwitch(NamedTuple): + """One version's set of kill switches.""" + + version: semantic_version.Version + kills: List[str] + + +class KillSwitchSet: + """Queryable set of kill switches.""" + + def __init__(self, kill_switches: List[KillSwitch]) -> None: + self.kill_switches = kill_switches + + def is_disabled(self, id: str, *, version=_current_version) -> bool: + """ + Return whether or not the given feature ID is disabled by a killswitch for the given version. + + :param id: The feature ID to check + :param version: The version to check killswitches for, defaults to the current EDMC version + :return: a bool indicating status + """ + for ks in self.kill_switches: + if version != ks.version: + continue + + return id in ks.kills + + return False + + def __str__(self) -> str: + """Return a string representation of KillSwitchSet.""" + return f'KillSwitchSet: {str(self.kill_switches)}' + + def __repr__(self) -> str: + """return __repr__ for KillSwitchSet.""" + return f'KillSwitchSet(kill_switches={self.kill_switches!r})' + + +KILL_SWITCH_JSON = List[Dict[str, Union[str, List[str]]]] +KILL_SWITCH_JSON_DICT = Dict[ + str, Union[ + str, # Last updated + int, # Version + KILL_SWITCH_JSON # kills + ] +] + + +def fetch_kill_switches(target=DEFAULT_KILLSWITCH_URL) -> Optional[KILL_SWITCH_JSON_DICT]: + """ + Fetch the JSON representation of our kill switches. + + :param target: the URL to fetch the kill switch list from, defaults to DEFAULT_KILLSWITCH_URL + :return: a list of dicts containing kill switch data, or None + """ + logger.info("Attempting to fetch kill switches") + try: + data = requests.get(target).json() + + except ValueError as e: + logger.warning(f"Failed to get kill switches, data was invalid: {e}") + return None + + except requests.exceptions.BaseHTTPError as e: + logger.warning(f"unable to connect to {target:r}: {e}") + return None + + return data + + +def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]: + """ + Parse kill switch dict to List of KillSwitches. + + :param data: dict containing raw killswitch data + :return: a list of all provided killswitches + """ + last_updated = data['last_updated'] + ks_version = data['version'] + logger.info(f'Kill switches last updated {last_updated}') + + if ks_version != 1: + logger.warning(f'Unknown killswitch version {ks_version}. Bailing out') + return [] + + kill_switches = cast(KILL_SWITCH_JSON, data['kill_switches']) + out: List[KillSwitch] = [] + + for idx, ks_data in enumerate(kill_switches): + try: + ver = semantic_version.Version(ks_data['version']) + + except ValueError as e: + logger.warning(f'could not parse killswitch idx {idx}: {e}') + continue + + ks = KillSwitch(version=ver, kills=cast(List[str], ks_data['kills'])) + out.append(ks) + + return out + + +active: KillSwitchSet = KillSwitchSet([]) + + +def setup_main_list(): + """ + Set up the global set of kill switches for querying. + + Plugins should NOT call this EVER. + """ + if (data := fetch_kill_switches()) is None: + logger.warning("Unable to fetch kill switches. Setting global set to an empty set") + return + + global active + active = KillSwitchSet(parse_kill_switches(data)) + + +def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> bool: + """ + Query the global KillSwitchSet for whether or not a given ID is disabled. + + See KillSwitchSet#is_disabled for more information + """ + return active.is_disabled(id, version=version) + + +if __name__ == "__main__": + setup_main_list() + print(f'{_current_version=}') + print(f"{is_disabled('test')=}") + print(f"{active=}") From 29adaa413b1a6ffe02fb08556e678e1962810cdb Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 14 Oct 2020 21:30:18 +0200 Subject: [PATCH 227/727] Added util method for URL -> KillSwitchSet --- killswitch.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/killswitch.py b/killswitch.py index 3847b88a..13c1b124 100644 --- a/killswitch.py +++ b/killswitch.py @@ -1,4 +1,5 @@ """Fetch kill switches from EDMC Repo.""" +from ast import parse from typing import Dict, List, NamedTuple, Optional, Union, cast import requests @@ -49,7 +50,7 @@ class KillSwitchSet: return f'KillSwitchSet: {str(self.kill_switches)}' def __repr__(self) -> str: - """return __repr__ for KillSwitchSet.""" + """Return __repr__ for KillSwitchSet.""" return f'KillSwitchSet(kill_switches={self.kill_switches!r})' @@ -117,6 +118,20 @@ def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]: return out +def get_kill_switches(target=DEFAULT_KILLSWITCH_URL) -> Optional[KillSwitchSet]: + """ + Get a kill switch set object. + + :param target: the URL to fetch the killswitch JSON from, defaults to DEFAULT_KILLSWITCH_URL + :return: the KillSwitchSet for the URL, or None if there was an error + """ + if (data := fetch_kill_switches(target)) is None: + logger.warning('could not get killswitches') + return None + + return KillSwitchSet(parse_kill_switches(data)) + + active: KillSwitchSet = KillSwitchSet([]) From 517a0e1f7cfdc90bd86640b368310f7c01bdb4c5 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 16 Oct 2020 08:06:39 +0200 Subject: [PATCH 228/727] Added timeout to GET for killswitches --- killswitch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/killswitch.py b/killswitch.py index 13c1b124..bb674c53 100644 --- a/killswitch.py +++ b/killswitch.py @@ -1,5 +1,4 @@ """Fetch kill switches from EDMC Repo.""" -from ast import parse from typing import Dict, List, NamedTuple, Optional, Union, cast import requests @@ -73,7 +72,7 @@ def fetch_kill_switches(target=DEFAULT_KILLSWITCH_URL) -> Optional[KILL_SWITCH_J """ logger.info("Attempting to fetch kill switches") try: - data = requests.get(target).json() + data = requests.get(target, timeout=10).json() except ValueError as e: logger.warning(f"Failed to get kill switches, data was invalid: {e}") From d81093760edb5669d104d46cd68cb5f970c0777d Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 18 Oct 2020 08:51:34 +0200 Subject: [PATCH 229/727] Added hooks into killswitches in plugins --- plugins/eddn.py | 11 ++++++++--- plugins/edsm.py | 5 +++++ plugins/inara.py | 6 +++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index b19227cf..06875fdb 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -10,12 +10,13 @@ from collections import OrderedDict from os import SEEK_SET from os.path import join from platform import system -from typing import TYPE_CHECKING, Any, AnyStr, Dict, Iterator, List, Mapping, MutableMapping, Optional, Tuple +from typing import TYPE_CHECKING, Any, AnyStr, Dict, Iterator, List, Mapping, MutableMapping, Optional from typing import OrderedDict as OrderedDictT -from typing import Sequence, TextIO +from typing import Sequence, TextIO, Tuple import requests +import killswitch import myNotebook as nb # noqa: N813 from companion import CAPIData, category_map from config import applongname, appversion, config @@ -25,7 +26,7 @@ from prefs import prefsVersion from ttkHyperlinkLabel import HyperlinkLabel if sys.platform != 'win32': - from fcntl import lockf, LOCK_EX, LOCK_NB + from fcntl import LOCK_EX, LOCK_NB, lockf if TYPE_CHECKING: @@ -126,6 +127,10 @@ class EDDN: :param cmdr: the CMDR to use as the uploader ID :param msg: the payload to send """ + if killswitch.is_disabled('plugins.eddn_send'): + logger.warning("eddn.send has been disabled via killswitch. Returning") + return + uploader_id = cmdr to_send: OrderedDictT[str, str] = OrderedDict([ diff --git a/plugins/edsm.py b/plugins/edsm.py index 566f910b..1fb6704e 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -19,6 +19,7 @@ from typing import TYPE_CHECKING, Any, List, Mapping, MutableMapping, Optional, import requests +import killswitch import myNotebook as nb # noqa: N813 import plug from config import applongname, appversion, config @@ -508,6 +509,10 @@ def worker() -> None: logger.debug('Empty queue message, setting closing = True') closing = True # Try to send any unsent events before we close + if killswitch.is_disabled("plugins.eddn.worker"): + logger.warning('EDSM worker has been disabled via kill switch. Not uploading data.') + continue + retrying = 0 while retrying < 3: try: diff --git a/plugins/inara.py b/plugins/inara.py index 0db096c0..8a5cfa11 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1,6 +1,5 @@ """Inara Sync.""" -from companion import CAPIData import dataclasses import json import sys @@ -17,9 +16,11 @@ from typing import Sequence, Union, cast import requests +import killswitch import myNotebook as nb # noqa: N813 import plug import timeout_session +from companion import CAPIData from config import applongname, appversion, config from EDMCLogging import get_main_logger from ttkHyperlinkLabel import HyperlinkLabel @@ -1202,6 +1203,9 @@ def new_worker(): logger.debug('Starting...') while True: events = get_events() + if killswitch.is_disabled("plugins.inara.worker"): + logger.warning("Inara worker disabled via killswitch") + return for creds, event_list in events.items(): if not event_list: From c96e59f7b3de41603e6f2c99ad1cf98271391414 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 18 Oct 2020 08:52:02 +0200 Subject: [PATCH 230/727] Added fetch killswitch task on start --- EDMarketConnector.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 72d26f7e..d7e3f8f4 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -12,6 +12,7 @@ import webbrowser from builtins import object, str from os import chdir, environ from os.path import dirname, isdir, join +import killswitch from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple, cast @@ -1565,6 +1566,9 @@ sys.path: {sys.path}''' Translations.install(config.get_str('language')) # Can generate errors so wait til log set up + logger.debug('fetching killswitches...') + killswitch.setup_main_list() + root = tk.Tk(className=appname.lower()) # UI Scaling From 2d127ae3d0568aa5f44fa0218ebceb286518933d Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 19 Oct 2020 10:25:52 +0200 Subject: [PATCH 231/727] Added docs, fixed incorrect kill switch names --- docs/Killswitches.md | 53 ++++++++++++++++++++++++++++++++++++++++++++ plugins/eddn.py | 2 +- plugins/edsm.py | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 docs/Killswitches.md diff --git a/docs/Killswitches.md b/docs/Killswitches.md new file mode 100644 index 00000000..c24197e1 --- /dev/null +++ b/docs/Killswitches.md @@ -0,0 +1,53 @@ +# Kill Switches + +EDMarketConnector implements a Kill Switch system that allows us to disable features based on a version mask. Meaning that we can stop major bugs from affecting the services we support, at the expense of disabling that support. + +## Format + +Killswitches are stored in a JSON file that is queried by EDMC on startup. The format is as follows: + +| Key | Type | Description | +| --------------: | :-----: | :------------------------------------------------------------ | +| `version` | integer | the version of the Kill Switch JSON file, always 1 | +| `last_updated` | string | When last the kill switches were updated (for human use only) | +| `kill_switches` | array | The kill switches this file contains (expanded below) | + +The `kill_switches` array contains kill switch objects. Each contains two fields: + +| Key | Type | Description | +| --------: | :----------------: | :---------------------------------------------------------------------- | +| `version` | `semantic version` | The version of EDMC these kill switches apply to (Must be valid semver) | +| `kills` | array of strings | The different keys to disable | +An example follows: + +```json +{ + "version": 1, + "last_updated": "19 October 2020", + "kill_switches": [ + { + "version": "1.0.0", + "kills": ["plugins.eddn.send"] + } + ] +} +``` + +### Versions + +Versions are checked using equality checks on `semantic_version.Version` instances. Meaning that **all** fields are checked (ie, Major, Minor, Patch, Prerelease, and Build). + +## Plugin support + +Plugins may use the killswitch system simply by hosting their own version of the killswitch file, and fetching it +using `killswitch.get_kill_switches(target='https://example.com/myplugin_killswitches.json')`. The returned object can +be used to query the kill switch set, see the docstrings for more information on specifying versions. + +## Currently supported killswitch strings + +The current recognised (to EDMC and its internal plugins) killswitch strings are as follows: +| Kill Switch | Description | +| :--------------------- | :---------------------------------------------------------------------------------------- | +| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | +| `plugins.edsm.worker` | Disables the send portion of the EDSM worker thread (effectively disables EDSM updates) | +| `plugins.inara.worker` | Disables the send portion of the INARA worker thread (effectively disables INARA updates) | diff --git a/plugins/eddn.py b/plugins/eddn.py index 06875fdb..e4813b88 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -127,7 +127,7 @@ class EDDN: :param cmdr: the CMDR to use as the uploader ID :param msg: the payload to send """ - if killswitch.is_disabled('plugins.eddn_send'): + if killswitch.is_disabled('plugins.eddn.send'): logger.warning("eddn.send has been disabled via killswitch. Returning") return diff --git a/plugins/edsm.py b/plugins/edsm.py index 1fb6704e..d6e0f706 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -509,7 +509,7 @@ def worker() -> None: logger.debug('Empty queue message, setting closing = True') closing = True # Try to send any unsent events before we close - if killswitch.is_disabled("plugins.eddn.worker"): + if killswitch.is_disabled("plugins.edsm.worker"): logger.warning('EDSM worker has been disabled via kill switch. Not uploading data.') continue From 98b27ee0463f7071840d01b4ff029995b5ca8c87 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 23 Oct 2020 12:40:21 +0200 Subject: [PATCH 232/727] Fixed startup exception when unable to connect --- killswitch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/killswitch.py b/killswitch.py index bb674c53..226f8ca0 100644 --- a/killswitch.py +++ b/killswitch.py @@ -78,8 +78,8 @@ def fetch_kill_switches(target=DEFAULT_KILLSWITCH_URL) -> Optional[KILL_SWITCH_J logger.warning(f"Failed to get kill switches, data was invalid: {e}") return None - except requests.exceptions.BaseHTTPError as e: - logger.warning(f"unable to connect to {target:r}: {e}") + except (requests.exceptions.BaseHTTPError, requests.exceptions.ConnectionError) as e: + logger.warning(f"unable to connect to {target!r}: {e}") return None return data From 10ca50bf5a2d7d3c42c601c81aff21a643b02436 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 24 Oct 2020 09:33:16 +0200 Subject: [PATCH 233/727] Moved edsm killswitch check It was causing exit hangs when edsm was disabled --- plugins/edsm.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/edsm.py b/plugins/edsm.py index d6e0f706..67ae4db8 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -509,12 +509,11 @@ def worker() -> None: logger.debug('Empty queue message, setting closing = True') closing = True # Try to send any unsent events before we close - if killswitch.is_disabled("plugins.edsm.worker"): - logger.warning('EDSM worker has been disabled via kill switch. Not uploading data.') - continue - retrying = 0 while retrying < 3: + if killswitch.is_disabled("plugins.edsm.worker"): + logger.warning('EDSM worker has been disabled via kill switch. Not uploading data.') + break try: if TYPE_CHECKING: # Tell the type checker that these two are bound. From f10cd9d70f8998a8838e8efdb2a24fc2c56a7fb6 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 24 Oct 2020 09:34:36 +0200 Subject: [PATCH 234/727] Dont exit inara worker thread --- plugins/inara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inara.py b/plugins/inara.py index 8a5cfa11..4f7d8d5a 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1205,7 +1205,7 @@ def new_worker(): events = get_events() if killswitch.is_disabled("plugins.inara.worker"): logger.warning("Inara worker disabled via killswitch") - return + continue for creds, event_list in events.items(): if not event_list: From d5b62d957b2cc5730c7ad7eed19f268050b5e6d0 Mon Sep 17 00:00:00 2001 From: A_D Date: Sat, 24 Oct 2020 16:19:27 +0200 Subject: [PATCH 235/727] Added support for comments in kill switches --- docs/Killswitches.md | 16 +++++++++------- killswitch.py | 21 ++++++++++++++------- plugins/eddn.py | 4 ++-- plugins/edsm.py | 6 ++++-- plugins/inara.py | 4 ++-- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index c24197e1..5ea69268 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -6,18 +6,18 @@ EDMarketConnector implements a Kill Switch system that allows us to disable feat Killswitches are stored in a JSON file that is queried by EDMC on startup. The format is as follows: -| Key | Type | Description | -| --------------: | :-----: | :------------------------------------------------------------ | -| `version` | integer | the version of the Kill Switch JSON file, always 1 | -| `last_updated` | string | When last the kill switches were updated (for human use only) | -| `kill_switches` | array | The kill switches this file contains (expanded below) | +| Key | Type | Description | +| --------------: | :------: | :------------------------------------------------------------ | +| `version` | `int` | the version of the Kill Switch JSON file, always 1 | +| `last_updated` | `string` | When last the kill switches were updated (for human use only) | +| `kill_switches` | `array` | The kill switches this file contains (expanded below) | The `kill_switches` array contains kill switch objects. Each contains two fields: | Key | Type | Description | | --------: | :----------------: | :---------------------------------------------------------------------- | | `version` | `semantic version` | The version of EDMC these kill switches apply to (Must be valid semver) | -| `kills` | array of strings | The different keys to disable | +| `kills` | `Dict[str, str]` | The different keys to disable, and the reason for the disable | An example follows: ```json @@ -27,7 +27,9 @@ An example follows: "kill_switches": [ { "version": "1.0.0", - "kills": ["plugins.eddn.send"] + "kills": { + "plugins.eddn.send": "some reason" + } } ] } diff --git a/killswitch.py b/killswitch.py index 226f8ca0..c6139527 100644 --- a/killswitch.py +++ b/killswitch.py @@ -1,5 +1,5 @@ """Fetch kill switches from EDMC Repo.""" -from typing import Dict, List, NamedTuple, Optional, Union, cast +from typing import Dict, List, NamedTuple, Optional, Tuple, Union, cast import requests import semantic_version @@ -19,7 +19,14 @@ class KillSwitch(NamedTuple): """One version's set of kill switches.""" version: semantic_version.Version - kills: List[str] + kills: Dict[str, str] + + +class DisabledResult(NamedTuple): + """DisabledResult is the result returned from various is_disabled calls.""" + + disbled: bool + reason: str class KillSwitchSet: @@ -28,7 +35,7 @@ class KillSwitchSet: def __init__(self, kill_switches: List[KillSwitch]) -> None: self.kill_switches = kill_switches - def is_disabled(self, id: str, *, version=_current_version) -> bool: + def is_disabled(self, id: str, *, version=_current_version) -> DisabledResult: """ Return whether or not the given feature ID is disabled by a killswitch for the given version. @@ -40,9 +47,9 @@ class KillSwitchSet: if version != ks.version: continue - return id in ks.kills + return DisabledResult(id in ks.kills, ks.kills.get(id, "")) - return False + return DisabledResult(False, "") def __str__(self) -> str: """Return a string representation of KillSwitchSet.""" @@ -111,7 +118,7 @@ def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]: logger.warning(f'could not parse killswitch idx {idx}: {e}') continue - ks = KillSwitch(version=ver, kills=cast(List[str], ks_data['kills'])) + ks = KillSwitch(version=ver, kills=cast(Dict[str, str], ks_data['kills'])) out.append(ks) return out @@ -148,7 +155,7 @@ def setup_main_list(): active = KillSwitchSet(parse_kill_switches(data)) -def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> bool: +def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> DisabledResult: """ Query the global KillSwitchSet for whether or not a given ID is disabled. diff --git a/plugins/eddn.py b/plugins/eddn.py index e4813b88..d952b219 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -127,8 +127,8 @@ class EDDN: :param cmdr: the CMDR to use as the uploader ID :param msg: the payload to send """ - if killswitch.is_disabled('plugins.eddn.send'): - logger.warning("eddn.send has been disabled via killswitch. Returning") + if (res := killswitch.is_disabled('plugins.eddn.send')).disbled: + logger.warning(f"eddn.send has been disabled via killswitch. Returning. ({res.reason})") return uploader_id = cmdr diff --git a/plugins/edsm.py b/plugins/edsm.py index 67ae4db8..4260e280 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -511,8 +511,10 @@ def worker() -> None: retrying = 0 while retrying < 3: - if killswitch.is_disabled("plugins.edsm.worker"): - logger.warning('EDSM worker has been disabled via kill switch. Not uploading data.') + if (res := killswitch.is_disabled("plugins.edsm.worker")).disbled: + logger.warning( + f'EDSM worker has been disabled via kill switch. Not uploading data. ({res.reason})' + ) break try: if TYPE_CHECKING: diff --git a/plugins/inara.py b/plugins/inara.py index 4f7d8d5a..abdfe7b9 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1203,8 +1203,8 @@ def new_worker(): logger.debug('Starting...') while True: events = get_events() - if killswitch.is_disabled("plugins.inara.worker"): - logger.warning("Inara worker disabled via killswitch") + if (res := killswitch.is_disabled("plugins.inara.worker")).disbled: + logger.warning(f"Inara worker disabled via killswitch. ({res.reason})") continue for creds, event_list in events.items(): From 8dca6783fc4719e56db17fc8ab7b93c93307a75c Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 11:03:37 +0200 Subject: [PATCH 236/727] Fixed spelling, added utility methods --- killswitch.py | 30 ++++++++++++++++++++++++------ plugins/eddn.py | 2 +- plugins/edsm.py | 2 +- plugins/inara.py | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/killswitch.py b/killswitch.py index c6139527..da56abd6 100644 --- a/killswitch.py +++ b/killswitch.py @@ -1,5 +1,5 @@ """Fetch kill switches from EDMC Repo.""" -from typing import Dict, List, NamedTuple, Optional, Tuple, Union, cast +from typing import Dict, List, NamedTuple, Optional, Union, cast import requests import semantic_version @@ -25,7 +25,7 @@ class KillSwitch(NamedTuple): class DisabledResult(NamedTuple): """DisabledResult is the result returned from various is_disabled calls.""" - disbled: bool + disabled: bool reason: str @@ -35,13 +35,13 @@ class KillSwitchSet: def __init__(self, kill_switches: List[KillSwitch]) -> None: self.kill_switches = kill_switches - def is_disabled(self, id: str, *, version=_current_version) -> DisabledResult: + def get_disabled(self, id: str, *, version=_current_version) -> DisabledResult: """ Return whether or not the given feature ID is disabled by a killswitch for the given version. :param id: The feature ID to check :param version: The version to check killswitches for, defaults to the current EDMC version - :return: a bool indicating status + :return: a namedtuple indicating status and reason, if any """ for ks in self.kill_switches: if version != ks.version: @@ -51,6 +51,14 @@ class KillSwitchSet: return DisabledResult(False, "") + def is_disabled(self, id: str, *, version=_current_version) -> bool: + """Return whether or not a given feature ID is disabled for the given version.""" + return self.get_disabled(id, version=version).disabled + + def get_reason(self, id: str, version=_current_version) -> str: + """Return a reason for why the given id is disabled for the given version, if any.""" + return self.get_disabled(id, version=version).reason + def __str__(self) -> str: """Return a string representation of KillSwitchSet.""" return f'KillSwitchSet: {str(self.kill_switches)}' @@ -155,17 +163,27 @@ def setup_main_list(): active = KillSwitchSet(parse_kill_switches(data)) -def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> DisabledResult: +def get_disabled(id: str, *, version: semantic_version.Version = _current_version) -> DisabledResult: """ Query the global KillSwitchSet for whether or not a given ID is disabled. See KillSwitchSet#is_disabled for more information """ + return active.get_disabled(id, version=version) + + +def is_disabled(id: str, *, version=_current_version) -> bool: + """Query the global KillSwitchSet#is_disabled method.""" return active.is_disabled(id, version=version) +def get_reason(id: str, *, version=_current_version) -> str: + """Query the global KillSwitchSet#get_reason method.""" + return active.get_reason(id, version=version) + + if __name__ == "__main__": setup_main_list() print(f'{_current_version=}') - print(f"{is_disabled('test')=}") + print(f"{get_disabled('test')=}") print(f"{active=}") diff --git a/plugins/eddn.py b/plugins/eddn.py index d952b219..1fcde025 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -127,7 +127,7 @@ class EDDN: :param cmdr: the CMDR to use as the uploader ID :param msg: the payload to send """ - if (res := killswitch.is_disabled('plugins.eddn.send')).disbled: + if (res := killswitch.get_disabled('plugins.eddn.send')).disabled: logger.warning(f"eddn.send has been disabled via killswitch. Returning. ({res.reason})") return diff --git a/plugins/edsm.py b/plugins/edsm.py index 4260e280..306c20e4 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -511,7 +511,7 @@ def worker() -> None: retrying = 0 while retrying < 3: - if (res := killswitch.is_disabled("plugins.edsm.worker")).disbled: + if (res := killswitch.get_disabled("plugins.edsm.worker")).disabled: logger.warning( f'EDSM worker has been disabled via kill switch. Not uploading data. ({res.reason})' ) diff --git a/plugins/inara.py b/plugins/inara.py index abdfe7b9..1543be1b 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1203,7 +1203,7 @@ def new_worker(): logger.debug('Starting...') while True: events = get_events() - if (res := killswitch.is_disabled("plugins.inara.worker")).disbled: + if (res := killswitch.get_disabled("plugins.inara.worker")).disabled: logger.warning(f"Inara worker disabled via killswitch. ({res.reason})") continue From 6b7517919918faf72698aa4e2c135f2b59ca9465 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 18:48:28 +0200 Subject: [PATCH 237/727] switched to using SimpleSpec for constraints --- docs/Killswitches.md | 10 +++++----- killswitch.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index 5ea69268..f4ea5145 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -14,10 +14,10 @@ Killswitches are stored in a JSON file that is queried by EDMC on startup. The f The `kill_switches` array contains kill switch objects. Each contains two fields: -| Key | Type | Description | -| --------: | :----------------: | :---------------------------------------------------------------------- | -| `version` | `semantic version` | The version of EDMC these kill switches apply to (Must be valid semver) | -| `kills` | `Dict[str, str]` | The different keys to disable, and the reason for the disable | +| Key | Type | Description | +| --------: | :--------------: | :--------------------------------------------------------------------------- | +| `version` | `version spec` | The version of EDMC these kill switches apply to (Must be valid semver spec) | +| `kills` | `Dict[str, str]` | The different keys to disable, and the reason for the disable | An example follows: ```json @@ -37,7 +37,7 @@ An example follows: ### Versions -Versions are checked using equality checks on `semantic_version.Version` instances. Meaning that **all** fields are checked (ie, Major, Minor, Patch, Prerelease, and Build). +Versions are checked using contains checks on `semantic_version.SimpleSpec` instances. ## Plugin support diff --git a/killswitch.py b/killswitch.py index da56abd6..b2336111 100644 --- a/killswitch.py +++ b/killswitch.py @@ -18,7 +18,7 @@ _current_version: semantic_version.Version = semantic_version.Version(config.app class KillSwitch(NamedTuple): """One version's set of kill switches.""" - version: semantic_version.Version + version: semantic_version.SimpleSpec kills: Dict[str, str] @@ -44,7 +44,7 @@ class KillSwitchSet: :return: a namedtuple indicating status and reason, if any """ for ks in self.kill_switches: - if version != ks.version: + if version not in ks.version: continue return DisabledResult(id in ks.kills, ks.kills.get(id, "")) @@ -120,7 +120,7 @@ def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]: for idx, ks_data in enumerate(kill_switches): try: - ver = semantic_version.Version(ks_data['version']) + ver = semantic_version.SimpleSpec(ks_data['version']) except ValueError as e: logger.warning(f'could not parse killswitch idx {idx}: {e}') From 70087a27e44adb61db4decb9825d87c6588a4179 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 29 Oct 2020 13:17:59 +0200 Subject: [PATCH 238/727] Added total journal cutoff killswitches --- docs/Killswitches.md | 14 +++++++++----- plugins/eddb.py | 18 ++++++++++++++++-- plugins/eddn.py | 6 ++++++ plugins/edsm.py | 5 +++++ plugins/inara.py | 5 +++++ 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index f4ea5145..d9b5930c 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -48,8 +48,12 @@ be used to query the kill switch set, see the docstrings for more information on ## Currently supported killswitch strings The current recognised (to EDMC and its internal plugins) killswitch strings are as follows: -| Kill Switch | Description | -| :--------------------- | :---------------------------------------------------------------------------------------- | -| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | -| `plugins.edsm.worker` | Disables the send portion of the EDSM worker thread (effectively disables EDSM updates) | -| `plugins.inara.worker` | Disables the send portion of the INARA worker thread (effectively disables INARA updates) | +| Kill Switch | Description | +| :---------------------- | :---------------------------------------------------------------------------------------- | +| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | +| `plugins.eddn.journal` | Disables all journal processing for EDDN | +| `plugins.edsm.worker` | Disables the send portion of the EDSM worker thread (effectively disables EDSM updates) | +| `plugins.edsm.journal` | Disables all journal processing for EDSM | +| `plugins.inara.worker` | Disables the send portion of the INARA worker thread (effectively disables INARA updates) | +| `plugins.inara.journal` | Disables all journal processing for INARA | +| `plugins.eddn.journal` | Disables all journal processing for EDDN | diff --git a/plugins/eddb.py b/plugins/eddb.py index 12ebc8ed..bd6b154f 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -23,17 +23,24 @@ # -from companion import CAPIData import sys -from typing import Any, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Optional + import requests +import EDMCLogging +import killswitch +import plug +from companion import CAPIData from config import config if TYPE_CHECKING: from tkinter import Tk +logger = EDMCLogging.get_main_logger() + + STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7 this: Any = sys.modules[__name__] # For holding module globals @@ -64,6 +71,7 @@ def station_url(system_name: str, station_name: str) -> str: return system_url(system_name) + def plugin_start3(plugin_dir): return 'eddb' @@ -83,7 +91,13 @@ def prefs_changed(cmdr, is_beta): # through correctly. We don't want a static string. pass + def journal_entry(cmdr, is_beta, system, station, entry, state): + if (ks := killswitch.get_disabled('plugins.eddb.journal')).disabled: + logger.warning(f'Journal processing for EDDB has been disabled: {ks.reason}') + plug.show_error('EDDB Journal processing disabled. See Log') + return + # Always update our system address even if we're not currently the provider for system or station, but dont update # on events that contain "future" data, such as FSDTarget if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'): diff --git a/plugins/eddn.py b/plugins/eddn.py index 1fcde025..eac1b0d3 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -18,6 +18,7 @@ import requests import killswitch import myNotebook as nb # noqa: N813 +import plug from companion import CAPIData, category_map from config import applongname, appversion, config from EDMCLogging import get_main_logger @@ -609,6 +610,11 @@ def plugin_stop() -> None: def journal_entry( # noqa: C901 cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any] ) -> Optional[str]: + if (ks := killswitch.get_disabled("plugins.eddn.journal")).disabled: + logger.warning(f"EDDN journal handler has been disabled via killswitch: {ks.reason}") + plug.show_error("EDDN journal handler disabled. See Log.") + return + # Recursively filter '*_Localised' keys from dict def filter_localised(d: Mapping[str, Any]) -> OrderedDictT[str, Any]: filtered: OrderedDictT[str, Any] = OrderedDict() diff --git a/plugins/edsm.py b/plugins/edsm.py index 306c20e4..970b26f2 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -339,6 +339,11 @@ def journal_entry( cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any] ) -> None: """Journal Entry hook.""" + if (ks := killswitch.get_disabled("plugins.edsm.journal")).disabled: + logger.warning(f"EDSM Journal handler disabled via killswitch: {ks.reason}") + plug.show_error("EDSM Handler disabled. See Log.") + return + if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): logger.trace(f'''{entry["event"]} Commander: {cmdr} diff --git a/plugins/inara.py b/plugins/inara.py index 1543be1b..729e4b9e 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -322,6 +322,11 @@ def journal_entry( cmdr: str, is_beta: bool, system: str, station: str, entry: Dict[str, Any], state: Dict[str, Any] ) -> None: """Journal entry hook.""" + if (ks := killswitch.get_disabled("plugins.inara.journal")).disabled: + logger.warning(f"INARA support has been disabled via killswitch: {ks.reason}") + plug.show_error("INARA disabled. See Log.") + return + event_name: str = entry['event'] this.cmdr = cmdr this.FID = state['FID'] From 6374fbbeb86272a5e5e89d700acf8d35778c35b6 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 29 Oct 2020 14:44:32 +0200 Subject: [PATCH 239/727] Added event disabling You can now disable specific event handlers in plugins --- docs/Killswitches.md | 15 ++++++--------- plugins/eddb.py | 3 +++ plugins/eddn.py | 3 +++ plugins/edsm.py | 9 ++++++--- plugins/inara.py | 7 ++++--- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index d9b5930c..8603d10d 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -48,12 +48,9 @@ be used to query the kill switch set, see the docstrings for more information on ## Currently supported killswitch strings The current recognised (to EDMC and its internal plugins) killswitch strings are as follows: -| Kill Switch | Description | -| :---------------------- | :---------------------------------------------------------------------------------------- | -| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | -| `plugins.eddn.journal` | Disables all journal processing for EDDN | -| `plugins.edsm.worker` | Disables the send portion of the EDSM worker thread (effectively disables EDSM updates) | -| `plugins.edsm.journal` | Disables all journal processing for EDSM | -| `plugins.inara.worker` | Disables the send portion of the INARA worker thread (effectively disables INARA updates) | -| `plugins.inara.journal` | Disables all journal processing for INARA | -| `plugins.eddn.journal` | Disables all journal processing for EDDN | +| Kill Switch | Description | +| :--------------------------------------------------- | :------------------------------------------------------------------------------------------- | +| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | +| `plugins.(eddn|inara|edsm|eddb).journal` | Disables all journal processing for EDDN/EDSM/INARA | +| `plugins.(edsm|inara).worker` | Disables the EDSM/INARA worker thread (effectively disables updates) (does not close thread) | +| `plugins.(eddn|inara|edsm).journal.event.$eventname` | Specific events to disable processing for | diff --git a/plugins/eddb.py b/plugins/eddb.py index bd6b154f..1886b410 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -97,6 +97,9 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): logger.warning(f'Journal processing for EDDB has been disabled: {ks.reason}') plug.show_error('EDDB Journal processing disabled. See Log') return + elif (ks := killswitch.get_disabled(f'plugins.eddb.journal.event.{entry["event"]}')).disabled: + logger.warning(f'Processing of event {entry["event"]} has been disabled: {ks.reason}') + return # Always update our system address even if we're not currently the provider for system or station, but dont update # on events that contain "future" data, such as FSDTarget diff --git a/plugins/eddn.py b/plugins/eddn.py index eac1b0d3..61624246 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -614,6 +614,9 @@ def journal_entry( # noqa: C901 logger.warning(f"EDDN journal handler has been disabled via killswitch: {ks.reason}") plug.show_error("EDDN journal handler disabled. See Log.") return + elif (ks := killswitch.get_disabled(f'plugins.eddn.journal.event{entry["name"]}')).disabled: + logger.warning(f'Handling of event {entry["name"]} disabled via killswitch: {ks.reason}') + return # Recursively filter '*_Localised' keys from dict def filter_localised(d: Mapping[str, Any]) -> OrderedDictT[str, Any]: diff --git a/plugins/edsm.py b/plugins/edsm.py index 970b26f2..f3f8479e 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -339,9 +339,12 @@ def journal_entry( cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any] ) -> None: """Journal Entry hook.""" - if (ks := killswitch.get_disabled("plugins.edsm.journal")).disabled: - logger.warning(f"EDSM Journal handler disabled via killswitch: {ks.reason}") - plug.show_error("EDSM Handler disabled. See Log.") + if (ks := killswitch.get_disabled('plugins.edsm.journal')).disabled: + logger.warning(f'EDSM Journal handler disabled via killswitch: {ks.reason}') + plug.show_error('EDSM Handler disabled. See Log.') + return + elif (ks := killswitch.get_disabled(f'plugins.edsm.journal.event.{entry["name"]}')).disabled: + logger.warning(f'Handling of event {entry["name"]} has been disabled via killswitch: {ks.reason}') return if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): diff --git a/plugins/inara.py b/plugins/inara.py index 729e4b9e..f48a9d31 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -322,10 +322,11 @@ def journal_entry( cmdr: str, is_beta: bool, system: str, station: str, entry: Dict[str, Any], state: Dict[str, Any] ) -> None: """Journal entry hook.""" - if (ks := killswitch.get_disabled("plugins.inara.journal")).disabled: - logger.warning(f"INARA support has been disabled via killswitch: {ks.reason}") - plug.show_error("INARA disabled. See Log.") + if (ks := killswitch.get_disabled('plugins.inara.journal')).disabled: + logger.warning(f'INARA support has been disabled via killswitch: {ks.reason}') + plug.show_error('INARA disabled. See Log.') return + elif (ks := killswitch.get_disabled(f'')) event_name: str = entry['event'] this.cmdr = cmdr From 81e2cd2f92cc21d1ebaddbcdc26b7223e48bc4aa Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 3 Nov 2020 17:52:21 +0200 Subject: [PATCH 240/727] Added warning popup on start Popup shows on start when there are killswitches that match the current version. --- EDMarketConnector.py | 52 ++++++++++++++++++++++++++++++++++++++++---- killswitch.py | 22 +++++++++++++++---- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index d7e3f8f4..55915717 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1435,6 +1435,50 @@ Locale LC_TIME: {locale.getlocale(locale.LC_TIME)}''' ) +def setup_killswitches(): + """Download and setup the main killswitch list.""" + logger.debug('fetching killswitches...') + killswitch.setup_main_list() + + +def show_killswitch_poppup(root=None): + """Show a warning popup if there are any killswitches that match the current version.""" + if len(kills := killswitch.kills_for_version()) == 0: + return + + text = ( + "Some EDMC Features have been disabled for known issues.\n" + "Please update EDMC as soon as possible to resolve any issues.\n" + ) + + tl = tk.Toplevel(root) + tl.wm_attributes('-topmost', True) + tl.geometry(f'+{root.winfo_rootx()}+{root.winfo_rooty()}') + + tl.columnconfigure(1, weight=1) + tl.title("EDMC Features have been disabled") + + frame = tk.Frame(tl) + frame.grid() + t = tk.Label(frame, text=text) + t.grid(columnspan=2) + idx = 1 + + for version in kills: + tk.Label(frame, text=f'Version: {version.version}').grid(row=idx, sticky=tk.W) + idx += 1 + for id, reason in version.kills.items(): + tk.Label(frame, text=id).grid(column=0, row=idx, sticky=tk.W, padx=(10, 0)) + tk.Label(frame, text=reason).grid(column=1, row=idx, sticky=tk.E, padx=(0, 10)) + idx += 1 + idx += 1 + + ok_button = tk.Button(frame, text="ok", command=tl.destroy) + ok_button.grid(columnspan=2, sticky=tk.EW) + + theme.apply(tl) + + # Run the app if __name__ == "__main__": # Command-line arguments @@ -1531,7 +1575,8 @@ sys.path: {sys.path}''' except Exception: logger.exception( - f"Exception other than locale.Error on setting LC_ALL=('{locale_startup[0]}', 'UTF_8')") + f"Exception other than locale.Error on setting LC_ALL=('{locale_startup[0]}', 'UTF_8')" + ) else: log_locale('After switching to UTF-8 encoding (same language)') @@ -1566,9 +1611,7 @@ sys.path: {sys.path}''' Translations.install(config.get_str('language')) # Can generate errors so wait til log set up - logger.debug('fetching killswitches...') - killswitch.setup_main_list() - + setup_killswitches() root = tk.Tk(className=appname.lower()) # UI Scaling @@ -1622,6 +1665,7 @@ sys.path: {sys.path}''' root.wm_attributes('-alpha', ui_transparency / 100) root.after(0, messagebox_not_py3) + root.after(1, show_killswitch_poppup, root) root.mainloop() logger.info('Exiting') diff --git a/killswitch.py b/killswitch.py index b2336111..44c92177 100644 --- a/killswitch.py +++ b/killswitch.py @@ -51,14 +51,23 @@ class KillSwitchSet: return DisabledResult(False, "") - def is_disabled(self, id: str, *, version=_current_version) -> bool: + def is_disabled(self, id: str, *, version: semantic_version.Version = _current_version) -> bool: """Return whether or not a given feature ID is disabled for the given version.""" return self.get_disabled(id, version=version).disabled - def get_reason(self, id: str, version=_current_version) -> str: + def get_reason(self, id: str, version: semantic_version.Version = _current_version) -> str: """Return a reason for why the given id is disabled for the given version, if any.""" return self.get_disabled(id, version=version).reason + def kills_for_version(self, version: semantic_version.Version = _current_version) -> List[KillSwitch]: + """ + Get all killswitch entries that apply to the given version. + + :param version: the version to check against, defaults to the current EDMC version + :return: the matching kill switches + """ + return [k for k in self.kill_switches if version in k.version] + def __str__(self) -> str: """Return a string representation of KillSwitchSet.""" return f'KillSwitchSet: {str(self.kill_switches)}' @@ -172,16 +181,21 @@ def get_disabled(id: str, *, version: semantic_version.Version = _current_versio return active.get_disabled(id, version=version) -def is_disabled(id: str, *, version=_current_version) -> bool: +def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> bool: """Query the global KillSwitchSet#is_disabled method.""" return active.is_disabled(id, version=version) -def get_reason(id: str, *, version=_current_version) -> str: +def get_reason(id: str, *, version: semantic_version.Version = _current_version) -> str: """Query the global KillSwitchSet#get_reason method.""" return active.get_reason(id, version=version) +def kills_for_version(version: semantic_version.Version = _current_version) -> List[KillSwitch]: + """Query the global KillSwitchSet for kills matching a particular version.""" + return active.kills_for_version(version) + + if __name__ == "__main__": setup_main_list() print(f'{_current_version=}') From b694bdc96540938e2764204785cab5f0ca5788c9 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 3 Nov 2020 18:02:39 +0200 Subject: [PATCH 241/727] Added per-event killswitch --- plugins/eddn.py | 8 ++++---- plugins/edsm.py | 4 ++-- plugins/inara.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 61624246..533fda18 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -613,10 +613,10 @@ def journal_entry( # noqa: C901 if (ks := killswitch.get_disabled("plugins.eddn.journal")).disabled: logger.warning(f"EDDN journal handler has been disabled via killswitch: {ks.reason}") plug.show_error("EDDN journal handler disabled. See Log.") - return - elif (ks := killswitch.get_disabled(f'plugins.eddn.journal.event{entry["name"]}')).disabled: - logger.warning(f'Handling of event {entry["name"]} disabled via killswitch: {ks.reason}') - return + return None + elif (ks := killswitch.get_disabled(f'plugins.eddn.journal.event{entry["event"]}')).disabled: + logger.warning(f'Handling of event {entry["event"]} disabled via killswitch: {ks.reason}') + return None # Recursively filter '*_Localised' keys from dict def filter_localised(d: Mapping[str, Any]) -> OrderedDictT[str, Any]: diff --git a/plugins/edsm.py b/plugins/edsm.py index f3f8479e..2edb62b6 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -343,8 +343,8 @@ def journal_entry( logger.warning(f'EDSM Journal handler disabled via killswitch: {ks.reason}') plug.show_error('EDSM Handler disabled. See Log.') return - elif (ks := killswitch.get_disabled(f'plugins.edsm.journal.event.{entry["name"]}')).disabled: - logger.warning(f'Handling of event {entry["name"]} has been disabled via killswitch: {ks.reason}') + elif (ks := killswitch.get_disabled(f'plugins.edsm.journal.event.{entry["event"]}')).disabled: + logger.warning(f'Handling of event {entry["event"]} has been disabled via killswitch: {ks.reason}') return if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): diff --git a/plugins/inara.py b/plugins/inara.py index f48a9d31..78da5517 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -326,7 +326,8 @@ def journal_entry( logger.warning(f'INARA support has been disabled via killswitch: {ks.reason}') plug.show_error('INARA disabled. See Log.') return - elif (ks := killswitch.get_disabled(f'')) + elif (ks := killswitch.get_disabled(f'plugins.inara.journal.event.{entry["event"]}')).disabled: + logger.warning(f'event {entry["event"]} processing has been disabled via killswitch: {ks.reason}') event_name: str = entry['event'] this.cmdr = cmdr From 37a6b13d083990950fb28b47fdff2793a4d6ea5b Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 3 Nov 2020 18:09:09 +0200 Subject: [PATCH 242/727] Updated wording for killswitch popup --- EDMarketConnector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 55915717..34d9550e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -346,7 +346,7 @@ import tkinter as tk import tkinter.filedialog import tkinter.font import tkinter.messagebox -from tkinter import ttk +from tkinter import Toplevel, ttk import commodity import companion @@ -1447,7 +1447,7 @@ def show_killswitch_poppup(root=None): return text = ( - "Some EDMC Features have been disabled for known issues.\n" + "Some EDMC Features have been disabled due to known issues.\n" "Please update EDMC as soon as possible to resolve any issues.\n" ) From cd67f12f224e1c43686e76228e73a04de7628b78 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 18:16:50 +0200 Subject: [PATCH 243/727] Fixed eddn event specific killswitch --- plugins/eddn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 533fda18..526ef6d8 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -614,7 +614,7 @@ def journal_entry( # noqa: C901 logger.warning(f"EDDN journal handler has been disabled via killswitch: {ks.reason}") plug.show_error("EDDN journal handler disabled. See Log.") return None - elif (ks := killswitch.get_disabled(f'plugins.eddn.journal.event{entry["event"]}')).disabled: + elif (ks := killswitch.get_disabled(f'plugins.eddn.journal.event.{entry["event"]}')).disabled: logger.warning(f'Handling of event {entry["event"]} disabled via killswitch: {ks.reason}') return None From 4900361621ab20c3a15b4863750c64980845fd3c Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 18:23:30 +0200 Subject: [PATCH 244/727] Set default killswitch URL to releases branch --- docs/Killswitches.md | 6 ++++++ killswitch.py | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index 8603d10d..dd2cd154 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -54,3 +54,9 @@ The current recognised (to EDMC and its internal plugins) killswitch strings are | `plugins.(eddn|inara|edsm|eddb).journal` | Disables all journal processing for EDDN/EDSM/INARA | | `plugins.(edsm|inara).worker` | Disables the EDSM/INARA worker thread (effectively disables updates) (does not close thread) | | `plugins.(eddn|inara|edsm).journal.event.$eventname` | Specific events to disable processing for | + +## File location + +The main killswitch file is kept in the `releases` branch on the EDMC github repo. The file should NEVER be committed to +any other repos. In the case that the killswitch file is found in other repos, the one in releases should always +be taken as correct regardless of others. diff --git a/killswitch.py b/killswitch.py index 44c92177..783b6ccc 100644 --- a/killswitch.py +++ b/killswitch.py @@ -9,8 +9,7 @@ import EDMCLogging logger = EDMCLogging.get_main_logger() -# DEFAULT_KILLSWITCH_URL = 'https://github.com/EDCD/EDMarketConnector' -DEFAULT_KILLSWITCH_URL = 'http://127.0.0.1:8080/killswitches.json' +DEFAULT_KILLSWITCH_URL = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/killswitches.json' _current_version: semantic_version.Version = semantic_version.Version(config.appversion) From 0fb5a3476aa0001072ff17207fa3b5608e8989ee Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 18:34:17 +0200 Subject: [PATCH 245/727] Removed prototyping code --- killswitch.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/killswitch.py b/killswitch.py index 783b6ccc..84dfd048 100644 --- a/killswitch.py +++ b/killswitch.py @@ -193,10 +193,3 @@ def get_reason(id: str, *, version: semantic_version.Version = _current_version) def kills_for_version(version: semantic_version.Version = _current_version) -> List[KillSwitch]: """Query the global KillSwitchSet for kills matching a particular version.""" return active.kills_for_version(version) - - -if __name__ == "__main__": - setup_main_list() - print(f'{_current_version=}') - print(f"{get_disabled('test')=}") - print(f"{active=}") From b5a8c03980f4ddcc2c625f4224c432fa4929166b Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 18:37:11 +0200 Subject: [PATCH 246/727] Added missing whitespace --- plugins/eddb.py | 1 + plugins/eddn.py | 1 + plugins/edsm.py | 1 + plugins/inara.py | 1 + 4 files changed, 4 insertions(+) diff --git a/plugins/eddb.py b/plugins/eddb.py index 1886b410..4f0ea25b 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -97,6 +97,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): logger.warning(f'Journal processing for EDDB has been disabled: {ks.reason}') plug.show_error('EDDB Journal processing disabled. See Log') return + elif (ks := killswitch.get_disabled(f'plugins.eddb.journal.event.{entry["event"]}')).disabled: logger.warning(f'Processing of event {entry["event"]} has been disabled: {ks.reason}') return diff --git a/plugins/eddn.py b/plugins/eddn.py index 526ef6d8..45823dc9 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -614,6 +614,7 @@ def journal_entry( # noqa: C901 logger.warning(f"EDDN journal handler has been disabled via killswitch: {ks.reason}") plug.show_error("EDDN journal handler disabled. See Log.") return None + elif (ks := killswitch.get_disabled(f'plugins.eddn.journal.event.{entry["event"]}')).disabled: logger.warning(f'Handling of event {entry["event"]} disabled via killswitch: {ks.reason}') return None diff --git a/plugins/edsm.py b/plugins/edsm.py index 2edb62b6..c0bfd5aa 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -343,6 +343,7 @@ def journal_entry( logger.warning(f'EDSM Journal handler disabled via killswitch: {ks.reason}') plug.show_error('EDSM Handler disabled. See Log.') return + elif (ks := killswitch.get_disabled(f'plugins.edsm.journal.event.{entry["event"]}')).disabled: logger.warning(f'Handling of event {entry["event"]} has been disabled via killswitch: {ks.reason}') return diff --git a/plugins/inara.py b/plugins/inara.py index 78da5517..1e5d277f 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -326,6 +326,7 @@ def journal_entry( logger.warning(f'INARA support has been disabled via killswitch: {ks.reason}') plug.show_error('INARA disabled. See Log.') return + elif (ks := killswitch.get_disabled(f'plugins.inara.journal.event.{entry["event"]}')).disabled: logger.warning(f'event {entry["event"]} processing has been disabled via killswitch: {ks.reason}') From 2319cbf4047c4f2aefb6de65f02bfe825ad16487 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 5 Jan 2021 16:46:32 +0000 Subject: [PATCH 247/727] Releasing.md: Document adding killswitches if needed. --- docs/Releasing.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 97934c34..23ddcb63 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -212,12 +212,19 @@ a `stable` release, as well as any social media posts you make. string, not the Windows A.B.C.D form.** 1. As you're working in a version-specific branch, `release-4.0.2`, you can safely commit these changes and push to GitHub. - **Do not merge the branch with `releases` until the GitHub release is in - place.** + **Do not merge the branch with `releases` until the GitHub release is in place.** If you're wondering, you needed to get the changelog prepared before building the .exe and .msi because ChangeLog.md is bundled with the install. + +# Adding killswitches + +If anything in this new release addresses a bug that causes, e.g. bad data +to be sent over EDDN, then you should add an appropriate entry to the +killswitches.json file *in the `releases` branch*. That file **must only ever +be commited to the `releases` branch!!!** See [docs/Killswitches.md](docs/Killswitches.md). + # Packaging & Installer Generation You'll want to do the .exe and .msi generation in a `cmd.exe` window, not e.g. From 41f7391e42f3b7e2f3e6b1df30d8061deedcf521 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 18:58:11 +0200 Subject: [PATCH 248/727] Added _str properties for config Path variables --- config.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/config.py b/config.py index 362cb266..2a54ec57 100644 --- a/config.py +++ b/config.py @@ -119,6 +119,36 @@ class AbstractConfig(abc.ABC): def __init__(self) -> None: self.home = pathlib.Path.home() + @property + def app_dir_str(self) -> str: + """Return a string version of app_dir.""" + return str(self.app_dir) + + @property + def plugin_dir_str(self) -> str: + """Return a string version of plugin_dir.""" + return str(self.plugin_dir) + + @property + def internal_plugin_dir_str(self) -> str: + """Return a string version of internal_plugin_dir.""" + return str(self.internal_plugin_dir) + + @property + def respath_str(self) -> str: + """Return a string version of respath.""" + return str(self.respath) + + @property + def home_str(self) -> str: + """Return a string version of home.""" + return str(self.home) + + @property + def default_journal_dir_str(self) -> str: + """Return a string version of default_journal_dir.""" + return str(self.default_journal_dir) + @staticmethod def _suppress_call( func: Callable[..., _T], exceptions: Union[Type[BaseException], List[Type[BaseException]]] = Exception, From 00629b742001bc2d60f3430b5675dfc33d230c9a Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 18:59:56 +0200 Subject: [PATCH 249/727] use _str versions of paths for string ops --- EDMC.py | 6 +++--- dashboard.py | 6 +++--- l10n.py | 4 ++-- monitor.py | 2 +- plug.py | 2 +- plugins/eddn.py | 2 +- prefs.py | 16 ++++++++-------- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/EDMC.py b/EDMC.py index 849c9a98..bdc24705 100755 --- a/EDMC.py +++ b/EDMC.py @@ -41,7 +41,7 @@ from config import appcmdname, appversion, config from monitor import monitor from update import EDMCVersion, Updater -sys.path.append(config.internal_plugin_dir) +sys.path.append(config.internal_plugin_dir_str) # This import must be after the sys.path.append. # The sys.path.append has to be after `import sys` and `from config import config` # isort: off @@ -189,9 +189,9 @@ sys.path: {sys.path}''' # Get state from latest Journal file logger.debug('Getting state from latest journal file') try: - logdir = config.get_str('journaldir', default=str(config.default_journal_dir)) + logdir = config.get_str('journaldir', default=config.default_journal_dir_str) if not logdir: - logdir = str(config.default_journal_dir) + logdir = config.default_journal_dir_str logger.debug(f'logdir = "{logdir}"') logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)), diff --git a/dashboard.py b/dashboard.py index d0ef8575..e0569070 100644 --- a/dashboard.py +++ b/dashboard.py @@ -41,10 +41,10 @@ class Dashboard(FileSystemEventHandler): self.root = root self.session_start = started - logdir = config.get_str('journaldir', default=str(config.default_journal_dir)) + logdir = config.get_str('journaldir', default=config.default_journal_dir_str) if logdir == '': - logdir = str(config.default_journal_dir) - + logdir = config.default_journal_dir_str + if not logdir or not isdir(logdir): logger.info(f"No logdir, or it isn't a directory: {logdir=}") self.stop() diff --git a/l10n.py b/l10n.py index 6b9b1494..779a41ac 100755 --- a/l10n.py +++ b/l10n.py @@ -117,7 +117,7 @@ class _Translations: plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) if isdir(plugin_path): try: - self.translations[plugin] = self.contents(cast(str, lang), plugin_path) + self.translations[plugin] = self.contents(cast(str, lang), str(plugin_path)) except UnicodeDecodeError as e: logger.warning(f'Malformed file {lang}.strings in plugin {plugin}: {e}') @@ -160,7 +160,7 @@ class _Translations: """ if context: # TODO: There is probably a better way to go about this now. - context = context[len(str(config.plugin_dir))+1:].split(os.sep)[0] + context = context[len(config.plugin_dir_str)+1:].split(os.sep)[0] if self.translations[None] and context not in self.translations: logger.debug(f'No translations for {context!r}') diff --git a/monitor.py b/monitor.py index 793789f9..2fedcd26 100644 --- a/monitor.py +++ b/monitor.py @@ -132,7 +132,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below journal_dir = config.get_str('journaldir') if journal_dir == '' or journal_dir is None: - journal_dir = str(config.default_journal_dir) + journal_dir = config.default_journal_dir_str # TODO(A_D): this is ignored for type checking due to all the different types config.get returns # When that is refactored, remove the magic comment diff --git a/plug.py b/plug.py index 755fec1c..3f1a175a 100644 --- a/plug.py +++ b/plug.py @@ -184,7 +184,7 @@ def load_plugins(master): PLUGINS.extend(sorted(internal, key=lambda p: operator.attrgetter('name')(p).lower())) # Add plugin folder to load path so packages can be loaded from plugin folder - sys.path.append(config.plugin_dir) + sys.path.append(config.plugin_dir_str) found = [] # Load any plugins that are also packages first diff --git a/plugins/eddn.py b/plugins/eddn.py index 45823dc9..7451f41d 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -745,7 +745,7 @@ def journal_entry( # noqa: C901 journaldir = config.get_str('journaldir') if journaldir is None or journaldir == '': - journaldir = str(config.default_journal_dir) + journaldir = config.default_journal_dir_str path = pathlib.Path(journaldir) / f'{entry["event"]}.json' diff --git a/prefs.py b/prefs.py index 1fe7d3b6..cfc4aded 100644 --- a/prefs.py +++ b/prefs.py @@ -408,7 +408,7 @@ class PreferencesDialog(tk.Toplevel): row = AutoInc(start=1) self.logdir = tk.StringVar() - default = str(config.default_journal_dir) if config.default_journal_dir is not None else '' + default = config.default_journal_dir_str if config.default_journal_dir is not None else '' logdir = config.get_str('journaldir') if logdir is None or logdir == '': logdir = default @@ -634,7 +634,7 @@ class PreferencesDialog(tk.Toplevel): def __setup_appearance_tab(self, notebook: Notebook) -> None: self.languages = Translations.available_names() # Appearance theme and language setting - self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), default=_('Default'))) + self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default'))) self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) self.theme = tk.IntVar(value=config.get_int('theme')) self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')] @@ -985,7 +985,7 @@ class PreferencesDialog(tk.Toplevel): entryfield['state'] = tk.NORMAL # must be writable to update entryfield.delete(0, tk.END) if platform == 'win32': - start = len(config.home.split('\\')) if pathvar.get().lower().startswith(config.home.lower()) else 0 + start = len(config.home_str.split('\\')) if pathvar.get().lower().startswith(config.home_str.lower()) else 0 display = [] components = normpath(pathvar.get()).split('\\') buf = ctypes.create_unicode_buffer(MAX_PATH) @@ -1006,7 +1006,7 @@ class PreferencesDialog(tk.Toplevel): # None if path doesn't exist elif platform == 'darwin' and NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get()): - if pathvar.get().startswith(config.home): + if pathvar.get().startswith(config.home_str): display = ['~'] + NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())[ len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home)): ] @@ -1016,8 +1016,8 @@ class PreferencesDialog(tk.Toplevel): entryfield.insert(0, '/'.join(display)) else: - if pathvar.get().startswith(config.home): - entryfield.insert(0, '~' + pathvar.get()[len(config.home):]) + if pathvar.get().startswith(config.home_str): + entryfield.insert(0, '~' + pathvar.get()[len(config.home_str):]) else: entryfield.insert(0, pathvar.get()) @@ -1027,7 +1027,7 @@ class PreferencesDialog(tk.Toplevel): def logdir_reset(self) -> None: """Reset the log dir to the default.""" if config.default_journal_dir: - self.logdir.set(config.default_journal_dir) + self.logdir.set(config.default_journal_dir_str) self.outvarchanged() @@ -1138,7 +1138,7 @@ class PreferencesDialog(tk.Toplevel): ) logdir = self.logdir.get() - if config.default_journal_dir and logdir.lower() == config.default_journal_dir.lower(): + if config.default_journal_dir and logdir.lower() == config.default_journal_dir_str.lower(): config.set('journaldir', '') # default location else: From 0035f69c182694ca6a63029d6cab104cc30ff00d Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 5 Jan 2021 19:28:51 +0200 Subject: [PATCH 250/727] Missed one _str --- prefs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prefs.py b/prefs.py index cfc4aded..a86f5521 100644 --- a/prefs.py +++ b/prefs.py @@ -800,7 +800,7 @@ class PreferencesDialog(tk.Toplevel): plugins_frame = nb.Frame(notebook) plugins_frame.columnconfigure(0, weight=1) plugdir = tk.StringVar() - plugdir.set(config.plugin_dir) + plugdir.set(config.plugin_dir_str) row = AutoInc(1) # Section heading in settings @@ -1008,7 +1008,7 @@ class PreferencesDialog(tk.Toplevel): elif platform == 'darwin' and NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get()): if pathvar.get().startswith(config.home_str): display = ['~'] + NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())[ - len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home)): + len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home_str)): ] else: From a1423c7ebad6ed7212323a52389440a7398bedcc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Jan 2021 07:08:51 +0000 Subject: [PATCH 251/727] Bump safety from 1.10.1 to 1.10.2 Bumps [safety](https://github.com/pyupio/safety) from 1.10.1 to 1.10.2. - [Release notes](https://github.com/pyupio/safety/releases) - [Changelog](https://github.com/pyupio/safety/blob/master/HISTORY.rst) - [Commits](https://github.com/pyupio/safety/compare/1.10.1...1.10.2) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 70d01a85..cab9802b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,7 +13,7 @@ flake8-use-fstring==1.1 mypy==0.790 pep8-naming==0.11.1 -safety==1.10.1 +safety==1.10.2 # Code formatting tools autopep8==1.5.4 From 50f9410c022dcd31810a8a3ea4385f5d615d3348 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 12 Jan 2021 15:30:03 +0000 Subject: [PATCH 252/727] config: Add class member and methods for signalling/checking shutdown status --- config.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config.py b/config.py index 2a54ec57..258b7c25 100644 --- a/config.py +++ b/config.py @@ -117,8 +117,16 @@ class AbstractConfig(abc.ABC): identifier: str def __init__(self) -> None: + self.in_shutdown = False # Is the application currently shutting down ? self.home = pathlib.Path.home() + def set_shutdown(self): + self.in_shutdown = True + + @property + def shutting_down(self) -> bool: + return self.in_shutdown + @property def app_dir_str(self) -> str: """Return a string version of app_dir.""" From 2459c40c4879de26106d52756e4dea9a64b8fed7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 12 Jan 2021 15:30:51 +0000 Subject: [PATCH 253/727] EDMarketConnector: call config.set_shutdown() in AppWindow.onexit() --- EDMarketConnector.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 34d9550e..596ded6e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1332,6 +1332,8 @@ class AppWindow(object): def onexit(self, event=None) -> None: """Application shutdown procedure.""" + config.set_shutdown() # Signal we're in shutdown now. + # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 if platform != 'darwin' or self.w.winfo_rooty() > 0: x, y = self.w.geometry().split('+')[1:3] # e.g. '212x170+2881+1267' From 719a58cbe9582282005802a250668eda750b08ce Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:08:53 +0000 Subject: [PATCH 254/727] plug.py: Avoid Tk event_generate() call from show_error() if in shutdown # Conflicts: # plug.py --- plug.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plug.py b/plug.py index 3f1a175a..c51342c9 100644 --- a/plug.py +++ b/plug.py @@ -371,8 +371,7 @@ def show_error(err): :param err: .. versionadded:: 2.3.7 """ - - if config.shutting_down: + if config.shutting_down(): logger.info(f'Called during shutdown: "{str(err)}"') return From 28a230b5844b67914714a90a00a912d6a7b584b6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 12 Jan 2021 15:33:01 +0000 Subject: [PATCH 255/727] config: Change self.in_shutdown to be mangled. I specifically made set_shutdown() *not* take an argument and only ever set this true so no-one else can monkey with it, so might as well mangle it too. --- config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index 258b7c25..9d5f5c17 100644 --- a/config.py +++ b/config.py @@ -117,15 +117,15 @@ class AbstractConfig(abc.ABC): identifier: str def __init__(self) -> None: - self.in_shutdown = False # Is the application currently shutting down ? + self.__in_shutdown = False # Is the application currently shutting down ? self.home = pathlib.Path.home() def set_shutdown(self): - self.in_shutdown = True + self.__in_shutdown = True @property def shutting_down(self) -> bool: - return self.in_shutdown + return self.__in_shutdown @property def app_dir_str(self) -> str: From 608a336bb3731b43f2e3ce9d5f483494cbc18c89 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:15:40 +0000 Subject: [PATCH 256/727] dashboard: Bail early from process() if in shutdown # Conflicts: # dashboard.py --- dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard.py b/dashboard.py index e0569070..415d0975 100644 --- a/dashboard.py +++ b/dashboard.py @@ -145,7 +145,7 @@ class Dashboard(FileSystemEventHandler): # Can be called either in watchdog thread or, if polling, in main thread. def process(self, logfile=None): - if config.shutting_down: + if config.shutting_down(): return try: From b39cc7974e562d31d0dba071788ef49ca3b5a269 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:16:12 +0000 Subject: [PATCH 257/727] hotkey: Avoid event_generate() calls during shutdown # Conflicts: # hotkey.py --- hotkey.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hotkey.py b/hotkey.py index 5165e0b9..af2d9533 100644 --- a/hotkey.py +++ b/hotkey.py @@ -128,7 +128,7 @@ if platform == 'darwin': self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE def _acquire_poll(self): - if config.shutting_down: + if config.shutting_down(): return # No way of signalling to Tkinter from within the monkey-patched event handler that doesn't @@ -350,8 +350,9 @@ elif platform == 'win32': config.get_int('hotkey_always') or WindowTitle(GetForegroundWindow()).startswith('Elite - Dangerous') ): - logger.debug('Sending event <>') - self.root.event_generate('<>', when="tail") + if not config.shutting_down: + logger.debug('Sending event <>') + self.root.event_generate('<>', when="tail") else: logger.debug('Passing key on') From e7a7314c1ab219e79d16458d405ebfb4e8354c33 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:17:00 +0000 Subject: [PATCH 258/727] protocol: Avoid Tk event_generate() calls during shutdown # Conflicts: # protocol.py --- protocol.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/protocol.py b/protocol.py index 0caa6a68..2c6dc155 100644 --- a/protocol.py +++ b/protocol.py @@ -34,9 +34,7 @@ class GenericProtocolHandler(object): def event(self, url): self.lastpayload = url - logger.trace(f'Payload: {self.lastpayload}') if not config.shutting_down: - logger.debug('event_generate("<>"') self.master.event_generate('<>', when="tail") From db48b6eaad07bd74e71b76a27c354a6276656820 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:18:00 +0000 Subject: [PATCH 259/727] plugins/edsm: Avoid Tk event_generate() calls during shutdown # Conflicts: # plugins/edsm.py --- plugins/edsm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/edsm.py b/plugins/edsm.py index c0bfd5aa..1707ae3d 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -622,9 +622,8 @@ def worker() -> None: if not closing and e['event'] in ('StartUp', 'Location', 'FSDJump', 'CarrierJump'): # Update main window's system status this.lastlookup = r - + # calls update_status in main thread if not config.shutting_down: - # calls update_status in main thread this.system_link.event_generate('<>', when="tail") if r['msgnum'] // 100 != 1: From 3ed08f0f7e1cd7bd3748de4d5bc6f9f4146d232f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:18:58 +0000 Subject: [PATCH 260/727] plugins/inara: Avoid Tk event_generate() calls during shutdown # Conflicts: # plugins/inara.py --- plugins/inara.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 1e5d277f..292d59b3 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1315,16 +1315,14 @@ def send_data(url: str, data: Mapping[str, Any]) -> bool: 'setCommanderTravelLocation' ): this.lastlocation = reply_event.get('eventData', {}) - + # calls update_location in main thread if not config.shutting_down: - # calls update_location in main thread this.system_link.event_generate('<>', when="tail") elif data_event['eventName'] in ['addCommanderShip', 'setCommanderShip']: this.lastship = reply_event.get('eventData', {}) - + # calls update_ship in main thread if not config.shutting_down: - # calls update_ship in main thread this.system_link.event_generate('<>', when="tail") return True # regardless of errors above, we DID manage to send it, therefore inform our caller as such From a8aab186bf3546b3d9b6c2d2cace0f83f7242b66 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 12 Jan 2021 15:45:14 +0000 Subject: [PATCH 261/727] config: Update some 'callers' of config.shutting_down for it being a property --- dashboard.py | 2 +- hotkey.py | 2 +- plug.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dashboard.py b/dashboard.py index 415d0975..e0569070 100644 --- a/dashboard.py +++ b/dashboard.py @@ -145,7 +145,7 @@ class Dashboard(FileSystemEventHandler): # Can be called either in watchdog thread or, if polling, in main thread. def process(self, logfile=None): - if config.shutting_down(): + if config.shutting_down: return try: diff --git a/hotkey.py b/hotkey.py index af2d9533..f40f5f9e 100644 --- a/hotkey.py +++ b/hotkey.py @@ -128,7 +128,7 @@ if platform == 'darwin': self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE def _acquire_poll(self): - if config.shutting_down(): + if config.shutting_down: return # No way of signalling to Tkinter from within the monkey-patched event handler that doesn't diff --git a/plug.py b/plug.py index c51342c9..64410d7b 100644 --- a/plug.py +++ b/plug.py @@ -371,7 +371,7 @@ def show_error(err): :param err: .. versionadded:: 2.3.7 """ - if config.shutting_down(): + if config.shutting_down: logger.info(f'Called during shutdown: "{str(err)}"') return From 104f2157326428451e134128c6d4b12c8d166648 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 12 Jan 2021 15:48:02 +0000 Subject: [PATCH 262/727] protocol.py: Need `from config import config` --- protocol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/protocol.py b/protocol.py index 2c6dc155..af09fc14 100644 --- a/protocol.py +++ b/protocol.py @@ -6,6 +6,7 @@ import urllib.request, urllib.error, urllib.parse import sys from EDMCLogging import get_main_logger +from config import config logger = get_main_logger() From b7094c59f3997f0a3fa146e2b3e2119919721ee2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 12 Jan 2021 15:55:50 +0000 Subject: [PATCH 263/727] config: __in_shutdown needs to be abstract member, not self. ? --- config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 9d5f5c17..cd6d9d55 100644 --- a/config.py +++ b/config.py @@ -116,8 +116,9 @@ class AbstractConfig(abc.ABC): identifier: str + __in_shutdown = False # Is the application currently shutting down ? + def __init__(self) -> None: - self.__in_shutdown = False # Is the application currently shutting down ? self.home = pathlib.Path.home() def set_shutdown(self): From cd909329af77890c1965fdc1e5fde94da148af76 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 12 Jan 2021 16:12:32 +0000 Subject: [PATCH 264/727] requirements: Change all specified versions to '==' Although the issue we've identified with GitHub builds isn't to do with a python module version it's best to nail precise versions so we can be sure it will build with the same as we've tested locally. --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 53cacec1..3bd02584 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 -requests>=2.11.1 -watchdog>=0.8.3 +requests==2.25.1 +watchdog==0.10.3 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From 762ceda73f4e77d97cb51717cbd2b0bf636e4215 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Jan 2021 06:22:56 +0000 Subject: [PATCH 265/727] Bump watchdog from 0.10.3 to 1.0.2 Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 0.10.3 to 1.0.2. - [Release notes](https://github.com/gorakhargosh/watchdog/releases) - [Changelog](https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst) - [Commits](https://github.com/gorakhargosh/watchdog/compare/v0.10.3...v1.0.2) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3bd02584..0824d629 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 requests==2.25.1 -watchdog==0.10.3 +watchdog==1.0.2 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From ce45a4d405e74a5b3da1488ed062a8877c1dc123 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:20:20 +0000 Subject: [PATCH 266/727] Fix console redirect to work with config.py now using logging. 1. We were now importing from config before the console redirect code runs. 2. That means that config.py's `logger = logging.getLogger(appname)` caused the logger to be set up whilst stdout/err were still pointing at the console. 3. So the redirect then had no effect on logging output. This commit moves the import from config (and also killswitch, because it also imports logging) to after the *moved* console redirect code. NB: This needs the "detected a process already running" instance checking. NB: There's still a `True or ` for testing purposes EDMarketConnector.py:25 # Conflicts: # EDMarketConnector.py --- EDMarketConnector.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 596ded6e..9ba7ee87 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -12,12 +12,28 @@ import webbrowser from builtins import object, str from os import chdir, environ from os.path import dirname, isdir, join -import killswitch from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple, cast -from constants import applongname, appname, protocolhandler_redirect +# config will now cause an appname logger to be set up, so we need the +# console redirect before this +appname = 'EDMarketConnector' # TODO: Must match config.appname, add test +if __name__ == '__main__': + # Keep this as the very first code run to be as sure as possible of no + # output until after this redirect is done, if needed. + if True or getattr(sys, 'frozen', False): + # By default py2exe tries to write log to dirname(sys.executable) which fails when installed + import tempfile + + # unbuffered not allowed for text in python3, so use `1 for line buffering + sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1) + # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup + +# isort: off +import killswitch # noqa: E402 # Will cause a logging import/startup so needs to be after the redirect +from config import applongname, appname, appversion, appversion_nobuild, config, copyright # noqa: E402 +# isort: on if __name__ == "__main__": def no_other_instance_running() -> bool: # noqa: CCR001 @@ -130,15 +146,6 @@ if __name__ == "__main__": # reach here. sys.exit(0) - # Keep this as the very first code run to be as sure as possible of no - # output until after this redirect is done, if needed. - if getattr(sys, 'frozen', False): - # By default py2exe tries to write log to dirname(sys.executable) which fails when installed - import tempfile - - # unbuffered not allowed for text in python3, so use `1 for line buffering - sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='a', buffering=1) - # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup # After the redirect in case config does logging setup from config import appversion, appversion_nobuild, config, copyright From 9fcaee9c88bfd5f8527650e3ba0c7fbad58c6bf9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 13 Jan 2021 15:01:26 +0000 Subject: [PATCH 267/727] "Is there already a process?" check now works 1. Moved the rest of the __main__ code so it's all in one block again. 2. Duplicate defined applongname, and protocolhandler.redirect as protocolhandler_redirect so that the process checking works. --- EDMarketConnector.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 9ba7ee87..3968275a 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -19,23 +19,9 @@ from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple, cast # config will now cause an appname logger to be set up, so we need the # console redirect before this appname = 'EDMarketConnector' # TODO: Must match config.appname, add test +applongname = 'E:D Market Connector' # TODO: Must match config.applongname, add test +protocolhandler_redirect = 'edmc://auth' # TODO: Must match protocolhandler.redirect, add test if __name__ == '__main__': - # Keep this as the very first code run to be as sure as possible of no - # output until after this redirect is done, if needed. - if True or getattr(sys, 'frozen', False): - # By default py2exe tries to write log to dirname(sys.executable) which fails when installed - import tempfile - - # unbuffered not allowed for text in python3, so use `1 for line buffering - sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1) - # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup - -# isort: off -import killswitch # noqa: E402 # Will cause a logging import/startup so needs to be after the redirect -from config import applongname, appname, appversion, appversion_nobuild, config, copyright # noqa: E402 -# isort: on - -if __name__ == "__main__": def no_other_instance_running() -> bool: # noqa: CCR001 """ Ensure only one copy of the app is running under this user account. @@ -88,7 +74,7 @@ if __name__ == "__main__": and window_title(window_handle) == applongname \ and GetProcessHandleFromHwnd(window_handle): # If GetProcessHandleFromHwnd succeeds then the app is already running as this user - if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect): + if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect): CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) # Wait for it to be responsive to avoid ShellExecute recursing ShowWindow(window_handle, SW_RESTORE) @@ -146,6 +132,21 @@ if __name__ == "__main__": # reach here. sys.exit(0) + # Keep this as the very first code run to be as sure as possible of no + # output until after this redirect is done, if needed. + if True or getattr(sys, 'frozen', False): + # By default py2exe tries to write log to dirname(sys.executable) which fails when installed + import tempfile + + # unbuffered not allowed for text in python3, so use `1 for line buffering + sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1) + # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup + +# isort: off +import killswitch # noqa: E402 # Will cause a logging import/startup so needs to be after the redirect +from config import applongname, appname, appversion, appversion_nobuild, config, copyright # noqa: E402 +# isort: on + # After the redirect in case config does logging setup from config import appversion, appversion_nobuild, config, copyright From 2ec767405f40ac6661e990d23a116ae77ca45ec3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 13 Jan 2021 15:23:11 +0000 Subject: [PATCH 268/727] 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. --- EDMarketConnector.py | 9 ++++----- protocol.py | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 3968275a..80eb0a7b 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -16,11 +16,10 @@ from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple, cast +from constants import applongname, appname, protocolhandler_redirect + # config will now cause an appname logger to be set up, so we need the # console redirect before this -appname = 'EDMarketConnector' # TODO: Must match config.appname, add test -applongname = 'E:D Market Connector' # TODO: Must match config.applongname, add test -protocolhandler_redirect = 'edmc://auth' # TODO: Must match protocolhandler.redirect, add test if __name__ == '__main__': def no_other_instance_running() -> bool: # noqa: CCR001 """ @@ -143,8 +142,8 @@ if __name__ == '__main__': # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup # isort: off -import killswitch # noqa: E402 # Will cause a logging import/startup so needs to be after the redirect -from config import applongname, appname, appversion, appversion_nobuild, config, copyright # noqa: E402 +import killswitch # Will cause a logging import/startup so needs to be after the redirect +from config import appversion, appversion_nobuild, config, copyright # isort: on diff --git a/protocol.py b/protocol.py index af09fc14..b27c5438 100644 --- a/protocol.py +++ b/protocol.py @@ -7,6 +7,7 @@ import sys from EDMCLogging import get_main_logger from config import config +from constants import protocolhandler_redirect logger = get_main_logger() From f38b2aa95e32d071c52bddb7adf07a40d5566844 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 13 Jan 2021 15:29:40 +0000 Subject: [PATCH 269/727] Revert testing 'True or' on console redirect --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 80eb0a7b..75bff451 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -133,7 +133,7 @@ if __name__ == '__main__': # Keep this as the very first code run to be as sure as possible of no # output until after this redirect is done, if needed. - if True or getattr(sys, 'frozen', False): + if getattr(sys, 'frozen', False): # By default py2exe tries to write log to dirname(sys.executable) which fails when installed import tempfile From 051245cf9059b773cf289b4f80b8f8fa9b3e3075 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 11 Jan 2021 15:55:50 +0200 Subject: [PATCH 270/727] Renamed various config values to be backwards compatible --- EDMC.py | 6 +-- EDMCLogging.py | 4 +- EDMarketConnector.py | 4 +- companion.py | 2 +- config.py | 96 ++++++++++++++++++++++---------------------- dashboard.py | 4 +- edshipyard.py | 2 +- hotkey.py | 8 ++-- l10n.py | 6 +-- monitor.py | 2 +- outfitting.py | 2 +- plug.py | 16 ++++---- plugins/eddn.py | 2 +- prefs.py | 26 ++++++------ 14 files changed, 90 insertions(+), 90 deletions(-) diff --git a/EDMC.py b/EDMC.py index bdc24705..d4aaf37d 100755 --- a/EDMC.py +++ b/EDMC.py @@ -41,7 +41,7 @@ from config import appcmdname, appversion, config from monitor import monitor from update import EDMCVersion, Updater -sys.path.append(config.internal_plugin_dir_str) +sys.path.append(config.internal_plugin_dir) # This import must be after the sys.path.append. # The sys.path.append has to be after `import sys` and `from config import config` # isort: off @@ -189,9 +189,9 @@ sys.path: {sys.path}''' # Get state from latest Journal file logger.debug('Getting state from latest journal file') try: - logdir = config.get_str('journaldir', default=config.default_journal_dir_str) + logdir = config.get_str('journaldir', default=config.default_journal_dir) if not logdir: - logdir = config.default_journal_dir_str + logdir = config.default_journal_dir logger.debug(f'logdir = "{logdir}"') logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)), diff --git a/EDMCLogging.py b/EDMCLogging.py index 35f50411..80b43c16 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -422,8 +422,8 @@ class EDMCContextFilter(logging.Filter): :return: The munged module_name. """ file_name = pathlib.Path(frame_info.filename).expanduser() - plugin_dir = pathlib.Path(config.plugin_dir).expanduser() - internal_plugin_dir = pathlib.Path(config.internal_plugin_dir).expanduser() + plugin_dir = pathlib.Path(config.plugin_dir_path).expanduser() + internal_plugin_dir = pathlib.Path(config.internal_plugin_dir_path).expanduser() # Find the first parent called 'plugins' plugin_top = file_name while plugin_top and plugin_top.name != '': diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 75bff451..55ff13a5 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -415,7 +415,7 @@ class AppWindow(object): else: self.w.tk.call('wm', 'iconphoto', self.w, '-default', - tk.PhotoImage(file=join(config.respath, 'EDMarketConnector.png'))) + tk.PhotoImage(file=join(config.respath_path, 'EDMarketConnector.png'))) # TODO: Export to files and merge from them in future ? self.theme_icon = tk.PhotoImage( @@ -1145,7 +1145,7 @@ class AppWindow(object): # Avoid file length limits if possible provider = config.get_str('shipyard_provider', default='EDSY') target = plug.invoke(provider, 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) - file_name = join(config.app_dir, "last_shipyard.html") + file_name = join(config.app_dir_path, "last_shipyard.html") with open(file_name, 'w') as f: print(SHIPYARD_HTML_TEMPLATE.format( diff --git a/companion.py b/companion.py index bdbca243..62d3745c 100644 --- a/companion.py +++ b/companion.py @@ -660,7 +660,7 @@ def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully if not commodity_map: # Lazily populate for f in ('commodity.csv', 'rare_commodity.csv'): - with open(join(config.respath, f), 'r') as csvfile: + with open(join(config.respath_path, f), 'r') as csvfile: reader = csv.DictReader(csvfile) for row in reader: diff --git a/config.py b/config.py index cd6d9d55..8d745eac 100644 --- a/config.py +++ b/config.py @@ -107,19 +107,19 @@ class AbstractConfig(abc.ABC): OUT_SYS_EDDN = 2048 OUT_SYS_DELAY = 4096 - app_dir: pathlib.Path - plugin_dir: pathlib.Path - internal_plugin_dir: pathlib.Path - respath: pathlib.Path - home: pathlib.Path - default_journal_dir: pathlib.Path + app_dir_path: pathlib.Path + plugin_dir_path: pathlib.Path + internal_plugin_dir_path: pathlib.Path + respath_path: pathlib.Path + home_path: pathlib.Path + default_journal_dir_path: pathlib.Path identifier: str __in_shutdown = False # Is the application currently shutting down ? def __init__(self) -> None: - self.home = pathlib.Path.home() + self.home_path = pathlib.Path.home() def set_shutdown(self): self.__in_shutdown = True @@ -129,34 +129,34 @@ class AbstractConfig(abc.ABC): return self.__in_shutdown @property - def app_dir_str(self) -> str: + def app_dir(self) -> str: """Return a string version of app_dir.""" - return str(self.app_dir) + return str(self.app_dir_path) @property - def plugin_dir_str(self) -> str: + def plugin_dir(self) -> str: """Return a string version of plugin_dir.""" - return str(self.plugin_dir) + return str(self.plugin_dir_path) @property - def internal_plugin_dir_str(self) -> str: + def internal_plugin_dir(self) -> str: """Return a string version of internal_plugin_dir.""" - return str(self.internal_plugin_dir) + return str(self.internal_plugin_dir_path) @property - def respath_str(self) -> str: + def respath(self) -> str: """Return a string version of respath.""" - return str(self.respath) + return str(self.respath_path) @property - def home_str(self) -> str: + def home(self) -> str: """Return a string version of home.""" - return str(self.home) + return str(self.home_path) @property - def default_journal_dir_str(self) -> str: + def default_journal_dir(self) -> str: """Return a string version of default_journal_dir.""" - return str(self.default_journal_dir) + return str(self.default_journal_dir_path) @staticmethod def _suppress_call( @@ -308,27 +308,27 @@ class WinConfig(AbstractConfig): """Implementation of AbstractConfig for windows.""" def __init__(self, do_winsparkle=True) -> None: - self.app_dir = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname - self.app_dir.mkdir(exist_ok=True) + self.app_dir_path = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname + self.app_dir_path.mkdir(exist_ok=True) - self.plugin_dir = self.app_dir / 'plugins' - self.plugin_dir.mkdir(exist_ok=True) + self.plugin_dir_path = self.app_dir_path / 'plugins' + self.plugin_dir_path.mkdir(exist_ok=True) if getattr(sys, 'frozen', False): - self.respath = pathlib.Path(sys.executable).parent - self.internal_plugin_dir = self.respath / 'plugins' + self.respath_path = pathlib.Path(sys.executable).parent + self.internal_plugin_dir_path = self.respath_path / 'plugins' else: - self.respath = pathlib.Path(__file__).parent - self.internal_plugin_dir = self.respath / 'plugins' + self.respath_path = pathlib.Path(__file__).parent + self.internal_plugin_dir_path = self.respath_path / 'plugins' - self.home = pathlib.Path.home() + self.home_path = pathlib.Path.home() journal_dir_str = known_folder_path(FOLDERID_SavedGames) journaldir = pathlib.Path(journal_dir_str) if journal_dir_str is not None else None - self.default_journal_dir = None + self.default_journal_dir_path = None if journaldir is not None: - self.default_journal_dir = journaldir / 'Frontier Developments' / 'Elite Dangerous' + self.default_journal_dir_path = journaldir / 'Frontier Developments' / 'Elite Dangerous' create_key_defaults = functools.partial( winreg.CreateKeyEx, @@ -350,7 +350,7 @@ class WinConfig(AbstractConfig): self.identifier = applongname if (outdir_str := self.get_str('outdir')) is None or not pathlib.Path(outdir_str).is_dir(): docs = known_folder_path(FOLDERID_Documents) - self.set('outdir', docs if docs is not None else str(self.home)) + self.set('outdir', docs if docs is not None else str(self.home_path)) def __setup_winsparkle(self): create_key_defaults = functools.partial( @@ -535,29 +535,29 @@ class MacConfig(AbstractConfig): )[0] ) - self.app_dir = support_path / appname - self.app_dir.mkdir(exist_ok=True) + self.app_dir_path = support_path / appname + self.app_dir_path.mkdir(exist_ok=True) - self.plugin_dir = self.app_dir / 'plugins' - self.plugin_dir.mkdir(exist_ok=True) + self.plugin_dir_path = self.app_dir_path / 'plugins' + self.plugin_dir_path.mkdir(exist_ok=True) # Bundle IDs identify a singled app though out a system if getattr(sys, 'frozen', False): exe_dir = pathlib.Path(sys.executable).parent - self.internal_plugin_dir = exe_dir.parent / 'Library' / 'plugins' - self.respath = exe_dir.parent / 'Resources' + self.internal_plugin_dir_path = exe_dir.parent / 'Library' / 'plugins' + self.respath_path = exe_dir.parent / 'Resources' self.identifier = NSBundle.mainBundle().bundleIdentifier() else: file_dir = pathlib.Path(__file__).parent - self.internal_plugin_dir = file_dir / 'plugins' - self.respath = file_dir + self.internal_plugin_dir_path = file_dir / 'plugins' + self.respath_path = file_dir self.identifier = f'uk.org.marginal.{appname.lower()}' NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier - self.default_journal_dir = support_path / 'Frontier Developments' / 'Elite Dangerous' + self.default_journal_dir_path = support_path / 'Frontier Developments' / 'Elite Dangerous' self._defaults = NSUserDefaults.standardUserDefaults() self._settings: Dict[str, Union[int, str, list]] = dict( self._defaults.persistentDomainForName_(self.identifier) or {} @@ -682,16 +682,16 @@ class LinuxConfig(AbstractConfig): super().__init__() # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser() - self.app_dir = xdg_data_home / appname - self.app_dir.mkdir(exist_ok=True, parents=True) + self.app_dir_path = xdg_data_home / appname + self.app_dir_path.mkdir(exist_ok=True, parents=True) - self.plugin_dir = self.app_dir / 'plugins' - self.plugin_dir.mkdir(exist_ok=True) + self.plugin_dir_path = self.app_dir_path / 'plugins' + self.plugin_dir_path.mkdir(exist_ok=True) - self.respath = pathlib.Path(__file__).parent + self.respath_path = pathlib.Path(__file__).parent - self.internal_plugin_dir = self.respath / 'plugins' - self.default_journal_dir = None + self.internal_plugin_dir_path = self.respath_path / 'plugins' + self.default_journal_dir_path = None self.identifier = f'uk.org.marginal.{appname.lower()}' # TODO: Unused? config_home = pathlib.Path(os.getenv('XDG_CONFIG_HOME', default='~/.config')).expanduser() @@ -711,7 +711,7 @@ class LinuxConfig(AbstractConfig): self.config.add_section(self.SECTION) if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir(): - self.set('outdir', str(self.home)) + self.set('outdir', str(self.home_path)) def __escape(self, s: str) -> str: """ diff --git a/dashboard.py b/dashboard.py index e0569070..71b16f4c 100644 --- a/dashboard.py +++ b/dashboard.py @@ -41,9 +41,9 @@ class Dashboard(FileSystemEventHandler): self.root = root self.session_start = started - logdir = config.get_str('journaldir', default=config.default_journal_dir_str) + logdir = config.get_str('journaldir', default=config.default_journal_dir) if logdir == '': - logdir = config.default_journal_dir_str + logdir = config.default_journal_dir if not logdir or not isdir(logdir): logger.info(f"No logdir, or it isn't a directory: {logdir=}") diff --git a/edshipyard.py b/edshipyard.py index 0a642810..0eae47d3 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -48,7 +48,7 @@ slot_map = { # Ship masses # TODO: prefer something other than pickle for this storage (dev readability, security) -ships = pickle.load(open(join(config.respath, 'ships.p'), 'rb')) +ships = pickle.load(open(join(config.respath_path, 'ships.p'), 'rb')) # Export ship loadout in E:D Shipyard plain text format diff --git a/hotkey.py b/hotkey.py index f40f5f9e..c0baa14c 100644 --- a/hotkey.py +++ b/hotkey.py @@ -42,8 +42,8 @@ if platform == 'darwin': self.tkProcessKeyEvent_old = None - self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_good.wav'), False) - self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_bad.wav'), False) + self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath_path, 'snd_good.wav'), False) + self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath_path, 'snd_bad.wav'), False) def register(self, root, keycode, modifiers): self.root = root @@ -291,8 +291,8 @@ elif platform == 'win32': def __init__(self): self.root = None self.thread = None - self.snd_good = open(join(config.respath, 'snd_good.wav'), 'rb').read() - self.snd_bad = open(join(config.respath, 'snd_bad.wav'), 'rb').read() + self.snd_good = open(join(config.respath_path, 'snd_good.wav'), 'rb').read() + self.snd_bad = open(join(config.respath_path, 'snd_bad.wav'), 'rb').read() atexit.register(self.unregister) def register(self, root, keycode, modifiers): diff --git a/l10n.py b/l10n.py index 779a41ac..9cc7d946 100755 --- a/l10n.py +++ b/l10n.py @@ -113,8 +113,8 @@ class _Translations: return self.translations = {None: self.contents(cast(str, lang))} - for plugin in os.listdir(config.plugin_dir): - plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) + for plugin in os.listdir(config.plugin_dir_path): + plugin_path = join(config.plugin_dir_path, plugin, LOCALISATION_DIR) if isdir(plugin_path): try: self.translations[plugin] = self.contents(cast(str, lang), str(plugin_path)) @@ -160,7 +160,7 @@ class _Translations: """ if context: # TODO: There is probably a better way to go about this now. - context = context[len(config.plugin_dir_str)+1:].split(os.sep)[0] + context = context[len(config.plugin_dir)+1:].split(os.sep)[0] if self.translations[None] and context not in self.translations: logger.debug(f'No translations for {context!r}') diff --git a/monitor.py b/monitor.py index 2fedcd26..abeae8de 100644 --- a/monitor.py +++ b/monitor.py @@ -132,7 +132,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below journal_dir = config.get_str('journaldir') if journal_dir == '' or journal_dir is None: - journal_dir = config.default_journal_dir_str + journal_dir = config.default_journal_dir # TODO(A_D): this is ignored for type checking due to all the different types config.get returns # When that is refactored, remove the magic comment diff --git a/outfitting.py b/outfitting.py index 11249a1c..1460ab5b 100644 --- a/outfitting.py +++ b/outfitting.py @@ -350,7 +350,7 @@ def lookup(module, ship_map, entitled=False): # Lazily populate if not moduledata: - moduledata.update(pickle.load(open(join(config.respath, 'modules.p'), 'rb'))) + moduledata.update(pickle.load(open(join(config.respath_path, 'modules.p'), 'rb'))) # if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout if not module.get('name'): raise AssertionError('%s: Missing name' % module['id']) diff --git a/plug.py b/plug.py index 64410d7b..e1d8a52b 100644 --- a/plug.py +++ b/plug.py @@ -173,10 +173,10 @@ def load_plugins(master): last_error['root'] = master internal = [] - for name in sorted(os.listdir(config.internal_plugin_dir)): + for name in sorted(os.listdir(config.internal_plugin_dir_path)): if name.endswith('.py') and not name[0] in ['.', '_']: try: - plugin = Plugin(name[:-3], os.path.join(config.internal_plugin_dir, name), logger) + plugin = Plugin(name[:-3], os.path.join(config.internal_plugin_dir_path, name), logger) plugin.folder = None # Suppress listing in Plugins prefs tab internal.append(plugin) except Exception as e: @@ -184,13 +184,13 @@ def load_plugins(master): PLUGINS.extend(sorted(internal, key=lambda p: operator.attrgetter('name')(p).lower())) # Add plugin folder to load path so packages can be loaded from plugin folder - sys.path.append(config.plugin_dir_str) + sys.path.append(config.plugin_dir) found = [] # Load any plugins that are also packages first - for name in sorted(os.listdir(config.plugin_dir), - key = lambda n: (not os.path.isfile(os.path.join(config.plugin_dir, n, '__init__.py')), n.lower())): - if not os.path.isdir(os.path.join(config.plugin_dir, name)) or name[0] in ['.', '_']: + for name in sorted(os.listdir(config.plugin_dir_path), + key = lambda n: (not os.path.isfile(os.path.join(config.plugin_dir_path, n, '__init__.py')), n.lower())): + if not os.path.isdir(os.path.join(config.plugin_dir_path, name)) or name[0] in ['.', '_']: pass elif name.endswith('.disabled'): name, discard = name.rsplit('.', 1) @@ -198,14 +198,14 @@ def load_plugins(master): else: try: # Add plugin's folder to load path in case plugin has internal package dependencies - sys.path.append(os.path.join(config.plugin_dir, name)) + sys.path.append(os.path.join(config.plugin_dir_path, name)) # Create a logger for this 'found' plugin. Must be before the # load.py is loaded. import EDMCLogging plugin_logger = EDMCLogging.get_plugin_logger(name) - found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py'), plugin_logger)) + found.append(Plugin(name, os.path.join(config.plugin_dir_path, name, 'load.py'), plugin_logger)) except Exception as e: logger.exception(f'Failure loading found Plugin "{name}"') pass diff --git a/plugins/eddn.py b/plugins/eddn.py index 7451f41d..c9565c7e 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -745,7 +745,7 @@ def journal_entry( # noqa: C901 journaldir = config.get_str('journaldir') if journaldir is None or journaldir == '': - journaldir = config.default_journal_dir_str + journaldir = config.default_journal_dir path = pathlib.Path(journaldir) / f'{entry["event"]}.json' diff --git a/prefs.py b/prefs.py index a86f5521..8f8a2ece 100644 --- a/prefs.py +++ b/prefs.py @@ -408,7 +408,7 @@ class PreferencesDialog(tk.Toplevel): row = AutoInc(start=1) self.logdir = tk.StringVar() - default = config.default_journal_dir_str if config.default_journal_dir is not None else '' + default = config.default_journal_dir if config.default_journal_dir_path is not None else '' logdir = config.get_str('journaldir') if logdir is None or logdir == '': logdir = default @@ -431,7 +431,7 @@ class PreferencesDialog(tk.Toplevel): ) self.logbutton.grid(column=3, padx=self.PADX, pady=self.PADY, sticky=tk.EW, row=row.get()) - if config.default_journal_dir: + if config.default_journal_dir_path: # Appearance theme and language setting nb.Button( config_frame, @@ -800,7 +800,7 @@ class PreferencesDialog(tk.Toplevel): plugins_frame = nb.Frame(notebook) plugins_frame.columnconfigure(0, weight=1) plugdir = tk.StringVar() - plugdir.set(config.plugin_dir_str) + plugdir.set(config.plugin_dir) row = AutoInc(1) # Section heading in settings @@ -949,7 +949,7 @@ class PreferencesDialog(tk.Toplevel): browseInfo.lpszTitle = title browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI browseInfo.lpfn = BrowseCallbackProc(browsecallback) - browseInfo.lParam = pathvar.get().startswith('~') and join(config.home, + browseInfo.lParam = pathvar.get().startswith('~') and join(config.home_path, pathvar.get()[2:]) or pathvar.get() ctypes.windll.ole32.CoInitialize(None) pidl = ctypes.windll.shell32.SHBrowseForFolderW(ctypes.byref(browseInfo)) @@ -985,7 +985,7 @@ class PreferencesDialog(tk.Toplevel): entryfield['state'] = tk.NORMAL # must be writable to update entryfield.delete(0, tk.END) if platform == 'win32': - start = len(config.home_str.split('\\')) if pathvar.get().lower().startswith(config.home_str.lower()) else 0 + start = len(config.home.split('\\')) if pathvar.get().lower().startswith(config.home.lower()) else 0 display = [] components = normpath(pathvar.get()).split('\\') buf = ctypes.create_unicode_buffer(MAX_PATH) @@ -1006,9 +1006,9 @@ class PreferencesDialog(tk.Toplevel): # None if path doesn't exist elif platform == 'darwin' and NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get()): - if pathvar.get().startswith(config.home_str): + if pathvar.get().startswith(config.home): display = ['~'] + NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())[ - len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home_str)): + len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home)): ] else: @@ -1016,8 +1016,8 @@ class PreferencesDialog(tk.Toplevel): entryfield.insert(0, '/'.join(display)) else: - if pathvar.get().startswith(config.home_str): - entryfield.insert(0, '~' + pathvar.get()[len(config.home_str):]) + if pathvar.get().startswith(config.home): + entryfield.insert(0, '~' + pathvar.get()[len(config.home):]) else: entryfield.insert(0, pathvar.get()) @@ -1026,8 +1026,8 @@ class PreferencesDialog(tk.Toplevel): def logdir_reset(self) -> None: """Reset the log dir to the default.""" - if config.default_journal_dir: - self.logdir.set(config.default_journal_dir_str) + if config.default_journal_dir_path: + self.logdir.set(config.default_journal_dir) self.outvarchanged() @@ -1134,11 +1134,11 @@ class PreferencesDialog(tk.Toplevel): config.set( 'outdir', - join(config.home, self.outdir.get()[2:]) if self.outdir.get().startswith('~') else self.outdir.get() + join(config.home_path, self.outdir.get()[2:]) if self.outdir.get().startswith('~') else self.outdir.get() ) logdir = self.logdir.get() - if config.default_journal_dir and logdir.lower() == config.default_journal_dir_str.lower(): + if config.default_journal_dir_path and logdir.lower() == config.default_journal_dir.lower(): config.set('journaldir', '') # default location else: From 3ac956dceca92ce5c0c8314f7d44231b71735d09 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 13 Jan 2021 22:22:48 +0200 Subject: [PATCH 271/727] Removed uneeded str() calls --- config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 8d745eac..8e3ef9be 100644 --- a/config.py +++ b/config.py @@ -350,7 +350,7 @@ class WinConfig(AbstractConfig): self.identifier = applongname if (outdir_str := self.get_str('outdir')) is None or not pathlib.Path(outdir_str).is_dir(): docs = known_folder_path(FOLDERID_Documents) - self.set('outdir', docs if docs is not None else str(self.home_path)) + self.set('outdir', docs if docs is not None else self.home) def __setup_winsparkle(self): create_key_defaults = functools.partial( @@ -711,7 +711,7 @@ class LinuxConfig(AbstractConfig): self.config.add_section(self.SECTION) if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir(): - self.set('outdir', str(self.home_path)) + self.set('outdir', self.home) def __escape(self, s: str) -> str: """ From a9e18b6e087133734a904b1f90137b5656639c46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Jan 2021 06:25:50 +0000 Subject: [PATCH 272/727] Bump flake8-annotations-coverage from 0.0.4 to 0.0.5 Bumps [flake8-annotations-coverage](https://github.com/best-doctor/flake8-annotations-coverage) from 0.0.4 to 0.0.5. - [Release notes](https://github.com/best-doctor/flake8-annotations-coverage/releases) - [Commits](https://github.com/best-doctor/flake8-annotations-coverage/commits) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index cab9802b..fd330ddd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ # Static analysis tools flake8==3.8.4 -flake8-annotations-coverage==0.0.4 +flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.3.1 flake8-docstrings==1.5.0 From e12a2724c5280f10eca53b8cc0bde30b7a5d5749 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jan 2021 07:33:23 +0000 Subject: [PATCH 273/727] Bump pytest-cov from 2.10.1 to 2.11.0 Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 2.10.1 to 2.11.0. - [Release notes](https://github.com/pytest-dev/pytest-cov/releases) - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v2.10.1...v2.11.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index fd330ddd..c06118ab 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -27,7 +27,7 @@ py2exe==0.10.1.0; sys_platform == 'win32' # Testing pytest==6.2.1 -pytest-cov==2.10.1 # Pytest code coverage support +pytest-cov==2.11.0 # Pytest code coverage support coverage[toml]==5.3.1 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs From 3f88f1af5b561e9de59e9d600f68020f9dba03d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jan 2021 07:33:24 +0000 Subject: [PATCH 274/727] Bump safety from 1.10.2 to 1.10.3 Bumps [safety](https://github.com/pyupio/safety) from 1.10.2 to 1.10.3. - [Release notes](https://github.com/pyupio/safety/releases) - [Changelog](https://github.com/pyupio/safety/blob/master/HISTORY.rst) - [Commits](https://github.com/pyupio/safety/compare/1.10.2...1.10.3) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index c06118ab..2faf75c6 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,7 +13,7 @@ flake8-use-fstring==1.1 mypy==0.790 pep8-naming==0.11.1 -safety==1.10.2 +safety==1.10.3 # Code formatting tools autopep8==1.5.4 From 1b0345436b2667c2536b0751d0b69baa0041c127 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Jan 2021 06:20:42 +0000 Subject: [PATCH 275/727] Bump flake8-json from 20.12.1 to 21.1.0 Bumps [flake8-json](https://gitlab.com/pycqa/flake8-json) from 20.12.1 to 21.1.0. - [Release notes](https://gitlab.com/pycqa/flake8-json/tags) - [Commits](https://gitlab.com/pycqa/flake8-json/compare/20.12.1...21.1.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 2faf75c6..1dffb52a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ flake8-comprehensions==3.3.1 flake8-docstrings==1.5.0 isort==5.7.0 flake8-isort==4.0.0 -flake8-json==20.12.1 +flake8-json==21.1.0 flake8-noqa==1.0.5 flake8-polyfill==1.0.2 flake8-use-fstring==1.1 From 77a20fd575afbfa6cc3b6ee38ac0db801d950339 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Jan 2021 05:54:04 +0000 Subject: [PATCH 276/727] Bump pytest-cov from 2.11.0 to 2.11.1 Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 2.11.0 to 2.11.1. - [Release notes](https://github.com/pytest-dev/pytest-cov/releases) - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v2.11.0...v2.11.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 1dffb52a..18830945 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -27,7 +27,7 @@ py2exe==0.10.1.0; sys_platform == 'win32' # Testing pytest==6.2.1 -pytest-cov==2.11.0 # Pytest code coverage support +pytest-cov==2.11.1 # Pytest code coverage support coverage[toml]==5.3.1 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs From e304d63713152f651fefc34813930f2e864c5ca7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Jan 2021 07:13:37 +0000 Subject: [PATCH 277/727] Bump mypy from 0.790 to 0.800 Bumps [mypy](https://github.com/python/mypy) from 0.790 to 0.800. - [Release notes](https://github.com/python/mypy/releases) - [Commits](https://github.com/python/mypy/compare/v0.790...v0.800) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 18830945..21479699 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -11,7 +11,7 @@ flake8-noqa==1.0.5 flake8-polyfill==1.0.2 flake8-use-fstring==1.1 -mypy==0.790 +mypy==0.800 pep8-naming==0.11.1 safety==1.10.3 From 588fd7a7179a731ffbdffb123a6ddbb9d11daa4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Jan 2021 07:13:34 +0000 Subject: [PATCH 278/727] Bump py2exe from 0.10.1.0 to 0.10.2.0 Bumps [py2exe](https://github.com/py2exe/py2exe) from 0.10.1.0 to 0.10.2.0. - [Release notes](https://github.com/py2exe/py2exe/releases) - [Changelog](https://github.com/py2exe/py2exe/blob/master/ChangeLog) - [Commits](https://github.com/py2exe/py2exe/compare/v0.10.1.0...v0.10.2.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 21479699..7d09ba98 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -23,7 +23,7 @@ grip==4.5.2 # Packaging # We only need py2exe on windows. -py2exe==0.10.1.0; sys_platform == 'win32' +py2exe==0.10.2.0; sys_platform == 'win32' # Testing pytest==6.2.1 From ba85df78def69806899ffb6fbf1287c59e910f14 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Jan 2021 06:22:22 +0000 Subject: [PATCH 279/727] Bump pytest from 6.2.1 to 6.2.2 Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.1 to 6.2.2. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.2.1...6.2.2) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7d09ba98..c951e44a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,7 +26,7 @@ grip==4.5.2 py2exe==0.10.2.0; sys_platform == 'win32' # Testing -pytest==6.2.1 +pytest==6.2.2 pytest-cov==2.11.1 # Pytest code coverage support coverage[toml]==5.3.1 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs From 8b70ae702781a6562320701163c8377b6ce17dbb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Jan 2021 06:18:48 +0000 Subject: [PATCH 280/727] Bump coverage[toml] from 5.3.1 to 5.4 Bumps [coverage[toml]](https://github.com/nedbat/coveragepy) from 5.3.1 to 5.4. - [Release notes](https://github.com/nedbat/coveragepy/releases) - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst) - [Commits](https://github.com/nedbat/coveragepy/compare/coverage-5.3.1...coverage-5.4) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index c951e44a..700de2cb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -28,7 +28,7 @@ py2exe==0.10.2.0; sys_platform == 'win32' # Testing pytest==6.2.2 pytest-cov==2.11.1 # Pytest code coverage support -coverage[toml]==5.3.1 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +coverage[toml]==5.4 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs # All of the normal requirements From 409e851840d8311f67913f149da239942c4cb8fb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:21:29 +0000 Subject: [PATCH 281/727] Port in the journals_dir locking and other changes * Use a lock file in the journals_dir location to prevent more than one instance running against the same journals. We no longer check just for a Windows handle. So this is more correct on win32 *and* is now a thing on all other platforms. * Adds `--suppress-dupe-process-popup` CL arg to suppress "we're a dupe!" popup to aid those using batch files to launch EDMC alongside the game. * Two minor fixups of typos in PLUGINS.md. * Misc noqa comments and other flake8 fixups. We're now only missing type annotations in EDMarketConnector.py. # Conflicts: # EDMarketConnector.py --- EDMarketConnector.py | 275 ++++++++++++++----------------------------- 1 file changed, 91 insertions(+), 184 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 55ff13a5..29fe30d5 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -11,126 +11,17 @@ import sys import webbrowser from builtins import object, str from os import chdir, environ +from os import getpid as os_getpid from os.path import dirname, isdir, join from sys import platform from time import localtime, strftime, time -from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple, cast +from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple from constants import applongname, appname, protocolhandler_redirect # config will now cause an appname logger to be set up, so we need the # console redirect before this if __name__ == '__main__': - def no_other_instance_running() -> bool: # noqa: CCR001 - """ - Ensure only one copy of the app is running under this user account. - - OSX does this automatically. - - :returns: True if we are the single instance, else False. - """ - # TODO: Linux implementation - if platform == 'win32': - import ctypes - from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR - - EnumWindows = ctypes.windll.user32.EnumWindows # noqa: N806 - GetClassName = ctypes.windll.user32.GetClassNameW # noqa: N806 - GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int] - GetWindowText = ctypes.windll.user32.GetWindowTextW # noqa: N806 - GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int] - GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW # noqa: N806 - GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 - - SW_RESTORE = 9 # noqa: N806 - SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow # noqa: N806 - ShowWindow = ctypes.windll.user32.ShowWindow # noqa: N806 - ShowWindowAsync = ctypes.windll.user32.ShowWindowAsync # noqa: N806 - - COINIT_MULTITHREADED = 0 # noqa: N806,F841 - COINIT_APARTMENTTHREADED = 0x2 # noqa: N806 - COINIT_DISABLE_OLE1DDE = 0x4 # noqa: N806 - CoInitializeEx = ctypes.windll.ole32.CoInitializeEx # noqa: N806 - - ShellExecute = ctypes.windll.shell32.ShellExecuteW # noqa: N806 - ShellExecute.argtypes = [HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT] - - def window_title(h): - if h: - text_length = GetWindowTextLength(h) + 1 - buf = ctypes.create_unicode_buffer(text_length) - if GetWindowText(h, buf, text_length): - return buf.value - - return None - - @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) - def enumwindowsproc(window_handle, l_param): - # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 - cls = ctypes.create_unicode_buffer(257) - if GetClassName(window_handle, cls, 257) \ - and cls.value == 'TkTopLevel' \ - and window_title(window_handle) == applongname \ - and GetProcessHandleFromHwnd(window_handle): - # If GetProcessHandleFromHwnd succeeds then the app is already running as this user - if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect): - CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) - # Wait for it to be responsive to avoid ShellExecute recursing - ShowWindow(window_handle, SW_RESTORE) - ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) - - else: - ShowWindowAsync(window_handle, SW_RESTORE) - SetForegroundWindow(window_handle) - - return False - - return True - - return EnumWindows(enumwindowsproc, 0) - - return True - - def already_running_popup(): - """Create the "already running" popup.""" - import tkinter as tk - from tkinter import ttk - - root = tk.Tk(className=appname.lower()) - - frame = tk.Frame(root) - frame.grid(row=1, column=0, sticky=tk.NSEW) - - label = tk.Label(frame) - label['text'] = 'An EDMarketConnector.exe process was already running, exiting.' - label.grid(row=1, column=0, sticky=tk.NSEW) - - button = ttk.Button(frame, text='OK', command=lambda: sys.exit(0)) - button.grid(row=2, column=0, sticky=tk.S) - - root.mainloop() - - if not no_other_instance_running(): - # There's a copy already running. We want to inform the user by - # **appending** to the log file, not truncating it. - if getattr(sys, 'frozen', False): - # By default py2exe tries to write log to dirname(sys.executable) which fails when installed - import tempfile - - # unbuffered not allowed for text in python3, so use `1 for line buffering - sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='a', buffering=1) - - # Logging isn't set up yet. - # We'll keep this print, but it will be over-written by any subsequent - # write by the already-running process. - print("An EDMarketConnector.exe process was already running, exiting.") - - # To be sure the user knows, we need a popup - already_running_popup() - # If the user closes the popup with the 'X', not the 'OK' button we'll - # reach here. - sys.exit(0) - # Keep this as the very first code run to be as sure as possible of no # output until after this redirect is done, if needed. if getattr(sys, 'frozen', False): @@ -141,16 +32,14 @@ if __name__ == '__main__': sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1) # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup +# These need to be after the stdout/err redirect because they will cause +# logging to be set up. # isort: off -import killswitch # Will cause a logging import/startup so needs to be after the redirect +import killswitch from config import appversion, appversion_nobuild, config, copyright # isort: on - -# After the redirect in case config does logging setup -from config import appversion, appversion_nobuild, config, copyright from EDMCLogging import edmclogger, logger, logging -from journal_lock import JournalLock, JournalLockResult if __name__ == '__main__': # noqa: C901 # Command-line arguments @@ -162,26 +51,23 @@ if __name__ == '__main__': # noqa: C901 "such as EDSM, Inara.cz and EDDB." ) - parser.add_argument('--trace', - help='Set the Debug logging loglevel to TRACE', - action='store_true', - ) + parser.add_argument( + '--trace', + help='Set the Debug logging loglevel to TRACE', + action='store_true', + ) + + parser.add_argument( + '--reset-ui', + help='reset UI theme and transparency to defaults', + action='store_true' + ) parser.add_argument('--suppress-dupe-process-popup', help='Suppress the popup from when the application detects another instance already running', action='store_true' ) - parser.add_argument('--force-localserver-for-auth', - help='Force EDMC to use a localhost webserver for Frontier Auth callback', - action='store_true' - ) - - parser.add_argument('edmc', - help='Callback from Frontier Auth', - nargs='*' - ) - args = parser.parse_args() if args.trace: @@ -190,18 +76,32 @@ if __name__ == '__main__': # noqa: C901 else: edmclogger.set_channels_loglevel(logging.DEBUG) - if args.force_localserver_for_auth: - config.set_auth_force_localserver() + def no_other_instance_running() -> bool: # noqa: CCR001 + """ + Ensure only one copy of the app is running for the configured journal directory. - def handle_edmc_callback_or_foregrounding(): # noqa: CCR001 - """Handle any edmc:// auth callback, else foreground existing window.""" + :returns: True if we are the single instance, else False. + """ logger.trace('Begin...') if platform == 'win32': + logger.trace('win32, using msvcrt') + # win32 doesn't have fcntl, so we have to use msvcrt + import msvcrt - # If *this* instance hasn't locked, then another already has and we - # now need to do the edmc:// checks for auth callback - if locked != JournalLockResult.LOCKED: + logger.trace(f'journal_dir_lockfile = {journal_dir_lockfile!r}') + + locked = False + try: + msvcrt.locking(journal_dir_lockfile.fileno(), msvcrt.LK_NBLCK, 4096) + + except Exception as e: + logger.info(f"Exception: Couldn't lock journal directory \"{journal_dir}\"" + f", assuming another process running: {e!r}") + locked = True + + if locked: + # Need to do the check for this being an edmc:// auth callback import ctypes from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR @@ -236,7 +136,7 @@ if __name__ == '__main__': # noqa: C901 return None @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) - def enumwindowsproc(window_handle, l_param): + def enumwindowsproc(window_handle, l_param): # noqa: CCR001 """ Determine if any window for the Application exists. @@ -259,7 +159,6 @@ if __name__ == '__main__': # noqa: C901 if GetProcessHandleFromHwnd(window_handle): # If GetProcessHandleFromHwnd succeeds then the app is already running as this user if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect): - logger.debug('Invoked with edmc:// protocol handler arg') CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) # Wait for it to be responsive to avoid ShellExecute recursing ShowWindow(window_handle, SW_RESTORE) @@ -281,7 +180,31 @@ if __name__ == '__main__': # noqa: C901 # Ref: EnumWindows(enumwindowsproc, 0) - return + return False # Another instance is running + + else: + logger.trace('NOT win32, using fcntl') + try: + import fcntl + + except ImportError: + logger.warning("Not on win32 and we have no fcntl, can't use a file lock!" + "Allowing multiple instances!") + return True # Lie that no other instances are running. + + try: + fcntl.flock(journal_dir_lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) + + except Exception as e: + logger.info(f"Exception: Couldn't lock journal directory \"{journal_dir}\"," + f"assuming another process running: {e!r}") + return False + + journal_dir_lockfile.write(f"Path: {journal_dir}\nPID: {os_getpid()}\n") + journal_dir_lockfile.flush() + + logger.trace('Done') + return True def already_running_popup(): """Create the "already running" popup.""" @@ -306,22 +229,30 @@ if __name__ == '__main__': # noqa: C901 root.mainloop() - journal_lock = JournalLock() - locked = journal_lock.obtain_lock() + journal_dir: str = config.get_str('journaldir') or config.default_journal_dir + # This must be at top level to guarantee the file handle doesn't go out + # of scope and get cleaned up, removing the lock with it. + journal_dir_lockfile_name = join(journal_dir, 'edmc-journal-lock.txt') + try: + journal_dir_lockfile = open(journal_dir_lockfile_name, mode='w+', encoding='utf-8') - handle_edmc_callback_or_foregrounding() + # Linux CIFS read-only mount throws: OSError(30, 'Read-only file system') + # Linux no-write-perm directory throws: PermissionError(13, 'Permission denied') + except Exception as e: # For remote FS this could be any of a wide range of exceptions + logger.warning(f"Couldn't open \"{journal_dir_lockfile_name}\" for \"w+\"" + f" Aborting duplicate process checks: {e!r}") - if locked == JournalLockResult.ALREADY_LOCKED: - # There's a copy already running. + else: + if not no_other_instance_running(): + # There's a copy already running. - logger.info("An EDMarketConnector.exe process was already running, exiting.") + logger.info("An EDMarketConnector.exe process was already running, exiting.") - # To be sure the user knows, we need a popup - if not args.edmc: + # To be sure the user knows, we need a popup already_running_popup() - # If the user closes the popup with the 'X', not the 'OK' button we'll - # reach here. - sys.exit(0) + # If the user closes the popup with the 'X', not the 'OK' button we'll + # reach here. + sys.exit(0) if getattr(sys, 'frozen', False): # Now that we're sure we're the only instance running we can truncate the logfile @@ -353,7 +284,7 @@ import tkinter as tk import tkinter.filedialog import tkinter.font import tkinter.messagebox -from tkinter import Toplevel, ttk +from tkinter import ttk import commodity import companion @@ -602,7 +533,7 @@ class AppWindow(object): # update geometry if config.get_str('geometry'): - match = re.match(r'\+([\-\d]+)\+([\-\d]+)', config.get_str('geometry')) # noqa: W605 + match = re.match(r'\+([\-\d]+)\+([\-\d]+)', config.get_str('geometry')) if match: if platform == 'darwin': # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 @@ -1140,7 +1071,11 @@ class AppWindow(object): def shipyard_url(self, shipname: str) -> str: """Despatch a ship URL to the configured handler.""" if not bool(config.get_int("use_alt_shipyard_open")): - return plug.invoke(config.get_str('shipyard_provider'), 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) + return plug.invoke(config.get_str('shipyard_provider'), + 'EDSY', + 'shipyard_url', + monitor.ship(), + monitor.is_beta) # Avoid file length limits if possible provider = config.get_str('shipyard_provider', default='EDSY') @@ -1489,36 +1424,7 @@ def show_killswitch_poppup(root=None): # Run the app -if __name__ == "__main__": - # Command-line arguments - parser = argparse.ArgumentParser( - prog=appname, - description="Utilises Elite Dangerous Journal files and the Frontier " - "Companion API (CAPI) service to gather data about a " - "player's state and actions to upload to third-party sites " - "such as EDSM, Inara.cz and EDDB." - ) - - parser.add_argument( - '--trace', - help='Set the Debug logging loglevel to TRACE', - action='store_true', - ) - - parser.add_argument( - '--reset-ui', - help='reset UI theme and transparency to defaults', - action='store_true' - ) - - args = parser.parse_args() - - if args.trace: - logger.setLevel(logging.TRACE) - edmclogger.set_channels_loglevel(logging.TRACE) - else: - edmclogger.set_channels_loglevel(logging.DEBUG) - +if __name__ == "__main__": # noqa: C901 logger.info(f'Startup v{appversion} : Running on Python v{sys.version}') logger.debug(f'''Platform: {sys.platform} {sys.platform == "win32" and sys.getwindowsversion()} argv[0]: {sys.argv[0]} @@ -1610,6 +1516,7 @@ sys.path: {sys.path}''' @property def test_prop(self): + """Test property.""" logger.debug("test log from property") return "Test property is testy" From 5093fb58ee374032943f0fd8227e1d9ced350433 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 23 Jan 2021 13:38:08 +0000 Subject: [PATCH 282/727] Add `--force-localserver-for-auth` CL arg to EDMarketConnector --- EDMarketConnector.py | 8 ++++++++ config.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 29fe30d5..2088489b 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -68,6 +68,11 @@ if __name__ == '__main__': # noqa: C901 action='store_true' ) + parser.add_argument('--force-localserver-for-auth', + help='Force EDMC to use a localhost webserver for Frontier Auth callback', + action='store_true' + ) + args = parser.parse_args() if args.trace: @@ -76,6 +81,9 @@ if __name__ == '__main__': # noqa: C901 else: edmclogger.set_channels_loglevel(logging.DEBUG) + if args.force_localserver_for_auth: + config.set_auth_force_localserver() + def no_other_instance_running() -> bool: # noqa: CCR001 """ Ensure only one copy of the app is running for the configured journal directory. diff --git a/config.py b/config.py index 8e3ef9be..06ccfc35 100644 --- a/config.py +++ b/config.py @@ -117,6 +117,7 @@ class AbstractConfig(abc.ABC): identifier: str __in_shutdown = False # Is the application currently shutting down ? + __auth_force_localserver = False # Should we use localhost for auth callback ? def __init__(self) -> None: self.home_path = pathlib.Path.home() @@ -128,6 +129,13 @@ class AbstractConfig(abc.ABC): def shutting_down(self) -> bool: return self.__in_shutdown + def set_auth_force_localserver(self): + self.__auth_force_localserver = True + + @property + def auth_force_localserver(self) -> bool: + return self.__auth_force_localserver + @property def app_dir(self) -> str: """Return a string version of app_dir.""" From f4d261d5b290bdfeec861803dde1d525b76750a4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Feb 2021 06:06:34 +0000 Subject: [PATCH 283/727] Bump flake8-noqa from 1.0.5 to 1.1.0 Bumps [flake8-noqa](https://github.com/plinss/flake8-noqa) from 1.0.5 to 1.1.0. - [Release notes](https://github.com/plinss/flake8-noqa/releases) - [Commits](https://github.com/plinss/flake8-noqa/compare/v1.0.5...v1.1.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 700de2cb..7acc86b3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,7 +7,7 @@ flake8-docstrings==1.5.0 isort==5.7.0 flake8-isort==4.0.0 flake8-json==21.1.0 -flake8-noqa==1.0.5 +flake8-noqa==1.1.0 flake8-polyfill==1.0.2 flake8-use-fstring==1.1 From 03c2e6a26c95093ed1ee98fe3b43b279643740fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Feb 2021 06:07:38 +0000 Subject: [PATCH 284/727] Bump autopep8 from 1.5.4 to 1.5.5 Bumps [autopep8](https://github.com/hhatto/autopep8) from 1.5.4 to 1.5.5. - [Release notes](https://github.com/hhatto/autopep8/releases) - [Commits](https://github.com/hhatto/autopep8/compare/v1.5.4...v1.5.5) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7acc86b3..ebda25e4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -16,7 +16,7 @@ pep8-naming==0.11.1 safety==1.10.3 # Code formatting tools -autopep8==1.5.4 +autopep8==1.5.5 # HTML changelogs grip==4.5.2 From b24b4ce6755a611756f9c590f8d526e16ce19d54 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Feb 2021 07:19:15 +0000 Subject: [PATCH 285/727] Bump watchdog from 1.0.2 to 2.0.0 Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 1.0.2 to 2.0.0. - [Release notes](https://github.com/gorakhargosh/watchdog/releases) - [Changelog](https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst) - [Commits](https://github.com/gorakhargosh/watchdog/compare/v1.0.2...v2.0.0) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0824d629..1cc32835 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 requests==2.25.1 -watchdog==1.0.2 +watchdog==2.0.0 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From ce5a586ed0c63744e60c2946d88b69fa68268879 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 18 Feb 2021 06:00:14 +0000 Subject: [PATCH 286/727] Bump watchdog from 2.0.0 to 2.0.1 Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 2.0.0 to 2.0.1. - [Release notes](https://github.com/gorakhargosh/watchdog/releases) - [Changelog](https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst) - [Commits](https://github.com/gorakhargosh/watchdog/compare/v2.0.0...v2.0.1) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1cc32835..a3cd6507 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 requests==2.25.1 -watchdog==2.0.0 +watchdog==2.0.1 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From f18a18f7dd93ee6062ae35d1108f994fb114c4c0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Feb 2021 07:04:37 +0000 Subject: [PATCH 287/727] Bump py2exe from 0.10.2.0 to 0.10.2.1 Bumps [py2exe](https://github.com/py2exe/py2exe) from 0.10.2.0 to 0.10.2.1. - [Release notes](https://github.com/py2exe/py2exe/releases) - [Changelog](https://github.com/py2exe/py2exe/blob/master/ChangeLog) - [Commits](https://github.com/py2exe/py2exe/compare/v0.10.2.0...v0.10.2.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ebda25e4..fc937f73 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -23,7 +23,7 @@ grip==4.5.2 # Packaging # We only need py2exe on windows. -py2exe==0.10.2.0; sys_platform == 'win32' +py2exe==0.10.2.1; sys_platform == 'win32' # Testing pytest==6.2.2 From 2abd3e825d2cdb871dbd5d5c4dd85af00f831e6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Feb 2021 07:04:39 +0000 Subject: [PATCH 288/727] Bump mypy from 0.800 to 0.812 Bumps [mypy](https://github.com/python/mypy) from 0.800 to 0.812. - [Release notes](https://github.com/python/mypy/releases) - [Commits](https://github.com/python/mypy/compare/v0.800...v0.812) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index fc937f73..c6bd6a70 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -11,7 +11,7 @@ flake8-noqa==1.1.0 flake8-polyfill==1.0.2 flake8-use-fstring==1.1 -mypy==0.800 +mypy==0.812 pep8-naming==0.11.1 safety==1.10.3 From 49cc2b4f0d4b10f99af54a43ec4ec10876a7d0e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Feb 2021 06:02:42 +0000 Subject: [PATCH 289/727] Bump watchdog from 2.0.1 to 2.0.2 Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 2.0.1 to 2.0.2. - [Release notes](https://github.com/gorakhargosh/watchdog/releases) - [Changelog](https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst) - [Commits](https://github.com/gorakhargosh/watchdog/compare/v2.0.1...v2.0.2) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a3cd6507..4d15cdef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 requests==2.25.1 -watchdog==2.0.1 +watchdog==2.0.2 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From 8c83625592facaa122b7b3f91ac91662aee8d953 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Mar 2021 07:41:24 +0000 Subject: [PATCH 290/727] Bump coverage[toml] from 5.4 to 5.5 Bumps [coverage[toml]](https://github.com/nedbat/coveragepy) from 5.4 to 5.5. - [Release notes](https://github.com/nedbat/coveragepy/releases) - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst) - [Commits](https://github.com/nedbat/coveragepy/compare/coverage-5.4...coverage-5.5) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index c6bd6a70..6f6e72ab 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -28,7 +28,7 @@ py2exe==0.10.2.1; sys_platform == 'win32' # Testing pytest==6.2.2 pytest-cov==2.11.1 # Pytest code coverage support -coverage[toml]==5.4 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +coverage[toml]==5.5 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs # All of the normal requirements From 471714f14918ec0172d82bf4ca14c6793e7ea2ba Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 5 Mar 2021 12:51:14 +0000 Subject: [PATCH 291/727] Bump version for `develop` to 4.3.0-beta1 Work against stable/main is going to be using 4.2.0-beta1 shortly. --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 06ccfc35..a77bd49c 100644 --- a/config.py +++ b/config.py @@ -28,7 +28,7 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '4.2.0-beta1' # -rc1+a872b5f' +appversion = '4.3.0-beta1' # -rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' From b3959cb8d28c7da3f5a93f60371cb0a73c78ba84 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 5 Mar 2021 12:03:54 +0000 Subject: [PATCH 292/727] Move journal locking code into new monitor.JournalLock class --- EDMarketConnector.py | 57 ++++-------------------------------- monitor.py | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 51 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 2088489b..131ce454 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -11,7 +11,6 @@ import sys import webbrowser from builtins import object, str from os import chdir, environ -from os import getpid as os_getpid from os.path import dirname, isdir, join from sys import platform from time import localtime, strftime, time @@ -40,6 +39,7 @@ from config import appversion, appversion_nobuild, config, copyright # isort: on from EDMCLogging import edmclogger, logger, logging +from monitor import JournalLock if __name__ == '__main__': # noqa: C901 # Command-line arguments @@ -92,23 +92,11 @@ if __name__ == '__main__': # noqa: C901 """ logger.trace('Begin...') + locked = journal_lock.journaldir_obtain_lock() + if platform == 'win32': - logger.trace('win32, using msvcrt') - # win32 doesn't have fcntl, so we have to use msvcrt - import msvcrt - logger.trace(f'journal_dir_lockfile = {journal_dir_lockfile!r}') - - locked = False - try: - msvcrt.locking(journal_dir_lockfile.fileno(), msvcrt.LK_NBLCK, 4096) - - except Exception as e: - logger.info(f"Exception: Couldn't lock journal directory \"{journal_dir}\"" - f", assuming another process running: {e!r}") - locked = True - - if locked: + if not locked: # Need to do the check for this being an edmc:// auth callback import ctypes from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR @@ -190,28 +178,6 @@ if __name__ == '__main__': # noqa: C901 return False # Another instance is running - else: - logger.trace('NOT win32, using fcntl') - try: - import fcntl - - except ImportError: - logger.warning("Not on win32 and we have no fcntl, can't use a file lock!" - "Allowing multiple instances!") - return True # Lie that no other instances are running. - - try: - fcntl.flock(journal_dir_lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) - - except Exception as e: - logger.info(f"Exception: Couldn't lock journal directory \"{journal_dir}\"," - f"assuming another process running: {e!r}") - return False - - journal_dir_lockfile.write(f"Path: {journal_dir}\nPID: {os_getpid()}\n") - journal_dir_lockfile.flush() - - logger.trace('Done') return True def already_running_popup(): @@ -237,20 +203,9 @@ if __name__ == '__main__': # noqa: C901 root.mainloop() - journal_dir: str = config.get_str('journaldir') or config.default_journal_dir - # This must be at top level to guarantee the file handle doesn't go out - # of scope and get cleaned up, removing the lock with it. - journal_dir_lockfile_name = join(journal_dir, 'edmc-journal-lock.txt') - try: - journal_dir_lockfile = open(journal_dir_lockfile_name, mode='w+', encoding='utf-8') + journal_lock = JournalLock() - # Linux CIFS read-only mount throws: OSError(30, 'Read-only file system') - # Linux no-write-perm directory throws: PermissionError(13, 'Permission denied') - except Exception as e: # For remote FS this could be any of a wide range of exceptions - logger.warning(f"Couldn't open \"{journal_dir_lockfile_name}\" for \"w+\"" - f" Aborting duplicate process checks: {e!r}") - - else: + if journal_lock.journal_dir_lockfile: if not no_other_instance_running(): # There's a copy already running. diff --git a/monitor.py b/monitor.py index abeae8de..266e168c 100644 --- a/monitor.py +++ b/monitor.py @@ -2,6 +2,7 @@ from collections import defaultdict, OrderedDict import json import re import threading +from os import getpid as os_getpid from os import listdir, SEEK_SET, SEEK_END from os.path import basename, expanduser, isdir, join from sys import platform @@ -1089,3 +1090,71 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # singleton monitor = EDLogs() + + +class JournalLock: + """Handle locking of journal directory.""" + + def __init__(self): + """Initialise where the journal directory and lock file are.""" + self.journal_dir: str = config.get('journaldir') or config.default_journal_dir + self.journal_dir_lock = None + + self.journal_dir_lockfile_name: str = join(self.journal_dir, 'edmc-journal-lock.txt') + try: + self.journal_dir_lockfile = open(self.journal_dir_lockfile_name, mode='w+', encoding='utf-8') + + # Linux CIFS read-only mount throws: OSError(30, 'Read-only file system') + # Linux no-write-perm directory throws: PermissionError(13, 'Permission denied') + except Exception as e: # For remote FS this could be any of a wide range of exceptions + logger.warning(f"Couldn't open \"{self.journal_dir_lockfile_name}\" for \"w+\"" + f" Aborting duplicate process checks: {e!r}") + + def journaldir_obtain_lock(self) -> bool: + """ + Attempt to obtain a lock on the journal directory. + + :return: bool - True if we successfully obtained the lock + """ + logger.trace(f'journal_dir_lockfile = {self.journal_dir_lockfile!r}') + + if platform == 'win32': + logger.trace('win32, using msvcrt') + # win32 doesn't have fcntl, so we have to use msvcrt + import msvcrt + + try: + msvcrt.locking(self.journal_dir_lockfile.fileno(), msvcrt.LK_NBLCK, 4096) + + except Exception as e: + logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\"" + f", assuming another process running: {e!r}") + return False + + else: + logger.trace('NOT win32, using fcntl') + try: + import fcntl + + except ImportError: + logger.warning("Not on win32 and we have no fcntl, can't use a file lock!" + "Allowing multiple instances!") + return True # Lie about being locked + + try: + fcntl.flock(self.journal_dir_lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) + + except Exception as e: + logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\"," + f"assuming another process running: {e!r}") + return False + + self.journal_dir_lockfile.write(f"Path: {self.journal_dir}\nPID: {os_getpid()}\n") + self.journal_dir_lockfile.flush() + + logger.trace('Done') + return True + + def journaldir_release_lock(self) -> bool: + """Release lock on journal directory.""" + pass From 0cb0701ca8674036c7bfbeaf5530022f181f456f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:22:21 +0000 Subject: [PATCH 293/727] 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(). # Conflicts: # EDMarketConnector.py --- EDMarketConnector.py | 5 ++- monitor.py | 85 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 131ce454..70bab6fa 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -92,8 +92,6 @@ if __name__ == '__main__': # noqa: C901 """ logger.trace('Begin...') - locked = journal_lock.journaldir_obtain_lock() - if platform == 'win32': if not locked: @@ -204,6 +202,7 @@ if __name__ == '__main__': # noqa: C901 root.mainloop() journal_lock = JournalLock() + locked = journal_lock.obtain_lock() if journal_lock.journal_dir_lockfile: if not no_other_instance_running(): @@ -571,7 +570,7 @@ class AppWindow(object): hotkeymgr.register(self.w, config.get_int('hotkey_code'), config.get_int('hotkey_mods')) # Update Journal lock if needs be. - journal_lock.update_lock(self.w) + journal_lock.update_lock() # (Re-)install log monitoring if not monitor.start(self.w): diff --git a/monitor.py b/monitor.py index 266e168c..2090181b 100644 --- a/monitor.py +++ b/monitor.py @@ -5,6 +5,7 @@ import threading from os import getpid as os_getpid from os import listdir, SEEK_SET, SEEK_END from os.path import basename, expanduser, isdir, join +import pathlib from sys import platform from time import gmtime, localtime, sleep, strftime, strptime, time from calendar import timegm @@ -1098,9 +1099,20 @@ class JournalLock: def __init__(self): """Initialise where the journal directory and lock file are.""" self.journal_dir: str = config.get('journaldir') or config.default_journal_dir + self.journal_dir_path = pathlib.Path(self.journal_dir) self.journal_dir_lock = None + self.journal_dir_lockfile_name = None + self.journal_dir_lockfile = None - self.journal_dir_lockfile_name: str = join(self.journal_dir, 'edmc-journal-lock.txt') + def obtain_lock(self) -> bool: + """ + Attempt to obtain a lock on the journal directory. + + :return: bool - True if we successfully obtained the lock + """ + logger.trace(f'journal_dir_lockfile = {self.journal_dir_lockfile!r}') + + self.journal_dir_lockfile_name: str = self.journal_dir_path / 'edmc-journal-lock.txt' try: self.journal_dir_lockfile = open(self.journal_dir_lockfile_name, mode='w+', encoding='utf-8') @@ -1110,14 +1122,6 @@ class JournalLock: logger.warning(f"Couldn't open \"{self.journal_dir_lockfile_name}\" for \"w+\"" f" Aborting duplicate process checks: {e!r}") - def journaldir_obtain_lock(self) -> bool: - """ - Attempt to obtain a lock on the journal directory. - - :return: bool - True if we successfully obtained the lock - """ - logger.trace(f'journal_dir_lockfile = {self.journal_dir_lockfile!r}') - if platform == 'win32': logger.trace('win32, using msvcrt') # win32 doesn't have fcntl, so we have to use msvcrt @@ -1155,6 +1159,63 @@ class JournalLock: logger.trace('Done') return True - def journaldir_release_lock(self) -> bool: - """Release lock on journal directory.""" - pass + def release_lock(self) -> bool: + """ + Release lock on journal directory. + + :return: bool - Success of unlocking operation.""" + unlocked = False + if platform == 'win32': + logger.trace('win32, using msvcrt') + # win32 doesn't have fcntl, so we have to use msvcrt + import msvcrt + + try: + msvcrt.locking(self.journal_dir_lockfile.fileno(), msvcrt.LK_UNLCK, 4096) + + except Exception as e: + logger.info(f"Exception: Couldn't unlock journal directory \"{self.journal_dir}\": {e!r}") + + else: + unlocked = True + + else: + logger.trace('NOT win32, using fcntl') + try: + import fcntl + + except ImportError: + logger.warning("Not on win32 and we have no fcntl, can't use a file lock!") + return True # Lie about being unlocked + + try: + fcntl.flock(self.journal_dir_lockfile, fcntl.LOCK_UN) + + except Exception as e: + logger.info(f"Exception: Couldn't unlock journal directory \"{self.journal_dir}\": {e!r}") + + else: + unlocked = True + + # Close the file whether or not the unlocking succeeded. + self.journal_dir_lockfile.close() + + self.journal_dir_lock = None + self.journal_dir_lockfile_name = None + self.journal_dir_lockfile = None + + return unlocked + + def update_lock(self) -> bool: + """ + Update journal directory lock to new location if possible. + + :return: bool - Success of obtaining new lock + """ + current_journaldir = config.get('journaldir') or config.default_journal_dir + + if current_journaldir == self.journal_dir: + return True # Still the same + + self.journaldir_release_lock() + return self.journaldir_obtain_lock() From 55ee4485d122322b218021a8ba2a8fd7d270eb03 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:23:13 +0000 Subject: [PATCH 294/727] Implement retry of locking when journal dir changed. In case the user does have another EDMC instance running that they need to kill first. # Conflicts: # monitor.py --- EDMarketConnector.py | 2 +- monitor.py | 80 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 70bab6fa..bdc2145b 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -570,7 +570,7 @@ class AppWindow(object): hotkeymgr.register(self.w, config.get_int('hotkey_code'), config.get_int('hotkey_mods')) # Update Journal lock if needs be. - journal_lock.update_lock() + journal_lock.update_lock(self.w) # (Re-)install log monitoring if not monitor.start(self.w): diff --git a/monitor.py b/monitor.py index 2090181b..cb78e14c 100644 --- a/monitor.py +++ b/monitor.py @@ -7,9 +7,11 @@ from os import listdir, SEEK_SET, SEEK_END from os.path import basename, expanduser, isdir, join import pathlib from sys import platform +import tkinter as tk +from tkinter import ttk from time import gmtime, localtime, sleep, strftime, strptime, time from calendar import timegm -from typing import Any, List, MutableMapping, Optional, OrderedDict as OrderedDictT, Tuple, TYPE_CHECKING, Union +from typing import Any, Callable, List, MutableMapping, Optional, OrderedDict as OrderedDictT, Tuple, TYPE_CHECKING, Union if TYPE_CHECKING: import tkinter @@ -1206,16 +1208,76 @@ class JournalLock: return unlocked - def update_lock(self) -> bool: - """ - Update journal directory lock to new location if possible. + class JournalAlreadyLocked(tk.Toplevel): + """Pop-up for when Journal directory already locked.""" - :return: bool - Success of obtaining new lock - """ + def __init__(self, parent: tk.Tk, callback: Callable): + tk.Toplevel.__init__(self, parent) + + self.parent = parent + self.callback = callback + self.title('Journal directory already locked') + + # remove decoration + if platform == 'win32': + self.attributes('-toolwindow', tk.TRUE) + + elif platform == 'darwin': + # http://wiki.tcl.tk/13428 + parent.call('tk::unsupported::MacWindowStyle', 'style', self, 'utility') + + self.resizable(tk.FALSE, tk.FALSE) + + frame = ttk.Frame(self) + frame.grid(sticky=tk.NSEW) + + self.blurb = tk.Label(frame) + self.blurb['text'] = '''The new Journal Directory location is already locked. +You can either attempt to resolve this and then Retry, or choose to Ignore this.''' + self.blurb.grid(row=1, column=0, columnspan=2, sticky=tk.NSEW) + + self.retry_button = ttk.Button(frame, text='Retry', command=self.retry) + self.retry_button.grid(row=2, column=0, sticky=tk.EW) + + self.ignore_button = ttk.Button(frame, text='Ignore', command=self.ignore) + self.ignore_button.grid(row=2, column=1, sticky=tk.EW) + self.protocol("WM_DELETE_WINDOW", self._destroy) + + def retry(self): + logger.trace('User selected: Retry') + self.destroy() + self.callback(True, self.parent) + + def ignore(self): + logger.trace('User selected: Ignore') + self.destroy() + self.callback(False, self.parent) + + def _destroy(self): + logger.trace('User force-closed popup, treating as Ignore') + self.ignore() + + def update_lock(self, parent: tk.Tk): + """Update journal directory lock to new location if possible.""" current_journaldir = config.get('journaldir') or config.default_journal_dir if current_journaldir == self.journal_dir: - return True # Still the same + return # Still the same - self.journaldir_release_lock() - return self.journaldir_obtain_lock() + self.release_lock() + + self.journal_dir = current_journaldir + self.journal_dir_path = pathlib.Path(self.journal_dir) + if not self.obtain_lock(): + # Pop-up message asking for Retry or Ignore + self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) + + def retry_lock(self, retry: bool, parent: tk.Tk): + logger.trace(f'We should retry: {retry}') + + current_journaldir = config.get('journaldir') or config.default_journal_dir + self.journal_dir = current_journaldir + self.journal_dir_path = pathlib.Path(self.journal_dir) + if not self.obtain_lock(): + # Pop-up message asking for Retry or Ignore + self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) From 851c4f0c7efa4be6417556b013ed6712668e24e5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:24:00 +0000 Subject: [PATCH 295/727] Update config.get() calls to config.get_str() # Conflicts: # monitor.py --- monitor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index cb78e14c..11caced1 100644 --- a/monitor.py +++ b/monitor.py @@ -1100,7 +1100,7 @@ class JournalLock: def __init__(self): """Initialise where the journal directory and lock file are.""" - self.journal_dir: str = config.get('journaldir') or config.default_journal_dir + self.journal_dir: str = config.get_str('journaldir') or config.default_journal_dir self.journal_dir_path = pathlib.Path(self.journal_dir) self.journal_dir_lock = None self.journal_dir_lockfile_name = None @@ -1259,7 +1259,7 @@ You can either attempt to resolve this and then Retry, or choose to Ignore this. def update_lock(self, parent: tk.Tk): """Update journal directory lock to new location if possible.""" - current_journaldir = config.get('journaldir') or config.default_journal_dir + current_journaldir = config.get_str('journaldir') or config.default_journal_dir if current_journaldir == self.journal_dir: return # Still the same @@ -1275,7 +1275,10 @@ You can either attempt to resolve this and then Retry, or choose to Ignore this. def retry_lock(self, retry: bool, parent: tk.Tk): logger.trace(f'We should retry: {retry}') - current_journaldir = config.get('journaldir') or config.default_journal_dir + if not retry: + return + + current_journaldir = config.get_str('journaldir') or config.default_journal_dir self.journal_dir = current_journaldir self.journal_dir_path = pathlib.Path(self.journal_dir) if not self.obtain_lock(): From 355d3790d20822f960effe154ca72cceaf7f066f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 6 Mar 2021 12:16:58 +0000 Subject: [PATCH 296/727] build: Now using Python 3.9 * .msi installs * .exe in that runs * Basic tests like 'Update' via CAPI and coriolis ship build work. * `plugintest` use of shutil and sqlite also works. --- EDMarketConnector.wxs | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index 48fc1f22..9013912c 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -198,7 +198,7 @@ - + @@ -602,7 +602,7 @@ - + diff --git a/setup.py b/setup.py index f131f8f2..14cefcaa 100755 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ import semantic_version from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval -if sys.version_info[0:2] != (3, 8): +if sys.version_info[0:2] != (3, 9): raise AssertionError(f'Unexpected python version {sys.version}') if sys.platform == 'win32': From 31da53200bec4bcccabd0711d9ceab4a10082685 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 6 Mar 2021 12:21:46 +0000 Subject: [PATCH 297/727] Bump python version in the github windows build workflow --- .github/workflows/windows-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index f040f24b..2efd61cd 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: "3.8.6" + python-version: "3.9.2" architecture: "x86" - name: Install python tools From d656354a9aca8304a51dbe13f20d352606e11675 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 6 Mar 2021 12:30:11 +0000 Subject: [PATCH 298/727] Releasing.md: Document necessary updates when changing Python version --- docs/Releasing.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/Releasing.md b/docs/Releasing.md index 23ddcb63..3f5419b5 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -356,3 +356,18 @@ If you are making a pre-release then: 1. **DO NOT** merge into `stable`. 1. *Do* merge the code into `beta` after you have made a 'pre-release' on GitHub. + +# Changing Python version + +When changing the Python version (Major.Minor.Patch) used: + +1. Any version change: + + 1. `.github/workflows/windows-build.yml` needs updating to have the GitHub + based build use the correct version. + +1. Major or Minor level changes: + + 1. `setup.py` will need its version check updating. + 1. `EDMarketConnector.wxs` will need updating to reference the correct + pythonXX.dll file. From 64f090487e03e4601dae60d77166cb55b87a37f2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 8 Mar 2021 14:50:56 +0000 Subject: [PATCH 299/727] Need `from config import appname` else DDE ctypes code fails --- protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol.py b/protocol.py index b27c5438..c64ad63a 100644 --- a/protocol.py +++ b/protocol.py @@ -6,7 +6,7 @@ import urllib.request, urllib.error, urllib.parse import sys from EDMCLogging import get_main_logger -from config import config +from config import appname, config from constants import protocolhandler_redirect logger = get_main_logger() From 47d5dce6fe21f8cff78ac6bb74c81f8e195e0ff5 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 12 Jan 2021 18:11:52 +0200 Subject: [PATCH 300/727] Autoformatted code --- protocol.py | 137 ++++++++++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 63 deletions(-) diff --git a/protocol.py b/protocol.py index c64ad63a..0f7f8ce4 100644 --- a/protocol.py +++ b/protocol.py @@ -51,7 +51,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): class ProtocolHandler(GenericProtocolHandler): - POLL = 100 # ms + POLL = 100 # ms def start(self, master): GenericProtocolHandler.start(self, master) @@ -68,84 +68,92 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): def init(self): self = objc.super(EventHandler, self).init() - NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_(self, 'handleEvent:withReplyEvent:', kInternetEventClass, kAEGetURL) + NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_( + self, + 'handleEvent:withReplyEvent:', + kInternetEventClass, + kAEGetURL + ) return self def handleEvent_withReplyEvent_(self, event, replyEvent): - protocolhandler.lasturl = urllib.parse.unquote(event.paramDescriptorForKeyword_(keyDirectObject).stringValue()).strip() + protocolhandler.lasturl = urllib.parse.unquote( + event.paramDescriptorForKeyword_(keyDirectObject).stringValue()).strip() protocolhandler.master.after(ProtocolHandler.POLL, protocolhandler.poll) elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: class WNDCLASS(Structure): - _fields_ = [('style', UINT), - ('lpfnWndProc', WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)), - ('cbClsExtra', INT), - ('cbWndExtra', INT), - ('hInstance', HINSTANCE), - ('hIcon', HICON), - ('hCursor', c_void_p), - ('hbrBackground', HBRUSH), - ('lpszMenuName', LPCWSTR), - ('lpszClassName', LPCWSTR) + _fields_ = [ + ('style', UINT), + ('lpfnWndProc', WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)), + ('cbClsExtra', INT), + ('cbWndExtra', INT), + ('hInstance', HINSTANCE), + ('hIcon', HICON), + ('hCursor', c_void_p), + ('hbrBackground', HBRUSH), + ('lpszMenuName', LPCWSTR), + ('lpszClassName', LPCWSTR) ] - CW_USEDEFAULT = 0x80000000 + CW_USEDEFAULT = 0x80000000 - CreateWindowEx = windll.user32.CreateWindowExW + CreateWindowEx = windll.user32.CreateWindowExW CreateWindowEx.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID] - CreateWindowEx.restype = HWND - RegisterClass = windll.user32.RegisterClassW - RegisterClass.argtypes = [POINTER(WNDCLASS)] - DefWindowProc = windll.user32.DefWindowProcW - GetParent = windll.user32.GetParent + CreateWindowEx.restype = HWND + RegisterClass = windll.user32.RegisterClassW + RegisterClass.argtypes = [POINTER(WNDCLASS)] + DefWindowProc = windll.user32.DefWindowProcW + GetParent = windll.user32.GetParent SetForegroundWindow = windll.user32.SetForegroundWindow - GetMessage = windll.user32.GetMessageW - TranslateMessage = windll.user32.TranslateMessage - DispatchMessage = windll.user32.DispatchMessageW + GetMessage = windll.user32.GetMessageW + TranslateMessage = windll.user32.TranslateMessage + DispatchMessage = windll.user32.DispatchMessageW PostThreadMessage = windll.user32.PostThreadMessageW - SendMessage = windll.user32.SendMessageW + SendMessage = windll.user32.SendMessageW SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM] - PostMessage = windll.user32.PostMessageW + PostMessage = windll.user32.PostMessageW PostMessage.argtypes = [HWND, UINT, WPARAM, LPARAM] - WM_QUIT = 0x0012 - WM_DDE_INITIATE = 0x03E0 - WM_DDE_TERMINATE = 0x03E1 - WM_DDE_ACK = 0x03E4 - WM_DDE_EXECUTE = 0x03E8 + WM_QUIT = 0x0012 + WM_DDE_INITIATE = 0x03E0 + WM_DDE_TERMINATE = 0x03E1 + WM_DDE_ACK = 0x03E4 + WM_DDE_EXECUTE = 0x03E8 - PackDDElParam = windll.user32.PackDDElParam + PackDDElParam = windll.user32.PackDDElParam PackDDElParam.argtypes = [UINT, LPARAM, LPARAM] - GlobalAddAtom = windll.kernel32.GlobalAddAtomW + GlobalAddAtom = windll.kernel32.GlobalAddAtomW GlobalAddAtom.argtypes = [LPWSTR] GlobalAddAtom.restype = ATOM GlobalGetAtomName = windll.kernel32.GlobalGetAtomNameW GlobalGetAtomName.argtypes = [ATOM, LPWSTR, INT] GlobalGetAtomName.restype = UINT - GlobalLock = windll.kernel32.GlobalLock + GlobalLock = windll.kernel32.GlobalLock GlobalLock.argtypes = [HGLOBAL] GlobalLock.restype = LPVOID - GlobalUnlock = windll.kernel32.GlobalUnlock + GlobalUnlock = windll.kernel32.GlobalUnlock GlobalUnlock.argtypes = [HGLOBAL] GlobalUnlock.restype = BOOL - @WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM) def WndProc(hwnd, message, wParam, lParam): service = create_unicode_buffer(256) topic = create_unicode_buffer(256) if message == WM_DDE_INITIATE: - if ((lParam & 0xffff == 0 or (GlobalGetAtomName(lParam & 0xffff, service, 256) and service.value == appname)) and - (lParam >> 16 == 0 or (GlobalGetAtomName(lParam >> 16, topic, 256) and topic.value.lower() == 'system'))): - SendMessage(wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System'))) + if ( + (lParam & 0xffff == 0 or (GlobalGetAtomName(lParam & 0xffff, service, 256) and service.value == appname)) and + (lParam >> 16 == 0 or (GlobalGetAtomName(lParam >> 16, topic, 256) and topic.value.lower() == 'system')) + ): + SendMessage(wParam, WM_DDE_ACK, hwnd, PackDDElParam( + WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System'))) return 0 return DefWindowProc(hwnd, message, wParam, lParam) - class ProtocolHandler(GenericProtocolHandler): def __init__(self): @@ -163,31 +171,33 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a if thread: self.thread = None PostThreadMessage(thread.ident, WM_QUIT, 0, 0) - thread.join() # Wait for it to quit + thread.join() # Wait for it to quit def worker(self): wndclass = WNDCLASS() - wndclass.style = 0 - wndclass.lpfnWndProc = WndProc - wndclass.cbClsExtra = 0 - wndclass.cbWndExtra = 0 - wndclass.hInstance = windll.kernel32.GetModuleHandleW(0) - wndclass.hIcon = None - wndclass.hCursor = None - wndclass.hbrBackground = None - wndclass.lpszMenuName = None - wndclass.lpszClassName = 'DDEServer' + wndclass.style = 0 + wndclass.lpfnWndProc = WndProc + wndclass.cbClsExtra = 0 + wndclass.cbWndExtra = 0 + wndclass.hInstance = windll.kernel32.GetModuleHandleW(0) + wndclass.hIcon = None + wndclass.hCursor = None + wndclass.hbrBackground = None + wndclass.lpszMenuName = None + wndclass.lpszClassName = 'DDEServer' if RegisterClass(byref(wndclass)): - hwnd = CreateWindowEx(0, - wndclass.lpszClassName, - "DDE Server", - 0, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - self.master.winfo_id(), # Don't use HWND_MESSAGE since the window won't get DDE broadcasts - None, - wndclass.hInstance, - None) + hwnd = CreateWindowEx( + 0, + wndclass.lpszClassName, + "DDE Server", + 0, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + self.master.winfo_id(), # Don't use HWND_MESSAGE since the window won't get DDE broadcasts + None, + wndclass.hInstance, + None + ) msg = MSG() while GetMessage(byref(msg), None, 0, 0) != 0: logger.trace(f'DDE message of type: {msg.message}') @@ -201,7 +211,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a if url.startswith(self.redirect): logger.debug(f'Message starts with {self.redirect}') self.event(url) - SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window + SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam)) else: PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam)) @@ -213,7 +223,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a else: print('Failed to register DDE for cAPI') -else: # Linux / Run from source +else: # Linux / Run from source from http.server import HTTPServer, BaseHTTPRequestHandler @@ -264,7 +274,7 @@ else: # Linux / Run from source self.send_response(200) return True else: - self.send_response(404) # Not found + self.send_response(404) # Not found return False def do_HEAD(self): @@ -275,7 +285,8 @@ else: # Linux / Run from source if self.parse(): self.send_header('Content-Type', 'text/html') self.end_headers() - self.wfile.write('{}'.format('Authentication successful').encode('utf-8')) + self.wfile.write( + '{}'.format('Authentication successful').encode('utf-8')) self.wfile.write('

    {}

    '.format('Authentication successful').encode('utf-8')) else: self.end_headers() From d4cce9ee84c8c2ac939dedb6c8ef9fc1cd0312e6 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 12 Jan 2021 19:09:48 +0200 Subject: [PATCH 301/727] Removed * Imports --- protocol.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/protocol.py b/protocol.py index 0f7f8ce4..0db051d7 100644 --- a/protocol.py +++ b/protocol.py @@ -1,9 +1,11 @@ # edmc: protocol handler for cAPI authorisation -import threading -import urllib.request, urllib.error, urllib.parse import sys +import threading +import urllib.error +import urllib.parse +import urllib.request from EDMCLogging import get_main_logger from config import appname, config @@ -11,13 +13,14 @@ from constants import protocolhandler_redirect logger = get_main_logger() +is_wine = False + if sys.platform == 'win32': - from ctypes import * - from ctypes.wintypes import * + from ctypes import windll # type: ignore try: is_wine = windll.ntdll.wine_get_version - except: - is_wine = False + except Exception: + pass class GenericProtocolHandler(object): @@ -43,6 +46,7 @@ class GenericProtocolHandler(object): if sys.platform == 'darwin' and getattr(sys, 'frozen', False): import struct + import objc from AppKit import NSAppleEventManager, NSObject @@ -83,6 +87,13 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: + # spell-checker: words HBRUSH HICON WPARAM wstring WNDCLASS + from ctypes import windll # type: ignore + from ctypes import POINTER, WINFUNCTYPE, Structure, byref, c_long, c_void_p, create_unicode_buffer, wstring_at + from ctypes.wintypes import ( + ATOM, BOOL, DWORD, HBRUSH, HGLOBAL, HICON, HINSTANCE, HMENU, HWND, INT, LPARAM, LPCWSTR, LPVOID, LPWSTR, MSG, + UINT, WPARAM + ) class WNDCLASS(Structure): _fields_ = [ @@ -225,7 +236,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a else: # Linux / Run from source - from http.server import HTTPServer, BaseHTTPRequestHandler + from http.server import BaseHTTPRequestHandler, HTTPServer class ProtocolHandler(GenericProtocolHandler): From 328f8c739735ecde20d8d2e6116445d2f4b47399 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 13 Jan 2021 22:33:50 +0200 Subject: [PATCH 302/727] Broke up giant if --- protocol.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/protocol.py b/protocol.py index 0db051d7..c2cb2805 100644 --- a/protocol.py +++ b/protocol.py @@ -87,7 +87,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: - # spell-checker: words HBRUSH HICON WPARAM wstring WNDCLASS + # spell-checker: words HBRUSH HICON WPARAM wstring WNDCLASS HMENU HGLOBAL from ctypes import windll # type: ignore from ctypes import POINTER, WINFUNCTYPE, Structure, byref, c_long, c_void_p, create_unicode_buffer, wstring_at from ctypes.wintypes import ( @@ -156,12 +156,18 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a service = create_unicode_buffer(256) topic = create_unicode_buffer(256) if message == WM_DDE_INITIATE: - if ( - (lParam & 0xffff == 0 or (GlobalGetAtomName(lParam & 0xffff, service, 256) and service.value == appname)) and - (lParam >> 16 == 0 or (GlobalGetAtomName(lParam >> 16, topic, 256) and topic.value.lower() == 'system')) - ): - SendMessage(wParam, WM_DDE_ACK, hwnd, PackDDElParam( - WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System'))) + # I have no idea what these do or how they work. + flag1 = (lParam & 0xffff == 0 or ( + GlobalGetAtomName(lParam & 0xffff, service, 256) and service.value == appname) + ) + flag2 = ( + lParam >> 16 == 0 or (GlobalGetAtomName(lParam >> 16, topic, 256) and topic.value.lower() == 'system') + ) + + if flag1 and flag2: + SendMessage( + wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System')) + ) return 0 return DefWindowProc(hwnd, message, wParam, lParam) From 52494893e54a897f4a0ad44618ad84567a784031 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 21 Jan 2021 11:49:11 +0200 Subject: [PATCH 303/727] Refactored WindowProc callback Who knew comments and a bit of explanation could help? --- protocol.py | 65 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/protocol.py b/protocol.py index c2cb2805..8f43d190 100644 --- a/protocol.py +++ b/protocol.py @@ -3,6 +3,7 @@ import sys import threading +from typing import Optional import urllib.error import urllib.parse import urllib.request @@ -54,16 +55,16 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): keyDirectObject = struct.unpack('>l', b'----')[0] class ProtocolHandler(GenericProtocolHandler): - POLL = 100 # ms def start(self, master): GenericProtocolHandler.start(self, master) - self.lasturl = None + self.lasturl: Optional[str] = None self.eventhandler = EventHandler.alloc().init() def poll(self): - # No way of signalling to Tkinter from within the callback handler block that doesn't cause Python to crash, so poll. + # No way of signalling to Tkinter from within the callback handler block that doesn't cause Python to crash, + # so poll. TODO: Resolved? if self.lasturl and self.lasturl.startswith(self.redirect): self.event(self.lasturl) self.lasturl = None @@ -130,6 +131,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a PostMessage.argtypes = [HWND, UINT, WPARAM, LPARAM] WM_QUIT = 0x0012 + # https://docs.microsoft.com/en-us/windows/win32/dataxchg/wm-dde-initiate WM_DDE_INITIATE = 0x03E0 WM_DDE_TERMINATE = 0x03E1 WM_DDE_ACK = 0x03E4 @@ -152,24 +154,45 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a GlobalUnlock.restype = BOOL @WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM) - def WndProc(hwnd, message, wParam, lParam): + def WndProc(hwnd: HWND, message: UINT, wParam, lParam): # noqa: N803 N802 + """ + Deal with DDE requests. + + :param hwnd: Window handle + :param message: The message being sent + :param wParam: Additional Message Information (depends on message type) + :param lParam: Also additional message information + :return: ??? + """ + if message != WM_DDE_INITIATE: + # Not a DDE init message, bail and tell windows to do the default + return DefWindowProc(hwnd, message, wParam, lParam) + service = create_unicode_buffer(256) topic = create_unicode_buffer(256) - if message == WM_DDE_INITIATE: - # I have no idea what these do or how they work. - flag1 = (lParam & 0xffff == 0 or ( - GlobalGetAtomName(lParam & 0xffff, service, 256) and service.value == appname) - ) - flag2 = ( - lParam >> 16 == 0 or (GlobalGetAtomName(lParam >> 16, topic, 256) and topic.value.lower() == 'system') - ) + # Note that lParam is 32 bits, and broken into two 16 bit words. This will break on 64bit as the math is + # wrong + lparam_low = lParam & 0xFFFF # if nonzero, the target application for which a conversation is requested + lparam_high = lParam >> 16 # if nonzero, the topic of said conversation - if flag1 and flag2: - SendMessage( - wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System')) - ) - return 0 - return DefWindowProc(hwnd, message, wParam, lParam) + # if either of the words are nonzero, they contain + # atoms https://docs.microsoft.com/en-us/windows/win32/dataxchg/about-atom-tables + # which we can read out as shown below, and then compare. + + target_is_valid = lparam_low == 0 or ( + GlobalGetAtomName(lparam_low, service, 256) and service.value == appname + ) + + topic_is_valid = lparam_high == 0 or ( + GlobalGetAtomName(lparam_high, topic, 256) and topic.value.lower() == 'system' + ) + + if target_is_valid and topic_is_valid: + # if everything is happy, send an acknowledgement of the DDE request + SendMessage( + wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System')) + ) + return 0 class ProtocolHandler(GenericProtocolHandler): @@ -215,6 +238,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a wndclass.hInstance, None ) + msg = MSG() while GetMessage(byref(msg), None, 0, 0) != 0: logger.trace(f'DDE message of type: {msg.message}') @@ -228,15 +252,20 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a if url.startswith(self.redirect): logger.debug(f'Message starts with {self.redirect}') self.event(url) + SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam)) + else: PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam)) + elif msg.message == WM_DDE_TERMINATE: PostMessage(msg.wParam, WM_DDE_TERMINATE, hwnd, 0) + else: TranslateMessage(byref(msg)) DispatchMessage(byref(msg)) + else: print('Failed to register DDE for cAPI') From 4d7ec877469e627d1724be81b831f1672a1e0d3e Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 21 Jan 2021 12:01:01 +0200 Subject: [PATCH 304/727] Renamed ProtocolHandler implementations so not to clash --- protocol.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/protocol.py b/protocol.py index 8f43d190..7c331058 100644 --- a/protocol.py +++ b/protocol.py @@ -54,7 +54,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): kInternetEventClass = kAEGetURL = struct.unpack('>l', b'GURL')[0] keyDirectObject = struct.unpack('>l', b'----')[0] - class ProtocolHandler(GenericProtocolHandler): + class DarwinProtocolHandler(GenericProtocolHandler): POLL = 100 # ms def start(self, master): @@ -194,7 +194,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a ) return 0 - class ProtocolHandler(GenericProtocolHandler): + class WindowsProtocolHandler(GenericProtocolHandler): def __init__(self): GenericProtocolHandler.__init__(self) @@ -273,7 +273,7 @@ else: # Linux / Run from source from http.server import BaseHTTPRequestHandler, HTTPServer - class ProtocolHandler(GenericProtocolHandler): + class LinuxProtocolHandler(GenericProtocolHandler): def __init__(self): GenericProtocolHandler.__init__(self) @@ -342,4 +342,12 @@ else: # Linux / Run from source # singleton -protocolhandler = ProtocolHandler() +protocolhandler: GenericProtocolHandler + +if sys.platform == 'darwin' and getattr(sys, 'frozen', False): + protocolhandler = DarwinProtocolHandler() # pyright: reportUnboundVariable=false + +elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine: + protocolhandler = WindowsProtocolHandler() +else: + protocolhandler = LinuxProtocolHandler() From 65645ee22458f048da1dd14b50f88da27e2ea456 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:24:39 +0000 Subject: [PATCH 305/727] Added docstrings # Conflicts: # protocol.py --- protocol.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/protocol.py b/protocol.py index 7c331058..d5fbb550 100644 --- a/protocol.py +++ b/protocol.py @@ -195,18 +195,26 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a return 0 class WindowsProtocolHandler(GenericProtocolHandler): + """ + Windows implementation of GenericProtocolHandler. + + This works by using windows Dynamic Data Exchange to pass messages between processes + https://en.wikipedia.org/wiki/Dynamic_Data_Exchange + """ def __init__(self): GenericProtocolHandler.__init__(self) self.thread = None def start(self, master): + """Start the DDE thread.""" GenericProtocolHandler.start(self, master) self.thread = threading.Thread(target=self.worker, name='DDE worker') self.thread.daemon = True self.thread.start() def close(self): + """Stop the DDE thread""" thread = self.thread if thread: self.thread = None @@ -214,6 +222,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a thread.join() # Wait for it to quit def worker(self): + """Start a DDE server.""" wndclass = WNDCLASS() wndclass.style = 0 wndclass.lpfnWndProc = WndProc @@ -274,6 +283,11 @@ else: # Linux / Run from source from http.server import BaseHTTPRequestHandler, HTTPServer class LinuxProtocolHandler(GenericProtocolHandler): + """ + Implementation of GenericProtocolHandler. + + This implementation uses a localhost HTTP server + """ def __init__(self): GenericProtocolHandler.__init__(self) @@ -283,12 +297,14 @@ else: # Linux / Run from source self.thread = None def start(self, master): + """Start the HTTP server thread.""" GenericProtocolHandler.start(self, master) self.thread = threading.Thread(target=self.worker, name='OAuth worker') self.thread.daemon = True self.thread.start() def close(self): + """Shutdown the HTTP server thread.""" thread = self.thread if thread: logger.debug('Thread') @@ -307,12 +323,15 @@ else: # Linux / Run from source logger.debug('Done.') def worker(self): + """HTTP Worker.""" + # TODO: This should probably be more ephemeral, and only handle one request, as its all we're expecting self.httpd.serve_forever() class HTTPRequestHandler(BaseHTTPRequestHandler): + """Simple HTTP server to handle IPC from protocol handler.""" def parse(self): - logger.trace(f'Got message on path: {self.path}') + """Parse a request.""" url = urllib.parse.unquote(self.path) if url.startswith('/auth'): logger.debug('Request starts with /auth, sending to protocolhandler.event()') @@ -323,11 +342,13 @@ else: # Linux / Run from source self.send_response(404) # Not found return False - def do_HEAD(self): + def do_HEAD(self): # noqa: N802 # Required to override + """Handle HEAD Request.""" self.parse() self.end_headers() - def do_GET(self): + def do_GET(self): # noqa: N802 # Required to override + """Handle GET Request.""" if self.parse(): self.send_header('Content-Type', 'text/html') self.end_headers() @@ -338,6 +359,7 @@ else: # Linux / Run from source self.end_headers() def log_request(self, code, size=None): + """Override to prevent logging.""" pass From d5670d9b089c3b196679c91b05e7bfaf7cc8ddf6 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 28 Jan 2021 18:13:16 +0200 Subject: [PATCH 306/727] Simplified GET response --- protocol.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/protocol.py b/protocol.py index d5fbb550..f1eb015c 100644 --- a/protocol.py +++ b/protocol.py @@ -352,9 +352,8 @@ else: # Linux / Run from source if self.parse(): self.send_header('Content-Type', 'text/html') self.end_headers() - self.wfile.write( - '{}'.format('Authentication successful').encode('utf-8')) - self.wfile.write('

    {}

    '.format('Authentication successful').encode('utf-8')) + self.wfile.write('Authentication successful'.encode('utf-8')) + self.wfile.write('

    Authentication successful

    '.encode('utf-8')) else: self.end_headers() From 1b0b482105d9818e6576c8bdbb62d7ba1ae6e866 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 28 Jan 2021 18:13:39 +0200 Subject: [PATCH 307/727] Replaced old formatting with fstring --- protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol.py b/protocol.py index f1eb015c..fc4fc4c6 100644 --- a/protocol.py +++ b/protocol.py @@ -292,7 +292,7 @@ else: # Linux / Run from source def __init__(self): GenericProtocolHandler.__init__(self) self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler) - self.redirect = 'http://localhost:%d/auth' % self.httpd.server_port + self.redirect = f'http://localhost:{self.httpd.server_port}/auth' logger.trace(f'Web server listening on {self.redirect}') self.thread = None From 96ac23a6eb29ff4994715ccd1e91f653905f2e39 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 28 Jan 2021 18:16:06 +0200 Subject: [PATCH 308/727] Made sure to use super() call Assuming you know what your super is is a bad idea --- protocol.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/protocol.py b/protocol.py index fc4fc4c6..7e1ad6da 100644 --- a/protocol.py +++ b/protocol.py @@ -203,12 +203,12 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a """ def __init__(self): - GenericProtocolHandler.__init__(self) - self.thread = None + super().__init__() + self.thread: Optional[threading.Thread] = None def start(self, master): """Start the DDE thread.""" - GenericProtocolHandler.start(self, master) + super().start(master) self.thread = threading.Thread(target=self.worker, name='DDE worker') self.thread.daemon = True self.thread.start() From 67d41d63dc41a3726b6e2337e5335aa9f9294df5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:25:32 +0000 Subject: [PATCH 309/727] Added more comments to windows DDE # Conflicts: # protocol.py --- protocol.py | 90 +++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/protocol.py b/protocol.py index 7e1ad6da..4a1142b2 100644 --- a/protocol.py +++ b/protocol.py @@ -3,10 +3,10 @@ import sys import threading -from typing import Optional import urllib.error import urllib.parse import urllib.request +from typing import Optional from EDMCLogging import get_main_logger from config import appname, config @@ -81,10 +81,12 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): ) return self - def handleEvent_withReplyEvent_(self, event, replyEvent): - protocolhandler.lasturl = urllib.parse.unquote( - event.paramDescriptorForKeyword_(keyDirectObject).stringValue()).strip() - protocolhandler.master.after(ProtocolHandler.POLL, protocolhandler.poll) + def handleEvent_withReplyEvent_(self, event, replyEvent): # noqa: N802 # Required to override + protocolhandler.lasturl = urllib.parse.unquote( # type: ignore # Its going to be a DPH in this code + event.paramDescriptorForKeyword_(keyDirectObject).stringValue() + ).strip() + + protocolhandler.master.after(DarwinProtocolHandler.POLL, protocolhandler.poll) # type: ignore elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: @@ -153,6 +155,8 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a GlobalUnlock.argtypes = [HGLOBAL] GlobalUnlock.restype = BOOL + # Windows Message handler stuff (IPC) + # https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85) @WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM) def WndProc(hwnd: HWND, message: UINT, wParam, lParam): # noqa: N803 N802 """ @@ -166,6 +170,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a """ if message != WM_DDE_INITIATE: # Not a DDE init message, bail and tell windows to do the default + # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-defwindowproca?redirectedfrom=MSDN return DefWindowProc(hwnd, message, wParam, lParam) service = create_unicode_buffer(256) @@ -192,6 +197,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a SendMessage( wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System')) ) + return 0 class WindowsProtocolHandler(GenericProtocolHandler): @@ -235,48 +241,52 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a wndclass.lpszMenuName = None wndclass.lpszClassName = 'DDEServer' - if RegisterClass(byref(wndclass)): - hwnd = CreateWindowEx( - 0, - wndclass.lpszClassName, - "DDE Server", - 0, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - self.master.winfo_id(), # Don't use HWND_MESSAGE since the window won't get DDE broadcasts - None, - wndclass.hInstance, - None - ) + if not RegisterClass(byref(wndclass)): + print('Failed to register Dynamic Data Exchange for cAPI') + return - msg = MSG() - while GetMessage(byref(msg), None, 0, 0) != 0: - logger.trace(f'DDE message of type: {msg.message}') - if msg.message == WM_DDE_EXECUTE: - args = wstring_at(GlobalLock(msg.lParam)).strip() - GlobalUnlock(msg.lParam) - if args.lower().startswith('open("') and args.endswith('")'): - logger.trace(f'args are: {args}') - url = urllib.parse.unquote(args[6:-2]).strip() - logger.trace(f'Parsed url: {url}') - if url.startswith(self.redirect): - logger.debug(f'Message starts with {self.redirect}') - self.event(url) + # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw + hwnd = CreateWindowEx( + 0, # dwExStyle + wndclass.lpszClassName, # lpClassName + "DDE Server", # lpWindowName + 0, # dwStyle + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, # X, Y, nWidth, nHeight + self.master.winfo_id(), # hWndParent # Don't use HWND_MESSAGE since the window won't get DDE broadcasts + None, # hMenu + wndclass.hInstance, # hInstance + None # lpParam + ) - SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window - PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam)) + msg = MSG() + # Calls GetMessageW: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew + while GetMessage(byref(msg), None, 0, 0) != 0: + if msg.message == WM_DDE_EXECUTE: + # GlobalLock does some sort of "please dont move this?" + # https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globallock + args = wstring_at(GlobalLock(msg.lParam)).strip() + GlobalUnlock(msg.lParam) # Unlocks the GlobalLock-ed object - else: - PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam)) + if args.lower().startswith('open("') and args.endswith('")'): + url = urllib.parse.unquote(args[6:-2]).strip() + if url.startswith(self.redirect): + self.event(url) - elif msg.message == WM_DDE_TERMINATE: - PostMessage(msg.wParam, WM_DDE_TERMINATE, hwnd, 0) + SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window + # Send back a WM_DDE_ACK. this is _required_ with WM_DDE_EXECUTE + PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam)) else: - TranslateMessage(byref(msg)) - DispatchMessage(byref(msg)) + # Send back a WM_DDE_ACK. this is _required_ with WM_DDE_EXECUTE + PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam)) + + elif msg.message == WM_DDE_TERMINATE: + PostMessage(msg.wParam, WM_DDE_TERMINATE, hwnd, 0) + + else: + TranslateMessage(byref(msg)) # "Translates virtual key messages into character messages" ??? + DispatchMessage(byref(msg)) - else: - print('Failed to register DDE for cAPI') else: # Linux / Run from source From 4e75941311cae5840f46a939786103f3ecbb8099 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 28 Jan 2021 18:36:31 +0200 Subject: [PATCH 310/727] Made sure windll names are correct A/W has meaning and should ALWAYS be noted --- protocol.py | 64 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/protocol.py b/protocol.py index 4a1142b2..58099bed 100644 --- a/protocol.py +++ b/protocol.py @@ -114,23 +114,23 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a CW_USEDEFAULT = 0x80000000 - CreateWindowEx = windll.user32.CreateWindowExW - CreateWindowEx.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID] - CreateWindowEx.restype = HWND - RegisterClass = windll.user32.RegisterClassW - RegisterClass.argtypes = [POINTER(WNDCLASS)] - DefWindowProc = windll.user32.DefWindowProcW + CreateWindowExW = windll.user32.CreateWindowExW + CreateWindowExW.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID] + CreateWindowExW.restype = HWND + RegisterClassW = windll.user32.RegisterClassW + RegisterClassW.argtypes = [POINTER(WNDCLASS)] + DefWindowProcW = windll.user32.DefWindowProcW GetParent = windll.user32.GetParent SetForegroundWindow = windll.user32.SetForegroundWindow - GetMessage = windll.user32.GetMessageW + GetMessageW = windll.user32.GetMessageW TranslateMessage = windll.user32.TranslateMessage - DispatchMessage = windll.user32.DispatchMessageW - PostThreadMessage = windll.user32.PostThreadMessageW - SendMessage = windll.user32.SendMessageW - SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM] - PostMessage = windll.user32.PostMessageW - PostMessage.argtypes = [HWND, UINT, WPARAM, LPARAM] + DispatchMessageW = windll.user32.DispatchMessageW + PostThreadMessageW = windll.user32.PostThreadMessageW + SendMessageW = windll.user32.SendMessageW + SendMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] + PostMessageW = windll.user32.PostMessageW + PostMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] WM_QUIT = 0x0012 # https://docs.microsoft.com/en-us/windows/win32/dataxchg/wm-dde-initiate @@ -142,12 +142,12 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a PackDDElParam = windll.user32.PackDDElParam PackDDElParam.argtypes = [UINT, LPARAM, LPARAM] - GlobalAddAtom = windll.kernel32.GlobalAddAtomW - GlobalAddAtom.argtypes = [LPWSTR] - GlobalAddAtom.restype = ATOM - GlobalGetAtomName = windll.kernel32.GlobalGetAtomNameW - GlobalGetAtomName.argtypes = [ATOM, LPWSTR, INT] - GlobalGetAtomName.restype = UINT + GlobalAddAtomW = windll.kernel32.GlobalAddAtomW + GlobalAddAtomW.argtypes = [LPWSTR] + GlobalAddAtomW.restype = ATOM + GlobalGetAtomNameW = windll.kernel32.GlobalGetAtomNameW + GlobalGetAtomNameW.argtypes = [ATOM, LPWSTR, INT] + GlobalGetAtomNameW.restype = UINT GlobalLock = windll.kernel32.GlobalLock GlobalLock.argtypes = [HGLOBAL] GlobalLock.restype = LPVOID @@ -171,7 +171,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a if message != WM_DDE_INITIATE: # Not a DDE init message, bail and tell windows to do the default # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-defwindowproca?redirectedfrom=MSDN - return DefWindowProc(hwnd, message, wParam, lParam) + return DefWindowProcW(hwnd, message, wParam, lParam) service = create_unicode_buffer(256) topic = create_unicode_buffer(256) @@ -185,17 +185,17 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a # which we can read out as shown below, and then compare. target_is_valid = lparam_low == 0 or ( - GlobalGetAtomName(lparam_low, service, 256) and service.value == appname + GlobalGetAtomNameW(lparam_low, service, 256) and service.value == appname ) topic_is_valid = lparam_high == 0 or ( - GlobalGetAtomName(lparam_high, topic, 256) and topic.value.lower() == 'system' + GlobalGetAtomNameW(lparam_high, topic, 256) and topic.value.lower() == 'system' ) if target_is_valid and topic_is_valid: # if everything is happy, send an acknowledgement of the DDE request - SendMessage( - wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System')) + SendMessageW( + wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtomW(appname), GlobalAddAtomW('System')) ) return 0 @@ -224,7 +224,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a thread = self.thread if thread: self.thread = None - PostThreadMessage(thread.ident, WM_QUIT, 0, 0) + PostThreadMessageW(thread.ident, WM_QUIT, 0, 0) thread.join() # Wait for it to quit def worker(self): @@ -241,12 +241,12 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a wndclass.lpszMenuName = None wndclass.lpszClassName = 'DDEServer' - if not RegisterClass(byref(wndclass)): + if not RegisterClassW(byref(wndclass)): print('Failed to register Dynamic Data Exchange for cAPI') return # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw - hwnd = CreateWindowEx( + hwnd = CreateWindowExW( 0, # dwExStyle wndclass.lpszClassName, # lpClassName "DDE Server", # lpWindowName @@ -260,7 +260,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a msg = MSG() # Calls GetMessageW: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew - while GetMessage(byref(msg), None, 0, 0) != 0: + while GetMessageW(byref(msg), None, 0, 0) != 0: if msg.message == WM_DDE_EXECUTE: # GlobalLock does some sort of "please dont move this?" # https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globallock @@ -274,18 +274,18 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window # Send back a WM_DDE_ACK. this is _required_ with WM_DDE_EXECUTE - PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam)) + PostMessageW(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam)) else: # Send back a WM_DDE_ACK. this is _required_ with WM_DDE_EXECUTE - PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam)) + PostMessageW(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam)) elif msg.message == WM_DDE_TERMINATE: - PostMessage(msg.wParam, WM_DDE_TERMINATE, hwnd, 0) + PostMessageW(msg.wParam, WM_DDE_TERMINATE, hwnd, 0) else: TranslateMessage(byref(msg)) # "Translates virtual key messages into character messages" ??? - DispatchMessage(byref(msg)) + DispatchMessageW(byref(msg)) else: # Linux / Run from source From a55e43c0b54799076a5902620a4a20f42d550b08 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 28 Jan 2021 18:46:09 +0200 Subject: [PATCH 311/727] Made linters happy --- protocol.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/protocol.py b/protocol.py index 58099bed..b7053e90 100644 --- a/protocol.py +++ b/protocol.py @@ -6,12 +6,15 @@ import threading import urllib.error import urllib.parse import urllib.request -from typing import Optional +from typing import TYPE_CHECKING, Optional from EDMCLogging import get_main_logger from config import appname, config from constants import protocolhandler_redirect +if TYPE_CHECKING: + import tkinter + logger = get_main_logger() is_wine = False @@ -31,38 +34,48 @@ class GenericProtocolHandler(object): self.master = None self.lastpayload = None - def start(self, master): + def start(self, master: 'tkinter.Tk'): + """Start Protocol Handler.""" self.master = master def close(self): + """Stop / Close Protocol Handler.""" pass def event(self, url): + """Generate an auth event.""" self.lastpayload = url if not config.shutting_down: self.master.event_generate('<>', when="tail") -if sys.platform == 'darwin' and getattr(sys, 'frozen', False): - +if sys.platform == 'darwin' and getattr(sys, 'frozen', False): # noqa: C901 # its guarding ALL macos stuff. import struct - import objc - from AppKit import NSAppleEventManager, NSObject + import objc # type: ignore + from AppKit import NSAppleEventManager, NSObject # type: ignore - kInternetEventClass = kAEGetURL = struct.unpack('>l', b'GURL')[0] - keyDirectObject = struct.unpack('>l', b'----')[0] + kInternetEventClass = kAEGetURL = struct.unpack('>l', b'GURL')[0] # noqa: N816 # API names + keyDirectObject = struct.unpack('>l', b'----')[0] # noqa: N816 # API names class DarwinProtocolHandler(GenericProtocolHandler): + """ + MacOS protocol handler implementation. + + Uses macOS event stuff. + """ + POLL = 100 # ms def start(self, master): + """Start Protocol Handler.""" GenericProtocolHandler.start(self, master) self.lasturl: Optional[str] = None self.eventhandler = EventHandler.alloc().init() def poll(self): + """Poll event until URL is updated.""" # No way of signalling to Tkinter from within the callback handler block that doesn't cause Python to crash, # so poll. TODO: Resolved? if self.lasturl and self.lasturl.startswith(self.redirect): @@ -70,8 +83,14 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): self.lasturl = None class EventHandler(NSObject): + """Handle NSAppleEventManager IPC stuff.""" def init(self): + """ + Init method for handler. + + (I'd assume this is related to the subclassing of NSObject for why its not __init__) + """ self = objc.super(EventHandler, self).init() NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_( self, @@ -81,7 +100,8 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): ) return self - def handleEvent_withReplyEvent_(self, event, replyEvent): # noqa: N802 # Required to override + def handleEvent_withReplyEvent_(self, event, replyEvent): # noqa: N802 N803 # Required to override + """Actual event handling from NSAppleEventManager.""" protocolhandler.lasturl = urllib.parse.unquote( # type: ignore # Its going to be a DPH in this code event.paramDescriptorForKeyword_(keyDirectObject).stringValue() ).strip() @@ -98,7 +118,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a UINT, WPARAM ) - class WNDCLASS(Structure): + class WNDCLASS(Structure): # noqa: D101 # I dont want to chance messing with a Structure with a docstring _fields_ = [ ('style', UINT), ('lpfnWndProc', WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)), @@ -220,7 +240,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a self.thread.start() def close(self): - """Stop the DDE thread""" + """Stop the DDE thread.""" thread = self.thread if thread: self.thread = None From 660878dcff56d0a14bc5645bd94aa15cca350535 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 28 Jan 2021 18:51:23 +0200 Subject: [PATCH 312/727] removed object --- protocol.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protocol.py b/protocol.py index b7053e90..a5ddf1a8 100644 --- a/protocol.py +++ b/protocol.py @@ -27,7 +27,8 @@ if sys.platform == 'win32': pass -class GenericProtocolHandler(object): +class GenericProtocolHandler: + """Base Protocol Handler.""" def __init__(self): self.redirect = protocolhandler_redirect # Base redirection URL From adba94efa24262952af8d24bfc1163068912183c Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 29 Jan 2021 13:53:05 +0200 Subject: [PATCH 313/727] re-added appname import from constants --- protocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol.py b/protocol.py index a5ddf1a8..9f5ca959 100644 --- a/protocol.py +++ b/protocol.py @@ -8,9 +8,9 @@ import urllib.parse import urllib.request from typing import TYPE_CHECKING, Optional +from config import config +from constants import appname, protocolhandler_redirect from EDMCLogging import get_main_logger -from config import appname, config -from constants import protocolhandler_redirect if TYPE_CHECKING: import tkinter From ceb2f748554df2d446a60873720da2abd674515f Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 8 Mar 2021 17:43:22 +0200 Subject: [PATCH 314/727] Final type annotation pass --- protocol.py | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/protocol.py b/protocol.py index 9f5ca959..e6184a5e 100644 --- a/protocol.py +++ b/protocol.py @@ -1,5 +1,4 @@ -# edmc: protocol handler for cAPI authorisation - +"""protocol handler for cAPI authorisation.""" import sys import threading @@ -30,20 +29,20 @@ if sys.platform == 'win32': class GenericProtocolHandler: """Base Protocol Handler.""" - def __init__(self): + def __init__(self) -> None: self.redirect = protocolhandler_redirect # Base redirection URL - self.master = None + self.master: 'tkinter.Tk' = None # type: ignore self.lastpayload = None - def start(self, master: 'tkinter.Tk'): + def start(self, master: 'tkinter.Tk') -> None: """Start Protocol Handler.""" self.master = master - def close(self): + def close(self) -> None: """Stop / Close Protocol Handler.""" pass - def event(self, url): + def event(self, url) -> None: """Generate an auth event.""" self.lastpayload = url @@ -69,13 +68,13 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): # noqa: C901 # i POLL = 100 # ms - def start(self, master): + def start(self, master: 'tkinter.Tk') -> None: """Start Protocol Handler.""" GenericProtocolHandler.start(self, master) self.lasturl: Optional[str] = None self.eventhandler = EventHandler.alloc().init() - def poll(self): + def poll(self) -> None: """Poll event until URL is updated.""" # No way of signalling to Tkinter from within the callback handler block that doesn't cause Python to crash, # so poll. TODO: Resolved? @@ -86,7 +85,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): # noqa: C901 # i class EventHandler(NSObject): """Handle NSAppleEventManager IPC stuff.""" - def init(self): + def init(self) -> None: """ Init method for handler. @@ -101,7 +100,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): # noqa: C901 # i ) return self - def handleEvent_withReplyEvent_(self, event, replyEvent): # noqa: N802 N803 # Required to override + def handleEvent_withReplyEvent_(self, event, replyEvent) -> None: # noqa: N802 N803 # Required to override """Actual event handling from NSAppleEventManager.""" protocolhandler.lasturl = urllib.parse.unquote( # type: ignore # Its going to be a DPH in this code event.paramDescriptorForKeyword_(keyDirectObject).stringValue() @@ -229,18 +228,18 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a https://en.wikipedia.org/wiki/Dynamic_Data_Exchange """ - def __init__(self): + def __init__(self) -> None: super().__init__() self.thread: Optional[threading.Thread] = None - def start(self, master): + def start(self, master: 'tkinter.Tk') -> None: """Start the DDE thread.""" super().start(master) self.thread = threading.Thread(target=self.worker, name='DDE worker') self.thread.daemon = True self.thread.start() - def close(self): + def close(self) -> None: """Stop the DDE thread.""" thread = self.thread if thread: @@ -248,7 +247,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a PostThreadMessageW(thread.ident, WM_QUIT, 0, 0) thread.join() # Wait for it to quit - def worker(self): + def worker(self) -> None: """Start a DDE server.""" wndclass = WNDCLASS() wndclass.style = 0 @@ -320,21 +319,21 @@ else: # Linux / Run from source This implementation uses a localhost HTTP server """ - def __init__(self): - GenericProtocolHandler.__init__(self) + def __init__(self) -> None: + super().__init__() self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler) self.redirect = f'http://localhost:{self.httpd.server_port}/auth' logger.trace(f'Web server listening on {self.redirect}') - self.thread = None + self.thread: Optional[threading.Thread] = None - def start(self, master): + def start(self, master) -> None: """Start the HTTP server thread.""" GenericProtocolHandler.start(self, master) self.thread = threading.Thread(target=self.worker, name='OAuth worker') self.thread.daemon = True self.thread.start() - def close(self): + def close(self) -> None: """Shutdown the HTTP server thread.""" thread = self.thread if thread: @@ -353,7 +352,7 @@ else: # Linux / Run from source logger.debug('Done.') - def worker(self): + def worker(self) -> None: """HTTP Worker.""" # TODO: This should probably be more ephemeral, and only handle one request, as its all we're expecting self.httpd.serve_forever() @@ -361,7 +360,7 @@ else: # Linux / Run from source class HTTPRequestHandler(BaseHTTPRequestHandler): """Simple HTTP server to handle IPC from protocol handler.""" - def parse(self): + def parse(self) -> bool: """Parse a request.""" url = urllib.parse.unquote(self.path) if url.startswith('/auth'): @@ -373,12 +372,12 @@ else: # Linux / Run from source self.send_response(404) # Not found return False - def do_HEAD(self): # noqa: N802 # Required to override + def do_HEAD(self) -> None: # noqa: N802 # Required to override """Handle HEAD Request.""" self.parse() self.end_headers() - def do_GET(self): # noqa: N802 # Required to override + def do_GET(self) -> None: # noqa: N802 # Required to override """Handle GET Request.""" if self.parse(): self.send_header('Content-Type', 'text/html') From d39c0521da6f3650a87b3b10b4a54c5377f41a3a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:30:41 +0000 Subject: [PATCH 315/727] Move JournalLock class into its own file Closes #891 # Conflicts: # journal_lock.py # monitor.py --- EDMarketConnector.py | 2 +- journal_lock.py | 111 ++++++------------------ monitor.py | 197 +------------------------------------------ 3 files changed, 29 insertions(+), 281 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index bdc2145b..0ba68077 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -39,7 +39,7 @@ from config import appversion, appversion_nobuild, config, copyright # isort: on from EDMCLogging import edmclogger, logger, logging -from monitor import JournalLock +from journal_lock import JournalLock if __name__ == '__main__': # noqa: C901 # Command-line arguments diff --git a/journal_lock.py b/journal_lock.py index 51f94f89..e769b31d 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -1,12 +1,9 @@ -"""Implements locking of Journal directory.""" - import pathlib import tkinter as tk -from enum import Enum from os import getpid as os_getpid from sys import platform from tkinter import ttk -from typing import TYPE_CHECKING, Callable, Optional +from typing import Callable, TYPE_CHECKING from config import config from EDMCLogging import get_main_logger @@ -18,48 +15,22 @@ if TYPE_CHECKING: return x -class JournalLockResult(Enum): - """Enumeration of possible outcomes of trying to lock the Journal Directory.""" - - LOCKED = 1 - JOURNALDIR_NOTEXIST = 2 - JOURNALDIR_READONLY = 3 - ALREADY_LOCKED = 4 - JOURNALDIR_IS_NONE = 5 - - class JournalLock: """Handle locking of journal directory.""" - def __init__(self) -> None: + def __init__(self): """Initialise where the journal directory and lock file are.""" - self.journal_dir: str = config.get('journaldir') or config.default_journal_dir - self.journal_dir_path: Optional[pathlib.Path] = None - self.set_path_from_journaldir() - self.journal_dir_lockfile_name: Optional[pathlib.Path] = None - # We never test truthiness of this, so let it be defined when first assigned. Avoids type hint issues. - # self.journal_dir_lockfile: Optional[IO] = None - self.locked = False + self.journal_dir: str = config.get_str('journaldir') or config.default_journal_dir + self.journal_dir_path = pathlib.Path(self.journal_dir) + self.journal_dir_lockfile_name = None + self.journal_dir_lockfile = None - def set_path_from_journaldir(self): - if self.journal_dir is None: - self.journal_dir_path = None - - else: - try: - self.journal_dir_path = pathlib.Path(self.journal_dir) - - except Exception: - logger.exception("Couldn't make pathlib.Path from journal_dir") - - def obtain_lock(self) -> JournalLockResult: + def obtain_lock(self) -> bool: """ Attempt to obtain a lock on the journal directory. - :return: LockResult - See the class Enum definition + :return: bool - True if we successfully obtained the lock """ - if self.journal_dir_path is None: - return JournalLockResult.JOURNALDIR_IS_NONE self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' logger.trace(f'journal_dir_lockfile_name = {self.journal_dir_lockfile_name!r}') @@ -71,7 +42,6 @@ class JournalLock: except Exception as e: # For remote FS this could be any of a wide range of exceptions logger.warning(f"Couldn't open \"{self.journal_dir_lockfile_name}\" for \"w+\"" f" Aborting duplicate process checks: {e!r}") - return JournalLockResult.JOURNALDIR_READONLY if platform == 'win32': logger.trace('win32, using msvcrt') @@ -84,7 +54,7 @@ class JournalLock: except Exception as e: logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\"" f", assuming another process running: {e!r}") - return JournalLockResult.ALREADY_LOCKED + return False else: logger.trace('NOT win32, using fcntl') @@ -94,7 +64,7 @@ class JournalLock: except ImportError: logger.warning("Not on win32 and we have no fcntl, can't use a file lock!" "Allowing multiple instances!") - return JournalLockResult.LOCKED + return True # Lie about being locked try: fcntl.flock(self.journal_dir_lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) @@ -102,25 +72,19 @@ class JournalLock: except Exception as e: logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\", " f"assuming another process running: {e!r}") - return JournalLockResult.ALREADY_LOCKED + return False self.journal_dir_lockfile.write(f"Path: {self.journal_dir}\nPID: {os_getpid()}\n") self.journal_dir_lockfile.flush() logger.trace('Done') - self.locked = True - - return JournalLockResult.LOCKED + return True def release_lock(self) -> bool: """ Release lock on journal directory. - :return: bool - Whether we're now unlocked. - """ - if not self.locked: - return True # We weren't locked, and still aren't - + :return: bool - Success of unlocking operation.""" unlocked = False if platform == 'win32': logger.trace('win32, using msvcrt') @@ -161,21 +125,14 @@ class JournalLock: self.journal_dir_lockfile.close() self.journal_dir_lockfile_name = None - # Avoids type hint issues, see 'declaration' in JournalLock.__init__() - # self.journal_dir_lockfile = None + self.journal_dir_lockfile = None return unlocked class JournalAlreadyLocked(tk.Toplevel): """Pop-up for when Journal directory already locked.""" - def __init__(self, parent: tk.Tk, callback: Callable) -> None: - """ - Init the user choice popup. - - :param parent: - The tkinter parent window. - :param callback: - The function to be called when the user makes their choice. - """ + def __init__(self, parent: tk.Tk, callback: Callable): tk.Toplevel.__init__(self, parent) self.parent = parent @@ -207,30 +164,23 @@ class JournalLock: self.ignore_button.grid(row=2, column=1, sticky=tk.EW) self.protocol("WM_DELETE_WINDOW", self._destroy) - def retry(self) -> None: - """Handle user electing to Retry obtaining the lock.""" + def retry(self): logger.trace('User selected: Retry') self.destroy() self.callback(True, self.parent) - def ignore(self) -> None: - """Handle user electing to Ignore failure to obtain the lock.""" + def ignore(self): logger.trace('User selected: Ignore') self.destroy() self.callback(False, self.parent) - def _destroy(self) -> None: - """Destroy the Retry/Ignore popup.""" + def _destroy(self): logger.trace('User force-closed popup, treating as Ignore') self.ignore() - def update_lock(self, parent: tk.Tk) -> None: - """ - Update journal directory lock to new location if possible. - - :param parent: - The parent tkinter window. - """ - current_journaldir = config.get('journaldir') or config.default_journal_dir + def update_lock(self, parent: tk.Tk): + """Update journal directory lock to new location if possible.""" + current_journaldir = config.get_str('journaldir') or config.default_journal_dir if current_journaldir == self.journal_dir: return # Still the same @@ -238,27 +188,20 @@ class JournalLock: self.release_lock() self.journal_dir = current_journaldir - self.set_path_from_journaldir() - - if self.obtain_lock() == JournalLockResult.ALREADY_LOCKED: + self.journal_dir_path = pathlib.Path(self.journal_dir) + if not self.obtain_lock(): # Pop-up message asking for Retry or Ignore self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) - def retry_lock(self, retry: bool, parent: tk.Tk) -> None: - """ - Try again to obtain a lock on the Journal Directory. - - :param retry: - does the user want to retry? Comes from the dialogue choice. - :param parent: - The parent tkinter window. - """ + def retry_lock(self, retry: bool, parent: tk.Tk): logger.trace(f'We should retry: {retry}') if not retry: return - current_journaldir = config.get('journaldir') or config.default_journal_dir + current_journaldir = config.get_str('journaldir') or config.default_journal_dir self.journal_dir = current_journaldir - self.set_path_from_journaldir() - if self.obtain_lock() == JournalLockResult.ALREADY_LOCKED: + self.journal_dir_path = pathlib.Path(self.journal_dir) + if not self.obtain_lock(): # Pop-up message asking for Retry or Ignore self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) diff --git a/monitor.py b/monitor.py index 11caced1..abeae8de 100644 --- a/monitor.py +++ b/monitor.py @@ -2,16 +2,12 @@ from collections import defaultdict, OrderedDict import json import re import threading -from os import getpid as os_getpid from os import listdir, SEEK_SET, SEEK_END from os.path import basename, expanduser, isdir, join -import pathlib from sys import platform -import tkinter as tk -from tkinter import ttk from time import gmtime, localtime, sleep, strftime, strptime, time from calendar import timegm -from typing import Any, Callable, List, MutableMapping, Optional, OrderedDict as OrderedDictT, Tuple, TYPE_CHECKING, Union +from typing import Any, List, MutableMapping, Optional, OrderedDict as OrderedDictT, Tuple, TYPE_CHECKING, Union if TYPE_CHECKING: import tkinter @@ -1093,194 +1089,3 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # singleton monitor = EDLogs() - - -class JournalLock: - """Handle locking of journal directory.""" - - def __init__(self): - """Initialise where the journal directory and lock file are.""" - self.journal_dir: str = config.get_str('journaldir') or config.default_journal_dir - self.journal_dir_path = pathlib.Path(self.journal_dir) - self.journal_dir_lock = None - self.journal_dir_lockfile_name = None - self.journal_dir_lockfile = None - - def obtain_lock(self) -> bool: - """ - Attempt to obtain a lock on the journal directory. - - :return: bool - True if we successfully obtained the lock - """ - logger.trace(f'journal_dir_lockfile = {self.journal_dir_lockfile!r}') - - self.journal_dir_lockfile_name: str = self.journal_dir_path / 'edmc-journal-lock.txt' - try: - self.journal_dir_lockfile = open(self.journal_dir_lockfile_name, mode='w+', encoding='utf-8') - - # Linux CIFS read-only mount throws: OSError(30, 'Read-only file system') - # Linux no-write-perm directory throws: PermissionError(13, 'Permission denied') - except Exception as e: # For remote FS this could be any of a wide range of exceptions - logger.warning(f"Couldn't open \"{self.journal_dir_lockfile_name}\" for \"w+\"" - f" Aborting duplicate process checks: {e!r}") - - if platform == 'win32': - logger.trace('win32, using msvcrt') - # win32 doesn't have fcntl, so we have to use msvcrt - import msvcrt - - try: - msvcrt.locking(self.journal_dir_lockfile.fileno(), msvcrt.LK_NBLCK, 4096) - - except Exception as e: - logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\"" - f", assuming another process running: {e!r}") - return False - - else: - logger.trace('NOT win32, using fcntl') - try: - import fcntl - - except ImportError: - logger.warning("Not on win32 and we have no fcntl, can't use a file lock!" - "Allowing multiple instances!") - return True # Lie about being locked - - try: - fcntl.flock(self.journal_dir_lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) - - except Exception as e: - logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\"," - f"assuming another process running: {e!r}") - return False - - self.journal_dir_lockfile.write(f"Path: {self.journal_dir}\nPID: {os_getpid()}\n") - self.journal_dir_lockfile.flush() - - logger.trace('Done') - return True - - def release_lock(self) -> bool: - """ - Release lock on journal directory. - - :return: bool - Success of unlocking operation.""" - unlocked = False - if platform == 'win32': - logger.trace('win32, using msvcrt') - # win32 doesn't have fcntl, so we have to use msvcrt - import msvcrt - - try: - msvcrt.locking(self.journal_dir_lockfile.fileno(), msvcrt.LK_UNLCK, 4096) - - except Exception as e: - logger.info(f"Exception: Couldn't unlock journal directory \"{self.journal_dir}\": {e!r}") - - else: - unlocked = True - - else: - logger.trace('NOT win32, using fcntl') - try: - import fcntl - - except ImportError: - logger.warning("Not on win32 and we have no fcntl, can't use a file lock!") - return True # Lie about being unlocked - - try: - fcntl.flock(self.journal_dir_lockfile, fcntl.LOCK_UN) - - except Exception as e: - logger.info(f"Exception: Couldn't unlock journal directory \"{self.journal_dir}\": {e!r}") - - else: - unlocked = True - - # Close the file whether or not the unlocking succeeded. - self.journal_dir_lockfile.close() - - self.journal_dir_lock = None - self.journal_dir_lockfile_name = None - self.journal_dir_lockfile = None - - return unlocked - - class JournalAlreadyLocked(tk.Toplevel): - """Pop-up for when Journal directory already locked.""" - - def __init__(self, parent: tk.Tk, callback: Callable): - tk.Toplevel.__init__(self, parent) - - self.parent = parent - self.callback = callback - self.title('Journal directory already locked') - - # remove decoration - if platform == 'win32': - self.attributes('-toolwindow', tk.TRUE) - - elif platform == 'darwin': - # http://wiki.tcl.tk/13428 - parent.call('tk::unsupported::MacWindowStyle', 'style', self, 'utility') - - self.resizable(tk.FALSE, tk.FALSE) - - frame = ttk.Frame(self) - frame.grid(sticky=tk.NSEW) - - self.blurb = tk.Label(frame) - self.blurb['text'] = '''The new Journal Directory location is already locked. -You can either attempt to resolve this and then Retry, or choose to Ignore this.''' - self.blurb.grid(row=1, column=0, columnspan=2, sticky=tk.NSEW) - - self.retry_button = ttk.Button(frame, text='Retry', command=self.retry) - self.retry_button.grid(row=2, column=0, sticky=tk.EW) - - self.ignore_button = ttk.Button(frame, text='Ignore', command=self.ignore) - self.ignore_button.grid(row=2, column=1, sticky=tk.EW) - self.protocol("WM_DELETE_WINDOW", self._destroy) - - def retry(self): - logger.trace('User selected: Retry') - self.destroy() - self.callback(True, self.parent) - - def ignore(self): - logger.trace('User selected: Ignore') - self.destroy() - self.callback(False, self.parent) - - def _destroy(self): - logger.trace('User force-closed popup, treating as Ignore') - self.ignore() - - def update_lock(self, parent: tk.Tk): - """Update journal directory lock to new location if possible.""" - current_journaldir = config.get_str('journaldir') or config.default_journal_dir - - if current_journaldir == self.journal_dir: - return # Still the same - - self.release_lock() - - self.journal_dir = current_journaldir - self.journal_dir_path = pathlib.Path(self.journal_dir) - if not self.obtain_lock(): - # Pop-up message asking for Retry or Ignore - self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) - - def retry_lock(self, retry: bool, parent: tk.Tk): - logger.trace(f'We should retry: {retry}') - - if not retry: - return - - current_journaldir = config.get_str('journaldir') or config.default_journal_dir - self.journal_dir = current_journaldir - self.journal_dir_path = pathlib.Path(self.journal_dir) - if not self.obtain_lock(): - # Pop-up message asking for Retry or Ignore - self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) From 6be73dc50e6062c4b04ad4ec7aa61b1abc609590 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 8 Mar 2021 17:01:24 +0000 Subject: [PATCH 316/727] journal_lock: Fix import order & add/expand docstrings --- journal_lock.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/journal_lock.py b/journal_lock.py index e769b31d..25ad3d69 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -1,9 +1,11 @@ +"""Implements locking of Journal directory.""" + import pathlib import tkinter as tk from os import getpid as os_getpid from sys import platform from tkinter import ttk -from typing import Callable, TYPE_CHECKING +from typing import TYPE_CHECKING, Callable from config import config from EDMCLogging import get_main_logger @@ -31,7 +33,6 @@ class JournalLock: :return: bool - True if we successfully obtained the lock """ - self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' logger.trace(f'journal_dir_lockfile_name = {self.journal_dir_lockfile_name!r}') try: @@ -84,7 +85,8 @@ class JournalLock: """ Release lock on journal directory. - :return: bool - Success of unlocking operation.""" + :return: bool - Success of unlocking operation. + """ unlocked = False if platform == 'win32': logger.trace('win32, using msvcrt') @@ -133,6 +135,12 @@ class JournalLock: """Pop-up for when Journal directory already locked.""" def __init__(self, parent: tk.Tk, callback: Callable): + """ + Init the user choice popup. + + :param parent: - The tkinter parent window. + :param callback: - The function to be called when the user makes their choice. + """ tk.Toplevel.__init__(self, parent) self.parent = parent @@ -165,21 +173,28 @@ class JournalLock: self.protocol("WM_DELETE_WINDOW", self._destroy) def retry(self): + """Handle user electing to Retry obtaining the lock.""" logger.trace('User selected: Retry') self.destroy() self.callback(True, self.parent) def ignore(self): + """Handle user electing to Ignore failure to obtain the lock.""" logger.trace('User selected: Ignore') self.destroy() self.callback(False, self.parent) def _destroy(self): + """Destroy the Retry/Ignore popup.""" logger.trace('User force-closed popup, treating as Ignore') self.ignore() def update_lock(self, parent: tk.Tk): - """Update journal directory lock to new location if possible.""" + """ + Update journal directory lock to new location if possible. + + :param parent: - The parent tkinter window. + """ current_journaldir = config.get_str('journaldir') or config.default_journal_dir if current_journaldir == self.journal_dir: @@ -194,6 +209,12 @@ class JournalLock: self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) def retry_lock(self, retry: bool, parent: tk.Tk): + """ + Try again to obtain a lock on the Journal Directory. + + :param retry: - does the user want to retry? Comes from the dialogue choice. + :param parent: - The parent tkinter window. + """ logger.trace(f'We should retry: {retry}') if not retry: From 9a82874c7e911ee1a71a973cde0b496879861113 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 8 Mar 2021 17:18:51 +0000 Subject: [PATCH 317/727] journal_lock: Now fully type-hinted. --- journal_lock.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/journal_lock.py b/journal_lock.py index 25ad3d69..48c3d572 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -5,7 +5,7 @@ import tkinter as tk from os import getpid as os_getpid from sys import platform from tkinter import ttk -from typing import TYPE_CHECKING, Callable +from typing import TYPE_CHECKING, Callable, Optional from config import config from EDMCLogging import get_main_logger @@ -20,12 +20,13 @@ if TYPE_CHECKING: class JournalLock: """Handle locking of journal directory.""" - def __init__(self): + def __init__(self) -> None: """Initialise where the journal directory and lock file are.""" self.journal_dir: str = config.get_str('journaldir') or config.default_journal_dir self.journal_dir_path = pathlib.Path(self.journal_dir) - self.journal_dir_lockfile_name = None - self.journal_dir_lockfile = None + self.journal_dir_lockfile_name: Optional[pathlib.Path] = None + # We never test truthiness of this, so let it be defined when first assigned. Avoids type hint issues. + # self.journal_dir_lockfile: Optional[IO] = None def obtain_lock(self) -> bool: """ @@ -43,6 +44,7 @@ class JournalLock: except Exception as e: # For remote FS this could be any of a wide range of exceptions logger.warning(f"Couldn't open \"{self.journal_dir_lockfile_name}\" for \"w+\"" f" Aborting duplicate process checks: {e!r}") + return False if platform == 'win32': logger.trace('win32, using msvcrt') @@ -127,14 +129,15 @@ class JournalLock: self.journal_dir_lockfile.close() self.journal_dir_lockfile_name = None - self.journal_dir_lockfile = None + # Avoids type hint issues, see 'declaration' in JournalLock.__init__() + # self.journal_dir_lockfile = None return unlocked class JournalAlreadyLocked(tk.Toplevel): """Pop-up for when Journal directory already locked.""" - def __init__(self, parent: tk.Tk, callback: Callable): + def __init__(self, parent: tk.Tk, callback: Callable) -> None: """ Init the user choice popup. @@ -172,24 +175,24 @@ class JournalLock: self.ignore_button.grid(row=2, column=1, sticky=tk.EW) self.protocol("WM_DELETE_WINDOW", self._destroy) - def retry(self): + def retry(self) -> None: """Handle user electing to Retry obtaining the lock.""" logger.trace('User selected: Retry') self.destroy() self.callback(True, self.parent) - def ignore(self): + def ignore(self) -> None: """Handle user electing to Ignore failure to obtain the lock.""" logger.trace('User selected: Ignore') self.destroy() self.callback(False, self.parent) - def _destroy(self): + def _destroy(self) -> None: """Destroy the Retry/Ignore popup.""" logger.trace('User force-closed popup, treating as Ignore') self.ignore() - def update_lock(self, parent: tk.Tk): + def update_lock(self, parent: tk.Tk) -> None: """ Update journal directory lock to new location if possible. @@ -208,7 +211,7 @@ class JournalLock: # Pop-up message asking for Retry or Ignore self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) - def retry_lock(self, retry: bool, parent: tk.Tk): + def retry_lock(self, retry: bool, parent: tk.Tk) -> None: """ Try again to obtain a lock on the Journal Directory. From 165f55bba48c9939a4cdbe4bdc8fcaecc2fdcc9d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 8 Mar 2021 17:30:43 +0000 Subject: [PATCH 318/727] protocol: Work around incompatible types using conditional on wine_get_version --- protocol.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/protocol.py b/protocol.py index e6184a5e..83b10e87 100644 --- a/protocol.py +++ b/protocol.py @@ -21,7 +21,8 @@ is_wine = False if sys.platform == 'win32': from ctypes import windll # type: ignore try: - is_wine = windll.ntdll.wine_get_version + if windll.ntdll.wine_get_version: + is_wine = True except Exception: pass @@ -398,7 +399,7 @@ protocolhandler: GenericProtocolHandler if sys.platform == 'darwin' and getattr(sys, 'frozen', False): protocolhandler = DarwinProtocolHandler() # pyright: reportUnboundVariable=false -elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine: +elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: protocolhandler = WindowsProtocolHandler() else: protocolhandler = LinuxProtocolHandler() From 1692cac51c7d131468fa6eafc990f7f9858c8cb2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 8 Mar 2021 17:37:33 +0000 Subject: [PATCH 319/727] protocol: docstring WNDCLASS structure * Built with py2exe. * Frontier Auth from scratch works on Windows 10 native. --- protocol.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/protocol.py b/protocol.py index 83b10e87..4e28d5c4 100644 --- a/protocol.py +++ b/protocol.py @@ -119,7 +119,9 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a UINT, WPARAM ) - class WNDCLASS(Structure): # noqa: D101 # I dont want to chance messing with a Structure with a docstring + class WNDCLASS(Structure): + """A WNDCLASS structure.""" + _fields_ = [ ('style', UINT), ('lpfnWndProc', WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)), From 1504f25d8f24ff23e2651e1a758f01a0402119cf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 8 Mar 2021 17:42:12 +0000 Subject: [PATCH 320/727] protocol: Expand slightly on WNDCLASS with some references. --- protocol.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/protocol.py b/protocol.py index 4e28d5c4..cca7c225 100644 --- a/protocol.py +++ b/protocol.py @@ -120,7 +120,12 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a ) class WNDCLASS(Structure): - """A WNDCLASS structure.""" + """ + A WNDCLASS structure. + + Ref: + + """ _fields_ = [ ('style', UINT), From 4255a2fd283fe279b637aed6f2aff3950056466e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 8 Mar 2021 17:57:49 +0000 Subject: [PATCH 321/727] monitor: Fix isort complains * Tested with py2exe build on Windows 10 native. Frontier auth works. --- monitor.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/monitor.py b/monitor.py index abeae8de..e9af7328 100644 --- a/monitor.py +++ b/monitor.py @@ -1,19 +1,21 @@ -from collections import defaultdict, OrderedDict import json import re import threading -from os import listdir, SEEK_SET, SEEK_END +from calendar import timegm +from collections import OrderedDict, defaultdict +from os import SEEK_END, SEEK_SET, listdir from os.path import basename, expanduser, isdir, join from sys import platform from time import gmtime, localtime, sleep, strftime, strptime, time -from calendar import timegm -from typing import Any, List, MutableMapping, Optional, OrderedDict as OrderedDictT, Tuple, TYPE_CHECKING, Union +from typing import TYPE_CHECKING, Any, List, MutableMapping, Optional +from typing import OrderedDict as OrderedDictT +from typing import Tuple, Union if TYPE_CHECKING: import tkinter -from config import config from companion import ship_file_name +from config import config from EDMCLogging import get_main_logger logger = get_main_logger() @@ -23,18 +25,20 @@ if TYPE_CHECKING: return x if platform == 'darwin': - from AppKit import NSWorkspace - from watchdog.observers import Observer - from watchdog.events import FileSystemEventHandler from fcntl import fcntl + + from AppKit import NSWorkspace + from watchdog.events import FileSystemEventHandler + from watchdog.observers import Observer F_GLOBAL_NOCACHE = 55 elif platform == 'win32': - from watchdog.observers import Observer - from watchdog.events import FileSystemEventHandler import ctypes from ctypes.wintypes import BOOL, HWND, LPARAM, LPWSTR + from watchdog.events import FileSystemEventHandler + from watchdog.observers import Observer + EnumWindows = ctypes.windll.user32.EnumWindows EnumWindowsProc = ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) From 180d5b0cb6fe3a35e007f2045087bed3beee14f0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 12:20:59 +0000 Subject: [PATCH 322/727] Bump Python 3.8 -> 3.9 in {pr,push}-checks.yml GH workflows Closes #893 --- .github/workflows/pr-checks.yml | 4 ++-- .github/workflows/push-checks.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 8572f5ac..2b7fc78c 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -45,10 +45,10 @@ jobs: #################################################################### # Get Python set up #################################################################### - - name: Set up Python 3.8 + - name: Set up Python 3.9 uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index 93776c4f..1dd650dc 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -20,10 +20,10 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set up Python 3.8 + - name: Set up Python 3.9 uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip From 09730adbe6ad1760159fa4bec9bfdaf52f875387 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 13:12:28 +0000 Subject: [PATCH 323/727] Remove last references to, and generation of, stations.p file. This was historically used by the core EDDB plugin to construct a valid URL for a given station. EDDB has long-since provided alternate URL formats that negate the need for this. Plugin authors have been warned not to use this already. --- EDMarketConnector.wxs | 4 ---- eddb.py | 11 ----------- setup.py | 2 -- 3 files changed, 17 deletions(-) diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index 9013912c..106e7a1a 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -218,9 +218,6 @@ - - - @@ -613,7 +610,6 @@ - diff --git a/eddb.py b/eddb.py index eb3f2ad1..367c755d 100755 --- a/eddb.py +++ b/eddb.py @@ -114,14 +114,3 @@ if __name__ == "__main__": with open('systems.p', 'wb') as h: pickle.dump(system_ids, h, protocol = pickle.HIGHEST_PROTOCOL) print('\n%d saved systems' % len(system_ids)) - - # station_id by (system_id, station_name) - stations = json.loads(download('stations.json').content) # let json do the utf-8 decode - station_ids = { - (x['system_id'], x['name']) : x['id'] # Pilgrim's Ruin in HR 3005 id 70972 has U+2019 quote - for x in stations if x['max_landing_pad_size'] - } - - with open('stations.p', 'wb') as h: - pickle.dump(station_ids, h, protocol = pickle.HIGHEST_PROTOCOL) - print('\n%d saved stations' % len(station_ids)) diff --git a/setup.py b/setup.py index 14cefcaa..446f36f3 100755 --- a/setup.py +++ b/setup.py @@ -133,7 +133,6 @@ if sys.platform == 'darwin': 'snd_bad.wav', 'modules.p', 'ships.p', - 'stations.p', 'systems.p' ], 'site_packages': False, @@ -195,7 +194,6 @@ elif sys.platform=='win32': 'snd_bad.wav', 'modules.p', 'ships.p', - 'stations.p', 'systems.p', '%s.VisualElementsManifest.xml' % APPNAME, '%s.ico' % APPNAME, From 357f2278b22bf3690017585097c7b42a8956dc6e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:31:19 +0000 Subject: [PATCH 324/727] Remove last references to, and generation of, systems.p file This was the last code in eddb.py, so that has now been removed. This was historically used by the core EDDB plugin to construct a valid URL for a given station. EDDB has long-since provided alternate URL formats that negate the need for this. Plugin authors have been warned not to use this already. # Conflicts: # setup.py --- EDMarketConnector.wxs | 4 -- eddb.py | 116 ------------------------------------------ setup.py | 6 +-- 3 files changed, 2 insertions(+), 124 deletions(-) delete mode 100755 eddb.py diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index 106e7a1a..4f4d8031 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -218,9 +218,6 @@ - - - @@ -611,7 +608,6 @@ - diff --git a/eddb.py b/eddb.py deleted file mode 100755 index 367c755d..00000000 --- a/eddb.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3 -# -# build databases from files systems.csv and stations.json from http://eddb.io/api -# - -import pickle -import csv -import json -import requests - -def download(filename): - r = requests.get('https://eddb.io/archive/v6/' + filename, stream=True) - print('\n%s\t%dK' % (filename, len(r.content) / 1024)) - return r - -if __name__ == "__main__": - - # Ellipsoid that encompasses most of the systems in the bubble (but not outliers like Sothis) - RX = RZ = 260 - CY = -50 - RY = 300 - - RX2 = RX * RX - RY2 = RY * RY - RZ2 = RZ * RZ - - def inbubble(x, y, z): - return (x * x)/RX2 + ((y - CY) * (y - CY))/RY2 + (z * z)/RZ2 <= 1 - - # Sphere around Jaques - JX, JY, JZ = -9530.50000, -910.28125, 19808.12500 - RJ2 = 80 * 80 # Furthest populated system is Pekoe at 50.16 Ly - - def around_jaques(x, y, z): - return ((x - JX) * (x - JX) + (y - JY) * (y - JY) + (z - JZ) * (z - JZ)) <= RJ2 - - # Sphere around outliers - RO2 = 40 * 40 - def around_outlier(cx, cy, cz, x, y, z): - return ((x - ox) * (x - ox) + (y - oy) * (y - oy) + (z - oz) * (z - oz)) <= RO2 - - # Load all EDDB-known systems into a dictionary - systems = { int(s['id']) : { - 'name' : s['name'], - 'x' : float(s['x']), - 'y' : float(s['y']), - 'z' : float(s['z']), - 'is_populated' : int(s['is_populated']), - } for s in csv.DictReader(download('systems.csv').iter_lines(decode_unicode=True)) } - #} for s in csv.DictReader(open('systems.csv')) } - print('%d\tsystems' % len(systems)) - - # Build another dict containing all systems considered to be in the - # main populated bubble (see constants above and inbubble() for - # the criteria). - # (system_id, is_populated) by system_name (ignoring duplicate names) - system_ids = { - str(s['name']) : (k, s['is_populated']) - for k,s in systems.items() if inbubble(s['x'], s['y'], s['z']) - } - print('%d\tsystems in bubble' % len(system_ids)) - - # Build another dict for systems considered to be around Colonia - extra_ids = { - str(s['name']) : (k, s['is_populated']) - for k,s in systems.items() if around_jaques(s['x'], s['y'], s['z']) - } - system_ids.update(extra_ids) - print('%d\tsystems in Colonia' % len(extra_ids)) - - # Build another dict for systems that are marked as populated, but - # didn't make it into the bubble list. - cut = { - k : s for k, s in systems.items() - if s['is_populated'] and s['name'] not in system_ids - } - print('%d\toutlying populated systems:' % len(cut)) - - # Build another dict with all the systems, populated or not, around any - # of the outliers. - extra_ids = {} - for k1,o in sorted(cut.items()): - ox, oy, oz = o['x'], o['y'], o['z'] - extra = { - str(s['name']) : (k, s['is_populated']) - for k,s in systems.items() if around_outlier(ox, oy, oz, s['x'], s['y'], s['z']) - } - print('%-30s%7d %11.5f %11.5f %11.5f %4d' % (o['name'], k1, ox, oy, oz, len(extra))) - extra_ids.update(extra) - print('\n%d\tsystems around outliers' % len(extra_ids)) - system_ids.update(extra_ids) - - # Re-build 'cut' dict to hold duplicate (name) systems - cut = { - k : s - for k,s in systems.items() if s['name'] in system_ids and system_ids[s['name']][0] != k - } - print('\n%d duplicate systems' % len(cut)) - for k,s in sorted(cut.items()): - print('%-20s%8d %8d %11.5f %11.5f %11.5f' % (s['name'], system_ids[s['name']][0], k, s['x'], s['y'], s['z'])) - - # Hack - ensure duplicate system names are pointing at the more interesting system - system_ids['Amo'] = (866, True) - system_ids['C Puppis'] = (25068, False) - system_ids['q Velorum'] = (15843, True) - system_ids['M Carinae'] = (22627, False) - system_ids['HH 17'] = (61275, False) - system_ids['K Carinae'] = (375886, False) - system_ids['d Velorum'] = (406476, False) - system_ids['L Velorum'] = (2016580, False) - system_ids['N Velorum'] = (3012033, False) - system_ids['i Velorum'] = (3387990, False) - - with open('systems.p', 'wb') as h: - pickle.dump(system_ids, h, protocol = pickle.HIGHEST_PROTOCOL) - print('\n%d saved systems' % len(system_ids)) diff --git a/setup.py b/setup.py index 446f36f3..c39c9553 100755 --- a/setup.py +++ b/setup.py @@ -133,7 +133,6 @@ if sys.platform == 'darwin': 'snd_bad.wav', 'modules.p', 'ships.p', - 'systems.p' ], 'site_packages': False, 'plist': { @@ -194,9 +193,8 @@ elif sys.platform=='win32': 'snd_bad.wav', 'modules.p', 'ships.p', - 'systems.p', - '%s.VisualElementsManifest.xml' % APPNAME, - '%s.ico' % APPNAME, + f'{appname}.VisualElementsManifest.xml', + f'{appname}.ico', 'EDMarketConnector - TRACE.bat', 'EDMarketConnector - localserver-auth.bat', ]), From 81e25adfb127e6f49647d38f96e3f738b9b600da Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 13:17:51 +0000 Subject: [PATCH 325/727] Bump version to 5.0.0-beta1, due to removal of {stations,systems}.p files --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index a77bd49c..51edad4d 100644 --- a/config.py +++ b/config.py @@ -28,7 +28,7 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '4.3.0-beta1' # -rc1+a872b5f' +appversion = '5.0.0-beta1' # -rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' From d589ca6ed21c601527cf9c3a0731bf64df4f7893 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 15:45:16 +0000 Subject: [PATCH 326/727] Expand caller_attributes() docstring to params and return --- EDMCLogging.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EDMCLogging.py b/EDMCLogging.py index 80b43c16..f28eed84 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -291,6 +291,9 @@ class EDMCContextFilter(logging.Filter): class if relevant. 3. module is munged if we detect the caller is an EDMC plugin, whether internal or found. + + :param module_name: The name of the calling module. + :return: Tuple[str, str, str] - class_name, qualname, module_name """ frame = cls.find_caller_frame() From a6866fb4d13306e138dccb72540dc6f3a980313f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 15:52:51 +0000 Subject: [PATCH 327/727] EDMCLogging: Return 'best efforts' if erroring in caller_attributes() --- EDMCLogging.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index f28eed84..6d9f8d28 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -316,8 +316,8 @@ class EDMCContextFilter(logging.Filter): except Exception: pass - # We've given up, so just return all '??' to signal we couldn't get the info - return '??', '??', '??' + # We've given up, so just return '??' to signal we couldn't get the info + return '??', '??', module_name args, _, _, value_dict = inspect.getargvalues(frame) if len(args) and args[0] in ('self', 'cls'): @@ -340,7 +340,8 @@ class EDMCContextFilter(logging.Filter): "EDMCLogging:EDMCContextFilter:caller_attributes():" "Failed to get attribute for function info. Bailing out" ) - return "??", "??", "??" + # class_name is better than nothing for __qualname__ + return class_name, class_name, module_name if fn is not None: if isinstance(fn, property): From 114379c8ed30309c6d1aaacbc9aaeffd6cc7d38d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 16 Oct 2020 15:32:00 +0100 Subject: [PATCH 328/727] hotkey: Load good/bad sounds without leaking an open file descriptor. --- hotkey.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hotkey.py b/hotkey.py index c0baa14c..309fd5b2 100644 --- a/hotkey.py +++ b/hotkey.py @@ -291,8 +291,10 @@ elif platform == 'win32': def __init__(self): self.root = None self.thread = None - self.snd_good = open(join(config.respath_path, 'snd_good.wav'), 'rb').read() - self.snd_bad = open(join(config.respath_path, 'snd_bad.wav'), 'rb').read() + with open(join(config.respath, 'snd_good.wav'), 'rb') as sg: + self.snd_good = sg.read() + with open(join(config.respath, 'snd_bad.wav'), 'rb') as sb: + self.snd_bad = sb.read() atexit.register(self.unregister) def register(self, root, keycode, modifiers): From f2ce63bfe79e150b3ffa7c912bdb0dd37eac8e25 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 16 Oct 2020 15:48:56 +0100 Subject: [PATCH 329/727] l10n: Close localisation files after reading content * These are opened in self.file() using codecs.open(), so no quick way to convert to a 'with'. --- l10n.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/l10n.py b/l10n.py index 9cc7d946..d6e4677e 100755 --- a/l10n.py +++ b/l10n.py @@ -131,6 +131,7 @@ class _Translations: """Load all the translations from a translation file.""" assert lang in self.available() translations = {} + h = self.file(lang, plugin_path) if not h: return {} @@ -144,6 +145,7 @@ class _Translations: elif not _Translations.COMMENT_RE.match(line): logger.debug(f'Bad translation: {line.strip()}') + h.close() if translations.get(LANGUAGE_ID, LANGUAGE_ID) == LANGUAGE_ID: translations[LANGUAGE_ID] = str(lang) # Replace language name with code if missing From 96953744c9e352991347f0166a31338c6d50ef78 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 16 Oct 2020 15:54:13 +0100 Subject: [PATCH 330/727] monitor: Close journal loghandle if signalled to close down. --- monitor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monitor.py b/monitor.py index e9af7328..9aecfe92 100644 --- a/monitor.py +++ b/monitor.py @@ -384,6 +384,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Check whether we're still supposed to be running if threading.current_thread() != self.thread: logger.info("We're not meant to be running, exiting...") + if loghandle: + loghandle.close() + return # Terminate if self.game_was_running: From 745c2ce8d25a1eb15de31b33a9c3b628cd9d15bc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 16 Oct 2020 16:04:09 +0100 Subject: [PATCH 331/727] edsm: Ensure Request handles are closed. --- plugins/edsm.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/edsm.py b/plugins/edsm.py index 1707ae3d..a5006a9d 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -541,6 +541,8 @@ def worker() -> None: r = this.session.get('https://www.edsm.net/api-journal-v1/discard', timeout=_TIMEOUT) r.raise_for_status() this.discardedEvents = set(r.json()) + r.close() + this.discardedEvents.discard('Docked') # should_send() assumes that we send 'Docked' events if not this.discardedEvents: logger.error( @@ -632,7 +634,10 @@ def worker() -> None: pending = [] + r.close() + break # No exception, so assume success + except Exception as e: logger.debug(f'Attempt to send API events: retrying == {retrying}', exc_info=e) retrying += 1 From d7d3dc19e4793d1530abcae8b89f86ddcf4c660b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 16 Oct 2020 16:22:02 +0100 Subject: [PATCH 332/727] companion.py: Add Auth destructor to close session. It's created in the constructor, so destructor is the place for this. --- companion.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/companion.py b/companion.py index 62d3745c..114ea599 100644 --- a/companion.py +++ b/companion.py @@ -274,6 +274,10 @@ class Auth(object): self.verifier: Union[bytes, None] = None self.state: Union[str, None] = None + def __del__(self): + if self.session: + self.session.close() + def refresh(self) -> Union[str, None]: """ Attempt use of Refresh Token to get a valid Access Token. @@ -309,6 +313,7 @@ class Auth(object): tokens[idx] = data.get('refresh_token', '') config.set('fdev_apikeys', tokens) config.save() # Save settings now for use by command-line app + return data.get('access_token') else: From 3d3674da5f9764c597507151465670254f09ec26 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 15:12:16 +0000 Subject: [PATCH 333/727] plugins/edsm: Call requests.Session.close() after we've shutdown worker thread This properly closes any sockets and avoids a -W default warning on shutdown. --- plugins/edsm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/edsm.py b/plugins/edsm.py index a5006a9d..d82c0fc0 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -168,6 +168,7 @@ def plugin_stop() -> None: this.queue.put(None) this.thread.join() this.thread = None + this.session.close() # Suppress 'Exception ignored in: ' errors # TODO: this is bad. this._IMG_KNOWN = this._IMG_UNKNOWN = this._IMG_NEW = this._IMG_ERROR = None logger.debug('Done.') @@ -541,7 +542,6 @@ def worker() -> None: r = this.session.get('https://www.edsm.net/api-journal-v1/discard', timeout=_TIMEOUT) r.raise_for_status() this.discardedEvents = set(r.json()) - r.close() this.discardedEvents.discard('Docked') # should_send() assumes that we send 'Docked' events if not this.discardedEvents: From 6aa4ccaf90f476d7fc62e5bad93ea0f07e3c0b23 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 15:36:35 +0000 Subject: [PATCH 334/727] plugins/edsm: Don't try to r.close(), that's not even valid --- plugins/edsm.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/edsm.py b/plugins/edsm.py index d82c0fc0..fc46a5a3 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -634,8 +634,6 @@ def worker() -> None: pending = [] - r.close() - break # No exception, so assume success except Exception as e: From 933ec723bd64c39bae21afb1e763d3becf1f0bfc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 9 Mar 2021 15:37:01 +0000 Subject: [PATCH 335/727] plugins/eddn: Call requests.Session.close() in EDDN.close() Avoids a `-W default` warning on shutdown. --- plugins/eddn.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index c9565c7e..22f76ec6 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -113,7 +113,7 @@ class EDDN: self.replayfile.flush() def close(self): - """Close the replay file.""" + """Close down the EDDN class instance.""" logger.debug('Closing replayfile...') if self.replayfile: self.replayfile.close() @@ -121,6 +121,9 @@ class EDDN: self.replayfile = None logger.debug('Done.') + logger.debug('Closing EDDN requests.Session.') + self.session.close() + def send(self, cmdr: str, msg: Mapping[str, Any]) -> None: """ Send sends an update to EDDN From 82db2e1a061c39275acca1da16f3996e5df14ac7 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 9 Mar 2021 18:19:57 +0200 Subject: [PATCH 336/727] Removed star import from ctypes --- theme.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/theme.py b/theme.py index 26cff4f3..d05a52e6 100644 --- a/theme.py +++ b/theme.py @@ -6,26 +6,25 @@ # import os -from sys import platform -from os.path import join - import tkinter as tk -from tkinter import ttk +from os.path import join +from sys import platform from tkinter import font as tkFont -from ttkHyperlinkLabel import HyperlinkLabel +from tkinter import ttk -from config import appname, applongname, config +from config import applongname, appname, config +from ttkHyperlinkLabel import HyperlinkLabel if __debug__: from traceback import print_exc if platform == "linux": - from ctypes import * + from ctypes import POINTER, c_char_p, c_int, c_long, c_uint, c_ulong, c_void_p, cdll, Structure, byref if platform == 'win32': import ctypes - from ctypes.wintypes import LPCWSTR, DWORD, LPCVOID + from ctypes.wintypes import DWORD, LPCVOID, LPCWSTR AddFontResourceEx = ctypes.windll.gdi32.AddFontResourceExW AddFontResourceEx.restypes = [LPCWSTR, DWORD, LPCVOID] FR_PRIVATE = 0x10 @@ -33,10 +32,11 @@ if platform == 'win32': AddFontResourceEx(join(config.respath, u'EUROCAPS.TTF'), FR_PRIVATE, 0) elif platform == 'linux': + # pyright: reportUnboundVariable=false XID = c_ulong # from X.h: typedef unsigned long XID Window = XID Atom = c_ulong - Display = c_void_p # Opaque + Display = c_void_p # Opaque PropModeReplace = 0 PropModePrepend = 1 @@ -338,7 +338,7 @@ class _Theme(object): self.active = theme if platform == 'darwin': - from AppKit import NSApplication, NSAppearance, NSMiniaturizableWindowMask, NSResizableWindowMask + from AppKit import NSAppearance, NSApplication, NSMiniaturizableWindowMask, NSResizableWindowMask root.update_idletasks() # need main window to be created appearance = NSAppearance.appearanceNamed_(theme and 'NSAppearanceNameDarkAqua' or From e293f0f3344d8b3fcb6f2a3c448896198aa02534 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 9 Mar 2021 18:34:04 +0200 Subject: [PATCH 337/727] Removed star import --- ttkHyperlinkLabel.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ttkHyperlinkLabel.py b/ttkHyperlinkLabel.py index 627a987f..c731ffac 100644 --- a/ttkHyperlinkLabel.py +++ b/ttkHyperlinkLabel.py @@ -1,15 +1,14 @@ -from sys import platform -import webbrowser - import tkinter as tk -from tkinter import ttk +import webbrowser +from sys import platform from tkinter import font as tkFont +from tkinter import ttk if platform == 'win32': import subprocess - import ctypes - from ctypes.wintypes import * - from winreg import CloseKey, OpenKeyEx, QueryValueEx, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, KEY_READ, REG_SZ, REG_MULTI_SZ + from winreg import ( + HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, CloseKey, OpenKeyEx, QueryValueEx + ) # A clickable ttk Label # From ef891fa8bd3dbf5ea536df7bd3a3d205528846b3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 11:20:25 +0000 Subject: [PATCH 338/727] Initial support for Route.json file --- PLUGINS.md | 6 ++++++ monitor.py | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/PLUGINS.md b/PLUGINS.md index f98a125a..32b5fd4e 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -426,6 +426,7 @@ Content of `state` (updated to the current journal entry): | `ModulesValue` | `int` | Value of the current ship's modules | | `Rebuy` | `int` | Current ship's rebuy cost | | `Modules` | `dict` | Currently fitted modules | +| `Route` | `dict` | Last plotted multi-hop route | A special "StartUp" entry is sent if EDMC is started while the game is already running. In this case you won't receive initial events such as "LoadGame", @@ -475,6 +476,11 @@ as the mission ID for mission specific cargo is not written at Commander login (instead the in-Journal `Cargo` event contains all the data), this will not be populated at login.** +New in version 5.0.0: + +`Route` contains the `json.load()` of `Route.json` as indicated by a journal +`Route` event. + #### Getting Commander Data ```python diff --git a/monitor.py b/monitor.py index 9aecfe92..f76eba24 100644 --- a/monitor.py +++ b/monitor.py @@ -126,7 +126,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'ModulesValue': None, 'Rebuy': None, 'Modules': None, - 'CargoJSON': None, # The raw data from the last time cargo.json was read + 'CargoJSON': None, # The raw data from the last time cargo.json was read + 'Route': None, # Last plotted route from Route.json file } def start(self, root: 'tkinter.Tk'): @@ -459,6 +460,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'ModulesValue': None, 'Rebuy': None, 'Modules': None, + 'Route': None, } elif event_type == 'Commander': @@ -666,6 +668,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean}) + elif event_type == 'Route': + # Added in ED 3.7 - multi-hop route details in Route.json + with open(join(self.currentdir, 'Route.json'), 'rb') as rf: # type: ignore + entry = json.load(rf) + self.state['Route'] = entry + elif event_type in ('CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined'): commodity = self.canonicalise(entry['Type']) self.state['Cargo'][commodity] += entry.get('Count', 1) From b3a1b0492e91326f27c10dc24b2eccfd36d1bdea Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 11:42:06 +0000 Subject: [PATCH 339/727] Correct event and file name to NavRoute(.json) & expand docs * Despite what section 4.18 of v28 Journal docs say, the event is `NavRoute`, not `Route`, and the file is `NavRoute.json`. The array of hops is still keyed as `Route` though. * Calls out that both `NavRoute` and `Cargo` events, as passed to plugins, are augmented with the data from their respective files, and are not simply the 'bare' event as seen in the Journal. --- PLUGINS.md | 24 +++++++++++++++++++++--- monitor.py | 4 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 32b5fd4e..5f773d08 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -426,7 +426,9 @@ Content of `state` (updated to the current journal entry): | `ModulesValue` | `int` | Value of the current ship's modules | | `Rebuy` | `int` | Current ship's rebuy cost | | `Modules` | `dict` | Currently fitted modules | -| `Route` | `dict` | Last plotted multi-hop route | +| `NavRoute` | `dict` | Last plotted multi-hop route | + +##### Synthetic Events A special "StartUp" entry is sent if EDMC is started while the game is already running. In this case you won't receive initial events such as "LoadGame", @@ -445,6 +447,22 @@ between the two scenarios. This event is not sent when EDMC is running on a different machine so you should not *rely* on receiving this event. +##### Augmented Events + +In some cases we augment the events, as seen in the Journal, with extra data. +Examples of this are: + +1. Every `Cargo` event passed to plugins contains the data from + `Cargo.json` (but see above for caveats). + +1. Every `NavRoute` event contains the full `Route` array as loaded from + `NavRoute.json`. You do not need to access this via + `monitor.state['NavRoute']`, although it is available there. + + *NB: There is no indication available when a player cancels a route.* The + game itself does not provide any such, not in a Journal event, not in a + `Status.json` flag. + #### Player Dashboard ```python @@ -478,8 +496,8 @@ contains all the data), this will not be populated at login.** New in version 5.0.0: -`Route` contains the `json.load()` of `Route.json` as indicated by a journal -`Route` event. +`NavRoute` contains the `json.load()` of `NavRoute.json` as indicated by a journal +`NavRoute` event. #### Getting Commander Data diff --git a/monitor.py b/monitor.py index f76eba24..a2fbc1b5 100644 --- a/monitor.py +++ b/monitor.py @@ -668,9 +668,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean}) - elif event_type == 'Route': + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in Route.json - with open(join(self.currentdir, 'Route.json'), 'rb') as rf: # type: ignore + with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore entry = json.load(rf) self.state['Route'] = entry From 1ee2be8fc8b76e2bb4202594b37bcb2f5f65118d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 11:50:11 +0000 Subject: [PATCH 340/727] Call out discrepancies between Journal doc v28 and reality in 3.7.x --- PLUGINS.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/PLUGINS.md b/PLUGINS.md index 5f773d08..e55b2b42 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -462,6 +462,22 @@ Examples of this are: *NB: There is no indication available when a player cancels a route.* The game itself does not provide any such, not in a Journal event, not in a `Status.json` flag. + + The Journal documentation v28 is incorrect about the event + and file being `Route(.json)` the word is `NavRoute`. Also the format of + the data is, e.g. + + ```json + { "timestamp":"2021-03-10T11:31:37Z", + "event":"NavRoute", + "Route": [ + { "StarSystem": "Esuvit", "SystemAddress": 2869709317505, "StarPos": [-13.18750,-1.15625,-92.68750], "StarClass": "M" }, + { "StarSystem": "Ndozins", "SystemAddress": 3446451210595, "StarPos": [-14.31250,-10.68750,-60.56250], "StarClass": "M" }, + { "StarSystem": "Tascheter Sector MN-T b3-6", "SystemAddress": 13864825529753, "StarPos": [-11.87500,-21.96875,-29.03125], "StarClass": "M" }, + { "StarSystem": "LP 823-4", "SystemAddress": 9466778953129, "StarPos": [-8.62500,-27.84375,3.93750], "StarClass": "M" } + ] + } + ``` #### Player Dashboard From 0dc7c62fa8f1b8549b991f7ae15406085f2b7eb6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 13:04:30 +0000 Subject: [PATCH 341/727] Correct `Route` to `NavRoute` in the code/comments as well --- monitor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index a2fbc1b5..2e1b8760 100644 --- a/monitor.py +++ b/monitor.py @@ -669,10 +669,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean}) elif event_type == 'NavRoute': - # Added in ED 3.7 - multi-hop route details in Route.json + # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore entry = json.load(rf) - self.state['Route'] = entry + self.state['NavRoute'] = entry elif event_type in ('CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined'): commodity = self.canonicalise(entry['Type']) From f280a7e8634b359fb1e694c1496e73711916aa71 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 13:12:20 +0000 Subject: [PATCH 342/727] try/except for NavRoute json.load() --- monitor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 2e1b8760..eaf2cfa9 100644 --- a/monitor.py +++ b/monitor.py @@ -671,8 +671,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore - entry = json.load(rf) - self.state['NavRoute'] = entry + try: + entry = json.load(rf) + + except json.JSONDecodeError: + logger.exception('Failed decoding NavRoute.json') + + else: + self.state['NavRoute'] = entry elif event_type in ('CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined'): commodity = self.canonicalise(entry['Type']) From 361cd168afc8fe0f71624a67b311103705cdcb1c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 13:39:08 +0000 Subject: [PATCH 343/727] Actually show exception on json.load() exception --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index eaf2cfa9..c6982103 100644 --- a/monitor.py +++ b/monitor.py @@ -675,7 +675,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below entry = json.load(rf) except json.JSONDecodeError: - logger.exception('Failed decoding NavRoute.json') + logger.exception('Failed decoding NavRoute.json', exc_info=True) else: self.state['NavRoute'] = entry From fd0ce6334115e1ccc24773391fd808c0c9cba41d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 12:07:39 +0000 Subject: [PATCH 344/727] Add basic support for ModuleInfo event. This still needs documentation adding in PLUGINS.md, which is easiest done after #897 is merged and re-based upon. --- monitor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/monitor.py b/monitor.py index c6982103..11afd2f9 100644 --- a/monitor.py +++ b/monitor.py @@ -680,6 +680,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below else: self.state['NavRoute'] = entry + elif event_type == 'ModuleInfo': + with open(join(self.currentdir, 'ModulesInfo.json'), 'rb') as mf: # type: ignore + entry = json.load(mf) + self.state['ModuleInfo'] = entry + elif event_type in ('CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined'): commodity = self.canonicalise(entry['Type']) self.state['Cargo'][commodity] += entry.get('Count', 1) From 3fddd2bdf968d477515af961ca17913979102cc0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 13:49:34 +0000 Subject: [PATCH 345/727] try/except ModulesInfo.json load & fully document --- PLUGINS.md | 9 +++++++++ monitor.py | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index e55b2b42..71c0f6a6 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -427,6 +427,7 @@ Content of `state` (updated to the current journal entry): | `Rebuy` | `int` | Current ship's rebuy cost | | `Modules` | `dict` | Currently fitted modules | | `NavRoute` | `dict` | Last plotted multi-hop route | +| `ModuleInfo` | `dict` | Last loaded ModulesInfo.json data | ##### Synthetic Events @@ -479,6 +480,11 @@ Examples of this are: } ``` +1. Every `ModuleInfo` event contains the full data as loaded from the + `ModulesInfo.json` file. It's also available as `monitor.stat['ModuleInfo']` + (noting that we used the singular form there to stay consistent with the + Journal event name). + #### Player Dashboard ```python @@ -515,6 +521,9 @@ New in version 5.0.0: `NavRoute` contains the `json.load()` of `NavRoute.json` as indicated by a journal `NavRoute` event. +`ModuleInfo` contains the `json.load()` of `ModulesInfo.json` as indicated by a +Journal `ModuleInfo` event. + #### Getting Commander Data ```python diff --git a/monitor.py b/monitor.py index 11afd2f9..e6f5f678 100644 --- a/monitor.py +++ b/monitor.py @@ -682,8 +682,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'ModuleInfo': with open(join(self.currentdir, 'ModulesInfo.json'), 'rb') as mf: # type: ignore - entry = json.load(mf) - self.state['ModuleInfo'] = entry + try: + entry = json.load(mf) + + except json.JSONDecodeError: + logger.exception('Failed decoding ModulesInfo.json', exc_info=True) + + else: + self.state['ModuleInfo'] = entry elif event_type in ('CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined'): commodity = self.canonicalise(entry['Type']) From 1c82605d9f232668deb266a089ec02cf19dd4327 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 14:30:25 +0000 Subject: [PATCH 346/727] monitor.py: General cleanup work on flake8 output. * docstrings added as per flake8 complaints. * Some type hints added (as I was documenting param and return). * Also reworked two uses of .format() * A number of functions had noqa added for cognitive complexity. --- monitor.py | 97 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 18 deletions(-) diff --git a/monitor.py b/monitor.py index e6f5f678..04912a99 100644 --- a/monitor.py +++ b/monitor.py @@ -1,3 +1,5 @@ +"""Monitor for new Journal files and contents of latest.""" + import json import re import threading @@ -7,7 +9,7 @@ from os import SEEK_END, SEEK_SET, listdir from os.path import basename, expanduser, isdir, join from sys import platform from time import gmtime, localtime, sleep, strftime, strptime, time -from typing import TYPE_CHECKING, Any, List, MutableMapping, Optional +from typing import TYPE_CHECKING, Any, Dict, List, MutableMapping, Optional from typing import OrderedDict as OrderedDictT from typing import Tuple, Union @@ -57,6 +59,8 @@ else: # Journal handler class EDLogs(FileSystemEventHandler): # type: ignore # See below + """Monitoring of Journal files.""" + # Magic with FileSystemEventHandler can confuse type checkers when they do not have access to every import _POLL = 1 # Polling is cheap, so do it often @@ -130,7 +134,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Route': None, # Last plotted route from Route.json file } - def start(self, root: 'tkinter.Tk'): + def start(self, root: 'tkinter.Tk'): # noqa: CCR001 """Start journal monitoring.""" logger.debug('Begin...') self.root = root @@ -254,15 +258,28 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Done.') def running(self): + """ + Determine if Journal watching is active. + + :return: bool + """ return self.thread and self.thread.is_alive() def on_created(self, event): - # watchdog callback, e.g. client (re)started. + """Watchdog callback when, e.g. client (re)started.""" if not event.is_directory and self._RE_LOGFILE.search(basename(event.src_path)): self.logfile = event.src_path - def worker(self): + def worker(self): # noqa: C901, CCR001 + """ + Watch latest Journal file. + + 1. Keep track of the latest Journal file, switching to a new one if + needs be. + 2. Read in lines from the latest Journal file and queue them up for + get_entry() to process in the main thread. + """ # Tk isn't thread-safe in general. # event_generate() is the only safe way to poke the main thread from this thread: # https://mail.python.org/pipermail/tkinter-discuss/2013-November/003522.html @@ -408,7 +425,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Done.') - def parse_entry(self, line: str): + def parse_entry(self, line: str) -> Dict: # noqa: C901, CCR001 + """ + Parse a Journal JSON line. + + This augments some events, sets internal state in reaction to many and + loads some extra files, e.g. Cargo.json, as necessary. + + :return: Dict of the processed event. + """ # TODO(A_D): a bunch of these can be simplified to use if itertools.product and filters if line is None: return {'event': None} # Fake startup event @@ -869,11 +894,18 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug(f'Invalid journal entry:\n{line}\n', exc_info=ex) return {'event': None} - # Commodities, Modules and Ships can appear in different forms e.g. "$HNShockMount_Name;", "HNShockMount", - # and "hnshockmount", "$int_cargorack_size6_class1_name;" and "Int_CargoRack_Size6_Class1", - # "python" and "Python", etc. - # This returns a simple lowercased name e.g. 'hnshockmount', 'int_cargorack_size6_class1', 'python', etc def canonicalise(self, item: Optional[str]): + """ + Produce canonical name for a ship module. + + Commodities, Modules and Ships can appear in different forms e.g. "$HNShockMount_Name;", "HNShockMount", + and "hnshockmount", "$int_cargorack_size6_class1_name;" and "Int_CargoRack_Size6_Class1", + "python" and "Python", etc. + This returns a simple lowercased name e.g. 'hnshockmount', 'int_cargorack_size6_class1', 'python', etc + + :param item: str - 'Found' name of the item. + :return: str - The canonical name. + """ if not item: return '' @@ -886,6 +918,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return item def category(self, item: str): + """ + Determine the category of an item. + + :param item: str - The item in question. + :return: str - The category for this item. + """ match = self._RE_CATEGORY.match(item) if match: @@ -945,20 +983,28 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.event_queue.append(json.dumps(entry, separators=(', ', ':'))) elif self.live and entry['event'] == 'Music' and entry.get('MusicTrack') == 'MainMenu': + ts = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) self.event_queue.append( - '{{ "timestamp":"{}", "event":"ShutDown" }}'.format(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())) + f'{{ "timestamp":"{ts}", "event":"ShutDown" }}' ) return entry - def game_running(self): + def game_running(self) -> bool: # noqa: CCR001 + """ + Determine if the game is currently running. + + TODO: Implement on Linux + + :return: bool - True if the game is running. + """ if platform == 'darwin': for app in NSWorkspace.sharedWorkspace().runningApplications(): if app.bundleIdentifier() == 'uk.co.frontier.EliteDangerous': return True elif platform == 'win32': - def WindowTitle(h): + def WindowTitle(h): # noqa: N802 if h: length = GetWindowTextLength(h) + 1 buf = ctypes.create_unicode_buffer(length) @@ -966,7 +1012,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return buf.value return None - def callback(hWnd, lParam): + def callback(hWnd, lParam): # noqa: N803 name = WindowTitle(hWnd) if name and name.startswith('Elite - Dangerous'): handle = GetProcessHandleFromHwnd(hWnd) @@ -980,8 +1026,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return False - # Return a subset of the received data describing the current ship as a Loadout event - def ship(self, timestamped=True): + def ship(self, timestamped=True) -> OrderedDictT: + """ + Produce a subset of data for the current ship. + + Return a subset of the received data describing the current ship as a Loadout event. + + :param timestamped: bool - Whether to add a 'timestamp' member. + :return: dict + """ if not self.state['Modules']: return None @@ -1024,8 +1077,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return d - # Export ship loadout as a Loadout event - def export_ship(self, filename=None): + def export_ship(self, filename=None) -> None: + """ + Export ship loadout as a Loadout event. + + Writes either to the specified filename or to a formatted filename based on + the ship name and a date+timestamp. + + :param filename: Name of file to write to, if not default. + """ # TODO(A_D): Some type checking has been disabled in here due to config.get getting weird outputs string = json.dumps(self.ship(False), ensure_ascii=False, indent=2, separators=(',', ': ')) # pretty print if filename: @@ -1061,8 +1121,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return # same as last time - don't write # Write + ts = strftime('%Y-%m-%dT%H.%M.%S', localtime(time())) filename = join( # type: ignore - config.get_str('outdir'), '{}.{}.txt'.format(ship, strftime('%Y-%m-%dT%H.%M.%S', localtime(time()))) + config.get_str('outdir'), f'{ship}.{ts}.txt' ) try: From 20772e7daff69af415d1b8567d6f98a716501d7c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 14:46:40 +0000 Subject: [PATCH 347/727] Fixed current mypy complaints. There are still *missing* type annotations. --- monitor.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/monitor.py b/monitor.py index 04912a99..0b7f110d 100644 --- a/monitor.py +++ b/monitor.py @@ -9,9 +9,9 @@ from os import SEEK_END, SEEK_SET, listdir from os.path import basename, expanduser, isdir, join from sys import platform from time import gmtime, localtime, sleep, strftime, strptime, time -from typing import TYPE_CHECKING, Any, Dict, List, MutableMapping, Optional +from typing import TYPE_CHECKING, Any, List, MutableMapping, Optional from typing import OrderedDict as OrderedDictT -from typing import Tuple, Union +from typing import Tuple if TYPE_CHECKING: import tkinter @@ -100,7 +100,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.station: Optional[str] = None self.station_marketid: Optional[int] = None self.stationtype: Optional[str] = None - self.coordinates: Optional[Tuple[int, int, int]] = None + self.coordinates: Optional[Tuple[float, float, float]] = None self.systemaddress: Optional[int] = None self.started: Optional[int] = None # Timestamp of the LoadGame event @@ -425,7 +425,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Done.') - def parse_entry(self, line: str) -> Dict: # noqa: C901, CCR001 + def parse_entry(self, line: str) -> MutableMapping[str, Any]: # noqa: C901, CCR001 """ Parse a Journal JSON line. @@ -623,7 +623,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.planet = None if 'StarPos' in entry: - self.coordinates = tuple(entry['StarPos']) + self.coordinates = tuple(entry['StarPos']) # type: ignore elif self.system != entry['StarSystem']: self.coordinates = None # Docked event doesn't include coordinates @@ -890,6 +890,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Friends'].discard(entry['Name']) return entry + except Exception as ex: logger.debug(f'Invalid journal entry:\n{line}\n', exc_info=ex) return {'event': None} @@ -931,7 +932,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return item.capitalize() - def get_entry(self) -> Union[OrderedDictT[str, Any], None]: + def get_entry(self) -> Optional[MutableMapping[str, Any]]: """ Pull the next Journal event from the event_queue. @@ -1026,7 +1027,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return False - def ship(self, timestamped=True) -> OrderedDictT: + def ship(self, timestamped=True) -> Optional[MutableMapping[str, Any]]: """ Produce a subset of data for the current ship. @@ -1043,7 +1044,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'PowerDistributor', 'Radar', 'FuelTank' ) - d = OrderedDict() + d: MutableMapping[str, Any] = OrderedDict() if timestamped: d['timestamp'] = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) From 4a1feb4d497147f9dd7a192486ee8a45fc83b618 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 15:50:38 +0000 Subject: [PATCH 348/727] Type hints should be 100% now. There's something around line 324: entry: OrderedDictT[str, Any] = OrderedDict([ producing an error with pre-commit's run of mypy --- monitor.py | 57 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/monitor.py b/monitor.py index 0b7f110d..2a5499e2 100644 --- a/monitor.py +++ b/monitor.py @@ -9,7 +9,7 @@ from os import SEEK_END, SEEK_SET, listdir from os.path import basename, expanduser, isdir, join from sys import platform from time import gmtime, localtime, sleep, strftime, strptime, time -from typing import TYPE_CHECKING, Any, List, MutableMapping, Optional +from typing import TYPE_CHECKING, Any, Dict, List, MutableMapping, Optional from typing import OrderedDict as OrderedDictT from typing import Tuple @@ -39,6 +39,8 @@ elif platform == 'win32': from ctypes.wintypes import BOOL, HWND, LPARAM, LPWSTR from watchdog.events import FileSystemEventHandler + if TYPE_CHECKING: + from watchdog.events import FileCreatedEvent from watchdog.observers import Observer EnumWindows = ctypes.windll.user32.EnumWindows @@ -68,16 +70,16 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below _RE_CATEGORY = re.compile(r'\$MICRORESOURCE_CATEGORY_(.+);') _RE_LOGFILE = re.compile(r'^Journal(Alpha|Beta)?\.[0-9]{12}\.[0-9]{2}\.log$') - def __init__(self): + def __init__(self) -> None: # TODO(A_D): A bunch of these should be switched to default values (eg '' for strings) and no longer be Optional FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog - self.root = None - self.currentdir: Optional[str] = None # The actual logdir that we're monitoring + self.root: 'tkinter.Tk' = None # type: ignore # Don't use Optional[] - mypy thinks no methods + self.currentdir: Optional[str] = None # The actual logdir that we're monitoring self.logfile: Optional[str] = None - self.observer = None - self.observed = None # a watchdog ObservedWatch, or None if polling + self.observer: Optional['Observer'] = None + self.observed = None # a watchdog ObservedWatch, or None if polling self.thread: Optional[threading.Thread] = None - self.event_queue = [] # For communicating journal entries back to main thread + self.event_queue: List = [] # For communicating journal entries back to main thread # On startup we might be: # 1) Looking at an old journal file because the game isn't running or the user has exited to the main menu. @@ -106,7 +108,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Cmdr state shared with EDSM and plugins # If you change anything here update PLUGINS.md documentation! - self.state = { + self.state: Dict = { 'Captain': None, # On a crew 'Cargo': defaultdict(int), 'Credits': None, @@ -134,10 +136,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Route': None, # Last plotted route from Route.json file } - def start(self, root: 'tkinter.Tk'): # noqa: CCR001 - """Start journal monitoring.""" + def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 + """ + Start journal monitoring. + + :param root: The parent Tk window. + :return: bool - False if we couldn't access/find latest Journal file. + """ logger.debug('Begin...') - self.root = root + self.root = root # type: ignore journal_dir = config.get_str('journaldir') if journal_dir == '' or journal_dir is None: @@ -193,7 +200,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if not self.observed and not polling: logger.debug('Not observed and not polling, setting observed...') - self.observed = self.observer.schedule(self, self.currentdir) + self.observed = self.observer.schedule(self, self.currentdir) # type: ignore logger.debug('Done') logger.info(f'{"Polling" if polling else "Monitoring"} Journal Folder: "{self.currentdir}"') @@ -209,7 +216,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Done.') return True - def stop(self): + def stop(self) -> None: """Stop journal monitoring.""" logger.debug('Stopping monitoring Journal') @@ -238,7 +245,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Done.') - def close(self): + def close(self) -> None: """Close journal monitoring.""" logger.debug('Calling self.stop()...') self.stop() @@ -257,21 +264,21 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Done.') - def running(self): + def running(self) -> bool: """ Determine if Journal watching is active. :return: bool """ - return self.thread and self.thread.is_alive() + return bool(self.thread and self.thread.is_alive()) - def on_created(self, event): + def on_created(self, event: FileCreatedEvent) -> None: """Watchdog callback when, e.g. client (re)started.""" if not event.is_directory and self._RE_LOGFILE.search(basename(event.src_path)): self.logfile = event.src_path - def worker(self): # noqa: C901, CCR001 + def worker(self) -> None: # noqa: C901, CCR001 """ Watch latest Journal file. @@ -300,12 +307,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.parse_entry(line) # Some events are of interest even in the past except Exception as ex: - logger.debug(f'Invalid journal entry:\n{line}\n', exc_info=ex) + logger.debug(f'Invalid journal entry:\n{line!r}\n', exc_info=ex) log_pos = loghandle.tell() else: - loghandle = None + loghandle = None # type: ignore logger.debug('Now at end of latest file.') @@ -425,7 +432,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Done.') - def parse_entry(self, line: str) -> MutableMapping[str, Any]: # noqa: C901, CCR001 + def parse_entry(self, line: bytes) -> MutableMapping[str, Any]: # noqa: C901, CCR001 """ Parse a Journal JSON line. @@ -892,10 +899,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return entry except Exception as ex: - logger.debug(f'Invalid journal entry:\n{line}\n', exc_info=ex) + logger.debug(f'Invalid journal entry:\n{line!r}\n', exc_info=ex) return {'event': None} - def canonicalise(self, item: Optional[str]): + def canonicalise(self, item: Optional[str]) -> str: """ Produce canonical name for a ship module. @@ -918,7 +925,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return item - def category(self, item: str): + def category(self, item: str) -> str: """ Determine the category of an item. @@ -1005,7 +1012,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return True elif platform == 'win32': - def WindowTitle(h): # noqa: N802 + def WindowTitle(h): # noqa: N802 # type: ignore if h: length = GetWindowTextLength(h) + 1 buf = ctypes.create_unicode_buffer(length) From 3997dbab3a0da7a3df9fbcd78a20904ba0eaf2ce Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 16:01:15 +0000 Subject: [PATCH 349/727] update pre-commit --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c325e4b..b161b359 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: '' + rev: 'v3.4.0' hooks: - id: check-merge-conflict - id: debug-statements @@ -30,7 +30,7 @@ repos: types: [ python ] - repo: https://github.com/pre-commit/pygrep-hooks - rev: '' + rev: 'v1.8.0' hooks: - id: python-no-eval - id: python-no-log-warn @@ -40,7 +40,7 @@ repos: # mypy - static type checking # mypy --follow-imports skip - repo: https://github.com/pre-commit/mirrors-mypy - rev: '' + rev: 'v0.812' hooks: - id: mypy args: [ "--follow-imports", "skip", "--ignore-missing-imports", "--scripts-are-modules" ] @@ -59,7 +59,7 @@ repos: # safety.exe check -r requirements.txt - repo: https://github.com/Lucas-C/pre-commit-hooks-safety - rev: '' + rev: 'v1.2.1' hooks: - id: python-safety-dependencies-check entry: safety From eef4acd30bcf4699bdbf9d8c4e01c76ce4fd332f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 16:07:06 +0000 Subject: [PATCH 350/727] Document `line` param to `parse_entry()` --- monitor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monitor.py b/monitor.py index 2a5499e2..61f2d3d2 100644 --- a/monitor.py +++ b/monitor.py @@ -439,6 +439,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below This augments some events, sets internal state in reaction to many and loads some extra files, e.g. Cargo.json, as necessary. + :param line: bytes - The entry being parsed. Yes, this is bytes, not str. + We rely on json.loads() dealing with this properly. :return: Dict of the processed event. """ # TODO(A_D): a bunch of these can be simplified to use if itertools.product and filters From 84afe6821acd590eea2d75f6fcc42e76906837bc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 17:48:51 +0000 Subject: [PATCH 351/727] import of watchdog.events.FileCreatedEvent needed even when not type checking PyCharm debugging bailed out due to the lack. --- monitor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index 61f2d3d2..25c3b7de 100644 --- a/monitor.py +++ b/monitor.py @@ -38,9 +38,7 @@ elif platform == 'win32': import ctypes from ctypes.wintypes import BOOL, HWND, LPARAM, LPWSTR - from watchdog.events import FileSystemEventHandler - if TYPE_CHECKING: - from watchdog.events import FileCreatedEvent + from watchdog.events import FileCreatedEvent, FileSystemEventHandler from watchdog.observers import Observer EnumWindows = ctypes.windll.user32.EnumWindows From ba91aa47339b210026fa432f3d929e7150cf9984 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 10 Mar 2021 17:49:42 +0000 Subject: [PATCH 352/727] Two final s/getint/get_int/g instances. Tested with firing up under debugger, switching to transparent theme, repeatedly mousing in and out, switching back to Dark theme. --- EDMarketConnector.py | 2 +- prefs.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 0ba68077..a81932c9 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1536,7 +1536,7 @@ sys.path: {sys.path}''' config.set('plugins_not_py3_last', int(time())) # UI Transparency - ui_transparency = config.getint('ui_transparency') + ui_transparency = config.get_int('ui_transparency') if ui_transparency == 0: ui_transparency = 100 diff --git a/prefs.py b/prefs.py index 8f8a2ece..99d441ab 100644 --- a/prefs.py +++ b/prefs.py @@ -749,7 +749,7 @@ class PreferencesDialog(tk.Toplevel): padx=self.PADX, pady=self.PADY*2, sticky=tk.W, row=cur_row ) self.transparency = tk.IntVar() - self.transparency.set(config.getint('ui_transparency') or 100) # Default to 100 for users + self.transparency.set(config.get_int('ui_transparency') or 100) # Default to 100 for users self.transparency_bar = tk.Scale( appearance_frame, variable=self.transparency, # type: ignore # Its accepted as an intvar From 45e14ee86c29cace999f51328ffc999e792b442a Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 11 Mar 2021 15:49:56 +0200 Subject: [PATCH 353/727] added stacktrace to debug log --- config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config.py b/config.py index 51edad4d..40a4999c 100644 --- a/config.py +++ b/config.py @@ -15,6 +15,7 @@ import os import pathlib import sys import warnings +import traceback from abc import abstractmethod from sys import platform from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Type, TypeVar, Union @@ -192,6 +193,8 @@ class AbstractConfig(abc.ABC): :return: the data or the default """ warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type')) + logger.debug('Attempt to use Deprecated get() method\n' + ''.join(traceback.format_stack())) + if (l := self._suppress_call(self.get_list, ValueError, key, None)) is not None: return l @@ -253,6 +256,8 @@ class AbstractConfig(abc.ABC): :raises OSError: on windows, if a registry error occurs. """ warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead')) + logger.debug('Attempt to use Deprecated get_int() method\n' + ''.join(traceback.format_stack())) + return self.get_int(key, default=default) @abstractmethod From 7707c26d189de65449c1d7e8c606552715519ff2 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 11 Mar 2021 15:53:44 +0200 Subject: [PATCH 354/727] tiny mypy cleanup --- config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index 40a4999c..39f6adc7 100644 --- a/config.py +++ b/config.py @@ -14,8 +14,8 @@ import logging import os import pathlib import sys -import warnings import traceback +import warnings from abc import abstractmethod from sys import platform from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Type, TypeVar, Union @@ -339,7 +339,7 @@ class WinConfig(AbstractConfig): journal_dir_str = known_folder_path(FOLDERID_SavedGames) journaldir = pathlib.Path(journal_dir_str) if journal_dir_str is not None else None - self.default_journal_dir_path = None + self.default_journal_dir_path = None # type: ignore if journaldir is not None: self.default_journal_dir_path = journaldir / 'Frontier Developments' / 'Elite Dangerous' @@ -704,7 +704,7 @@ class LinuxConfig(AbstractConfig): self.respath_path = pathlib.Path(__file__).parent self.internal_plugin_dir_path = self.respath_path / 'plugins' - self.default_journal_dir_path = None + self.default_journal_dir_path = None # type: ignore self.identifier = f'uk.org.marginal.{appname.lower()}' # TODO: Unused? config_home = pathlib.Path(os.getenv('XDG_CONFIG_HOME', default='~/.config')).expanduser() From f5575e5b8e6cb076e3f54df79f56f6e4c2929c2f Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 11 Mar 2021 16:14:19 +0200 Subject: [PATCH 355/727] Fixed broken suppress_call calls --- config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 39f6adc7..7458c207 100644 --- a/config.py +++ b/config.py @@ -195,16 +195,16 @@ class AbstractConfig(abc.ABC): warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type')) logger.debug('Attempt to use Deprecated get() method\n' + ''.join(traceback.format_stack())) - if (l := self._suppress_call(self.get_list, ValueError, key, None)) is not None: + if (l := self._suppress_call(self.get_list, ValueError, key, default=None)) is not None: return l - elif (s := self._suppress_call(self.get_str, ValueError, key, None)) is not None: + elif (s := self._suppress_call(self.get_str, ValueError, key, default=None)) is not None: return s - elif (b := self._suppress_call(self.get_bool, ValueError, key, None)) is not None: + elif (b := self._suppress_call(self.get_bool, ValueError, key, default=None)) is not None: return b - elif (i := self._suppress_call(self.get_int, ValueError, key, None)) is not None: + elif (i := self._suppress_call(self.get_int, ValueError, key, default=None)) is not None: return i return default # type: ignore From ee4451560a74e3f451684f4cc16ddda7f1684c26 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 11 Mar 2021 16:30:27 +0200 Subject: [PATCH 356/727] added regression test --- tests/test_config.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index 8fa179c5..4e484a2f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -108,10 +108,10 @@ class TestNewConfig: """Save a list and then ask for it back.""" name = f'list_test_{ hash("".join(lst)) }' config.set(name, lst) - + config.save() self.__update_linuxconfig() - + assert lst == config.get_list(name) config.delete(name) @@ -126,6 +126,18 @@ class TestNewConfig: assert b == config.get_bool(name) config.delete(name) + def test_get_no_error(self) -> None: + """Regression test to ensure that get() doesn't throw a TypeError.""" + name = 'test-get' + config.set(name, '1337') + config.save() + self.__update_linuxconfig() + with pytest.deprecated_call(): + res = config.get(name) + + assert res == '1337' + config.delete(name) + class TestOldNewConfig: """Tests going through the old config and out the new config.""" From e4c070314294d127c71394a722b24941bdfd6caf Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 11 Mar 2021 21:07:02 +0200 Subject: [PATCH 357/727] fixed log wording --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 7458c207..b46f667c 100644 --- a/config.py +++ b/config.py @@ -256,7 +256,7 @@ class AbstractConfig(abc.ABC): :raises OSError: on windows, if a registry error occurs. """ warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead')) - logger.debug('Attempt to use Deprecated get_int() method\n' + ''.join(traceback.format_stack())) + logger.debug('Attempt to use Deprecated getint() method\n' + ''.join(traceback.format_stack())) return self.get_int(key, default=default) From 60dd93a3deb08b198713675d066e968bb694b29e Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 11 Mar 2021 21:08:08 +0200 Subject: [PATCH 358/727] Fixed invalid type annotation --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 25c3b7de..18a751b7 100644 --- a/monitor.py +++ b/monitor.py @@ -270,7 +270,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below """ return bool(self.thread and self.thread.is_alive()) - def on_created(self, event: FileCreatedEvent) -> None: + def on_created(self, event: 'FileCreatedEvent') -> None: """Watchdog callback when, e.g. client (re)started.""" if not event.is_directory and self._RE_LOGFILE.search(basename(event.src_path)): From e77772765807e775fb5d2935858e2cf36bc061b2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 14:32:46 +0000 Subject: [PATCH 359/727] 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. # Conflicts: # EDMarketConnector.py --- EDMarketConnector.py | 15 ++++++--------- journal_lock.py | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index a81932c9..e4aa7c30 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -39,7 +39,7 @@ from config import appversion, appversion_nobuild, config, copyright # isort: on from EDMCLogging import edmclogger, logger, logging -from journal_lock import JournalLock +from journal_lock import JournalLock, JournalLockResult if __name__ == '__main__': # noqa: C901 # Command-line arguments @@ -84,18 +84,15 @@ if __name__ == '__main__': # noqa: C901 if args.force_localserver_for_auth: config.set_auth_force_localserver() - def no_other_instance_running() -> bool: # noqa: CCR001 - """ - Ensure only one copy of the app is running for the configured journal directory. - - :returns: True if we are the single instance, else False. - """ + def handle_edmc_callback_or_foregrounding(): # noqa: CCR001 + """Handle any edmc:// auth callback, else foreground existing window.""" logger.trace('Begin...') if platform == 'win32': - if not locked: - # Need to do the check for this being an edmc:// auth callback + # If *this* instance hasn't locked, then another already has and we + # now need to do the edmc:// checks for auth callback + if locked != JournalLockResult.LOCKED: import ctypes from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR diff --git a/journal_lock.py b/journal_lock.py index 48c3d572..1217205d 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -2,6 +2,7 @@ import pathlib import tkinter as tk +from enum import Enum from os import getpid as os_getpid from sys import platform from tkinter import ttk @@ -17,6 +18,15 @@ if TYPE_CHECKING: return x +class JournalLockResult(Enum): + """Enumeration of possible outcomes of trying to lock the Journal Directory.""" + + LOCKED = 1 + JOURNALDIR_NOTEXIST = 2 + JOURNALDIR_READONLY = 3 + ALREADY_LOCKED = 4 + + class JournalLock: """Handle locking of journal directory.""" @@ -28,11 +38,11 @@ class JournalLock: # We never test truthiness of this, so let it be defined when first assigned. Avoids type hint issues. # self.journal_dir_lockfile: Optional[IO] = None - def obtain_lock(self) -> bool: + def obtain_lock(self) -> JournalLockResult: """ Attempt to obtain a lock on the journal directory. - :return: bool - True if we successfully obtained the lock + :return: LockResult - See the class Enum definition """ self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' logger.trace(f'journal_dir_lockfile_name = {self.journal_dir_lockfile_name!r}') @@ -44,7 +54,7 @@ class JournalLock: except Exception as e: # For remote FS this could be any of a wide range of exceptions logger.warning(f"Couldn't open \"{self.journal_dir_lockfile_name}\" for \"w+\"" f" Aborting duplicate process checks: {e!r}") - return False + return JournalLockResult.JOURNALDIR_READONLY if platform == 'win32': logger.trace('win32, using msvcrt') @@ -57,7 +67,7 @@ class JournalLock: except Exception as e: logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\"" f", assuming another process running: {e!r}") - return False + return JournalLockResult.ALREADY_LOCKED else: logger.trace('NOT win32, using fcntl') @@ -67,7 +77,7 @@ class JournalLock: except ImportError: logger.warning("Not on win32 and we have no fcntl, can't use a file lock!" "Allowing multiple instances!") - return True # Lie about being locked + return JournalLockResult.LOCKED try: fcntl.flock(self.journal_dir_lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) @@ -75,13 +85,13 @@ class JournalLock: except Exception as e: logger.info(f"Exception: Couldn't lock journal directory \"{self.journal_dir}\", " f"assuming another process running: {e!r}") - return False + return JournalLockResult.ALREADY_LOCKED self.journal_dir_lockfile.write(f"Path: {self.journal_dir}\nPID: {os_getpid()}\n") self.journal_dir_lockfile.flush() logger.trace('Done') - return True + return JournalLockResult.LOCKED def release_lock(self) -> bool: """ From 0f83e5b035eeb020e1db57676d8635c8256ea018 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 13 Mar 2021 12:53:02 +0000 Subject: [PATCH 360/727] macos config: Respect `suppress` argument to config.delete() Else the blind deletion of the shipyard key at startup causes a fatal exception. --- config.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index b46f667c..c33ec421 100644 --- a/config.py +++ b/config.py @@ -670,7 +670,12 @@ class MacConfig(AbstractConfig): :param key: the key to delete """ - del self._settings[key] + try: + del self._settings[key] + + except Exception: + if suppress: + pass def save(self) -> None: """Save the configuration.""" From 1c269e9f4b35d2e7becab0b3e5d535fe9765ac5c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 13 Mar 2021 15:52:41 +0000 Subject: [PATCH 361/727] Change darwin __raw_get() check for list to check it's not the OTHERS On darwin this comes back with the type `__NSCFArray`, which I can't find the definition of (in order to test against it). So instead let's check that `res` is not-None, and not one of `str` or `int`, because then it should be (meant to be) `list`. Yes, this is weird given the pre-rewrite code is: ```python def get(self, key: str) -> Union[None, list, str]: """Look up a string configuration value.""" val = self.settings.get(key) if val is None: return None elif isinstance(val, str): return str(val) elif isinstance(val, list): return list(val) # make writeable else: return None ``` But maybe something changed since 3.43 was tested and built. --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index c33ec421..50b0a41b 100644 --- a/config.py +++ b/config.py @@ -581,7 +581,7 @@ class MacConfig(AbstractConfig): def __raw_get(self, key: str) -> Union[None, list, str, int]: res = self._settings.get(key) - if isinstance(res, list): + if res and not isinstance(res, str) and not isinstance(res, int): return list(res) return res From 6a4ab10cd4002d6c4b7d3a3862d041bcda86b6fa Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 13 Mar 2021 15:58:29 +0000 Subject: [PATCH 362/727] Add comment about the __NSCFArray issue --- config.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config.py b/config.py index 50b0a41b..4db4e127 100644 --- a/config.py +++ b/config.py @@ -581,6 +581,12 @@ class MacConfig(AbstractConfig): def __raw_get(self, key: str) -> Union[None, list, str, int]: res = self._settings.get(key) + # On MacOS Catalina, with python.org python 3.9.2 any 'list' + # has type __NSCFArray so a simple `isinstance(res, list)` is + # False. So, check it's not-None, and not the other types. + # + # If we can find where to import the definition of NSCFArray + # then we could possibly test against that. if res and not isinstance(res, str) and not isinstance(res, int): return list(res) From 87c88b80ea27b1d8dd211fb0cb7170dcf4f021b2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 13 Mar 2021 16:51:15 +0000 Subject: [PATCH 363/727] Slightly more paranoia in that NSCFArray check --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 4db4e127..3c1e9dbb 100644 --- a/config.py +++ b/config.py @@ -587,7 +587,7 @@ class MacConfig(AbstractConfig): # # If we can find where to import the definition of NSCFArray # then we could possibly test against that. - if res and not isinstance(res, str) and not isinstance(res, int): + if res is not None and not isinstance(res, str) and not isinstance(res, int): return list(res) return res From 34876f28a28eca06c7f7f700f4002f90df42885a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Mar 2021 07:16:40 +0000 Subject: [PATCH 364/727] Bump flake8 from 3.8.4 to 3.9.0 Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.8.4 to 3.9.0. - [Release notes](https://gitlab.com/pycqa/flake8/tags) - [Commits](https://gitlab.com/pycqa/flake8/compare/3.8.4...3.9.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6f6e72ab..70e23ee7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ # Static analysis tools -flake8==3.8.4 +flake8==3.9.0 flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.3.1 From 831981f383309895d5156049ce61942ab36a3c48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Mar 2021 07:16:46 +0000 Subject: [PATCH 365/727] Bump py2exe from 0.10.2.1 to 0.10.3.0 Bumps [py2exe](https://github.com/py2exe/py2exe) from 0.10.2.1 to 0.10.3.0. - [Release notes](https://github.com/py2exe/py2exe/releases) - [Changelog](https://github.com/py2exe/py2exe/blob/master/ChangeLog) - [Commits](https://github.com/py2exe/py2exe/compare/v0.10.2.1...v0.10.3.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 70e23ee7..409ca63a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -23,7 +23,7 @@ grip==4.5.2 # Packaging # We only need py2exe on windows. -py2exe==0.10.2.1; sys_platform == 'win32' +py2exe==0.10.3.0; sys_platform == 'win32' # Testing pytest==6.2.2 From 74afcb085af16b12a1616e98c956bb157d0fc069 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 15 Mar 2021 11:20:46 +0000 Subject: [PATCH 366/727] JournalLock: Catch when journal_dir is None * If it's None then set journal_dir_path to None as well. Setting '' or nothing results in '.' (CWD), which could cause other issues. * As we do this in three places, it's in a helper function. * New JournalLockResult.JOURNALDIR_IS_NONE to signal this. * Fix checking of return from obtain_lock() to specifically reference JournalLockResult.ALREADY_LOCKED. --- journal_lock.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/journal_lock.py b/journal_lock.py index 1217205d..a5f72187 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -25,6 +25,7 @@ class JournalLockResult(Enum): JOURNALDIR_NOTEXIST = 2 JOURNALDIR_READONLY = 3 ALREADY_LOCKED = 4 + JOURNALDIR_IS_NONE = 5 class JournalLock: @@ -33,17 +34,33 @@ class JournalLock: def __init__(self) -> None: """Initialise where the journal directory and lock file are.""" self.journal_dir: str = config.get_str('journaldir') or config.default_journal_dir - self.journal_dir_path = pathlib.Path(self.journal_dir) + self.journal_dir_path: Optional[pathlib.Path] = None + self.set_path_from_journaldir() self.journal_dir_lockfile_name: Optional[pathlib.Path] = None # We never test truthiness of this, so let it be defined when first assigned. Avoids type hint issues. # self.journal_dir_lockfile: Optional[IO] = None + def set_path_from_journaldir(self): + """Set self.journal_dir_path from seld.journal_dir.""" + if self.journal_dir is None: + self.journal_dir_path = None + + else: + try: + self.journal_dir_path = pathlib.Path(self.journal_dir) + + except Exception: + logger.exception("Couldn't make pathlib.Path from journal_dir", exc_info=True) + def obtain_lock(self) -> JournalLockResult: """ Attempt to obtain a lock on the journal directory. :return: LockResult - See the class Enum definition """ + if self.journal_dir_path is None: + return JournalLockResult.JOURNALDIR_IS_NONE + self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' logger.trace(f'journal_dir_lockfile_name = {self.journal_dir_lockfile_name!r}') try: @@ -97,7 +114,7 @@ class JournalLock: """ Release lock on journal directory. - :return: bool - Success of unlocking operation. + :return: bool - Whether we're now unlocked. """ unlocked = False if platform == 'win32': @@ -216,8 +233,9 @@ class JournalLock: self.release_lock() self.journal_dir = current_journaldir - self.journal_dir_path = pathlib.Path(self.journal_dir) - if not self.obtain_lock(): + self.set_path_from_journaldir() + + if self.obtain_lock() == JournalLockResult.ALREADY_LOCKED: # Pop-up message asking for Retry or Ignore self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) @@ -235,7 +253,7 @@ class JournalLock: current_journaldir = config.get_str('journaldir') or config.default_journal_dir self.journal_dir = current_journaldir - self.journal_dir_path = pathlib.Path(self.journal_dir) - if not self.obtain_lock(): + self.set_path_from_journaldir() + if self.obtain_lock() == JournalLockResult.ALREADY_LOCKED: # Pop-up message asking for Retry or Ignore self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) From baa86b4fbf3f23dcb72558490d8117e37f930fb8 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 15 Mar 2021 12:07:39 +0000 Subject: [PATCH 367/727] Add extra logging for Frontier Auth, especially via edmc:// --- protocol.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/protocol.py b/protocol.py index cca7c225..cab216db 100644 --- a/protocol.py +++ b/protocol.py @@ -48,6 +48,7 @@ class GenericProtocolHandler: self.lastpayload = url if not config.shutting_down: + logger.debug('event_generate("<>"') self.master.event_generate('<>', when="tail") @@ -289,6 +290,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a msg = MSG() # Calls GetMessageW: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew while GetMessageW(byref(msg), None, 0, 0) != 0: + logger.trace(f'DDE message of type: {msg.message}') if msg.message == WM_DDE_EXECUTE: # GlobalLock does some sort of "please dont move this?" # https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globallock @@ -296,8 +298,10 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a GlobalUnlock(msg.lParam) # Unlocks the GlobalLock-ed object if args.lower().startswith('open("') and args.endswith('")'): + logger.trace(f'args are: {args}') url = urllib.parse.unquote(args[6:-2]).strip() if url.startswith(self.redirect): + logger.debug(f'Message starts with {self.redirect}') self.event(url) SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window From 740da49ce1b68164e0674f23edeaa00376374803 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 15 Mar 2021 12:13:28 +0000 Subject: [PATCH 368/727] Add similar extra logging for localhost handler * This also adjusts the logging in Session.auth_callback() because it can be called from either protocol. Saying 'edmc://' there is misleading. --- protocol.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protocol.py b/protocol.py index cab216db..8afba1b3 100644 --- a/protocol.py +++ b/protocol.py @@ -47,6 +47,7 @@ class GenericProtocolHandler: """Generate an auth event.""" self.lastpayload = url + logger.trace(f'Payload: {self.lastpayload}') if not config.shutting_down: logger.debug('event_generate("<>"') self.master.event_generate('<>', when="tail") @@ -374,6 +375,7 @@ else: # Linux / Run from source def parse(self) -> bool: """Parse a request.""" + logger.trace(f'Got message on path: {self.path}') url = urllib.parse.unquote(self.path) if url.startswith('/auth'): logger.debug('Request starts with /auth, sending to protocolhandler.event()') From e475ad66595cf3925dec8b09f1b43739e554a623 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 15 Mar 2021 18:53:20 +0200 Subject: [PATCH 369/727] 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. --- EDMarketConnector.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index e4aa7c30..280c2b2a 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1216,14 +1216,11 @@ class AppWindow(object): ) if f: with open(f, 'wb') as h: - h.write(json.dumps( - data, - ensure_ascii=False, - indent=2, - sort_keys=True, - separators=(',', ': ')).encode('utf-8') - ) - + h.write(json.dumps(dict(data), + ensure_ascii=False, + indent=2, + sort_keys=True, + separators=(',', ': ')).encode('utf-8')) except companion.ServerError as e: self.status['text'] = str(e) From bc7767c5ce72d64a086c1d2ac231b06caf7255a7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 15 Mar 2021 17:25:36 +0000 Subject: [PATCH 370/727] Also wrap as dict(data) in dump_capi_data() --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 280c2b2a..233c9d22 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -671,7 +671,7 @@ class AppWindow(object): timestamp = strftime('%Y-%m-%dT%H.%M.%S', localtime()) with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: - h.write(json.dumps(data, + h.write(json.dumps(dict(data), ensure_ascii=False, indent=2, sort_keys=True, From d8fb17df9fdc6b77949022176d5d3c247661c2ef Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 15 Mar 2021 17:03:39 +0000 Subject: [PATCH 371/727] plugins/eddn: Add paranoia about data in is_horizons() A damaged station has `"modules": []`, so trips over modules.values(). --- plugins/eddn.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 22f76ec6..bbcd5b35 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -805,8 +805,19 @@ MAP_STR_ANY = Mapping[str, Any] def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY) -> bool: - return ( - any(economy['name'] == 'Colony' for economy in economies.values()) or - any(module.get('sku') == HORIZ_SKU for module in modules.values()) or - any(ship.get('sku') == HORIZ_SKU for ship in ships.get('shipyard_list', {}).values()) - ) + economies_colony = False + modules_horizons = False + ship_horizons = False + + if isinstance(dict, economies): + economies_colony = any(economy['name'] == 'Colony' for economy in economies.values()) + + if isinstance(dict, modules): + modules_horizons = any(module.get('sku') == HORIZ_SKU for module in modules.values()) + + if isinstance(dict, ships): + if ships.get('shipyard_list') is not None: + ship_horizons = any(ship.get('sku') == HORIZ_SKU for ship in ships['shipyard_list'].values()) + + return economies_colony or modules_horizons or ship_horizons + From 9634c914c35919e7280f9043f072fbe548d27786 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Mar 2021 06:01:18 +0000 Subject: [PATCH 372/727] Bump autopep8 from 1.5.5 to 1.5.6 Bumps [autopep8](https://github.com/hhatto/autopep8) from 1.5.5 to 1.5.6. - [Release notes](https://github.com/hhatto/autopep8/releases) - [Commits](https://github.com/hhatto/autopep8/compare/v1.5.5...v1.5.6) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 409ca63a..c93bd441 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -16,7 +16,7 @@ pep8-naming==0.11.1 safety==1.10.3 # Code formatting tools -autopep8==1.5.5 +autopep8==1.5.6 # HTML changelogs grip==4.5.2 From 73dadca3083b18a61309db771715b2ab9333e28f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 17 Mar 2021 14:53:48 +0000 Subject: [PATCH 373/727] Add 'wheel' to requirements-dev.txt to avoid warnings --- requirements-dev.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index c93bd441..8e553887 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,7 @@ +# So that you don't get warnings like: +# Using legacy 'setup.py install' for flake8-annotations-coverage, since package 'wheel' is not installed. +wheel + # Static analysis tools flake8==3.9.0 flake8-annotations-coverage==0.0.5 From 383776882d60d283aa7c629b9416be26b9e2762b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Mar 2021 05:53:45 +0000 Subject: [PATCH 374/727] Bump flake8-comprehensions from 3.3.1 to 3.4.0 Bumps [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions) from 3.3.1 to 3.4.0. - [Release notes](https://github.com/adamchainz/flake8-comprehensions/releases) - [Changelog](https://github.com/adamchainz/flake8-comprehensions/blob/main/HISTORY.rst) - [Commits](https://github.com/adamchainz/flake8-comprehensions/compare/3.3.1...3.4.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 8e553887..7f739f17 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ wheel flake8==3.9.0 flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 -flake8-comprehensions==3.3.1 +flake8-comprehensions==3.4.0 flake8-docstrings==1.5.0 isort==5.7.0 flake8-isort==4.0.0 From cc49a535566b1a9432f98ca55bb11a18fcd8b0c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Mar 2021 08:52:53 +0000 Subject: [PATCH 375/727] Bump flake8-docstrings from 1.5.0 to 1.6.0 Bumps [flake8-docstrings](https://gitlab.com/pycqa/flake8-docstrings) from 1.5.0 to 1.6.0. - [Release notes](https://gitlab.com/pycqa/flake8-docstrings/tags) - [Changelog](https://gitlab.com/pycqa/flake8-docstrings/blob/master/HISTORY.rst) - [Commits](https://gitlab.com/pycqa/flake8-docstrings/compare/1.5.0...1.6.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7f739f17..60a727cb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,7 +7,7 @@ flake8==3.9.0 flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.4.0 -flake8-docstrings==1.5.0 +flake8-docstrings==1.6.0 isort==5.7.0 flake8-isort==4.0.0 flake8-json==21.1.0 From 7fc5144121d25af7f7fadebe576ad208728c8ac7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Mar 2021 07:21:08 +0000 Subject: [PATCH 376/727] Bump isort from 5.7.0 to 5.8.0 Bumps [isort](https://github.com/pycqa/isort) from 5.7.0 to 5.8.0. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.7.0...5.8.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 60a727cb..742f69f5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,7 +8,7 @@ flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.4.0 flake8-docstrings==1.6.0 -isort==5.7.0 +isort==5.8.0 flake8-isort==4.0.0 flake8-json==21.1.0 flake8-noqa==1.1.0 From bc33bf1b1925e700c3de35d364e8652bc8130fb8 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 15:02:27 +0000 Subject: [PATCH 377/727] Attempt to get `develop` back to code state before rebase on main. --- EDMCLogging.py | 7 ++++-- EDMarketConnector.py | 52 ++++++++++++++++++++++++++++---------------- journal_lock.py | 6 +++++ plugins/eddn.py | 18 ++++++++++++--- setup.py | 9 +++++++- 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 6d9f8d28..d4836ad6 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -325,8 +325,11 @@ class EDMCContextFilter(logging.Filter): if frame_class: # See https://en.wikipedia.org/wiki/Name_mangling#Python for how name mangling works. - if (name := frame_info.function).startswith("__") and not name.endswith("__"): - name = f'_{frame_class.__class__.__name__}{frame_info.function}' + # For more detail, see _Py_Mangle in CPython's Python/compile.c. + name = frame_info.function + class_name = frame_class.__class__.__name__.lstrip("_") + if name.startswith("__") and not name.endswith("__") and class_name: + name = f'_{class_name}{frame_info.function}' # Find __qualname__ of the caller fn = inspect.getattr_static(frame_class, name, None) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 233c9d22..de1c526a 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -73,6 +73,11 @@ if __name__ == '__main__': # noqa: C901 action='store_true' ) + parser.add_argument('edmc', + help='Callback from Frontier Auth', + nargs='*' + ) + args = parser.parse_args() if args.trace: @@ -171,9 +176,7 @@ if __name__ == '__main__': # noqa: C901 # Ref: EnumWindows(enumwindowsproc, 0) - return False # Another instance is running - - return True + return def already_running_popup(): """Create the "already running" popup.""" @@ -201,17 +204,19 @@ if __name__ == '__main__': # noqa: C901 journal_lock = JournalLock() locked = journal_lock.obtain_lock() - if journal_lock.journal_dir_lockfile: - if not no_other_instance_running(): - # There's a copy already running. + handle_edmc_callback_or_foregrounding() - logger.info("An EDMarketConnector.exe process was already running, exiting.") + if locked == JournalLockResult.ALREADY_LOCKED: + # There's a copy already running. - # To be sure the user knows, we need a popup + logger.info("An EDMarketConnector.exe process was already running, exiting.") + + # To be sure the user knows, we need a popup + if not args.edmc: already_running_popup() - # If the user closes the popup with the 'X', not the 'OK' button we'll - # reach here. - sys.exit(0) + # If the user closes the popup with the 'X', not the 'OK' button we'll + # reach here. + sys.exit(0) if getattr(sys, 'frozen', False): # Now that we're sure we're the only instance running we can truncate the logfile @@ -1238,31 +1243,40 @@ class AppWindow(object): config.set('geometry', f'+{x}+{y}') # Let the user know we're shutting down. - self.status['text'] = 'Shutting down...' + self.status['text'] = _('Shutting down...') self.w.update_idletasks() logger.info('Starting shutdown procedures...') - logger.info('Closing protocol handler...') - protocolhandler.close() + # First so it doesn't interrupt us + logger.info('Closing update checker...') + self.updater.close() + # Earlier than anything else so plugin code can't interfere *and* it + # won't still be running in a manner that might rely on something + # we'd otherwise have already stopped. + logger.info('Notifying plugins to stop...') + plug.notify_stop() + + # Handling of application hotkeys now so the user can't possible cause + # an issue via triggering one. logger.info('Unregistering hotkey manager...') hotkeymgr.unregister() + # Now the main programmatic input methods logger.info('Closing dashboard...') dashboard.close() logger.info('Closing journal monitor...') monitor.close() - logger.info('Notifying plugins to stop...') - plug.notify_stop() - - logger.info('Closing update checker...') - self.updater.close() + # Frontier auth/CAPI handling + logger.info('Closing protocol handler...') + protocolhandler.close() logger.info('Closing Frontier CAPI sessions...') companion.session.close() + # Now anything else. logger.info('Closing config...') config.close() diff --git a/journal_lock.py b/journal_lock.py index a5f72187..bfb6ee85 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -39,6 +39,7 @@ class JournalLock: self.journal_dir_lockfile_name: Optional[pathlib.Path] = None # We never test truthiness of this, so let it be defined when first assigned. Avoids type hint issues. # self.journal_dir_lockfile: Optional[IO] = None + self.locked = False def set_path_from_journaldir(self): """Set self.journal_dir_path from seld.journal_dir.""" @@ -108,6 +109,8 @@ class JournalLock: self.journal_dir_lockfile.flush() logger.trace('Done') + self.locked = True + return JournalLockResult.LOCKED def release_lock(self) -> bool: @@ -116,6 +119,9 @@ class JournalLock: :return: bool - Whether we're now unlocked. """ + if not self.locked: + return True # We weren't locked, and still aren't + unlocked = False if platform == 'win32': logger.trace('win32, using msvcrt') diff --git a/plugins/eddn.py b/plugins/eddn.py index bbcd5b35..46a893db 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -809,15 +809,27 @@ def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY modules_horizons = False ship_horizons = False - if isinstance(dict, economies): + if isinstance(economies, dict): economies_colony = any(economy['name'] == 'Colony' for economy in economies.values()) - if isinstance(dict, modules): + else: + logger.error(f'economies type is {type(economies)}') + + if isinstance(modules, dict): modules_horizons = any(module.get('sku') == HORIZ_SKU for module in modules.values()) - if isinstance(dict, ships): + else: + logger.error(f'modules type is {type(modules)}') + + if isinstance(ships, dict): if ships.get('shipyard_list') is not None: ship_horizons = any(ship.get('sku') == HORIZ_SKU for ship in ships['shipyard_list'].values()) + else: + logger.debug('No ships["shipyard_list"] - Damaged station or FC ?') + + else: + logger.error(f'ships type is {type(ships)}') + return economies_colony or modules_horizons or ship_horizons diff --git a/setup.py b/setup.py index c39c9553..51f0d1f9 100755 --- a/setup.py +++ b/setup.py @@ -177,7 +177,14 @@ elif sys.platform=='win32': 'timeout_session', 'zipfile', # Included for plugins ], - 'excludes': [ 'distutils', '_markerlib', 'optparse', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ], + 'excludes': [ + 'distutils', + '_markerlib', + 'optparse', + 'PIL', + 'pkg_resources', + 'simplejson', + 'unittest' ], } } From 732cfa119222bcda89322839f24eec9c53064094 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 15:06:24 +0000 Subject: [PATCH 378/727] journal_lock: No need for exc_info=True on logger.exception() --- journal_lock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/journal_lock.py b/journal_lock.py index bfb6ee85..f3ed4165 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -51,7 +51,7 @@ class JournalLock: self.journal_dir_path = pathlib.Path(self.journal_dir) except Exception: - logger.exception("Couldn't make pathlib.Path from journal_dir", exc_info=True) + logger.exception("Couldn't make pathlib.Path from journal_dir") def obtain_lock(self) -> JournalLockResult: """ From 8a3176c67dd3ed2ff11f30e3deab53eb29b0b497 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 15:07:33 +0000 Subject: [PATCH 379/727] setup.py: Fix win32 OPTIONS formatting --- setup.py | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index 51f0d1f9..4fb47045 100755 --- a/setup.py +++ b/setup.py @@ -164,28 +164,30 @@ if sys.platform == 'darwin': } DATA_FILES = [] -elif sys.platform=='win32': - OPTIONS = { 'py2exe': - {'dist_dir': dist_dir, - 'optimize': 2, - 'packages': [ - 'sqlite3', # Included for plugins - ], - 'includes': [ - 'dataclasses', - 'shutil', # Included for plugins - 'timeout_session', - 'zipfile', # Included for plugins - ], - 'excludes': [ - 'distutils', - '_markerlib', - 'optparse', - 'PIL', - 'pkg_resources', - 'simplejson', - 'unittest' ], - } +elif sys.platform == 'win32': + OPTIONS = { + 'py2exe': { + 'dist_dir': dist_dir, + 'optimize': 2, + 'packages': [ + 'sqlite3', # Included for plugins + ], + 'includes': [ + 'dataclasses', + 'shutil', # Included for plugins + 'timeout_session', + 'zipfile', # Included for plugins + ], + 'excludes': [ + 'distutils', + '_markerlib', + 'optparse', + 'PIL', + 'pkg_resources', + 'simplejson', + 'unittest' + ], + } } DATA_FILES = [ From c0bf09d974fed290e45467b75b7db186888ddaa4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 15:09:55 +0000 Subject: [PATCH 380/727] setup.py: Fix whitespace before comments --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 4fb47045..703f2d96 100755 --- a/setup.py +++ b/setup.py @@ -174,9 +174,9 @@ elif sys.platform == 'win32': ], 'includes': [ 'dataclasses', - 'shutil', # Included for plugins + 'shutil', # Included for plugins 'timeout_session', - 'zipfile', # Included for plugins + 'zipfile', # Included for plugins ], 'excludes': [ 'distutils', From a40091c36cbd63f142c69d916626c1f71fc477ff Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 15:36:33 +0000 Subject: [PATCH 381/727] Add .python-version file At the very least `pyenv` uses this as a signal for the version of Python that should be used. See: --- .python-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 00000000..2009c7df --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.9.2 From bbb99eff2c32a2b74584304c72822f1062f8dbdc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 15:48:26 +0000 Subject: [PATCH 382/727] Releasing.md: Update .python-version as needed. --- docs/Releasing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/Releasing.md b/docs/Releasing.md index 3f5419b5..d904e731 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -361,6 +361,8 @@ If you are making a pre-release then: When changing the Python version (Major.Minor.Patch) used: +1. Change the contents of `.python-version` so that pyenv notices. + 1. Any version change: 1. `.github/workflows/windows-build.yml` needs updating to have the GitHub From 99cbbf1cf88ffb3db7bc259c6dbd412d1adbd8d4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 22 Mar 2021 16:04:02 +0000 Subject: [PATCH 383/727] Releasing.md: .pre-commit-config.yaml may need python version updating also. --- docs/Releasing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/Releasing.md b/docs/Releasing.md index d904e731..fcfc89ad 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -373,3 +373,5 @@ When changing the Python version (Major.Minor.Patch) used: 1. `setup.py` will need its version check updating. 1. `EDMarketConnector.wxs` will need updating to reference the correct pythonXX.dll file. + 1. `.pre-commit-config.yaml` will need the `default_language_version` + section updated to the appropriate version. From b7c20facdd151dc256c4824152435c6d4cc0c399 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 23 Mar 2021 14:29:52 +0200 Subject: [PATCH 384/727] Fix spurious modules or ships was None Nothing other than /shipyard actually returns the modules and ships data, so checking for it anywhere other than that automatically is just asking for extra log noise and nothing else. --- companion.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/companion.py b/companion.py index 114ea599..eec2e242 100644 --- a/companion.py +++ b/companion.py @@ -126,7 +126,7 @@ ship_map = { class CAPIData(UserDict): """CAPI Response.""" - def __init__(self, data: Union[str, Dict[str, Any], 'CAPIData', None] = None) -> None: + def __init__(self, data: Union[str, Dict[str, Any], 'CAPIData', None] = None, source_endpoint: str = None) -> None: if data is None: super().__init__() elif isinstance(data, str): @@ -136,8 +136,14 @@ class CAPIData(UserDict): self.original_data = self.data.copy() # Just in case - # Only the /profile end point has star port, and thus ships/modules. - if self.data.get('lastStarport'): + self.source_endpoint = source_endpoint + + if source_endpoint is None: + return + + if source_endpoint == URL_SHIPYARD and self.data.get('lastStarport'): + # All the other endpoints may or may not have a lastStarport, but definitely wont have valid data + # for this check, which means it'll just make noise for no reason while we're working on other things self.check_modules_ships() def check_modules_ships(self) -> None: @@ -558,7 +564,7 @@ class Session(object): try: r.raise_for_status() # Typically 403 "Forbidden" on token expiry - data = CAPIData(r.json()) # May also fail here if token expired since response is empty + data = CAPIData(r.json(), endpoint) # May also fail here if token expired since response is empty except (requests.HTTPError, ValueError) as e: logger.exception('Frontier CAPI Auth: GET ') @@ -628,6 +634,8 @@ class Session(object): else: data['lastStarport'].update(shipdata) + data.check_modules_ships() + return data def close(self) -> None: From 557e88bc444f8a1b150b7957fa4cbd17f5bd44a9 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 23 Mar 2021 15:39:50 +0200 Subject: [PATCH 385/727] removed extra check --- companion.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/companion.py b/companion.py index eec2e242..beb0b69e 100644 --- a/companion.py +++ b/companion.py @@ -634,8 +634,6 @@ class Session(object): else: data['lastStarport'].update(shipdata) - data.check_modules_ships() - return data def close(self) -> None: From 5a38537294ad8e9c10bad8647e59f69d0e5c4334 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 10:34:32 +0000 Subject: [PATCH 386/727] docs: General update for `main` now using Python 3.9 & misc * Extend EDCD copyright into 2021 here as well. * Recommend *against* any attempt at making plugins also work with Python 2.7. * setup.py no longer writes appcast files. Mention edmarketconnector.xml enclosure instead for the url= bit. * DRY about location of log files, just point to appropriate wiki link. --- PLUGINS.md | 17 +++++++---------- README.md | 15 ++++----------- docs/Releasing.md | 25 +++++++++++++++++++------ 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 71c0f6a6..9ccd0df6 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -700,8 +700,8 @@ Disabled and enabled plugins are listed on the "Plugins" Settings tab ## Migration from Python 2.7 Starting with pre-release 3.5 EDMC used Python 3.7. The first full -release under Python 3.7 was 4.0.0.0. The 4.1.x series was the last to use -Python 3.7, with releases moving on to latest Python 3.8.x after that. +release under Python 3.7 was 4.0.0.0. The 4.2.x series was the last to use +Python 3.7, with releases moving on to the latest Python 3.9.x after that. This is a brief outline of the steps required to migrate a plugin from earlier versions of EDMC: @@ -717,14 +717,11 @@ versions of EDMC: the correct number of arguments. Older versions of this app were tolerant of missing arguments in these function declarations. -- Port the code to Python 3.7 or 3.8 as appropriate. The +- Port the code to Python 3.9+. The [2to3](https://docs.python.org/3/library/2to3.html) tool can automate much of this work. -Depending on the complexity of the plugin it may be feasible to make it -compatible with both EDMC 3.4 + Python 2.7 and EDMC 3.5 + Python 3.7/3.8. - -You might find [compatible idioms](https://python-future.org/compatible_idioms.html), -a guide on writing Python 2/3 compatible code, useful. There's also [an - example of changes required for a simple plugin](https://github.com/Marginal/HabZone/commit/3c41cd41d5ad81ef36aab40e967e3baf77b4bd06) -. +We advise *against* making any attempt to have a plugin's code work under +both Python 2.7 and 3.x. We no longer maintain the Python 2.7-based +versions of this application and you shouldn't support use of them with +your plugin. diff --git a/README.md b/README.md index fe5c5371..1d297395 100644 --- a/README.md +++ b/README.md @@ -42,16 +42,9 @@ Please see the [Troubleshooting](https://github.com/EDCD/EDMarketConnector/wiki/ Reporting a problem --- Please report a problem as a new GitHub [issue](https://github.com/EDCD/EDMarketConnector/issues/new?assignees=&labels=bug%2C+unconfirmed&template=bug_report.md&title=). -Please wait for the error to occur and zip up and attach this app's log file to the new issue: - -Mac: - -* `$TMPDIR/EDMarketConnector.log` - -Windows: - -* `%TMP%\EDMarketConnector.log` - +See [Reporting a problem](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#reporting-a-problem) +for further guidance, including how to find the necessary log files to +attach to the report. Packaging for distribution -------- @@ -74,6 +67,6 @@ Please see the [Acknowledgements](https://github.com/EDCD/EDMarketConnector/wiki License ------- -Copyright © 2015-2019 Jonathan Harris, 2020 EDCD +Copyright © 2015-2019 Jonathan Harris, 2020-2021 EDCD Licensed under the [GNU Public License (GPL)](http://www.gnu.org/licenses/gpl-2.0.html) version 2 or later. diff --git a/docs/Releasing.md b/docs/Releasing.md index fcfc89ad..4e8bda75 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -31,10 +31,11 @@ You will need several pieces of software installed, or the files from their auto-select some others). NB: If you have need to uninstall this it's "Windows Software Development Kit - Windows 10.0.19041.1" in "Apps & Features", *not* "Windows SDK AddOn". -1. [Python](https://python.org): 32-bit version of Python 3.8 for Windows. - [v3.8.6](https://www.python.org/downloads/release/python-386/) is the most +1. [Python](https://python.org): 32-bit version of Python 3.9 for Windows. + [v3.9.2](https://www.python.org/downloads/release/python-392/) is the most recently tested version. You need the `Windows x86 executable installer` - file, for the 32-bit version. + file, for the 32-bit version. Double-check the version against the + `.python.version` file, as it should always contain the intended version. 1. [py2exe](https://github.com/albertosottile/py2exe) - Now available via PyPi, so will be picked up with the `pip install` below. Latest tested as per `requirements-dev.txt`. @@ -92,9 +93,6 @@ that. appears in the EXE properties, and is also used as the location of WinSparkle registry entries on Windows. -1. Location of release files. To change this edit `setup.py`. Look for the -`appcast.write()` statement and change the `url="...` line. - 1. Application names, version and URL of the file with latest release information. These are all in the `config.py` file. See the `from config import ...` lines in setup.py. @@ -112,6 +110,21 @@ that. URL doesn't change over application versions) version of the appcast_win_.xml file. The original upstream value is `https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml`. + +1. Location of release files. This needs to be cited correctly in the + `edmarketconnector.xml` file, which is what the application queries to + see if there is a newer version. + Look for the `url="...` line in the ` + ## Adding a new file From bfb7780efc2a0bc7c29cbb9f04bcd83a89dc0fa7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 13:45:35 +0000 Subject: [PATCH 387/727] Version to 4.2.0-beta1 to distinguish Python 3.8 builds * I don't want to be checking something against 4.1.x releases when my last build was with Python 3.8. # Conflicts: # config.py --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 3c1e9dbb..b9bcb652 100644 --- a/config.py +++ b/config.py @@ -29,7 +29,7 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '5.0.0-beta1' # -rc1+a872b5f' +appversion = '4.2.0-beta1' #-rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' From c43343742a753939d8706a62dc2308d8aca012f2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 10:50:41 +0000 Subject: [PATCH 388/727] tests: Move the config.py related files into tests/config.py/ In general I think this will keep things neater: 1. Create a directory inside tests/ named after the file the tests are for. 2. Put all files for that test inside this new directory. --- tests/{ => config.py}/_old_config.py | 0 tests/{ => config.py}/test_config.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/{ => config.py}/_old_config.py (100%) rename tests/{ => config.py}/test_config.py (100%) diff --git a/tests/_old_config.py b/tests/config.py/_old_config.py similarity index 100% rename from tests/_old_config.py rename to tests/config.py/_old_config.py diff --git a/tests/test_config.py b/tests/config.py/test_config.py similarity index 100% rename from tests/test_config.py rename to tests/config.py/test_config.py From f53dcd92e5e8c4b9abaf0198640af5a750e563b9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 10:59:37 +0000 Subject: [PATCH 389/727] Fix small typo in JournalLock.set_path_from_journaldir() docstring --- journal_lock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/journal_lock.py b/journal_lock.py index f3ed4165..66de8491 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -42,7 +42,7 @@ class JournalLock: self.locked = False def set_path_from_journaldir(self): - """Set self.journal_dir_path from seld.journal_dir.""" + """Set self.journal_dir_path from self.journal_dir.""" if self.journal_dir is None: self.journal_dir_path = None From 8612e772cf21d3e270f492c7fc65b9de0bd0981a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 11:58:02 +0000 Subject: [PATCH 390/727] tests/journal_lock.py: Initial framework. No actual test per se yet, but this runs with `pytest -k 'journal_lock'` --- tests/journal_lock.py/test_journal_lock.py | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/journal_lock.py/test_journal_lock.py diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py new file mode 100644 index 00000000..6f5d7d38 --- /dev/null +++ b/tests/journal_lock.py/test_journal_lock.py @@ -0,0 +1,57 @@ +"""Tests for journal_lock.py code.""" +# Tests: +# - Need logging set up, at TRACE level. +# +# - Will need to mock config for the retrieval of journaldir. +# - Can ask pytest to create a unique tmp dir: +# +# +# +# - Is file actually locked after obtain_lock(). Problem: We opened the +# file in a manner which means nothing else can open it. Also I assume +# that the same process will either be allowed to lock it 'again' or +# overwrite the lock. +# +# Expected failures if: +# +# 1. Lock already held (elsewhere). +# 2. Can't open lock file 'w+'. +# 3. Path to lock file doesn't exist. +# 4. journaldir is None (default on Linux). +# +# - Does release_lock() work? Easier to test, if it's worked.... +# 1. return True if not locked. +# 2. return True if locked, but successful unlock. +# 3. return False otherwise. +# +# - JournalLock.set_path_from_journaldir +# 1. When journaldir is None. +# 2. Succeeds otherwise? +# +# - Can any string to pathlib.Path result in an invalid path for other +# operations? +# +# - Not sure about testing JournalAlreadyLocked class. + +from pytest._pytest import monkeypatch, tmpdir + +from config import config +from journal_lock import JournalLock + + +def test_journal_lock_init(monkeypatch: monkeypatch, tmpdir: tmpdir): # type: ignore + """Test JournalLock instantiation.""" + + def get_str(key: str, *, default: str = None) -> str: + """Mock config.*Config get_str to provide fake journaldir.""" + if key == 'journaldir': + print('journaldir: using tmpdir') + return tmpdir + + print('Other key, calling up ...') + return config.get_str(key) # Call the non-mocked + + with monkeypatch.context() as m: + m.setattr(config, "get_str", get_str) + print(f'{tmpdir=}') + jlock = JournalLock() From a325c62765fe60c690ffc8c8346a06b0b1565638 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 14:20:27 +0000 Subject: [PATCH 391/727] Generalise mock get_str() for re-use, and add asserts * mock get_str() is now via a fixture so it can be re-used in more than one test, avoiding DRY issue. * Some actual tests, in the form of asserts, added to test_journal_lock_init(). --- tests/journal_lock.py/test_journal_lock.py | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 6f5d7d38..154890d4 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -33,19 +33,23 @@ # # - Not sure about testing JournalAlreadyLocked class. -from pytest._pytest import monkeypatch, tmpdir +import pytest +# Import as other names else they get picked up when used as fixtures +from _pytest import monkeypatch as _pytest_monkeypatch +from _pytest import tmpdir as _pytest_tmpdir +from py._path.local import LocalPath as py_path_local_LocalPath from config import config from journal_lock import JournalLock -def test_journal_lock_init(monkeypatch: monkeypatch, tmpdir: tmpdir): # type: ignore - """Test JournalLock instantiation.""" - +@pytest.fixture +def mock_get_str(monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath: + """Fixture for get_str() mock setup.""" def get_str(key: str, *, default: str = None) -> str: """Mock config.*Config get_str to provide fake journaldir.""" if key == 'journaldir': - print('journaldir: using tmpdir') + print(f'journaldir: using tmpdir: {tmpdir}') return tmpdir print('Other key, calling up ...') @@ -53,5 +57,14 @@ def test_journal_lock_init(monkeypatch: monkeypatch, tmpdir: tmpdir): # type: i with monkeypatch.context() as m: m.setattr(config, "get_str", get_str) - print(f'{tmpdir=}') - jlock = JournalLock() + yield tmpdir + + +def test_journal_lock_init(mock_get_str: py_path_local_LocalPath): + """Test JournalLock instantiation.""" + tmpdir = mock_get_str + + jlock = JournalLock() + assert jlock.journal_dir == str(tmpdir) + assert jlock.journal_dir_path is not None + assert jlock.journal_dir_lockfile_name is None From 509a1f2c2e0407ac944334898991e097a4b61948 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 14:24:25 +0000 Subject: [PATCH 392/727] Rename mock_get_str() to mock_journaldir() --- tests/journal_lock.py/test_journal_lock.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 154890d4..b2994eac 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -44,8 +44,8 @@ from journal_lock import JournalLock @pytest.fixture -def mock_get_str(monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath: - """Fixture for get_str() mock setup.""" +def mock_journaldir(monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath: + """Fixture for mocking config.get_str('journaldir').""" def get_str(key: str, *, default: str = None) -> str: """Mock config.*Config get_str to provide fake journaldir.""" if key == 'journaldir': @@ -60,9 +60,9 @@ def mock_get_str(monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py yield tmpdir -def test_journal_lock_init(mock_get_str: py_path_local_LocalPath): +def test_journal_lock_init(mock_journaldir: py_path_local_LocalPath): """Test JournalLock instantiation.""" - tmpdir = mock_get_str + tmpdir = mock_journaldir jlock = JournalLock() assert jlock.journal_dir == str(tmpdir) From c344d612ad27c42fc6bff037e7f2ff936c50d587 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 14:25:52 +0000 Subject: [PATCH 393/727] No need to str(tmpdir), as comparison works without now. --- tests/journal_lock.py/test_journal_lock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index b2994eac..9d9231b6 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -65,6 +65,6 @@ def test_journal_lock_init(mock_journaldir: py_path_local_LocalPath): tmpdir = mock_journaldir jlock = JournalLock() - assert jlock.journal_dir == str(tmpdir) + assert jlock.journal_dir == tmpdir assert jlock.journal_dir_path is not None assert jlock.journal_dir_lockfile_name is None From 7bd6e8ff58696872f9207e8bb24f9ec3fa093be6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 14:38:53 +0000 Subject: [PATCH 394/727] Move test & fixture into a class. This is for then adding more tests. --- tests/journal_lock.py/test_journal_lock.py | 42 +++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 9d9231b6..bdfe8d16 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -43,28 +43,30 @@ from config import config from journal_lock import JournalLock -@pytest.fixture -def mock_journaldir(monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath: - """Fixture for mocking config.get_str('journaldir').""" - def get_str(key: str, *, default: str = None) -> str: - """Mock config.*Config get_str to provide fake journaldir.""" - if key == 'journaldir': - print(f'journaldir: using tmpdir: {tmpdir}') - return tmpdir +class TestJournalLock: + """JournalLock test class.""" - print('Other key, calling up ...') - return config.get_str(key) # Call the non-mocked + @pytest.fixture + def mock_journaldir(self, monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath: + """Fixture for mocking config.get_str('journaldir').""" + def get_str(key: str, *, default: str = None) -> str: + """Mock config.*Config get_str to provide fake journaldir.""" + if key == 'journaldir': + print(f'journaldir: using tmpdir: {tmpdir}') + return tmpdir - with monkeypatch.context() as m: - m.setattr(config, "get_str", get_str) - yield tmpdir + print('Other key, calling up ...') + return config.get_str(key) # Call the non-mocked + with monkeypatch.context() as m: + m.setattr(config, "get_str", get_str) + yield tmpdir -def test_journal_lock_init(mock_journaldir: py_path_local_LocalPath): - """Test JournalLock instantiation.""" - tmpdir = mock_journaldir + def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock instantiation.""" + tmpdir = mock_journaldir - jlock = JournalLock() - assert jlock.journal_dir == tmpdir - assert jlock.journal_dir_path is not None - assert jlock.journal_dir_lockfile_name is None + jlock = JournalLock() + assert jlock.journal_dir == tmpdir + assert jlock.journal_dir_path is not None + assert jlock.journal_dir_lockfile_name is None From 12e5d2627638f2cf13c2df233b45941c5b690527 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 14:45:03 +0000 Subject: [PATCH 395/727] Add tests on JournalLock.set_path_from_journaldir() --- tests/journal_lock.py/test_journal_lock.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index bdfe8d16..521e2618 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -33,6 +33,8 @@ # # - Not sure about testing JournalAlreadyLocked class. +import pathlib + import pytest # Import as other names else they get picked up when used as fixtures from _pytest import monkeypatch as _pytest_monkeypatch @@ -67,6 +69,27 @@ class TestJournalLock: tmpdir = mock_journaldir jlock = JournalLock() + # Check members are properly initialised. assert jlock.journal_dir == tmpdir assert jlock.journal_dir_path is not None assert jlock.journal_dir_lockfile_name is None + + def test_path_from_journaldir_with_none(self): + """Test JournalLock.set_path_from_journaldir().""" + jlock = JournalLock() + + # Check that 'None' is handled correctly. + jlock.journal_dir = None + jlock.set_path_from_journaldir() + assert jlock.journal_dir_path is None + + def test_path_from_journaldir_with_tmpdir(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock.set_path_from_journaldir().""" + tmpdir = mock_journaldir + + jlock = JournalLock() + + # Check that an actual journaldir is handled correctly. + jlock.journal_dir = tmpdir + jlock.set_path_from_journaldir() + assert isinstance(jlock.journal_dir_path, pathlib.Path) From 80b99195eb4e9cf0c792610b244c69a38cc63083 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 14:54:40 +0000 Subject: [PATCH 396/727] Differentiate test docstrings. --- tests/journal_lock.py/test_journal_lock.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 521e2618..d24bd98e 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -75,7 +75,7 @@ class TestJournalLock: assert jlock.journal_dir_lockfile_name is None def test_path_from_journaldir_with_none(self): - """Test JournalLock.set_path_from_journaldir().""" + """Test JournalLock.set_path_from_journaldir() with None.""" jlock = JournalLock() # Check that 'None' is handled correctly. @@ -84,7 +84,7 @@ class TestJournalLock: assert jlock.journal_dir_path is None def test_path_from_journaldir_with_tmpdir(self, mock_journaldir: py_path_local_LocalPath): - """Test JournalLock.set_path_from_journaldir().""" + """Test JournalLock.set_path_from_journaldir() with tmpdir.""" tmpdir = mock_journaldir jlock = JournalLock() From fbad8e240f100f562d7d12afaa07a7d2c27475d2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 16:17:20 +0000 Subject: [PATCH 397/727] obtain_lock() Read-Only test Only tested under win32 so far, but I'd hope os.chmod() is the way to go on Linux and macOS. The win32 implementation currently relies on the pywin32 package being installed in order to use its ntsecuritycon and win32security modules. It might be possible to do this with ctypes instead, but this sure looks cleaner than most ctypes code I've seen. --- tests/journal_lock.py/test_journal_lock.py | 66 +++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index d24bd98e..286dd67e 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -33,7 +33,9 @@ # # - Not sure about testing JournalAlreadyLocked class. +import os import pathlib +import sys import pytest # Import as other names else they get picked up when used as fixtures @@ -42,7 +44,7 @@ from _pytest import tmpdir as _pytest_tmpdir from py._path.local import LocalPath as py_path_local_LocalPath from config import config -from journal_lock import JournalLock +from journal_lock import JournalLock, JournalLockResult class TestJournalLock: @@ -51,6 +53,9 @@ class TestJournalLock: @pytest.fixture def mock_journaldir(self, monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath: """Fixture for mocking config.get_str('journaldir').""" + # Force the directory to pre-defined for testing making !Write + # tmpdir = pathlib.Path(r'C:\Users\Athan\AppData\Local\Temp\rotest') + def get_str(key: str, *, default: str = None) -> str: """Mock config.*Config get_str to provide fake journaldir.""" if key == 'journaldir': @@ -93,3 +98,62 @@ class TestJournalLock: jlock.journal_dir = tmpdir jlock.set_path_from_journaldir() assert isinstance(jlock.journal_dir_path, pathlib.Path) + + def test_obtain_lock_with_none(self): + """Test JournalLock.obtain_lock() with None.""" + jlock = JournalLock() + + # Check that 'None' is handled correctly. + jlock.journal_dir = None + jlock.set_path_from_journaldir() + assert jlock.journal_dir_path is None + locked = jlock.obtain_lock() + assert locked == JournalLockResult.JOURNALDIR_IS_NONE + + def test_obtain_lock_with_tmpdir(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock.obtain_lock() with tmpdir.""" + jlock = JournalLock() + + # Check that an actual journaldir is handled correctly. + locked = jlock.obtain_lock() + assert locked == JournalLockResult.LOCKED + + def test_obtain_lock_with_tmpdir_ro(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock.obtain_lock() with tmpdir.""" + tmpdir = mock_journaldir + + # Make tmpdir read-only ? + if sys.platform == 'win32': + # Ref: + # 1. Look up the current user + user = os.environ.get('USERNAME') + + # From pywin32 + import ntsecuritycon as con + import win32security + + # 2. Fetch its details + winuser, domain, type = win32security.LookupAccountName("", user) + + # 3. Fetch the current security of tmpdir for that user. + sd = win32security.GetFileSecurity(str(tmpdir), win32security.DACL_SECURITY_INFORMATION) + dacl = sd.GetSecurityDescriptorDacl() # instead of dacl = win32security.ACL() + + # 4. Add Write to Denied list + dacl.AddAccessDeniedAce(win32security.ACL_REVISION, con.FILE_GENERIC_WRITE, winuser) + # 5. Apply that change. + sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary + win32security.SetFileSecurity(str(tmpdir), win32security.DACL_SECURITY_INFORMATION, sd) + # + # And, we might need to undo all of that to exit tests cleanly ? + + else: + import stat + os.chmod(tmpdir, stat.S_IRUSR | stat.S_IUSR) + + jlock = JournalLock() + + # Check that an actual journaldir is handled correctly. + locked = jlock.obtain_lock() + print(f'{locked=}') + assert locked == JournalLockResult.JOURNALDIR_READONLY From ec230a9c05762fa915fed476e4d57014a63b2182 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 17:04:37 +0000 Subject: [PATCH 398/727] Make tmpdir non-writable for the read-only test * On win32 this uses pywin32 package modules, so that's now in requirements-dev.txt. * I *think* that code is as clean as it's going to be. Windows is a pain with having you *append* a Deny ACL (rather than remove an Allow one), and then you have to find it in all the ACLs for the object in order to remove it by index. * Linux version of this using `os.chmod()` currently untested. --- requirements-dev.txt | 2 + tests/journal_lock.py/test_journal_lock.py | 55 ++++++++++++++++------ 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 742f69f5..481b066f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -33,6 +33,8 @@ py2exe==0.10.3.0; sys_platform == 'win32' pytest==6.2.2 pytest-cov==2.11.1 # Pytest code coverage support coverage[toml]==5.5 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +# For manipulating folder permissions and the like. +pywin32==300; sys_platform == 'win32' # All of the normal requirements diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 286dd67e..66215d06 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -119,41 +119,66 @@ class TestJournalLock: assert locked == JournalLockResult.LOCKED def test_obtain_lock_with_tmpdir_ro(self, mock_journaldir: py_path_local_LocalPath): - """Test JournalLock.obtain_lock() with tmpdir.""" + """Test JournalLock.obtain_lock() with read-only tmpdir.""" tmpdir = mock_journaldir # Make tmpdir read-only ? if sys.platform == 'win32': # Ref: - # 1. Look up the current user - user = os.environ.get('USERNAME') - - # From pywin32 import ntsecuritycon as con import win32security - # 2. Fetch its details - winuser, domain, type = win32security.LookupAccountName("", user) - - # 3. Fetch the current security of tmpdir for that user. + # Fetch user details + winuser, domain, type = win32security.LookupAccountName("", os.environ.get('USERNAME')) + # Fetch the current security of tmpdir for that user. sd = win32security.GetFileSecurity(str(tmpdir), win32security.DACL_SECURITY_INFORMATION) dacl = sd.GetSecurityDescriptorDacl() # instead of dacl = win32security.ACL() - # 4. Add Write to Denied list - dacl.AddAccessDeniedAce(win32security.ACL_REVISION, con.FILE_GENERIC_WRITE, winuser) - # 5. Apply that change. + # Add Write to Denied list + dacl.AddAccessDeniedAce(win32security.ACL_REVISION, con.FILE_WRITE_DATA, winuser) + # Apply that change. sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary win32security.SetFileSecurity(str(tmpdir), win32security.DACL_SECURITY_INFORMATION, sd) - # - # And, we might need to undo all of that to exit tests cleanly ? else: import stat - os.chmod(tmpdir, stat.S_IRUSR | stat.S_IUSR) + os.chmod(tmpdir, stat.S_IRUSR | stat.S_IXUSR) jlock = JournalLock() # Check that an actual journaldir is handled correctly. locked = jlock.obtain_lock() + + # Revert permissions for test cleanup + if sys.platform == 'win32': + # We can reuse winuser etc from before + import pywintypes + + # We have to call GetAce() until we find one that looks like what + # we added. + i = 0 + ace = dacl.GetAce(i) + while ace: + print(f'After {ace=}') + if ace[0] == (con.ACCESS_DENIED_ACE_TYPE, 0) and ace[1] == con.FILE_WRITE_DATA: + # Delete the Ace that we added + dacl.DeleteAce(i) + # Apply that change. + sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary + win32security.SetFileSecurity(str(tmpdir), win32security.DACL_SECURITY_INFORMATION, sd) + print('Found the Ace we added, removing...') + break + + i += 1 + try: + ace = dacl.GetAce(i) + + except pywintypes.error: + print("Couldn't find the Ace we added, so can't remove") + break + + else: + os.chmod(tmpdir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) + print(f'{locked=}') assert locked == JournalLockResult.JOURNALDIR_READONLY From 70bdc5e0e9a54c37f6c26e7f039816e1c045743c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 18:48:37 +0000 Subject: [PATCH 399/727] Read-Only obtain_lock() test commented and cleaned up. * Comment added about what you'd see if you could check tmpdir properties whilst it's set !Write. * Deleted all the testing print()s. --- tests/journal_lock.py/test_journal_lock.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 66215d06..97e5be0f 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -59,7 +59,6 @@ class TestJournalLock: def get_str(key: str, *, default: str = None) -> str: """Mock config.*Config get_str to provide fake journaldir.""" if key == 'journaldir': - print(f'journaldir: using tmpdir: {tmpdir}') return tmpdir print('Other key, calling up ...') @@ -135,6 +134,10 @@ class TestJournalLock: dacl = sd.GetSecurityDescriptorDacl() # instead of dacl = win32security.ACL() # Add Write to Denied list + # con.FILE_WRITE_DATA results in a 'Special permissions' being + # listed on Properties > Security for the user in the 'Deny' column. + # Clicking through to 'Advanced' shows a 'Deny' for + # 'Create files / write data'. dacl.AddAccessDeniedAce(win32security.ACL_REVISION, con.FILE_WRITE_DATA, winuser) # Apply that change. sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary @@ -159,14 +162,12 @@ class TestJournalLock: i = 0 ace = dacl.GetAce(i) while ace: - print(f'After {ace=}') if ace[0] == (con.ACCESS_DENIED_ACE_TYPE, 0) and ace[1] == con.FILE_WRITE_DATA: # Delete the Ace that we added dacl.DeleteAce(i) # Apply that change. sd.SetSecurityDescriptorDacl(1, dacl, 0) # may not be necessary win32security.SetFileSecurity(str(tmpdir), win32security.DACL_SECURITY_INFORMATION, sd) - print('Found the Ace we added, removing...') break i += 1 @@ -180,5 +181,4 @@ class TestJournalLock: else: os.chmod(tmpdir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) - print(f'{locked=}') assert locked == JournalLockResult.JOURNALDIR_READONLY From cfdf9fbf201b9db7b9781f7646a59b1341d4f206 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 19:16:45 +0000 Subject: [PATCH 400/727] Re-factor JournalLock.obtain_lock() for 'ALREADY_LOCKED' test. This splits the code for opening the lockfile away from that for actually obtaining the lock. It enables a test for trying to lock again with the same file handle. --- journal_lock.py | 40 ++++++++++++++++------ tests/journal_lock.py/test_journal_lock.py | 10 ++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/journal_lock.py b/journal_lock.py index 66de8491..4f54bc30 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -53,16 +53,9 @@ class JournalLock: except Exception: logger.exception("Couldn't make pathlib.Path from journal_dir") - def obtain_lock(self) -> JournalLockResult: - """ - Attempt to obtain a lock on the journal directory. - - :return: LockResult - See the class Enum definition - """ - if self.journal_dir_path is None: - return JournalLockResult.JOURNALDIR_IS_NONE - - self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' + def open_journal_dir_lockfile(self) -> bool: + """Open journal_dir lockfile ready for locking.""" + self.journal_dir_lockfile_name = self.journal_dir_path / 'edmc-journal-lock.txt' # type: ignore logger.trace(f'journal_dir_lockfile_name = {self.journal_dir_lockfile_name!r}') try: self.journal_dir_lockfile = open(self.journal_dir_lockfile_name, mode='w+', encoding='utf-8') @@ -72,8 +65,35 @@ class JournalLock: except Exception as e: # For remote FS this could be any of a wide range of exceptions logger.warning(f"Couldn't open \"{self.journal_dir_lockfile_name}\" for \"w+\"" f" Aborting duplicate process checks: {e!r}") + return False + + return True + + def obtain_lock(self) -> JournalLockResult: + """ + Attempt to obtain a lock on the journal directory. + + :return: LockResult - See the class Enum definition + """ + if self.journal_dir_path is None: + return JournalLockResult.JOURNALDIR_IS_NONE + + if not self.open_journal_dir_lockfile(): return JournalLockResult.JOURNALDIR_READONLY + return self._obtain_lock() + + def _obtain_lock(self) -> JournalLockResult: + """ + Actual code for obtaining a lock. + + This is split out so tests can call *just* it, without the attempt + at opening the file. If we call open_journal_dir_lockfile() we + re-use self.journal_dir_lockfile and in the process close the + previous handle stored in it and thus release the lock. + + :return: LockResult - See the class Enum definition + """ if platform == 'win32': logger.trace('win32, using msvcrt') # win32 doesn't have fcntl, so we have to use msvcrt diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 97e5be0f..9c4a274f 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -182,3 +182,13 @@ class TestJournalLock: os.chmod(tmpdir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) assert locked == JournalLockResult.JOURNALDIR_READONLY + + def test_obtain_lock_already_locked(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock.obtain_lock() with tmpdir.""" + jlock = JournalLock() + + locked = jlock.obtain_lock() + assert locked == JournalLockResult.LOCKED + # Now attempt to lock again, but only that. + second_attempt = jlock._obtain_lock() + assert second_attempt == JournalLockResult.ALREADY_LOCKED From 1fca5703c14a2e3efccba057fd0d6f0180a065b5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 19 Mar 2021 19:19:45 +0000 Subject: [PATCH 401/727] Add self.locked asserts as check on _obtain_lock() side effects --- tests/journal_lock.py/test_journal_lock.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 9c4a274f..f25cb8ca 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -116,6 +116,7 @@ class TestJournalLock: # Check that an actual journaldir is handled correctly. locked = jlock.obtain_lock() assert locked == JournalLockResult.LOCKED + assert jlock.locked is True def test_obtain_lock_with_tmpdir_ro(self, mock_journaldir: py_path_local_LocalPath): """Test JournalLock.obtain_lock() with read-only tmpdir.""" @@ -189,6 +190,7 @@ class TestJournalLock: locked = jlock.obtain_lock() assert locked == JournalLockResult.LOCKED + assert jlock.locked is True # Now attempt to lock again, but only that. second_attempt = jlock._obtain_lock() assert second_attempt == JournalLockResult.ALREADY_LOCKED From e84af6ae7f52e42308abaa81ec03329309a3f707 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 21 Mar 2021 11:04:50 +0000 Subject: [PATCH 402/727] Update: "TODO" tests comments --- tests/journal_lock.py/test_journal_lock.py | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index f25cb8ca..a4fb62be 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -1,12 +1,5 @@ """Tests for journal_lock.py code.""" # Tests: -# - Need logging set up, at TRACE level. -# -# - Will need to mock config for the retrieval of journaldir. -# - Can ask pytest to create a unique tmp dir: -# -# -# # - Is file actually locked after obtain_lock(). Problem: We opened the # file in a manner which means nothing else can open it. Also I assume # that the same process will either be allowed to lock it 'again' or @@ -24,10 +17,6 @@ # 2. return True if locked, but successful unlock. # 3. return False otherwise. # -# - JournalLock.set_path_from_journaldir -# 1. When journaldir is None. -# 2. Succeeds otherwise? -# # - Can any string to pathlib.Path result in an invalid path for other # operations? # @@ -68,6 +57,8 @@ class TestJournalLock: m.setattr(config, "get_str", get_str) yield tmpdir + ########################################################################### + # Tests against JournalLock.__init__() def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath): """Test JournalLock instantiation.""" tmpdir = mock_journaldir @@ -78,6 +69,8 @@ class TestJournalLock: assert jlock.journal_dir_path is not None assert jlock.journal_dir_lockfile_name is None + ########################################################################### + # Tests against JournalLock.set_path_from_journaldir() def test_path_from_journaldir_with_none(self): """Test JournalLock.set_path_from_journaldir() with None.""" jlock = JournalLock() @@ -98,6 +91,8 @@ class TestJournalLock: jlock.set_path_from_journaldir() assert isinstance(jlock.journal_dir_path, pathlib.Path) + ########################################################################### + # Tests against JournalLock.obtain_lock() def test_obtain_lock_with_none(self): """Test JournalLock.obtain_lock() with None.""" jlock = JournalLock() @@ -193,4 +188,12 @@ class TestJournalLock: assert jlock.locked is True # Now attempt to lock again, but only that. second_attempt = jlock._obtain_lock() + # Fails on Linux, because flock(2) is per process, so we'd need to + # use multiprocessing to test this. assert second_attempt == JournalLockResult.ALREADY_LOCKED + + ########################################################################### + # Tests against JournalLock.release_lock() + + ########################################################################### + # Tests against JournalLock.update_lock() From 3a80d77997451d3299dc33f23f4d2e875eb3c5f8 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 21 Mar 2021 11:17:59 +0000 Subject: [PATCH 403/727] Contributing.md: We use `pytest` and a particular file layout for tests. --- Contributing.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Contributing.md b/Contributing.md index 80374301..15c1981c 100644 --- a/Contributing.md +++ b/Contributing.md @@ -157,10 +157,20 @@ Note that if your PR does not cleanly (or mostly cleanly) pass a linting scan, y ### Unit testing -Where possible please write unit tests for your PRs, especially in the case of bug fixes, having regression tests help -ensure that we don't accidentally re-introduce a bug down the line. +Where possible please write unit tests for your PRs, especially in the case of +bug fixes, having regression tests help ensure that we don't accidentally +re-introduce a bug down the line. -We use the python stdlib library `unittest` for unit testing. +We use the `pytest` for unit testing. + +The files for a test should go in a sub-directory of `tests/` names after the +(main) file that contains the code they are testing. e.g. for journal_lock.py +the tests are in `tests/journal_lock.py/test_journal_lock.py`. The `test_` +prefix on `test_journal_lock.py` is necessary in order for `pytest` to +recognise the file as containing tests to be run. +The sub-directory avoids having a mess of files in `tests`, particularly when +there might be supporting files, e.g. `tests/config.py/_old_config.py` or files +containing test data. --- From 0cae22e4a4bd0eed215ac7296449638ae210930a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 21 Mar 2021 11:23:50 +0000 Subject: [PATCH 404/727] Contributing.md: Expand on unit test docs & set vim wordwrap. * vim: modeline for 79 character line wrap * Add some hints about running tests. * Pointer to the pytest docs. --- Contributing.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Contributing.md b/Contributing.md index 15c1981c..5416cf68 100644 --- a/Contributing.md +++ b/Contributing.md @@ -1,3 +1,6 @@ + # Guidelines for contributing to EDMC ## Work on Issues @@ -163,15 +166,28 @@ re-introduce a bug down the line. We use the `pytest` for unit testing. -The files for a test should go in a sub-directory of `tests/` names after the -(main) file that contains the code they are testing. e.g. for journal_lock.py -the tests are in `tests/journal_lock.py/test_journal_lock.py`. The `test_` -prefix on `test_journal_lock.py` is necessary in order for `pytest` to -recognise the file as containing tests to be run. +The files for a test should go in a sub-directory of `tests/` named after the +(principal) file that contains the code they are testing. e.g. for +journal_lock.py the tests are in `tests/journal_lock.py/test_journal_lock.py`. +The `test_` prefix on `test_journal_lock.py` is necessary in order for `pytest` +to recognise the file as containing tests to be run. The sub-directory avoids having a mess of files in `tests`, particularly when there might be supporting files, e.g. `tests/config.py/_old_config.py` or files containing test data. +Invoking just a bare `pytest` command will run all tests. + +To run only a sub-set of tests you can use, e.g. `pytest -k journal_lock`. You +might want to use `pytest -rA -k journal_lock` if you have any debug print() +statements within the test code itself, so you can see the output even when the +tests all succeed. + +Adding `--trace` to a `pytest` invocation causes it to drop into `pdb` prompt +for each test, handy if you want to step through the testing code to be sure of +anything. + +Otherwise see the [pytest documentation](https://docs.pytest.org/en/stable/contents.html). + --- ## General workflow From 6dbdd332be885c1b1b7eb4bb9723d655d4ca1ab6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 13:50:34 +0000 Subject: [PATCH 405/727] config.py: Silence flake8 complaint about no space at start of comment --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index b9bcb652..8308c022 100644 --- a/config.py +++ b/config.py @@ -29,7 +29,7 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '4.2.0-beta1' #-rc1+a872b5f' +appversion = '4.2.0-beta1' # -rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' From 6d33ee0d8b2a4f2fe481327099065ece0ee25ecd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 14:49:27 +0000 Subject: [PATCH 406/727] JournalLock: Use multiprocessing for 'already locked' test. Confirmed working on Windows. --- tests/journal_lock.py/test_journal_lock.py | 57 +++++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index a4fb62be..510c0358 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -22,6 +22,7 @@ # # - Not sure about testing JournalAlreadyLocked class. +import multiprocessing as mp import os import pathlib import sys @@ -36,6 +37,36 @@ from config import config from journal_lock import JournalLock, JournalLockResult +# We need another process to already hold the lock. +def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib.Path): + """ + Obtain the lock in a sub-process. + + :param continue_q: Write to this when parent should continue. + :param exit_q: When there's an item in this, exit. + :param lockfile: Path where the lockfile should be. + """ + with open(lockfile / 'edmc-journal-lock.txt', mode='w+') as lf: + print(f'Opened {lockfile} for read...') + # This needs to be kept in sync with journal_lock.py:_obtain_lock() + if sys.platform == 'win32': + print('On win32') + import msvcrt + try: + print('Trying msvcrt.locking() ...') + msvcrt.locking(lf.fileno(), msvcrt.LK_NBLCK, 4096) + + except Exception as e: + print(f"sub-process: Unable to lock file: {e!r}") + return + + print('Telling main process to go...') + continue_q.put('go', timeout=5) + # Wait for signal to exit + print('Waiting for exit signal...') + exit_q.get(block=True, timeout=None) + + class TestJournalLock: """JournalLock test class.""" @@ -181,19 +212,31 @@ class TestJournalLock: def test_obtain_lock_already_locked(self, mock_journaldir: py_path_local_LocalPath): """Test JournalLock.obtain_lock() with tmpdir.""" - jlock = JournalLock() + continue_q: mp.Queue = mp.Queue() + exit_q: mp.Queue = mp.Queue() + locker = mp.Process(target=other_process_lock, + args=(continue_q, exit_q, mock_journaldir) + ) + print('Starting sub-process other_process_lock()...') + locker.start() + # Wait for the sub-process to have locked + print('Waiting for "go" signal from sub-process...') + continue_q.get(block=True, timeout=5) - locked = jlock.obtain_lock() - assert locked == JournalLockResult.LOCKED - assert jlock.locked is True - # Now attempt to lock again, but only that. - second_attempt = jlock._obtain_lock() + print('Attempt actual lock test...') + # Now attempt to lock with to-test code + jlock = JournalLock() + second_attempt = jlock.obtain_lock() # Fails on Linux, because flock(2) is per process, so we'd need to # use multiprocessing to test this. assert second_attempt == JournalLockResult.ALREADY_LOCKED + print('Telling sub-process to quit...') + exit_q.put('quit') + print('Waiting for sub-process...') + locker.join() + print('Done.') ########################################################################### # Tests against JournalLock.release_lock() - ########################################################################### # Tests against JournalLock.update_lock() From 1a1ad868403b03a70e40537c80154052b688e9ed Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 14:56:30 +0000 Subject: [PATCH 407/727] JournalLock: Implement non-win32 sub-process lock --- tests/journal_lock.py/test_journal_lock.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 510c0358..c76ed9a1 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -57,9 +57,19 @@ def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib msvcrt.locking(lf.fileno(), msvcrt.LK_NBLCK, 4096) except Exception as e: - print(f"sub-process: Unable to lock file: {e!r}") + print(f'sub-process: Unable to lock file: {e!r}') return + else: + import fcntl + + print('Not win32, using fcntl') + try: + fcntl.flock(lf, fcntl.LOCK_EX | fcntl.LOCK_NB) + + except Exception as e: + print(f'sub-process: Unable to lock file: {e!r}') + print('Telling main process to go...') continue_q.put('go', timeout=5) # Wait for signal to exit From cda6d344ae0f830b2e387ab20cce53df21502126 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 14:58:42 +0000 Subject: [PATCH 408/727] JournalLock: Tag sub-process locker prints for easy reading --- tests/journal_lock.py/test_journal_lock.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index c76ed9a1..718415f7 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -47,13 +47,13 @@ def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib :param lockfile: Path where the lockfile should be. """ with open(lockfile / 'edmc-journal-lock.txt', mode='w+') as lf: - print(f'Opened {lockfile} for read...') + print(f'sub-process: Opened {lockfile} for read...') # This needs to be kept in sync with journal_lock.py:_obtain_lock() if sys.platform == 'win32': - print('On win32') + print('sub-process: On win32') import msvcrt try: - print('Trying msvcrt.locking() ...') + print('sub-process: Trying msvcrt.locking() ...') msvcrt.locking(lf.fileno(), msvcrt.LK_NBLCK, 4096) except Exception as e: @@ -63,17 +63,17 @@ def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib else: import fcntl - print('Not win32, using fcntl') + print('sub-process: Not win32, using fcntl') try: fcntl.flock(lf, fcntl.LOCK_EX | fcntl.LOCK_NB) except Exception as e: print(f'sub-process: Unable to lock file: {e!r}') - print('Telling main process to go...') + print('sub-process: Got lock, telling main process to go...') continue_q.put('go', timeout=5) # Wait for signal to exit - print('Waiting for exit signal...') + print('sub-process: Waiting for exit signal...') exit_q.get(block=True, timeout=None) From 0c9b841e80095336f1060595508ce7e58739f5d9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 15:44:07 +0000 Subject: [PATCH 409/727] JournalLock: Test release_lock() This re-factored other_process_lock() a little for DRY reasons. --- tests/journal_lock.py/test_journal_lock.py | 70 +++++++++++++++------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 718415f7..a48dc15e 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -49,26 +49,9 @@ def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib with open(lockfile / 'edmc-journal-lock.txt', mode='w+') as lf: print(f'sub-process: Opened {lockfile} for read...') # This needs to be kept in sync with journal_lock.py:_obtain_lock() - if sys.platform == 'win32': - print('sub-process: On win32') - import msvcrt - try: - print('sub-process: Trying msvcrt.locking() ...') - msvcrt.locking(lf.fileno(), msvcrt.LK_NBLCK, 4096) - - except Exception as e: - print(f'sub-process: Unable to lock file: {e!r}') - return - - else: - import fcntl - - print('sub-process: Not win32, using fcntl') - try: - fcntl.flock(lf, fcntl.LOCK_EX | fcntl.LOCK_NB) - - except Exception as e: - print(f'sub-process: Unable to lock file: {e!r}') + if not _obtain_lock('sub-process', lf): + print('sub-process: Failed to get lock, so returning') + return print('sub-process: Got lock, telling main process to go...') continue_q.put('go', timeout=5) @@ -77,6 +60,39 @@ def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib exit_q.get(block=True, timeout=None) +def _obtain_lock(prefix: str, filehandle) -> bool: + """ + Obtain the JournalLock. + + :param prefix: str - what to prefix output with. + :param filehandle: File handle already open on the lockfile. + :return: bool - True if we obtained the lock. + """ + if sys.platform == 'win32': + print(f'{prefix}: On win32') + import msvcrt + try: + print(f'{prefix}: Trying msvcrt.locking() ...') + msvcrt.locking(filehandle.fileno(), msvcrt.LK_NBLCK, 4096) + + except Exception as e: + print(f'{prefix}: Unable to lock file: {e!r}') + return False + + else: + import fcntl + + print(f'{prefix}: Not win32, using fcntl') + try: + fcntl.flock(filehandle, fcntl.LOCK_EX | fcntl.LOCK_NB) + + except Exception as e: + print(f'{prefix}: Unable to lock file: {e!r}') + return False + + return True + + class TestJournalLock: """JournalLock test class.""" @@ -248,5 +264,19 @@ class TestJournalLock: ########################################################################### # Tests against JournalLock.release_lock() + def test_release_lock(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock.release_lock().""" + # First actually obtain the lock, and check it worked + jlock = JournalLock() + jlock.obtain_lock() + assert jlock.locked is True + + # Now release the lock + assert jlock.release_lock() is True + + # And finally check it actually IS unlocked. + with open(mock_journaldir / 'edmc-journal-lock.txt', mode='w+') as lf: + assert _obtain_lock('release-lock', lf) is True + ########################################################################### # Tests against JournalLock.update_lock() From 8c74d463687a844cd49c5f396e84e1e8e1395a60 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 16:14:49 +0000 Subject: [PATCH 410/727] JournalLock: Implement update_lock() test. * This uses a separate mock_journaldir_changing() that returns a new tmpdir on each invocation of config.get_str('journaldir'). --- tests/journal_lock.py/test_journal_lock.py | 41 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index a48dc15e..cf4e5e42 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -99,9 +99,6 @@ class TestJournalLock: @pytest.fixture def mock_journaldir(self, monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath: """Fixture for mocking config.get_str('journaldir').""" - # Force the directory to pre-defined for testing making !Write - # tmpdir = pathlib.Path(r'C:\Users\Athan\AppData\Local\Temp\rotest') - def get_str(key: str, *, default: str = None) -> str: """Mock config.*Config get_str to provide fake journaldir.""" if key == 'journaldir': @@ -114,6 +111,24 @@ class TestJournalLock: m.setattr(config, "get_str", get_str) yield tmpdir + @pytest.fixture + def mock_journaldir_changing( + self, + monkeypatch: _pytest_monkeypatch, + tmpdir_factory: _pytest_tmpdir.TempdirFactory) -> py_path_local_LocalPath: + """Fixture for mocking config.get_str('journaldir').""" + def get_str(key: str, *, default: str = None) -> str: + """Mock config.*Config get_str to provide fake journaldir.""" + if key == 'journaldir': + return tmpdir_factory.mktemp() + + print('Other key, calling up ...') + return config.get_str(key) # Call the non-mocked + + with monkeypatch.context() as m: + m.setattr(config, "get_str", get_str) + yield tmpdir_factory + ########################################################################### # Tests against JournalLock.__init__() def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath): @@ -280,3 +295,23 @@ class TestJournalLock: ########################################################################### # Tests against JournalLock.update_lock() + def test_update_lock(self, mock_journaldir_changing: py_path_local_LocalPath): + """ + Test JournalLock.update_lock(). + + NB: This uses mock_journaldir_changing so that each subsequent call + to config.get_str('journaldir') gets a new, unique, path. + This should mean that the call to update_lock() switches to a new + journaldir. + """ + # First actually obtain the lock, and check it worked + jlock = JournalLock() + jlock.obtain_lock() + assert jlock.locked is True + + # Now store the 'current' journaldir for reference and attempt + # to update to a new one. + old_journaldir = jlock.journal_dir + jlock.update_lock() + assert jlock.journaldir != old_journaldir + assert jlock.locked is True From baca42f06ecc2d2186d60262aa514f020a96c1c3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 16:41:56 +0000 Subject: [PATCH 411/727] JournalLock: Fix update_lock() with an extra mock * update_lock() wants to, potentially, invoke JournalLock.JournalAlreadyLocked() instance for a tkinter pop-up. We do *not* want to mock all of that, so monkeypatch a mock so that in the 'test PASSED' case this just works. --- tests/journal_lock.py/test_journal_lock.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index cf4e5e42..4fe03671 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -120,7 +120,7 @@ class TestJournalLock: def get_str(key: str, *, default: str = None) -> str: """Mock config.*Config get_str to provide fake journaldir.""" if key == 'journaldir': - return tmpdir_factory.mktemp() + return tmpdir_factory.mktemp("changing") print('Other key, calling up ...') return config.get_str(key) # Call the non-mocked @@ -129,6 +129,17 @@ class TestJournalLock: m.setattr(config, "get_str", get_str) yield tmpdir_factory + @pytest.fixture + def mock_journalalreadylocked(self, monkeypatch: _pytest_monkeypatch) -> JournalLock: + """Fixture to mock JournalAlreadyLocked in JournalLock instance.""" + class MockJournalAlreadyLocked: + def __init__(self, parent, callback) -> None: + pass + + with monkeypatch.context() as m: + m.setattr(JournalLock, "JournalAlreadyLocked", MockJournalAlreadyLocked) + yield + ########################################################################### # Tests against JournalLock.__init__() def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath): @@ -295,7 +306,10 @@ class TestJournalLock: ########################################################################### # Tests against JournalLock.update_lock() - def test_update_lock(self, mock_journaldir_changing: py_path_local_LocalPath): + def test_update_lock( + self, + mock_journaldir_changing: py_path_local_LocalPath, + mock_journalalreadylocked): """ Test JournalLock.update_lock(). @@ -312,6 +326,6 @@ class TestJournalLock: # Now store the 'current' journaldir for reference and attempt # to update to a new one. old_journaldir = jlock.journal_dir - jlock.update_lock() - assert jlock.journaldir != old_journaldir + jlock.update_lock(None) + assert jlock.journal_dir != old_journaldir assert jlock.locked is True From 2fa3428581ce9ef439986b933277f84586a886a4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 16:44:48 +0000 Subject: [PATCH 412/727] JournalLock: Actually, just passing `None` as the tk.Tk parent works. In the PASSED case we never even make a JournalAlreadyLocked instance. In the FAILED case let it blow up on the `None`. --- tests/journal_lock.py/test_journal_lock.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 4fe03671..321452bb 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -129,17 +129,6 @@ class TestJournalLock: m.setattr(config, "get_str", get_str) yield tmpdir_factory - @pytest.fixture - def mock_journalalreadylocked(self, monkeypatch: _pytest_monkeypatch) -> JournalLock: - """Fixture to mock JournalAlreadyLocked in JournalLock instance.""" - class MockJournalAlreadyLocked: - def __init__(self, parent, callback) -> None: - pass - - with monkeypatch.context() as m: - m.setattr(JournalLock, "JournalAlreadyLocked", MockJournalAlreadyLocked) - yield - ########################################################################### # Tests against JournalLock.__init__() def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath): @@ -308,8 +297,7 @@ class TestJournalLock: # Tests against JournalLock.update_lock() def test_update_lock( self, - mock_journaldir_changing: py_path_local_LocalPath, - mock_journalalreadylocked): + mock_journaldir_changing: py_path_local_LocalPath): """ Test JournalLock.update_lock(). From 8bf5a43c5b07a1cea33a35dbe10842e77e70a82d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 17:14:32 +0000 Subject: [PATCH 413/727] JournalLock: Add release_lock() test when not locked. --- tests/journal_lock.py/test_journal_lock.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 321452bb..61b7af34 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -293,6 +293,11 @@ class TestJournalLock: with open(mock_journaldir / 'edmc-journal-lock.txt', mode='w+') as lf: assert _obtain_lock('release-lock', lf) is True + def test_release_lock_not_locked(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock.release_lock() when not locked.""" + jlock = JournalLock() + assert jlock.release_lock() is True + ########################################################################### # Tests against JournalLock.update_lock() def test_update_lock( From f2fd16307cd32b95c0324fe1be8fe17681964f95 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 17:38:20 +0000 Subject: [PATCH 414/727] JournalLock: Cleanup pytest coverage * Some `# pragma: no cover' added where it's more pain to get coverage than to put up with lack of testing. We are choosing to NOT test retry_lock() or the call to it from update_lock() as it's tkinter stuff. * Check `self.journal_dir_lockfile` exists before trying to call .close() on it. * Note where platform checks means only one if branch gets run, so of course coverage will complain about the other one. * Add test_release_lock_lie_locked() to test when not locked, but pretend we were so release_lock() returns False. * Add test_update_lock_same() to check if an attempt is made to 'update' to the same directory. --- journal_lock.py | 19 +++++++-------- tests/journal_lock.py/test_journal_lock.py | 27 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/journal_lock.py b/journal_lock.py index 4f54bc30..318eff6b 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -13,7 +13,7 @@ from EDMCLogging import get_main_logger logger = get_main_logger() -if TYPE_CHECKING: +if TYPE_CHECKING: # pragma: no cover def _(x: str) -> str: return x @@ -50,7 +50,7 @@ class JournalLock: try: self.journal_dir_path = pathlib.Path(self.journal_dir) - except Exception: + except Exception: # pragma: no cover logger.exception("Couldn't make pathlib.Path from journal_dir") def open_journal_dir_lockfile(self) -> bool: @@ -107,7 +107,7 @@ class JournalLock: f", assuming another process running: {e!r}") return JournalLockResult.ALREADY_LOCKED - else: + else: # pytest coverage only sees this on !win32 logger.trace('NOT win32, using fcntl') try: import fcntl @@ -133,7 +133,7 @@ class JournalLock: return JournalLockResult.LOCKED - def release_lock(self) -> bool: + def release_lock(self) -> bool: # noqa: CCR001 """ Release lock on journal directory. @@ -160,7 +160,7 @@ class JournalLock: else: unlocked = True - else: + else: # pytest coverage only sees this on !win32 logger.trace('NOT win32, using fcntl') try: import fcntl @@ -179,7 +179,8 @@ class JournalLock: unlocked = True # Close the file whether or not the unlocking succeeded. - self.journal_dir_lockfile.close() + if hasattr(self, 'journal_dir_lockfile'): + self.journal_dir_lockfile.close() self.journal_dir_lockfile_name = None # Avoids type hint issues, see 'declaration' in JournalLock.__init__() @@ -187,7 +188,7 @@ class JournalLock: return unlocked - class JournalAlreadyLocked(tk.Toplevel): + class JournalAlreadyLocked(tk.Toplevel): # pragma: no cover """Pop-up for when Journal directory already locked.""" def __init__(self, parent: tk.Tk, callback: Callable) -> None: @@ -263,9 +264,9 @@ class JournalLock: if self.obtain_lock() == JournalLockResult.ALREADY_LOCKED: # Pop-up message asking for Retry or Ignore - self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) + self.retry_popup = self.JournalAlreadyLocked(parent, self.retry_lock) # pragma: no cover - def retry_lock(self, retry: bool, parent: tk.Tk) -> None: + def retry_lock(self, retry: bool, parent: tk.Tk) -> None: # pragma: no cover """ Try again to obtain a lock on the Journal Directory. diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 61b7af34..da8cc755 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -298,6 +298,12 @@ class TestJournalLock: jlock = JournalLock() assert jlock.release_lock() is True + def test_release_lock_lie_locked(self, mock_journaldir: py_path_local_LocalPath): + """Test JournalLock.release_lock() when not locked, but lie we are.""" + jlock = JournalLock() + jlock.locked = True + assert jlock.release_lock() is False + ########################################################################### # Tests against JournalLock.update_lock() def test_update_lock( @@ -319,6 +325,25 @@ class TestJournalLock: # Now store the 'current' journaldir for reference and attempt # to update to a new one. old_journaldir = jlock.journal_dir - jlock.update_lock(None) + jlock.update_lock(None) # type: ignore assert jlock.journal_dir != old_journaldir assert jlock.locked is True + + def test_update_lock_same(self, mock_journaldir: py_path_local_LocalPath): + """ + Test JournalLock.update_lock(). + + Due to using 'static' mock_journaldir this should 'work', because the + directory is still the same. + """ + # First actually obtain the lock, and check it worked + jlock = JournalLock() + jlock.obtain_lock() + assert jlock.locked is True + + # Now store the 'current' journaldir for reference and attempt + # to update to a new one. + old_journaldir = jlock.journal_dir + jlock.update_lock(None) # type: ignore + assert jlock.journal_dir == old_journaldir + assert jlock.locked is True From e3d3e79b5008c31137330736c8535c87822a9f9a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 24 Mar 2021 17:44:49 +0000 Subject: [PATCH 415/727] tests: Add .coveragerc (excludes tests/ and venv/) Without these 'omit' settings pytest coverage reports on the tests themselves, plus the venv files if present. --- .coveragerc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..019facb4 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,6 @@ +[run] +omit = + # The tests themselves + tests/* + # Any venv files + venv/* From 7ad3518a7b41e36799fd530cba9534286e47b7e4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 10:18:08 +0000 Subject: [PATCH 416/727] config.py: Restor appversion to intended 5.0.0-beta1 for current develop. --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 8308c022..3c1e9dbb 100644 --- a/config.py +++ b/config.py @@ -29,7 +29,7 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '4.2.0-beta1' # -rc1+a872b5f' +appversion = '5.0.0-beta1' # -rc1+a872b5f' # For some things we want appversion without (possible) +build metadata appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' From e0574e558448fd32bd46247781d5a2bf688047a9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 10:18:36 +0000 Subject: [PATCH 417/727] Contributing.md: Minor pytest-related edits * URL-ise some things. * `` around some code. --- Contributing.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Contributing.md b/Contributing.md index 5416cf68..0f57c12c 100644 --- a/Contributing.md +++ b/Contributing.md @@ -164,7 +164,7 @@ Where possible please write unit tests for your PRs, especially in the case of bug fixes, having regression tests help ensure that we don't accidentally re-introduce a bug down the line. -We use the `pytest` for unit testing. +We use the [`pytest`](https://docs.pytest.org/en/stable/) for unit testing. The files for a test should go in a sub-directory of `tests/` named after the (principal) file that contains the code they are testing. e.g. for @@ -178,15 +178,15 @@ containing test data. Invoking just a bare `pytest` command will run all tests. To run only a sub-set of tests you can use, e.g. `pytest -k journal_lock`. You -might want to use `pytest -rA -k journal_lock` if you have any debug print() +might want to use `pytest -rA -k journal_lock` if you have any debug `print()` statements within the test code itself, so you can see the output even when the tests all succeed. -Adding `--trace` to a `pytest` invocation causes it to drop into `pdb` prompt -for each test, handy if you want to step through the testing code to be sure of -anything. +Adding `--trace` to a `pytest` invocation causes it to drop into a +[`pdb`](https://docs.python.org/3/library/pdb.html) prompt for each test, +handy if you want to step through the testing code to be sure of anything. -Otherwise see the [pytest documentation](https://docs.pytest.org/en/stable/contents.html). +Otherwise, see the [pytest documentation](https://docs.pytest.org/en/stable/contents.html). --- From d0617ba3373d6c7f656fbd81ed9f1036a392626d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 10:19:25 +0000 Subject: [PATCH 418/727] JournalLock: tests - minor docstring and formatting cleanups --- tests/journal_lock.py/test_journal_lock.py | 55 ++++++++++++---------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index da8cc755..3334fbd4 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -1,27 +1,33 @@ -"""Tests for journal_lock.py code.""" -# Tests: -# - Is file actually locked after obtain_lock(). Problem: We opened the -# file in a manner which means nothing else can open it. Also I assume -# that the same process will either be allowed to lock it 'again' or -# overwrite the lock. -# -# Expected failures if: -# -# 1. Lock already held (elsewhere). -# 2. Can't open lock file 'w+'. -# 3. Path to lock file doesn't exist. -# 4. journaldir is None (default on Linux). -# -# - Does release_lock() work? Easier to test, if it's worked.... -# 1. return True if not locked. -# 2. return True if locked, but successful unlock. -# 3. return False otherwise. -# -# - Can any string to pathlib.Path result in an invalid path for other -# operations? -# -# - Not sure about testing JournalAlreadyLocked class. +""" +Tests for journal_lock.py code. +Tests: + - Is file actually locked after obtain_lock(). Problem: We opened the + file in a manner which means nothing else can open it. Also I assume + that the same process will either be allowed to lock it 'again' or + overwrite the lock. + + Expected failures if: + + 1. Lock already held (elsewhere). + 2. Can't open lock file 'w+'. + 3. Path to lock file doesn't exist. + 4. journaldir is None (default on Linux). + + - Does release_lock() work? Easier to test, if it's worked.... + 1. return True if not locked. + 2. return True if locked, but successful unlock. + 3. return False otherwise. + + - JournalLock.set_path_from_journaldir + 1. When journaldir is None. + 2. Succeeds otherwise? + + - Can any string to pathlib.Path result in an invalid path for other + operations? + + - Not sure about testing JournalAlreadyLocked class. +""" import multiprocessing as mp import os import pathlib @@ -115,7 +121,8 @@ class TestJournalLock: def mock_journaldir_changing( self, monkeypatch: _pytest_monkeypatch, - tmpdir_factory: _pytest_tmpdir.TempdirFactory) -> py_path_local_LocalPath: + tmpdir_factory: _pytest_tmpdir.TempdirFactory + ) -> py_path_local_LocalPath: """Fixture for mocking config.get_str('journaldir').""" def get_str(key: str, *, default: str = None) -> str: """Mock config.*Config get_str to provide fake journaldir.""" From 0811a000edf8e3d454e676bec06a3d1122f911ec Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 10:27:13 +0000 Subject: [PATCH 419/727] JournalLock: tests - Expand on comment about other_process_lock() section --- tests/journal_lock.py/test_journal_lock.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 3334fbd4..a2ebaa63 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -43,7 +43,11 @@ from config import config from journal_lock import JournalLock, JournalLockResult -# We need another process to already hold the lock. +########################################################################### +# For some tests (at least on Linux) we need another process to already +# hold the lock. +# This is at top level due to multiprocessing.Process wanting to +# pickle its arguments, other_process_lock() being one of them. def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib.Path): """ Obtain the lock in a sub-process. @@ -97,6 +101,7 @@ def _obtain_lock(prefix: str, filehandle) -> bool: return False return True +########################################################################### class TestJournalLock: From b6dcc39fb2087c5b8f155271e44feccab5989f98 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 11:03:35 +0000 Subject: [PATCH 420/727] JournalLock: No need to ' is True' on assert --- tests/journal_lock.py/test_journal_lock.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index a2ebaa63..75a6be1f 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -195,7 +195,7 @@ class TestJournalLock: # Check that an actual journaldir is handled correctly. locked = jlock.obtain_lock() assert locked == JournalLockResult.LOCKED - assert jlock.locked is True + assert jlock.locked def test_obtain_lock_with_tmpdir_ro(self, mock_journaldir: py_path_local_LocalPath): """Test JournalLock.obtain_lock() with read-only tmpdir.""" @@ -296,19 +296,19 @@ class TestJournalLock: # First actually obtain the lock, and check it worked jlock = JournalLock() jlock.obtain_lock() - assert jlock.locked is True + assert jlock.locked # Now release the lock - assert jlock.release_lock() is True + assert jlock.release_lock() # And finally check it actually IS unlocked. with open(mock_journaldir / 'edmc-journal-lock.txt', mode='w+') as lf: - assert _obtain_lock('release-lock', lf) is True + assert _obtain_lock('release-lock', lf) def test_release_lock_not_locked(self, mock_journaldir: py_path_local_LocalPath): """Test JournalLock.release_lock() when not locked.""" jlock = JournalLock() - assert jlock.release_lock() is True + assert jlock.release_lock() def test_release_lock_lie_locked(self, mock_journaldir: py_path_local_LocalPath): """Test JournalLock.release_lock() when not locked, but lie we are.""" @@ -332,14 +332,14 @@ class TestJournalLock: # First actually obtain the lock, and check it worked jlock = JournalLock() jlock.obtain_lock() - assert jlock.locked is True + assert jlock.locked # Now store the 'current' journaldir for reference and attempt # to update to a new one. old_journaldir = jlock.journal_dir jlock.update_lock(None) # type: ignore assert jlock.journal_dir != old_journaldir - assert jlock.locked is True + assert jlock.locked def test_update_lock_same(self, mock_journaldir: py_path_local_LocalPath): """ @@ -351,11 +351,11 @@ class TestJournalLock: # First actually obtain the lock, and check it worked jlock = JournalLock() jlock.obtain_lock() - assert jlock.locked is True + assert jlock.locked # Now store the 'current' journaldir for reference and attempt # to update to a new one. old_journaldir = jlock.journal_dir jlock.update_lock(None) # type: ignore assert jlock.journal_dir == old_journaldir - assert jlock.locked is True + assert jlock.locked From 63be402cb45e984115e8143bcf10010542843434 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 12:00:45 +0000 Subject: [PATCH 421/727] EDDN: Restore safe_modules_and_ships() from 4.2.4 --- plugins/eddn.py | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 46a893db..7b9d5241 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -299,6 +299,36 @@ Msg:\n{msg}''' this.commodities = commodities + def safe_modules_and_ships(self, data: Mapping[str, Any]) -> Tuple[Dict, Dict]: + modules: Dict[str, Any] = data['lastStarport'].get('modules') + if modules is None or not isinstance(modules, dict): + if modules is None: + logger.debug('modules was None. FC or Damaged Station?') + + elif isinstance(modules, list): + if len(modules) == 0: + logger.debug('modules is empty list. Damaged Station?') + + else: + logger.error(f'modules is non-empty list: {modules!r}') + + else: + logger.error(f'modules was not None, a list, or a dict! type = {type(modules)}') + # Set a safe value + modules = {} + + ships: Dict[str, Any] = data['lastStarport'].get('ships') + if ships is None or not isinstance(ships, dict): + if ships is None: + logger.debug('ships was None') + + else: + logger.error(f'ships was neither None nor a Dict! Type = {type(ships)}') + # Set a safe value + ships = {'shipyard_list': {}, 'unavailable_list': []} + + return (modules, ships) + def export_outfitting(self, data: CAPIData, is_beta: bool) -> None: """ export_outfitting updates EDDN with the current (lastStarport) station's outfitting options, if any. @@ -307,19 +337,20 @@ Msg:\n{msg}''' :param data: dict containing the outfitting data :param is_beta: whether or not we're currently in beta mode """ + modules, ships = self.safe_modules_and_ships(data) # Horizons flag - will hit at least Int_PlanetApproachSuite other than at engineer bases ("Colony"), # prison or rescue Megaships, or under Pirate Attack etc horizons: bool = is_horizons( data['lastStarport'].get('economies', {}), - data['lastStarport']['modules'], - data['lastStarport']['ships'] + modules, + ships ) to_search: Iterator[Mapping[str, Any]] = filter( lambda m: self.MODULE_RE.search(m['name']) and m.get('sku') in (None, HORIZ_SKU) and m['name'] != 'Int_PlanetApproachSuite', - data['lastStarport']['modules'].values() + modules.values() ) outfitting: List[str] = sorted( @@ -350,12 +381,11 @@ Msg:\n{msg}''' :param data: dict containing the shipyard data :param is_beta: whether or not we are in beta mode """ - - ships = data['lastStarport']['ships'] + modules, ships = self.safe_modules_and_ships(data) horizons: bool = is_horizons( data['lastStarport'].get('economies', {}), - data['lastStarport']['modules'], + modules, ships ) @@ -832,4 +862,3 @@ def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY logger.error(f'ships type is {type(ships)}') return economies_colony or modules_horizons or ship_horizons - From 9a8daf665e25505f2a0080efda654c2d3ec289eb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 12:03:19 +0000 Subject: [PATCH 422/727] EDDN: Restore 4.2.4 is_horizons() check in full --- plugins/eddn.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 7b9d5241..32ba121e 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -853,10 +853,14 @@ def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY if isinstance(ships, dict): if ships.get('shipyard_list') is not None: - ship_horizons = any(ship.get('sku') == HORIZ_SKU for ship in ships['shipyard_list'].values()) + if isinstance(ships.get('shipyard_list'), dict): + ship_horizons = any(ship.get('sku') == HORIZ_SKU for ship in ships['shipyard_list'].values()) + + else: + logger.debug('ships["shipyard_list"] is not dict - FC or Damaged Station?') else: - logger.debug('No ships["shipyard_list"] - Damaged station or FC ?') + logger.debug('ships["shipyard_list"] is None - FC or Damaged Station?') else: logger.error(f'ships type is {type(ships)}') From f0c6b9efaafa0a6510a198c3d14d71ca20ae858f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 12:06:37 +0000 Subject: [PATCH 423/727] EDDN: Minor logging and format fixup to match 4.2.4 --- plugins/eddn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 32ba121e..6806355c 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -307,7 +307,7 @@ Msg:\n{msg}''' elif isinstance(modules, list): if len(modules) == 0: - logger.debug('modules is empty list. Damaged Station?') + logger.debug('modules is empty list. FC or Damaged Station?') else: logger.error(f'modules is non-empty list: {modules!r}') @@ -327,7 +327,7 @@ Msg:\n{msg}''' # Set a safe value ships = {'shipyard_list': {}, 'unavailable_list': []} - return (modules, ships) + return modules, ships def export_outfitting(self, data: CAPIData, is_beta: bool) -> None: """ From 8b3294ecdd46d2317ea837f30adc3a72c5b1839a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 13:31:38 +0000 Subject: [PATCH 424/727] typeshed now handles tk 'name' parameter --- EDMarketConnector.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index de1c526a..8c595ba0 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -320,7 +320,7 @@ class AppWindow(object): self.theme_close = tk.BitmapImage( data='#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e,\n 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c,\n 0x1c, 0x38, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00 };\n') # noqa: E501 - frame = tk.Frame(self.w, name=appname.lower()) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + frame = tk.Frame(self.w, name=appname.lower()) frame.grid(sticky=tk.NSEW) frame.columnconfigure(1, weight=1) @@ -334,8 +334,8 @@ class AppWindow(object): self.system_label.grid(row=3, column=0, sticky=tk.W) self.station_label.grid(row=4, column=0, sticky=tk.W) - self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 - self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr') + self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship') self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system') self.station = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.station_url, name='station') @@ -358,7 +358,7 @@ class AppWindow(object): # Update button in main window self.button = ttk.Button(frame, text=_('Update'), width=28, default=tk.ACTIVE, state=tk.DISABLED) self.theme_button = tk.Label(frame, width=32 if platform == 'darwin' else 28, state=tk.DISABLED) - self.status = tk.Label(frame, name='status', anchor=tk.W) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.status = tk.Label(frame, name='status', anchor=tk.W) row = frame.grid_size()[1] self.button.grid(row=row, columnspan=2, sticky=tk.NSEW) @@ -384,23 +384,23 @@ class AppWindow(object): root.call('tk::unsupported::MacWindowStyle', 'style', root, 'document', 'closeBox resizable') # https://www.tcl.tk/man/tcl/TkCmd/menu.htm - self.system_menu = tk.Menu(self.menubar, name='apple') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.system_menu = tk.Menu(self.menubar, name='apple') self.system_menu.add_command(command=lambda: self.w.call('tk::mac::standardAboutPanel')) self.system_menu.add_command(command=lambda: self.updater.checkForUpdates()) self.menubar.add_cascade(menu=self.system_menu) - self.file_menu = tk.Menu(self.menubar, name='file') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.file_menu = tk.Menu(self.menubar, name='file') self.file_menu.add_command(command=self.save_raw) self.menubar.add_cascade(menu=self.file_menu) - self.edit_menu = tk.Menu(self.menubar, name='edit') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.edit_menu = tk.Menu(self.menubar, name='edit') self.edit_menu.add_command(accelerator='Command-c', state=tk.DISABLED, command=self.copy) self.menubar.add_cascade(menu=self.edit_menu) self.w.bind('', self.copy) - self.view_menu = tk.Menu(self.menubar, name='view') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.view_menu = tk.Menu(self.menubar, name='view') self.view_menu.add_command(command=lambda: stats.StatsDialog(self.w, self.status)) self.menubar.add_cascade(menu=self.view_menu) - window_menu = tk.Menu(self.menubar, name='window') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + window_menu = tk.Menu(self.menubar, name='window') self.menubar.add_cascade(menu=window_menu) - self.help_menu = tk.Menu(self.menubar, name='help') # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.help_menu = tk.Menu(self.menubar, name='help') self.w.createcommand("::tk::mac::ShowHelp", self.help_general) self.help_menu.add_command(command=self.help_privacy) self.help_menu.add_command(command=self.help_releases) @@ -436,7 +436,7 @@ class AppWindow(object): if platform == 'win32': # Must be added after at least one "real" menu entry self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) - self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) # type: ignore # https://github.com/python/typeshed/issues/4658 # noqa: E501 + self.system_menu = tk.Menu(self.menubar, name='system', tearoff=tk.FALSE) self.system_menu.add_separator() self.system_menu.add_checkbutton(label=_('Always on top'), variable=self.always_ontop, From 3f3a4f282ea1c593a40738d2150b1f322b5d087b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 14:40:03 +0000 Subject: [PATCH 425/727] app version: Write a .gitversion file with short hash from setup.py --- .gitignore | 1 + constants.py | 1 + setup.py | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/.gitignore b/.gitignore index a1e314a8..d5414bd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.gitversion .DS_Store build dist.* diff --git a/constants.py b/constants.py index 814471e4..9e757be7 100644 --- a/constants.py +++ b/constants.py @@ -9,6 +9,7 @@ found necessary to move out of other files. # config.py appname = 'EDMarketConnector' applongname = 'E:D Market Connector' +GITVERSION_FILE = '.gitversion' # protocol.py protocolhandler_redirect = 'edmc://auth' diff --git a/setup.py b/setup.py index 703f2d96..eb1e16b2 100755 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ import os import platform import re import shutil +import subprocess import sys from distutils.core import setup from os.path import exists, isdir, join @@ -21,10 +22,34 @@ from typing import Any, Generator, Set import semantic_version from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval +from constants import GITVERSION_FILE if sys.version_info[0:2] != (3, 9): raise AssertionError(f'Unexpected python version {sys.version}') +# Retrieve current git short hash and store in file GITVERSION_FILE +try: + git_cmd = subprocess.Popen('git rev-parse --short HEAD'.split(), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + out, err = git_cmd.communicate() + +except Exception as e: + print(f"Couldn't run git command for short hash: {e!r}") + exit(-1) + +else: + git_shorthash: str = out.decode().rstrip('\n') + if re.match(r'^[0-9a-f]{7,}$', git_shorthash) is None: + print(f"'{git_shorthash}' doesn't look like a valid git short hash!") + exit(-2) + + with open(GITVERSION_FILE, 'w+', encoding='utf-8') as gvf: + gvf.write(git_shorthash) + +print(f'Git short hash: {git_shorthash}') + if sys.platform == 'win32': assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit' import py2exe # noqa: F401 # Yes, this *is* used From cc571e44b12a15bd1e446d36468338e8e6fb168a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 15:03:24 +0000 Subject: [PATCH 426/727] Re-factor git short hash into a config.py function. This should clear the way for using it in running code when not frozen. --- config.py | 30 ++++++++++++++++++++++++++++++ setup.py | 28 +++++++++------------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/config.py b/config.py index 3c1e9dbb..fa2e3815 100644 --- a/config.py +++ b/config.py @@ -13,6 +13,8 @@ import functools import logging import os import pathlib +import re +import subprocess import sys import traceback import warnings @@ -89,6 +91,34 @@ elif platform == 'linux': _T = TypeVar('_T') +########################################################################### +def git_shorthash_from_head() -> str: + """ + Determine short hash for current git HEAD. + + :return: str - None if we couldn't determine the short hash. + """ + shorthash: str = None # type: ignore + try: + git_cmd = subprocess.Popen('git rev-parse --short HEAD'.split(), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + out, err = git_cmd.communicate() + + except Exception as e: + logger.error(f"Couldn't run git command for short hash: {e!r}") + + else: + shorthash = out.decode().rstrip('\n') + if re.match(r'^[0-9a-f]{7,}$', shorthash) is None: + logger.error(f"'{shorthash}' doesn't look like a valid git short hash, forcing to None") + shorthash = None # type: ignore + + return shorthash +########################################################################### + + class AbstractConfig(abc.ABC): """Abstract root class of all platform specific Config implementations.""" diff --git a/setup.py b/setup.py index eb1e16b2..c5066624 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,6 @@ import os import platform import re import shutil -import subprocess import sys from distutils.core import setup from os.path import exists, isdir, join @@ -21,34 +20,25 @@ from typing import Any, Generator, Set import semantic_version -from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval +from config import ( + appcmdname, applongname, appname, appversion, copyright, git_shorthash_from_head, update_feed, update_interval +) from constants import GITVERSION_FILE if sys.version_info[0:2] != (3, 9): raise AssertionError(f'Unexpected python version {sys.version}') +########################################################################### # Retrieve current git short hash and store in file GITVERSION_FILE -try: - git_cmd = subprocess.Popen('git rev-parse --short HEAD'.split(), - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT - ) - out, err = git_cmd.communicate() - -except Exception as e: - print(f"Couldn't run git command for short hash: {e!r}") +git_shorthash = git_shorthash_from_head() +if git_shorthash is None: exit(-1) -else: - git_shorthash: str = out.decode().rstrip('\n') - if re.match(r'^[0-9a-f]{7,}$', git_shorthash) is None: - print(f"'{git_shorthash}' doesn't look like a valid git short hash!") - exit(-2) - - with open(GITVERSION_FILE, 'w+', encoding='utf-8') as gvf: - gvf.write(git_shorthash) +with open(GITVERSION_FILE, 'w+', encoding='utf-8') as gvf: + gvf.write(git_shorthash) print(f'Git short hash: {git_shorthash}') +########################################################################### if sys.platform == 'win32': assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit' From dcc4f1c4f17515c77c846112801c71ddc09dad0e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 15:22:53 +0000 Subject: [PATCH 427/727] Begin converting config.appversion to a function. In-place converstion done, next will be all the call sites. --- config.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index fa2e3815..2b83f0b4 100644 --- a/config.py +++ b/config.py @@ -24,17 +24,25 @@ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Type, Typ import semantic_version -from constants import applongname, appname +from constants import GITVERSION_FILE, applongname, appname # Any of these may be imported by plugins appcmdname = 'EDMC' +# Replacing appversion with a function: +# +# 1. In setup.py grab the current HEAD short hash and place in a file .gitversion +# 2. config.py code then needs to check: +# a. If we're not frozen and .git/ exists (i.e. not from a tarball ?) use something to get the current HEAD +# b. If not frozen and no .gitversion (but there should be) ??? +# c. If frozen, just read the .gitversion (that had better damned well be there, but catch if it's not). +# 3. But I don't want to spam EDDN with different 5.0.0-beta1+shorthash when testing... so ??? # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '5.0.0-beta1' # -rc1+a872b5f' +static_appversion = '5.0.0-beta1' # For some things we want appversion without (possible) +build metadata -appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) -copyright = '© 2015-2019 Jonathan Harris, 2020 EDCD' +static_appversion_nobuild = str(semantic_version.Version(static_appversion).truncate('prerelease')) +copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' update_interval = 8*60*60 @@ -116,6 +124,27 @@ def git_shorthash_from_head() -> str: shorthash = None # type: ignore return shorthash + + +def appversion() -> str: + if getattr(sys, 'frozen', False): + # Running frozen, so we should have a .gitversion file + with open(GITVERSION_FILE, 'r', encoding='utf-8') as gitv: + shorthash = gitv.read() + + # TODO: Check if there was already a build meta data in static_appversion ? + + else: + # Running from source + shorthash = git_shorthash_from_head() + if shorthash is None: + shorthash = 'UNKNOWN' + + return f'{static_appversion}+{shorthash}' + + +def appversion_nobuild() -> str: + return str(semantic_version.Version(appversion()).truncate('prerelease')) ########################################################################### From 2f9789afdde511567ba849afbdc98606f2876895 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 15:44:18 +0000 Subject: [PATCH 428/727] Update all code to use config.appversion() as a function This *also* caught some instances where appversion_nobuild should already have been used, so those were both changed and updated to a function call. --- EDMC.py | 6 +++--- EDMarketConnector.py | 10 +++++----- companion.py | 2 +- killswitch.py | 2 +- plugins/eddn.py | 4 ++-- plugins/edsm.py | 2 +- plugins/inara.py | 2 +- prefs.py | 4 ++-- setup.py | 20 ++++++++++---------- td.py | 2 +- update.py | 8 +++++--- 11 files changed, 32 insertions(+), 30 deletions(-) diff --git a/EDMC.py b/EDMC.py index d4aaf37d..a1b32a47 100755 --- a/EDMC.py +++ b/EDMC.py @@ -145,9 +145,9 @@ def main(): updater = Updater(provider='internal') newversion: Optional[EDMCVersion] = updater.check_appcast() if newversion: - print(f'{appversion} ({newversion.title!r} is available)') + print(f'{appversion()} ({newversion.title!r} is available)') else: - print(appversion) + print(appversion()) return @@ -160,7 +160,7 @@ def main(): sys.exit(EXIT_ARGS) edmclogger.set_channels_loglevel(args.loglevel) - logger.debug(f'Startup v{appversion} : Running on Python v{sys.version}') + logger.debug(f'Startup v{appversion()} : Running on Python v{sys.version}') logger.debug(f'''Platform: {sys.platform} argv[0]: {sys.argv[0]} exec_prefix: {sys.exec_prefix} diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 8c595ba0..5161f574 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1147,11 +1147,11 @@ class AppWindow(object): # version ttk.Label(frame).grid(row=row, column=0) # spacer row += 1 - self.appversion_label = tk.Label(frame, text=appversion) + self.appversion_label = tk.Label(frame, text=appversion()) self.appversion_label.grid(row=row, column=0, sticky=tk.E) self.appversion = HyperlinkLabel(frame, compound=tk.RIGHT, text=_('Release Notes'), url='https://github.com/EDCD/EDMarketConnector/releases/tag/Release/' - f'{appversion_nobuild}', + f'{appversion_nobuild()}', underline=True) self.appversion.grid(row=row, column=2, sticky=tk.W) row += 1 @@ -1180,7 +1180,7 @@ class AppWindow(object): self.protocol("WM_DELETE_WINDOW", self._destroy) ############################################################ - logger.info(f'Current version is {appversion}') + logger.info(f'Current version is {appversion()}') def apply(self) -> None: """Close the window.""" @@ -1395,7 +1395,7 @@ def show_killswitch_poppup(root=None): # Run the app if __name__ == "__main__": # noqa: C901 - logger.info(f'Startup v{appversion} : Running on Python v{sys.version}') + logger.info(f'Startup v{appversion()} : Running on Python v{sys.version}') logger.debug(f'''Platform: {sys.platform} {sys.platform == "win32" and sys.getwindowsversion()} argv[0]: {sys.argv[0]} exec_prefix: {sys.exec_prefix} @@ -1493,7 +1493,7 @@ sys.path: {sys.path}''' # abinit = A.B() # Plain, not via `logger` - print(f'{applongname} {appversion}') + print(f'{applongname} {appversion()}') Translations.install(config.get_str('language')) # Can generate errors so wait til log set up diff --git a/companion.py b/companion.py index beb0b69e..d9972743 100644 --- a/companion.py +++ b/companion.py @@ -55,7 +55,7 @@ SERVER_AUTH = 'https://auth.frontierstore.net' URL_AUTH = '/auth' URL_TOKEN = '/token' -USER_AGENT = f'EDCD-{appname}-{appversion}' +USER_AGENT = f'EDCD-{appname}-{appversion()}' SERVER_LIVE = 'https://companion.orerve.net' SERVER_BETA = 'https://pts-companion.orerve.net' diff --git a/killswitch.py b/killswitch.py index 84dfd048..cb75c2cf 100644 --- a/killswitch.py +++ b/killswitch.py @@ -11,7 +11,7 @@ logger = EDMCLogging.get_main_logger() DEFAULT_KILLSWITCH_URL = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/killswitches.json' -_current_version: semantic_version.Version = semantic_version.Version(config.appversion) +_current_version: semantic_version.Version = semantic_version.Version(config.appversion_nobuild()) class KillSwitch(NamedTuple): diff --git a/plugins/eddn.py b/plugins/eddn.py index 6806355c..14dd407e 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -20,7 +20,7 @@ import killswitch import myNotebook as nb # noqa: N813 import plug from companion import CAPIData, category_map -from config import applongname, appversion, config +from config import applongname, appversion_nobuild, config from EDMCLogging import get_main_logger from myNotebook import Frame from prefs import prefsVersion @@ -141,7 +141,7 @@ class EDDN: ('$schemaRef', msg['$schemaRef']), ('header', OrderedDict([ ('softwareName', f'{applongname} [{system() if sys.platform != "darwin" else "Mac OS"}]'), - ('softwareVersion', appversion), + ('softwareVersion', appversion_nobuild()), ('uploaderID', uploader_id), ])), ('message', msg['message']), diff --git a/plugins/edsm.py b/plugins/edsm.py index fc46a5a3..e61fa5ab 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -573,7 +573,7 @@ def worker() -> None: 'commanderName': username.encode('utf-8'), 'apiKey': apikey, 'fromSoftware': applongname, - 'fromSoftwareVersion': appversion, + 'fromSoftwareVersion': appversion(), 'message': json.dumps(pending, ensure_ascii=False).encode('utf-8'), } diff --git a/plugins/inara.py b/plugins/inara.py index 292d59b3..c7333b0a 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1222,7 +1222,7 @@ def new_worker(): data = { 'header': { 'appName': applongname, - 'appVersion': appversion, + 'appVersion': appversion(), 'APIkey': creds.api_key, 'commanderName': creds.cmdr, 'commanderFrontierID': creds.fid diff --git a/prefs.py b/prefs.py index 99d441ab..81c850c8 100644 --- a/prefs.py +++ b/prefs.py @@ -14,7 +14,7 @@ from typing import TYPE_CHECKING, Any, Callable, Optional, Type, Union import myNotebook as nb # noqa: N813 import plug -from config import applongname, appversion, config +from config import applongname, appversion_nobuild, config from EDMCLogging import edmclogger, get_main_logger from hotkey import hotkeymgr from l10n import Translations @@ -1122,7 +1122,7 @@ class PreferencesDialog(tk.Toplevel): def apply(self) -> None: """Update the config with the options set on the dialog.""" - config.set('PrefsVersion', prefsVersion.stringToSerial(appversion)) + config.set('PrefsVersion', prefsVersion.stringToSerial(appversion_nobuild())) config.set( 'output', (self.out_td.get() and config.OUT_MKT_TD) + diff --git a/setup.py b/setup.py index c5066624..9cd8721d 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,8 @@ from typing import Any, Generator, Set import semantic_version from config import ( - appcmdname, applongname, appname, appversion, copyright, git_shorthash_from_head, update_feed, update_interval + appcmdname, applongname, appname, appversion, appversion_nobuild, copyright, git_shorthash_from_head, update_feed, + update_interval ) from constants import GITVERSION_FILE @@ -52,7 +53,7 @@ else: assert False, f'Unsupported platform {sys.platform}' # Split version, as py2exe wants the 'base' for version -semver = semantic_version.Version.coerce(appversion) +semver = semantic_version.Version.coerce(appversion()) base_appversion = str(semver.truncate('patch')) if dist_dir and len(dist_dir) > 1 and isdir(dist_dir): @@ -89,7 +90,6 @@ if sys.platform == 'darwin': APP = 'EDMarketConnector.py' APPCMD = 'EDMC.py' -SHORTappversion = ''.join(appversion.split('.')[:3]) PLUGINS = [ 'plugins/coriolis.py', 'plugins/eddb.py', @@ -154,8 +154,8 @@ if sys.platform == 'darwin': 'CFBundleName': applongname, 'CFBundleIdentifier': f'uk.org.marginal.{appname.lower()}', 'CFBundleLocalizations': get_cfbundle_localizations(), - 'CFBundleShortVersionString': appversion, - 'CFBundleVersion': appversion, + 'CFBundleShortVersionString': appversion(), + 'CFBundleVersion': appversion(), 'CFBundleURLTypes': [ { 'CFBundleTypeRole': 'Viewer', @@ -228,7 +228,7 @@ elif sys.platform == 'win32': setup( name=applongname, - version=appversion, + version=appversion(), windows=[ { 'dest_base': appname, @@ -237,7 +237,7 @@ setup( 'company_name': 'EDCD', # Used by WinSparkle 'product_name': appname, # Used by WinSparkle 'version': base_appversion, - 'product_version': appversion, + 'product_version': appversion(), 'copyright': copyright, 'other_resources': [(24, 1, open(f'{appname}.manifest').read())], } @@ -249,7 +249,7 @@ setup( 'company_name': 'EDCD', 'product_name': appname, 'version': base_appversion, - 'product_version': appversion, + 'product_version': appversion(), 'copyright': copyright, 'other_resources': [(24, 1, open(f'{appcmdname}.manifest').read())], } @@ -279,7 +279,7 @@ if sys.platform == 'darwin': os.system(f'codesign --deep -v -s "Developer ID Application: {macdeveloperid}" {dist_dir}/{appname}.app') # Make zip for distribution, preserving signature - package_filename = f'{appname}_mac_{appversion}.zip' + package_filename = f'{appname}_mac_{appversion_nobuild()}.zip' os.system(f'cd {dist_dir}; ditto -ck --keepParent --sequesterRsrc {appname}.app ../{package_filename}; cd ..') elif sys.platform == 'win32': @@ -288,7 +288,7 @@ elif sys.platform == 'win32': if not exists(f'{dist_dir}/{appname}.wixobj'): raise AssertionError(f'No {dist_dir}/{appname}.wixobj: candle.exe failed?') - package_filename = f'{appname}_win_{appversion}.msi' + package_filename = f'{appname}_win_{appversion_nobuild()}.msi' os.system(rf'"{WIXPATH}\light.exe" -sacl -spdb -sw1076 {dist_dir}\{appname}.wixobj -out {package_filename}') if not exists(package_filename): diff --git a/td.py b/td.py index 799d68ec..f38a828f 100644 --- a/td.py +++ b/td.py @@ -34,7 +34,7 @@ def export(data): '#\n# \n\n' '@ {system}/{starport}\n'.format( appname=applongname, - appversion=appversion, + appversion=appversion(), platform=platform == 'darwin' and "Mac OS" or system(), cmdr=data['commander']['name'].strip(), system=data['lastSystem']['name'].strip(), diff --git a/update.py b/update.py index de7eb8cd..e71f39b9 100644 --- a/update.py +++ b/update.py @@ -9,7 +9,8 @@ if TYPE_CHECKING: import tkinter as tk # ensure registry is set up on Windows before we start -from config import appname, appversion, appversion_nobuild, config, update_feed +from config import appname, appversion_nobuild, config, update_feed + class EDMCVersion(object): """ @@ -29,6 +30,7 @@ class EDMCVersion(object): self.title: str = title self.sv: semantic_version.base.Version = sv + class Updater(object): """ Updater class to handle checking for updates, whether using internal code @@ -79,7 +81,7 @@ class Updater(object): # NB: It 'accidentally' supports pre-release due to how it # splits and compares strings: # - self.updater.win_sparkle_set_app_build_version(appversion_nobuild) + self.updater.win_sparkle_set_app_build_version(appversion_nobuild()) # set up shutdown callback global root @@ -175,7 +177,7 @@ class Updater(object): ) # Look for any remaining version greater than appversion - simple_spec = semantic_version.SimpleSpec('>' + appversion) + simple_spec = semantic_version.SimpleSpec('>' + appversion_nobuild()) newversion = simple_spec.select(items.keys()) if newversion: From a3129a38c8c55023c6da6badd4229790a6a5bf82 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 15:49:14 +0000 Subject: [PATCH 429/727] build: Somehow ko.strings got left out of .wxs 'Feature' And thus didn't make it into builds. Probably an issue with the develop rebase. --- EDMarketConnector.wxs | 1 + 1 file changed, 1 insertion(+) diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index 4f4d8031..ace4e591 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -585,6 +585,7 @@ + From fbd94c68aaa9679e4c63da25ca56aa4045643546 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 25 Mar 2021 15:54:48 +0000 Subject: [PATCH 430/727] build: .gitversion in DATA_FILES and installer. --- EDMarketConnector.wxs | 4 ++++ setup.py | 1 + 2 files changed, 5 insertions(+) diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index ace4e591..67fa5366 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -239,6 +239,9 @@ + + + @@ -555,6 +558,7 @@ + diff --git a/setup.py b/setup.py index 9cd8721d..3e67f846 100755 --- a/setup.py +++ b/setup.py @@ -207,6 +207,7 @@ elif sys.platform == 'win32': DATA_FILES = [ ('', [ + '.gitversion', # Contains git short hash 'WinSparkle.dll', 'WinSparkle.pdb', # For debugging - don't include in package 'EUROCAPS.TTF', From 7a8b1100e9b7988bfaca44259e330ecf6d591c22 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 10:52:39 +0000 Subject: [PATCH 431/727] config.py: Remove static_appversion_nobuild, and point to functions * Also renamed static_appversion to have leading _ to further discourage use. --- config.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 2b83f0b4..a3d30c71 100644 --- a/config.py +++ b/config.py @@ -39,9 +39,8 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -static_appversion = '5.0.0-beta1' -# For some things we want appversion without (possible) +build metadata -static_appversion_nobuild = str(semantic_version.Version(static_appversion).truncate('prerelease')) +# NB: Do *not* import this, use the functions appversion() and appversion_nobuild() +_static_appversion = '5.0.0-beta1' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' @@ -140,7 +139,7 @@ def appversion() -> str: if shorthash is None: shorthash = 'UNKNOWN' - return f'{static_appversion}+{shorthash}' + return f'{_static_appversion}+{shorthash}' def appversion_nobuild() -> str: From 9444973ebd9202c080ce59cbdcf4799bcd2cf81d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 10:55:24 +0000 Subject: [PATCH 432/727] config.py: docstring new appversion() and appversion_nobuild() --- config.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config.py b/config.py index a3d30c71..53e7d15c 100644 --- a/config.py +++ b/config.py @@ -126,6 +126,11 @@ def git_shorthash_from_head() -> str: def appversion() -> str: + """ + Determine app version including git short hash if possible. + + :return: str - The augmented app version. + """ if getattr(sys, 'frozen', False): # Running frozen, so we should have a .gitversion file with open(GITVERSION_FILE, 'r', encoding='utf-8') as gitv: @@ -143,6 +148,14 @@ def appversion() -> str: def appversion_nobuild() -> str: + """ + Determine app version without *any* build meta data. + + This will not only strip any added git short hash, but also any trailing + '+' in _static_appversion. + + :return: str - App version without any build meta data. + """ return str(semantic_version.Version(appversion()).truncate('prerelease')) ########################################################################### From 9a185e91cae80ca50dcd7507b318b7ccb43f225f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 11:30:06 +0000 Subject: [PATCH 433/727] config.py: Add a lot of docstrings to Config class methods. I settled on having the full docstring only in the AbstractConfig definitions. In the implementations we then have: """ Implements :meth:`AbstractConfig.`. """ --- config.py | 129 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 49 deletions(-) diff --git a/config.py b/config.py index 53e7d15c..fbc092d6 100644 --- a/config.py +++ b/config.py @@ -195,17 +195,29 @@ class AbstractConfig(abc.ABC): self.home_path = pathlib.Path.home() def set_shutdown(self): + """Set flag denoting we're in the shutdown sequence.""" self.__in_shutdown = True @property def shutting_down(self) -> bool: + """ + Determine if we're in the shutdown sequence. + + :return: bool - True if in shutdown sequence. + """ return self.__in_shutdown def set_auth_force_localserver(self): + """Set flag to force use of localhost web server for Frontier Auth callback.""" self.__auth_force_localserver = True @property def auth_force_localserver(self) -> bool: + """ + Determine if use of localhost is forced for Frontier Auth callback. + + :return: bool - True if we should use localhost web server. + """ return self.__auth_force_localserver @property @@ -256,7 +268,7 @@ class AbstractConfig(abc.ABC): def get(self, key: str, default: Union[list, str, bool, int] = None) -> Union[list, str, bool, int]: """ - Get the requested key, or a default. + Return the requested key, or a default. :param key: the key to get :param default: the default to return if the key does not exist, defaults to None @@ -283,20 +295,16 @@ class AbstractConfig(abc.ABC): @abstractmethod def get_list(self, key: str, *, default: list = None) -> list: """ - Get the list referred to by the given key if it exists, or the default. + Return the list referred to by the given key if it exists, or the default. - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to None - :raises ValueError: If an internal error occurs getting or converting a value - :raises OSError: on windows, if a registry error occurs. - :return: The requested data or the default + Implements :meth:`AbstractConfig.get_list()`. """ raise NotImplementedError @abstractmethod def get_str(self, key: str, *, default: str = None) -> str: """ - Get the string referred to by the given key if it exists, or the default. + Return the string referred to by the given key if it exists, or the default. :param key: The key to search for :param default: Default to return if the key does not exist, defaults to None @@ -309,7 +317,7 @@ class AbstractConfig(abc.ABC): @abstractmethod def get_bool(self, key: str, *, default: bool = None) -> bool: """ - Get the bool referred to by the given key if it exists, or the default. + Return the bool referred to by the given key if it exists, or the default. :param key: The key to search for :param default: Default to return if the key does not exist, defaults to None @@ -334,7 +342,7 @@ class AbstractConfig(abc.ABC): @abstractmethod def get_int(self, key: str, *, default: int = 0) -> int: """ - Get the int referred to by key if it exists in the config. + Return the int referred to by key if it exists in the config. For legacy reasons, the default is 0 and not None. @@ -348,7 +356,14 @@ class AbstractConfig(abc.ABC): @abstractmethod def set(self, key: str, val: Union[int, str, List[str], bool]) -> None: - """Set the given key to the given data.""" + """ + Set the given key's value to the given value. + + :param key: The key to set the value on. + :param val: The value to set the key's data to. + :raises ValueError: On an invalid type. + :raises OSError: On any internal failure to the registry. + """ raise NotImplementedError @abstractmethod @@ -492,12 +507,9 @@ class WinConfig(AbstractConfig): def get_str(self, key: str, *, default: str = None) -> str: """ - Return the string represented by the key, or the default if it does not exist. + Return the string referred to by the given key if it exists, or the default. - :param key: the key to access - :param default: the default to return when the key does not exist, defaults to None - :raises ValueError: when the key is not a string type - :return: the requested data, or the default + Implements :meth:`AbstractConfig.get_str()`. """ res = self.__get_regentry(key) if res is None: @@ -510,12 +522,9 @@ class WinConfig(AbstractConfig): def get_list(self, key: str, *, default: list = None) -> list: """ - Return the list found at the given key, or the default if none exists. + Return the list referred to by the given key if it exists, or the default. - :param key: The key to access - :param default: Default to return when the key does not exist, defaults to None - :raises ValueError: When the data at the given key is not a list - :return: the requested data or the default + Implements :meth:`AbstractConfig.get_list()`. """ res = self.__get_regentry(key) if res is None: @@ -528,12 +537,9 @@ class WinConfig(AbstractConfig): def get_int(self, key: str, *, default: int = 0) -> int: """ - Return the int found at the given key, or the default if none exists. + Return the int referred to by key if it exists in the config. - :param key: The key to access - :param default: Default to return when the key does not exist, defaults to 0 - :raises ValueError: If the data returned is of an unexpected type - :return: the data requested or the default + Implements :meth:`AbstractConfig.get_int()`. """ res = self.__get_regentry(key) if res is None: @@ -546,12 +552,9 @@ class WinConfig(AbstractConfig): def get_bool(self, key: str, *, default: bool = None) -> bool: """ - Return the bool found at the given key, or the default if none exists. + Return the bool referred to by the given key if it exists, or the default. - :param key: The key to access - :param default: Default to return when key does not exist, defaults to None - :raises ValueError: If the data returned is of an unexpected type - :return: The data requested or the default + Implements :meth:`AbstractConfig.get_bool()`. """ res = self.get_int(key) if res is None: @@ -590,6 +593,15 @@ class WinConfig(AbstractConfig): winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore def delete(self, key: str, *, suppress=False) -> None: + """ + Remove the given key from the Windows Registry. + + 'key' is relative to the base path we use. + + :param key: str - The name of the sub-key to be removed. + :param suppress: bool - Whether to suppress any errors. Useful in case + code to migrate settings is blindly removing an old key. + """ try: winreg.DeleteValue(self.__reg_handle, key) except OSError: @@ -599,12 +611,15 @@ class WinConfig(AbstractConfig): raise def save(self) -> None: - """Save the configuration.""" - # Not required as reg keys are flushed on write + """ + Save the configuration. + + Not required for WinConfig as reg keys are flushed on write. + """ pass def close(self): - """Close the config file.""" + """Close the Registry handle.""" self.__reg_handle.Close() @@ -665,12 +680,9 @@ class MacConfig(AbstractConfig): def get_str(self, key: str, *, default: str = None) -> str: """ - Return the string represented by the key, or the default if it does not exist. + Return the string referred to by the given key if it exists, or the default. - :param key: the key to access - :param default: the default to return when the key does not exist, defaults to None - :raises ValueError: when the key is not a string type - :return: the requested data, or the default + Implements :meth:`AbstractConfig.get_str()`. """ res = self.__raw_get(key) if res is None: @@ -683,12 +695,9 @@ class MacConfig(AbstractConfig): def get_list(self, key: str, *, default: list = None) -> list: """ - Return the list found at the given key, or the default if none exists. + Return the list referred to by the given key if it exists, or the default. - :param key: The key to access - :param default: Default to return when the key does not exist, defaults to None - :raises ValueError: When the data at the given key is not a list - :return: the requested data or the default + Implements :meth:`AbstractConfig.get_list()`. """ res = self.__raw_get(key) if res is None: @@ -701,12 +710,9 @@ class MacConfig(AbstractConfig): def get_int(self, key: str, *, default: int = 0) -> int: """ - Return the int found at the given key, or the default if none exists. + Return the int referred to by key if it exists in the config. - :param key: The key to access - :param default: Default to return when the key does not exist, defaults to 0 - :raises ValueError: If the data returned is of an unexpected type - :return: the data requested or the default + Implements :meth:`AbstractConfig.get_int()`. """ res = self.__raw_get(key) if res is None: @@ -723,6 +729,11 @@ class MacConfig(AbstractConfig): return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default def get_bool(self, key: str, *, default: bool = None) -> bool: + """ + Return the bool referred to by the given key if it exists, or the default. + + Implements :meth:`AbstractConfig.get_bool()`. + """ res = self.__raw_get(key) if res is None: return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default @@ -854,6 +865,11 @@ class LinuxConfig(AbstractConfig): return self.config[self.SECTION].get(key) def get_str(self, key: str, *, default: str = None) -> str: + """ + Return the string referred to by the given key if it exists, or the default. + + Implements :meth:`AbstractConfig.get_str()`. + """ data = self.__raw_get(key) if data is None: return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default @@ -864,6 +880,11 @@ class LinuxConfig(AbstractConfig): return self.__unescape(data) def get_list(self, key: str, *, default: list = None) -> list: + """ + Return the list referred to by the given key if it exists, or the default. + + Implements :meth:`AbstractConfig.get_list()`. + """ data = self.__raw_get(key) if data is None: @@ -876,6 +897,11 @@ class LinuxConfig(AbstractConfig): return list(map(self.__unescape, split[:-1])) def get_int(self, key: str, *, default: int = 0) -> int: + """ + Return the int referred to by key if it exists in the config. + + Implements :meth:`AbstractConfig.get_int()`. + """ data = self.__raw_get(key) if data is None: @@ -888,6 +914,11 @@ class LinuxConfig(AbstractConfig): raise ValueError(f'requested {key=} as int cannot be converted to int') from e def get_bool(self, key: str, *, default: bool = None) -> bool: + """ + Return the bool referred to by the given key if it exists, or the default. + + Implements :meth:`AbstractConfig.get_bool`. + """ if self.config is None: raise ValueError('attempt to use a closed config') From 6d2a0e29ee886472b608df7e243b1eb4f23cc94f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 11:48:29 +0000 Subject: [PATCH 434/727] Bring MacConfig.set() in line with other implmentations. * It wasn't doing any value type validation. * Also dropped the `()` from the 'Implements' lines. --- config.py | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/config.py b/config.py index fbc092d6..0bd74054 100644 --- a/config.py +++ b/config.py @@ -297,7 +297,7 @@ class AbstractConfig(abc.ABC): """ Return the list referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_list()`. + Implements :meth:`AbstractConfig.get_list`. """ raise NotImplementedError @@ -357,12 +357,12 @@ class AbstractConfig(abc.ABC): @abstractmethod def set(self, key: str, val: Union[int, str, List[str], bool]) -> None: """ - Set the given key's value to the given value. + Set the given key's data to the given value. :param key: The key to set the value on. :param val: The value to set the key's data to. :raises ValueError: On an invalid type. - :raises OSError: On any internal failure to the registry. + :raises OSError: On Windows for any Registry failure. """ raise NotImplementedError @@ -509,7 +509,7 @@ class WinConfig(AbstractConfig): """ Return the string referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_str()`. + Implements :meth:`AbstractConfig.get_str`. """ res = self.__get_regentry(key) if res is None: @@ -524,7 +524,7 @@ class WinConfig(AbstractConfig): """ Return the list referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_list()`. + Implements :meth:`AbstractConfig.get_list`. """ res = self.__get_regentry(key) if res is None: @@ -539,7 +539,7 @@ class WinConfig(AbstractConfig): """ Return the int referred to by key if it exists in the config. - Implements :meth:`AbstractConfig.get_int()`. + Implements :meth:`AbstractConfig.get_int`. """ res = self.__get_regentry(key) if res is None: @@ -554,7 +554,7 @@ class WinConfig(AbstractConfig): """ Return the bool referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_bool()`. + Implements :meth:`AbstractConfig.get_bool`. """ res = self.get_int(key) if res is None: @@ -564,12 +564,9 @@ class WinConfig(AbstractConfig): def set(self, key: str, val: Union[int, str, List[str], bool]) -> None: """ - Set sets the given key to the given value. + Set the given key's data to the given value. - :param key: The key to set the value to - :param val: The value to set the key - :raises ValueError: On an invalid type - :raises OSError: On any internal failure to the registry + Implements :meth:`AbstractConfig.set`. """ reg_type = None if isinstance(val, str): @@ -682,7 +679,7 @@ class MacConfig(AbstractConfig): """ Return the string referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_str()`. + Implements :meth:`AbstractConfig.get_str`. """ res = self.__raw_get(key) if res is None: @@ -697,7 +694,7 @@ class MacConfig(AbstractConfig): """ Return the list referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_list()`. + Implements :meth:`AbstractConfig.get_list`. """ res = self.__raw_get(key) if res is None: @@ -712,7 +709,7 @@ class MacConfig(AbstractConfig): """ Return the int referred to by key if it exists in the config. - Implements :meth:`AbstractConfig.get_int()`. + Implements :meth:`AbstractConfig.get_int`. """ res = self.__raw_get(key) if res is None: @@ -732,7 +729,7 @@ class MacConfig(AbstractConfig): """ Return the bool referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_bool()`. + Implements :meth:`AbstractConfig.get_bool`. """ res = self.__raw_get(key) if res is None: @@ -745,11 +742,16 @@ class MacConfig(AbstractConfig): def set(self, key: str, val: Union[int, str, List[str], bool]) -> None: """ - Set sets the given key to the given value. + Set the given key's data to the given value. - :param key: The key to set the value to - :param val: The value to set the key + Implements :meth:`AbstractConfig.set`. """ + if self._settings is None: + raise ValueError('attempt to use a closed _settings') + + if not isinstance(val, (bool, str, int, list)): + raise ValueError(f'Unexpected type for value {type(val)=}') + self._settings[key] = val def delete(self, key: str, *, suppress=False) -> None: @@ -868,7 +870,7 @@ class LinuxConfig(AbstractConfig): """ Return the string referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_str()`. + Implements :meth:`AbstractConfig.get_str`. """ data = self.__raw_get(key) if data is None: @@ -883,7 +885,7 @@ class LinuxConfig(AbstractConfig): """ Return the list referred to by the given key if it exists, or the default. - Implements :meth:`AbstractConfig.get_list()`. + Implements :meth:`AbstractConfig.get_list`. """ data = self.__raw_get(key) @@ -900,7 +902,7 @@ class LinuxConfig(AbstractConfig): """ Return the int referred to by key if it exists in the config. - Implements :meth:`AbstractConfig.get_int()`. + Implements :meth:`AbstractConfig.get_int`. """ data = self.__raw_get(key) @@ -929,6 +931,11 @@ class LinuxConfig(AbstractConfig): return bool(int(data)) def set(self, key: str, val: Union[int, str, List[str]]) -> None: + """ + Set the given key's data to the given value. + + Implements :meth:`AbstractConfig.set`. + """ if self.config is None: raise ValueError('attempt to use a closed config') @@ -946,7 +953,7 @@ class LinuxConfig(AbstractConfig): to_set = '\n'.join([self.__escape(s) for s in val] + [';']) else: - raise NotImplementedError(f'value of type {type(val)} is not supported') + raise ValueError(f'Unexpected type for value {type(val)=}') self.config.set(self.SECTION, key, to_set) From 52a64d3fb641b7179fe322b221fad4289126038d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 11:55:04 +0000 Subject: [PATCH 435/727] config.py: Last few docstrings * Implementations of: delete(), save(), close(). * get_config() --- config.py | 58 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/config.py b/config.py index 0bd74054..d3e8a205 100644 --- a/config.py +++ b/config.py @@ -372,7 +372,9 @@ class AbstractConfig(abc.ABC): Delete the given key from the config. :param key: The key to delete - :raises OSError: on windows, if a registry error occurs. + :param suppress: bool - Whether to suppress any errors. Useful in case + code to migrate settings is blindly removing an old key. + :raises OSError: On Windows, if a registry error occurs. """ raise NotImplementedError @@ -381,7 +383,7 @@ class AbstractConfig(abc.ABC): """ Save the current configuration. - :raises OSError: on windows, if a registry error occurs. + :raises OSError: On Windows, if a Registry error occurs. """ raise NotImplementedError @@ -591,13 +593,11 @@ class WinConfig(AbstractConfig): def delete(self, key: str, *, suppress=False) -> None: """ - Remove the given key from the Windows Registry. + Delete the given key from the config. - 'key' is relative to the base path we use. + 'key' is relative to the base Registry path we use. - :param key: str - The name of the sub-key to be removed. - :param suppress: bool - Whether to suppress any errors. Useful in case - code to migrate settings is blindly removing an old key. + Implements :meth:`AbstractConfig.delete`. """ try: winreg.DeleteValue(self.__reg_handle, key) @@ -611,12 +611,16 @@ class WinConfig(AbstractConfig): """ Save the configuration. - Not required for WinConfig as reg keys are flushed on write. + Not required for WinConfig as Registry keys are flushed on write. """ pass def close(self): - """Close the Registry handle.""" + """ + Close this config and release any associated resources. + + Implements :meth:`AbstractConfig.close`. + """ self.__reg_handle.Close() @@ -758,7 +762,7 @@ class MacConfig(AbstractConfig): """ Delete the given key from the config. - :param key: the key to delete + Implements :meth:`AbstractConfig.delete`. """ try: del self._settings[key] @@ -768,12 +772,20 @@ class MacConfig(AbstractConfig): pass def save(self) -> None: - """Save the configuration.""" + """ + Save the current configuration. + + Implements :meth:`AbstractConfig.save`. + """ self._defaults.setPersistentDomain_forName_(self._settings, self.identifier) self._defaults.synchronize() def close(self) -> None: - """Close the configuration.""" + """ + Close this config and release any associated resources. + + Implements :meth:`AbstractConfig.close`. + """ self.save() self._defaults = None @@ -958,12 +970,22 @@ class LinuxConfig(AbstractConfig): self.config.set(self.SECTION, key, to_set) def delete(self, key: str, *, suppress=False) -> None: + """ + Delete the given key from the config. + + Implements :meth:`AbstractConfig.delete`. + """ if self.config is None: raise ValueError('attempt to use a closed config') self.config.remove_option(self.SECTION, key) def save(self) -> None: + """ + Save the current configuration. + + Implements :meth:`AbstractConfig.save`. + """ if self.config is None: raise ValueError('attempt to use a closed config') @@ -971,11 +993,23 @@ class LinuxConfig(AbstractConfig): self.config.write(f) def close(self) -> None: + """ + Close this config and release any associated resources. + + Implements :meth:`AbstractConfig.close`. + """ self.save() self.config = None def get_config(*args, **kwargs) -> AbstractConfig: + """ + Get the appropriate config class for the current platform. + + :param args: Args to be passed through to implementation. + :param kwargs: Args to be passed through to implementation. + :return: Instance of the implementation. + """ if sys.platform == "darwin": return MacConfig(*args, **kwargs) elif sys.platform == "win32": From e37c635a84c29ae4334fed4c789133b63534dd20 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 12:09:18 +0000 Subject: [PATCH 436/727] config.py: docstring pass for consistency. --- config.py | 75 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/config.py b/config.py index d3e8a205..95fcc78c 100644 --- a/config.py +++ b/config.py @@ -1,8 +1,9 @@ """ Code dealing with the configuration of the program. -On Windows this uses the Registry to store values in a flat manner. +Windows uses the Registry to store values in a flat manner. Linux uses a file, but for commonality it's still a flat data structure. +macOS uses a 'defaults' object. """ # spell-checker: words HKEY FOLDERID wchar wstring edcdhkey @@ -268,12 +269,12 @@ class AbstractConfig(abc.ABC): def get(self, key: str, default: Union[list, str, bool, int] = None) -> Union[list, str, bool, int]: """ - Return the requested key, or a default. + Return the data for the requested key, or a default. - :param key: the key to get - :param default: the default to return if the key does not exist, defaults to None - :raises OSError: on windows, if a registry error occurs. - :return: the data or the default + :param key: The key data is being requested for. + :param default: The default to return if the key does not exist, defaults to None. + :raises OSError: On Windows, if a Registry error occurs. + :return: The data or the default. """ warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type')) logger.debug('Attempt to use Deprecated get() method\n' + ''.join(traceback.format_stack())) @@ -306,11 +307,11 @@ class AbstractConfig(abc.ABC): """ Return the string referred to by the given key if it exists, or the default. - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to None - :raises ValueError: If an internal error occurs getting or converting a value - :raises OSError: on windows, if a registry error occurs. - :return: The requested data or the default + :param key: The key data is being requested for. + :param default: Default to return if the key does not exist, defaults to None. + :raises ValueError: If an internal error occurs getting or converting a value. + :raises OSError: On Windows, if a Registry error occurs. + :return: The requested data or the default. """ raise NotImplementedError @@ -319,10 +320,10 @@ class AbstractConfig(abc.ABC): """ Return the bool referred to by the given key if it exists, or the default. - :param key: The key to search for + :param key: The key data is being requested for. :param default: Default to return if the key does not exist, defaults to None :raises ValueError: If an internal error occurs getting or converting a value - :raises OSError: on windows, if a registry error occurs. + :raises OSError: On Windows, if a Registry error occurs. :return: The requested data or the default """ raise NotImplementedError @@ -332,7 +333,7 @@ class AbstractConfig(abc.ABC): Getint is a Deprecated getter method. See get_int for its replacement. - :raises OSError: on windows, if a registry error occurs. + :raises OSError: On Windows, if a Registry error occurs. """ warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead')) logger.debug('Attempt to use Deprecated getint() method\n' + ''.join(traceback.format_stack())) @@ -346,11 +347,11 @@ class AbstractConfig(abc.ABC): For legacy reasons, the default is 0 and not None. - :param key: The key to search for - :param default: Default to return if the key does not exist, defaults to 0 - :raises ValueError: if the internal representation of this key cannot be converted to an int - :raises OSError: on windows, if a registry error occurs. - :return: The requested data or the default + :param key: The key data is being requested for. + :param default: Default to return if the key does not exist, defaults to 0. + :raises ValueError: If the internal representation of this key cannot be converted to an int. + :raises OSError: On Windows, if a Registry error occurs. + :return: The requested data or the default. """ raise NotImplementedError @@ -362,7 +363,7 @@ class AbstractConfig(abc.ABC): :param key: The key to set the value on. :param val: The value to set the key's data to. :raises ValueError: On an invalid type. - :raises OSError: On Windows for any Registry failure. + :raises OSError: On Windows, if a Registry error occurs. """ raise NotImplementedError @@ -371,7 +372,7 @@ class AbstractConfig(abc.ABC): """ Delete the given key from the config. - :param key: The key to delete + :param key: The key to delete. :param suppress: bool - Whether to suppress any errors. Useful in case code to migrate settings is blindly removing an old key. :raises OSError: On Windows, if a registry error occurs. @@ -406,7 +407,7 @@ class AbstractConfig(abc.ABC): class WinConfig(AbstractConfig): - """Implementation of AbstractConfig for windows.""" + """Implementation of AbstractConfig for Windows.""" def __init__(self, do_winsparkle=True) -> None: self.app_dir_path = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname @@ -454,6 +455,7 @@ class WinConfig(AbstractConfig): self.set('outdir', docs if docs is not None else self.home) def __setup_winsparkle(self): + """Ensure the necessary Registry keys for WinSparkle are present.""" create_key_defaults = functools.partial( winreg.CreateKeyEx, key=winreg.HKEY_CURRENT_USER, @@ -466,7 +468,7 @@ class WinConfig(AbstractConfig): ) except OSError: - logger.exception('could not open winsparkle handle') + logger.exception('could not open WinSparkle handle') raise # set WinSparkle defaults - https://github.com/vslavik/winsparkle/wiki/Registry-Settings @@ -485,7 +487,7 @@ class WinConfig(AbstractConfig): edcd_handle.Close() def __get_regentry(self, key: str) -> Union[None, list, str, int]: - """Access the registry for the raw entry.""" + """Access the Registry for the raw entry.""" try: value, _type = winreg.QueryValueEx(self.__reg_handle, key) except FileNotFoundError: @@ -667,6 +669,12 @@ class MacConfig(AbstractConfig): self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0]) def __raw_get(self, key: str) -> Union[None, list, str, int]: + """ + Retrieve the raw data for the given key. + + :param str: str - The key data is being requested for. + :return: The requested data. + """ res = self._settings.get(key) # On MacOS Catalina, with python.org python 3.9.2 any 'list' # has type __NSCFArray so a simple `isinstance(res, list)` is @@ -835,9 +843,12 @@ class LinuxConfig(AbstractConfig): def __escape(self, s: str) -> str: """ - Escape the string using self.__escape_lut. + Escape a string using self.__escape_lut. - This does NOT support multi-character escapes + This does NOT support multi-character escapes. + + :param s: str - String to be escaped. + :return: str - The escaped string. """ out = "" for c in s: @@ -850,6 +861,12 @@ class LinuxConfig(AbstractConfig): return out def __unescape(self, s: str) -> str: + """ + Unescape a string. + + :param s: str - The string to unescape. + :return: str - The unescaped string. + """ out: List[str] = [] i = 0 while i < len(s): @@ -873,6 +890,12 @@ class LinuxConfig(AbstractConfig): return "".join(out) def __raw_get(self, key: str) -> Optional[str]: + """ + Get a raw data value from the config file. + + :param key: str - The key data is being requested for. + :return: str - The raw data, if found. + """ if self.config is None: raise ValueError('Attempt to use a closed config') From 26c47f3653728b1ceef283ece3b707045632ca0c Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Sat, 27 Mar 2021 13:18:46 +0500 Subject: [PATCH 437/727] fix screening in killswitches.md --- docs/Killswitches.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index dd2cd154..9e08feb5 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -48,12 +48,12 @@ be used to query the kill switch set, see the docstrings for more information on ## Currently supported killswitch strings The current recognised (to EDMC and its internal plugins) killswitch strings are as follows: -| Kill Switch | Description | -| :--------------------------------------------------- | :------------------------------------------------------------------------------------------- | -| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | -| `plugins.(eddn|inara|edsm|eddb).journal` | Disables all journal processing for EDDN/EDSM/INARA | -| `plugins.(edsm|inara).worker` | Disables the EDSM/INARA worker thread (effectively disables updates) (does not close thread) | -| `plugins.(eddn|inara|edsm).journal.event.$eventname` | Specific events to disable processing for | +| Kill Switch | Description | +| :--------------------------------------------------- | :------------------------------------------------------------------------------------------- | +| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | +| `plugins.(eddn\|inara\|edsm\|eddb).journal` | Disables all journal processing for EDDN/EDSM/INARA | +| `plugins.(edsm\|inara).worker` | Disables the EDSM/INARA worker thread (effectively disables updates) (does not close thread) | +| `plugins.(eddn\|inara\|edsm).journal.event.$eventname`| Specific events to disable processing for | ## File location From 321ba6c8120201a787ac655f693721ae67c4a42b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 14:51:34 +0000 Subject: [PATCH 438/727] coriolis: .p files update, and slight Releasing.md tweak about this. --- docs/Releasing.md | 4 ++++ modules.p | Bin 54967 -> 44236 bytes ships.p | Bin 1103 -> 920 bytes 3 files changed, 4 insertions(+) diff --git a/docs/Releasing.md b/docs/Releasing.md index 4e8bda75..f3d81e24 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -175,8 +175,12 @@ Before you create a new install each time you should: 1. Ensure the data sourced from coriolis.io is up to date and works: 1. Update the `coriolis-data` repo. **NB: You will need 'npm' installed for this.** + 1. `cd coriolis-data` + 1. `git pull` + 1. `npm install` - to check it's worked. 1. Run `coriolis.py` to update `modules.p` and `ships.p` 1. XXX: Test ? + 1. `git commit` the changes to the repo and the `.p` files. 1. Ensure translations are up to date, see [Translations.md](Translations.md). # Preparing to Package diff --git a/modules.p b/modules.p index 118464a028284074764c33d4eb6358655902bada..85d732ef100248b81722e743802bc061aee9ab83 100644 GIT binary patch literal 44236 zcmbVVON=B}R&BT2?az3SO?SIL{+0i2j|V*V_%mXpE(xR(Dm7Rzk`W6^QJGm)*_}US zWVX9!G^iH{SkwyFj0CIRAc2GsYcvbkBG|BIF^Cls8w5fK&4L^6oyZqA?&rOn-i*d^ z?s?~a-hJ;yL`6Ql@T0%~t8?Ms>DLDH$z(KGjpwua?DT8Dxg3s`qv5ZO2dlHM&ffj4 zvzw=vsv-TigK9aQua^hM%W63K*4YowPA^QWx<1=KS8Iq532}09|8e!=NAcnl_30JH zJsmHXa~j>ayc|`e^WJE4`Gsm$4d%09CB)Itq)WdJX|Gt9syT7pNh)MnXJa z)eA$OxCCWa6f1~&uZd?OK4d#c-YI=7(9vi{65D@$eHV5>+ zSfAdIqj0%8hN~sa)t2X;A=UsStp*@Ty)K3jN+m=Hy*ya2R%Q`sS0RyRw{{i!XkNa+ znYlQ5ohzg3*N5Y3O18r(I4XhNXz>kbQq-k=&)2I6WB5SQEo-JckuyTkQBkbRYF z>VY8qm+RA)JHiu4NY`OpJh5FF&L@kL@yw8|UWVWu!x~a=(R}EUbCC*w%Ok+0QFS~S z8RC?Skaj_}gs`VbH>2gU#APmuF26LIF2>8z0k!<)*qlWkD#`RvN$)HAh(fr56CT_E z9}B}~3lf(C8{uHA%j z@dSJAXhfo`W=lw=v%EK=7Hm{@7MdK%LX$ghI0A%I9@uqlxSTKQld-is>*`gZaP55_ zFck{dzNk;TYWq;`S_aHrBk+c1iZLJdr5->>ffflq(pGlI)fg(`}*fJZ;f9Ggl|Cb7ge>wUY&%bcXkuKn_>)%af8`S(vP?`pW79v;!EJssEen6?zQTm#yZ8(kCF)q1%ct$Ja2Bj~lTJ>r)mc)Fgf z#)E1$GeY}{1?$l%I921Tk`K5Z;Z6fQtm^RqpknCPA&K)C7` zxoTi~vUMV^yN6Nhp*NUb3px=W>`J4W6*6=D1#y`>eN|lVIV=hI_}%MT)Iyl%wO+^EOjAAN8zpovm9cNR}BcDkaAjw?wi zI<73G=x=YO3B^NO9bz0N^YySiY6jYfnt?W= zW}uCz8E6r;=;d-e9hG}&pbak#wBe@!ppGU441SikSkNKI>L(F+Y*@T*qcoY zvcWy-ZL&o?$1FL-}=-ya}=d$QWi-l%z!v7FDw1G?ogqZ^0Q zQB|+$4v03R!ooq5?(THHTvhD~-3wCK!F51-&kK93BO3gqIV*4Gaa{9zj3E{hs}sM~ z#Nv2eE$Lp`?BJN%NthR#tyYga6o3QgfqsXPFDPZSd2M@;wokg5H|Pl}7=mkZhfr6f zcRf*hR7(covUp(Y6G{l%De$cT&zeN{f|MiYQfzWHJa4n`bhYTQ$9{sq+YeN zp3?@W`at-^ks-Q3)}wJf9h@wWzpR!gLu~kasSfi&$Lr|`rP>;-52=|Q4afC@){V{4 z&>KRx;68*2WDW6is8R#f=96OIJr8xYQ-(rIj#9cPuD4Bkk1BxVy3p3!2CaD1p47V| zt6oHX%c^8^;$X$r#KDSZY2u5uwk>;UcP+ zMuHn7Yn35JHYy`5+EPJ8Q)`&dj^hSqQ ztKsNq)ZAW0AUX@xPvd(rxE&Ww>XZ54uCv~E*d?^5q!Sd0<&idM)v5}+N~u=A4d4?O ziBRjz5TRF_Ap&47BHWh>i+OihV8s^Nmw@mp3r$2|dI<`R$p9VD+PhpYsNOe68+}|Z zzmL(HM_-$ot(&tZiZ)Az-pIyA&V$m?ddg`0~U$A=0;^c-+B86M8(b@T3!a(8jl^{di&BdHb3N774`j|2=KDbU;>%{Dis!}B2Z#?j7r zHXJQR^xo-gb>P0?kwc=uo~=)FNR$}8d-b|KI)6gyWBJok!d|Cs5zV&a;|GV;gD`16 z?B0^!Cy^!ueq7Wb-)1bA9SB&S(IB5Nme(B!Se~aR+>J-!K|{D>+Vp{MF&cVBSix|& zb<9TvJlt`e=i>q%?z+zNX#vk?eay`epE1aQg)4iVXq9`8s#}&gu)vJnT?-DPXw=(Ii znc0ZmC#R#|gkF4VUyBcOffdf)t<3@w{3|ew5&1a`#reNN zw@J;g+y*gFTP|%4>jgbor`x<ItP5sUwtHq<&Cpk-9F?R_$w9k+4=n1*1M?KnR_9Gc`l1^9t*gXHw5<{&(XvX6QoAZai&o_t z@l4RNUxH38ssx?dQwch?rV?~&OD1-WQm`?PeIpi}E9 zL8rD;f=(@`1fAN=`^ucH>5mra&d+#plIc6!7>hZ)jj@=^+Zd-gy^WQa+eOA=j&Ea? z=K3~PY0htBmFE67R;dRRS&3e-jaBLi+gPREu#Hvf5!+a$UQuKvdd4*rcHbk2?0B?Ko0mQff0{r~k_-S`Q6dZmxMDNFmFLVM;EKW^8d6^*01&A} z3jm0u`xXWRMDCaXh*TK(Q>UAf0RV_p;s5|d+6)l6YYqXC3WI27{Wt&skxCo@fJoXx z84M6f=L-V>kqQHU?)FGB005Cn8~}hwn<0w4eNO2>pnyuEc(LhqN8{rYdTQ1_@D+ur zfka_wAf6cdra*YAcT^8)RQls)`npu+UQz}hW7T<_mchr+by|G}k95;PH3N(REg-hm z5{n;r6a{581B8dE%V+TLkUC%n2oLkbVi~cB0fcK#i~&U5Q@hVF!Y68&86c*C!zdOK zixEILA&*ulU8Mhl_DFgU8hjjH{U!zpjVZy^C=*gU8hjjH{W~xUPqnw~KK#gU8hjjH{V1 zQMw+!eR46bX7IS0fpInS6;s#4cT+CL)eIh2Gcc}ZzJTj`_~y#RxSGM^Y6iyD%r{!P z9=_LdF|KCtxSIK%i^dA?&xHr?)$DG!J*S~01l`AjV6uA<%qp$8@cS2iqehl6 z+S`3K9{zpXrW_R8*B=IB-?k}j#rCas-0b@XICp}QF4+0mTtkxoanm6wY>ZLG>| zu=vwHv%m%=8Nb!APkWwn8;nz?4RwuiXj@k>4s0+^nKn!gj6*xFf^lGjamut|hGCqY zqH$n@aY$RZ8`jprbUti8zLc+oZLBaB)k2Y#sD^E3ZLBaB)kKk%sETc@ zFc#HCk(H>7ZLBaB)ke7I+1AEl{$+F2roUtyAFem&ZR#>jH~pWZ@UO%q($nqF_Cr^QQ3S;$Knq}p;w2T$T z>bEq@%5P~ID~#2)w8HI9Xag=5yi^AcR%Abq1ux~?!HP`hvEZfrI#`j_JQlo^O9v}5 zn8$*b@)qt2pFCL5611dm_V=HsH9Ot*mg4D?^TjIun7{|8Pfn}*%@OHr@7BM?26*~p z^Z)4&_31zT;U9hD{IkFQx2I1x|0(p%v;FgHZ?HxY4YvQ-oj++d|DW9XivDNAedjFv zzd!i?zwZ6@wi^W~ZRT(W()~fw6Xn$trDnr|83r)(N z32JX&do1wopI4K0J}$|6vOw4-E0*f*U+EF@G?fsxX@bJv>k;w!UxBG+N z3Hz=X(9MjHQ-5!_guTrZ$di$Qv%kx#j+vW>;f1>m9w3YC-Y1@f$xcfK~_8g1D_IlfdLGO(VF=0=r33G+w z{#SE=ZxVJh3jMoQ=oP08;`F2^47_c^V%^^UEDEJ#6yxOqDB*1r2EBiy^YVn1@U{ut zjdA#wCy=lkPQprf+k`>yQ%}Z(J*6hhCB)sxHesJfp^sXjuf_A2I>Ro;YkI=K+a?SZ z`@M?@0O#ciE8%Su2E7Qt-Y)0m2`k}k6ZSC1;UAuY-nX0rE8%Su2EC`xfcIUted+Eq z_I6!f+#+uC_9*DxKNsuZoSH8jm-T#sugzC1*ghZ6Qwd+2CtV-UPYECLLvL`X4sS28 zO^hy(CuAcq+!dINk4E)+v7m2b%6rS5_Z>WN6Yl0_(@*16!p#YTxrt@xKEDrc0!0m& z&RgF2jrVyN(^Rzqi4;RLDcbqf=lg=!w179I_i0pa4AFC*{xHQ=rsqGva|Vi zVhL3ACC3FP=v?WI7@aV=IvZEgMejAJT%Fx0p{%e01@##&sHfAbHzL$qT%AoF>7qC5 zRIbhzjZjv+fP(rA7u3^Z1#d*Cx41ex9MW~u;OgvG2xY|!D5%eHLH({jBGg-4o#mc% zeQt1d7H>jX@d66!Gh9&r&>s=%Ew0X@N4g#vT%DziP*%Kvg8B?sR3F|OR7(eBkWXaa zXkH$i(lbXsCvv`BslI@Onp7U?cQgPZc~qD6vB(BP)b zx@eKo5;V9em*IWG1%1Gs{-9vA98`z&t9#As1uWE^jgp1u;cH*EREYTuaezE%v;td0 z^O=wbqE9+N9#dLAt)cnU$OAES9*8x@0gA=j(#Y3uT1_)RXv_nlk$~Yf`R1V}tr83R z4nQ?Hsn_EbzQ%oyzOUM>A^J1w?uV*6M~$pSEaA?1BWn>I+hz=SNDD@mJg%2T9OTeLsPLgALnDq5w@%A2Jd zS3uzwb-^qv+}bUG!Y!9o9Dr;A;uMsH!mZCetzd;)4-24h%ViZOBU`ID9%Z3$>yf7w ztkJD-P|DK6FQN^P!h0|ISPkF7VuMDl-T_5tI%|%DMUtqkI-uxAhETM0jZidm2Lw0L za^hg&2DMQK1UGy_(ZV%C(YzfHN{iMF2L%1pFC7r7$zT#qT4NIJ*#SW~tqcwb!l@%V zAP6^@L>tzaL<4p}5Kg_{0YUhV3xaTiNiw+NMU=poV8%{J) z2L$2Nza0>SKXgG5PE6siAeN&e`a}F>{1!3${%Z3#VI~A^(t|*<2Z3M@0=X)LwRc@E z-@tn;o?Nhaaslz=^8T%A;oaMVcyhtw$pyrd%lovdg?DKW;>iVzCl?SQxB29h_GQgZ zF-VB0T?r9#B}B-T5KpdEyB!v*b|u7y+hMV4S3*3wR_#g_Pp(zF9Tuy0 zCB&0!)vjdmqBURSVxk zco0u6SUkCacyjsPLDj-{4j#ml3l>iGo9=><_hdRHS_sHbMFbfPhkm14?)7 zQJ_@g;O&@BBtj|g##%gpfKrD8N_Xv1pj6}FotTawLMd;=T0DS&QilUdAKIfpsm8&Z z@FRtT_h2m^KtQR(5tW7;ULqj80~1Mjh!p>@hkh4ua@hML_xL72r`Kihq914Q(VKF9 zWPv(PhBzjpfY|EQ7QblO86Z4N?KXplht#PuKzNuZ7VX?37F|69L@82Z&H&*P^|TBS zQ^;Wy9p7RUjXwi~Gt|2?KsZBfF9U=#4x?BUEJm?5WPosn+It2FXLhncIO8yib;BB3 zEFT#loS_vU1B5fwJTpKz<1mV)#bOjIOa=&NXpzVO;mpG<5Y9M^V)e0x7K=~@2xpvS z1dP#{uq0(D;SEu~70w3XR{@VlbWbt-Vr}P(86S1NlX+|N%O~`kY;>Zqts;MCU3e#F zaM1Z#;m%&(9LQQwat64MM2CPJGKRgQ#S9g+bVHTai`+1%Kw61%NCY)en?Z%3kGnx_ z-YGUm5Q|q1i7?U*A%{fu(&%RV+EYv_wGy!i94&V_38;3GU`7lQc*JN;F{#B0nL{FC zUY^An$&6Tw>_n_UEFwm0YECR7Mx18EAc04W7A})oEW0u>!G(*lyk}M2tAih(Q967%jnO z9K?nqheX7@1dFq)8L<}GiCBSHMC@VSEkuks&4@t)kJuxJTI^cPh>2}W4w?2XX2ihR zSvi}R`*XxGVqu??gCb-^YK9CNSjcYg(gq>?HVpkv@`Qd*_;5aaKpzYm%zY1h z6#ww+96bQOOTPoXI+!${Fg~c3Q~J4xgX3j29N{kxJP0Pl4TlAJ{g|FuD+BRg+BHD@ zCw2*REiz5-j>m>#3jx7z+8ogPtMs*0ISQAnW4KzvT$)zX!^#keR{de$p!VVay`w}#e-Gz10{L^YFAV3X;)L( zy}+5dE-I$pb*`)_wt74qecAk2G|gdkdRPc3q$y}2ppv$EH{>W>sgB`l33F*hpNjd! z5UN~+M*2}|evFieH4N9n}(|Zq@6XQP#$m%en>Co6B4l zT@JFoCFh}%Ob?axzM_vP zgc~^FL8z7c2Ok>J)yvRK+dK6##Qp~TIYcA2L(Wwy04|RJ7~msc9=|N)@ykNq=CUPk z0}%2;QQkMiDHoG8d+)tt@4a{Z*?aE| zd+)u!XTE3Vu(O$RH*fyH&&NE^Ip>zS_wMZMW>&9;hPLMBVnau%t+m{5J8CRav2n9f zLq|Wa$0|E`^Ng4@phu4$g+~7Wbp>i^>!i9VRA?-Y^m_VUuSvc6mo0^I+3P*NM>z$x zygt4+Z&UB_z0wHVo6q<9GSR0zY4PfGEhVBhF3OwV_xhzUR4i}{rWd^he6PPSO9XLR z3k_|pjfJYp7xcY_7~+CcAu1@r(Q3 z5`rxnL@T#f)ji1fmgL`a-ATWk+vOU9*=GHUI^eQ!ht zr!82;_g0EQ^l_xEo z98X&^()X-PQrlwto+D&1{~Frrsn9a5R4P>shwFQz7~`g7V3s%9_ts%-p-jy7*7d#h z7+bnLX>ejvZO8h)w?P)D&DhZQHWDzH2vIYpSG8h{?~P?DoK(q_#S>}O+xgzaG)PO{-uHG8DCmO5QlW*H%KAdXw5o33(f4*@F1!xX zILq7F_jX}!LAegnINRIR_a-qnSgwNvPMfit@9myRYFqa3y*(4j8O>F#*~|C#W|CVI zT!j_ct4PbM^SynT9F#}eUcvY3nOv(pY1y=x+NK8IYm`b;S#4F(_a;l+U{h>tYi@5U zwN|xfitjZs!|h39EU)ByQ<)i(&e+~G-)m-Oj9fNVxwQHg-)l{!wC*a7wBCJvZ$=8E)z0+2{e)R2sJ5lO zM8!JZ)2P(t65ikU4q%ka&Ot5D_q_ud<@$3_+dIhjW=R3dr52zqI@tFP$%D0Nhx*=O z0tYK~*tA$rg=e|LeeVbcxnY^0oiXx}?VQdhJ;mRg&1tnVF{jcS9A z_q`JY4X)m>K^?()wEA>|4JCAv8p$Tt$ z=lk9TQqKz6^=NA^^u5_ehPL@4-@90hs+t<9t-ah-sy_Q(;(M1e-?hz&yyacydzUl6 zdY3jQ^0s${?_J6KuH{KpZLa3E%~$!})kcQ4`5NE5R*aS7{i->F!&}v0U*~(*v&0QI zmMrfE-@B0|ZoRQ&dpG&s%~IY7gYvW=Zt=Za%{A?e+kEeK(T2pcP3de+82>wb?@q?K z8w_yEyUX|PW}G{~0Jpt+eD7W{u1+UWay?|u_OoBM$8Jt#tO1fN{w7uwB*)`sd! z`yt=^A7k9i49xN#_Ps|K8<2_F-lM+v7-K8TYTY%dHs^8Qdm;DP@4*! z&0SXBr+x1kMz{$nh~+)&d(Sa4Pby-2&->mBjP#UqZak5e{i5%^lm=s}QeP~zG#AQz2}&7FojiYk^1YuKTSQ)mC1EnpfAPIvrP|;q zm&Ao-{^onXOPRq7#UxPb`@{GCl=`B9sICuOT~o2p;r-=%e+%3-=#)}ReWAGyt@+3I z{$-9^)3wTwlji*AQ;&JLJY2cKNiJS!$V!uF9wvS2DSUXCP2^EA^#a~oaPI%ErBqHb z>H~aU!Fe6&T1{-4(R|?h3ZGa_$V)Zz1Mep|R};MO3yP0jNI~b(0wDVf$z2%SGU!60 z`)EO+3kk|K2RBc;pkePV40aJ=x!%OEQtP5X7ZWsE%;(lxG14>u=s-ca*s2OD2b&fL zyM(Y@ZFE6|T@WAaL4cPOn9EHLEcGr0cCfHqZxtIG=B2?dBW%|q;$yrl;N=AFT10Gs zmj^pUSS})3FdKM(YAXkAS~L=(RjX)|4biDpbjXD`s#ejZ(Gb^36{*xxOzfO> zA+A@eXwmu*H>g##X+ww`)haqP2IAOSMVB^)xJk7*G+am-4ya>kb@Z- zovNx%dDTY_+8o{%;_(`^Vw5d@I;`-*gySG?sR`FG6!q{-TOq>M8evt_2*HxoM&qGx zqk4XeWrdyqZ(H$raa=t&ExfsPZ-)RAHNem?Krwh1l-gQL{Eld6E8o9wDHh6|d@m5| z!uGIsfK{==Mq4|tBGX#hsG|@a#lmjh5!z1Bf^m&b{1tqBpV%3~E-FOl@yT3WQ*bXx zmn%8)g?V;`Hc7RpH@j-_bi2XZUA>jU&Y03!Aig=?S~rE4Rb0|~L=Q9W0dr3^qnVds z$^h;Kac>cM0EbtnZ08BWFO;HXx#EOPb#V6)m#2Ghqarw^XwpPCthfNVUSu8%v&2$# z1KdV&x#+yaVK2+sst9?q$XxX*IaSApXbS8mvAJx+)KYf|@>G$z?k=NLZsLKCogAg+ zX%L%5Q8PgmD_o@)*CBf;v*p+rE+!RWLesKG~8pv2VLMNRaFPnqJ}0$S3evWd!JndhbkV2qb9duYA)cmU#g(9y z#XI737-y)F)RtJ|&xCN63fdMbBpz1J27eCtifc4mv*=uC=hdd!bUw5TYSSFL5Zdh8 zG?y-dc5$^9-O%WILk{;5E`fC^tl(CRc1802JGu<~<-+rNtV7g=52xD|5Uv!VVioRM zj|g+;&s8w5Rx`acnW)!*zgGClWwA?X;O8c~4&wDHMhCO5C5p&PWLxVLx&hjaswLG| zc^Bj+@HY$3U7gf*v0EXxK)6)|?rXh(DjF2OA95Rv+r_BdO1c`-XLmrjQv~j_q?*Dj zP7V)uLAYCll$zof^*u1|6(gml*hPIGg!@I{nxY*?4uFM*20qU7yQpo^K81Pw0Hg;+ z;?5l!ZrN#)wB{jL{}YQ_6TQ&MwB}BnhoL{BdNgs;^zf2+6xw5=agW5c_O?=MM`Lkv zF?b6p>=+y{9*6b>v~gqRa0B_Lx~1i&wuWg5hrTBvKP5T2rSY6yt+3Rmp*OyqCo5(w~(@hMrXUGPGAj z%d9eX1-uIFHPJGwj9&+@!+S%#%qnA7!<*3F5{;{j?y2KMSGil`GI$&GJ3{ki5Uu`Q zXqo@-0)J0%ZcDU;b-}~w@ILrC!gCv|GDto?r7QT%7+dA0>YOfaKjTiDmJ&i0{^w}Tz>)| zn^fO`|5o_qg5tC3I|$#4kX%q~8vOwNN8!1k=zW~IEw1mRa!19xP4p9#pGDzLjb1Gz zD>9*ef%B_4+>Rm9dJ(+-z-+Bd6L#)zkbW15+mf9~CdeOf{uGDX6P?zRi-S|gN5bIY zP5KM&-|D92tDIr~!1-4k?u@jC#irSRkb3mwH52b$4Nd8dPzt+a9_INSEU~yda#Bfu z^n%n|B<_ziDK_i+K$=%19<8+c;!|%vSbfFHs4q7E=7-czB(5)dTZamzW_~Or{u*!r z!2LBtG+C42I!q{95XwTTMDOmz73r&m!7d_f#kIiCrWBhS>)YDO!6Ux0cVQNVvKW+# zy*DZ>)wE~;%z=`OAB)IUY+4-35~7&Y=g=T1ONzoD#>ma$(o#?cLm4-=KTl2mnL99L zet4d@&S*uD%X?`!%SalYFq$R-uA@RLzfrj?l;u=ein9bKh^qME++QB_5TSW)Mbo5; zmT?>kc$mQ4PhCRCF2)r=uP8Lv9&ITaI(`+d1bk(|xstTtQp#}9BZN*WC3fAd0(w=U zlS+wSaH|1dUGSt*VprN4pw|?dONrV!qu8qNFyi3_x%<5q@U?+gyd)mN!&GW*EVdW< zLpH4)bxBWR(nz?Lq~f__AX#KXazyHHB-!Lb8YL1xw>>Pgyyz(+8Vzk7LoIr)h}MO+ zo@&9^^P!xVnkiFe))!`CZLp$uXx9h5fzaHbEZU+CL2o4VyeYI3#U2BCtk46qX^S=n zy@}BMQs_}p>`g&$CiJju+M>-tZz1%eGOdC>!8_M@6Dn9RM@GTN0pC(^o*Ka{?22n2 zZUubn9Ndngj|aX@4z9g80r<8#xEn>^4*0|zT>Ei*;5+2tqoe3M0^cbIUnjzM2EL2p z!OcN*Bp<5V%KRvCJGHeW^-h8PwV5o7ZIBZf^=5ThxKq0bN2P=`Y$ z#F&a0!DDAN$SzHT++35amu?H>*6zp_wLxz0j%nGYZ>%x9t_3$izgcu%l+Ch-x<$7@zg2YO;zQl0+o0dxz3dL%0sT(VjTf>o zyGwULzgx2>?%@0aqTJ38$nhI$u^r(a$oE37SOsf{VbOhvaeo+N4wgV(18az3(*ua{ z;QylzhaN(V{~<=|c{jNuTzVMtBi$)L*S<#)<1r~9?eJMufUbOxLw-W!w9|UBY}1pF zpXyF#hn|M~jL2!n-sH?KJq!7{nlkH(_dMhmL{2+=R%O=p?nTHiiELQ5u68d&ex*B^ z9eNe=Ya;VpJ%)`8M=z`VRj0 z-OTUM5Ac74A1vF3iCy{$;?K1v))D>%{;!glm+QR5x>WxL@plmoDh@@P{($&rtr;Eq z3*z4*@>*wDs!RVs{MR_6PUHU|_UMJTHF+B6Wei1&=3#~3*%Z;B)KIjk7sTGRW^||z z#Cb*JbMQE+V4A zvJz%=X;FxaX~y7#8VT!BnZId;Z}FDeo2u8}0SGV<0V>v|8sk{BIN~f3#?keu#yB<& zLYyW4pY=Gj6ygj6*#m40<0(jc(JIl2`;UK04vvAfv$7I5nzM_;C0Tl0$uM`L4Z{yKn+dMb#FBU zSiQRyIJ5==tSJF_QK_*BF0F+CYu8+Xu7@KLz>)yG9-3C5>!OVSjs&Qo3A#SI2r#O< z6*x2+0oIWKyiV5G1eexDfc3P3VM*&He}-^+vCL0NQL$Vs5Pv*keP|m%t5_w2M_Yo` zw%9s_KU0E(t-g=CA(V|o8QYsl{*li*Co2|>fif0K@Vy=B;ceO&>?Y>n9oiJiW)hws zUPuq`(&k{ds16^!57@QAZr$VpKaD*O-j>x~LMmM#w}P@Yl;FEb(^-qggWX10UJKJ% zn<$_?p-;lLg?+Lkgq>7K2(E9|?hJMpVfnd%bk?F> z!A=r3c|60oHthy>cZ0YN?E!XAVHe4&!KJ;x?wu7^7x6l<`v}X6ctYEBy)J;Q7dCl7 zbZKq?+h`Eip(5DH!txT9UV}?hz&2&Y)h7>1V5bT@A~9~rS~Lx8v#`ni8?rXFfNeF1 z>rflmc45b6)!>o`ma^jNzEK9-AuR7334NwpL?_tk!Y22x?gsmUona8yp_yR!6LwZs z4KD2u_JFLo`b>up_CR50C&mp~iw*)iOW5T84OyEG278D>T!#(?dl=XWJ(Ab`FtAI9 z13p3n2ahuc`^n_elqP;6BYGrCFS;YaA0<3rbSb<}fED4M%GZZ=xnIxKn;!%`HoHJ!a1+@bPk;l^#V!9 zTTp&Fmo9`eyM}anRJaK0#gdMX3K{7_$D&K%Tq;iX*oBTwm%+KbhCB{k0q06_c*n}G z&84g0Ty2s^PYBn*xmFxLA!OtU9gD7mbG<#kT>!U2wkgGjWUV0Dh+#Zqr@B?>567x(E2ZX1GiD0lz;7 z*Ja=V;18PN7Ci*~e`dH%4+DS140q^J;E$Q%E?eUgWrkbyH1KE4aGRb5 z{+t=^(DT4wFvDGX5%^0vxL&_61AoN~x9C;iubJUCy$<{hGu)v!fxl&jyYx2jcXDt& zd%O$$Ju}>*_kqtb!)^Ki_=je=LmvVE*bH~+6X2ib;CgKO4EX0}xJ6$8|I!S%=_}x0 zo8b<91N>Vv+@uG9!(EYM$J$Ebsx_>sUul*MUy-+r-ucj9Uy+}5#uTK{R zy;wG_ulNRl9;kG5TPXV0Bz{3u`FXaHv^az%_}>u~-#$BOettnSwX>xiFb(2gkMG@y zkHrQr^HQQ&v?QV}RTXV2{CRVIn+C&QI>{e5HaN%ePi`28mO+?hlfw*~WfsPzTZKQq!T8U}p@ z(fOs7nXad~6``*rI-kL7(k)sU`f$;Wi`N6z2b#pLY%d zxDtSeuEqcsjY5FY5`br(X#kyj>mb0o5`c%V#sC(rhXCtKfEt>h^KSzL*iZuS5Smt? zGjJmW7$X5{XoAkc;692^8%uy1hEZqXCJ3;p1gN12IuAEPfXyWU&qLEb(3!Xe0*sRY z+=S@Ot7s;+x9uC;aO1aOO7)$3*NwJ>wiUE-V}6~CA4A)stznNBdu;FMJJOAE+q4br z385W)i8B8f=5}aX*xQA6xb7R;E=`2JJ?!A`pBa@rigtjuqiFnR+>Er*v=g+QMcc_x zTZeXmwyS7Y%J*MXZuA&a{@RsrGqWi8Yk)rO24UQo-=iL_K5kTbHth~?5Anv%XX7U~ zpF?}X+bi@2ogMs~lk2&(H@v#g8y?NNoH|F*KJW^mH`>q}P4(~^LT{X*w+=PJD~8^# zkym|j%J&Lntn!l)XA0s}K5!CUoH+q3YC?dL1V~ur(*o!!KNSI{Nq~eUGADpV%?QvU z0TNdEv;exww<18B1V~sSa{^e@jsTtnsG$kE$`b;VB|yR|pH_jc@*N1!DFJF|g0Aw@ z5nx{lkg&?9RiLZ<39hrIYx7j$a%9tEDg_xKBVQ^Zyz*<|ElG@SEU&^SANQDfrD1N3Pbh|5kV7MQiXI z>^gL65U6KoPE8h_#+*;5^S@lv_<5$HfKgLpNvBGp!}j}N-1P(ZpK2D`rZW)wObM;c zl?)psW|&n!;iVt0`r9yrLuVnw*4sm`4UCb^=hAYAh{m_O9OU{E7<9jBKaZfn|rH-+#cvm9!Rbgzo1SYIs6+1q< zhOuqB8nLg5*S&XD?D)7E#&+mh#J(>>{jfj0y7<-@$?Aj80+}M6HhKb|bOBScp@zp)%W~8_!Od<1s z!t~@6@nJShVbiThaa+6<_a>)^kG5e7hi*rTJHix0q@$+w3deboSVwiM6)xS06nDj2 zF}SykbDzX<&MRNvS-Kms?+Ig%kn$gl%3nNVtqxzSr;c-&!lHYT;=VA2Tn`i0k@Cll zji-qBkYNg&?njCT;;pzbIYoS&4O2MuAW}ROrWh+7^-iB~oCjx&vtbIC{)ZF~$6L{N zJ{jk}iQ}9XTi;fD1hF3tV^5UwXGi4+-v`J)iP!VI^1IY=4pUh47*aeQrUbp5DdOX7n8Kl_kmBhu#VqNlr}~DiSSfZvbgLCEJ%bd_ z##?b*zc9rrvBO<_`Oa&FzP0!qQam4~n2lD9?;$fOd6>gnHmSoLhPLPhgnls$Ef+#{ z=y=B%hPLS?gnl`*>iDo4hIZ%`gnm^*^J9>SJ<_eRU3v|%U(YN%K8{*;bib;(G`U#r zY;Wg3KNEjf=?%nwlmD%F7jN$Uu@ujux8S`UdUNC&&h>112j06i=5y#hc<;jt?oZ`3 z%%wRHJ}^zBw+23h_mOzfIVwG0=vnkJyiec-k1nPa7z#Fh3gNRF6FKxbye}jX-xkP8 z|_l+dt#}(5O>5HasA$%u7#u$ZyP2WTK!8C(IKSKCP1ind;Q<6(R zL--{(gTCPS6~b>K@bigj8T3`e?-2eFA!9f~!KObU{AHTKp}!&gBLd$m$tlUDedJ17X?R40>2u4#M&x%udgs zN01>9hKi6e4xwPvFbFG{W^ial2rEIrhbGeIcbLMZm0=9m6sz%;8@$uj!rz0*e=)jk zX6Bvpku(DSD&q6vT$|6&P{3cUR$uqk)#0xpKChF8`E`F?6aHGY=GWb9ZTKU_=OxQ9 zziw_8d|Q0;`gLP*;Jf1U>S35)_nA@fM~iP>zpnA?z+YEyp17{Po4>`d5tR zU*7X08$jGpM4ottqD31)93vv1sPaUeYGWa8EFuq;p=i-25H}Ukpj4e)n?c-ML>`>H zj5@2ffH+P>gHm-mZ3%HJ5e$BSrCs!pJ7AWjgGCs1A+b>?gfaXS&Y)aYXs z?fk9{e-gJy4TbuWe6NlU;Y2vw!_oIYGF2Um9iZ+g=_)>DlaNk_VJA2{n>acGyTI91 zoQhAfB;?V~p9E*O8XSJ|0nQ#Kj*iuyaP|_14|Ew_uEVr9oVpquoA!ZIsKIfl9!`Ua zqi3~7I7M+rWVT0-Ym?zjsllI&>i9gCr#{ z|0XG2ng#3Nno{cWcnIV}B_%J9nJIOFJPg+1V&#oxXxVfGtRrj6<Ejuwk|D3c0Z zItJFUX1R0`KMvOMV(}uLnM;@P6JVVvR^G6MmQ5$YI=QA?4xIw)RIzyXG^x;~(_o!$ zmP@ydGhm%57H=Dwxpd<=3)b0U<&9Tp*>n!9b8E`w(0Q=V7mE)eCKbAL0jvwna_Ocs z8`ec)@uriROSheiVO=6t-gt$UO_##DtfpKJT@LFCvBsKJ=+c$2t}@G|cMh(Gb&XgP zb8_kJgKJ@3Csy8g={~kF<EpWn%$=FoG{o|iPdO=Xwm(hJ~UG)$v==u6OEmNdMFrlir` z^A+%~3ZGt(QNY4)_m*Pw&r=cj!a#9|_MpPIf&meGLASy!g5gehU6G;dviSiLX20=it8( zKD{2@`@RJKmGJ5P8S)N&4gMS9c~8l%$E9zeJNQ5H;_F`aC-}dFpPd?Ccd@_0|08^QJ-UDW z3;sXh)B7{z9qPePA@I9V{4c*7H7l#Xt`*q8%Ct zdT}G#r6oWQ%BFSST@v(CMzlqPK`(7Y+q4YmWsPWumIJ-K5$)0t&_lCn-Cu`+UcrdA zXhqN~8PPVa40^Z`?a&C&s~FKPtqOXz1UmSB@#;U7vpVQCjA;H$E$Fq3Xq(msJ<^DF z$O3H}(Jncl-E3N~%Tb_58_^c61A1K}+NSkDuWv*uGl<&^sH^7VQFhS0mb{NuYN#q8-{D^d3gEOM8OeE1T9c?%ts5jA)DY z0bMYnZK?;|U_?9A2)bxQyEGZ}lx$j0woRZ*Mzlp!K~FQHZE6PHVnjRC3cAgRcBvh- zmrd(=mOz({Xp1^PcN)<)O$WWN5$(_n&@+u_m-Yj_ztX{Uc^oN$YV6_{^) zBt;Hki_QalzQ8Hn9l|zU0Qf?a$PUd0e38I>|01Idmo5f;NoHi-OD_d{nZSIfBPntS zTXZ?#D+EsI=Mc8(O2Ai{M0V(Ez}E;oB(n^ct_6HuW@Oz)uLpdCztpw&)SSj|!a9&mnBnV}Ktw ziR{o5fS&}6cQ2AUIt=a7Q=p&L(9z>A@?`}L#pdSvs;`V2NzcG}7EZ+mny*^)9MtDS zbq==C9&;Z`NzZE23s7IIJ*z`6L46r&u&d@*>e4H4UacXW?y;{yeO=VKdu&El-D=-} z`X2c&7bbahr~VSoSK{zaosma3?62W`BTn`( z>Aw9fobPJLZ7%%{=O2?iy5Ii`=Ra|Hzt89c-S&I%mv->&eg2nk?`MyX?*2XD z^b*G?k3+rT^bvX z=)fSIJput%sSaR}+@V$Bt_F8J??(obORGa#qdMX69_iB~tk{i4XibDz3n79(7?qV* z4;^bm8d;0PU;PQm7Ku+C2AOPfAi0_;YcQg-iVVgmn4{G+NaxTxkk%E6cSHlprS%}K zubGDTNbmlzM(zF$;BF``A6>E%>Un1)NMmY|EE)@GW07(un4WkxfwZY+%If||lJ4IO z=H_Y|G>qRLfizAe-i!?-ewzf+R+?#eM)!v`YWHsqcf7cKYRXEeN3CrjO{hh(Xj@3z ziIg+5^sqG%()OAutNSBKx_<|lJF02WFo$-6w6jQj4ls~h+6B_CnrV1O_lGrV_Xl5s z#$UfFE+3?_66z^$cSw8GB3ZO2q`gGSnOSi*E=51&9f2oes)1{Qz#1lGZtYIsKfhpDvx z4}p6q+zDg(lsF=iJNO=5f$G~DXYv<7H?&RX$F|B1g;qXh*A*J47g`&NjdU37!(j(E zz@qQCEoaDlW-n4pv9VO({~mz=M`{3*?B$L^Yh!`GlJY3XN2?rs88luIbn-V=Hc)4Y z|JG``9DIBAF(8i>vWGljHjN6Uj=JXHuiVuYsD=NYb=?#yG!{qFaiEVkqAfZB^oc?b z&W_EWI01dK(5^g5mrzMdiKvaZhfe{2Y93F;LPH0CMJJsG{&eMoo3s+YWm>6J)zC8l zpD8eRO9pJwS%A+Lc*RVZKS~1lT!A;0KdRNW3~l9kz|YUYwUHM9zfkc3+{l(fOMRiL zeY3$`BpkOdnX~9(aF+--AdTaXgn+wDxRuM3f(aMPs|~swv>J{NlP5;B5kOLxR)^phdR>yhA{~u2Mjo?gV(3fP6_U(Iuib=Wd|)WT4uhdx74k zXmD+mOO3^SORbH;5*S-C?g#vUz~P0I0`mtg06!!!FPa&V`BN5v9~PKju>^meu4`m% z;3L2v&B3*ij{$#N@!$gK;P3k#Rn@*Hz&$Bkcp-J=EP4vu)57(a3#lt-(=*_n6>gAR zNHIsGbq9dPdoSJ9d{XVH7$-WP8C+}6Z7o92M~ zK)5sJj*N2JmJdOGlul|}J_h-TlED|N1pTvaT}!FC)KTE)!Q+?Hrw~39fg6=0SoArB zFGS$h=!}9XVh6$E&d+l4?=Q_(@2Yc z1o@MY{BkjkwCQJ%zX-Xl{3YV5?Ao|r!Ty%TYO8(+`-ie~E3m6t^(V-`gp9Q+PFnOg z$bW>4wJJ{9^e@Q&gp9RHNo`e+zIb1Q|K;~Jl38t4Pq4j|jV`zuRc-1Gu8(jP7hIg< zk12qgPdIK-ayIUauu0o(xL=9jj_;%Qq3f?PbE)V3@Ea*&e2ZYeSOKs&vvK}!N& zN?>kK2FxEm0KBxo;lo=gk@>R+fR`1Rn-=WDU14qCa=@3*!L^Y?fDctXm;}>1n>#wG zSk=N|AXgAFyrhyyzWon!B_S6L2O}XS-}47KT*wtI`FoJ;c1oid(_=vtYK? zD5FQ3Fo7))zD0O>1yu^fwnz3GS=$vPlp-Rl^qvcev;89BQdJ|aVdjNAJPBp0i&Xyu znBEi0(>Za*OjMa)H^6j<5^u9wQ4JJ|p4rKNB0d?sdF2 z`4gD)p5#efF6kRE&22L0)ONm)op&g%Nx0(zkd$j@60@YB!B6abslr34PN>$lFnEpP zYvd`JKwagX1G8CGJx#@F(%YeG5YfRnKadsi2TW@hN0$%d_p$Y8kx<1@)sV9Uf32YW zL~BTB2|w30(OEu3Y(_WR$Q=`uqRxKHWWUS}n_S9BGBN=c?33P?3SGqt=!#uTDF}W;pzCH_VR>#vP&ZRgZ0yl-1FBz8-=GUX4{q*h1Ab9P)!y-C{ufur4#K7qiDPE3^EPD^R-o(-C$X7HxNeY zAfM0EFw+QJUzC|@CS^L!bOzvuGDiS%wy2@CU11#@w{n(g6ls(3`D_K5SwdMTa}oOaEy#nB631wyK4J%naM!4pQtu~ zZ2vS_FF2H8DCr8*IQUyUvYF=s&sW+%!E_ZocS@Q4P5!mWt>bG<*JG^bwvV%@65ah#W;@V2dcshrm~JB2*C>~-`7*H4bJnqa{G?kh{iUMmzj2I8eE Date: Fri, 26 Mar 2021 15:35:48 +0000 Subject: [PATCH 439/727] plugins/eddn: Now fully docstring'ed. --- plugins/eddn.py | 155 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 118 insertions(+), 37 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 14dd407e..60d6debe 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1,4 +1,4 @@ -# Export to EDDN +"""Handle exporting data to EDDN.""" import itertools import json @@ -55,6 +55,8 @@ HORIZ_SKU = 'ELITE_HORIZONS_V_PLANETARY_LANDINGS' # TODO: a good few of these methods are static or could be classmethods. they should be created as such. class EDDN: + """EDDN Data export.""" + # SERVER = 'http://localhost:8081' # testing SERVER = 'https://eddn.edcd.io:4430' UPLOAD = f'{SERVER}/upload/' @@ -72,7 +74,7 @@ class EDDN: def load_journal_replay(self) -> bool: """ - Load cached journal entries from disk + Load cached journal entries from disk. :return: a bool indicating success """ @@ -102,9 +104,7 @@ class EDDN: return True def flush(self): - """ - flush flushes the replay file, clearing any data currently there that is not in the replaylog list - """ + """Flush the replay file, clearing any data currently there that is not in the replaylog list.""" self.replayfile.seek(0, SEEK_SET) self.replayfile.truncate() for line in self.replaylog: @@ -126,10 +126,10 @@ class EDDN: def send(self, cmdr: str, msg: Mapping[str, Any]) -> None: """ - Send sends an update to EDDN + Send sends an update to EDDN. - :param cmdr: the CMDR to use as the uploader ID - :param msg: the payload to send + :param cmdr: the CMDR to use as the uploader ID. + :param msg: the payload to send. """ if (res := killswitch.get_disabled('plugins.eddn.send')).disabled: logger.warning(f"eddn.send has been disabled via killswitch. Returning. ({res.reason})") @@ -171,10 +171,8 @@ Msg:\n{msg}''' r.raise_for_status() - def sendreplay(self) -> None: - """ - sendreplay updates EDDN with cached journal lines - """ + def sendreplay(self) -> None: # noqa: CCR001 + """Send cached Journal lines to EDDN.""" if not self.replayfile: return # Probably closing app @@ -239,15 +237,14 @@ Msg:\n{msg}''' self.parent.after(self.REPLAYPERIOD, self.sendreplay) - def export_commodities(self, data: Mapping[str, Any], is_beta: bool) -> None: - """ - export_commodities updates EDDN with the commodities on the current (lastStarport) station. + def export_commodities(self, data: Mapping[str, Any], is_beta: bool) -> None: # noqa: CCR001 + """Update EDDN with the commodities on the current (lastStarport) station. + Once the send is complete, this.commodities is updated with the new data. :param data: a dict containing the starport data :param is_beta: whether or not we're currently in beta mode """ - commodities: List[OrderedDictT[str, Any]] = [] for commodity in data['lastStarport'].get('commodities') or []: # Check 'marketable' and 'not prohibited' @@ -300,6 +297,16 @@ Msg:\n{msg}''' this.commodities = commodities def safe_modules_and_ships(self, data: Mapping[str, Any]) -> Tuple[Dict, Dict]: + """ + Produce a sanity-checked version of ships and modules from CAPI data. + + Principally this catches where the supplied CAPI data either doesn't + contain expected elements, or they're not of the expected type (e.g. + a list instead of a dict). + + :param data: The raw CAPI data. + :return: Sanity-checked data. + """ modules: Dict[str, Any] = data['lastStarport'].get('modules') if modules is None or not isinstance(modules, dict): if modules is None: @@ -330,8 +337,8 @@ Msg:\n{msg}''' return modules, ships def export_outfitting(self, data: CAPIData, is_beta: bool) -> None: - """ - export_outfitting updates EDDN with the current (lastStarport) station's outfitting options, if any. + """Update EDDN with the current (lastStarport) station's outfitting options, if any. + Once the send is complete, this.outfitting is updated with the given data. :param data: dict containing the outfitting data @@ -374,9 +381,9 @@ Msg:\n{msg}''' this.outfitting = (horizons, outfitting) def export_shipyard(self, data: CAPIData, is_beta: bool) -> None: - """ - export_shipyard updates EDDN with the current (lastStarport) station's outfitting options, if any. - once the send is complete, this.shipyard is updated to the new data. + """Update EDDN with the current (lastStarport) station's outfitting options, if any. + + Once the send is complete, this.shipyard is updated to the new data. :param data: dict containing the shipyard data :param is_beta: whether or not we are in beta mode @@ -412,9 +419,9 @@ Msg:\n{msg}''' this.shipyard = (horizons, shipyard) def export_journal_commodities(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """ - export_journal_commodities updates EDDN with the commodities list on the current station (lastStarport) from - data in the journal. As a side effect, it also updates this.commodities with the data + """Update EDDN with Journal commodities data from the current station (lastStarport). + + As a side effect, it also updates this.commodities with the data. :param cmdr: The commander to send data under :param is_beta: whether or not we're in beta mode @@ -453,9 +460,9 @@ Msg:\n{msg}''' this.commodities: OrderedDictT[str, Any] = commodities def export_journal_outfitting(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """ - export_journal_outfitting updates EDDN with station outfitting based on a journal entry. As a side effect, - it also updates this.outfitting with the data + """Update EDDN with Journal oufitting data from the current station (lastStarport). + + As a side effect, it also updates this.outfitting with the data. :param cmdr: The commander to send data under :param is_beta: Whether or not we're in beta mode @@ -486,9 +493,9 @@ Msg:\n{msg}''' this.outfitting = (horizons, outfitting) def export_journal_shipyard(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """ - export_journal_shipyard updates EDDN with station shipyard data based on a journal entry. As a side effect, - this.shipyard is updated with the data. + """Update EDDN with Journal shipyard data from the current station (lastStarport). + + As a side effect, this.shipyard is updated with the data. :param cmdr: the commander to send this update under :param is_beta: Whether or not we're in beta mode @@ -514,9 +521,9 @@ Msg:\n{msg}''' this.shipyard = (horizons, shipyard) def export_journal_entry(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """ - export_journal_entry updates EDDN with a line from the journal. Additionally if additional lines are cached, - it may send those as well. + """Update EDDN with an event from the journal. + + Additionally if additional lines are cached, it may send those as well. :param cmdr: the commander under which this upload is made :param is_beta: whether or not we are in beta mode @@ -547,6 +554,12 @@ Msg:\n{msg}''' status['text'] = '' def canonicalise(self, item: str) -> str: + """ + Canonicalise the given commodity name. + + :param item: Name of an commodity we want the canonical name for. + :return: The canonical name for this commodity. + """ match = self.CANONICALISE_RE.match(item) return match and match.group(1) or item @@ -554,10 +567,27 @@ Msg:\n{msg}''' # Plugin callbacks def plugin_start3(plugin_dir: str) -> str: + """ + Start this plugin. + + :param plugin_dir: `str` - The full path to this plugin's directory. + :return: `str` - Name of this plugin to use in UI. + """ return 'EDDN' def plugin_app(parent: tk.Tk) -> None: + """ + Set up any plugin-specific UI. + + In this case we need the tkinter parent in order to later call + `update_idletasks()` on it. + + TODO: Re-work the whole replaylog and general sending to EDDN so this isn't + necessary. + + :param parent: tkinter parent frame. + """ this.parent = parent this.eddn = EDDN(parent) # Try to obtain exclusive lock on journal cache, even if we don't need it yet @@ -567,6 +597,14 @@ def plugin_app(parent: tk.Tk) -> None: def plugin_prefs(parent, cmdr: str, is_beta: bool) -> Frame: + """ + Set up Preferences pane for this plugin. + + :param parent: tkinter parent to attach to. + :param cmdr: `str` - Name of current Cmdr. + :param is_beta: `bool` - True if this is a beta version of the Game. + :return: The tkinter frame we created. + """ PADX = 10 # noqa: N806 BUTTONX = 12 # noqa: N806 # indent Checkbuttons and Radiobuttons @@ -618,15 +656,27 @@ def plugin_prefs(parent, cmdr: str, is_beta: bool) -> Frame: def prefsvarchanged(event=None) -> None: + """ + Handle changes to EDDN Preferences. + + :param event: tkinter event ? + """ this.eddn_station_button['state'] = tk.NORMAL this.eddn_system_button['state'] = tk.NORMAL this.eddn_delay_button['state'] = this.eddn.replayfile and this.eddn_system.get() and tk.NORMAL or tk.DISABLED def prefs_changed(cmdr: str, is_beta: bool) -> None: + """ + Handle when Preferences have been changed. + + :param cmdr: `str` - Name of current Cmdr. + :param is_beta: `bool` - True if this is a beta version of the Game. + """ config.set( 'output', - (config.get_int('output') & (config.OUT_MKT_TD | config.OUT_MKT_CSV | config.OUT_SHIP | config.OUT_MKT_MANUAL)) + + (config.get_int('output') + & (config.OUT_MKT_TD | config.OUT_MKT_CSV | config.OUT_SHIP | config.OUT_MKT_MANUAL)) + (this.eddn_station.get() and config.OUT_MKT_EDDN) + (this.eddn_system.get() and config.OUT_SYS_EDDN) + (this.eddn_delay.get() and config.OUT_SYS_DELAY) @@ -640,9 +690,25 @@ def plugin_stop() -> None: logger.debug('Done.') -def journal_entry( # noqa: C901 - cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any] +def journal_entry( # noqa: C901, CCR001 + cmdr: str, + is_beta: bool, + system: str, + station: str, + entry: MutableMapping[str, Any], + state: Mapping[str, Any] ) -> Optional[str]: + """ + Process a new Journal entry. + + :param cmdr: `str` - Name of currennt Cmdr. + :param is_beta: `bool` - True if this is a beta version of the Game. + :param system: `str` - Name of system Cmdr is in. + :param station: `str` - Name of station Cmdr is docked at, if applicable. + :param entry: `dict` - The data for this Journal entry. + :param state: `dict` - Current `monitor.state` data. + :return: `str` - Error message, or `None` if no errors. + """ if (ks := killswitch.get_disabled("plugins.eddn.journal")).disabled: logger.warning(f"EDDN journal handler has been disabled via killswitch: {ks.reason}") plug.show_error("EDDN journal handler disabled. See Log.") @@ -802,7 +868,14 @@ def journal_entry( # noqa: C901 return str(e) -def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: +def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: # noqa: CCR001 + """ + Process new CAPI data. + + :param data: CAPI data to process. + :param is_beta: bool - True if this is a beta version of the Game. + :return: str - Error message, or `None` if no errors. + """ if data['commander'].get('docked') and config.get_int('output') & config.OUT_MKT_EDDN: try: if this.marketId != data['lastStarport']['id']: @@ -835,6 +908,14 @@ MAP_STR_ANY = Mapping[str, Any] def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY) -> bool: + """ + Indicate if the supplied data indicates a player has Horizons access. + + :param economies: Economies of where the Cmdr is docked. + :param modules: Modules available at the docked station. + :param ships: Ships available at the docked station. + :return: bool - True if the Cmdr has Horizons access. + """ economies_colony = False modules_horizons = False ship_horizons = False From 7da15faaf3c3a721a863919a55b1f665277b8e34 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 16:06:10 +0000 Subject: [PATCH 440/727] plugins/eddn: Convert 'this' to a class for typing reasons. * Typing hates the 'this' hack on module's __name__, so use a small class instead. * Added missing `return None`s. * Other typing cleanups. --- plugins/eddn.py | 78 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 60d6debe..7240f5c7 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -10,9 +10,9 @@ from collections import OrderedDict from os import SEEK_SET from os.path import join from platform import system -from typing import TYPE_CHECKING, Any, AnyStr, Dict, Iterator, List, Mapping, MutableMapping, Optional +from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Mapping, MutableMapping, Optional from typing import OrderedDict as OrderedDictT -from typing import Sequence, TextIO, Tuple +from typing import TextIO, Tuple import requests @@ -36,18 +36,41 @@ if TYPE_CHECKING: logger = get_main_logger() -this: Any = sys.modules[__name__] # For holding module globals -# Track location to add to Journal events -this.systemaddress = None -this.coordinates = None -this.planet = None +class This: + """Holds module globals.""" + + def __init__(self): + # Track location to add to Journal events + self.systemaddress = None + self.coordinates = None + self.planet = None + + # Avoid duplicates + self.marketId = None + self.commodities: Optional[List[OrderedDictT[str, Any]]] = None + self.outfitting: Optional[Tuple[bool, List[str]]] = None + self.shipyard = None + + # For the tkinter parent window, so we can call update_idletasks() + self.parent: tk.Tk + + # To hold EDDN class instance + self.eddn: EDDN + + # tkinter UI bits. + self.eddn_station: tk.IntVar + self.eddn_station_button: nb.Checkbutton + + self.eddn_system: tk.IntVar + self.eddn_system_button: nb.Checkbutton + + self.eddn_delay: tk.IntVar + self.eddn_delay_button: nb.Checkbutton + + +this = This() -# Avoid duplicates -this.marketId = None -this.commodities = None -this.outfitting: Optional[Tuple[bool, MutableMapping[str, Any]]] = None -this.shipyard = None HORIZ_SKU = 'ELITE_HORIZONS_V_PLANETARY_LANDINGS' @@ -137,7 +160,7 @@ class EDDN: uploader_id = cmdr - to_send: OrderedDictT[str, str] = OrderedDict([ + to_send: OrderedDictT[str, OrderedDict[str, Any]] = OrderedDict([ ('$schemaRef', msg['$schemaRef']), ('header', OrderedDict([ ('softwareName', f'{applongname} [{system() if sys.platform != "darwin" else "Mac OS"}]'), @@ -176,7 +199,7 @@ Msg:\n{msg}''' if not self.replayfile: return # Probably closing app - status: Dict[str, Any] = self.parent.children['status'] + status: tk.Widget = self.parent.children['status'] if not self.replaylog: status['text'] = '' @@ -428,7 +451,7 @@ Msg:\n{msg}''' :param entry: the journal entry containing the commodities data """ items: List[Mapping[str, Any]] = entry.get('Items') or [] - commodities: Sequence[OrderedDictT[AnyStr, Any]] = sorted((OrderedDict([ + commodities: List[OrderedDictT[str, Any]] = sorted((OrderedDict([ ('name', self.canonicalise(commodity['Name'])), ('meanPrice', commodity['MeanPrice']), ('buyPrice', commodity['BuyPrice']), @@ -457,7 +480,7 @@ Msg:\n{msg}''' ]), }) - this.commodities: OrderedDictT[str, Any] = commodities + this.commodities = commodities def export_journal_outfitting(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: """Update EDDN with Journal oufitting data from the current station (lastStarport). @@ -537,7 +560,7 @@ Msg:\n{msg}''' if self.replayfile or self.load_journal_replay(): # Store the entry self.replaylog.append(json.dumps([cmdr, msg])) - self.replayfile.write(f'{self.replaylog[-1]}\n') + self.replayfile.write(f'{self.replaylog[-1]}\n') # type: ignore if ( entry['event'] == 'Docked' or (entry['event'] == 'Location' and entry['Docked']) or not @@ -547,11 +570,10 @@ Msg:\n{msg}''' else: # Can't access replay file! Send immediately. - status: MutableMapping[str, str] = self.parent.children['status'] - status['text'] = _('Sending data to EDDN...') + self.parent.children['status']['text'] = _('Sending data to EDDN...') self.parent.update_idletasks() self.send(cmdr, msg) - status['text'] = '' + self.parent.children['status']['text'] = '' def canonicalise(self, item: str) -> str: """ @@ -593,7 +615,7 @@ def plugin_app(parent: tk.Tk) -> None: # Try to obtain exclusive lock on journal cache, even if we don't need it yet if not this.eddn.load_journal_replay(): # Shouldn't happen - don't bother localizing - this.status['text'] = 'Error: Is another copy of this app already running?' + this.parent.children['status']['text'] = 'Error: Is another copy of this app already running?' def plugin_prefs(parent, cmdr: str, is_beta: bool) -> Frame: @@ -739,18 +761,18 @@ def journal_entry( # noqa: C901, CCR001 # Track location if entry['event'] in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): if entry['event'] in ('Location', 'CarrierJump'): - this.planet: Optional[str] = entry.get('Body') if entry.get('BodyType') == 'Planet' else None + this.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None elif entry['event'] == 'FSDJump': - this.planet: Optional[str] = None + this.planet = None if 'StarPos' in entry: - this.coordinates: Optional[Tuple[int, int, int]] = tuple(entry['StarPos']) + this.coordinates = tuple(entry['StarPos']) elif this.systemaddress != entry.get('SystemAddress'): - this.coordinates: Optional[Tuple[int, int, int]] = None # Docked event doesn't include coordinates + this.coordinates = None # Docked event doesn't include coordinates - this.systemaddress: Optional[str] = entry.get('SystemAddress') + this.systemaddress = entry.get('SystemAddress') # type: ignore elif entry['event'] == 'ApproachBody': this.planet = entry['Body'] @@ -867,6 +889,8 @@ def journal_entry( # noqa: C901, CCR001 logger.debug(f'Failed exporting {entry["event"]}', exc_info=e) return str(e) + return None + def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: # noqa: CCR001 """ @@ -903,6 +927,8 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: # noqa: CCR001 logger.debug('Failed exporting data', exc_info=e) return str(e) + return None + MAP_STR_ANY = Mapping[str, Any] From 501682c4390a40460c6aad76bafebbccaad34fe6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 16:19:24 +0000 Subject: [PATCH 441/727] Split text following """ if entire docstring not single line. --- plugins/eddn.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 7240f5c7..fe4a1744 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -261,7 +261,8 @@ Msg:\n{msg}''' self.parent.after(self.REPLAYPERIOD, self.sendreplay) def export_commodities(self, data: Mapping[str, Any], is_beta: bool) -> None: # noqa: CCR001 - """Update EDDN with the commodities on the current (lastStarport) station. + """ + Update EDDN with the commodities on the current (lastStarport) station. Once the send is complete, this.commodities is updated with the new data. @@ -360,7 +361,8 @@ Msg:\n{msg}''' return modules, ships def export_outfitting(self, data: CAPIData, is_beta: bool) -> None: - """Update EDDN with the current (lastStarport) station's outfitting options, if any. + """ + Update EDDN with the current (lastStarport) station's outfitting options, if any. Once the send is complete, this.outfitting is updated with the given data. @@ -404,7 +406,8 @@ Msg:\n{msg}''' this.outfitting = (horizons, outfitting) def export_shipyard(self, data: CAPIData, is_beta: bool) -> None: - """Update EDDN with the current (lastStarport) station's outfitting options, if any. + """ + Update EDDN with the current (lastStarport) station's outfitting options, if any. Once the send is complete, this.shipyard is updated to the new data. @@ -442,7 +445,8 @@ Msg:\n{msg}''' this.shipyard = (horizons, shipyard) def export_journal_commodities(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """Update EDDN with Journal commodities data from the current station (lastStarport). + """ + Update EDDN with Journal commodities data from the current station (lastStarport). As a side effect, it also updates this.commodities with the data. @@ -483,7 +487,8 @@ Msg:\n{msg}''' this.commodities = commodities def export_journal_outfitting(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """Update EDDN with Journal oufitting data from the current station (lastStarport). + """ + Update EDDN with Journal oufitting data from the current station (lastStarport). As a side effect, it also updates this.outfitting with the data. @@ -516,7 +521,8 @@ Msg:\n{msg}''' this.outfitting = (horizons, outfitting) def export_journal_shipyard(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """Update EDDN with Journal shipyard data from the current station (lastStarport). + """ + Update EDDN with Journal shipyard data from the current station (lastStarport). As a side effect, this.shipyard is updated with the data. @@ -544,7 +550,8 @@ Msg:\n{msg}''' this.shipyard = (horizons, shipyard) def export_journal_entry(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: - """Update EDDN with an event from the journal. + """ + Update EDDN with an event from the journal. Additionally if additional lines are cached, it may send those as well. From 567bda048dd6d174016a2b7e9d8c459eb26c8275 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 26 Mar 2021 16:27:59 +0000 Subject: [PATCH 442/727] plugins/eddn: Ensure types on all 'this' variables. --- plugins/eddn.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index fe4a1744..0cd91537 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -42,15 +42,15 @@ class This: def __init__(self): # Track location to add to Journal events - self.systemaddress = None - self.coordinates = None - self.planet = None + self.systemaddress: Optional[str] = None + self.coordinates: Optional[Tuple] = None + self.planet: Optional[str] = None # Avoid duplicates - self.marketId = None + self.marketId: Optional[str] = None self.commodities: Optional[List[OrderedDictT[str, Any]]] = None self.outfitting: Optional[Tuple[bool, List[str]]] = None - self.shipyard = None + self.shipyard: Optional[Tuple[bool, List[Mapping[str, Any]]]] = None # For the tkinter parent window, so we can call update_idletasks() self.parent: tk.Tk From 71fb362c52c2a143cb9d325e4e8f44933aa43228 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 27 Mar 2021 11:04:19 +0000 Subject: [PATCH 443/727] EDMarketConnector.py: Two missing type annotations Surprisingly window_title has nice simple types. --- EDMarketConnector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 5161f574..2a0c37fd 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -89,7 +89,7 @@ if __name__ == '__main__': # noqa: C901 if args.force_localserver_for_auth: config.set_auth_force_localserver() - def handle_edmc_callback_or_foregrounding(): # noqa: CCR001 + def handle_edmc_callback_or_foregrounding() -> None: # noqa: CCR001 """Handle any edmc:// auth callback, else foreground existing window.""" logger.trace('Begin...') @@ -122,7 +122,7 @@ if __name__ == '__main__': # noqa: C901 ShellExecute = ctypes.windll.shell32.ShellExecuteW # noqa: N806 ShellExecute.argtypes = [HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT] - def window_title(h): + def window_title(h: int) -> Optional[str]: if h: text_length = GetWindowTextLength(h) + 1 buf = ctypes.create_unicode_buffer(text_length) From 20645f0731aedbc101f7ee4366c7400d384c3933 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 14:46:41 +0100 Subject: [PATCH 444/727] Pre-Release 5.0.0-beta1: Changelog appversion was already set from use in `develop`. # Conflicts: # ChangeLog.md # Conflicts: # ChangeLog.md --- ChangeLog.md | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index f66335f5..5074c6e0 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,110 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- +Pre-Release 5.0.0-beta1 +=== + +This release comes after some substantial code cleanup and is our first based +on Python 3.9 rather than 3.7. Other than what is noted in this changelog +it should have the same functionality as 4.2.4. + +* We are now testing and building with Python 3.9 (3.9.2 specifically at + this point). This should have no impact on users or plugin developers, other + than the latter now being free to use features that were introduced since the + Python 3.7 series. + + For developers you can check the contents of the `.python-version` file + in the source (it's not distributed with the Windows installer) for the + currently used version in a given branch. + +* We now also cite the git 'short hash' in the version string. For a Windows + install of the application this is sourced from the `.gitversion` file + (written during the build process). + + When running from source we attempt to use the command `git rev-parse --short HEAD` + to obtain this. If this doesn't work it will be set to 'UNKNOWN'. + +* New 'Main window transparency' slider on `Settings` > `Appearance`. + +* New command-line argument for EDMarketConnector.exe `--reset-ui`. This will: + + 1. Reset to the default Theme. + 2. Reset the UI transparency to fully opaque. + + The intention is this can be used if you've lost sight of the main window + due to tweaking these options. + +* We have added a 'killswitch' feature to turn off specific functionality if it + is found to have a bug. An example use of this would be in an "oh + shit! we're sending bad data to EDDN!" moment so as to protect EDDN + listeners such as EDDB. + + If we ever have to use this we'll announce it clearly and endeavour to + get a fixed version of the program released ASAP. We will **NOT** be + using this merely to try and get some laggards to upgrade. + +* Our logging code will make best efforts to still show class name and + other such fields if it has trouble finding any of the required data for + the calling frame. This means no longer seeing `??:??:??` when there is + an issue with this. + +* macOS: We've managed to test the latest code on macOS Catalina. Other than + [keyboard shortcut support not working](https://github.com/EDCD/EDMarketConnector/issues/906) + it appears to be working. + +* We've pulled the latest Coriolis data which might have caused changes to + ship and module names as written out to some files. + +Plugin Developers +----------------- + +* config.py has undergone a major rewrite. You should no longer be using + `config.get(...)` or `config.getint(...)`, which will both give a + deprecation warning. + Use instead the correct config.get_ function: + + * `config.get_list()` + * `config.get_str()` + * `config.get_bool()` + * `config.get_int()` + + Setting still uses `config.set(...)`. + +* The files `stations.p` and `systems.p` have been removed from the Windows + Installer. These were never intended for third-party use. Their core + code use was for generating EDDB-id links, but we long since changed the + EDDB plugin's handlers for that to use alternate URL formats based on + game IDs or names. + + If you were using either to lookup EDDB IDs for systems and/or stations + then please see how `system_url()` and `station_url` now work in + `plugins/eddb.py`. + + This change also removed the core (not plugin) `eddb.py` file which + generated these files. You can find it still in the git history if needs + be. It had gotten to the stage where generating `systems.p` took many + hours and required 64-bit Python to have any hope of working due to + memory usage. + +* Support has been added for the `NavRoute` (not `Route` as v28 of the + official Journal documentation erroneously labels it) Journal event and + its associated file `NavRoute.json`. See [PLUGINS.md:Events documentation](https://github.com/EDCD/EDMarketConnector/blob/main/PLUGINS.md#journal-entry) + +* Similarly there is now support for the `ModuleInfo` event and its + associated `ModulesInfo.json` file. + +Code Clean Up +------------- + +* Some code to do with processing Journal events has been re-factored. + +* The code for `File` > `Status` has been cleaned up. + +* Localisation code has been cleaned up. + +* Code handling the Frontier Authorisation callback on Windows has been + cleaned up. + Release 4.2.7 === From 0a437961a39c5369a64d03a15e9f386ff3f1a65b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 28 Mar 2021 11:21:07 +0100 Subject: [PATCH 445/727] plugintest: Add event type to logging & convert to classed 'this'. --- docs/examples/plugintest/load.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index 4a614aa2..2e43f12e 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -6,7 +6,6 @@ import logging import os import shutil import sqlite3 -import sys import zipfile from SubA import SubA @@ -32,9 +31,16 @@ if not logger.hasHandlers(): logger.addHandler(logger_channel) -this = sys.modules[__name__] # For holding module globals -this.DBFILE = 'plugintest.db' -this.mt = None +class This: + """Module global variables.""" + + def __init__(self): + self.DBFILE = 'plugintest.db' + self.plugin_test: PluginTest + self.suba: SubA + + +this = This() class PluginTest(object): @@ -87,7 +93,7 @@ def plugin_start3(plugin_dir: str) -> str: :return: 'Pretty' name of this plugin. """ logger.info(f'Folder is {plugin_dir}') - this.mt = PluginTest(plugin_dir) + this.plugin_test = PluginTest(plugin_dir) this.suba = SubA(logger) @@ -117,5 +123,9 @@ def journal_entry(cmdrname: str, is_beta: bool, system: str, station: str, entry :param state: :return: None """ - logger.debug(f'cmdr = "{cmdrname}", is_beta = "{is_beta}", system = "{system}", station = "{station}"') - this.mt.store(entry['timestamp'], cmdrname, system, station, entry['event']) + logger.debug( + f'cmdr = "{cmdrname}", is_beta = "{is_beta}"' + f', system = "{system}", station = "{station}"' + f', event = "{entry["event"]}' + ) + this.plugin_test.store(entry['timestamp'], cmdrname, system, station, entry['event']) From c0324b2d3f314c72e5c461652fab1ed8d04c9e6e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 28 Mar 2021 11:29:54 +0100 Subject: [PATCH 446/727] plugintest: Add missing " in logging --- docs/examples/plugintest/load.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index 2e43f12e..8e92c73c 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -126,6 +126,6 @@ def journal_entry(cmdrname: str, is_beta: bool, system: str, station: str, entry logger.debug( f'cmdr = "{cmdrname}", is_beta = "{is_beta}"' f', system = "{system}", station = "{station}"' - f', event = "{entry["event"]}' + f', event = "{entry["event"]}"' ) this.plugin_test.store(entry['timestamp'], cmdrname, system, station, entry['event']) From dc920fdc6a740d12251044972be62eb61f6c8250 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 28 Mar 2021 11:50:49 +0100 Subject: [PATCH 447/727] plugintest: Implement example EDMC core version check. --- docs/examples/plugintest/load.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index 8e92c73c..b64a0cb8 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -8,9 +8,10 @@ import shutil import sqlite3 import zipfile +import semantic_version from SubA import SubA -from config import appname +from config import appname, appversion # This could also be returned from plugin_start3() plugin_name = os.path.basename(os.path.dirname(__file__)) @@ -92,6 +93,23 @@ def plugin_start3(plugin_dir: str) -> str: :param plugin_dir: :return: 'Pretty' name of this plugin. """ + if isinstance(appversion, str): + core_version = appversion + + elif callable(appversion): + core_version = appversion() + + else: + core_version = '' + + logger.info(f'Core EDMC version: {core_version}') + core_version_sv = semantic_version.Version(core_version) + if core_version_sv < semantic_version.Version('5.0.0-beta1'): + logger.info('EDMC core version is before 5.0.0-beta1') + + else: + logger.info('EDMC core version is at least 5.0.0-beta1') + logger.info(f'Folder is {plugin_dir}') this.plugin_test = PluginTest(plugin_dir) From b841d434e5c011396b3fd49503eb3b88236cc3cf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 28 Mar 2021 12:01:05 +0100 Subject: [PATCH 448/727] plugintest: Document core version code & add to PLUGINS.md * New PLUGINS.md section 'Checking core EDMC version'. * And the same comments might as well be in the plugintest/load.py. --- PLUGINS.md | 34 ++++++++++++++++++++++++++++++++ docs/examples/plugintest/load.py | 9 ++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 9ccd0df6..d80e1e66 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -170,6 +170,40 @@ functions, in the output. --- +### Checking core EDMC version + +If you have code that needs to act differently under different versions of +this application then you can check the core version using: + +```python +import semantic_version +from config import appversion + +... + if isinstance(appversion, str): + core_version = appversion # Up until 5.0.0-beta1 this is a string + + elif callable(appversion): + core_version = appversion() # From 5.0.0-beta1 it's a function + + else: + core_version = '' # Paranoia + + # Either way you now have a string + logger.info(f'Core EDMC version: {core_version}') + # The easiest way to compare is using semantic_version, so convert + core_version_sv = semantic_version.Version(core_version) + # And then compare like this + if core_version_sv < semantic_version.Version('5.0.0-beta1'): + logger.info('EDMC core version is before 5.0.0-beta1') + + else: + logger.info('EDMC core version is at least 5.0.0-beta1') + +``` + +--- + ### Startup EDMC will import the `load.py` file as a module and then call the diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index b64a0cb8..c5eedd88 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -94,16 +94,19 @@ def plugin_start3(plugin_dir: str) -> str: :return: 'Pretty' name of this plugin. """ if isinstance(appversion, str): - core_version = appversion + core_version = appversion # Up until 5.0.0-beta1 this is a string elif callable(appversion): - core_version = appversion() + core_version = appversion() # From 5.0.0-beta1 it's a function else: - core_version = '' + core_version = '' # Paranoia + # Either way you now have a string logger.info(f'Core EDMC version: {core_version}') + # The easiest way to compare is using semantic_version, so convert core_version_sv = semantic_version.Version(core_version) + # And then compare like this if core_version_sv < semantic_version.Version('5.0.0-beta1'): logger.info('EDMC core version is before 5.0.0-beta1') From 5de4950fbaa96c1de37900630b140800124d31c6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 28 Mar 2021 12:28:22 +0100 Subject: [PATCH 449/727] Change config.appversion() to return semantic_version.Version As we're changing it to a function at this stage anyway, it might as well return this type, not a str. --- PLUGINS.md | 15 ++++++--------- config.py | 8 ++++---- docs/examples/plugintest/load.py | 16 +++++++--------- killswitch.py | 2 +- update.py | 2 +- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index d80e1e66..7393c439 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -180,26 +180,23 @@ import semantic_version from config import appversion ... + # Up until 5.0.0-beta1 config.appversion is a string if isinstance(appversion, str): - core_version = appversion # Up until 5.0.0-beta1 this is a string + core_version = semantic_version.Version(appversion) elif callable(appversion): - core_version = appversion() # From 5.0.0-beta1 it's a function + # From 5.0.0-beta1 it's a function, returning semantic_version.Version + core_version = appversion() - else: - core_version = '' # Paranoia + # Yes, just blow up if config.appverison is neither str or callable - # Either way you now have a string logger.info(f'Core EDMC version: {core_version}') - # The easiest way to compare is using semantic_version, so convert - core_version_sv = semantic_version.Version(core_version) # And then compare like this - if core_version_sv < semantic_version.Version('5.0.0-beta1'): + if core_version < semantic_version.Version('5.0.0-beta1'): logger.info('EDMC core version is before 5.0.0-beta1') else: logger.info('EDMC core version is at least 5.0.0-beta1') - ``` --- diff --git a/config.py b/config.py index 95fcc78c..54ece308 100644 --- a/config.py +++ b/config.py @@ -126,7 +126,7 @@ def git_shorthash_from_head() -> str: return shorthash -def appversion() -> str: +def appversion() -> semantic_version.Version: """ Determine app version including git short hash if possible. @@ -145,10 +145,10 @@ def appversion() -> str: if shorthash is None: shorthash = 'UNKNOWN' - return f'{_static_appversion}+{shorthash}' + return semantic_version.Version(f'{_static_appversion}+{shorthash}') -def appversion_nobuild() -> str: +def appversion_nobuild() -> semantic_version.Version: """ Determine app version without *any* build meta data. @@ -157,7 +157,7 @@ def appversion_nobuild() -> str: :return: str - App version without any build meta data. """ - return str(semantic_version.Version(appversion()).truncate('prerelease')) + return appversion().truncate('prerelease') ########################################################################### diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index c5eedd88..9f243d93 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -93,26 +93,24 @@ def plugin_start3(plugin_dir: str) -> str: :param plugin_dir: :return: 'Pretty' name of this plugin. """ + # Up until 5.0.0-beta1 config.appversion is a string if isinstance(appversion, str): - core_version = appversion # Up until 5.0.0-beta1 this is a string + core_version = semantic_version.Version(appversion) elif callable(appversion): - core_version = appversion() # From 5.0.0-beta1 it's a function + # From 5.0.0-beta1 it's a function, returning semantic_version.Version + core_version = appversion() - else: - core_version = '' # Paranoia - - # Either way you now have a string logger.info(f'Core EDMC version: {core_version}') - # The easiest way to compare is using semantic_version, so convert - core_version_sv = semantic_version.Version(core_version) # And then compare like this - if core_version_sv < semantic_version.Version('5.0.0-beta1'): + if core_version < semantic_version.Version('5.0.0-beta1'): logger.info('EDMC core version is before 5.0.0-beta1') else: logger.info('EDMC core version is at least 5.0.0-beta1') + # Yes, just blow up if config.appverison is neither str or callable + logger.info(f'Folder is {plugin_dir}') this.plugin_test = PluginTest(plugin_dir) diff --git a/killswitch.py b/killswitch.py index cb75c2cf..aca020aa 100644 --- a/killswitch.py +++ b/killswitch.py @@ -11,7 +11,7 @@ logger = EDMCLogging.get_main_logger() DEFAULT_KILLSWITCH_URL = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/killswitches.json' -_current_version: semantic_version.Version = semantic_version.Version(config.appversion_nobuild()) +_current_version: semantic_version.Version = config.appversion_nobuild() class KillSwitch(NamedTuple): diff --git a/update.py b/update.py index e71f39b9..c025609a 100644 --- a/update.py +++ b/update.py @@ -177,7 +177,7 @@ class Updater(object): ) # Look for any remaining version greater than appversion - simple_spec = semantic_version.SimpleSpec('>' + appversion_nobuild()) + simple_spec = semantic_version.SimpleSpec(f'>{appversion_nobuild()}') newversion = simple_spec.select(items.keys()) if newversion: From 4d1c6906e7390d86d00ac3155445c54db0ccd44f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 28 Mar 2021 12:58:07 +0100 Subject: [PATCH 450/727] Maybe I should stop putting types on :return: and :param: ... --- config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 54ece308..38bad78e 100644 --- a/config.py +++ b/config.py @@ -130,7 +130,7 @@ def appversion() -> semantic_version.Version: """ Determine app version including git short hash if possible. - :return: str - The augmented app version. + :return: The augmented app version. """ if getattr(sys, 'frozen', False): # Running frozen, so we should have a .gitversion file @@ -155,7 +155,7 @@ def appversion_nobuild() -> semantic_version.Version: This will not only strip any added git short hash, but also any trailing '+' in _static_appversion. - :return: str - App version without any build meta data. + :return: App version without any build meta data. """ return appversion().truncate('prerelease') ########################################################################### From 4398e7a85e861b4a97a1a8cc37d3b57b72ae8113 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Mar 2021 06:58:24 +0000 Subject: [PATCH 451/727] build(deps-dev): bump py2exe from 0.10.3.0 to 0.10.3.1 Bumps [py2exe](https://github.com/py2exe/py2exe) from 0.10.3.0 to 0.10.3.1. - [Release notes](https://github.com/py2exe/py2exe/releases) - [Changelog](https://github.com/py2exe/py2exe/blob/master/ChangeLog) - [Commits](https://github.com/py2exe/py2exe/compare/v0.10.3.0...v0.10.3.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 481b066f..b876d56a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -27,7 +27,7 @@ grip==4.5.2 # Packaging # We only need py2exe on windows. -py2exe==0.10.3.0; sys_platform == 'win32' +py2exe==0.10.3.1; sys_platform == 'win32' # Testing pytest==6.2.2 From 69bc90f5b44f02dc34795150e5fc69ef5bab6ae0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Mar 2021 11:14:46 +0100 Subject: [PATCH 452/727] Make export_ship() paranoid about possible encoding issues. We had a report of a UnicodeDecodeError trying to read an old file. So try utf-8 first, if it fails try the default, and if nothing else try to write a new file so the next call should actually work as expected. --- monitor.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/monitor.py b/monitor.py index 18a751b7..e0c75ff3 100644 --- a/monitor.py +++ b/monitor.py @@ -1085,7 +1085,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return d - def export_ship(self, filename=None) -> None: + def export_ship(self, filename=None) -> None: # noqa: C901, CCR001 """ Export ship loadout as a Loadout event. @@ -1124,9 +1124,23 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below regexp = re.compile(re.escape(ship) + r'\.\d{4}\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted((x for x in listdir(config.get_str('outdir')) if regexp.match(x))) # type: ignore if oldfiles: - with open(join(config.get_str('outdir'), oldfiles[-1]), 'rU') as h: # type: ignore - if h.read() == string: - return # same as last time - don't write + try: + with open(join(config.get('outdir'), oldfiles[-1]), 'r', encoding='utf-8') as h: # type: ignore + if h.read() == string: + return # same as last time - don't write + + except UnicodeError: + logger.exception("UnicodeError reading old ship loadout with utf-8 encoding, trying without...") + try: + with open(join(config.get('outdir'), oldfiles[-1]), 'rU') as h: # type: ignore + if h.read() == string: + return # same as last time - don't write + + except OSError: + logger.exception("OSError reading old ship loadout default encoding.") + + except OSError: + logger.exception("OSError reading old ship loadout with default encoding") # Write ts = strftime('%Y-%m-%dT%H.%M.%S', localtime(time())) From be740d0bcdd582038c4861bbcfe0d7045bd2ba33 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Mar 2021 11:19:48 +0100 Subject: [PATCH 453/727] Remove another open 'U' flag. --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index e0c75ff3..8cebc237 100644 --- a/monitor.py +++ b/monitor.py @@ -1132,7 +1132,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below except UnicodeError: logger.exception("UnicodeError reading old ship loadout with utf-8 encoding, trying without...") try: - with open(join(config.get('outdir'), oldfiles[-1]), 'rU') as h: # type: ignore + with open(join(config.get('outdir'), oldfiles[-1]), 'r') as h: # type: ignore if h.read() == string: return # same as last time - don't write From b0bda6e9827510d90ca3e2ab11bf7dda8859d2cf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Mar 2021 16:34:00 +0100 Subject: [PATCH 454/727] EDDN: Convert appversion_nobuild() to str Without this the JSON serialisation later on barfs on it. --- plugins/eddn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 0cd91537..0655bf80 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -164,7 +164,7 @@ class EDDN: ('$schemaRef', msg['$schemaRef']), ('header', OrderedDict([ ('softwareName', f'{applongname} [{system() if sys.platform != "darwin" else "Mac OS"}]'), - ('softwareVersion', appversion_nobuild()), + ('softwareVersion', str(appversion_nobuild())), ('uploaderID', uploader_id), ])), ('message', msg['message']), From d585dd9233426dd1a19a7fb502bd8014623752f7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Mar 2021 16:35:41 +0100 Subject: [PATCH 455/727] Also str() appversion in EDSM and Inara plugins --- plugins/edsm.py | 2 +- plugins/inara.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/edsm.py b/plugins/edsm.py index e61fa5ab..0c0ec3db 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -573,7 +573,7 @@ def worker() -> None: 'commanderName': username.encode('utf-8'), 'apiKey': apikey, 'fromSoftware': applongname, - 'fromSoftwareVersion': appversion(), + 'fromSoftwareVersion': str(appversion()), 'message': json.dumps(pending, ensure_ascii=False).encode('utf-8'), } diff --git a/plugins/inara.py b/plugins/inara.py index c7333b0a..fcb5c86f 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1222,7 +1222,7 @@ def new_worker(): data = { 'header': { 'appName': applongname, - 'appVersion': appversion(), + 'appVersion': str(appversion()), 'APIkey': creds.api_key, 'commanderName': creds.cmdr, 'commanderFrontierID': creds.fid From 3c47b6c782ac79d930c0a3720380566629200522 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Mar 2021 16:49:18 +0100 Subject: [PATCH 456/727] Fix semantic_version appversion issues in update.py and setup.py --- setup.py | 13 +++++++------ update.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 3e67f846..525dc313 100755 --- a/setup.py +++ b/setup.py @@ -53,7 +53,8 @@ else: assert False, f'Unsupported platform {sys.platform}' # Split version, as py2exe wants the 'base' for version -semver = semantic_version.Version.coerce(appversion()) +semver = appversion() +appversion_str = str(semver) base_appversion = str(semver.truncate('patch')) if dist_dir and len(dist_dir) > 1 and isdir(dist_dir): @@ -154,8 +155,8 @@ if sys.platform == 'darwin': 'CFBundleName': applongname, 'CFBundleIdentifier': f'uk.org.marginal.{appname.lower()}', 'CFBundleLocalizations': get_cfbundle_localizations(), - 'CFBundleShortVersionString': appversion(), - 'CFBundleVersion': appversion(), + 'CFBundleShortVersionString': appversion_str, + 'CFBundleVersion': appversion_str, 'CFBundleURLTypes': [ { 'CFBundleTypeRole': 'Viewer', @@ -229,7 +230,7 @@ elif sys.platform == 'win32': setup( name=applongname, - version=appversion(), + version=appversion_str, windows=[ { 'dest_base': appname, @@ -238,7 +239,7 @@ setup( 'company_name': 'EDCD', # Used by WinSparkle 'product_name': appname, # Used by WinSparkle 'version': base_appversion, - 'product_version': appversion(), + 'product_version': appversion_str, 'copyright': copyright, 'other_resources': [(24, 1, open(f'{appname}.manifest').read())], } @@ -250,7 +251,7 @@ setup( 'company_name': 'EDCD', 'product_name': appname, 'version': base_appversion, - 'product_version': appversion(), + 'product_version': appversion_str, 'copyright': copyright, 'other_resources': [(24, 1, open(f'{appcmdname}.manifest').read())], } diff --git a/update.py b/update.py index c025609a..00fe9e6d 100644 --- a/update.py +++ b/update.py @@ -81,7 +81,7 @@ class Updater(object): # NB: It 'accidentally' supports pre-release due to how it # splits and compares strings: # - self.updater.win_sparkle_set_app_build_version(appversion_nobuild()) + self.updater.win_sparkle_set_app_build_version(str(appversion_nobuild())) # set up shutdown callback global root From 95458f12c7046f26193a30678d32656cf6f186f9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Mar 2021 19:59:05 +0100 Subject: [PATCH 457/727] Pre-Release 5.0.0-beta2: appversion & changelog --- ChangeLog.md | 28 ++++++++++++++++++++++++++++ config.py | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5074c6e0..31a3a69b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,34 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- +Pre-Release 5.0.0-beta2 +=== + +* Support the 'JournalAlpha' files from the Odyssey Alpha. We've confirmed + any data from these is correctly tagged as 'beta' for the is_beta flag + passed to plugins. + + Any data from Odyssey Alpha is sent to EDDN using the test schemas. + + No data from Odyssey Alpha is sent to the EDSM or Inara APIs. + +* Fix ship loadout export to files to not trip up in the face of file encoding + issues. This relates to the 'Ship Loadout' option on the 'Output' tab of + Settings/Preferences. + +Plugin Authors +--- + +* `config.appversion()` now returns a `semantic_version.Version`. In contexts + where you're expecting a string this should mostly just work. If needs + be wrap it in a `str()`. + +* Example plugin + [plugintest](https://github.com/EDCD/EDMarketConnector/tree/main/docs/examples/plugintest) + updated. This includes an example of how to check core EDMC version if needs + be. This example is also in + [PLUGINS.md](https://github.com/EDCD/EDMarketConnector/blob/main/PLUGINS.md#checking-core-edmc-version). + Pre-Release 5.0.0-beta1 === diff --git a/config.py b/config.py index 38bad78e..f8afe737 100644 --- a/config.py +++ b/config.py @@ -41,7 +41,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta1' +_static_appversion = '5.0.0-beta2' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From 7ae40591adbe3989bb775413ed5c3d80963437cd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 12:05:46 +0100 Subject: [PATCH 458/727] PLUGINS.md: Big cleanup * New 'Avoiding potential pitfalls' section to be sure we list them all. * All plain text now wrapped at 80 columns. * Re-did all the section headings for consistency, and added many `---` between sections. * Headers added within the 'Plugin-specific events' section. --- PLUGINS.md | 264 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 190 insertions(+), 74 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 7393c439..79e0fe62 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -31,15 +31,20 @@ If you're developing your plugin simply against an install of EDMarketConnector then you'll be relying on the bundled version of Python (it's baked into the .exe via the py2exe build process). ---- - -### Examples - -We have some example plugins available in the docs/examples directory. See the readme in each folder for more info. +Please be sure to read the [Avoiding potential pitfalls](#avoiding-potential-pitfalls) +section, else you might inadvertently cause issues for the core EDMC code +including whole application crashes. --- -### Available imports +## Examples + +We have some example plugins available in the docs/examples directory. See the +readme in each folder for more info. + +--- + +## Available imports **`import`ing anything from the core EDMarketConnector code that is not explicitly mentioned here is unsupported and may lead to your plugin @@ -55,10 +60,10 @@ breaking with future code changes.** `from prefs import prefsVersion` - to allow for versioned preferences. -`from companion import category_map` - Or any of the other static date +`from companion import category_map` - Or any of the other static data contained therein. NB: There's a plan to move such to a `data` module. -`import plug` - Mostly for using `plug.show_error()`. Also the flags +`import plug` - For using `plug.show_error()` and accessing the flags for `dashboard_entry()` to be useful (see example below). Relying on anything else isn't supported. @@ -66,19 +71,16 @@ else isn't supported. think the game is running. *NB: This is a function, and should be called as such. Using the bare word `game_running` will always be `True`.* -`import timeout_session` - provides a method called `new_session` that creates a requests.session with a default timeout -on all requests. Recommended to reduce noise in HTTP requests - -```python -from ttkHyperlinkLabel import HyperlinkLabel -import myNotebook as nb -``` +`import timeout_session` - provides a method called `new_session` that creates +a requests.session with a default timeout on all requests. Recommended to +reduce noise in HTTP requests +`from ttkHyperlinkLabel import HyperlinkLabel` and `import myNotebook as nb` - For creating UI elements. --- -### Logging +## Logging In the past the only way to provide any logged output from a plugin was to use `print(...)` statements. When running the application from @@ -90,7 +92,8 @@ EDMC now implements proper logging using the Python `logging` module. Plugin developers should now use the following code instead of simple `print(...)` statements. -Insert this at the top-level of your load.py file (so not inside `plugin_start3()` ): +Insert this at the top-level of your load.py file (so not inside +`plugin_start3()`): ```python import logging @@ -161,8 +164,8 @@ Replace all `print(...)` statements with one of the following: logger.debug('Exception we only note in debug output', exc_info=e) ``` -Remember you can use [fstrings](https://www.python.org/dev/peps/pep-0498/) to include variables, and even the returns of -functions, in the output. +Remember you can use [fstrings](https://www.python.org/dev/peps/pep-0498/) to +include variables, and even the returns of functions, in the output. ```python logger.debug(f"Couldn't frob the {thing} with the {wotsit()}") @@ -170,7 +173,7 @@ functions, in the output. --- -### Checking core EDMC version +## Checking core EDMC version If you have code that needs to act differently under different versions of this application then you can check the core version using: @@ -201,7 +204,7 @@ from config import appversion --- -### Startup +## Startup EDMC will import the `load.py` file as a module and then call the `plugin_start3()` function. @@ -226,20 +229,77 @@ Mac, and `$TMP/EDMarketConnector.log` on Linux. | `plugin_dir` | `str` | The directory that your plugin is located in. | | `RETURN` | `str` | The name you want to be used for your plugin internally | -### Shutdown +--- -This gets called when the user closes the program: +## Avoiding potential pitfalls + +There are a number of things that your code should either do or avoiding +doing so as to play nicely with the core EDMC code and not risk causing +application crashes or hangs. + +### Use a thread for long-running code + +By default your plugin code will be running in the main thread. So, if you +perform some operation that takes significant time (more than a second) you +will be blocking both the core code from continuing *and* any other plugins +from running their main-thread code. + +This includes any connections to remote services, such as a website or +remote database. So please place such code within its own thread. + +See the [EDSM plugin](https://github.com/EDCD/EDMarketConnector/blob/main/plugins/edsm.py) +code for an example of using a thread worker, along +with a queue to send data, and telling the sub-thread to stop during shutdown. + +### All tkinter calls in main thread + +The only tkinter calls that should ever be made from a sub-thread are +`event_generate()` calls to send data back to the main thread. + +Any attempt to manipulate tkinter UI elements directly from a sub-thread +will most likely crash the whole program. + +See the [EDSM plugin](https://github.com/EDCD/EDMarketConnector/blob/main/plugins/edsm.py) +code for an example of using `event_generate()` to cause the plugin main +thread code to update a UI element. Start from the `plugin_app()` +implementation. + +### Do not call tkinter `event_generate` during shutdown. + +However, you must **not** make *any* tkinter `event_generate()` call whilst +the application is shutting down. + +The application shutdown sequence is itself triggered from the `<>` event +handler, and generating another event from any code in, or called from, +there causes the application to hang somewhere in the tk libraries. + +You can detect if the application is shutting down with the boolean +`config.shutting_down`. Note that although this is technically a function +its implementation is of a property on `config.AbstractConfig` and thus you +should treat it as a variable. + +**Do NOT use**: ```python -def plugin_stop() -> None: - """ - EDMC is closing - """ - print("Farewell cruel world!") + from config import shutting_down + + if shutting_down(): + # During shutdown ``` -If your plugin uses one or more threads to handle Events then `stop()` and `join()` -(to wait for their exit -- Recommended, not required) the threads before returning from this function. +as this will cause the 'During shutdown' branch to *always* be taken, as in +this context you're testing if the function exists, and that is always True. + +So instead use: + +```python + from config import shutting_down + + if shutting_down: + # During shutdown +``` + +--- ## Plugin Hooks @@ -251,9 +311,10 @@ title will be the value that you returned from `plugin_start3`. Use widgets from EDMC's myNotebook.py for the correct look-and-feel. You can be notified when the settings dialog is closed so you can save your settings. -You can use `set()` and `get_$type()` (where type is one of: `int`, `bool`, `str`, `list`) from EDMC's -`config.config` object to retrieve your plugin's settings in a platform-independent way. Previously this was done with -a single set and two get methods, the new methods provide better type safety. +You can use `set()` and `get_$type()` (where type is one of: `int`, `bool`, +`str`, `list`) from EDMC's `config.config` object to retrieve your plugin's +settings in a platform-independent way. Previously this was done with a single +set and two get methods, the new methods provide better type safety. **Be sure to use a unique prefix for any settings you save so as not to clash with core EDMC or other plugins.** @@ -313,6 +374,8 @@ def prefs_changed(cmdr: str, is_beta: bool) -> None: | `cmdr` | `str` | The current commander | | `is_beta` | `bool` | If the game is currently a beta version | +--- + ### Display You can also have your plugin add an item to the EDMC main window and update @@ -353,12 +416,15 @@ def some_other_function() -> None: | `parent` | `tk.Frame` | The root EDMC window | | `RETURN` | `Union[tk.Widget, Tuple[tk.Widget, tk.Widget]]` | A widget to add to the main window. See below for more info | -The return from plugin_app can either be any widget (Frame, Label, Notebook, etc.), or a 2 tuple of widgets. In the case of -a 2 tuple, indices 0 and 1 are placed automatically in the outer grid on column indices 0 and 1. Otherwise, the only thing done -to your return widget is it is set to use a columnspan of 2, and placed on the grid. +The return from `plugin_app()` can either be any widget (`Frame`, `Label`, +`Notebook`, etc.), or a 2-tuple of widgets. In the case of a 2-tuple, indices +0 and 1 are placed automatically in the outer grid on column indices 0 and 1. +Otherwise, the only thing done to your return widget is it is set to use a +columnspan of 2, and placed on the grid. -You can dynamically add and remove widgets on the main window by returning a tk.Frame from `plugin_app()` and later -creating and destroying child widgets of that frame. +You can dynamically add and remove widgets on the main window by returning a +`tk.Frame` from `plugin_app()` and later creating and destroying child widgets +of that frame. ```python from typing import Option @@ -386,6 +452,11 @@ def some_other_function_called_later() -> None: theme.update(this.frame) # Apply theme colours to the frame and its children, including the new widgets ``` +Remember, you must **NOT** manipulate any tkinter elements from a sub-thread! +See [Avoiding potential pitfalls](#avoiding-potential-pitfalls). + +--- + ### Events Once you have created your plugin and EDMC has loaded it there are three other @@ -515,28 +586,7 @@ Examples of this are: `ModulesInfo.json` file. It's also available as `monitor.stat['ModuleInfo']` (noting that we used the singular form there to stay consistent with the Journal event name). - -#### Player Dashboard - -```python -import plug - -def dashboard_entry(cmdr: str, is_beta: bool, entry: Dict[str, Any]): - is_deployed = entry['Flags'] & plug.FlagsHardpointsDeployed - sys.stderr.write("Hardpoints {}\n".format(is_deployed and "deployed" or "stowed")) -``` - -This gets called when something on the player's cockpit display changes - -typically about once a second when in orbital flight. - -| Parameter | Type | Description | -| :-------- | :----: | :-------------------------------- | -| `cmdr` | `str` | Current command name | -| `is_beta` | `bool` | if the game is currently in beta | -| `entry` | `dict` | Data from status.json (see below) | - - For more info on `status.json`, See the "Status File" section in the Frontier [Journal documentation](https://forums.frontier.co.uk/showthread.php/401661) for the available `entry` properties and for the list of available `"Flags"`. Refer to the source code of [plug.py](./plug.py) for the list of available constants. - + New in version 4.1.6: `CargoJSON` contains the raw data from the last read of `Cargo.json` passed @@ -549,13 +599,63 @@ contains all the data), this will not be populated at login.** New in version 5.0.0: -`NavRoute` contains the `json.load()` of `NavRoute.json` as indicated by a journal -`NavRoute` event. +`NavRoute` contains the `json.load()` of `NavRoute.json` as indicated by a +journal `NavRoute` event. `ModuleInfo` contains the `json.load()` of `ModulesInfo.json` as indicated by a Journal `ModuleInfo` event. -#### Getting Commander Data +--- + +### Shutdown + +This gets called when the user closes the program: + +```python +def plugin_stop() -> None: + """ + EDMC is closing + """ + print("Farewell cruel world!") +``` + +If your plugin uses one or more threads to handle Events then `stop()` and +`join()` (to wait for their exit -- Recommended, not required) the threads +before returning from this function. + +--- + +### Player Dashboard + +```python +import plug + +def dashboard_entry(cmdr: str, is_beta: bool, entry: Dict[str, Any]): + is_deployed = entry['Flags'] & plug.FlagsHardpointsDeployed + sys.stderr.write("Hardpoints {}\n".format(is_deployed and "deployed" or "stowed")) +``` + +`dashboard_entry()` is called with the latest data from the `Status.json` +file when an update to that file is detected. + +This will be when something on the player's cockpit display changes - +typically about once a second when in orbital flight. + +| Parameter | Type | Description | +| :-------- | :----: | :-------------------------------- | +| `cmdr` | `str` | Current command name | +| `is_beta` | `bool` | if the game is currently in beta | +| `entry` | `dict` | Data from status.json (see below) | + +For more info on `Status.json`, See the "Status File" section in the Frontier +[Journal documentation](https://forums.frontier.co.uk/showthread.php/401661). +That includes the available `entry` properties and the list of `"Flags"`. +Refer to the source code of [plug.py](./plug.py) for the list of available +constants. + +--- + +### Commander Data from Frontier CAPI ```python def cmdr_data(data, is_beta): @@ -568,16 +668,19 @@ def cmdr_data(data, is_beta): logger.info(data['commander']['name']) ``` -This gets called when EDMC has just fetched fresh Cmdr and station data from -Frontier's servers. +This gets called when the application has just fetched fresh Cmdr and station +data from Frontier's servers. | Parameter | Type | Description | | :-------- | :--------------: | :------------------------------------------------------------------------------------------------------- | | `data` | `Dict[str, Any]` | `/profile` API response, with `/market` and `/shipyard` added under the keys `marketdata` and `shipdata` | | `is_beta` | `bool` | If the game is currently in beta | -#### Plugin-specific events +--- +### Plugin-specific events + +#### EDSM Notify System ```python def edsm_notify_system(reply): """ @@ -604,6 +707,7 @@ some time after the corresponding `journal_entry()` event. | :-------- | :--------------: | :--------------------------------------------------------------------------------------------- | | `reply` | `Dict[str, Any]` | Response to an API call to [EDSM's journal API target](https://www.edsm.net/en/api-journal-v1) | +#### Inara Notify Location ```python def inara_notify_location(event_data): """ @@ -630,8 +734,7 @@ event. | :----------- | :--------------: | :----------------------------------------------------------------------------------------------------------- | | `event_data` | `Dict[str, Any]` | Response to an API call to [INARA's `Commander Flight Log` event](https://inara.cz/inara-api-docs/#event-29) | ---- - +#### Inara Notify Ship ```python def inara_notify_ship(event_data): """ @@ -651,6 +754,8 @@ time after the corresponding `journal_entry()` event. | :----------- | :--------------: | :----------------------------------------------------------------------------------------------------------------------------- | | `event_data` | `Dict[str, Any]` | Response to an API call to [INARA's `addCommanderShip` or `setCommanderShip` event](https://inara.cz/inara-api-docs/#event-11) | +--- + ## Error messages You can display an error in EDMC's status area by returning a string from your @@ -663,6 +768,8 @@ The status area is shared between EDMC itself and all other plugins, so your message won't be displayed for very long. Create a dedicated widget if you need to display routine status information. +--- + ## Localisation You can localise your plugin to one of the languages that EDMC itself supports. @@ -696,6 +803,8 @@ See EDMC's own [`L10n`](https://github.com/EDCD/EDMarketConnector/tree/main/L10n folder for the list of supported language codes and for example translation files. +--- + ## Python Package Plugins A _Package Plugin_ is both a standard Python package (i.e. contains an @@ -706,6 +815,8 @@ before any non-Package plugins. Other plugins can access features in a Package Plugin by `import`ing the package by name in the usual way. +--- + ## Distributing a Plugin To package your plugin for distribution simply create a `.zip` archive of your @@ -718,7 +829,10 @@ plugin's folder: If there are any external dependencies then include them in the plugin's folder. -Optionally, for tidiness delete any `.pyc` and `.pyo` files in the archive, as well as the `__pycache__` directory. +Optionally, for tidiness delete any `.pyc` and `.pyo` files in the archive, as +well as the `__pycache__` directory. + +--- ## Disable a plugin @@ -728,6 +842,8 @@ plugin folder to append ".disabled". Eg, Disabled and enabled plugins are listed on the "Plugins" Settings tab +--- + ## Migration from Python 2.7 Starting with pre-release 3.5 EDMC used Python 3.7. The first full @@ -740,13 +856,13 @@ versions of EDMC: - Rename the function `plugin_start` to `plugin_start3(plugin_dir)`. Plugins without a `plugin_start3` function are listed as disabled on EDMC's "Plugins" tab and a message like "plugin SuperSpaceHelper needs migrating" - appears in the log. Such plugins are also listed in a section "Plugins Without - Python 3.x Support:" on the Settings > Plugins tab. + appears in the log. Such plugins are also listed in a section "Plugins + Without Python 3.x Support:" on the Settings > Plugins tab. - Check that callback functions `plugin_prefs`, `prefs_changed`, - `journal_entry`, `dashboard_entry` and `cmdr_data` if used are declared with - the correct number of arguments. Older versions of this app were tolerant - of missing arguments in these function declarations. + `journal_entry`, `dashboard_entry` and `cmdr_data`, if used, are declared + with the correct number of arguments. Older versions of this app were + tolerant of missing arguments in these function declarations. - Port the code to Python 3.9+. The [2to3](https://docs.python.org/3/library/2to3.html) From b4d246e0718ac01c1acf97357e7f3e2fda7763cf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 31 Mar 2021 15:16:01 +0100 Subject: [PATCH 459/727] Add 'Game Version' to bug report template We don't want confusion if someone's reporting something on an Alpha rather than Live. --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index e24f8a60..9284b95e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -13,6 +13,7 @@ assignees: '' **Please complete the following information:** - Version [e.g. 4.0.6 - See 'Help > About E:D Market Connector'. If running from source using git then please paste the output of `git log --decorate=full | head -1`] + - Game Version [e.g. 'Live' or 'Odyssey Alpha'] - OS: [e.g. Windows 10, Linux Debian 10.6, etc.] - OS Locale: [e.g. English, French, Serbian...] - If applicable: Browser [e.g. chrome, safari] From 7bf4fba85a2491dbcb4751e42999f4e19d9789f1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 14:47:24 +0100 Subject: [PATCH 460/727] Version to 4.2.0-beta1 to distinguish Python 3.8 builds * I don't want to be checking something against 4.1.x releases when my last build was with Python 3.8. # Conflicts: # config.py # Conflicts: # config.py # Conflicts: # config.py --- config.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index f8afe737..5941b5a1 100644 --- a/config.py +++ b/config.py @@ -40,9 +40,10 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -# NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta2' -copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' +appversion = '4.2.0-beta1' #-rc1+a872b5f' +# For some things we want appversion without (possible) +build metadata +appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) +copyright = u'© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' update_interval = 8*60*60 From 0113295ae56929a8004d211ebe2c59aed0642168 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 14:59:28 +0100 Subject: [PATCH 461/727] monitor.py: Set monitor.on_foot if LoadGame is in a suit * Also sets monitor.station via BodyType/Body if the former is 'Station'. --- monitor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/monitor.py b/monitor.py index 8cebc237..7008bbdc 100644 --- a/monitor.py +++ b/monitor.py @@ -67,6 +67,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below _RE_CANONICALISE = re.compile(r'\$(.+)_name;') _RE_CATEGORY = re.compile(r'\$MICRORESOURCE_CATEGORY_(.+);') _RE_LOGFILE = re.compile(r'^Journal(Alpha|Beta)?\.[0-9]{12}\.[0-9]{2}\.log$') + _RE_SHIP_ONFOOT = re.compile(r'^(FlightSuit|UtilitySuit_Class.)$') def __init__(self) -> None: # TODO(A_D): A bunch of these should be switched to default values (eg '' for strings) and no longer be Optional @@ -103,6 +104,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.coordinates: Optional[Tuple[float, float, float]] = None self.systemaddress: Optional[int] = None self.started: Optional[int] = None # Timestamp of the LoadGame event + self.on_foot: bool = False # Cmdr state shared with EDSM and plugins # If you change anything here update PLUGINS.md documentation! @@ -525,6 +527,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Statistics': {}, 'Role': None, }) + if self._RE_SHIP_ONFOOT.search(entry['Ship']): + self.on_foot = True elif event_type == 'NewCommander': self.cmdr = entry['Name'] @@ -641,7 +645,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.systempopulation = entry.get('Population') self.system = 'CQC' if entry['StarSystem'] == 'ProvingGround' else entry['StarSystem'] + self.station = entry.get('StationName') # May be None + # If on foot in-station 'Docked' is false, but we have a + # 'BodyType' of 'Station', and the 'Body' is the station name + # NB: No MarketID + if entry.get('BodyType') and entry['BodyType'] == 'Station': + self.station = entry.get('Body') + self.station_marketid = entry.get('MarketID') # May be None self.stationtype = entry.get('StationType') # May be None self.stationservices = entry.get('StationServices') # None under E:D < 2.4 From b44320f47cae742eac8ebdfc7e13e935d913a677 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 15:04:44 +0100 Subject: [PATCH 462/727] Split large 'Server Lagging' test into multiple Also adjusts the 'docked and station name matches' check to account for being on-foot. --- EDMarketConnector.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 2a0c37fd..baace9bc 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -773,15 +773,30 @@ class AppWindow(object): self.status['text'] = _("What are you flying?!") # Shouldn't happen elif monitor.cmdr and data['commander']['name'] != monitor.cmdr: - # Companion API return doesn't match Journal + # Companion API Commander doesn't match Journal raise companion.CmdrError() - elif ((auto_update and not data['commander'].get('docked')) - or (data['lastSystem']['name'] != monitor.system) - or ((data['commander']['docked'] - and data['lastStarport']['name'] or None) != monitor.station) - or (data['ship']['id'] != monitor.state['ShipID']) - or (data['ship']['name'].lower() != monitor.state['ShipType'])): + elif auto_update and not monitor.on_foot and not data['commander'].get('docked'): + # auto update is only when just docked + raise companion.ServerLagging() + + elif data['lastSystem']['name'] != monitor.system: + # CAPI system must match last journal one + raise companion.ServerLagging() + + elif (monitor.on_foot and monitor.station + and data['lastStarport']['name'] != monitor.station # On foot station must match if set + or ((data['commander']['docked'] and data['lastStarport']['name'] or None) + != monitor.station) # CAPI lastStarport must match + ): + raise companion.ServerLagging() + + elif not monitor.on_foot and data['ship']['id'] != monitor.state['ShipID']: + # CAPI ship must match + raise companion.ServerLagging() + + elif not monitor.on_foot and data['ship']['name'].lower() != monitor.state['ShipType']: + # CAPI ship type must match raise companion.ServerLagging() else: From b3cef1e29b8b51fa1f236840f718ade4fac7e2dd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 15:11:12 +0100 Subject: [PATCH 463/727] Server Lagging check now works again. Well, it doesn't now raise ServerLagging for a last Journal with a LoadGame on-foot and in-station. It does then cause "You're not docked at a station!" to show up. --- EDMarketConnector.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index baace9bc..96634086 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -784,12 +784,18 @@ class AppWindow(object): # CAPI system must match last journal one raise companion.ServerLagging() - elif (monitor.on_foot and monitor.station - and data['lastStarport']['name'] != monitor.station # On foot station must match if set - or ((data['commander']['docked'] and data['lastStarport']['name'] or None) - != monitor.station) # CAPI lastStarport must match - ): - raise companion.ServerLagging() + elif data['lastStarport']['name'] != monitor.station: + if monitor.on_foot and monitor.station: + raise companion.ServerLagging() + + else: + last_station = None + if data['commander']['docked']: + last_station = data['lastStarport']['name'] + + if last_station != monitor.station: + # CAPI lastStarport must match + raise companion.ServerLagging() elif not monitor.on_foot and data['ship']['id'] != monitor.state['ShipID']: # CAPI ship must match From 6fe86cd7193d0e5512f8c188fca1397c3848568d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 15:27:18 +0100 Subject: [PATCH 464/727] on_foot: Attempt to set correctly when state changes. * For taxi-usage you 'Embark' on it to take the trip and 'Disembark' onto foot at the other end. * Joining a multi-crew session will mean no longer being on foot. * When quitting a multi-crew session we might miss that you're back on-foot. Need to test. --- monitor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/monitor.py b/monitor.py index 7008bbdc..c56edb73 100644 --- a/monitor.py +++ b/monitor.py @@ -234,6 +234,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.coordinates = None self.systemaddress = None self.is_beta = False + self.on_foot = False if self.observed: logger.debug('self.observed: Calling unschedule_all()') @@ -496,6 +497,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Modules': None, 'Route': None, } + self.on_foot = False elif event_type == 'Commander': self.live = True # First event in 3.0 @@ -623,6 +625,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationtype = None self.stationservices = None + elif event_type == 'Embark': + self.on_foot = False + + elif event_type == 'Disembark': + self.on_foot = True + elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): if event_type in ('Location', 'CarrierJump'): self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None @@ -884,6 +892,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationservices = None self.coordinates = None self.systemaddress = None + self.on_foot = False elif event_type == 'ChangeCrewRole': self.state['Role'] = entry['Role'] @@ -899,6 +908,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationservices = None self.coordinates = None self.systemaddress = None + # TODO: on_foot: Will we get an event after this to know ? elif event_type == 'Friends': if entry['Status'] in ('Online', 'Added'): From a09512f3b3f562911b93f2edf7d744dc1a2048c7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 15:53:46 +0100 Subject: [PATCH 465/727] Mostly refactoring companion.ship_file_name() into util_ships.py * Also prevent "You're not docked at a station!" for on_foot. --- EDMarketConnector.py | 7 ++--- collate.py | 7 ++--- companion.py | 61 ------------------------------------------ coriolis.py | 5 ++-- edshipyard.py | 12 ++++----- loadout.py | 3 ++- monitor.py | 4 +-- outfitting.py | 4 +-- shipyard.py | 2 +- stats.py | 2 +- util_ships.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 88 insertions(+), 82 deletions(-) create mode 100644 util_ships.py diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 96634086..47d85551 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -256,6 +256,7 @@ import plug import prefs import stats import td +import util_ships from commodity import COMMODITY_CSV from dashboard import dashboard from hotkey import hotkeymgr @@ -689,7 +690,7 @@ class AppWindow(object): :return: True if all OK, else False to trigger play_bad in caller. """ if config.get_int('output') & (config.OUT_STATION_ANY): - if not data['commander'].get('docked'): + if not data['commander'].get('docked') and not monitor.on_foot: if not self.status['text']: # Signal as error because the user might actually be docked # but the server hosting the Companion API hasn't caught up @@ -810,7 +811,7 @@ class AppWindow(object): self.dump_capi_data(data) if not monitor.state['ShipType']: # Started game in SRV or fighter - self.ship['text'] = companion.ship_map.get(data['ship']['name'].lower(), data['ship']['name']) + self.ship['text'] = util_ships.ship_map.get(data['ship']['name'].lower(), data['ship']['name']) monitor.state['ShipID'] = data['ship']['id'] monitor.state['ShipType'] = data['ship']['name'].lower() @@ -912,7 +913,7 @@ class AppWindow(object): ship_text = monitor.state['ShipName'] else: - ship_text = companion.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) + ship_text = util_ships.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) if not ship_text: ship_text = '' diff --git a/collate.py b/collate.py index a5fa219f..3a0aa824 100755 --- a/collate.py +++ b/collate.py @@ -6,12 +6,13 @@ import csv import json import os -from os.path import isfile import sys +from os.path import isfile from traceback import print_exc import companion import outfitting +import util_ships def __make_backup(file_name: str, suffix: str = '.bak') -> None: @@ -106,7 +107,7 @@ def addmodules(data): raise ValueError('id: {} != {}'.format(key, module['id'])) try: - new = outfitting.lookup(module, companion.ship_map, True) + new = outfitting.lookup(module, util_ships.ship_map, True) except Exception: print('{}, {}:'.format(module['id'], module['name'])) @@ -164,7 +165,7 @@ def addships(data): for ship in tuple(data_ships.get('shipyard_list', {}).values()) + data_ships.get('unavailable_list'): # sanity check key = int(ship['id']) - new = {'id': key, 'symbol': ship['name'], 'name': companion.ship_map.get(ship['name'].lower())} + new = {'id': key, 'symbol': ship['name'], 'name': util_ships.ship_map.get(ship['name'].lower())} if new: old = ships.get(key) if old: diff --git a/companion.py b/companion.py index d9972743..51834b08 100644 --- a/companion.py +++ b/companion.py @@ -75,53 +75,6 @@ category_map = { commodity_map: Dict = {} -ship_map = { - 'adder': 'Adder', - 'anaconda': 'Anaconda', - 'asp': 'Asp Explorer', - 'asp_scout': 'Asp Scout', - 'belugaliner': 'Beluga Liner', - 'cobramkiii': 'Cobra MkIII', - 'cobramkiv': 'Cobra MkIV', - 'clipper': 'Panther Clipper', - 'cutter': 'Imperial Cutter', - 'diamondback': 'Diamondback Scout', - 'diamondbackxl': 'Diamondback Explorer', - 'dolphin': 'Dolphin', - 'eagle': 'Eagle', - 'empire_courier': 'Imperial Courier', - 'empire_eagle': 'Imperial Eagle', - 'empire_fighter': 'Imperial Fighter', - 'empire_trader': 'Imperial Clipper', - 'federation_corvette': 'Federal Corvette', - 'federation_dropship': 'Federal Dropship', - 'federation_dropship_mkii': 'Federal Assault Ship', - 'federation_gunship': 'Federal Gunship', - 'federation_fighter': 'F63 Condor', - 'ferdelance': 'Fer-de-Lance', - 'hauler': 'Hauler', - 'independant_trader': 'Keelback', - 'independent_fighter': 'Taipan Fighter', - 'krait_mkii': 'Krait MkII', - 'krait_light': 'Krait Phantom', - 'mamba': 'Mamba', - 'orca': 'Orca', - 'python': 'Python', - 'scout': 'Taipan Fighter', - 'sidewinder': 'Sidewinder', - 'testbuggy': 'Scarab', - 'type6': 'Type-6 Transporter', - 'type7': 'Type-7 Transporter', - 'type9': 'Type-9 Heavy', - 'type9_military': 'Type-10 Defender', - 'typex': 'Alliance Chieftain', - 'typex_2': 'Alliance Crusader', - 'typex_3': 'Alliance Challenger', - 'viper': 'Viper MkIII', - 'viper_mkiv': 'Viper MkIV', - 'vulture': 'Vulture', -} - class CAPIData(UserDict): """CAPI Response.""" @@ -769,19 +722,5 @@ def ship(data: CAPIData) -> CAPIData: return filter_ship(data['ship']) -def ship_file_name(ship_name: str, ship_type: str) -> str: - """Return a ship name suitable for a filename.""" - name = str(ship_name or ship_map.get(ship_type.lower(), ship_type)).strip() - if name.endswith('.'): - name = name[:-1] - - if name.lower() in ('con', 'prn', 'aux', 'nul', - 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', - 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'): - name = name + '_' - - return name.translate({ord(x): u'_' for x in ('\0', '<', '>', ':', '"', '/', '\\', '|', '?', '*')}) - - # singleton session = Session() diff --git a/coriolis.py b/coriolis.py index bf694d37..7f6d9c0a 100755 --- a/coriolis.py +++ b/coriolis.py @@ -15,6 +15,7 @@ from traceback import print_exc from config import config import outfitting import companion +import util_ships if __name__ == "__main__": @@ -39,7 +40,7 @@ if __name__ == "__main__": } # Symbolic name from in-game name - reverse_ship_map = {v: k for k, v in list(companion.ship_map.items())} + reverse_ship_map = {v: k for k, v in list(util_ships.ship_map.items())} bulkheads = list(outfitting.armour_map.keys()) @@ -98,7 +99,7 @@ if __name__ == "__main__": reader = csv.DictReader(csvfile, restval='') for row in reader: try: - module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, companion.ship_map) + module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, util_ships.ship_map) except: print(row['symbol']) print_exc() diff --git a/edshipyard.py b/edshipyard.py index 0eae47d3..0cf13dac 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -8,14 +8,14 @@ import re import time from config import config -import companion import outfitting +import util_ships from typing import Dict, Union, List __Module = Dict[str, Union[str, List[str]]] # Map API ship names to E:D Shipyard ship names -ship_map = companion.ship_map.copy() +ship_map = util_ships.ship_map.copy() ship_map.update( { @@ -172,11 +172,11 @@ def export(data, filename=None): string += '---\nCargo : {} T\nFuel : {} T\n'.format(cargo, fuel) # Add mass and range - assert data['ship']['name'].lower() in companion.ship_map, data['ship']['name'] - assert companion.ship_map[data['ship']['name'].lower()] in ships, companion.ship_map[data['ship']['name'].lower()] + assert data['ship']['name'].lower() in util_ships.ship_map, data['ship']['name'] + assert util_ships.ship_map[data['ship']['name'].lower()] in ships, util_ships.ship_map[data['ship']['name'].lower()] try: - mass += ships[companion.ship_map[data['ship']['name'].lower()]]['hullMass'] + mass += ships[util_ships.ship_map[data['ship']['name'].lower()]]['hullMass'] string += 'Mass : {:.2f} T empty\n {:.2f} T full\n'.format(mass, mass + fuel + cargo) multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 / fsd['fuelpower']) * fsd['optmass'] @@ -197,7 +197,7 @@ def export(data, filename=None): return # Look for last ship of this type - ship = companion.ship_file_name(data['ship'].get('shipName'), data['ship']['name']) + ship = util_ships.ship_file_name(data['ship'].get('shipName'), data['ship']['name']) regexp = re.compile(re.escape(ship) + r'\.\d{4}-\d\d-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted([x for x in os.listdir(config.get_str('outdir')) if regexp.match(x)]) if oldfiles: diff --git a/loadout.py b/loadout.py index 8eb90448..d3a08743 100644 --- a/loadout.py +++ b/loadout.py @@ -8,6 +8,7 @@ import time from config import config import companion +import util_ships def export(data, filename=None): @@ -20,7 +21,7 @@ def export(data, filename=None): return # Look for last ship of this type - ship = companion.ship_file_name(data['ship'].get('shipName'), data['ship']['name']) + ship = util_ships.ship_file_name(data['ship'].get('shipName'), data['ship']['name']) regexp = re.compile(re.escape(ship) + '\.\d\d\d\d\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted([x for x in os.listdir(config.get_str('outdir')) if regexp.match(x)]) if oldfiles: diff --git a/monitor.py b/monitor.py index c56edb73..13cb59ba 100644 --- a/monitor.py +++ b/monitor.py @@ -16,7 +16,7 @@ from typing import Tuple if TYPE_CHECKING: import tkinter -from companion import ship_file_name +import util_ships from config import config from EDMCLogging import get_main_logger @@ -1141,7 +1141,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return - ship = ship_file_name(self.state['ShipName'], self.state['ShipType']) + ship = util_ships.ship_file_name(self.state['ShipName'], self.state['ShipType']) regexp = re.compile(re.escape(ship) + r'\.\d{4}\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted((x for x in listdir(config.get_str('outdir')) if regexp.match(x))) # type: ignore if oldfiles: diff --git a/outfitting.py b/outfitting.py index 1460ab5b..a132032d 100644 --- a/outfitting.py +++ b/outfitting.py @@ -3,7 +3,7 @@ import pickle from os.path import join import time -import companion +import util_ships from config import config @@ -521,7 +521,7 @@ def export(data, filename): h.write(header) for v in list(data['lastStarport'].get('modules', {}).values()): try: - m = lookup(v, companion.ship_map) + m = lookup(v, util_ships.ship_map) if m: h.write('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n' % (rowheader, m['category'], m['name'], m.get('mount',''), m.get('guidance',''), m.get('ship',''), m['class'], m['rating'], m['id'], data['timestamp'])) except AssertionError as e: diff --git a/shipyard.py b/shipyard.py index 6659ab99..2a8edfdd 100644 --- a/shipyard.py +++ b/shipyard.py @@ -2,8 +2,8 @@ import time -from companion import ship_map from config import config +from util_ships import ship_map def export(data, filename): diff --git a/stats.py b/stats.py index f0cac5b8..baf5894a 100644 --- a/stats.py +++ b/stats.py @@ -8,9 +8,9 @@ from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, NamedTuple, Optional, import companion import EDMCLogging import myNotebook as nb # noqa: N813 -from companion import ship_map from l10n import Locale from monitor import monitor +from util_ships import ship_map logger = EDMCLogging.get_main_logger() diff --git a/util_ships.py b/util_ships.py new file mode 100644 index 00000000..1ece05d9 --- /dev/null +++ b/util_ships.py @@ -0,0 +1,63 @@ +"""Utility functions relating to ships.""" + + +ship_map = { + 'adder': 'Adder', + 'anaconda': 'Anaconda', + 'asp': 'Asp Explorer', + 'asp_scout': 'Asp Scout', + 'belugaliner': 'Beluga Liner', + 'cobramkiii': 'Cobra MkIII', + 'cobramkiv': 'Cobra MkIV', + 'clipper': 'Panther Clipper', + 'cutter': 'Imperial Cutter', + 'diamondback': 'Diamondback Scout', + 'diamondbackxl': 'Diamondback Explorer', + 'dolphin': 'Dolphin', + 'eagle': 'Eagle', + 'empire_courier': 'Imperial Courier', + 'empire_eagle': 'Imperial Eagle', + 'empire_fighter': 'Imperial Fighter', + 'empire_trader': 'Imperial Clipper', + 'federation_corvette': 'Federal Corvette', + 'federation_dropship': 'Federal Dropship', + 'federation_dropship_mkii': 'Federal Assault Ship', + 'federation_gunship': 'Federal Gunship', + 'federation_fighter': 'F63 Condor', + 'ferdelance': 'Fer-de-Lance', + 'hauler': 'Hauler', + 'independant_trader': 'Keelback', + 'independent_fighter': 'Taipan Fighter', + 'krait_mkii': 'Krait MkII', + 'krait_light': 'Krait Phantom', + 'mamba': 'Mamba', + 'orca': 'Orca', + 'python': 'Python', + 'scout': 'Taipan Fighter', + 'sidewinder': 'Sidewinder', + 'testbuggy': 'Scarab', + 'type6': 'Type-6 Transporter', + 'type7': 'Type-7 Transporter', + 'type9': 'Type-9 Heavy', + 'type9_military': 'Type-10 Defender', + 'typex': 'Alliance Chieftain', + 'typex_2': 'Alliance Crusader', + 'typex_3': 'Alliance Challenger', + 'viper': 'Viper MkIII', + 'viper_mkiv': 'Viper MkIV', + 'vulture': 'Vulture', +} + + +def ship_file_name(ship_name: str, ship_type: str) -> str: + """Return a ship name suitable for a filename.""" + name = str(ship_name or ship_map.get(ship_type.lower(), ship_type)).strip() + if name.endswith('.'): + name = name[:-2] + + if name.lower() in ('con', 'prn', 'aux', 'nul', + 'com0', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', + 'lpt0', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'): + name = name + '_' + + return name.translate({ord(x): u'_' for x in ('\-1', '<', '>', ':', '"', '/', '\\', '|', '?', '*')}) From 567cfdb9cae10bc9ba34a6338773d47b2f2847e8 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 16:26:06 +0100 Subject: [PATCH 466/727] Will now send data to EDDN when on-foot in-station. NB: No shipyard in tests because data['ships']['shipyard_list'] is an empty list. This might be the bug not having been fixed, or the station might genuinely have no ships for sale. We have no way to check in Odyssey Alpha Phase 1. --- companion.py | 3 ++- monitor.py | 4 ++++ plugins/eddn.py | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/companion.py b/companion.py index 51834b08..3e6c6993 100644 --- a/companion.py +++ b/companion.py @@ -28,6 +28,7 @@ import requests from config import appname, appversion, config from EDMCLogging import get_main_logger +from monitor import monitor from protocol import protocolhandler logger = get_main_logger() @@ -563,7 +564,7 @@ class Session(object): logger.error('No commander in returned data') return data - if not data['commander'].get('docked'): + if not data['commander'].get('docked') and not monitor.on_foot: return data services = data['lastStarport'].get('services', {}) diff --git a/monitor.py b/monitor.py index 13cb59ba..b50213ad 100644 --- a/monitor.py +++ b/monitor.py @@ -626,9 +626,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationservices = None elif event_type == 'Embark': + # If we've embarked then we're no longer on the station. + self.station = None self.on_foot = False elif event_type == 'Disembark': + # We don't yet have a way, other than LoadGame+Location, to detect if we *are* on a station on-foot. + self.station = None self.on_foot = True elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): diff --git a/plugins/eddn.py b/plugins/eddn.py index 0655bf80..b67fd3f0 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -22,6 +22,7 @@ import plug from companion import CAPIData, category_map from config import applongname, appversion_nobuild, config from EDMCLogging import get_main_logger +from monitor import monitor from myNotebook import Frame from prefs import prefsVersion from ttkHyperlinkLabel import HyperlinkLabel @@ -907,7 +908,8 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: # noqa: CCR001 :param is_beta: bool - True if this is a beta version of the Game. :return: str - Error message, or `None` if no errors. """ - if data['commander'].get('docked') and config.get_int('output') & config.OUT_MKT_EDDN: + if (data['commander'].get('docked') or (monitor.on_foot and monitor.station) + and config.get_int('output') & config.OUT_MKT_EDDN): try: if this.marketId != data['lastStarport']['id']: this.commodities = this.outfitting = this.shipyard = None From f45f817fa25c4a8558ea596ebc098b1ce808d3ac Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 17:39:28 +0100 Subject: [PATCH 467/727] EDDB plugin now setting Station name correctly on_foot * monitor.on_foot is now monitor.state['on_foot'] as plugins need to access it. * EDDB:journal_entry() now stores that in this.on_foot to check later. * this.on_foot checked in cmdr_data() to actually set station name from that data if needs be. This avoids setting it to STATION_UNDOCKED if data['commander']['docked'] is False, when we're on_foot. --- EDMarketConnector.py | 11 ++++++----- companion.py | 2 +- monitor.py | 14 +++++++------- plugins/eddb.py | 10 ++++++++-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 47d85551..403ef5f2 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -690,7 +690,7 @@ class AppWindow(object): :return: True if all OK, else False to trigger play_bad in caller. """ if config.get_int('output') & (config.OUT_STATION_ANY): - if not data['commander'].get('docked') and not monitor.on_foot: + if not data['commander'].get('docked') and not monitor.state['on_foot']: if not self.status['text']: # Signal as error because the user might actually be docked # but the server hosting the Companion API hasn't caught up @@ -777,7 +777,7 @@ class AppWindow(object): # Companion API Commander doesn't match Journal raise companion.CmdrError() - elif auto_update and not monitor.on_foot and not data['commander'].get('docked'): + elif auto_update and not monitor.state['on_foot'] and not data['commander'].get('docked'): # auto update is only when just docked raise companion.ServerLagging() @@ -786,7 +786,7 @@ class AppWindow(object): raise companion.ServerLagging() elif data['lastStarport']['name'] != monitor.station: - if monitor.on_foot and monitor.station: + if monitor.state['on_foot'] and monitor.station: raise companion.ServerLagging() else: @@ -798,11 +798,11 @@ class AppWindow(object): # CAPI lastStarport must match raise companion.ServerLagging() - elif not monitor.on_foot and data['ship']['id'] != monitor.state['ShipID']: + elif not monitor.state['on_foot'] and data['ship']['id'] != monitor.state['ShipID']: # CAPI ship must match raise companion.ServerLagging() - elif not monitor.on_foot and data['ship']['name'].lower() != monitor.state['ShipType']: + elif not monitor.state['on_foot'] and data['ship']['name'].lower() != monitor.state['ShipType']: # CAPI ship type must match raise companion.ServerLagging() @@ -909,6 +909,7 @@ class AppWindow(object): self.ship_label['text'] = _('Ship') + ':' # Main window + # TODO: Show something else when on_foot if monitor.state['ShipName']: ship_text = monitor.state['ShipName'] diff --git a/companion.py b/companion.py index 3e6c6993..98fb5e1c 100644 --- a/companion.py +++ b/companion.py @@ -564,7 +564,7 @@ class Session(object): logger.error('No commander in returned data') return data - if not data['commander'].get('docked') and not monitor.on_foot: + if not data['commander'].get('docked') and not monitor.state['on_foot']: return data services = data['lastStarport'].get('services', {}) diff --git a/monitor.py b/monitor.py index b50213ad..2fdf0b81 100644 --- a/monitor.py +++ b/monitor.py @@ -104,7 +104,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.coordinates: Optional[Tuple[float, float, float]] = None self.systemaddress: Optional[int] = None self.started: Optional[int] = None # Timestamp of the LoadGame event - self.on_foot: bool = False # Cmdr state shared with EDSM and plugins # If you change anything here update PLUGINS.md documentation! @@ -134,6 +133,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Modules': None, 'CargoJSON': None, # The raw data from the last time cargo.json was read 'Route': None, # Last plotted route from Route.json file + 'on_foot': False, # Whether we think you're on-foot } def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 @@ -234,7 +234,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.coordinates = None self.systemaddress = None self.is_beta = False - self.on_foot = False + self.state['on_foot'] = False if self.observed: logger.debug('self.observed: Calling unschedule_all()') @@ -497,7 +497,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Modules': None, 'Route': None, } - self.on_foot = False + self.state['on_foot'] = False elif event_type == 'Commander': self.live = True # First event in 3.0 @@ -530,7 +530,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Role': None, }) if self._RE_SHIP_ONFOOT.search(entry['Ship']): - self.on_foot = True + self.state['on_foot'] = True elif event_type == 'NewCommander': self.cmdr = entry['Name'] @@ -628,12 +628,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'Embark': # If we've embarked then we're no longer on the station. self.station = None - self.on_foot = False + self.state['on_foot'] = False elif event_type == 'Disembark': # We don't yet have a way, other than LoadGame+Location, to detect if we *are* on a station on-foot. self.station = None - self.on_foot = True + self.state['on_foot'] = True elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): if event_type in ('Location', 'CarrierJump'): @@ -896,7 +896,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationservices = None self.coordinates = None self.systemaddress = None - self.on_foot = False + self.state['on_foot'] = False elif event_type == 'ChangeCrewRole': self.state['Role'] = entry['Role'] diff --git a/plugins/eddb.py b/plugins/eddb.py index 4f0ea25b..d8a48daa 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -53,6 +53,7 @@ this.system_population: Optional[int] = None this.station_link: 'Optional[Tk]' = None this.station: Optional[str] = None this.station_marketid: Optional[int] = None +this.on_foot = False def system_url(system_name: str) -> str: @@ -102,6 +103,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): logger.warning(f'Processing of event {entry["event"]} has been disabled: {ks.reason}') return + this.on_foot = state['on_foot'] # Always update our system address even if we're not currently the provider for system or station, but dont update # on events that contain "future" data, such as FSDTarget if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'): @@ -115,9 +117,13 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.system_population = pop this.station = entry.get('StationName') or this.station + # on_foot station detection + if not this.station and entry['event'] == 'Location' and entry['BodyType'] == 'Station': + this.station = entry['Body'] + this.station_marketid = entry.get('MarketID') or this.station_marketid # We might pick up StationName in DockingRequested, make sure we clear it if leaving - if entry['event'] in ('Undocked', 'FSDJump', 'SupercruiseEntry'): + if entry['event'] in ('Undocked', 'FSDJump', 'SupercruiseEntry', 'Embark'): this.station = None this.station_marketid = None @@ -164,7 +170,7 @@ def cmdr_data(data: CAPIData, is_beta): this.system_link.update_idletasks() if config.get_str('station_provider') == 'eddb': - if data['commander']['docked']: + if data['commander']['docked'] or this.on_foot and this.station: this.station_link['text'] = this.station elif data['lastStarport']['name'] and data['lastStarport']['name'] != "": From bd4489974da63440974e912dcc06c3876bac31c2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 17:46:48 +0100 Subject: [PATCH 468/727] EDSM plugin now maintaining Station Name when on_foot --- plugins/edsm.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/edsm.py b/plugins/edsm.py index 0c0ec3db..61fba362 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -55,6 +55,7 @@ this.system_population: Optional[int] = None this.station_link: tk.Tk = None this.station: Optional[str] = None this.station_marketid: Optional[int] = None # Frontier MarketID +this.on_foot = False STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7 __cleanup = str.maketrans({' ': None, '\n': None}) IMG_KNOWN_B64 = """ @@ -349,6 +350,7 @@ def journal_entry( logger.warning(f'Handling of event {entry["event"]} has been disabled via killswitch: {ks.reason}') return + this.on_foot = state['on_foot'] if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): logger.trace(f'''{entry["event"]} Commander: {cmdr} @@ -370,6 +372,10 @@ entry: {entry!r}''' this.system_population = pop this.station = entry.get('StationName', this.station) + # on_foot station detection + if not this.station and entry['event'] == 'Location' and entry['BodyType'] == 'Station': + this.station = entry['Body'] + this.station_marketid = entry.get('MarketID', this.station) # We might pick up StationName in DockingRequested, make sure we clear it if leaving if entry['event'] in ('Undocked', 'FSDJump', 'SupercruiseEntry'): @@ -479,7 +485,7 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> None: this.system_link.update_idletasks() if config.get_str('station_provider') == 'EDSM': - if data['commander']['docked']: + if data['commander']['docked'] or this.on_foot and this.station: this.station_link['text'] = this.station elif data['lastStarport']['name'] and data['lastStarport']['name'] != "": From 734cb9ed11c6c136f7b9ec7ef241d07518a2566a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 17:51:25 +0100 Subject: [PATCH 469/727] Inara plugin now maintains Station Name when on_foot --- plugins/inara.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/inara.py b/plugins/inara.py index fcb5c86f..854617c0 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -59,6 +59,7 @@ this.storedmodules: Optional[OrderedDictT[str, Any]] = None this.loadout: Optional[OrderedDictT[str, Any]] = None this.fleet: Optional[List[OrderedDictT[str, Any]]] = None this.shipswap: bool = False # just swapped ship +this.on_foot = False # last time we updated, if unset in config this is 0, which means an instant update LAST_UPDATE_CONF_KEY = 'inara_last_update' @@ -330,6 +331,7 @@ def journal_entry( elif (ks := killswitch.get_disabled(f'plugins.inara.journal.event.{entry["event"]}')).disabled: logger.warning(f'event {entry["event"]} processing has been disabled via killswitch: {ks.reason}') + this.on_foot = state['on_foot'] event_name: str = entry['event'] this.cmdr = cmdr this.FID = state['FID'] @@ -380,6 +382,10 @@ def journal_entry( this.system_population = pop this.station = entry.get('StationName', this.station) + # on_foot station detection + if not this.station and entry['event'] == 'Location' and entry['BodyType'] == 'Station': + this.station = entry['Body'] + this.station_marketid = entry.get('MarketID', this.station_marketid) or this.station_marketid # We might pick up StationName in DockingRequested, make sure we clear it if leaving if event_name in ('Undocked', 'FSDJump', 'SupercruiseEntry'): @@ -1069,7 +1075,7 @@ def cmdr_data(data: CAPIData, is_beta): this.system_link.update_idletasks() if config.get_str('station_provider') == 'Inara': - if data['commander']['docked']: + if data['commander']['docked'] or this.on_foot and this.station: this.station_link['text'] = this.station elif data['lastStarport']['name'] and data['lastStarport']['name'] != "": From f40f6464b6edfb85865388febb42be33b4221c9b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 18:34:43 +0100 Subject: [PATCH 470/727] PLUGINS.md: Document state['on_foot'] * Also restore 'New in' bits to just below the table. --- PLUGINS.md | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 79e0fe62..ab9d513d 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -530,6 +530,28 @@ Content of `state` (updated to the current journal entry): | `Modules` | `dict` | Currently fitted modules | | `NavRoute` | `dict` | Last plotted multi-hop route | | `ModuleInfo` | `dict` | Last loaded ModulesInfo.json data | +| `on_foot` | `bool` | Whether you're on_foot | + +New in version 4.1.6: + +`CargoJSON` contains the raw data from the last read of `Cargo.json` passed +through json.load. It contains more information about the cargo contents, such +as the mission ID for mission specific cargo + +**NB: Because this is only the data loaded from the `Cargo.json` file, and that +is not written at Commander login (instead the in-Journal `Cargo` event +contains all the data), this will not be populated at login.** + +New in version 5.0.0: + +`NavRoute` contains the `json.load()` of `NavRoute.json` as indicated by a +journal `NavRoute` event. + +`ModuleInfo` contains the `json.load()` of `ModulesInfo.json` as indicated by a +Journal `ModuleInfo` event. + +`on_foot` is an indication as to if the player is on-foot, rather than in a +vehicle. ##### Synthetic Events @@ -587,24 +609,6 @@ Examples of this are: (noting that we used the singular form there to stay consistent with the Journal event name). -New in version 4.1.6: - -`CargoJSON` contains the raw data from the last read of `Cargo.json` passed -through json.load. It contains more information about the cargo contents, such -as the mission ID for mission specific cargo - -**NB: Because this is only the data loaded from the `Cargo.json` file, and that -is not written at Commander login (instead the in-Journal `Cargo` event -contains all the data), this will not be populated at login.** - -New in version 5.0.0: - -`NavRoute` contains the `json.load()` of `NavRoute.json` as indicated by a -journal `NavRoute` event. - -`ModuleInfo` contains the `json.load()` of `ModulesInfo.json` as indicated by a -Journal `ModuleInfo` event. - --- ### Shutdown From 4be52fd259ac8e0a6204a86ae0238b1d5aef2f79 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 30 Mar 2021 20:25:53 +0100 Subject: [PATCH 471/727] Add comment about how/when system and station text is updated It took me hours to track this down, due to the use of parent.children(), so let's try to shorten that next time. --- EDMarketConnector.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 403ef5f2..dca11c3c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -337,6 +337,10 @@ class AppWindow(object): self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr') self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship') + # system and station text is set/updated by the 'provider' plugins + # eddb, edsm and inara. Look for: + # + # parent.children['system'] / parent.children['station'] self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system') self.station = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.station_url, name='station') From 5edf8d5b59a194d392ae888b864e25e1b395999b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 11:53:31 +0100 Subject: [PATCH 472/727] Change monitor.state['on_foot'] to 'OnFoot' for consistency --- EDMarketConnector.py | 10 +++++----- PLUGINS.md | 4 ++-- monitor.py | 14 +++++++------- plugins/eddb.py | 2 +- plugins/eddn.py | 5 ++++- plugins/edsm.py | 2 +- plugins/inara.py | 2 +- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index dca11c3c..404a7bb5 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -694,7 +694,7 @@ class AppWindow(object): :return: True if all OK, else False to trigger play_bad in caller. """ if config.get_int('output') & (config.OUT_STATION_ANY): - if not data['commander'].get('docked') and not monitor.state['on_foot']: + if not data['commander'].get('docked') and not monitor.state['OnFoot']: if not self.status['text']: # Signal as error because the user might actually be docked # but the server hosting the Companion API hasn't caught up @@ -781,7 +781,7 @@ class AppWindow(object): # Companion API Commander doesn't match Journal raise companion.CmdrError() - elif auto_update and not monitor.state['on_foot'] and not data['commander'].get('docked'): + elif auto_update and not monitor.state['OnFoot'] and not data['commander'].get('docked'): # auto update is only when just docked raise companion.ServerLagging() @@ -790,7 +790,7 @@ class AppWindow(object): raise companion.ServerLagging() elif data['lastStarport']['name'] != monitor.station: - if monitor.state['on_foot'] and monitor.station: + if monitor.state['OnFoot'] and monitor.station: raise companion.ServerLagging() else: @@ -802,11 +802,11 @@ class AppWindow(object): # CAPI lastStarport must match raise companion.ServerLagging() - elif not monitor.state['on_foot'] and data['ship']['id'] != monitor.state['ShipID']: + elif not monitor.state['OnFoot'] and data['ship']['id'] != monitor.state['ShipID']: # CAPI ship must match raise companion.ServerLagging() - elif not monitor.state['on_foot'] and data['ship']['name'].lower() != monitor.state['ShipType']: + elif not monitor.state['OnFoot'] and data['ship']['name'].lower() != monitor.state['ShipType']: # CAPI ship type must match raise companion.ServerLagging() diff --git a/PLUGINS.md b/PLUGINS.md index ab9d513d..3d4d6856 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -530,7 +530,7 @@ Content of `state` (updated to the current journal entry): | `Modules` | `dict` | Currently fitted modules | | `NavRoute` | `dict` | Last plotted multi-hop route | | `ModuleInfo` | `dict` | Last loaded ModulesInfo.json data | -| `on_foot` | `bool` | Whether you're on_foot | +| `OnFoot` | `bool` | Whether the Cmdr is on foot | New in version 4.1.6: @@ -550,7 +550,7 @@ journal `NavRoute` event. `ModuleInfo` contains the `json.load()` of `ModulesInfo.json` as indicated by a Journal `ModuleInfo` event. -`on_foot` is an indication as to if the player is on-foot, rather than in a +`OnFoot` is an indication as to if the player is on-foot, rather than in a vehicle. ##### Synthetic Events diff --git a/monitor.py b/monitor.py index 2fdf0b81..b55075b5 100644 --- a/monitor.py +++ b/monitor.py @@ -133,7 +133,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Modules': None, 'CargoJSON': None, # The raw data from the last time cargo.json was read 'Route': None, # Last plotted route from Route.json file - 'on_foot': False, # Whether we think you're on-foot + 'OnFoot': False, # Whether we think you're on-foot } def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 @@ -234,7 +234,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.coordinates = None self.systemaddress = None self.is_beta = False - self.state['on_foot'] = False + self.state['OnFoot'] = False if self.observed: logger.debug('self.observed: Calling unschedule_all()') @@ -497,7 +497,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Modules': None, 'Route': None, } - self.state['on_foot'] = False + self.state['OnFoot'] = False elif event_type == 'Commander': self.live = True # First event in 3.0 @@ -530,7 +530,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Role': None, }) if self._RE_SHIP_ONFOOT.search(entry['Ship']): - self.state['on_foot'] = True + self.state['OnFoot'] = True elif event_type == 'NewCommander': self.cmdr = entry['Name'] @@ -628,12 +628,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'Embark': # If we've embarked then we're no longer on the station. self.station = None - self.state['on_foot'] = False + self.state['OnFoot'] = False elif event_type == 'Disembark': # We don't yet have a way, other than LoadGame+Location, to detect if we *are* on a station on-foot. self.station = None - self.state['on_foot'] = True + self.state['OnFoot'] = True elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): if event_type in ('Location', 'CarrierJump'): @@ -896,7 +896,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationservices = None self.coordinates = None self.systemaddress = None - self.state['on_foot'] = False + self.state['OnFoot'] = False elif event_type == 'ChangeCrewRole': self.state['Role'] = entry['Role'] diff --git a/plugins/eddb.py b/plugins/eddb.py index d8a48daa..2c926152 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -103,7 +103,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): logger.warning(f'Processing of event {entry["event"]} has been disabled: {ks.reason}') return - this.on_foot = state['on_foot'] + this.on_foot = state['OnFoot'] # Always update our system address even if we're not currently the provider for system or station, but dont update # on events that contain "future" data, such as FSDTarget if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'): diff --git a/plugins/eddn.py b/plugins/eddn.py index b67fd3f0..dd3446d3 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -42,6 +42,8 @@ class This: """Holds module globals.""" def __init__(self): + # Track if we're on foot + self.on_foot = False # Track location to add to Journal events self.systemaddress: Optional[str] = None self.coordinates: Optional[Tuple] = None @@ -766,6 +768,7 @@ def journal_entry( # noqa: C901, CCR001 return filtered + this.on_foot = state['OnFoot'] # Track location if entry['event'] in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): if entry['event'] in ('Location', 'CarrierJump'): @@ -908,7 +911,7 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: # noqa: CCR001 :param is_beta: bool - True if this is a beta version of the Game. :return: str - Error message, or `None` if no errors. """ - if (data['commander'].get('docked') or (monitor.on_foot and monitor.station) + if (data['commander'].get('docked') or (this.on_foot and monitor.station) and config.get_int('output') & config.OUT_MKT_EDDN): try: if this.marketId != data['lastStarport']['id']: diff --git a/plugins/edsm.py b/plugins/edsm.py index 61fba362..2ca2f62d 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -350,7 +350,7 @@ def journal_entry( logger.warning(f'Handling of event {entry["event"]} has been disabled via killswitch: {ks.reason}') return - this.on_foot = state['on_foot'] + this.on_foot = state['OnFoot'] if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): logger.trace(f'''{entry["event"]} Commander: {cmdr} diff --git a/plugins/inara.py b/plugins/inara.py index 854617c0..4967737f 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -331,7 +331,7 @@ def journal_entry( elif (ks := killswitch.get_disabled(f'plugins.inara.journal.event.{entry["event"]}')).disabled: logger.warning(f'event {entry["event"]} processing has been disabled via killswitch: {ks.reason}') - this.on_foot = state['on_foot'] + this.on_foot = state['OnFoot'] event_name: str = entry['event'] this.cmdr = cmdr this.FID = state['FID'] From b70efab3457cde93f46461358c60f46308dc9d1d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 15:33:14 +0100 Subject: [PATCH 473/727] companion.py: Another s/on_foot/OnFoot/ for monitor.state --- companion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion.py b/companion.py index 98fb5e1c..e5afb40d 100644 --- a/companion.py +++ b/companion.py @@ -564,7 +564,7 @@ class Session(object): logger.error('No commander in returned data') return data - if not data['commander'].get('docked') and not monitor.state['on_foot']: + if not data['commander'].get('docked') and not monitor.state['OnFoot']: return data services = data['lastStarport'].get('services', {}) From cd2407c1c3bfb8bcd8d88ea210fd7c925b124c29 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Apr 2021 15:35:46 +0100 Subject: [PATCH 474/727] utils_ship: Correct fat-finger/bad replace on `'\0'` --- util_ships.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util_ships.py b/util_ships.py index 1ece05d9..9aad1cc4 100644 --- a/util_ships.py +++ b/util_ships.py @@ -60,4 +60,4 @@ def ship_file_name(ship_name: str, ship_type: str) -> str: 'lpt0', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'): name = name + '_' - return name.translate({ord(x): u'_' for x in ('\-1', '<', '>', ':', '"', '/', '\\', '|', '?', '*')}) + return name.translate({ord(x): u'_' for x in ('\0', '<', '>', ':', '"', '/', '\\', '|', '?', '*')}) From 5010f133a8b35586e511437427c608d1f7a3fd78 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 1 Apr 2021 21:57:31 +0200 Subject: [PATCH 475/727] Added font override --- EDMarketConnector.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 404a7bb5..d74ca185 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1433,7 +1433,9 @@ sys.path: {sys.path}''' if args.reset_ui: config.set('theme', 0) # 'Default' theme uses ID 0 config.set('ui_transparency', 100) # 100 is completely opaque - logger.info('reset theme and transparency to default.') + config.delete('font') + config.delete('font_size') + logger.info('reset theme, font, font size, and transparency to default.') # We prefer a UTF-8 encoding gets set, but older Windows versions have # issues with this. From Windows 10 1903 onwards we can rely on the @@ -1526,6 +1528,13 @@ sys.path: {sys.path}''' setup_killswitches() root = tk.Tk(className=appname.lower()) + if sys.platform != 'win32' and ((f := config.get_str('font')) is not None or f != ''): + size = config.get_int('font_size', default=-1) + if size == -1: + size = 10 + + logger.info(f'Overriding tkinter default font to {f!r} at size {size}') + tk.font.nametofont('TkDefaultFont').configure(family=f, size=size) # UI Scaling """ From 8f2802fbcf64abbd90bc0aeb59840b20216d0ca5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 08:48:42 +0100 Subject: [PATCH 476/727] monitor.py: Add support for Odyssey 'Component' materials. --- PLUGINS.md | 4 ++++ monitor.py | 1 + 2 files changed, 5 insertions(+) diff --git a/PLUGINS.md b/PLUGINS.md index 3d4d6856..7e5fbe8e 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -515,6 +515,7 @@ Content of `state` (updated to the current journal entry): | `Raw` | `dict` | Current raw engineering materials | | `Manufactured` | `dict` | Current manufactured engineering materials | | `Encoded` | `dict` | Current encoded engineering materials | +| `Component` | `dict` | Current component materials | | `Engineers` | `dict` | Current Raw engineering materials | | `Rank` | `Dict[str, Tuple[int, int]` | Current ranks, each entry is a tuple of the current rank, and age | | `Statistics` | `dict` | Contents of a Journal Statistics event, ie, data shown in the stats panel. See the Journal manual for more info | @@ -553,6 +554,9 @@ Journal `ModuleInfo` event. `OnFoot` is an indication as to if the player is on-foot, rather than in a vehicle. +`Component` is a dict tracking your 'on-foot' materials for upgrading Suits +and on-foot weapons. + ##### Synthetic Events A special "StartUp" entry is sent if EDMC is started while the game is already diff --git a/monitor.py b/monitor.py index b55075b5..72730d3a 100644 --- a/monitor.py +++ b/monitor.py @@ -117,6 +117,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Raw': defaultdict(int), 'Manufactured': defaultdict(int), 'Encoded': defaultdict(int), + 'Component': defaultdict(int), # Odyssey materials 'Engineers': {}, 'Rank': {}, 'Reputation': {}, From 672c0d3d493478dfdbfaaeeb69536a61b47b351d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 10:51:25 +0100 Subject: [PATCH 477/727] Don't log when monitor.get_entry() returns `None` This is expected due to code using this just to 'tickle' a display update. --- EDMarketConnector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index d74ca185..66d13235 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -894,7 +894,8 @@ class AppWindow(object): while True: entry = monitor.get_entry() if not entry: - logger.trace('No entry from monitor.get_entry()') + # This is expected due to some monitor.py code that appends `None` + # logger.trace('No entry from monitor.get_entry()') return # Update main window From 3933dea4790afa97700f9ac9a060652adff191b1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 12:19:40 +0100 Subject: [PATCH 478/727] Convert monitor.event_queue to a queue.Queue. * We now use event_queue.empty() to see if it is indeed empty. * Changed AppWindow.journal_event() to also use .empty() rather than `while True`. Keeping the `'if not entry'` check just in case. This prevents it from calling monitor.get_entry() when the prior run through the loop has just emptied the queue. Thus we'll only log when it genuinely IS unexpectedly empty. * During *game* Shutdown we can send the synthetic 'Shutdown' event through, and then find and append the actual game 'Shutdown' event (i.e. this wasn't a crash, which is what the synthetic event is meant to react to). But AppWindow.journal_event() loop picks up both events in one call, so the second <> sends it working on an empty queue. Thus we log in monitor.get_entry() only if the queue is empty *and* the game is still running. * NB: Also adds 'Component' to the OTHER place montitor.state is initialised. --- EDMarketConnector.py | 2 +- monitor.py | 102 +++++++++++++++++++++++-------------------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 66d13235..41724cb8 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -891,7 +891,7 @@ class AppWindow(object): logger.debug('monitor.thread is None, assuming shutdown and returning') return - while True: + while not monitor.event_queue.empty(): entry = monitor.get_entry() if not entry: # This is expected due to some monitor.py code that appends `None` diff --git a/monitor.py b/monitor.py index 72730d3a..0abe721a 100644 --- a/monitor.py +++ b/monitor.py @@ -1,6 +1,7 @@ """Monitor for new Journal files and contents of latest.""" import json +import queue import re import threading from calendar import timegm @@ -78,7 +79,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.observer: Optional['Observer'] = None self.observed = None # a watchdog ObservedWatch, or None if polling self.thread: Optional[threading.Thread] = None - self.event_queue: List = [] # For communicating journal entries back to main thread + # For communicating journal entries back to main thread + self.event_queue: queue.Queue = queue.Queue(maxsize=0) # On startup we might be: # 1) Looking at an old journal file because the game isn't running or the user has exited to the main menu. @@ -342,11 +344,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below entry['StationType'] = self.stationtype entry['MarketID'] = self.station_marketid - self.event_queue.append(json.dumps(entry, separators=(', ', ':'))) + self.event_queue.put(json.dumps(entry, separators=(', ', ':'))) else: # Generate null event to update the display (with possibly out-of-date info) - self.event_queue.append(None) + self.event_queue.put(None) self.live = False # Watchdog thread -- there is a way to get this by using self.observer.emitters and checking for an attribute: @@ -396,12 +398,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return # Terminate if b'"event":"Location"' in line: - logger.trace('Found "Location" event, appending to event_queue') + logger.trace('Found "Location" event, adding to event_queue') - self.event_queue.append(line) + self.event_queue.put(line) - if self.event_queue: + if not self.event_queue.empty(): if not config.shutting_down: + # logger.trace('Sending <>') self.root.event_generate('<>', when="tail") log_pos = loghandle.tell() @@ -420,11 +423,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if not self.game_running(): logger.info('Detected exit from game, synthesising ShutDown event') timestamp = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) - self.event_queue.append( + self.event_queue.put( f'{{ "timestamp":"{timestamp}", "event":"ShutDown" }}' ) if not config.shutting_down: + # logger.trace('Sending <>') self.root.event_generate('<>', when="tail") self.game_was_running = False @@ -482,6 +486,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Raw': defaultdict(int), 'Manufactured': defaultdict(int), 'Encoded': defaultdict(int), + 'Component': defaultdict(int), 'Engineers': {}, 'Rank': {}, 'Reputation': {}, @@ -975,54 +980,55 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug('Called whilst self.thread is None, returning') return None - if not self.event_queue: - logger.trace('Called with no event_queue') + # logger.trace('Begin') + if self.event_queue.empty() and self.game_running(): + logger.error('event_queue is empty whilst game_running, this should not happen, returning') return None - else: - entry = self.parse_entry(self.event_queue.pop(0)) + # logger.trace('event_queue NOT empty') + entry = self.parse_entry(self.event_queue.get_nowait()) + + if entry['event'] == 'Location': + logger.trace('"Location" event') + + if not self.live and entry['event'] not in (None, 'Fileheader'): + # Game not running locally, but Journal has been updated + self.live = True + if self.station: + entry = OrderedDict([ + ('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())), + ('event', 'StartUp'), + ('Docked', True), + ('MarketID', self.station_marketid), + ('StationName', self.station), + ('StationType', self.stationtype), + ('StarSystem', self.system), + ('StarPos', self.coordinates), + ('SystemAddress', self.systemaddress), + ]) + + else: + entry = OrderedDict([ + ('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())), + ('event', 'StartUp'), + ('Docked', False), + ('StarSystem', self.system), + ('StarPos', self.coordinates), + ('SystemAddress', self.systemaddress), + ]) if entry['event'] == 'Location': - logger.trace('"Location" event') + logger.trace('Appending "Location" event to event_queue') - if not self.live and entry['event'] not in (None, 'Fileheader'): - # Game not running locally, but Journal has been updated - self.live = True - if self.station: - entry = OrderedDict([ - ('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())), - ('event', 'StartUp'), - ('Docked', True), - ('MarketID', self.station_marketid), - ('StationName', self.station), - ('StationType', self.stationtype), - ('StarSystem', self.system), - ('StarPos', self.coordinates), - ('SystemAddress', self.systemaddress), - ]) + self.event_queue.put(json.dumps(entry, separators=(', ', ':'))) - else: - entry = OrderedDict([ - ('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())), - ('event', 'StartUp'), - ('Docked', False), - ('StarSystem', self.system), - ('StarPos', self.coordinates), - ('SystemAddress', self.systemaddress), - ]) + elif self.live and entry['event'] == 'Music' and entry.get('MusicTrack') == 'MainMenu': + ts = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) + self.event_queue.put( + f'{{ "timestamp":"{ts}", "event":"ShutDown" }}' + ) - if entry['event'] == 'Location': - logger.trace('Appending "Location" event to event_queue') - - self.event_queue.append(json.dumps(entry, separators=(', ', ':'))) - - elif self.live and entry['event'] == 'Music' and entry.get('MusicTrack') == 'MainMenu': - ts = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) - self.event_queue.append( - f'{{ "timestamp":"{ts}", "event":"ShutDown" }}' - ) - - return entry + return entry def game_running(self) -> bool: # noqa: CCR001 """ From c26d1bce93bf068640227624a0a2c702fc8dfeac Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 12:35:46 +0100 Subject: [PATCH 479/727] Comment out un-necessary logger.trace() In monitor.py it was all that 'Location' event tracing. --- EDMarketConnector.py | 2 +- monitor.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 41724cb8..e837abf7 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -959,7 +959,7 @@ class AppWindow(object): self.login() if not entry['event'] or not monitor.mode: - logger.trace('Startup or in CQC, returning') + # logger.trace('Startup or in CQC, returning') return # Startup or in CQC if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started: diff --git a/monitor.py b/monitor.py index 0abe721a..6ae6b372 100644 --- a/monitor.py +++ b/monitor.py @@ -305,8 +305,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below for line in loghandle: try: - if b'"event":"Location"' in line: - logger.trace('"Location" event in the past at startup') + # if b'"event":"Location"' in line: + # logger.trace('"Location" event in the past at startup') self.parse_entry(line) # Some events are of interest even in the past @@ -397,8 +397,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.info("We're not meant to be running, exiting...") return # Terminate - if b'"event":"Location"' in line: - logger.trace('Found "Location" event, adding to event_queue') + # if b'"event":"Location"' in line: + # logger.trace('Found "Location" event, adding to event_queue') self.event_queue.put(line) @@ -645,8 +645,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if event_type in ('Location', 'CarrierJump'): self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None - if event_type == 'Location': - logger.trace('"Location" event') + # if event_type == 'Location': + # logger.trace('"Location" event') elif event_type == 'FSDJump': self.planet = None @@ -988,8 +988,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # logger.trace('event_queue NOT empty') entry = self.parse_entry(self.event_queue.get_nowait()) - if entry['event'] == 'Location': - logger.trace('"Location" event') + # if entry['event'] == 'Location': + # logger.trace('"Location" event') if not self.live and entry['event'] not in (None, 'Fileheader'): # Game not running locally, but Journal has been updated @@ -1017,8 +1017,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below ('SystemAddress', self.systemaddress), ]) - if entry['event'] == 'Location': - logger.trace('Appending "Location" event to event_queue') + # if entry['event'] == 'Location': + # logger.trace('Appending "Location" event to event_queue') self.event_queue.put(json.dumps(entry, separators=(', ', ':'))) From 74a2b70a196010a5d6aa3746123fecd6aff487aa Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 13:41:29 +0100 Subject: [PATCH 480/727] PLUGINS.md: Add ship_utils.ship_map to allowed imports --- PLUGINS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PLUGINS.md b/PLUGINS.md index 7e5fbe8e..503a60fa 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -63,6 +63,9 @@ breaking with future code changes.** `from companion import category_map` - Or any of the other static data contained therein. NB: There's a plan to move such to a `data` module. +`from util_ships import ship_map` - A mapping of symbolic to English +readable names for ships. + `import plug` - For using `plug.show_error()` and accessing the flags for `dashboard_entry()` to be useful (see example below). Relying on anything else isn't supported. From 7bbc8e86a23a83975d004d5ceac3f87697b55f7b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 08:31:40 +0100 Subject: [PATCH 481/727] Pre-Release 5.0.0-beta3: appversion and changelog # Conflicts: # config.py --- ChangeLog.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ config.py | 7 +++---- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 31a3a69b..d6aba4ad 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,52 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- +Pre-Release 5.0.0-beta3 +=== + +This pre-release allows for using the application with the Odyssey Phase 1 +Alpha without constant complaints of 'Error: Frontier server is lagging'. +Work is on-going for supporting any new items and features in the Alpha, +but this application should now be usable with it. Please +[report](https://github.com/EDCD/EDMarketConnector/issues/new?assignees=&labels=bug%2C+unconfirmed&template=bug_report.md&title=) +any EDMC errors you experience! + +* Add support for detecting if a player is on-foot. This is then used to + prevent false 'Frontier server lagging' messages. + + Note that currently your on-foot location can only be detected when you + login, and not when you disembark from an Apex shuttle anywhere. + +* Linux and macOS: You can now set a font name and size in your config file. + Ensuring this is a TTF font, rather than a bitmap font, should allow the + application UI scaling to work. + + 1. 'font' - the font name to attempt using + 2. 'font_size' - the font size to attempt using. + + There is no UI for this in Preferences, you will need to edit your + [config file](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#location-of-configuration-files) + to set or change it, and then restart the application. + + This is not supported on Windows so as not to risk weird bugs. UI + Scaling works on Windows without this. + +* Code to do with processing Journal events was reworked and noisy logging + reduced as a consequence. + +Plugin Authors +--- + +* The new materials added in Odyssey (for things like Suit and on-foot + Weapon upgrades) are now tracked in the `state['Component']` dictionary. + + NB: Only from the `MissionCompleted` event at this point, support still + needs adding for the `ShipLockerMaterials` event to synchronise totals at + login. + +* `companion.ship_map` was moved to `util_ships.ship_map` so as to avoid an + import loop from some other changes. + Pre-Release 5.0.0-beta2 === diff --git a/config.py b/config.py index 5941b5a1..159a29b3 100644 --- a/config.py +++ b/config.py @@ -40,10 +40,9 @@ appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) -appversion = '4.2.0-beta1' #-rc1+a872b5f' -# For some things we want appversion without (possible) +build metadata -appversion_nobuild = str(semantic_version.Version(appversion).truncate('prerelease')) -copyright = u'© 2015-2019 Jonathan Harris, 2020-2021 EDCD' +# NB: Do *not* import this, use the functions appversion() and appversion_nobuild() +_static_appversion = '5.0.0-beta3' +copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' update_interval = 8*60*60 From 103e856446ada9a70dccfadf1f0d78b1e5e352fe Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 18:39:58 +0100 Subject: [PATCH 482/727] EDMarketConnector.py: Move chdir as early as possible We need the config.py read of .gitversion to be from the right place. --- EDMarketConnector.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index e837abf7..87bee355 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -16,6 +16,17 @@ from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple +# Have this as early as possible for people running EDMarketConnector.exe +# from cmd.exe or a bat file or similar. Else they might not be in the correct +# place for things like config.py reading .gitversion +if getattr(sys, 'frozen', False): + # Under py2exe sys.path[0] is the executable name + if platform == 'win32': + chdir(dirname(sys.path[0])) + # Allow executable to be invoked from any cwd + environ['TCL_LIBRARY'] = join(dirname(sys.path[0]), 'lib', 'tcl') + environ['TK_LIBRARY'] = join(dirname(sys.path[0]), 'lib', 'tk') + from constants import applongname, appname, protocolhandler_redirect # config will now cause an appname logger to be set up, so we need the @@ -236,14 +247,6 @@ if TYPE_CHECKING: """Fake the l10n translation functions for typing.""" return x -if getattr(sys, 'frozen', False): - # Under py2exe sys.path[0] is the executable name - if platform == 'win32': - chdir(dirname(sys.path[0])) - # Allow executable to be invoked from any cwd - environ['TCL_LIBRARY'] = join(dirname(sys.path[0]), 'lib', 'tcl') - environ['TK_LIBRARY'] = join(dirname(sys.path[0]), 'lib', 'tk') - import tkinter as tk import tkinter.filedialog import tkinter.font From 0b8811784454c427016b198bf221374df8d2fc2f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 19:13:04 +0100 Subject: [PATCH 483/727] chdir() to __file__ when not running frozen --- EDMarketConnector.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 87bee355..3bf232f2 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -6,6 +6,7 @@ import argparse import html import json import locale +import pathlib import re import sys import webbrowser @@ -27,6 +28,11 @@ if getattr(sys, 'frozen', False): environ['TCL_LIBRARY'] = join(dirname(sys.path[0]), 'lib', 'tcl') environ['TK_LIBRARY'] = join(dirname(sys.path[0]), 'lib', 'tk') +else: + # We still want to *try* to have CWD be where the main script is, even if + # not frozen. + chdir(pathlib.Path(__file__).parent) + from constants import applongname, appname, protocolhandler_redirect # config will now cause an appname logger to be set up, so we need the From f16a367986873c759271d1137da31bf61f505e65 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 19:19:45 +0100 Subject: [PATCH 484/727] Use full path to open .gitversion out of paranoia. --- config.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config.py b/config.py index 159a29b3..b193dda6 100644 --- a/config.py +++ b/config.py @@ -134,11 +134,9 @@ def appversion() -> semantic_version.Version: """ if getattr(sys, 'frozen', False): # Running frozen, so we should have a .gitversion file - with open(GITVERSION_FILE, 'r', encoding='utf-8') as gitv: + with open(pathlib.Path(sys.path[0]).parent / GITVERSION_FILE, 'r', encoding='utf-8') as gitv: shorthash = gitv.read() - # TODO: Check if there was already a build meta data in static_appversion ? - else: # Running from source shorthash = git_shorthash_from_head() From c1cf90bda3aebbfeadfd5f1e4a6e3c24abd0dd10 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Apr 2021 19:33:13 +0100 Subject: [PATCH 485/727] Add comment about using .parent because non-main script is in library.zip --- config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config.py b/config.py index b193dda6..ffa651d4 100644 --- a/config.py +++ b/config.py @@ -134,6 +134,7 @@ def appversion() -> semantic_version.Version: """ if getattr(sys, 'frozen', False): # Running frozen, so we should have a .gitversion file + # Yes, .parent because if frozen we're inside library.zip with open(pathlib.Path(sys.path[0]).parent / GITVERSION_FILE, 'r', encoding='utf-8') as gitv: shorthash = gitv.read() From f2b89691c6029a658b7498283b6fc82bd026dbc5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 10:11:49 +0100 Subject: [PATCH 486/727] Python: Use 3.9.3 --- .github/workflows/windows-build.yml | 2 +- .pre-commit-config.yaml | 2 +- .python-version | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 2efd61cd..7a62de8e 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: "3.9.2" + python-version: "3.9.3" architecture: "x86" - name: Install python tools diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b161b359..25f65352 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,7 +67,7 @@ repos: language: system default_language_version: - python: python3.8 + python: python3.9 default_stages: [ commit, push ] diff --git a/.python-version b/.python-version index 2009c7df..820476af 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.9.2 +3.9.3 From ee9565564b75389904ddb340efeca02befe58cc0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 10:14:38 +0100 Subject: [PATCH 487/727] Add new data.py file to hold all static data. The aim here is to avoid static data in modules that contain code. Why? So that we can avoid some potential import loops when the 'inner' module only wants static data but is already imported by the 'outer' module for code purposes. --- data.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 data.py diff --git a/data.py b/data.py new file mode 100644 index 00000000..af379fb1 --- /dev/null +++ b/data.py @@ -0,0 +1 @@ +"""Static data.""" From 5d289454a959cf825c3d282279c804044f70b110 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 10:17:37 +0100 Subject: [PATCH 488/727] Move commodity.py bracketmap into data.py --- commodity.py | 7 +------ data.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/commodity.py b/commodity.py index c384d127..5ad0830c 100644 --- a/commodity.py +++ b/commodity.py @@ -6,13 +6,8 @@ import hashlib import time from config import config +from data import commodity_bracketmap as bracketmap -bracketmap = { - 0: '', - 1: 'Low', - 2: 'Med', - 3: 'High', -} # DEFAULT means semi-colon separation # CSV means comma separation diff --git a/data.py b/data.py index af379fb1..058bf1c1 100644 --- a/data.py +++ b/data.py @@ -1 +1,13 @@ -"""Static data.""" +""" +Static data. + +For easy reference any variable should be prefixed with the name of the file it +was either in originally, or where the primary code utilising it is. +""" + +commodity_bracketmap = { + 0: '', + 1: 'Low', + 2: 'Med', + 3: 'High', +} From 5db62e48a3346fcba5f6ce322e51637580db2ede Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 10:24:13 +0100 Subject: [PATCH 489/727] Move companion.py category_map into data.py --- collate.py | 5 +++-- companion.py | 11 +---------- data.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/collate.py b/collate.py index 3a0aa824..10bb24b6 100755 --- a/collate.py +++ b/collate.py @@ -11,6 +11,7 @@ from os.path import isfile from traceback import print_exc import companion +import data import outfitting import util_ships @@ -54,13 +55,13 @@ def addcommodities(data): new = { 'id' : commodity['id'], 'symbol' : commodity['name'], - 'category' : companion.category_map.get(commodity['categoryname']) or commodity['categoryname'], + 'category' : data.companion_category_map.get(commodity['categoryname']) or commodity['categoryname'], 'name' : commodity.get('locName') or 'Limpets', } old = commodities.get(key) - if old and companion.category_map.get(commodity['categoryname'], True): + if old and data.companion_category_map.get(commodity['categoryname'], True): if new['symbol'] != old['symbol'] or new['name'] != old['name']: raise ValueError('{}: {!r} != {!r}'.format(key, new, old)) diff --git a/companion.py b/companion.py index e5afb40d..c8b3e015 100644 --- a/companion.py +++ b/companion.py @@ -27,6 +27,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Union, cast import requests from config import appname, appversion, config +from data import companion_category_map as category_map from EDMCLogging import get_main_logger from monitor import monitor from protocol import protocolhandler @@ -64,16 +65,6 @@ URL_QUERY = '/profile' URL_MARKET = '/market' URL_SHIPYARD = '/shipyard' - -# Map values reported by the Companion interface to names displayed in-game -# May be imported by plugins -category_map = { - 'Narcotics': 'Legal Drugs', - 'Slaves': 'Slavery', - 'Waste ': 'Waste', - 'NonMarketable': False, # Don't appear in the in-game market so don't report -} - commodity_map: Dict = {} diff --git a/data.py b/data.py index 058bf1c1..3688f8c9 100644 --- a/data.py +++ b/data.py @@ -5,9 +5,19 @@ For easy reference any variable should be prefixed with the name of the file it was either in originally, or where the primary code utilising it is. """ +# Map numeric 'demand/supply brackets' to the names as shown in-game. commodity_bracketmap = { 0: '', 1: 'Low', 2: 'Med', 3: 'High', } + +# Map values reported by the Companion interface to names displayed in-game. +# May be imported by plugins. +companion_category_map = { + 'Narcotics': 'Legal Drugs', + 'Slaves': 'Slavery', + 'Waste ': 'Waste', + 'NonMarketable': False, # Don't appear in the in-game market so don't report +} From cc809de042ddf6b4b24e11fd15989f474a372163 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 10:25:17 +0100 Subject: [PATCH 490/727] config.py: Remove 'protoype' comment about appversion being a function --- config.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/config.py b/config.py index ffa651d4..16528fae 100644 --- a/config.py +++ b/config.py @@ -29,14 +29,6 @@ from constants import GITVERSION_FILE, applongname, appname # Any of these may be imported by plugins appcmdname = 'EDMC' -# Replacing appversion with a function: -# -# 1. In setup.py grab the current HEAD short hash and place in a file .gitversion -# 2. config.py code then needs to check: -# a. If we're not frozen and .git/ exists (i.e. not from a tarball ?) use something to get the current HEAD -# b. If not frozen and no .gitversion (but there should be) ??? -# c. If frozen, just read the .gitversion (that had better damned well be there, but catch if it's not). -# 3. But I don't want to spam EDDN with different 5.0.0-beta1+shorthash when testing... so ??? # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) From 02d1a8cf45c90ef18788c16b51acfc1fe657d933 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 10:28:07 +0100 Subject: [PATCH 491/727] Move coriolis.py coriolis_ship_map into data.py --- coriolis.py | 10 +--------- data.py | 9 +++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/coriolis.py b/coriolis.py index 7f6d9c0a..36a61afe 100755 --- a/coriolis.py +++ b/coriolis.py @@ -16,6 +16,7 @@ from config import config import outfitting import companion import util_ships +from data import coriolis_ship_map if __name__ == "__main__": @@ -30,15 +31,6 @@ if __name__ == "__main__": data = json.load(open('coriolis-data/dist/index.json')) - # Map Coriolis's names to names displayed in the in-game shipyard - coriolis_ship_map = { - 'Cobra Mk III' : 'Cobra MkIII', - 'Cobra Mk IV' : 'Cobra MkIV', - 'Krait Mk II' : 'Krait MkII', - 'Viper' : 'Viper MkIII', - 'Viper Mk IV' : 'Viper MkIV', - } - # Symbolic name from in-game name reverse_ship_map = {v: k for k, v in list(util_ships.ship_map.items())} diff --git a/data.py b/data.py index 3688f8c9..fd8adf84 100644 --- a/data.py +++ b/data.py @@ -21,3 +21,12 @@ companion_category_map = { 'Waste ': 'Waste', 'NonMarketable': False, # Don't appear in the in-game market so don't report } + +# Map Coriolis's names to names displayed in the in-game shipyard. +coriolis_ship_map = { + 'Cobra Mk III': 'Cobra MkIII', + 'Cobra Mk IV' : 'Cobra MkIV', + 'Krait Mk II' : 'Krait MkII', + 'Viper' : 'Viper MkIII', + 'Viper Mk IV' : 'Viper MkIV', +} From b961ca814a817635540b1fc796f372b6b933189b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 10:35:35 +0100 Subject: [PATCH 492/727] Move edshipyard.py slot_map into data.py --- data.py | 26 ++++++++++++++++++++++---- edshipyard.py | 32 +------------------------------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/data.py b/data.py index fd8adf84..ec64cd30 100644 --- a/data.py +++ b/data.py @@ -25,8 +25,26 @@ companion_category_map = { # Map Coriolis's names to names displayed in the in-game shipyard. coriolis_ship_map = { 'Cobra Mk III': 'Cobra MkIII', - 'Cobra Mk IV' : 'Cobra MkIV', - 'Krait Mk II' : 'Krait MkII', - 'Viper' : 'Viper MkIII', - 'Viper Mk IV' : 'Viper MkIV', + 'Cobra Mk IV': 'Cobra MkIV', + 'Krait Mk II': 'Krait MkII', + 'Viper': 'Viper MkIII', + 'Viper Mk IV': 'Viper MkIV', +} + +# Map API slot names to E:D Shipyard slot names +edshipyard_slot_map = { + 'hugehardpoint': 'H', + 'largehardpoint': 'L', + 'mediumhardpoint': 'M', + 'smallhardpoint': 'S', + 'tinyhardpoint': 'U', + 'armour': 'BH', + 'powerplant': 'RB', + 'mainengines': 'TM', + 'frameshiftdrive': 'FH', + 'lifesupport': 'EC', + 'powerdistributor': 'PC', + 'radar': 'SS', + 'fueltank': 'FS', + 'military': 'MC', } diff --git a/edshipyard.py b/edshipyard.py index 0cf13dac..0f29f7b6 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -8,43 +8,13 @@ import re import time from config import config +from data import edshipyard_slot_map as slot_map import outfitting import util_ships from typing import Dict, Union, List __Module = Dict[str, Union[str, List[str]]] -# Map API ship names to E:D Shipyard ship names -ship_map = util_ships.ship_map.copy() - -ship_map.update( - { - 'cobramkiii': 'Cobra Mk III', - 'cobramkiv' : 'Cobra Mk IV', - 'viper' : 'Viper', - 'viper_mkiv': 'Viper Mk IV', - } -) - - -# Map API slot names to E:D Shipyard slot names -slot_map = { - 'hugehardpoint' : 'H', - 'largehardpoint' : 'L', - 'mediumhardpoint' : 'M', - 'smallhardpoint' : 'S', - 'tinyhardpoint' : 'U', - 'armour' : 'BH', - 'powerplant' : 'RB', - 'mainengines' : 'TM', - 'frameshiftdrive' : 'FH', - 'lifesupport' : 'EC', - 'powerdistributor' : 'PC', - 'radar' : 'SS', - 'fueltank' : 'FS', - 'military' : 'MC', -} - # Ship masses # TODO: prefer something other than pickle for this storage (dev readability, security) From a47143a6a595b90dc4a427dd325f60e057c7333d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 11:02:08 +0100 Subject: [PATCH 493/727] Move all static data from outfitting.py into data.py --- data.py | 328 +++++++++++++++++++++++++++++++++++++++++++++++ outfitting.py | 346 +++----------------------------------------------- 2 files changed, 345 insertions(+), 329 deletions(-) diff --git a/data.py b/data.py index ec64cd30..710bc2fd 100644 --- a/data.py +++ b/data.py @@ -4,6 +4,7 @@ Static data. For easy reference any variable should be prefixed with the name of the file it was either in originally, or where the primary code utilising it is. """ +from collections import OrderedDict # Map numeric 'demand/supply brackets' to the names as shown in-game. commodity_bracketmap = { @@ -48,3 +49,330 @@ edshipyard_slot_map = { 'fueltank': 'FS', 'military': 'MC', } + +# Map API module names to in-game names + +outfitting_armour_map = OrderedDict([ + ('grade1', 'Lightweight Alloy'), + ('grade2', 'Reinforced Alloy'), + ('grade3', 'Military Grade Composite'), + ('mirrored', 'Mirrored Surface Composite'), + ('reactive', 'Reactive Surface Composite'), +]) + +outfitting_weapon_map = { + 'advancedtorppylon': 'Torpedo Pylon', + 'atdumbfiremissile': 'AX Missile Rack', + 'atmulticannon': 'AX Multi-Cannon', + 'basicmissilerack': 'Seeker Missile Rack', + 'beamlaser': 'Beam Laser', + ('beamlaser', 'heat'): 'Retributor Beam Laser', + 'cannon': 'Cannon', + 'causticmissile': 'Enzyme Missile Rack', + 'drunkmissilerack': 'Pack-Hound Missile Rack', + 'dumbfiremissilerack': 'Missile Rack', + ('dumbfiremissilerack', 'advanced'): 'Advanced Missile Rack', + ('dumbfiremissilerack', 'lasso'): 'Rocket Propelled FSD Disruptor', + 'flakmortar': 'Remote Release Flak Launcher', + 'flechettelauncher': 'Remote Release Flechette Launcher', + 'guardian_gausscannon': 'Guardian Gauss Cannon', + 'guardian_plasmalauncher': 'Guardian Plasma Charger', + 'guardian_shardcannon': 'Guardian Shard Cannon', + 'minelauncher': 'Mine Launcher', + ('minelauncher', 'impulse'): 'Shock Mine Launcher', + 'mining_abrblstr': 'Abrasion Blaster', + 'mining_seismchrgwarhd': 'Seismic Charge Launcher', + 'mining_subsurfdispmisle': 'Sub-Surface Displacement Missile', + 'mininglaser': 'Mining Laser', + ('mininglaser', 'advanced'): 'Mining Lance Beam Laser', + 'multicannon': 'Multi-Cannon', + ('multicannon', 'advanced'): 'Advanced Multi-Cannon', + ('multicannon', 'strong'): 'Enforcer Cannon', + 'plasmaaccelerator': 'Plasma Accelerator', + ('plasmaaccelerator', 'advanced'): 'Advanced Plasma Accelerator', + 'plasmashockcannon': 'Shock Cannon', + 'pulselaser': 'Pulse Laser', + ('pulselaser', 'disruptor'): 'Pulse Disruptor Laser', + 'pulselaserburst': 'Burst Laser', + ('pulselaserburst', 'scatter'): 'Cytoscrambler Burst Laser', + 'railgun': 'Rail Gun', + ('railgun', 'burst'): 'Imperial Hammer Rail Gun', + 'slugshot': 'Fragment Cannon', + ('slugshot', 'range'): 'Pacifier Frag-Cannon', +} + +outfitting_missiletype_map = { + 'advancedtorppylon': 'Seeker', + 'atdumbfiremissile': 'Dumbfire', + 'basicmissilerack': 'Seeker', + 'causticmissile': 'Dumbfire', + 'drunkmissilerack': 'Swarm', + 'dumbfiremissilerack': 'Dumbfire', + 'mining_subsurfdispmisle': 'Seeker', + 'mining_seismchrgwarhd': 'Seeker', +} + +outfitting_weaponmount_map = { + 'fixed': 'Fixed', + 'gimbal': 'Gimballed', + 'turret': 'Turreted', +} + +outfitting_weaponclass_map = { + 'tiny': '0', + 'small': '1', + 'smallfree': '1', + 'medium': '2', + 'large': '3', + 'huge': '4', +} + +# There's no discernable pattern for weapon ratings, so here's a lookup table +outfitting_weaponrating_map = { + 'hpt_advancedtorppylon_fixed_small': 'I', + 'hpt_advancedtorppylon_fixed_medium': 'I', + 'hpt_advancedtorppylon_fixed_large': 'I', + 'hpt_atdumbfiremissile_fixed_medium': 'B', + 'hpt_atdumbfiremissile_fixed_large': 'A', + 'hpt_atdumbfiremissile_turret_medium': 'B', + 'hpt_atdumbfiremissile_turret_large': 'A', + 'hpt_atmulticannon_fixed_medium': 'E', + 'hpt_atmulticannon_fixed_large': 'C', + 'hpt_atmulticannon_turret_medium': 'F', + 'hpt_atmulticannon_turret_large': 'E', + 'hpt_basicmissilerack_fixed_small': 'B', + 'hpt_basicmissilerack_fixed_medium': 'B', + 'hpt_basicmissilerack_fixed_large': 'A', + 'hpt_beamlaser_fixed_small': 'E', + 'hpt_beamlaser_fixed_medium': 'D', + 'hpt_beamlaser_fixed_large': 'C', + 'hpt_beamlaser_fixed_huge': 'A', + 'hpt_beamlaser_gimbal_small': 'E', + 'hpt_beamlaser_gimbal_medium': 'D', + 'hpt_beamlaser_gimbal_large': 'C', + 'hpt_beamlaser_gimbal_huge': 'A', + 'hpt_beamlaser_turret_small': 'F', + 'hpt_beamlaser_turret_medium': 'E', + 'hpt_beamlaser_turret_large': 'D', + 'hpt_cannon_fixed_small': 'D', + 'hpt_cannon_fixed_medium': 'D', + 'hpt_cannon_fixed_large': 'C', + 'hpt_cannon_fixed_huge': 'B', + 'hpt_cannon_gimbal_small': 'E', + 'hpt_cannon_gimbal_medium': 'D', + 'hpt_cannon_gimbal_large': 'C', + 'hpt_cannon_gimbal_huge': 'B', + 'hpt_cannon_turret_small': 'F', + 'hpt_cannon_turret_medium': 'E', + 'hpt_cannon_turret_large': 'D', + 'hpt_causticmissile_fixed_medium': 'B', + 'hpt_drunkmissilerack_fixed_medium': 'B', + 'hpt_dumbfiremissilerack_fixed_small': 'B', + 'hpt_dumbfiremissilerack_fixed_medium': 'B', + 'hpt_dumbfiremissilerack_fixed_large': 'A', + 'hpt_flakmortar_fixed_medium': 'B', + 'hpt_flakmortar_turret_medium': 'B', + 'hpt_flechettelauncher_fixed_medium': 'B', + 'hpt_flechettelauncher_turret_medium': 'B', + 'hpt_guardian_gausscannon_fixed_small': 'D', + 'hpt_guardian_gausscannon_fixed_medium': 'B', + 'hpt_guardian_plasmalauncher_fixed_small': 'D', + 'hpt_guardian_plasmalauncher_fixed_medium': 'B', + 'hpt_guardian_plasmalauncher_fixed_large': 'C', + 'hpt_guardian_plasmalauncher_turret_small': 'F', + 'hpt_guardian_plasmalauncher_turret_medium': 'E', + 'hpt_guardian_plasmalauncher_turret_large': 'D', + 'hpt_guardian_shardcannon_fixed_small': 'D', + 'hpt_guardian_shardcannon_fixed_medium': 'A', + 'hpt_guardian_shardcannon_fixed_large': 'C', + 'hpt_guardian_shardcannon_turret_small': 'F', + 'hpt_guardian_shardcannon_turret_medium': 'D', + 'hpt_guardian_shardcannon_turret_large': 'D', + 'hpt_minelauncher_fixed_small': 'I', + 'hpt_minelauncher_fixed_medium': 'I', + 'hpt_mining_abrblstr_fixed_small': 'D', + 'hpt_mining_abrblstr_turret_small': 'D', + 'hpt_mining_seismchrgwarhd_fixed_medium': 'B', + 'hpt_mining_seismchrgwarhd_turret_medium': 'B', + 'hpt_mining_subsurfdispmisle_fixed_small': 'B', + 'hpt_mining_subsurfdispmisle_fixed_medium': 'B', + 'hpt_mining_subsurfdispmisle_turret_small': 'B', + 'hpt_mining_subsurfdispmisle_turret_medium': 'B', + 'hpt_mininglaser_fixed_small': 'D', + 'hpt_mininglaser_fixed_medium': 'D', + 'hpt_mininglaser_turret_small': 'D', + 'hpt_mininglaser_turret_medium': 'D', + 'hpt_multicannon_fixed_small': 'F', + 'hpt_multicannon_fixed_medium': 'E', + 'hpt_multicannon_fixed_large': 'C', + 'hpt_multicannon_fixed_huge': 'A', + 'hpt_multicannon_gimbal_small': 'G', + 'hpt_multicannon_gimbal_medium': 'F', + 'hpt_multicannon_gimbal_large': 'C', + 'hpt_multicannon_gimbal_huge': 'A', + 'hpt_multicannon_turret_small': 'G', + 'hpt_multicannon_turret_medium': 'F', + 'hpt_multicannon_turret_large': 'E', + 'hpt_plasmaaccelerator_fixed_medium': 'C', + 'hpt_plasmaaccelerator_fixed_large': 'B', + 'hpt_plasmaaccelerator_fixed_huge': 'A', + 'hpt_plasmashockcannon_fixed_small': 'D', + 'hpt_plasmashockcannon_fixed_medium': 'D', + 'hpt_plasmashockcannon_fixed_large': 'C', + 'hpt_plasmashockcannon_gimbal_small': 'E', + 'hpt_plasmashockcannon_gimbal_medium': 'D', + 'hpt_plasmashockcannon_gimbal_large': 'C', + 'hpt_plasmashockcannon_turret_small': 'F', + 'hpt_plasmashockcannon_turret_medium': 'E', + 'hpt_plasmashockcannon_turret_large': 'D', + 'hpt_pulselaser_fixed_small': 'F', + 'hpt_pulselaser_fixed_smallfree': 'F', + 'hpt_pulselaser_fixed_medium': 'E', + 'hpt_pulselaser_fixed_large': 'D', + 'hpt_pulselaser_fixed_huge': 'A', + 'hpt_pulselaser_gimbal_small': 'G', + 'hpt_pulselaser_gimbal_medium': 'F', + 'hpt_pulselaser_gimbal_large': 'E', + 'hpt_pulselaser_gimbal_huge': 'A', + 'hpt_pulselaser_turret_small': 'G', + 'hpt_pulselaser_turret_medium': 'F', + 'hpt_pulselaser_turret_large': 'F', + 'hpt_pulselaserburst_fixed_small': 'F', + 'hpt_pulselaserburst_fixed_medium': 'E', + 'hpt_pulselaserburst_fixed_large': 'D', + 'hpt_pulselaserburst_fixed_huge': 'E', + 'hpt_pulselaserburst_gimbal_small': 'G', + 'hpt_pulselaserburst_gimbal_medium': 'F', + 'hpt_pulselaserburst_gimbal_large': 'E', + 'hpt_pulselaserburst_gimbal_huge': 'E', + 'hpt_pulselaserburst_turret_small': 'G', + 'hpt_pulselaserburst_turret_medium': 'F', + 'hpt_pulselaserburst_turret_large': 'E', + 'hpt_railgun_fixed_small': 'D', + 'hpt_railgun_fixed_medium': 'B', + 'hpt_slugshot_fixed_small': 'E', + 'hpt_slugshot_fixed_medium': 'A', + 'hpt_slugshot_fixed_large': 'C', + 'hpt_slugshot_gimbal_small': 'E', + 'hpt_slugshot_gimbal_medium': 'D', + 'hpt_slugshot_gimbal_large': 'C', + 'hpt_slugshot_turret_small': 'E', + 'hpt_slugshot_turret_medium': 'D', + 'hpt_slugshot_turret_large': 'C', +} + +# Old standard weapon variants +outfitting_weaponoldvariant_map = { + 'f': 'Focussed', + 'hi': 'High Impact', + 'lh': 'Low Heat', + 'oc': 'Overcharged', + 'ss': 'Scatter Spray', +} + +outfitting_countermeasure_map = { + 'antiunknownshutdown': ('Shutdown Field Neutraliser', 'F'), + 'chafflauncher': ('Chaff Launcher', 'I'), + 'electroniccountermeasure': ('Electronic Countermeasure', 'F'), + 'heatsinklauncher': ('Heat Sink Launcher', 'I'), + 'plasmapointdefence': ('Point Defence', 'I'), + 'xenoscanner': ('Xeno Scanner', 'E'), +} + +outfitting_utility_map = { + 'cargoscanner': 'Cargo Scanner', + 'cloudscanner': 'Frame Shift Wake Scanner', + 'crimescanner': 'Kill Warrant Scanner', + 'mrascanner': 'Pulse Wave Analyser', + 'shieldbooster': 'Shield Booster', +} + +outfitting_cabin_map = { + '0': 'Prisoner Cells', + '1': 'Economy Class Passenger Cabin', + '2': 'Business Class Passenger Cabin', + '3': 'First Class Passenger Cabin', + '4': 'Luxury Class Passenger Cabin', + '5': 'Passenger Cabin', # not seen +} + +outfitting_rating_map = { + '1': 'E', + '2': 'D', + '3': 'C', + '4': 'B', + '5': 'A', +} + +# Ratings are weird for the following + +outfitting_corrosion_rating_map = { + '1': 'E', + '2': 'F', +} + +outfitting_planet_rating_map = { + '1': 'H', + '2': 'G', +} + +outfitting_fighter_rating_map = { + '1': 'D', +} + +outfitting_misc_internal_map = { + ('detailedsurfacescanner', 'tiny'): ('Detailed Surface Scanner', 'I'), + ('dockingcomputer', 'advanced'): ('Advanced Docking Computer', 'E'), + ('dockingcomputer', 'standard'): ('Standard Docking Computer', 'E'), + 'planetapproachsuite': ('Planetary Approach Suite', 'I'), + ('stellarbodydiscoveryscanner', 'standard'): ('Basic Discovery Scanner', 'E'), + ('stellarbodydiscoveryscanner', 'intermediate'): ('Intermediate Discovery Scanner', 'D'), + ('stellarbodydiscoveryscanner', 'advanced'): ('Advanced Discovery Scanner', 'C'), + 'supercruiseassist': ('Supercruise Assist', 'E'), +} + +outfitting_standard_map = { + # 'armour': handled separately + 'engine': 'Thrusters', + ('engine', 'fast'): 'Enhanced Performance Thrusters', + 'fueltank': 'Fuel Tank', + 'guardianpowerdistributor': 'Guardian Hybrid Power Distributor', + 'guardianpowerplant': 'Guardian Hybrid Power Plant', + 'hyperdrive': 'Frame Shift Drive', + 'lifesupport': 'Life Support', + # 'planetapproachsuite': handled separately + 'powerdistributor': 'Power Distributor', + 'powerplant': 'Power Plant', + 'sensors': 'Sensors', +} + +outfitting_internal_map = { + 'buggybay': 'Planetary Vehicle Hangar', + 'cargorack': 'Cargo Rack', + 'collection': 'Collector Limpet Controller', + 'corrosionproofcargorack': 'Corrosion Resistant Cargo Rack', + 'decontamination': 'Decontamination Limpet Controller', + 'fighterbay': 'Fighter Hangar', + 'fsdinterdictor': 'Frame Shift Drive Interdictor', + 'fuelscoop': 'Fuel Scoop', + 'fueltransfer': 'Fuel Transfer Limpet Controller', + 'guardianfsdbooster': 'Guardian FSD Booster', + 'guardianhullreinforcement': 'Guardian Hull Reinforcement', + 'guardianmodulereinforcement': 'Guardian Module Reinforcement', + 'guardianshieldreinforcement': 'Guardian Shield Reinforcement', + 'hullreinforcement': 'Hull Reinforcement Package', + 'metaalloyhullreinforcement': 'Meta Alloy Hull Reinforcement', + 'modulereinforcement': 'Module Reinforcement Package', + 'passengercabin': 'Passenger Cabin', + 'prospector': 'Prospector Limpet Controller', + 'refinery': 'Refinery', + 'recon': 'Recon Limpet Controller', + 'repair': 'Repair Limpet Controller', + 'repairer': 'Auto Field-Maintenance Unit', + 'resourcesiphon': 'Hatch Breaker Limpet Controller', + 'shieldcellbank': 'Shield Cell Bank', + 'shieldgenerator': 'Shield Generator', + ('shieldgenerator', 'fast'): 'Bi-Weave Shield Generator', + ('shieldgenerator', 'strong'): 'Prismatic Shield Generator', + 'unkvesselresearch': 'Research Limpet Controller', +} diff --git a/outfitting.py b/outfitting.py index a132032d..714f5c06 100644 --- a/outfitting.py +++ b/outfitting.py @@ -5,340 +5,28 @@ import time import util_ships from config import config - - -# Map API module names to in-game names - -armour_map = OrderedDict([ - ('grade1', 'Lightweight Alloy'), - ('grade2', 'Reinforced Alloy'), - ('grade3', 'Military Grade Composite'), - ('mirrored', 'Mirrored Surface Composite'), - ('reactive', 'Reactive Surface Composite'), -]) - -weapon_map = { - 'advancedtorppylon' : 'Torpedo Pylon', - 'atdumbfiremissile' : 'AX Missile Rack', - 'atmulticannon' : 'AX Multi-Cannon', - 'basicmissilerack' : 'Seeker Missile Rack', - 'beamlaser' : 'Beam Laser', - ('beamlaser','heat') : 'Retributor Beam Laser', - 'cannon' : 'Cannon', - 'causticmissile' : 'Enzyme Missile Rack', - 'drunkmissilerack' : 'Pack-Hound Missile Rack', - 'dumbfiremissilerack' : 'Missile Rack', - ('dumbfiremissilerack', 'advanced') : 'Advanced Missile Rack', - ('dumbfiremissilerack', 'lasso') : 'Rocket Propelled FSD Disruptor', - 'flakmortar' : 'Remote Release Flak Launcher', - 'flechettelauncher' : 'Remote Release Flechette Launcher', - 'guardian_gausscannon' : 'Guardian Gauss Cannon', - 'guardian_plasmalauncher' : 'Guardian Plasma Charger', - 'guardian_shardcannon' : 'Guardian Shard Cannon', - 'minelauncher' : 'Mine Launcher', - ('minelauncher','impulse') : 'Shock Mine Launcher', - 'mining_abrblstr' : 'Abrasion Blaster', - 'mining_seismchrgwarhd' : 'Seismic Charge Launcher', - 'mining_subsurfdispmisle' : 'Sub-Surface Displacement Missile', - 'mininglaser' : 'Mining Laser', - ('mininglaser','advanced') : 'Mining Lance Beam Laser', - 'multicannon' : 'Multi-Cannon', - ('multicannon','advanced') : 'Advanced Multi-Cannon', - ('multicannon','strong') : 'Enforcer Cannon', - 'plasmaaccelerator' : 'Plasma Accelerator', - ('plasmaaccelerator','advanced') : 'Advanced Plasma Accelerator', - 'plasmashockcannon' : 'Shock Cannon', - 'pulselaser' : 'Pulse Laser', - ('pulselaser','disruptor') : 'Pulse Disruptor Laser', - 'pulselaserburst' : 'Burst Laser', - ('pulselaserburst','scatter') : 'Cytoscrambler Burst Laser', - 'railgun' : 'Rail Gun', - ('railgun','burst') : 'Imperial Hammer Rail Gun', - 'slugshot' : 'Fragment Cannon', - ('slugshot','range') : 'Pacifier Frag-Cannon', -} - -missiletype_map = { - 'advancedtorppylon' : 'Seeker', - 'atdumbfiremissile' : 'Dumbfire', - 'basicmissilerack' : 'Seeker', - 'causticmissile' : 'Dumbfire', - 'drunkmissilerack' : 'Swarm', - 'dumbfiremissilerack' : 'Dumbfire', - 'mining_subsurfdispmisle' : 'Seeker', - 'mining_seismchrgwarhd' : 'Seeker', -} - -weaponmount_map = { - 'fixed' : 'Fixed', - 'gimbal' : 'Gimballed', - 'turret' : 'Turreted', -} - -weaponclass_map = { - 'tiny' : '0', - 'small' : '1', - 'smallfree' : '1', - 'medium' : '2', - 'large' : '3', - 'huge' : '4', -} - -# There's no discernable pattern for weapon ratings, so here's a lookup table -weaponrating_map = { - 'hpt_advancedtorppylon_fixed_small' : 'I', - 'hpt_advancedtorppylon_fixed_medium': 'I', - 'hpt_advancedtorppylon_fixed_large' : 'I', - 'hpt_atdumbfiremissile_fixed_medium': 'B', - 'hpt_atdumbfiremissile_fixed_large' : 'A', - 'hpt_atdumbfiremissile_turret_medium': 'B', - 'hpt_atdumbfiremissile_turret_large' : 'A', - 'hpt_atmulticannon_fixed_medium' : 'E', - 'hpt_atmulticannon_fixed_large' : 'C', - 'hpt_atmulticannon_turret_medium' : 'F', - 'hpt_atmulticannon_turret_large' : 'E', - 'hpt_basicmissilerack_fixed_small' : 'B', - 'hpt_basicmissilerack_fixed_medium' : 'B', - 'hpt_basicmissilerack_fixed_large' : 'A', - 'hpt_beamlaser_fixed_small' : 'E', - 'hpt_beamlaser_fixed_medium' : 'D', - 'hpt_beamlaser_fixed_large': 'C', - 'hpt_beamlaser_fixed_huge': 'A', - 'hpt_beamlaser_gimbal_small': 'E', - 'hpt_beamlaser_gimbal_medium': 'D', - 'hpt_beamlaser_gimbal_large': 'C', - 'hpt_beamlaser_gimbal_huge': 'A', - 'hpt_beamlaser_turret_small': 'F', - 'hpt_beamlaser_turret_medium': 'E', - 'hpt_beamlaser_turret_large': 'D', - 'hpt_cannon_fixed_small': 'D', - 'hpt_cannon_fixed_medium': 'D', - 'hpt_cannon_fixed_large': 'C', - 'hpt_cannon_fixed_huge': 'B', - 'hpt_cannon_gimbal_small': 'E', - 'hpt_cannon_gimbal_medium': 'D', - 'hpt_cannon_gimbal_large': 'C', - 'hpt_cannon_gimbal_huge': 'B', - 'hpt_cannon_turret_small': 'F', - 'hpt_cannon_turret_medium': 'E', - 'hpt_cannon_turret_large': 'D', - 'hpt_causticmissile_fixed_medium': 'B', - 'hpt_drunkmissilerack_fixed_medium': 'B', - 'hpt_dumbfiremissilerack_fixed_small': 'B', - 'hpt_dumbfiremissilerack_fixed_medium': 'B', - 'hpt_dumbfiremissilerack_fixed_large': 'A', - 'hpt_flakmortar_fixed_medium': 'B', - 'hpt_flakmortar_turret_medium': 'B', - 'hpt_flechettelauncher_fixed_medium': 'B', - 'hpt_flechettelauncher_turret_medium': 'B', - 'hpt_guardian_gausscannon_fixed_small': 'D', - 'hpt_guardian_gausscannon_fixed_medium': 'B', - 'hpt_guardian_plasmalauncher_fixed_small': 'D', - 'hpt_guardian_plasmalauncher_fixed_medium': 'B', - 'hpt_guardian_plasmalauncher_fixed_large': 'C', - 'hpt_guardian_plasmalauncher_turret_small': 'F', - 'hpt_guardian_plasmalauncher_turret_medium': 'E', - 'hpt_guardian_plasmalauncher_turret_large': 'D', - 'hpt_guardian_shardcannon_fixed_small': 'D', - 'hpt_guardian_shardcannon_fixed_medium': 'A', - 'hpt_guardian_shardcannon_fixed_large': 'C', - 'hpt_guardian_shardcannon_turret_small': 'F', - 'hpt_guardian_shardcannon_turret_medium': 'D', - 'hpt_guardian_shardcannon_turret_large': 'D', - 'hpt_minelauncher_fixed_small': 'I', - 'hpt_minelauncher_fixed_medium': 'I', - 'hpt_mining_abrblstr_fixed_small' : 'D', - 'hpt_mining_abrblstr_turret_small' : 'D', - 'hpt_mining_seismchrgwarhd_fixed_medium' : 'B', - 'hpt_mining_seismchrgwarhd_turret_medium' : 'B', - 'hpt_mining_subsurfdispmisle_fixed_small' : 'B', - 'hpt_mining_subsurfdispmisle_fixed_medium' : 'B', - 'hpt_mining_subsurfdispmisle_turret_small' : 'B', - 'hpt_mining_subsurfdispmisle_turret_medium' : 'B', - 'hpt_mininglaser_fixed_small': 'D', - 'hpt_mininglaser_fixed_medium': 'D', - 'hpt_mininglaser_turret_small': 'D', - 'hpt_mininglaser_turret_medium': 'D', - 'hpt_multicannon_fixed_small': 'F', - 'hpt_multicannon_fixed_medium': 'E', - 'hpt_multicannon_fixed_large': 'C', - 'hpt_multicannon_fixed_huge': 'A', - 'hpt_multicannon_gimbal_small': 'G', - 'hpt_multicannon_gimbal_medium': 'F', - 'hpt_multicannon_gimbal_large': 'C', - 'hpt_multicannon_gimbal_huge': 'A', - 'hpt_multicannon_turret_small': 'G', - 'hpt_multicannon_turret_medium': 'F', - 'hpt_multicannon_turret_large': 'E', - 'hpt_plasmaaccelerator_fixed_medium': 'C', - 'hpt_plasmaaccelerator_fixed_large': 'B', - 'hpt_plasmaaccelerator_fixed_huge': 'A', - 'hpt_plasmashockcannon_fixed_small': 'D', - 'hpt_plasmashockcannon_fixed_medium': 'D', - 'hpt_plasmashockcannon_fixed_large': 'C', - 'hpt_plasmashockcannon_gimbal_small': 'E', - 'hpt_plasmashockcannon_gimbal_medium': 'D', - 'hpt_plasmashockcannon_gimbal_large': 'C', - 'hpt_plasmashockcannon_turret_small': 'F', - 'hpt_plasmashockcannon_turret_medium': 'E', - 'hpt_plasmashockcannon_turret_large': 'D', - 'hpt_pulselaser_fixed_small': 'F', - 'hpt_pulselaser_fixed_smallfree': 'F', - 'hpt_pulselaser_fixed_medium': 'E', - 'hpt_pulselaser_fixed_large': 'D', - 'hpt_pulselaser_fixed_huge': 'A', - 'hpt_pulselaser_gimbal_small': 'G', - 'hpt_pulselaser_gimbal_medium': 'F', - 'hpt_pulselaser_gimbal_large': 'E', - 'hpt_pulselaser_gimbal_huge': 'A', - 'hpt_pulselaser_turret_small': 'G', - 'hpt_pulselaser_turret_medium': 'F', - 'hpt_pulselaser_turret_large': 'F', - 'hpt_pulselaserburst_fixed_small': 'F', - 'hpt_pulselaserburst_fixed_medium': 'E', - 'hpt_pulselaserburst_fixed_large': 'D', - 'hpt_pulselaserburst_fixed_huge': 'E', - 'hpt_pulselaserburst_gimbal_small': 'G', - 'hpt_pulselaserburst_gimbal_medium': 'F', - 'hpt_pulselaserburst_gimbal_large': 'E', - 'hpt_pulselaserburst_gimbal_huge': 'E', - 'hpt_pulselaserburst_turret_small': 'G', - 'hpt_pulselaserburst_turret_medium': 'F', - 'hpt_pulselaserburst_turret_large': 'E', - 'hpt_railgun_fixed_small': 'D', - 'hpt_railgun_fixed_medium': 'B', - 'hpt_slugshot_fixed_small': 'E', - 'hpt_slugshot_fixed_medium': 'A', - 'hpt_slugshot_fixed_large': 'C', - 'hpt_slugshot_gimbal_small': 'E', - 'hpt_slugshot_gimbal_medium': 'D', - 'hpt_slugshot_gimbal_large': 'C', - 'hpt_slugshot_turret_small': 'E', - 'hpt_slugshot_turret_medium': 'D', - 'hpt_slugshot_turret_large': 'C', -} - -# Old standard weapon variants -weaponoldvariant_map = { - 'f' : 'Focussed', - 'hi' : 'High Impact', - 'lh' : 'Low Heat', - 'oc' : 'Overcharged', - 'ss' : 'Scatter Spray', -} - -countermeasure_map = { - 'antiunknownshutdown' : ('Shutdown Field Neutraliser', 'F'), - 'chafflauncher' : ('Chaff Launcher', 'I'), - 'electroniccountermeasure' : ('Electronic Countermeasure', 'F'), - 'heatsinklauncher' : ('Heat Sink Launcher', 'I'), - 'plasmapointdefence' : ('Point Defence', 'I'), - 'xenoscanner' : ('Xeno Scanner', 'E'), -} - -utility_map = { - 'cargoscanner' : 'Cargo Scanner', - 'cloudscanner' : 'Frame Shift Wake Scanner', - 'crimescanner' : 'Kill Warrant Scanner', - 'mrascanner' : 'Pulse Wave Analyser', - 'shieldbooster' : 'Shield Booster', -} - -cabin_map = { - '0': 'Prisoner Cells', - '1': 'Economy Class Passenger Cabin', - '2': 'Business Class Passenger Cabin', - '3': 'First Class Passenger Cabin', - '4': 'Luxury Class Passenger Cabin', - '5': 'Passenger Cabin', # not seen -} - -rating_map = { - '1': 'E', - '2': 'D', - '3': 'C', - '4': 'B', - '5': 'A', -} - -# Ratings are weird for the following - -corrosion_rating_map = { - '1': 'E', - '2': 'F', -} - -planet_rating_map = { - '1': 'H', - '2': 'G', -} - -fighter_rating_map = { - '1': 'D', -} - -misc_internal_map = { - ('detailedsurfacescanner', 'tiny') : ('Detailed Surface Scanner', 'I'), - ('dockingcomputer', 'advanced') : ('Advanced Docking Computer', 'E'), - ('dockingcomputer', 'standard') : ('Standard Docking Computer', 'E'), - 'planetapproachsuite' : ('Planetary Approach Suite', 'I'), - ('stellarbodydiscoveryscanner', 'standard') : ('Basic Discovery Scanner', 'E'), - ('stellarbodydiscoveryscanner', 'intermediate') : ('Intermediate Discovery Scanner', 'D'), - ('stellarbodydiscoveryscanner', 'advanced') : ('Advanced Discovery Scanner', 'C'), - 'supercruiseassist' : ('Supercruise Assist', 'E'), -} - -standard_map = { - # 'armour' : handled separately - 'engine' : 'Thrusters', - ('engine','fast') : 'Enhanced Performance Thrusters', - 'fueltank' : 'Fuel Tank', - 'guardianpowerdistributor' : 'Guardian Hybrid Power Distributor', - 'guardianpowerplant' : 'Guardian Hybrid Power Plant', - 'hyperdrive' : 'Frame Shift Drive', - 'lifesupport' : 'Life Support', - # 'planetapproachsuite' : handled separately - 'powerdistributor' : 'Power Distributor', - 'powerplant' : 'Power Plant', - 'sensors' : 'Sensors', -} - -internal_map = { - 'buggybay' : 'Planetary Vehicle Hangar', - 'cargorack' : 'Cargo Rack', - 'collection' : 'Collector Limpet Controller', - 'corrosionproofcargorack' : 'Corrosion Resistant Cargo Rack', - 'decontamination' : 'Decontamination Limpet Controller', - 'fighterbay' : 'Fighter Hangar', - 'fsdinterdictor' : 'Frame Shift Drive Interdictor', - 'fuelscoop' : 'Fuel Scoop', - 'fueltransfer' : 'Fuel Transfer Limpet Controller', - 'guardianfsdbooster' : 'Guardian FSD Booster', - 'guardianhullreinforcement' : 'Guardian Hull Reinforcement', - 'guardianmodulereinforcement': 'Guardian Module Reinforcement', - 'guardianshieldreinforcement': 'Guardian Shield Reinforcement', - 'hullreinforcement' : 'Hull Reinforcement Package', - 'metaalloyhullreinforcement' : 'Meta Alloy Hull Reinforcement', - 'modulereinforcement' : 'Module Reinforcement Package', - 'passengercabin' : 'Passenger Cabin', - 'prospector' : 'Prospector Limpet Controller', - 'refinery' : 'Refinery', - 'recon' : 'Recon Limpet Controller', - 'repair' : 'Repair Limpet Controller', - 'repairer' : 'Auto Field-Maintenance Unit', - 'resourcesiphon' : 'Hatch Breaker Limpet Controller', - 'shieldcellbank' : 'Shield Cell Bank', - 'shieldgenerator' : 'Shield Generator', - ('shieldgenerator','fast') : 'Bi-Weave Shield Generator', - ('shieldgenerator','strong') : 'Prismatic Shield Generator', - 'unkvesselresearch' : 'Research Limpet Controller', -} +from data import outfitting_armour_map as armour_map +from data import outfitting_weapon_map as weapon_map +from data import outfitting_missiletype_map as missiletype_map +from data import outfitting_weaponmount_map as weaponmount_map +from data import outfitting_weaponclass_map as weaponclass_map +from data import outfitting_weaponrating_map as weaponrating_map +from data import outfitting_weaponoldvariant_map as weaponoldvariant_map +from data import outfitting_countermeasure_map as countermeasure_map +from data import outfitting_utility_map as utility_map +from data import outfitting_cabin_map as cabin_map +from data import outfitting_rating_map as rating_map +from data import outfitting_corrosion_rating_map as corrosion_rating_map +from data import outfitting_planet_rating_map as planet_rating_map +from data import outfitting_fighter_rating_map as fighter_rating_map +from data import outfitting_misc_internal_map as misc_internal_map +from data import outfitting_standard_map as standard_map +from data import outfitting_internal_map as internal_map # Module mass, FSD data etc moduledata = OrderedDict() - # Given a module description from the Companion API returns a description of the module in the form of a # dict { category, name, [mount], [guidance], [ship], rating, class } using the same terms found in the # English langauge game. For fitted modules, dict also includes { enabled, priority }. From dda5a86f3dfc134d115deba0923bbd5f08dabb62 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 11:15:38 +0100 Subject: [PATCH 494/727] Move Status.json flags into data.py These aren't used by any core code, but at least one plugin uses one. --- data.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ plug.py | 49 ------------------------------------------------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/data.py b/data.py index 710bc2fd..ef50c9a9 100644 --- a/data.py +++ b/data.py @@ -376,3 +376,51 @@ outfitting_internal_map = { ('shieldgenerator', 'strong'): 'Prismatic Shield Generator', 'unkvesselresearch': 'Research Limpet Controller', } + +# Dashboard Flags constants +FlagsDocked = 1 << 0 # on a landing pad +FlagsLanded = 1 << 1 # on planet surface +FlagsLandingGearDown = 1 << 2 +FlagsShieldsUp = 1 << 3 +FlagsSupercruise = 1 << 4 +FlagsFlightAssistOff = 1 << 5 +FlagsHardpointsDeployed = 1 << 6 +FlagsInWing = 1 << 7 +FlagsLightsOn = 1 << 8 +FlagsCargoScoopDeployed = 1 << 9 +FlagsSilentRunning = 1 << 10 +FlagsScoopingFuel = 1 << 11 +FlagsSrvHandbrake = 1 << 12 +FlagsSrvTurret = 1 << 13 # using turret view +FlagsSrvUnderShip = 1 << 14 # turret retracted +FlagsSrvDriveAssist = 1 << 15 +FlagsFsdMassLocked = 1 << 16 +FlagsFsdCharging = 1 << 17 +FlagsFsdCooldown = 1 << 18 +FlagsLowFuel = 1 << 19 # < 25% +FlagsOverHeating = 1 << 20 # > 100%, or is this 80% now ? +FlagsHasLatLong = 1 << 21 +FlagsIsInDanger = 1 << 22 +FlagsBeingInterdicted = 1 << 23 +FlagsInMainShip = 1 << 24 +FlagsInFighter = 1 << 25 +FlagsInSRV = 1 << 26 +FlagsAnalysisMode = 1 << 27 # Hud in Analysis mode +FlagsNightVision = 1 << 28 +FlagsAverageAltitude = 1 << 29 # Altitude from Average radius +FlagsFsdJump = 1 << 30 +FlagsSrvHighBeam = 1 << 31 + +# Dashboard GuiFocus constants +GuiFocusNoFocus = 0 +GuiFocusInternalPanel = 1 # right hand side +GuiFocusExternalPanel = 2 # left hand side +GuiFocusCommsPanel = 3 # top +GuiFocusRolePanel = 4 # bottom +GuiFocusStationServices = 5 +GuiFocusGalaxyMap = 6 +GuiFocusSystemMap = 7 +GuiFocusOrrery = 8 +GuiFocusFSS = 9 +GuiFocusSAA = 10 +GuiFocusCodex = 11 diff --git a/plug.py b/plug.py index e1d8a52b..1ca11072 100644 --- a/plug.py +++ b/plug.py @@ -19,55 +19,6 @@ import logging logger = get_main_logger() -# Dashboard Flags constants -FlagsDocked = 1 << 0 # on a landing pad -FlagsLanded = 1 << 1 # on planet surface -FlagsLandingGearDown = 1 << 2 -FlagsShieldsUp = 1 << 3 -FlagsSupercruise = 1 << 4 -FlagsFlightAssistOff = 1 << 5 -FlagsHardpointsDeployed = 1 << 6 -FlagsInWing = 1 << 7 -FlagsLightsOn = 1 << 8 -FlagsCargoScoopDeployed = 1 << 9 -FlagsSilentRunning = 1 << 10 -FlagsScoopingFuel = 1 << 11 -FlagsSrvHandbrake = 1 << 12 -FlagsSrvTurret = 1 << 13 # using turret view -FlagsSrvUnderShip = 1 << 14 # turret retracted -FlagsSrvDriveAssist = 1 << 15 -FlagsFsdMassLocked = 1 << 16 -FlagsFsdCharging = 1 << 17 -FlagsFsdCooldown = 1 << 18 -FlagsLowFuel = 1 << 19 # <25% -FlagsOverHeating = 1 << 20 # > 100% -FlagsHasLatLong = 1 << 21 -FlagsIsInDanger = 1 << 22 -FlagsBeingInterdicted = 1 << 23 -FlagsInMainShip = 1 << 24 -FlagsInFighter = 1 << 25 -FlagsInSRV = 1 << 26 -FlagsAnalysisMode = 1 << 27 # Hud in Analysis mode -FlagsNightVision = 1 << 28 -FlagsAverageAltitude = 1 << 29 # Altitude from Average radius -FlagsFsdJump = 1 << 30 -FlagsSrvHighBeam = 1 << 31 - -# Dashboard GuiFocus constants -GuiFocusNoFocus = 0 -GuiFocusInternalPanel = 1 # right hand side -GuiFocusExternalPanel = 2 # left hand side -GuiFocusCommsPanel = 3 # top -GuiFocusRolePanel = 4 # bottom -GuiFocusStationServices = 5 -GuiFocusGalaxyMap = 6 -GuiFocusSystemMap = 7 -GuiFocusOrrery = 8 -GuiFocusFSS = 9 -GuiFocusSAA = 10 -GuiFocusCodex = 11 - - # List of loaded Plugins PLUGINS = [] PLUGINS_not_py3 = [] From a80635fb46c654f665682e14e3e70a745e7c87d9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 11:19:49 +0100 Subject: [PATCH 495/727] td.py: Add comment about *not* moving some constants to data.py --- td.py | 1 + 1 file changed, 1 insertion(+) diff --git a/td.py b/td.py index f38a828f..0476703c 100644 --- a/td.py +++ b/td.py @@ -11,6 +11,7 @@ import time from config import applongname, appversion, config +# These are specific to Trade Dangerous, so don't move to data.py demandbracketmap = { 0: '?', 1: 'L', 2: 'M', From ad8c63c64cdbf2a9eeace841da45c5809a64eb32 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 11:40:17 +0100 Subject: [PATCH 496/727] Move util_ships.py ship_map to data.py ship_name_map Also refactors data.py to edmc_data.py as I'm having weird issues with PyCharm debugger not starting, and this seems to be to do with module name clashes. --- EDMarketConnector.py | 6 ++--- collate.py | 7 +++--- commodity.py | 2 +- companion.py | 2 +- coriolis.py | 15 ++++-------- data.py => edmc_data.py | 47 +++++++++++++++++++++++++++++++++++++ edshipyard.py | 21 ++++++++++------- outfitting.py | 45 +++++++++++++++++------------------ shipyard.py | 4 ++-- stats.py | 8 +++---- td.py | 2 +- util_ships.py | 52 ++--------------------------------------- 12 files changed, 103 insertions(+), 108 deletions(-) rename data.py => edmc_data.py (88%) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 3bf232f2..5f4efc45 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -265,9 +265,9 @@ import plug import prefs import stats import td -import util_ships from commodity import COMMODITY_CSV from dashboard import dashboard +from edmc_data import ship_name_map from hotkey import hotkeymgr from l10n import Translations from monitor import monitor @@ -824,7 +824,7 @@ class AppWindow(object): self.dump_capi_data(data) if not monitor.state['ShipType']: # Started game in SRV or fighter - self.ship['text'] = util_ships.ship_map.get(data['ship']['name'].lower(), data['ship']['name']) + self.ship['text'] = ship_name_map.get(data['ship']['name'].lower(), data['ship']['name']) monitor.state['ShipID'] = data['ship']['id'] monitor.state['ShipType'] = data['ship']['name'].lower() @@ -928,7 +928,7 @@ class AppWindow(object): ship_text = monitor.state['ShipName'] else: - ship_text = util_ships.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) + ship_text = ship_name_map.get(monitor.state['ShipType'], monitor.state['ShipType']) if not ship_text: ship_text = '' diff --git a/collate.py b/collate.py index 10bb24b6..591f073b 100755 --- a/collate.py +++ b/collate.py @@ -11,9 +11,8 @@ from os.path import isfile from traceback import print_exc import companion -import data import outfitting -import util_ships +from edmc_data import ship_name_map def __make_backup(file_name: str, suffix: str = '.bak') -> None: @@ -108,7 +107,7 @@ def addmodules(data): raise ValueError('id: {} != {}'.format(key, module['id'])) try: - new = outfitting.lookup(module, util_ships.ship_map, True) + new = outfitting.lookup(module, ship_name_map, True) except Exception: print('{}, {}:'.format(module['id'], module['name'])) @@ -166,7 +165,7 @@ def addships(data): for ship in tuple(data_ships.get('shipyard_list', {}).values()) + data_ships.get('unavailable_list'): # sanity check key = int(ship['id']) - new = {'id': key, 'symbol': ship['name'], 'name': util_ships.ship_map.get(ship['name'].lower())} + new = {'id': key, 'symbol': ship['name'], 'name': ship_name_map.get(ship['name'].lower())} if new: old = ships.get(key) if old: diff --git a/commodity.py b/commodity.py index 5ad0830c..a3fd0fc4 100644 --- a/commodity.py +++ b/commodity.py @@ -6,7 +6,7 @@ import hashlib import time from config import config -from data import commodity_bracketmap as bracketmap +from edmc_data import commodity_bracketmap as bracketmap # DEFAULT means semi-colon separation diff --git a/companion.py b/companion.py index c8b3e015..da56a229 100644 --- a/companion.py +++ b/companion.py @@ -27,7 +27,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Union, cast import requests from config import appname, appversion, config -from data import companion_category_map as category_map +from edmc_data import companion_category_map as category_map from EDMCLogging import get_main_logger from monitor import monitor from protocol import protocolhandler diff --git a/coriolis.py b/coriolis.py index 36a61afe..a8493a9f 100755 --- a/coriolis.py +++ b/coriolis.py @@ -4,20 +4,15 @@ # import csv -import base64 -from collections import OrderedDict -import pickle import json +import pickle import subprocess import sys +from collections import OrderedDict from traceback import print_exc -from config import config import outfitting -import companion -import util_ships -from data import coriolis_ship_map - +from edmc_data import coriolis_ship_map, ship_name_map if __name__ == "__main__": @@ -32,7 +27,7 @@ if __name__ == "__main__": data = json.load(open('coriolis-data/dist/index.json')) # Symbolic name from in-game name - reverse_ship_map = {v: k for k, v in list(util_ships.ship_map.items())} + reverse_ship_map = {v: k for k, v in list(ship_name_map.items())} bulkheads = list(outfitting.armour_map.keys()) @@ -91,7 +86,7 @@ if __name__ == "__main__": reader = csv.DictReader(csvfile, restval='') for row in reader: try: - module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, util_ships.ship_map) + module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, ship_name_map) except: print(row['symbol']) print_exc() diff --git a/data.py b/edmc_data.py similarity index 88% rename from data.py rename to edmc_data.py index ef50c9a9..1d51d185 100644 --- a/data.py +++ b/edmc_data.py @@ -424,3 +424,50 @@ GuiFocusOrrery = 8 GuiFocusFSS = 9 GuiFocusSAA = 10 GuiFocusCodex = 11 + +ship_name_map = { + 'adder': 'Adder', + 'anaconda': 'Anaconda', + 'asp': 'Asp Explorer', + 'asp_scout': 'Asp Scout', + 'belugaliner': 'Beluga Liner', + 'cobramkiii': 'Cobra MkIII', + 'cobramkiv': 'Cobra MkIV', + 'clipper': 'Panther Clipper', + 'cutter': 'Imperial Cutter', + 'diamondback': 'Diamondback Scout', + 'diamondbackxl': 'Diamondback Explorer', + 'dolphin': 'Dolphin', + 'eagle': 'Eagle', + 'empire_courier': 'Imperial Courier', + 'empire_eagle': 'Imperial Eagle', + 'empire_fighter': 'Imperial Fighter', + 'empire_trader': 'Imperial Clipper', + 'federation_corvette': 'Federal Corvette', + 'federation_dropship': 'Federal Dropship', + 'federation_dropship_mkii': 'Federal Assault Ship', + 'federation_gunship': 'Federal Gunship', + 'federation_fighter': 'F63 Condor', + 'ferdelance': 'Fer-de-Lance', + 'hauler': 'Hauler', + 'independant_trader': 'Keelback', + 'independent_fighter': 'Taipan Fighter', + 'krait_mkii': 'Krait MkII', + 'krait_light': 'Krait Phantom', + 'mamba': 'Mamba', + 'orca': 'Orca', + 'python': 'Python', + 'scout': 'Taipan Fighter', + 'sidewinder': 'Sidewinder', + 'testbuggy': 'Scarab', + 'type6': 'Type-6 Transporter', + 'type7': 'Type-7 Transporter', + 'type9': 'Type-9 Heavy', + 'type9_military': 'Type-10 Defender', + 'typex': 'Alliance Chieftain', + 'typex_2': 'Alliance Crusader', + 'typex_3': 'Alliance Challenger', + 'viper': 'Viper MkIII', + 'viper_mkiv': 'Viper MkIV', + 'vulture': 'Vulture', +} diff --git a/edshipyard.py b/edshipyard.py index 0f29f7b6..ad19d518 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -1,20 +1,23 @@ # Export ship loadout in E:D Shipyard plain text format -import pickle -from collections import defaultdict import os -from os.path import join +import pickle import re import time +from collections import defaultdict +from os.path import join +from typing import Dict, List, Union -from config import config -from data import edshipyard_slot_map as slot_map import outfitting import util_ships +from config import config +from edmc_data import edshipyard_slot_map as slot_map +from edmc_data import ship_name_map -from typing import Dict, Union, List __Module = Dict[str, Union[str, List[str]]] +# Map API ship names to ED Shipyard names +ship_map = ship_name_map.copy() # Ship masses # TODO: prefer something other than pickle for this storage (dev readability, security) @@ -142,11 +145,11 @@ def export(data, filename=None): string += '---\nCargo : {} T\nFuel : {} T\n'.format(cargo, fuel) # Add mass and range - assert data['ship']['name'].lower() in util_ships.ship_map, data['ship']['name'] - assert util_ships.ship_map[data['ship']['name'].lower()] in ships, util_ships.ship_map[data['ship']['name'].lower()] + assert data['ship']['name'].lower() in ship_name_map, data['ship']['name'] + assert ship_name_map[data['ship']['name'].lower()] in ships, ship_name_map[data['ship']['name'].lower()] try: - mass += ships[util_ships.ship_map[data['ship']['name'].lower()]]['hullMass'] + mass += ships[ship_name_map[data['ship']['name'].lower()]]['hullMass'] string += 'Mass : {:.2f} T empty\n {:.2f} T full\n'.format(mass, mass + fuel + cargo) multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 / fsd['fuelpower']) * fsd['optmass'] diff --git a/outfitting.py b/outfitting.py index 714f5c06..eb60f4b1 100644 --- a/outfitting.py +++ b/outfitting.py @@ -1,28 +1,27 @@ -from collections import OrderedDict import pickle -from os.path import join import time +from collections import OrderedDict +from os.path import join -import util_ships from config import config -from data import outfitting_armour_map as armour_map -from data import outfitting_weapon_map as weapon_map -from data import outfitting_missiletype_map as missiletype_map -from data import outfitting_weaponmount_map as weaponmount_map -from data import outfitting_weaponclass_map as weaponclass_map -from data import outfitting_weaponrating_map as weaponrating_map -from data import outfitting_weaponoldvariant_map as weaponoldvariant_map -from data import outfitting_countermeasure_map as countermeasure_map -from data import outfitting_utility_map as utility_map -from data import outfitting_cabin_map as cabin_map -from data import outfitting_rating_map as rating_map -from data import outfitting_corrosion_rating_map as corrosion_rating_map -from data import outfitting_planet_rating_map as planet_rating_map -from data import outfitting_fighter_rating_map as fighter_rating_map -from data import outfitting_misc_internal_map as misc_internal_map -from data import outfitting_standard_map as standard_map -from data import outfitting_internal_map as internal_map - +from edmc_data import outfitting_armour_map as armour_map +from edmc_data import outfitting_cabin_map as cabin_map +from edmc_data import outfitting_corrosion_rating_map as corrosion_rating_map +from edmc_data import outfitting_countermeasure_map as countermeasure_map +from edmc_data import outfitting_fighter_rating_map as fighter_rating_map +from edmc_data import outfitting_internal_map as internal_map +from edmc_data import outfitting_misc_internal_map as misc_internal_map +from edmc_data import outfitting_missiletype_map as missiletype_map +from edmc_data import outfitting_planet_rating_map as planet_rating_map +from edmc_data import outfitting_rating_map as rating_map +from edmc_data import outfitting_standard_map as standard_map +from edmc_data import outfitting_utility_map as utility_map +from edmc_data import outfitting_weapon_map as weapon_map +from edmc_data import outfitting_weaponclass_map as weaponclass_map +from edmc_data import outfitting_weaponmount_map as weaponmount_map +from edmc_data import outfitting_weaponoldvariant_map as weaponoldvariant_map +from edmc_data import outfitting_weaponrating_map as weaponrating_map +from edmc_data import ship_name_map # Module mass, FSD data etc moduledata = OrderedDict() @@ -30,7 +29,7 @@ moduledata = OrderedDict() # Given a module description from the Companion API returns a description of the module in the form of a # dict { category, name, [mount], [guidance], [ship], rating, class } using the same terms found in the # English langauge game. For fitted modules, dict also includes { enabled, priority }. -# ship_map tells us what ship names to use for Armour - i.e. EDDN schema names or in-game names. +# ship_name_map tells us what ship names to use for Armour - i.e. EDDN schema names or in-game names. # # Returns None if the module is user-specific (i.e. decal, paintjob, kit) or PP-specific in station outfitting. # (Given the ad-hocery in this implementation a big lookup table might have been simpler and clearer). @@ -209,7 +208,7 @@ def export(data, filename): h.write(header) for v in list(data['lastStarport'].get('modules', {}).values()): try: - m = lookup(v, util_ships.ship_map) + m = lookup(v, ship_name_map) if m: h.write('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n' % (rowheader, m['category'], m['name'], m.get('mount',''), m.get('guidance',''), m.get('ship',''), m['class'], m['rating'], m['id'], data['timestamp'])) except AssertionError as e: diff --git a/shipyard.py b/shipyard.py index 2a8edfdd..78961ad7 100644 --- a/shipyard.py +++ b/shipyard.py @@ -3,7 +3,7 @@ import time from config import config -from util_ships import ship_map +from edmc_data import ship_name_map def export(data, filename): @@ -19,6 +19,6 @@ def export(data, filename): h = open(filename, 'wt') h.write(header) - for (name,fdevid) in [(ship_map.get(ship['name'].lower(), ship['name']), ship['id']) for ship in list((data['lastStarport']['ships'].get('shipyard_list') or {}).values()) + data['lastStarport']['ships'].get('unavailable_list')]: + for (name,fdevid) in [(ship_name_map.get(ship['name'].lower(), ship['name']), ship['id']) for ship in list((data['lastStarport']['ships'].get('shipyard_list') or {}).values()) + data['lastStarport']['ships'].get('unavailable_list')]: h.write('%s,%s,%s,%s\n' % (rowheader, name, fdevid, data['timestamp'])) h.close() diff --git a/stats.py b/stats.py index baf5894a..fcd514cc 100644 --- a/stats.py +++ b/stats.py @@ -8,9 +8,9 @@ from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, NamedTuple, Optional, import companion import EDMCLogging import myNotebook as nb # noqa: N813 +from edmc_data import ship_name_map from l10n import Locale from monitor import monitor -from util_ships import ship_map logger = EDMCLogging.get_main_logger() @@ -216,7 +216,7 @@ def ships(companion_data: Dict[str, Any]) -> List[ShipRet]: # Set current system, not last docked out.append(ShipRet( id=str(ships[0]['id']), - type=ship_map.get(ships[0]['name'].lower(), ships[0]['name']), + type=ship_name_map.get(ships[0]['name'].lower(), ships[0]['name']), name=str(ships[0].get('shipName', '')), system=companion_data['lastSystem']['name'], station='', @@ -225,7 +225,7 @@ def ships(companion_data: Dict[str, Any]) -> List[ShipRet]: out.extend( ShipRet( id=str(ship['id']), - type=ship_map.get(ship['name'].lower(), ship['name']), + type=ship_name_map.get(ship['name'].lower(), ship['name']), name=ship.get('shipName', ''), system=ship['starsystem']['name'], station=ship['station']['name'], @@ -238,7 +238,7 @@ def ships(companion_data: Dict[str, Any]) -> List[ShipRet]: return [ ShipRet( id=str(ship['id']), - type=ship_map.get(ship['name'].lower(), ship['name']), + type=ship_name_map.get(ship['name'].lower(), ship['name']), name=ship.get('shipName', ''), system=ship['starsystem']['name'], station=ship['station']['name'], diff --git a/td.py b/td.py index 0476703c..13c32edd 100644 --- a/td.py +++ b/td.py @@ -11,7 +11,7 @@ import time from config import applongname, appversion, config -# These are specific to Trade Dangerous, so don't move to data.py +# These are specific to Trade Dangerous, so don't move to edmc_data.py demandbracketmap = { 0: '?', 1: 'L', 2: 'M', diff --git a/util_ships.py b/util_ships.py index 9aad1cc4..204e21f5 100644 --- a/util_ships.py +++ b/util_ships.py @@ -1,57 +1,9 @@ """Utility functions relating to ships.""" - - -ship_map = { - 'adder': 'Adder', - 'anaconda': 'Anaconda', - 'asp': 'Asp Explorer', - 'asp_scout': 'Asp Scout', - 'belugaliner': 'Beluga Liner', - 'cobramkiii': 'Cobra MkIII', - 'cobramkiv': 'Cobra MkIV', - 'clipper': 'Panther Clipper', - 'cutter': 'Imperial Cutter', - 'diamondback': 'Diamondback Scout', - 'diamondbackxl': 'Diamondback Explorer', - 'dolphin': 'Dolphin', - 'eagle': 'Eagle', - 'empire_courier': 'Imperial Courier', - 'empire_eagle': 'Imperial Eagle', - 'empire_fighter': 'Imperial Fighter', - 'empire_trader': 'Imperial Clipper', - 'federation_corvette': 'Federal Corvette', - 'federation_dropship': 'Federal Dropship', - 'federation_dropship_mkii': 'Federal Assault Ship', - 'federation_gunship': 'Federal Gunship', - 'federation_fighter': 'F63 Condor', - 'ferdelance': 'Fer-de-Lance', - 'hauler': 'Hauler', - 'independant_trader': 'Keelback', - 'independent_fighter': 'Taipan Fighter', - 'krait_mkii': 'Krait MkII', - 'krait_light': 'Krait Phantom', - 'mamba': 'Mamba', - 'orca': 'Orca', - 'python': 'Python', - 'scout': 'Taipan Fighter', - 'sidewinder': 'Sidewinder', - 'testbuggy': 'Scarab', - 'type6': 'Type-6 Transporter', - 'type7': 'Type-7 Transporter', - 'type9': 'Type-9 Heavy', - 'type9_military': 'Type-10 Defender', - 'typex': 'Alliance Chieftain', - 'typex_2': 'Alliance Crusader', - 'typex_3': 'Alliance Challenger', - 'viper': 'Viper MkIII', - 'viper_mkiv': 'Viper MkIV', - 'vulture': 'Vulture', -} - +from edmc_data import ship_name_map def ship_file_name(ship_name: str, ship_type: str) -> str: """Return a ship name suitable for a filename.""" - name = str(ship_name or ship_map.get(ship_type.lower(), ship_type)).strip() + name = str(ship_name or ship_name_map.get(ship_type.lower(), ship_type)).strip() if name.endswith('.'): name = name[:-2] From 5c5e5b507e55ed2a2bd810ebcec6064ef06cb0f6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 12:39:01 +0100 Subject: [PATCH 497/727] monitor.py: Fix up legavy config.get() calls --- monitor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 6ae6b372..ab205b9d 100644 --- a/monitor.py +++ b/monitor.py @@ -1157,14 +1157,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below oldfiles = sorted((x for x in listdir(config.get_str('outdir')) if regexp.match(x))) # type: ignore if oldfiles: try: - with open(join(config.get('outdir'), oldfiles[-1]), 'r', encoding='utf-8') as h: # type: ignore + with open(join(config.get_str('outdir'), oldfiles[-1]), 'r', encoding='utf-8') as h: # type: ignore if h.read() == string: return # same as last time - don't write except UnicodeError: logger.exception("UnicodeError reading old ship loadout with utf-8 encoding, trying without...") try: - with open(join(config.get('outdir'), oldfiles[-1]), 'r') as h: # type: ignore + with open(join(config.get_str('outdir'), oldfiles[-1]), 'r') as h: # type: ignore if h.read() == string: return # same as last time - don't write From 32d87f68dd9ddce365accd714f02928b5b556054 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 12:47:17 +0100 Subject: [PATCH 498/727] collate.py: Fix references to companion_category_map --- collate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/collate.py b/collate.py index 591f073b..9e05458d 100755 --- a/collate.py +++ b/collate.py @@ -12,7 +12,7 @@ from traceback import print_exc import companion import outfitting -from edmc_data import ship_name_map +from edmc_data import companion_category_map, ship_name_map def __make_backup(file_name: str, suffix: str = '.bak') -> None: @@ -54,13 +54,13 @@ def addcommodities(data): new = { 'id' : commodity['id'], 'symbol' : commodity['name'], - 'category' : data.companion_category_map.get(commodity['categoryname']) or commodity['categoryname'], + 'category' : companion_category_map.get(commodity['categoryname']) or commodity['categoryname'], 'name' : commodity.get('locName') or 'Limpets', } old = commodities.get(key) - if old and data.companion_category_map.get(commodity['categoryname'], True): + if old and companion_category_map.get(commodity['categoryname'], True): if new['symbol'] != old['symbol'] or new['name'] != old['name']: raise ValueError('{}: {!r} != {!r}'.format(key, new, old)) From dbfa50739f6c98d58c11ee704a9e30f23720f2dc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 12:54:38 +0100 Subject: [PATCH 499/727] collate.py: Use always '\n` line-ending on commodity file --- collate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collate.py b/collate.py index 9e05458d..7255dc1f 100755 --- a/collate.py +++ b/collate.py @@ -72,7 +72,7 @@ def addcommodities(data): if isfile(commodityfile): __make_backup(commodityfile) - with open(commodityfile, 'w') as csvfile: + with open(commodityfile, 'w', newline='\n') as csvfile: writer = csv.DictWriter(csvfile, ['id', 'symbol', 'category', 'name']) writer.writeheader() From c17e6ecade35cdeb3b52c20a16900c3de875f8b5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 12:57:17 +0100 Subject: [PATCH 500/727] collate.py: Also newline='\n' on other open-for-write --- collate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collate.py b/collate.py index 7255dc1f..b7192b4e 100755 --- a/collate.py +++ b/collate.py @@ -133,7 +133,7 @@ def addmodules(data): if isfile(outfile): __make_backup(outfile) - with open(outfile, 'w') as csvfile: + with open(outfile, 'w', newline='\n') as csvfile: writer = csv.DictWriter(csvfile, fields, extrasaction='ignore') writer.writeheader() @@ -186,7 +186,7 @@ def addships(data): if isfile(shipfile): __make_backup(shipfile) - with open(shipfile, 'w') as csvfile: + with open(shipfile, 'w', newline='\n') as csvfile: writer = csv.DictWriter(csvfile, ['id', 'symbol', 'name']) writer.writeheader() From 33f0064dab15adf4b56ebd8e82a7fdfd3e51c33a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 13:27:54 +0100 Subject: [PATCH 501/727] Document edmc_data.py * PLUGINS.md - now we only need mention this for such data. * ChangeLog.md - pre-emptive section. --- ChangeLog.md | 11 +++++++++++ PLUGINS.md | 12 ++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index d6aba4ad..c1a3b0c5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,17 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- +Pre-Release 5.0.0-beta4 +=== + +Plugin Developers +--- + +* All of our static data, such as mappings of names, should now be in + edmc_data.py. So adjust any imports accordingly. Any future such will + be placed in this file. We will endeavour not to make breaking changes to + this file without a Major version bump. + Pre-Release 5.0.0-beta3 === diff --git a/PLUGINS.md b/PLUGINS.md index 503a60fa..23016a2b 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -60,15 +60,11 @@ breaking with future code changes.** `from prefs import prefsVersion` - to allow for versioned preferences. -`from companion import category_map` - Or any of the other static data -contained therein. NB: There's a plan to move such to a `data` module. +`import edmc_data` (or specific 'from' imports) - This contains various static +data that used to be in other files. You should **not** now import anything +from the original files unless specified as allowed in this section. -`from util_ships import ship_map` - A mapping of symbolic to English -readable names for ships. - -`import plug` - For using `plug.show_error()` and accessing the flags -for `dashboard_entry()` to be useful (see example below). Relying on anything -else isn't supported. +`import plug` - For using `plug.show_error()` only. `from monitor import game_running` - in case a plugin needs to know if we think the game is running. *NB: This is a function, and should be called as From bc6557dd9c6d13f69688f05273cdc159e72436f6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 13:21:42 +0100 Subject: [PATCH 502/727] Quieten various TRACE log output. * A lot of this is commented out. It might be useful in the future, but is just too noisy for now. * Changed the protocol webserver to info, as it is. * Left the EDSM 'not 1XX, 2XX or 5XX' in as it's a warning, so 'pass's on the conditional bodies that would be empty now trace's are commented. --- companion.py | 2 +- plug.py | 4 +-- plugins/edsm.py | 76 +++++++++++++++++++++++++------------------------ protocol.py | 2 +- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/companion.py b/companion.py index da56a229..3eee5d2f 100644 --- a/companion.py +++ b/companion.py @@ -535,7 +535,7 @@ class Session(object): self.retrying = False if 'timestamp' not in data: - logger.trace('timestamp not in data, adding from response headers') + # logger.trace('timestamp not in data, adding from response headers') data['timestamp'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', parsedate(r.headers['Date'])) # type: ignore return data diff --git a/plug.py b/plug.py index 1ca11072..eea96ea7 100644 --- a/plug.py +++ b/plug.py @@ -258,8 +258,8 @@ def notify_journal_entry(cmdr, is_beta, system, station, entry, state): :param is_beta: whether the player is in a Beta universe. :returns: Error message from the first plugin that returns one (if any) """ - if entry['event'] in ('Location'): - logger.trace('Notifying plugins of "Location" event') + # if entry['event'] in ('Location'): + # logger.trace('Notifying plugins of "Location" event') error = None for plugin in PLUGINS: diff --git a/plugins/edsm.py b/plugins/edsm.py index 2ca2f62d..0f6ed269 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -351,14 +351,14 @@ def journal_entry( return this.on_foot = state['OnFoot'] - if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): - logger.trace(f'''{entry["event"]} -Commander: {cmdr} -System: {system} -Station: {station} -state: {state!r} -entry: {entry!r}''' - ) + # if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): + # logger.trace(f'''{entry["event"]} +# Commander: {cmdr} +# System: {system} +# Station: {station} +# state: {state!r} +# entry: {entry!r}''' +# ) # Always update our system address even if we're not currently the provider for system or station, but dont update # on events that contain "future" data, such as FSDTarget if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'): @@ -453,10 +453,10 @@ entry: {entry!r}''' materials.update(transient) this.queue.put((cmdr, materials)) - if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): - logger.trace(f'''{entry["event"]} -Queueing: {entry!r}''' - ) + # if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): + # logger.trace(f'''{entry["event"]} +# Queueing: {entry!r}''' +# ) this.queue.put((cmdr, entry)) @@ -561,14 +561,14 @@ def worker() -> None: pending = list(filter(lambda x: x['event'] not in this.discardedEvents, pending)) if should_send(pending): - if any(p for p in pending if p['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked')): - logger.trace("pending has at least one of " - "('CarrierJump', 'FSDJump', 'Location', 'Docked')" - " and it passed should_send()") - for p in pending: - if p['event'] in ('Location'): - logger.trace('"Location" event in pending passed should_send(), ' - f'timestamp: {p["timestamp"]}') + # if any(p for p in pending if p['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked')): + # logger.trace("pending has at least one of " + # "('CarrierJump', 'FSDJump', 'Location', 'Docked')" + # " and it passed should_send()") + # for p in pending: + # if p['event'] in ('Location'): + # logger.trace('"Location" event in pending passed should_send(), ' + # f'timestamp: {p["timestamp"]}') creds = credentials(cmdr) # TODO: possibly unbound if creds is None: @@ -583,25 +583,25 @@ def worker() -> None: 'message': json.dumps(pending, ensure_ascii=False).encode('utf-8'), } - if any(p for p in pending if p['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked')): - data_elided = data.copy() - data_elided['apiKey'] = '' - logger.trace( - "pending has at least one of " - "('CarrierJump', 'FSDJump', 'Location', 'Docked')" - " Attempting API call with the following events:" - ) + # if any(p for p in pending if p['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked')): + # data_elided = data.copy() + # data_elided['apiKey'] = '' + # logger.trace( + # "pending has at least one of " + # "('CarrierJump', 'FSDJump', 'Location', 'Docked')" + # " Attempting API call with the following events:" + # ) - for p in pending: - logger.trace(f"Event: {p!r}") - if p['event'] in ('Location'): - logger.trace('Attempting API call for "Location" event with timestamp: ' - f'{p["timestamp"]}') + # for p in pending: + # logger.trace(f"Event: {p!r}") + # if p['event'] in ('Location'): + # logger.trace('Attempting API call for "Location" event with timestamp: ' + # f'{p["timestamp"]}') - logger.trace(f'Overall POST data (elided) is:\n{data_elided}') + # logger.trace(f'Overall POST data (elided) is:\n{data_elided}') r = this.session.post('https://www.edsm.net/api-journal-v1', data=data, timeout=_TIMEOUT) - logger.trace(f'API response content: {r.content}') + # logger.trace(f'API response content: {r.content}') r.raise_for_status() reply = r.json() msg_num = reply['msgnum'] @@ -618,10 +618,12 @@ def worker() -> None: else: if msg_num // 100 == 1: - logger.trace('Overall OK') + # logger.trace('Overall OK') + pass elif msg_num // 100 == 5: - logger.trace('Event(s) not currently processed, but saved for later') + # logger.trace('Event(s) not currently processed, but saved for later') + pass else: logger.warning(f'EDSM API call status not 1XX, 2XX or 5XX: {msg.num}') diff --git a/protocol.py b/protocol.py index 8afba1b3..471876b1 100644 --- a/protocol.py +++ b/protocol.py @@ -336,7 +336,7 @@ else: # Linux / Run from source super().__init__() self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler) self.redirect = f'http://localhost:{self.httpd.server_port}/auth' - logger.trace(f'Web server listening on {self.redirect}') + logger.info(f'Web server listening on {self.redirect}') self.thread: Optional[threading.Thread] = None def start(self, master) -> None: From 72d200f6167a79e762114f5e29f81ac5b9bb3f57 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Apr 2021 22:43:04 +0100 Subject: [PATCH 503/727] Detect when on-foot but no known station. This will trigger the "Where are you?!" message, which now can happen. I need to double-check this against live behaviour, and might move this to a different check, as I think on live it's valid to query in-space. --- EDMarketConnector.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 5f4efc45..44ff28f2 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -779,8 +779,9 @@ class AppWindow(object): self.status['text'] = _("Who are you?!") # Shouldn't happen elif (not data.get('lastSystem', {}).get('name') - or (data['commander'].get('docked') - and not data.get('lastStarport', {}).get('name'))): # Only care if docked + or (data['commander'].get('docked') or monitor.state['OnFoot'] + and not data.get('lastStarport', {}).get('name')) + or (monitor.state['OnFoot'] and data['lastStarport']['name'] != monitor.station)): self.status['text'] = _("Where are you?!") # Shouldn't happen elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'): From 5c99ef1243f5307f29e896039f8b1f69d40743a7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 4 Apr 2021 09:34:37 +0100 Subject: [PATCH 504/727] Fix CAPI update properly for on-foot/embarking. * Stop relying on self.status['text'] as indicator, set and use `err`. --- EDMarketConnector.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 44ff28f2..8c17945d 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -741,6 +741,7 @@ class AppWindow(object): auto_update = not event play_sound = (auto_update or int(event.type) == self.EVENT_VIRTUAL) and not config.get_int('hotkey_mute') play_bad = False + err: Optional[str] = None if not monitor.cmdr or not monitor.mode or monitor.state['Captain'] or not monitor.system: return # In CQC or on crew - do nothing @@ -773,19 +774,18 @@ class AppWindow(object): # Validation if 'commander' not in data: # This can happen with EGS Auth if no commander created yet - self.status['text'] = _('CAPI: No commander data returned') + err = self.status['text'] = _('CAPI: No commander data returned') elif not data.get('commander', {}).get('name'): - self.status['text'] = _("Who are you?!") # Shouldn't happen + err = self.status['text'] = _("Who are you?!") # Shouldn't happen elif (not data.get('lastSystem', {}).get('name') or (data['commander'].get('docked') or monitor.state['OnFoot'] - and not data.get('lastStarport', {}).get('name')) - or (monitor.state['OnFoot'] and data['lastStarport']['name'] != monitor.station)): - self.status['text'] = _("Where are you?!") # Shouldn't happen + and not data.get('lastStarport', {}).get('name'))): + err = self.status['text'] = _("Where are you?!") # Shouldn't happen elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'): - self.status['text'] = _("What are you flying?!") # Shouldn't happen + err = self.status['text'] = _("What are you flying?!") # Shouldn't happen elif monitor.cmdr and data['commander']['name'] != monitor.cmdr: # Companion API Commander doesn't match Journal @@ -812,6 +812,8 @@ class AppWindow(object): # CAPI lastStarport must match raise companion.ServerLagging() + self.holdofftime = querytime + companion.holdoff + elif not monitor.state['OnFoot'] and data['ship']['id'] != monitor.state['ShipID']: # CAPI ship must match raise companion.ServerLagging() @@ -841,14 +843,16 @@ class AppWindow(object): # Export market data if not self.export_market_data(data): + err = 'Error: Exporting Market data' play_bad = True self.holdofftime = querytime + companion.holdoff # Companion API problem except companion.ServerLagging as e: + err = str(e) if retrying: - self.status['text'] = str(e) + self.status['text'] = err play_bad = True else: @@ -857,17 +861,17 @@ class AppWindow(object): return # early exit to avoid starting cooldown count except companion.CmdrError as e: # Companion API return doesn't match Journal - self.status['text'] = str(e) + err = self.status['text'] = str(e) play_bad = True companion.session.invalidate() self.login() except Exception as e: # Including CredentialsError, ServerError logger.debug('"other" exception', exc_info=e) - self.status['text'] = str(e) + err = self.status['text'] = str(e) play_bad = True - if not self.status['text']: # no errors + if not err: # not self.status['text']: # no errors self.status['text'] = strftime(_('Last updated at %H:%M:%S'), localtime(querytime)) if play_sound and play_bad: From 88a3f6d73af229a2cc697f7b7d496c47fe482b89 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 4 Apr 2021 11:02:53 +0100 Subject: [PATCH 505/727] Remove erroneous on-foot check for 'Where are you?!' This causes the check to not work as intended on live and is a left-over from before fixing the code to just use 'err'. --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 8c17945d..39d6fc0e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -780,7 +780,7 @@ class AppWindow(object): err = self.status['text'] = _("Who are you?!") # Shouldn't happen elif (not data.get('lastSystem', {}).get('name') - or (data['commander'].get('docked') or monitor.state['OnFoot'] + or (data['commander'].get('docked') and not data.get('lastStarport', {}).get('name'))): err = self.status['text'] = _("Where are you?!") # Shouldn't happen From 27961c1513fe399a0ac64e93e5c2361fc7b12816 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 4 Apr 2021 11:46:46 +0100 Subject: [PATCH 506/727] AppWindow.getandsend: Only blank status text when we play the bad sound AppWindow.getandsend() is set on a timer for all of StartUp, Location and Docked. This means it can trigger up to three times for a login when docked. Subsequent calls would hit the cooldown timer and blank the status text blindly, hiding the 'Last Updated at' text. To be honest I'm not sure it even needs blanking *then*. --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 39d6fc0e..e3312ed1 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -753,8 +753,8 @@ class AppWindow(object): if not retrying: if time() < self.holdofftime: # Was invoked by key while in cooldown - self.status['text'] = '' if play_sound and (self.holdofftime - time()) < companion.holdoff * 0.75: + self.status['text'] = '' hotkeymgr.play_bad() # Don't play sound in first few seconds to prevent repeats return From 30db492212a99c66a957ff051fc54dffcefc7262 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 4 Apr 2021 21:45:05 +0100 Subject: [PATCH 507/727] Bump to Python 3.9.4 I can PyCharm debug with this, unlike 3.9.3 :) --- .github/workflows/windows-build.yml | 2 +- .python-version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 7a62de8e..8cc9297c 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: "3.9.3" + python-version: "3.9.4" architecture: "x86" - name: Install python tools diff --git a/.python-version b/.python-version index 820476af..e0d61b5b 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.9.3 +3.9.4 From 874b688c0959a056a5a649c26d0e9aa9dd4828c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Apr 2021 07:01:59 +0000 Subject: [PATCH 508/727] build(deps-dev): bump pytest from 6.2.2 to 6.2.3 Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.2 to 6.2.3. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.2.2...6.2.3) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index b876d56a..6e7338e5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -30,7 +30,7 @@ grip==4.5.2 py2exe==0.10.3.1; sys_platform == 'win32' # Testing -pytest==6.2.2 +pytest==6.2.3 pytest-cov==2.11.1 # Pytest code coverage support coverage[toml]==5.5 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs # For manipulating folder permissions and the like. From b66d599508e4db8eece883787c313f0e066a8ace Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 12:42:39 +0100 Subject: [PATCH 509/727] Pre-Release 5.0.0-beta4: appversion and changelog --- ChangeLog.md | 38 ++++++++++++++++++++++++++++++++++---- config.py | 2 +- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c1a3b0c5..78ff66bb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,13 +4,43 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are Pre-Release 5.0.0-beta4 === +* Now using Python 3.9.4. + +* Some initial support for things new in Odyssey has been added. We can + detect when you're on-foot and at a station, so as to leverage Frontier + CAPI to send data about the station to EDDN etc. + + **NB: Due to shortcomings in Journal support we can only detect your + 'station' location on orbital stations, and only when you first login + there, not for subsequent Disembarking at one, and not at all for surface + ports, let alone surface settlements.** + + More support, for things like the 'ShipLocker' inventory of all the new + materials, will be added in a subsequent beta. + +* A little TRACE logging output has been commented out for now. + Plugin Developers --- -* All of our static data, such as mappings of names, should now be in - edmc_data.py. So adjust any imports accordingly. Any future such will - be placed in this file. We will endeavour not to make breaking changes to - this file without a Major version bump. +* All static data that is cleared for use by plugins is now in the file + `edmc_data.py` and should be imported from there, not *any* other module. + + The one thing we didn't move was the 'bracket map' dictionaries in td.py + as they're for use only by the code in that file. + + All future such data will be added to this file, and we'll endeavour not + to make breaking changes to any of it without increasing our Major version. + +* We now change the current working directory of EDMarketConnector.exe to + its location as soon as possible in its execution. We're also now more + paranoid about ensuring we reference the full path to the `.gitversion` file. + + However, no plugin should itself call `os.chdir(...)` or equivalent. You'll + change the current working directory for all core code and other plugins as + well (it's global to the whole **process**, not per-thread). Use full + absolute paths instead (`pathlib` is what to use for this) + Pre-Release 5.0.0-beta3 === diff --git a/config.py b/config.py index 16528fae..d793267c 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta3' +_static_appversion = '5.0.0-beta4' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From c4df5b28228f176a7561f912945b402af78c5625 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 09:14:31 +0100 Subject: [PATCH 510/727] DRY init of self.state It's identical in both places, so use a common function. --- monitor.py | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/monitor.py b/monitor.py index ab205b9d..3967ff03 100644 --- a/monitor.py +++ b/monitor.py @@ -107,6 +107,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.systemaddress: Optional[int] = None self.started: Optional[int] = None # Timestamp of the LoadGame event + self.__init_state() + + def __init_state(self) -> None: # Cmdr state shared with EDSM and plugins # If you change anything here update PLUGINS.md documentation! self.state: Dict = { @@ -476,34 +479,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.coordinates = None self.systemaddress = None self.started = None - self.state = { - 'Captain': None, - 'Cargo': defaultdict(int), - 'Credits': None, - 'FID': None, - 'Horizons': None, - 'Loan': None, - 'Raw': defaultdict(int), - 'Manufactured': defaultdict(int), - 'Encoded': defaultdict(int), - 'Component': defaultdict(int), - 'Engineers': {}, - 'Rank': {}, - 'Reputation': {}, - 'Statistics': {}, - 'Role': None, - 'Friends': set(), - 'ShipID': None, - 'ShipIdent': None, - 'ShipName': None, - 'ShipType': None, - 'HullValue': None, - 'ModulesValue': None, - 'Rebuy': None, - 'Modules': None, - 'Route': None, - } - self.state['OnFoot'] = False + self.__init_state() elif event_type == 'Commander': self.live = True # First event in 3.0 From ad677d73f6d2837438d99e39c1e999e40c9a90f3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 09:18:26 +0100 Subject: [PATCH 511/727] monitor.state: Group all Odyssey, and add other ShipLocker categories --- monitor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 3967ff03..ccbc7bfb 100644 --- a/monitor.py +++ b/monitor.py @@ -122,7 +122,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Raw': defaultdict(int), 'Manufactured': defaultdict(int), 'Encoded': defaultdict(int), - 'Component': defaultdict(int), # Odyssey materials 'Engineers': {}, 'Rank': {}, 'Reputation': {}, @@ -139,7 +138,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Modules': None, 'CargoJSON': None, # The raw data from the last time cargo.json was read 'Route': None, # Last plotted route from Route.json file - 'OnFoot': False, # Whether we think you're on-foot + 'OnFoot': False, # Whether we think you're on-foot + 'Component': defaultdict(int), # Odyssey Components in Ship Locker + 'Items': defaultdict(int), # Odyssey Items in Ship Locker + 'Consumables': defaultdict(int), # Odyssey Consumables in Ship Locker } def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 From 7040975bd27ed13b0838ec272d14993ff76f7ea4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 09:41:09 +0100 Subject: [PATCH 512/727] Add support for 'ShipLockerMaterials' --- monitor.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/monitor.py b/monitor.py index ccbc7bfb..9a7e3932 100644 --- a/monitor.py +++ b/monitor.py @@ -707,6 +707,21 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean}) + elif event_type == 'ShipLockerMaterials': + # This event has the current totals, so drop any current data + self.state['Component'] = defaultdict(int) + self.state['Consumable'] = defaultdict(int) + self.state['Item'] = defaultdict(int) + + clean_components = self.coalesce_cargo(entry['Components']) + self.state['Component'].update({self.canonicalise(x['Name']): x['Count'] for x in clean_components}) + + clean_consumables = self.coalesce_cargo(entry['Consumables']) + self.state['Consumable'].update({self.canonicalise(x['Name']): x['Count'] for x in clean_consumables}) + + clean_items = self.coalesce_cargo(entry['Items']) + self.state['Item'].update({self.canonicalise(x['Name']): x['Count'] for x in clean_items}) + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From 28c4fa03b15e9a26826aa57ee6e0fc7ebba25eeb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 11:02:30 +0100 Subject: [PATCH 513/727] Add support for BacKPackMaterials event It's unclear from my Journals if this is adding to the current or is the total state at the time. I think it's the latter, despite not finding where a '737844537' had come from (looks like from a mission, but that would be reward and should have gone straight to ShipLocker?). --- monitor.py | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/monitor.py b/monitor.py index 9a7e3932..b9b0ca9c 100644 --- a/monitor.py +++ b/monitor.py @@ -139,9 +139,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'CargoJSON': None, # The raw data from the last time cargo.json was read 'Route': None, # Last plotted route from Route.json file 'OnFoot': False, # Whether we think you're on-foot - 'Component': defaultdict(int), # Odyssey Components in Ship Locker - 'Items': defaultdict(int), # Odyssey Items in Ship Locker - 'Consumables': defaultdict(int), # Odyssey Consumables in Ship Locker + 'Component': defaultdict(int), # Odyssey Components in Ship Locker + 'Item': defaultdict(int), # Odyssey Items in Ship Locker + 'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker + 'BackPack': { # Odyssey BackPack contents + 'Component': defaultdict(int), # BackPack Components + 'Consumable': defaultdict(int), # BackPack Consumables + 'Item': defaultdict(int), # BackPack Items + }, } def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 @@ -714,13 +719,40 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Item'] = defaultdict(int) clean_components = self.coalesce_cargo(entry['Components']) - self.state['Component'].update({self.canonicalise(x['Name']): x['Count'] for x in clean_components}) + self.state['Component'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_components} + ) clean_consumables = self.coalesce_cargo(entry['Consumables']) - self.state['Consumable'].update({self.canonicalise(x['Name']): x['Count'] for x in clean_consumables}) + self.state['Consumable'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_consumables} + ) clean_items = self.coalesce_cargo(entry['Items']) - self.state['Item'].update({self.canonicalise(x['Name']): x['Count'] for x in clean_items}) + self.state['Item'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_items} + ) + + elif event_type == 'BackPackMaterials': + # Assume this reflects the current state when written + self.state['BackPack']['Component'] = defaultdict(int) + self.state['BackPack']['Consumable'] = defaultdict(int) + self.state['BackPack']['Item'] = defaultdict(int) + + clean_components = self.coalesce_cargo(entry['Components']) + self.state['BackPack']['Component'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_components} + ) + + clean_consumables = self.coalesce_cargo(entry['Consumables']) + self.state['BackPack']['Consumable'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_consumables} + ) + + clean_items = self.coalesce_cargo(entry['Items']) + self.state['BackPack']['Item'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_items} + ) elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json From a2c48fdd70386b056dd69be55bb4cdd8093d7633 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 11:08:53 +0100 Subject: [PATCH 514/727] Support for 'BuyMicroResources' event This is currently only when buying Consumables from a Pioneer Supplies vendor. One event per Item type, it's not an array. We're assuming these go into ShipLocker, not BackPack. --- monitor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/monitor.py b/monitor.py index b9b0ca9c..da994ed2 100644 --- a/monitor.py +++ b/monitor.py @@ -754,6 +754,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below {self.canonicalise(x['Name']): x['Count'] for x in clean_items} ) + elif event_type == 'BuyMicroResources': + # Buying from a Pioneer Supplies, goes directly to ShipLocker. + # One event per Item, not an array. + self.state[entry['Category']][entry['Name']] += entry['Count'] + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From c94ebad54c1fdca8aa3b2483f8321e77ab5c4a52 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 11:17:42 +0100 Subject: [PATCH 515/727] Support for event 'SellMicroResources' These are being sold to a Bar Tender. There's a MicroResources array, one per item name. We assume this is always selling from ShipLocker, not BackPack. --- monitor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index da994ed2..e343cece 100644 --- a/monitor.py +++ b/monitor.py @@ -757,7 +757,18 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'BuyMicroResources': # Buying from a Pioneer Supplies, goes directly to ShipLocker. # One event per Item, not an array. - self.state[entry['Category']][entry['Name']] += entry['Count'] + category = self.category(entry['Category']) + name = self.canonicalise(entry['Name']) + self.state[category][name] += entry['Count'] + + elif event_type == 'SellMicroResources': + # Selling to a Bar Tender on-foot. + # One event per whole sale, so it's an array. + for mr in entry['MicroResources']: + category = self.category(mr['Category']) + name = self.canonicalise(mr['Name']) + + self.state[category][name] -= mr['Count'] elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json From c5d2300ba588016a49f3dcd6076a26c4bff180e2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 11:22:39 +0100 Subject: [PATCH 516/727] Support for 'TradeMicroResources' event This has an array 'Offered' listing what was traded away. 'Category' & 'Received' is what you got in return, 'Count' many. Again, we assume this only interacts with ShipLocker, not BackPack. --- monitor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index e343cece..94585518 100644 --- a/monitor.py +++ b/monitor.py @@ -767,9 +767,21 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below for mr in entry['MicroResources']: category = self.category(mr['Category']) name = self.canonicalise(mr['Name']) - self.state[category][name] -= mr['Count'] + elif event_type == 'TradeMicroResources': + # Trading some MicroResources for another at a Bar Tender + # 'Offered' is what we traded away + for offer in entry['Offered']: + category = self.category(offer['Category']) + name = self.canonicalise(offer['Name']) + self.state[category][name] -= offer['Count'] + + # For a single item name received + category = self.category(entry['Category']) + name = self.canonicalise(entry['Received']) + self.state[category][name] += entry['Count'] + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From 9609286ff467e80a2356f238f9630005313c93e3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 13:46:16 +0100 Subject: [PATCH 517/727] Support for 'TransferMicroResources' event. --- monitor.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/monitor.py b/monitor.py index 94585518..34036d3a 100644 --- a/monitor.py +++ b/monitor.py @@ -782,6 +782,23 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below name = self.canonicalise(entry['Received']) self.state[category][name] += entry['Count'] + elif event_type == 'TransferMicroResources': + # Moving Odyssey MicroResources between ShipLocker and BackPack + for mr in entry['Transfers']: + category = self.category(mr['Category']) + name = self.canonicalise(mr['Name']) + + if mr['Direction'] == 'ToShipLocker': + self.state[category][name] += mr['Count'] + self.state['BackPack'][category][name] -= mr['Count'] + + elif mr['Direction'] == 'ToBackpack': + self.state[category][name] -= mr['Count'] + self.state['BackPack'][category][name] += mr['Count'] + + else: + logger.warning(f'TransferMicroResources with unexpected Direction {mr["Direction"]=}: {mr=}') + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From 5f59487a7ba16e77e1e17f040b45bc7c6108e33e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 15:46:03 +0100 Subject: [PATCH 518/727] Zero out BackPack Materials on ShipLockerMaterials This at least ensures we're correct after logging back in at a station. If you relog whilst out at a Settlement then counts will definitely be wrong now. But there are no events for using consumables, or picking anything up anyway, so it's almost always going to be off there. --- monitor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monitor.py b/monitor.py index 34036d3a..230794b1 100644 --- a/monitor.py +++ b/monitor.py @@ -717,6 +717,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Component'] = defaultdict(int) self.state['Consumable'] = defaultdict(int) self.state['Item'] = defaultdict(int) + # TODO: Assume backpack is empty? + self.state['BackPack']['Component'] = defaultdict(int) + self.state['BackPack']['Consumable'] = defaultdict(int) + self.state['BackPack']['Item'] = defaultdict(int) clean_components = self.coalesce_cargo(entry['Components']) self.state['Component'].update( From 112525c31e649d7a3ede0c5b6f932cb22d0a9e77 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 15:56:20 +0100 Subject: [PATCH 519/727] Add paranoia check for BackPack material counts going negative. Reset them to zero if they're negative. It's probably from an Embark-related TransferMicroResources event, so they should now be zeroes anyway. --- monitor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/monitor.py b/monitor.py index 230794b1..bb1de6a5 100644 --- a/monitor.py +++ b/monitor.py @@ -803,6 +803,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below else: logger.warning(f'TransferMicroResources with unexpected Direction {mr["Direction"]=}: {mr=}') + # Paranoia check to see if anything has gone negative. + # As of Odyssey Alpha Phase 1 Hotfix 2 keeping track of BackPack + # materials is impossible when used/picked up anyway. + for c in self.state['BackPack']: + for m in self.state['BackPack'][c]: + if self.state['BackPack'][c][m] < 0: + self.state['BackPack'][c][m] = 0 + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From 020eb36d8414ac7e2a169bc9c85777402c84c5b6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 15:58:57 +0100 Subject: [PATCH 520/727] Add comment about why we empty backpack on ShipLockerMaterials --- monitor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index bb1de6a5..75aa938b 100644 --- a/monitor.py +++ b/monitor.py @@ -717,7 +717,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Component'] = defaultdict(int) self.state['Consumable'] = defaultdict(int) self.state['Item'] = defaultdict(int) - # TODO: Assume backpack is empty? + # TODO: Really we need a full BackPackMaterials event at the same time. + # In lieu of that, empty the backpack. This will explicitly + # be wrong if Cmdr relogs at a Settlement with anything in + # backpack. We can't track when they use/pick up items + # anyway (Odyssey Alpha Phase 1 Hotfix 2). self.state['BackPack']['Component'] = defaultdict(int) self.state['BackPack']['Consumable'] = defaultdict(int) self.state['BackPack']['Item'] = defaultdict(int) From 960cb17cfb82ea2aa1d385514dbcb5e74b2814c9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Apr 2021 18:28:10 +0100 Subject: [PATCH 521/727] Also handle 'Data' category ShipLocker and BackPack I missed this because it is NOT in `ShipLockerItems`, but does show up in `TransferMicroResources`. --- monitor.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/monitor.py b/monitor.py index 75aa938b..5d482c1f 100644 --- a/monitor.py +++ b/monitor.py @@ -139,13 +139,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'CargoJSON': None, # The raw data from the last time cargo.json was read 'Route': None, # Last plotted route from Route.json file 'OnFoot': False, # Whether we think you're on-foot - 'Component': defaultdict(int), # Odyssey Components in Ship Locker - 'Item': defaultdict(int), # Odyssey Items in Ship Locker - 'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker - 'BackPack': { # Odyssey BackPack contents - 'Component': defaultdict(int), # BackPack Components - 'Consumable': defaultdict(int), # BackPack Consumables - 'Item': defaultdict(int), # BackPack Items + 'Component': defaultdict(int), # Odyssey Components in Ship Locker + 'Item': defaultdict(int), # Odyssey Items in Ship Locker + 'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker + 'Data': defaultdict(int), # Odyssey Data in Ship Locker + 'BackPack': { # Odyssey BackPack contents + 'Component': defaultdict(int), # BackPack Components + 'Consumable': defaultdict(int), # BackPack Consumables + 'Item': defaultdict(int), # BackPack Items + 'Data': defaultdict(int), # Backpack Data }, } From 9fd14a398067ea21d3a522312810639bd05886ea Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 13:17:38 +0100 Subject: [PATCH 522/727] Inara: Don't send a setCommanderReputationMajorFaction if we have no Reputations Sure the `for k, v in ...` means not sending any that are empty/none, but it will still send the event, just with *no* reputations. When you're on a fresh character you have no reputations yet, so avoid causing an Inara API error, including status line text. Close #581 --- plugins/inara.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 4967737f..30b95cda 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -410,14 +410,16 @@ def journal_entry( ] ) - new_add_event( - 'setCommanderReputationMajorFaction', - entry['timestamp'], - [ - {'majorfactionName': k.lower(), 'majorfactionReputation': v / 100.0} - for k, v in state['Reputation'].items() if v is not None - ] - ) + # Don't send the API call with no values. + if state['Reputation']: + new_add_event( + 'setCommanderReputationMajorFaction', + entry['timestamp'], + [ + {'majorfactionName': k.lower(), 'majorfactionReputation': v / 100.0} + for k, v in state['Reputation'].items() if v is not None + ] + ) if state['Engineers']: # Not populated < 3.3 to_send: List[Mapping[str, Any]] = [] From f494a948eb1c9cddc5b83b3b7e96d4988b2bd083 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 14:01:07 +0100 Subject: [PATCH 523/727] inara: Rename ALLCAPS function vars for padding. --- plugins/inara.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 30b95cda..a81528f1 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -200,23 +200,23 @@ def plugin_stop() -> None: def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame: """Plugin Preferences UI hook.""" - PADX = 10 - BUTTONX = 12 # indent Checkbuttons and Radiobuttons - PADY = 2 # close spacing + x_padding = 10 + x_button_padding = 12 # indent Checkbuttons and Radiobuttons + y_padding = 2 # close spacing frame = nb.Frame(parent) frame.columnconfigure(1, weight=1) HyperlinkLabel( frame, text='Inara', background=nb.Label().cget('background'), url='https://inara.cz/', underline=True - ).grid(columnspan=2, padx=PADX, sticky=tk.W) # Don't translate + ).grid(columnspan=2, padx=x_padding, sticky=tk.W) # Don't translate this.log = tk.IntVar(value=config.get_int('inara_out') and 1) this.log_button = nb.Checkbutton( frame, text=_('Send flight log and Cmdr status to Inara'), variable=this.log, command=prefsvarchanged ) - this.log_button.grid(columnspan=2, padx=BUTTONX, pady=(5, 0), sticky=tk.W) + this.log_button.grid(columnspan=2, padx=x_button_padding, pady=(5, 0), sticky=tk.W) nb.Label(frame).grid(sticky=tk.W) # big spacer @@ -229,12 +229,12 @@ def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame: underline=True ) - this.label.grid(columnspan=2, padx=PADX, sticky=tk.W) + this.label.grid(columnspan=2, padx=x_padding, sticky=tk.W) this.apikey_label = nb.Label(frame, text=_('API Key')) # Inara setting - this.apikey_label.grid(row=12, padx=PADX, sticky=tk.W) + this.apikey_label.grid(row=12, padx=x_padding, sticky=tk.W) this.apikey = nb.Entry(frame) - this.apikey.grid(row=12, column=1, padx=PADX, pady=PADY, sticky=tk.EW) + this.apikey.grid(row=12, column=1, padx=x_padding, pady=y_padding, sticky=tk.EW) prefs_cmdr_changed(cmdr, is_beta) From 8cbf37624c7fd3ff184e37a492b3c592b5dc11ed Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 14:03:06 +0100 Subject: [PATCH 524/727] Inara: Ignore cognitive complexity & snake_case a var --- plugins/inara.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index a81528f1..8c64ef7f 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -319,7 +319,7 @@ def credentials(cmdr: str) -> Optional[str]: return None -def journal_entry( +def journal_entry( # noqa: C901, CCR001 cmdr: str, is_beta: bool, system: str, station: str, entry: Dict[str, Any], state: Dict[str, Any] ) -> None: """Journal entry hook.""" @@ -1055,7 +1055,7 @@ def journal_entry( this.station_link.update_idletasks() -def cmdr_data(data: CAPIData, is_beta): +def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001 """CAPI event hook.""" this.cmdr = data['commander']['name'] @@ -1110,7 +1110,7 @@ def cmdr_data(data: CAPIData, is_beta): this.lastcredits = float(data['commander']['credits']) -def make_loadout(state: Dict[str, Any]) -> OrderedDictT[str, Any]: +def make_loadout(state: Dict[str, Any]) -> OrderedDictT[str, Any]: # noqa: CCR001 """ Construct an inara loadout from an event. @@ -1282,7 +1282,7 @@ def try_send_data(url: str, data: Mapping[str, Any]) -> None: return -def send_data(url: str, data: Mapping[str, Any]) -> bool: +def send_data(url: str, data: Mapping[str, Any]) -> bool: # noqa: CCR001 """ Write a set of events to the inara API. @@ -1347,7 +1347,7 @@ def update_location(event: Dict[str, Any] = None) -> None: plug.invoke(plugin, None, 'inara_notify_location', this.lastlocation) -def inara_notify_location(eventData: Dict[str, Any]) -> None: +def inara_notify_location(event_data: Dict[str, Any]) -> None: """Unused.""" pass From 6e98cf04d9c0af508dba878fa969e2f6fef3bfcf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 14:08:24 +0100 Subject: [PATCH 525/727] inara: Begin conversion to 'This' class. --- plugins/inara.py | 72 +++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 8c64ef7f..42fc902a 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -2,7 +2,6 @@ import dataclasses import json -import sys import time import tkinter as tk from collections import OrderedDict, defaultdict, deque @@ -37,46 +36,51 @@ FAKE = ('CQC', 'Training', 'Destination') # Fake systems that shouldn't be sent CREDIT_RATIO = 1.05 # Update credits if they change by 5% over the course of a session -this: Any = sys.modules[__name__] # For holding module globals -this.session = timeout_session.new_session() -this.lastlocation = None # eventData from the last Commander's Flight Log event -this.lastship = None # eventData from the last addCommanderShip or setCommanderShip event +class This: + """Holds module globals.""" -# Cached Cmdr state -this.events: List[OrderedDictT[str, Any]] = [] # Unsent events -this.event_lock = Lock -this.cmdr: Optional[str] = None -this.FID: Optional[str] = None # Frontier ID -this.multicrew: bool = False # don't send captain's ship info to Inara while on a crew -this.newuser: bool = False # just entered API Key - send state immediately -this.newsession: bool = True # starting a new session - wait for Cargo event -this.undocked: bool = False # just undocked -this.suppress_docked = False # Skip initial Docked event if started docked -this.cargo: Optional[OrderedDictT[str, Any]] = None -this.materials: Optional[OrderedDictT[str, Any]] = None -this.lastcredits: int = 0 # Send credit update soon after Startup / new game -this.storedmodules: Optional[OrderedDictT[str, Any]] = None -this.loadout: Optional[OrderedDictT[str, Any]] = None -this.fleet: Optional[List[OrderedDictT[str, Any]]] = None -this.shipswap: bool = False # just swapped ship -this.on_foot = False + def __init__(self): + self.session = timeout_session.new_session() + self.lastlocation = None # eventData from the last Commander's Flight Log event + self.lastship = None # eventData from the last addCommanderShip or setCommanderShip event + # Cached Cmdr state + self.events: List[OrderedDictT[str, Any]] = [] # Unsent events + self.event_lock = Lock + self.cmdr: Optional[str] = None + self.FID: Optional[str] = None # Frontier ID + self.multicrew: bool = False # don't send captain's ship info to Inara while on a crew + self.newuser: bool = False # just entered API Key - send state immediately + self.newsession: bool = True # starting a new session - wait for Cargo event + self.undocked: bool = False # just undocked + self.suppress_docked = False # Skip initial Docked event if started docked + self.cargo: Optional[OrderedDictT[str, Any]] = None + self.materials: Optional[OrderedDictT[str, Any]] = None + self.lastcredits: int = 0 # Send credit update soon after Startup / new game + self.storedmodules: Optional[OrderedDictT[str, Any]] = None + self.loadout: Optional[OrderedDictT[str, Any]] = None + self.fleet: Optional[List[OrderedDictT[str, Any]]] = None + self.shipswap: bool = False # just swapped ship + self.on_foot = False + + self.timer_run = True + + # Main window clicks + self.system_link = None + self.system = None + self.system_address = None + self.system_population = None + self.station_link = None + self.station = None + self.station_marketid = None + + +this = This() # last time we updated, if unset in config this is 0, which means an instant update LAST_UPDATE_CONF_KEY = 'inara_last_update' EVENT_COLLECT_TIME = 31 # Minimum time to take collecting events before requesting a send WORKER_WAIT_TIME = 35 # Minimum time for worker to wait between sends -this.timer_run = True - - -# Main window clicks -this.system_link = None -this.system = None -this.system_address = None -this.system_population = None -this.station_link = None -this.station = None -this.station_marketid = None STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7 From 3ea6dac00b105a00e4109a609551d9e820288d03 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 14:33:44 +0100 Subject: [PATCH 526/727] inara: Further cleanup * missing 'this' variables declared in This.__init__() * Types up to end of journal_entry() --- plugins/inara.py | 57 ++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 42fc902a..c9a6d9e1 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -41,6 +41,7 @@ class This: def __init__(self): self.session = timeout_session.new_session() + self.thread: Thread self.lastlocation = None # eventData from the last Commander's Flight Log event self.lastship = None # eventData from the last addCommanderShip or setCommanderShip event @@ -54,8 +55,8 @@ class This: self.newsession: bool = True # starting a new session - wait for Cargo event self.undocked: bool = False # just undocked self.suppress_docked = False # Skip initial Docked event if started docked - self.cargo: Optional[OrderedDictT[str, Any]] = None - self.materials: Optional[OrderedDictT[str, Any]] = None + self.cargo: Optional[List[OrderedDictT[str, Any]]] = None + self.materials: Optional[List[OrderedDictT[str, Any]]] = None self.lastcredits: int = 0 # Send credit update soon after Startup / new game self.storedmodules: Optional[OrderedDictT[str, Any]] = None self.loadout: Optional[OrderedDictT[str, Any]] = None @@ -74,6 +75,13 @@ class This: self.station = None self.station_marketid = None + # Prefs UI + self.log: 'tk.IntVar' + self.log_button: nb.Checkbutton + self.label: HyperlinkLabel + self.apikey: nb.Entry + self.apikey_label: HyperlinkLabel + this = This() # last time we updated, if unset in config this is 0, which means an instant update @@ -88,7 +96,7 @@ class Credentials(NamedTuple): """Credentials holds the set of credentials required to identify an inara API payload to inara.""" cmdr: str - fid: str + fid: Optional[str] api_key: str @@ -255,7 +263,7 @@ def prefs_cmdr_changed(cmdr: str, is_beta: bool) -> None: if cred: this.apikey.insert(0, cred) - state = tk.DISABLED + state: str = tk.DISABLED if cmdr and not is_beta and this.log.get(): state = tk.NORMAL @@ -325,12 +333,16 @@ def credentials(cmdr: str) -> Optional[str]: def journal_entry( # noqa: C901, CCR001 cmdr: str, is_beta: bool, system: str, station: str, entry: Dict[str, Any], state: Dict[str, Any] -) -> None: - """Journal entry hook.""" +) -> str: + """ + Journal entry hook. + + :return: str - empty if no error, else error string. + """ if (ks := killswitch.get_disabled('plugins.inara.journal')).disabled: logger.warning(f'INARA support has been disabled via killswitch: {ks.reason}') plug.show_error('INARA disabled. See Log.') - return + return '' elif (ks := killswitch.get_disabled(f'plugins.inara.journal.event.{entry["event"]}')).disabled: logger.warning(f'event {entry["event"]} processing has been disabled via killswitch: {ks.reason}') @@ -426,7 +438,7 @@ def journal_entry( # noqa: C901, CCR001 ) if state['Engineers']: # Not populated < 3.3 - to_send: List[Mapping[str, Any]] = [] + to_send_list: List[Mapping[str, Any]] = [] for k, v in state['Engineers'].items(): e = {'engineerName': k} if isinstance(v, tuple): @@ -435,12 +447,12 @@ def journal_entry( # noqa: C901, CCR001 else: e['rankStage'] = v - to_send.append(e) + to_send_list.append(e) new_add_event( 'setCommanderRankEngineer', entry['timestamp'], - to_send, + to_send_list, ) # Update location @@ -455,7 +467,7 @@ def journal_entry( # noqa: C901, CCR001 # Update ship if state['ShipID']: # Unknown if started in Fighter or SRV - cur_ship = { + cur_ship: Dict[str, Any] = { 'shipType': state['ShipType'], 'shipGameID': state['ShipID'], 'shipName': state['ShipName'], @@ -488,17 +500,17 @@ def journal_entry( # noqa: C901, CCR001 elif event_name == 'EngineerProgress' and 'Engineer' in entry: # TODO: due to this var name being used above, the types are weird - to_send = {'engineerName': entry['Engineer']} + to_send_dict = {'engineerName': entry['Engineer']} if 'Rank' in entry: - to_send['rankValue'] = entry['Rank'] + to_send_dict['rankValue'] = entry['Rank'] else: - to_send['rankStage'] = entry['Progress'] + to_send_dict['rankStage'] = entry['Progress'] new_add_event( 'setCommanderRankEngineer', entry['timestamp'], - to_send + to_send_dict ) # PowerPlay status change @@ -525,7 +537,7 @@ def journal_entry( # noqa: C901, CCR001 # Ship change if event_name == 'Loadout' and this.shipswap: - cur_ship: Dict[str, Any] = { + cur_ship = { 'shipType': state['ShipType'], 'shipGameID': state['ShipID'], 'shipName': state['ShipName'], # Can be None @@ -636,14 +648,15 @@ def journal_entry( # noqa: C901, CCR001 # Ignore the following 'Docked' event this.suppress_docked = True - cargo = [{'itemName': k, 'itemCount': state['Cargo'][k]} for k in sorted(state['Cargo'])] + cargo: List[OrderedDictT[str, Any]] + cargo = [OrderedDict({'itemName': k, 'itemCount': state['Cargo'][k]}) for k in sorted(state['Cargo'])] # Send cargo and materials if changed if this.cargo != cargo: new_add_event('setCommanderInventoryCargo', entry['timestamp'], cargo) this.cargo = cargo - materials: List[Mapping[str, Any]] = [] + materials: List[OrderedDictT[str, Any]] = [] for category in ('Raw', 'Manufactured', 'Encoded'): materials.extend( [OrderedDict([('itemName', k), ('itemCount', state[category][k])]) for k in sorted(state[category])] @@ -1058,6 +1071,8 @@ def journal_entry( # noqa: C901, CCR001 # through correctly. We don't want a static string. this.station_link.update_idletasks() + return '' # No error + def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001 """CAPI event hook.""" @@ -1340,7 +1355,7 @@ def send_data(url: str, data: Mapping[str, Any]) -> bool: # noqa: CCR001 return True # regardless of errors above, we DID manage to send it, therefore inform our caller as such -def update_location(event: Dict[str, Any] = None) -> None: +def update_location(event=None) -> None: """ Update other plugins with our response to system and station changes. @@ -1351,12 +1366,12 @@ def update_location(event: Dict[str, Any] = None) -> None: plug.invoke(plugin, None, 'inara_notify_location', this.lastlocation) -def inara_notify_location(event_data: Dict[str, Any]) -> None: +def inara_notify_location(event_data) -> None: """Unused.""" pass -def update_ship(event: Dict[str, Any] = None) -> None: +def update_ship(event=None) -> None: """ Update other plugins with our response to changing. From 7ef6c17fa18eb6cc0c7aba96e2f495330847ed0a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 14:38:07 +0100 Subject: [PATCH 527/727] inara: Fix 'fleet' type --- plugins/inara.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index c9a6d9e1..98937069 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -747,8 +747,8 @@ def journal_entry( # noqa: C901, CCR001 # Fleet if event_name == 'StoredShips': - fleet = sorted( - [{ + fleet: List[OrderedDictT[str, Any]] = sorted( + [OrderedDict({ 'shipType': x['ShipType'], 'shipGameID': x['ShipID'], 'shipName': x.get('Name'), @@ -756,15 +756,15 @@ def journal_entry( # noqa: C901, CCR001 'starsystemName': entry['StarSystem'], 'stationName': entry['StationName'], 'marketID': entry['MarketID'], - } for x in entry['ShipsHere']] + - [{ + }) for x in entry['ShipsHere']] + + [OrderedDict({ 'shipType': x['ShipType'], 'shipGameID': x['ShipID'], 'shipName': x.get('Name'), 'isHot': x['Hot'], 'starsystemName': x.get('StarSystem'), # Not present for ships in transit 'marketID': x.get('ShipMarketID'), # " - } for x in entry['ShipsRemote']], + }) for x in entry['ShipsRemote']], key=itemgetter('shipGameID') ) From aaceaf0f524f3108eed0d04d6a8f867e449b33e5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 15:24:23 +0100 Subject: [PATCH 528/727] inara: More type fixing --- plugins/inara.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 98937069..66bd44f5 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -7,9 +7,7 @@ import tkinter as tk from collections import OrderedDict, defaultdict, deque from operator import itemgetter from threading import Lock, Thread -from typing import ( - TYPE_CHECKING, Any, AnyStr, Callable, Deque, Dict, List, Mapping, MutableMapping, NamedTuple, Optional -) +from typing import TYPE_CHECKING, Any, AnyStr, Callable, Deque, Dict, List, Mapping, NamedTuple, Optional from typing import OrderedDict as OrderedDictT from typing import Sequence, Union, cast @@ -58,7 +56,7 @@ class This: self.cargo: Optional[List[OrderedDictT[str, Any]]] = None self.materials: Optional[List[OrderedDictT[str, Any]]] = None self.lastcredits: int = 0 # Send credit update soon after Startup / new game - self.storedmodules: Optional[OrderedDictT[str, Any]] = None + self.storedmodules: Optional[List[OrderedDictT[str, Any]]] = None self.loadout: Optional[OrderedDictT[str, Any]] = None self.fleet: Optional[List[OrderedDictT[str, Any]]] = None self.shipswap: bool = False # just swapped ship @@ -792,7 +790,7 @@ def journal_entry( # noqa: C901, CCR001 # Stored modules if event_name == 'StoredModules': items = {mod['StorageSlot']: mod for mod in entry['Items']} # Impose an order - modules = [] + modules: List[OrderedDictT[str, Any]] = [] for slot in sorted(items): item = items[slot] module: OrderedDictT[str, Any] = OrderedDict([ @@ -829,7 +827,7 @@ def journal_entry( # noqa: C901, CCR001 # Missions if event_name == 'MissionAccepted': - data = OrderedDict([ + data: OrderedDictT[str, Any] = OrderedDict([ ('missionName', entry['Name']), ('missionGameID', entry['MissionID']), ('influenceGain', entry['Influence']), @@ -939,7 +937,7 @@ def journal_entry( # noqa: C901, CCR001 new_add_event('addCommanderCombatInterdicted', entry['timestamp'], data) elif event_name == 'Interdiction': - data: OrderedDictT[str, Any] = OrderedDict([ + data = OrderedDict([ ('starsystemName', system), ('isPlayer', entry['IsPlayer']), ('isSuccess', entry['Success']), @@ -990,7 +988,7 @@ def journal_entry( # noqa: C901, CCR001 # )) for goal in entry['CurrentGoals']: - data: MutableMapping[str, Any] = OrderedDict([ + data = OrderedDict([ ('communitygoalGameID', goal['CGID']), ('communitygoalName', goal['Title']), ('starsystemName', goal['SystemName']), @@ -1013,7 +1011,7 @@ def journal_entry( # noqa: C901, CCR001 new_add_event('setCommunityGoal', entry['timestamp'], data) - data: MutableMapping[str, Any] = OrderedDict([ + data = OrderedDict([ ('communitygoalGameID', goal['CGID']), ('contribution', goal['PlayerContribution']), ('percentileBand', goal['PlayerPercentileBand']), From 878a2476047b556c72ea89e0753e45f0a1151f47 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 15:31:34 +0100 Subject: [PATCH 529/727] inara: A few final type fixups --- plugins/inara.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 66bd44f5..c497a099 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -93,7 +93,7 @@ STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00 class Credentials(NamedTuple): """Credentials holds the set of credentials required to identify an inara API payload to inara.""" - cmdr: str + cmdr: Optional[str] fid: Optional[str] api_key: str @@ -311,7 +311,7 @@ def prefs_changed(cmdr: str, is_beta: bool) -> None: ) -def credentials(cmdr: str) -> Optional[str]: +def credentials(cmdr: Optional[str]) -> Optional[str]: """ Get the credentials for the current commander. @@ -1124,7 +1124,7 @@ def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001 } ) - this.lastcredits = float(data['commander']['credits']) + this.lastcredits = int(data['commander']['credits']) def make_loadout(state: Dict[str, Any]) -> OrderedDictT[str, Any]: # noqa: CCR001 From 34d4e72bc48315aae3ded74b19e962d4c3723a49 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 16:25:16 +0100 Subject: [PATCH 530/727] GitHub workflows: echo info about what we're git diff'ing Whenever A_D does a PR the checks, for some unclear reason, also contain 'other' files causing unexpected flake8 output. i.e. PR that changes only plugins/inara.py somehow "git diff .. | flake8" such that flake8 complains about things in collate.py, coriolis.py, loadout.py --- .github/workflows/pr-checks.yml | 5 +++++ .github/workflows/push-checks.yml | 1 + 2 files changed, 6 insertions(+) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 2b7fc78c..c5c7a325 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -36,6 +36,8 @@ jobs: BASE_REPO_OWNER: ${{github.event.pull_request.base.repo.owner.login}} run: | + echo "BASE_REPO_URL: ${BASE_REPO_URL}" + echo "BASE_REPO_OWNER: ${BASE_REPO_OWNER}" # Add the 'base' repo as a new remote git remote add ${BASE_REPO_OWNER} ${BASE_REPO_URL} # And then fetch its references @@ -70,6 +72,9 @@ jobs: BASE_REF: ${{github.base_ref}} run: | + echo "BASE_REPO_URL: ${BASE_REPO_URL}" + echo "BASE_REPO_OWNER: ${BASE_REPO_OWNER}" + echo "BASE_REF: ${BASE_REF}" # Explicitly check for some errors # E9 - Runtime (syntax and the like) # F63 - 'tests' checking diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index 1dd650dc..362d75ab 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -39,6 +39,7 @@ jobs: run: | DATA=$(jq --raw-output .before $GITHUB_EVENT_PATH) + echo "DATA: ${DATA}" # stop the build if there are Python syntax errors or undefined names, ignore existing git diff "$DATA" | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --diff # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide From d0bc006f9f2d5f08e2920bec28cfcd8bcb548c3a Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 6 Apr 2021 17:13:04 +0200 Subject: [PATCH 531/727] Cleared final mypy errors in inara --- plugins/inara.py | 109 ++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 59 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index c497a099..28b19959 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1,13 +1,13 @@ """Inara Sync.""" -import dataclasses import json +import threading import time import tkinter as tk from collections import OrderedDict, defaultdict, deque from operator import itemgetter from threading import Lock, Thread -from typing import TYPE_CHECKING, Any, AnyStr, Callable, Deque, Dict, List, Mapping, NamedTuple, Optional +from typing import TYPE_CHECKING, Any, Callable, Deque, Dict, List, Mapping, NamedTuple, Optional from typing import OrderedDict as OrderedDictT from typing import Sequence, Union, cast @@ -34,6 +34,26 @@ FAKE = ('CQC', 'Training', 'Destination') # Fake systems that shouldn't be sent CREDIT_RATIO = 1.05 # Update credits if they change by 5% over the course of a session +# These need to be defined above This +class Credentials(NamedTuple): + """Credentials holds the set of credentials required to identify an inara API payload to inara.""" + + cmdr: Optional[str] + fid: Optional[str] + api_key: str + + +EVENT_DATA = Union[Mapping[str, Any], Sequence[Mapping[str, Any]]] + + +class Event(NamedTuple): + """Event represents an event for the Inara API.""" + + name: str + timestamp: str + data: EVENT_DATA + + class This: """Holds module globals.""" @@ -44,8 +64,6 @@ class This: self.lastship = None # eventData from the last addCommanderShip or setCommanderShip event # Cached Cmdr state - self.events: List[OrderedDictT[str, Any]] = [] # Unsent events - self.event_lock = Lock self.cmdr: Optional[str] = None self.FID: Optional[str] = None # Frontier ID self.multicrew: bool = False # don't send captain's ship info to Inara while on a crew @@ -65,11 +83,11 @@ class This: self.timer_run = True # Main window clicks - self.system_link = None - self.system = None - self.system_address = None - self.system_population = None - self.station_link = None + self.system_link: tk.Widget = None # type: ignore + self.system: Optional[str] = None # type: ignore + self.system_address: Optional[str] = None # type: ignore + self.system_population: Optional[int] = None + self.station_link: tk.Widget = None # type: ignore self.station = None self.station_marketid = None @@ -80,45 +98,8 @@ class This: self.apikey: nb.Entry self.apikey_label: HyperlinkLabel - -this = This() -# last time we updated, if unset in config this is 0, which means an instant update -LAST_UPDATE_CONF_KEY = 'inara_last_update' -EVENT_COLLECT_TIME = 31 # Minimum time to take collecting events before requesting a send -WORKER_WAIT_TIME = 35 # Minimum time for worker to wait between sends - -STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7 - - -class Credentials(NamedTuple): - """Credentials holds the set of credentials required to identify an inara API payload to inara.""" - - cmdr: Optional[str] - fid: Optional[str] - api_key: str - - -EVENT_DATA = Union[Mapping[AnyStr, Any], Sequence[Mapping[AnyStr, Any]]] - - -class Event(NamedTuple): - """Event represents an event for the Inara API.""" - - name: str - timestamp: str - data: EVENT_DATA - - -@dataclasses.dataclass -class NewThis: - """ - NewThis is where the plugin stores all of its data. - - It is named NewThis as it is currently being migrated to. Once migration is complete it will be renamed to This. - """ - - events: Dict[Credentials, Deque[Event]] = dataclasses.field(default_factory=lambda: defaultdict(deque)) - event_lock: Lock = dataclasses.field(default_factory=Lock) # protects events, for use when rewriting events + self.events: Dict[Credentials, Deque[Event]] = defaultdict(deque) + self.event_lock: Lock = threading.Lock() # protects events, for use when rewriting events def filter_events(self, key: Credentials, predicate: Callable[[Event], bool]) -> None: """ @@ -135,7 +116,15 @@ class NewThis: self.events[key].extend(filter(predicate, tmp)) -new_this = NewThis() +this = This() +# last time we updated, if unset in config this is 0, which means an instant update +LAST_UPDATE_CONF_KEY = 'inara_last_update' +EVENT_COLLECT_TIME = 31 # Minimum time to take collecting events before requesting a send +WORKER_WAIT_TIME = 35 # Minimum time for worker to wait between sends + +STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7 + + TARGET_URL = 'https://inara.cz/inapi/v1/' @@ -768,7 +757,7 @@ def journal_entry( # noqa: C901, CCR001 if this.fleet != fleet: this.fleet = fleet - new_this.filter_events(current_creds, lambda e: e.name != 'setCommanderShip') + this.filter_events(current_creds, lambda e: e.name != 'setCommanderShip') # this.events = [x for x in this.events if x['eventName'] != 'setCommanderShip'] # Remove any unsent for ship in this.fleet: @@ -780,9 +769,11 @@ def journal_entry( # noqa: C901, CCR001 if this.loadout != loadout: this.loadout = loadout - new_this.filter_events( + this.filter_events( current_creds, - lambda e: e.name != 'setCommanderShipLoadout' or e.data['shipGameID'] != this.loadout['shipGameID'] + lambda e: ( + e.name != 'setCommanderShipLoadout' + or cast(dict, e.data)['shipGameID'] != cast(dict, this.loadout)['shipGameID']) ) new_add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout) @@ -820,7 +811,7 @@ def journal_entry( # noqa: C901, CCR001 # Only send on change this.storedmodules = modules # Remove any unsent - new_this.filter_events(current_creds, lambda e: e.name != 'setCommanderStorageModules') + this.filter_events(current_creds, lambda e: e.name != 'setCommanderStorageModules') # this.events = list(filter(lambda e: e['eventName'] != 'setCommanderStorageModules', this.events)) new_add_event('setCommanderStorageModules', entry['timestamp'], this.storedmodules) @@ -978,7 +969,7 @@ def journal_entry( # noqa: C901, CCR001 # Community Goals if event_name == 'CommunityGoal': # Remove any unsent - new_this.filter_events( + this.filter_events( current_creds, lambda e: e.name not in ('setCommunityGoal', 'setCommanderCommunityGoalProgress') ) @@ -1109,7 +1100,7 @@ def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001 if config.get_int('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr): if not (CREDIT_RATIO > this.lastcredits / data['commander']['credits'] > 1/CREDIT_RATIO): - new_this.filter_events( + this.filter_events( Credentials(this.cmdr, this.FID, str(credentials(this.cmdr))), lambda e: e.name != 'setCommanderCredits' ) @@ -1223,8 +1214,8 @@ def new_add_event( key = Credentials(str(cmdr), str(fid), api_key) # this fails type checking due to `this` weirdness, hence str() - with new_this.event_lock: - new_this.events[key].append(Event(name, timestamp, data)) + with this.event_lock: + this.events[key].append(Event(name, timestamp, data)) def new_worker(): @@ -1272,8 +1263,8 @@ def get_events(clear: bool = True) -> Dict[Credentials, List[Event]]: :return: the frozen event list """ out: Dict[Credentials, List[Event]] = {} - with new_this.event_lock: - for key, events in new_this.events.items(): + with this.event_lock: + for key, events in this.events.items(): out[key] = list(events) if clear: events.clear() From 4dfe467d1c34d2698b745f9bf951f6f640795028 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 16:33:23 +0100 Subject: [PATCH 532/727] collate: Fix dict : whitespace --- collate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/collate.py b/collate.py index b7192b4e..16000af6 100755 --- a/collate.py +++ b/collate.py @@ -52,10 +52,10 @@ def addcommodities(data): for commodity in data['lastStarport'].get('commodities'): key = int(commodity['id']) new = { - 'id' : commodity['id'], - 'symbol' : commodity['name'], - 'category' : companion_category_map.get(commodity['categoryname']) or commodity['categoryname'], - 'name' : commodity.get('locName') or 'Limpets', + 'id': commodity['id'], + 'symbol': commodity['name'], + 'category': companion_category_map.get(commodity['categoryname']) or commodity['categoryname'], + 'name': commodity.get('locName') or 'Limpets', } old = commodities.get(key) From 7fc6b624ee1b1e3ec10d10f8c007a592e1f2d53b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 16:41:03 +0100 Subject: [PATCH 533/727] collate: Convert .format to f-string --- collate.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/collate.py b/collate.py index 16000af6..4171c30c 100755 --- a/collate.py +++ b/collate.py @@ -62,7 +62,7 @@ def addcommodities(data): if old and companion_category_map.get(commodity['categoryname'], True): if new['symbol'] != old['symbol'] or new['name'] != old['name']: - raise ValueError('{}: {!r} != {!r}'.format(key, new, old)) + raise ValueError(f'{key}: {new!r} != {old!r}') commodities[key] = new @@ -79,7 +79,7 @@ def addcommodities(data): for key in sorted(commodities): writer.writerow(commodities[key]) - print('Added {} new commodities'.format(len(commodities) - size_pre)) + print(f'Added {len(commodities) - size_pre} new commodities') # keep a summary of modules found @@ -104,13 +104,13 @@ def addmodules(data): # sanity check key = int(key) if key != module.get('id'): - raise ValueError('id: {} != {}'.format(key, module['id'])) + raise ValueError(f'id: {key} != {module['id']}') try: new = outfitting.lookup(module, ship_name_map, True) except Exception: - print('{}, {}:'.format(module['id'], module['name'])) + print(f'{module["id"]}, {module["name"]}:') print_exc(0) new = None @@ -123,7 +123,7 @@ def addmodules(data): size_pre -= 1 elif str(new.get(thing, '')) != old.get(thing): - raise ValueError('{}: {} {!r}!={!r}'.format(key, thing, new.get(thing), old.get(thing))) + raise ValueError(f'{key}: {thing} {new.get(thing)!r}!={old.get(thing)!r}') modules[key] = new @@ -140,7 +140,7 @@ def addmodules(data): for key in sorted(modules): writer.writerow(modules[key]) - print('Added {} new modules'.format(len(modules) - size_pre)) + print(f'Added {len(modules) - size_pre} new modules') # keep a summary of ships found @@ -176,7 +176,7 @@ def addships(data): size_pre -= 1 elif str(new.get(thing, '')) != old.get(thing): - raise ValueError('{}: {} {!r} != {!r}'.format(key, thing, new.get(thing), old.get(thing))) + raise ValueError(f'{key}: {thing} {new.get(thing)!r} != {old.get(thing)!r}') ships[key] = new @@ -193,7 +193,7 @@ def addships(data): for key in sorted(ships): writer.writerow(ships[key]) - print('Added {} new ships'.format(len(ships) - size_pre)) + print(f'Added {len(ships) - size_pre} new ships') if __name__ == "__main__": From 155d0082b00e6e913daddb0e92241a0dbd0fa4cd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 16:43:33 +0100 Subject: [PATCH 534/727] collate: docstring module and addcommodities() --- collate.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/collate.py b/collate.py index 4171c30c..6f0edebf 100755 --- a/collate.py +++ b/collate.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -# -# Script for collating lists of seen commodities, modules and ships from dumps of the Companion API output -# +"""Collate lists of seen commodities, modules and ships from dumps of the Companion API output.""" import csv import json @@ -22,7 +20,6 @@ def __make_backup(file_name: str, suffix: str = '.bak') -> None: :param file_name: The name of the file to make a backup of :param suffix: The suffix to use for backup files (default '.bak') """ - backup_name = file_name + suffix if isfile(backup_name): @@ -31,9 +28,13 @@ def __make_backup(file_name: str, suffix: str = '.bak') -> None: os.rename(file_name, backup_name) -# keep a summary of commodities found using in-game names -# Assumes that the commodity data has already been 'fixed up' -def addcommodities(data): +def addcommodities(data) -> None: # noqa: CCR001 + """ + Keep a summary of commodities found using in-game names. + + Assumes that the commodity data has already been 'fixed up' + :param data: - Fixed up commodity data. + """ if not data['lastStarport'].get('commodities'): return @@ -104,7 +105,7 @@ def addmodules(data): # sanity check key = int(key) if key != module.get('id'): - raise ValueError(f'id: {key} != {module['id']}') + raise ValueError(f'id: {key} != {module["id"]}') try: new = outfitting.lookup(module, ship_name_map, True) From 1e1e06c03b0c6cd12a7137c0434cc43ecbe8a742 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 16:44:21 +0100 Subject: [PATCH 535/727] collate: docstring addmodules & noqa complexity --- collate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collate.py b/collate.py index 6f0edebf..e46902e6 100755 --- a/collate.py +++ b/collate.py @@ -83,8 +83,8 @@ def addcommodities(data) -> None: # noqa: CCR001 print(f'Added {len(commodities) - size_pre} new commodities') -# keep a summary of modules found -def addmodules(data): +def addmodules(data): # noqa: C901, CCR001 + """Keep a summary of modules found.""" if not data['lastStarport'].get('modules'): return From 472d7178a359a0626d018a594d7e9643656997eb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 16:51:55 +0100 Subject: [PATCH 536/727] collate: docstring addships() --- collate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collate.py b/collate.py index e46902e6..a47b4a45 100755 --- a/collate.py +++ b/collate.py @@ -144,8 +144,8 @@ def addmodules(data): # noqa: C901, CCR001 print(f'Added {len(modules) - size_pre} new modules') -# keep a summary of ships found -def addships(data): +def addships(data) -> None: # noqa: CCR001 + """Keep a summary of ships found.""" if not data['lastStarport'].get('ships'): return From 236fb5a5cb42d3efb0bf76157b1060134e2a2048 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 17:02:39 +0100 Subject: [PATCH 537/727] coriolis: docstrings, formatting, return type --- coriolis.py | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/coriolis.py b/coriolis.py index a8493a9f..5ce76a29 100755 --- a/coriolis.py +++ b/coriolis.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 -# -# build ship and module databases from https://github.com/EDCD/coriolis-data/ -# +"""Build ship and module databases from https://github.com/EDCD/coriolis-data/ .""" + import csv import json @@ -16,8 +15,9 @@ from edmc_data import coriolis_ship_map, ship_name_map if __name__ == "__main__": - def add(modules, name, attributes): - assert name not in modules or modules[name] == attributes, '%s: %s!=%s' % (name, modules.get(name), attributes) + def add(modules, name, attributes) -> None: + """Add the given module to the modules dict.""" + assert name not in modules or modules[name] == attributes, f'{name}: {modules.get(name)} != {attributes}' assert name not in modules, name modules[name] = attributes @@ -38,11 +38,11 @@ if __name__ == "__main__": for m in list(data['Ships'].values()): name = coriolis_ship_map.get(m['properties']['name'], str(m['properties']['name'])) assert name in reverse_ship_map, name - ships[name] = { 'hullMass' : m['properties']['hullMass'] } + ships[name] = {'hullMass': m['properties']['hullMass']} for i in range(len(bulkheads)): - modules['_'.join([reverse_ship_map[name], 'armour', bulkheads[i]])] = { 'mass': m['bulkheads'][i]['mass'] } + modules['_'.join([reverse_ship_map[name], 'armour', bulkheads[i]])] = {'mass': m['bulkheads'][i]['mass']} - ships = OrderedDict([(k,ships[k]) for k in sorted(ships)]) # sort for easier diffing + ships = OrderedDict([(k, ships[k]) for k in sorted(ships)]) # sort for easier diffing pickle.dump(ships, open('ships.p', 'wb')) # Module masses @@ -53,32 +53,32 @@ if __name__ == "__main__": key = str(m['symbol'].lower()) if grp == 'fsd': modules[key] = { - 'mass' : m['mass'], - 'optmass' : m['optmass'], - 'maxfuel' : m['maxfuel'], - 'fuelmul' : m['fuelmul'], - 'fuelpower' : m['fuelpower'], + 'mass': m['mass'], + 'optmass': m['optmass'], + 'maxfuel': m['maxfuel'], + 'fuelmul': m['fuelmul'], + 'fuelpower': m['fuelpower'], } elif grp == 'gfsb': modules[key] = { - 'mass' : m['mass'], - 'jumpboost' : m['jumpboost'], + 'mass': m['mass'], + 'jumpboost': m['jumpboost'], } else: - modules[key] = { 'mass': m.get('mass', 0) } # Some modules don't have mass + modules[key] = {'mass': m.get('mass', 0)} # Some modules don't have mass # Pre 3.3 modules - add(modules, 'int_stellarbodydiscoveryscanner_standard', { 'mass': 2 }) - add(modules, 'int_stellarbodydiscoveryscanner_intermediate', { 'mass': 2 }) - add(modules, 'int_stellarbodydiscoveryscanner_advanced', { 'mass': 2 }) + add(modules, 'int_stellarbodydiscoveryscanner_standard', {'mass': 2}) + add(modules, 'int_stellarbodydiscoveryscanner_intermediate', {'mass': 2}) + add(modules, 'int_stellarbodydiscoveryscanner_advanced', {'mass': 2}) # Missing - add(modules, 'hpt_dumbfiremissilerack_fixed_small_advanced', { 'mass': 2 }) - add(modules, 'hpt_dumbfiremissilerack_fixed_medium_advanced',{ 'mass': 4 }) - add(modules, 'hpt_multicannon_fixed_small_advanced', { 'mass': 2 }) - add(modules, 'hpt_multicannon_fixed_medium_advanced', { 'mass': 4 }) + add(modules, 'hpt_dumbfiremissilerack_fixed_small_advanced', {'mass': 2}) + add(modules, 'hpt_dumbfiremissilerack_fixed_medium_advanced', {'mass': 4}) + add(modules, 'hpt_multicannon_fixed_small_advanced', {'mass': 2}) + add(modules, 'hpt_multicannon_fixed_medium_advanced', {'mass': 4}) - modules = OrderedDict([(k,modules[k]) for k in sorted(modules)]) # sort for easier diffing + modules = OrderedDict([(k, modules[k]) for k in sorted(modules)]) # sort for easier diffing pickle.dump(modules, open('modules.p', 'wb')) # Check data is present for all modules @@ -86,7 +86,7 @@ if __name__ == "__main__": reader = csv.DictReader(csvfile, restval='') for row in reader: try: - module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, ship_name_map) - except: + module = outfitting.lookup({'id': row['id'], 'name': row['symbol']}, ship_name_map) + except AssertionError: print(row['symbol']) print_exc() From c2a23771373d8809199a32a50ff7608686f3fff7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 17:51:26 +0100 Subject: [PATCH 538/727] outfitting.py: Cleanup flake8 and mypy output --- outfitting.py | 239 +++++++++++++++++++++++++++++++------------------- 1 file changed, 150 insertions(+), 89 deletions(-) diff --git a/outfitting.py b/outfitting.py index eb60f4b1..723b9817 100644 --- a/outfitting.py +++ b/outfitting.py @@ -1,7 +1,10 @@ +"""Code dealing with ship outfitting.""" + import pickle -import time from collections import OrderedDict from os.path import join +from typing import Optional +from typing import OrderedDict as OrderedDictT from config import config from edmc_data import outfitting_armour_map as armour_map @@ -22,43 +25,64 @@ from edmc_data import outfitting_weaponmount_map as weaponmount_map from edmc_data import outfitting_weaponoldvariant_map as weaponoldvariant_map from edmc_data import outfitting_weaponrating_map as weaponrating_map from edmc_data import ship_name_map +from EDMCLogging import get_main_logger + +logger = get_main_logger() # Module mass, FSD data etc -moduledata = OrderedDict() +moduledata: OrderedDictT = OrderedDict() -# Given a module description from the Companion API returns a description of the module in the form of a -# dict { category, name, [mount], [guidance], [ship], rating, class } using the same terms found in the -# English langauge game. For fitted modules, dict also includes { enabled, priority }. -# ship_name_map tells us what ship names to use for Armour - i.e. EDDN schema names or in-game names. -# -# Returns None if the module is user-specific (i.e. decal, paintjob, kit) or PP-specific in station outfitting. -# (Given the ad-hocery in this implementation a big lookup table might have been simpler and clearer). -def lookup(module, ship_map, entitled=False): +def lookup(module, ship_map, entitled=False) -> Optional[dict]: # noqa: C901, CCR001 + """ + Produce a standard dict description of the given module. + + Given a module description from the Companion API returns a description of the module in the form of a + dict { category, name, [mount], [guidance], [ship], rating, class } using the same terms found in the + English language game. For fitted modules, dict also includes { enabled, priority }. + ship_name_map tells us what ship names to use for Armour - i.e. EDDN schema names or in-game names. + + Given the ad-hocery in this implementation a big lookup table might have been simpler and clearer. + + :param module: + :param ship_map: + :param entitled: + :return: None if the module is user-specific (i.e. decal, paintjob, kit) or PP-specific in station outfitting. + """ # Lazily populate if not moduledata: moduledata.update(pickle.load(open(join(config.respath_path, 'modules.p'), 'rb'))) - # if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout - if not module.get('name'): raise AssertionError('%s: Missing name' % module['id']) + if not module.get('name'): + raise AssertionError(f'{module["id"]}') name = module['name'].lower().split('_') - new = { 'id': module['id'], 'symbol': module['name'] } + new = {'id': module['id'], 'symbol': module['name']} # Armour - e.g. Federation_Dropship_Armour_Grade2 if name[-2] == 'armour': - name = module['name'].lower().rsplit('_', 2) # Armour is ship-specific, and ship names can have underscores + name = module['name'].lower().rsplit('_', 2) # Armour is ship-specific, and ship names can have underscores new['category'] = 'standard' new['name'] = armour_map[name[2]] - new['ship'] = ship_map[name[0]] # Generate error on unknown ship + new['ship'] = ship_map[name[0]] # Generate error on unknown ship new['class'] = '1' new['rating'] = 'I' # Skip uninteresting stuff - some no longer present in ED 3.1 cAPI data - elif name[0] in ['bobble', 'decal', 'nameplate', 'paintjob', 'enginecustomisation', 'voicepack', 'weaponcustomisation'] or name[1].startswith('shipkit') : + elif (name[0] in [ + 'bobble', + 'decal', + 'nameplate', + 'paintjob', + 'enginecustomisation', + 'voicepack', + 'weaponcustomisation' + ] + or name[1].startswith('shipkit')): return None - # Shouldn't be listing player-specific paid stuff or broker/powerplay-specific modules in outfitting, other than Horizons + # Shouldn't be listing player-specific paid stuff or broker/powerplay-specific modules in outfitting, + # other than Horizons elif not entitled and module.get('sku') and module['sku'] != 'ELITE_HORIZONS_V_PLANETARY_LANDINGS': return None @@ -67,152 +91,189 @@ def lookup(module, ship_map, entitled=False): return None # Countermeasures - e.g. Hpt_PlasmaPointDefence_Turret_Tiny - elif name[0]=='hpt' and name[1] in countermeasure_map: + elif name[0] == 'hpt' and name[1] in countermeasure_map: new['category'] = 'utility' - new['name'], new['rating'] = countermeasure_map[len(name)>4 and (name[1],name[4]) or name[1]] + new['name'], new['rating'] = countermeasure_map[len(name) > 4 and (name[1], name[4]) or name[1]] new['class'] = weaponclass_map[name[-1]] # Utility - e.g. Hpt_CargoScanner_Size0_Class1 - elif name[0]=='hpt' and name[1] in utility_map: + elif name[0] == 'hpt' and name[1] in utility_map: new['category'] = 'utility' - new['name'] = utility_map[len(name)>4 and (name[1],name[4]) or name[1]] - if not name[2].startswith('size') or not name[3].startswith('class'): raise AssertionError('%s: Unknown class/rating "%s/%s"' % (module['id'], name[2], name[3])) + new['name'] = utility_map[len(name) > 4 and (name[1], name[4]) or name[1]] + if not name[2].startswith('size') or not name[3].startswith('class'): + raise AssertionError(f'{module["id"]}: Unknown class/rating "{name[2]}/{name[3]}"') + new['class'] = str(name[2][4:]) new['rating'] = rating_map[name[3][5:]] # Hardpoints - e.g. Hpt_Slugshot_Fixed_Medium - elif name[0]=='hpt': + elif name[0] == 'hpt': # Hack 'Guardian' and 'Mining' prefixes if len(name) > 3 and name[3] in weaponmount_map: prefix = name.pop(1) - name[1] = '%s_%s' % (prefix, name[1]) - if name[1] not in weapon_map: raise AssertionError('%s: Unknown weapon "%s"' % (module['id'], name[0])) - if name[2] not in weaponmount_map: raise AssertionError('%s: Unknown weapon mount "%s"' % (module['id'], name[2])) - if name[3] not in weaponclass_map: raise AssertionError('%s: Unknown weapon class "%s"' % (module['id'], name[3])) + name[1] = f'{prefix}_{name[1]}' + + if name[1] not in weapon_map: + raise AssertionError(f'{module["id"]}: Unknown weapon "{name[0]}"') + + if name[2] not in weaponmount_map: + raise AssertionError(f'{module["id"]}: Unknown weapon mount "{name[2]}"') + + if name[3] not in weaponclass_map: + raise AssertionError(f'{module["id"]}: Unknown weapon class "{name[3]}"') new['category'] = 'hardpoint' - if len(name)>4: - if name[4] in weaponoldvariant_map: # Old variants e.g. Hpt_PulseLaserBurst_Turret_Large_OC - new['name'] = weapon_map[name[1]] + ' ' + weaponoldvariant_map[name[4]] + if len(name) > 4: + if name[4] in weaponoldvariant_map: # Old variants e.g. Hpt_PulseLaserBurst_Turret_Large_OC + new['name'] = weapon_map[name[1]] + ' ' + weaponoldvariant_map[name[4]] new['rating'] = '?' + elif '_'.join(name[:4]) not in weaponrating_map: - raise AssertionError('%s: Unknown weapon rating "%s"' % (module['id'], module['name'])) - else: # PP faction-specific weapons e.g. Hpt_Slugshot_Fixed_Large_Range - new['name'] = weapon_map[(name[1],name[4])] - new['rating'] = weaponrating_map['_'.join(name[:4])] # assumes same rating as base weapon + raise AssertionError(f'{module["id"]}: Unknown weapon rating "{module["name"]}"') + + else: + # PP faction-specific weapons e.g. Hpt_Slugshot_Fixed_Large_Range + new['name'] = weapon_map[(name[1], name[4])] + new['rating'] = weaponrating_map['_'.join(name[:4])] # assumes same rating as base weapon + elif module['name'].lower() not in weaponrating_map: - raise AssertionError('%s: Unknown weapon rating "%s"' % (module['id'], module['name'])) + raise AssertionError(f'{module["id"]}: Unknown weapon rating "{module["name"]}"') + else: - new['name'] = weapon_map[name[1]] - new['rating'] = weaponrating_map[module['name'].lower()] # no obvious rule - needs lookup table + new['name'] = weapon_map[name[1]] + new['rating'] = weaponrating_map[module['name'].lower()] # no obvious rule - needs lookup table + new['mount'] = weaponmount_map[name[2]] - if name[1] in missiletype_map: # e.g. Hpt_DumbfireMissileRack_Fixed_Small + if name[1] in missiletype_map: + # e.g. Hpt_DumbfireMissileRack_Fixed_Small new['guidance'] = missiletype_map[name[1]] + new['class'] = weaponclass_map[name[3]] - elif name[0]!='int': - raise AssertionError('%s: Unknown prefix "%s"' % (module['id'], name[0])) + elif name[0] != 'int': + raise AssertionError(f'{module["id"]}: Unknown prefix "{name[0]}"') - # Miscellaneous Class 1 - e.g. Int_PlanetApproachSuite, Int_StellarBodyDiscoveryScanner_Advanced, Int_DockingComputer_Standard + # Miscellaneous Class 1 + # e.g. Int_PlanetApproachSuite, Int_StellarBodyDiscoveryScanner_Advanced, Int_DockingComputer_Standard elif name[1] in misc_internal_map: new['category'] = 'internal' new['name'], new['rating'] = misc_internal_map[name[1]] new['class'] = '1' - elif len(name) > 2 and (name[1],name[2]) in misc_internal_map: + + elif len(name) > 2 and (name[1], name[2]) in misc_internal_map: # Reported category is not necessarily helpful. e.g. "Int_DockingComputer_Standard" has category "utility" new['category'] = 'internal' - new['name'], new['rating'] = misc_internal_map[(name[1],name[2])] + new['name'], new['rating'] = misc_internal_map[(name[1], name[2])] new['class'] = '1' - # Standard & Internal else: - if name[1] == 'dronecontrol': # e.g. Int_DroneControl_Collection_Size1_Class1 + # Standard & Internal + if name[1] == 'dronecontrol': # e.g. Int_DroneControl_Collection_Size1_Class1 name.pop(0) - elif name[-1] == 'free': # Starter Sidewinder or Freagle modules - just treat them like vanilla modules + + elif name[-1] == 'free': # Starter Sidewinder or Freagle modules - just treat them like vanilla modules name.pop() - if name[1] in standard_map: # e.g. Int_Engine_Size2_Class1, Int_ShieldGenerator_Size8_Class5_Strong + if name[1] in standard_map: # e.g. Int_Engine_Size2_Class1, Int_ShieldGenerator_Size8_Class5_Strong new['category'] = 'standard' - new['name'] = standard_map[len(name)>4 and (name[1],name[4]) or name[1]] - elif name[1] in internal_map: # e.g. Int_CargoRack_Size8_Class1 + new['name'] = standard_map[len(name) > 4 and (name[1], name[4]) or name[1]] + + elif name[1] in internal_map: # e.g. Int_CargoRack_Size8_Class1 new['category'] = 'internal' if name[1] == 'passengercabin': new['name'] = cabin_map[name[3][5:]] - else: - new['name'] = internal_map[len(name)>4 and (name[1],name[4]) or name[1]] - else: - raise AssertionError('%s: Unknown module "%s"' % (module['id'], name[1])) - if len(name) < 4 and name[1] == 'unkvesselresearch': # Hack! No size or class. - (new['class'], new['rating']) = ('1', 'E') - elif len(name) < 4 and name[1] == 'resourcesiphon': # Hack! 128066402 has no size or class. - (new['class'], new['rating']) = ('1', 'I') - elif len(name) < 4 and name[1] in ['guardianpowerdistributor', 'guardianpowerplant']: # Hack! No class. - (new['class'], new['rating']) = (str(name[2][4:]), 'A') - elif len(name) < 4 and name[1] in ['guardianfsdbooster']: # Hack! No class. - (new['class'], new['rating']) = (str(name[2][4:]), 'H') + else: + new['name'] = internal_map[len(name) > 4 and (name[1], name[4]) or name[1]] + else: - if len(name) < 3: raise AssertionError('%s: length < 3]' % (name)) - if not name[2].startswith('size') or not name[3].startswith('class'): raise AssertionError('%s: Unknown class/rating "%s/%s"' % (module['id'], name[2], name[3])) + raise AssertionError(f'{module["id"]}: Unknown module "{name[1]}"') + + if len(name) < 4 and name[1] == 'unkvesselresearch': # Hack! No size or class. + (new['class'], new['rating']) = ('1', 'E') + + elif len(name) < 4 and name[1] == 'resourcesiphon': # Hack! 128066402 has no size or class. + (new['class'], new['rating']) = ('1', 'I') + + elif len(name) < 4 and name[1] in ['guardianpowerdistributor', 'guardianpowerplant']: # Hack! No class. + (new['class'], new['rating']) = (str(name[2][4:]), 'A') + + elif len(name) < 4 and name[1] in ['guardianfsdbooster']: # Hack! No class. + (new['class'], new['rating']) = (str(name[2][4:]), 'H') + + else: + if len(name) < 3: + raise AssertionError(f'{name}: length < 3]') + + if not name[2].startswith('size') or not name[3].startswith('class'): + raise AssertionError(f'{module["id"]}: Unknown class/rating "{name[2]}/{name[3]}"') + new['class'] = str(name[2][4:]) - new['rating'] = (name[1]=='buggybay' and planet_rating_map or - name[1]=='fighterbay' and fighter_rating_map or - name[1]=='corrosionproofcargorack' and corrosion_rating_map or + new['rating'] = (name[1] == 'buggybay' and planet_rating_map or + name[1] == 'fighterbay' and fighter_rating_map or + name[1] == 'corrosionproofcargorack' and corrosion_rating_map or rating_map)[name[3][5:]] # Disposition of fitted modules if 'on' in module and 'priority' in module: - new['enabled'], new['priority'] = module['on'], module['priority'] # priority is zero-based + new['enabled'], new['priority'] = module['on'], module['priority'] # priority is zero-based # Entitlements if not module.get('sku'): pass + else: new['entitlement'] = module['sku'] # Extra module data if module['name'].endswith('_free'): - key = module['name'][:-5].lower() # starter modules - treated like vanilla modules + key = module['name'][:-5].lower() # starter modules - treated like vanilla modules + else: key = module['name'].lower() + if __debug__: m = moduledata.get(key, {}) if not m: - print('No data for module %s' % key) + print(f'No data for module {key}') + elif new['name'] == 'Frame Shift Drive': assert 'mass' in m and 'optmass' in m and 'maxfuel' in m and 'fuelmul' in m and 'fuelpower' in m, m + else: assert 'mass' in m, m + new.update(moduledata.get(module['name'].lower(), {})) # check we've filled out mandatory fields - for thing in ['id', 'symbol', 'category', 'name', 'class', 'rating']: # Don't consider mass etc as mandatory - if not new.get(thing): raise AssertionError('%s: failed to set %s' % (module['id'], thing)) + for thing in ['id', 'symbol', 'category', 'name', 'class', 'rating']: # Don't consider mass etc as mandatory + if not new.get(thing): + raise AssertionError(f'{module["id"]}: failed to set {thing}') + if new['category'] == 'hardpoint' and not new.get('mount'): - raise AssertionError('%s: failed to set %s' % (module['id'], 'mount')) + raise AssertionError(f'{module["id"]}: failed to set mount') return new -def export(data, filename): - - querytime = config.get_int('querytime', default=int(time.time())) - +def export(data, filename) -> None: + """Export given data to provided filename.""" assert data['lastSystem'].get('name') assert data['lastStarport'].get('name') header = 'System,Station,Category,Name,Mount,Guidance,Ship,Class,Rating,FDevID,Date\n' - rowheader = '%s,%s' % (data['lastSystem']['name'], data['lastStarport']['name']) + rowheader = f'{data["lastSystem"]["name"]},{data["lastStarport"]["name"]}' - h = open(filename, 'wt') - h.write(header) - for v in list(data['lastStarport'].get('modules', {}).values()): - try: - m = lookup(v, ship_name_map) - if m: - h.write('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n' % (rowheader, m['category'], m['name'], m.get('mount',''), m.get('guidance',''), m.get('ship',''), m['class'], m['rating'], m['id'], data['timestamp'])) - except AssertionError as e: - if __debug__: print('Outfitting: %s' % e) # Silently skip unrecognized modules - except: - if __debug__: raise - h.close() + with open(filename, 'wt') as h: + h.write(header) + for v in list(data['lastStarport'].get('modules', {}).values()): + try: + m = lookup(v, ship_name_map) + if m: + h.write(f'{rowheader}, {m["category"]}, {m["name"]}, {m.get("mount","")},' + f'{m.get("guidance","")}, {m.get("ship","")}, {m["class"]}, {m["rating"]},' + f'{m["id"]}, {data["timestamp"]}\n') + + except AssertionError as e: + # Log unrecognised modules + logger.debug('Outfitting', exc_info=e) From e7cb7dc34fb0a554ae235c6a02613792f815addb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 17:55:26 +0100 Subject: [PATCH 539/727] outfitting.py: Improve function docstrings --- outfitting.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/outfitting.py b/outfitting.py index 723b9817..e59aa8d0 100644 --- a/outfitting.py +++ b/outfitting.py @@ -44,9 +44,9 @@ def lookup(module, ship_map, entitled=False) -> Optional[dict]: # noqa: C901, C Given the ad-hocery in this implementation a big lookup table might have been simpler and clearer. - :param module: - :param ship_map: - :param entitled: + :param module: module dict, e.g. from CAPI lastStarport->modules. + :param ship_map: dict mapping symbols to English names. + :param entitled: Whether to report modules that require e.g. Horizons. :return: None if the module is user-specific (i.e. decal, paintjob, kit) or PP-specific in station outfitting. """ # Lazily populate @@ -257,7 +257,12 @@ def lookup(module, ship_map, entitled=False) -> Optional[dict]: # noqa: C901, C def export(data, filename) -> None: - """Export given data to provided filename.""" + """ + Export given data about module availability. + + :param data: CAPI data to export. + :param filename: Filename to export into. + """ assert data['lastSystem'].get('name') assert data['lastStarport'].get('name') From efc3c9030d211c09c5af869bb654153693fceabe Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 6 Apr 2021 17:58:29 +0100 Subject: [PATCH 540/727] protocol.py: Silence web server INFO if running without UI Testing the outfitting.py changes brought this to light. I know, e.g. TCE that uses EDMC.exe likes to have no extraneous output. --- protocol.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protocol.py b/protocol.py index 471876b1..eff33e5e 100644 --- a/protocol.py +++ b/protocol.py @@ -1,5 +1,6 @@ """protocol handler for cAPI authorisation.""" +import os import sys import threading import urllib.error @@ -336,7 +337,9 @@ else: # Linux / Run from source super().__init__() self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler) self.redirect = f'http://localhost:{self.httpd.server_port}/auth' - logger.info(f'Web server listening on {self.redirect}') + if not os.getenv("EDMC_NO_UI"): + logger.info(f'Web server listening on {self.redirect}') + self.thread: Optional[threading.Thread] = None def start(self, master) -> None: From 9ff936165d0aa489b7b646f22e997c38eb479bdf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 12:22:15 +0100 Subject: [PATCH 541/727] EDMC.py: Quieten remaining flake8/mypy output --- EDMC.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EDMC.py b/EDMC.py index a1b32a47..4c5283a7 100755 --- a/EDMC.py +++ b/EDMC.py @@ -10,7 +10,7 @@ import re import sys from os.path import getmtime, join from time import sleep, time -from typing import TYPE_CHECKING, Any, Optional +from typing import TYPE_CHECKING, Any, List, Optional # isort: off @@ -68,7 +68,7 @@ EXIT_SUCCESS, EXIT_SERVER, EXIT_CREDENTIALS, EXIT_VERIFICATION, EXIT_LAGGING, EX JOURNAL_RE = re.compile(r'^Journal(Beta)?\.[0-9]{12}\.[0-9]{2}\.log$') -def versioncmp(versionstring): +def versioncmp(versionstring) -> List: """Quick and dirty version comparison assuming "strict" numeric only version numbers.""" return list(map(int, versionstring.split('.'))) @@ -106,7 +106,7 @@ def deep_get(target: dict, *args: str, default=None) -> Any: return current -def main(): +def main(): # noqa: C901, CCR001 """Run the main code of the program.""" try: # arg parsing From e34deb53886d74b011341780e0547ce17adbd7e9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 12:51:41 +0100 Subject: [PATCH 542/727] companion.py: Fix lints mypy is still a PITA with `Optional[]` thinking the variable is `None` at points and refusing to believe it has methods the non-None type has. --- companion.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/companion.py b/companion.py index 3eee5d2f..d1aca078 100644 --- a/companion.py +++ b/companion.py @@ -22,7 +22,7 @@ from email.utils import parsedate # TODO: see https://github.com/EDCD/EDMarketConnector/issues/569 from http.cookiejar import LWPCookieJar # noqa: F401 - No longer needed but retained in case plugins use it from os.path import join -from typing import TYPE_CHECKING, Any, Dict, List, Union, cast +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union import requests @@ -35,7 +35,7 @@ from protocol import protocolhandler logger = get_main_logger() if TYPE_CHECKING: - def _(x): return x # noqa: E731 # to make flake8 stop complaining that the hacked in _ method doesnt exist + def _(x): return x UserDict = collections.UserDict[str, Any] # indicate to our type checkers what this generic class holds normally else: @@ -92,6 +92,12 @@ class CAPIData(UserDict): self.check_modules_ships() def check_modules_ships(self) -> None: + """ + Sanity check our `data` for modules and ships being as expected. + + This has side-effects of fixing `data` to be as expected in terms of + types of those elements. + """ modules: Dict[str, Any] = self.data['lastStarport'].get('modules') if modules is None or not isinstance(modules, dict): if modules is None: @@ -158,7 +164,7 @@ def listify(thing: Union[List, Dict]) -> List: class ServerError(Exception): """Exception Class for CAPI ServerErrors.""" - def __init__(self, *args): + def __init__(self, *args) -> None: # Raised when cannot contact the Companion API server self.args = args if not args: @@ -172,7 +178,7 @@ class ServerLagging(Exception): servers are too busy. """ - def __init__(self, *args): + def __init__(self, *args) -> None: self.args = args if not args: self.args = (_('Error: Frontier server is lagging'),) @@ -185,7 +191,7 @@ class SKUError(Exception): purchased E:D i.e. doesn't have the correct 'SKU'. """ - def __init__(self, *args): + def __init__(self, *args) -> None: self.args = args if not args: self.args = (_('Error: Frontier server SKU problem'),) @@ -194,7 +200,7 @@ class SKUError(Exception): class CredentialsError(Exception): """Exception Class for CAPI Credentials error.""" - def __init__(self, *args): + def __init__(self, *args) -> None: self.args = args if not args: self.args = (_('Error: Invalid Credentials'),) @@ -209,7 +215,7 @@ class CmdrError(Exception): for the old Cmdr. """ - def __init__(self, *args): + def __init__(self, *args) -> None: self.args = args if not args: self.args = (_('Error: Wrong Cmdr'),) @@ -218,18 +224,19 @@ class CmdrError(Exception): class Auth(object): """Handles authentication with the Frontier CAPI service via oAuth2.""" - def __init__(self, cmdr: str): + def __init__(self, cmdr: str) -> None: self.cmdr: str = cmdr self.session = requests.Session() self.session.headers['User-Agent'] = USER_AGENT self.verifier: Union[bytes, None] = None self.state: Union[str, None] = None - def __del__(self): + def __del__(self) -> None: + """Ensure our Session is closed if we're being deleted.""" if self.session: self.session.close() - def refresh(self) -> Union[str, None]: + def refresh(self) -> Optional[str]: """ Attempt use of Refresh Token to get a valid Access Token. @@ -388,12 +395,12 @@ class Session(object): STATE_INIT, STATE_AUTH, STATE_OK = list(range(3)) - def __init__(self): + def __init__(self) -> None: self.state = Session.STATE_INIT - self.server = None - self.credentials = None - self.session = None - self.auth = None + self.server: Optional[str] = None + self.credentials: Optional[Dict[str, Any]] = None + self.session: Optional[requests.Session] = None + self.auth: Optional[Auth] = None self.retrying = False # Avoid infinite loop when successful auth / unsuccessful query def login(self, cmdr: str = None, is_beta: Union[None, bool] = None) -> bool: @@ -456,7 +463,7 @@ class Session(object): try: logger.debug('Trying authorize with payload from handler') - self.start(self.auth.authorize(protocolhandler.lastpayload)) + self.start(self.auth.authorize(protocolhandler.lastpayload)) # type: ignore self.auth = None except Exception: @@ -486,7 +493,7 @@ class Session(object): try: logger.trace('Trying...') - r = self.session.get(self.server + endpoint, timeout=timeout) + r = self.session.get(self.server + endpoint, timeout=timeout) # type: ignore except Exception as e: logger.debug('Attempting GET', exc_info=e) @@ -598,7 +605,7 @@ class Session(object): logger.debug('Forcing a full re-authentication') # Force a full re-authentication self.close() - Auth.invalidate(self.credentials['cmdr']) + Auth.invalidate(self.credentials['cmdr']) # type: ignore # noinspection PyMethodMayBeStatic def dump(self, r: requests.Response) -> None: From 2de9352f9a20fa1a2f5310448e22d669b5cf45f2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 15:49:08 +0100 Subject: [PATCH 543/727] hotkey.py: module docstring, and fix imports --- hotkey.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hotkey.py b/hotkey.py index 309fd5b2..a7a19d56 100644 --- a/hotkey.py +++ b/hotkey.py @@ -1,3 +1,4 @@ +"""Handle keyboard input for manual update triggering.""" # -*- coding: utf-8 -*- from os.path import join @@ -8,11 +9,15 @@ from EDMCLogging import get_main_logger logger = get_main_logger() -if platform == 'darwin': +if platform == 'darwin': # noqa: C901 import objc - - from AppKit import NSApplication, NSWorkspace, NSBeep, NSSound, NSEvent, NSKeyDown, NSKeyUp, NSFlagsChanged, NSKeyDownMask, NSFlagsChangedMask, NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, NSCommandKeyMask, NSNumericPadKeyMask, NSDeviceIndependentModifierFlagsMask, NSF1FunctionKey, NSF35FunctionKey, NSDeleteFunctionKey, NSClearLineFunctionKey + from AppKit import ( + NSAlternateKeyMask, NSApplication, NSBeep, NSClearLineFunctionKey, NSCommandKeyMask, NSControlKeyMask, + NSDeleteFunctionKey, NSDeviceIndependentModifierFlagsMask, NSEvent, NSF1FunctionKey, NSF35FunctionKey, + NSFlagsChanged, NSFlagsChangedMask, NSKeyDown, NSKeyDownMask, NSKeyUp, NSNumericPadKeyMask, NSShiftKeyMask, + NSSound, NSWorkspace + ) class HotkeyMgr: @@ -189,9 +194,9 @@ elif platform == 'win32': import atexit import ctypes - from ctypes.wintypes import DWORD, HWND, LONG, LPWSTR, MSG, ULONG, WORD import threading import winsound + from ctypes.wintypes import DWORD, HWND, LONG, LPWSTR, MSG, ULONG, WORD RegisterHotKey = ctypes.windll.user32.RegisterHotKey UnregisterHotKey = ctypes.windll.user32.UnregisterHotKey From 5d15751528562ed7f685242605123f78a5a474d9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 15:49:39 +0100 Subject: [PATCH 544/727] Remove unused darwin import --- hotkey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotkey.py b/hotkey.py index a7a19d56..66515cdf 100644 --- a/hotkey.py +++ b/hotkey.py @@ -15,7 +15,7 @@ if platform == 'darwin': # noqa: C901 from AppKit import ( NSAlternateKeyMask, NSApplication, NSBeep, NSClearLineFunctionKey, NSCommandKeyMask, NSControlKeyMask, NSDeleteFunctionKey, NSDeviceIndependentModifierFlagsMask, NSEvent, NSF1FunctionKey, NSF35FunctionKey, - NSFlagsChanged, NSFlagsChangedMask, NSKeyDown, NSKeyDownMask, NSKeyUp, NSNumericPadKeyMask, NSShiftKeyMask, + NSFlagsChanged, NSKeyDown, NSKeyDownMask, NSKeyUp, NSNumericPadKeyMask, NSShiftKeyMask, NSSound, NSWorkspace ) From 92376dda85d18c843412e92e9a52e72dfec5a885 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 15:50:11 +0100 Subject: [PATCH 545/727] And now isort wants things to cuddle up --- hotkey.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hotkey.py b/hotkey.py index 66515cdf..cd451b43 100644 --- a/hotkey.py +++ b/hotkey.py @@ -15,8 +15,7 @@ if platform == 'darwin': # noqa: C901 from AppKit import ( NSAlternateKeyMask, NSApplication, NSBeep, NSClearLineFunctionKey, NSCommandKeyMask, NSControlKeyMask, NSDeleteFunctionKey, NSDeviceIndependentModifierFlagsMask, NSEvent, NSF1FunctionKey, NSF35FunctionKey, - NSFlagsChanged, NSKeyDown, NSKeyDownMask, NSKeyUp, NSNumericPadKeyMask, NSShiftKeyMask, - NSSound, NSWorkspace + NSFlagsChanged, NSKeyDown, NSKeyDownMask, NSKeyUp, NSNumericPadKeyMask, NSShiftKeyMask, NSSound, NSWorkspace ) class HotkeyMgr: From 7dbf150846c2d4f539fde6e6ce3e2aef03341c21 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 16:22:42 +0100 Subject: [PATCH 546/727] hotkey: flake8 lints for darwin --- hotkey.py | 196 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 140 insertions(+), 56 deletions(-) diff --git a/hotkey.py b/hotkey.py index cd451b43..bb26f5ab 100644 --- a/hotkey.py +++ b/hotkey.py @@ -1,12 +1,18 @@ """Handle keyboard input for manual update triggering.""" # -*- coding: utf-8 -*- -from os.path import join +import pathlib from sys import platform +from typing import TYPE_CHECKING, Optional, Tuple, Union from config import config from EDMCLogging import get_main_logger +# isort: off +if TYPE_CHECKING: + import tkinter as tk +# isort: on + logger = get_main_logger() if platform == 'darwin': # noqa: C901 @@ -19,17 +25,19 @@ if platform == 'darwin': # noqa: C901 ) class HotkeyMgr: + """Hot key management.""" - MODIFIERMASK = NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask|NSNumericPadKeyMask + MODIFIERMASK = NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask | NSNumericPadKeyMask POLL = 250 # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/#//apple_ref/doc/constant_group/Function_Key_Unicodes - DISPLAY = { 0x03: u'⌅', 0x09: u'⇥', 0xd: u'↩', 0x19: u'⇤', 0x1b: u'esc', 0x20: u'⏘', 0x7f: u'⌫', - 0xf700: u'↑', 0xf701: u'↓', 0xf702: u'←', 0xf703: u'→', - 0xf727: u'Ins', - 0xf728: u'⌦', 0xf729: u'↖', 0xf72a: u'Fn', 0xf72b: u'↘', - 0xf72c: u'⇞', 0xf72d: u'⇟', 0xf72e: u'PrtScr', 0xf72f: u'ScrollLock', - 0xf730: u'Pause', 0xf731: u'SysReq', 0xf732: u'Break', 0xf733: u'Reset', - 0xf739: u'⌧', + DISPLAY = { + 0x03: u'⌅', 0x09: u'⇥', 0xd: u'↩', 0x19: u'⇤', 0x1b: u'esc', 0x20: u'⏘', 0x7f: u'⌫', + 0xf700: u'↑', 0xf701: u'↓', 0xf702: u'←', 0xf703: u'→', + 0xf727: u'Ins', + 0xf728: u'⌦', 0xf729: u'↖', 0xf72a: u'Fn', 0xf72b: u'↘', + 0xf72c: u'⇞', 0xf72d: u'⇟', 0xf72e: u'PrtScr', 0xf72f: u'ScrollLock', + 0xf730: u'Pause', 0xf731: u'SysReq', 0xf732: u'Break', 0xf733: u'Reset', + 0xf739: u'⌧', } (ACQUIRE_INACTIVE, ACQUIRE_ACTIVE, ACQUIRE_NEW) = range(3) @@ -46,10 +54,21 @@ if platform == 'darwin': # noqa: C901 self.tkProcessKeyEvent_old = None - self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath_path, 'snd_good.wav'), False) - self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath_path, 'snd_bad.wav'), False) + self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_( + pathlib.Path(config.respath_path) / 'snd_good.wav', False + ) + self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_( + pathlib.Path(config.respath_path) / 'snd_bad.wav', False + ) - def register(self, root, keycode, modifiers): + def register(self, root: tk.Tk, keycode, modifiers) -> None: + """ + Register current hotkey for monitoring. + + :param root: parent window. + :param keycode: Key to monitor. + :param modifiers: Any modifiers to take into account. + """ self.root = root self.keycode = keycode self.modifiers = modifiers @@ -65,32 +84,56 @@ if platform == 'darwin': # noqa: C901 sel = b'tkProcessKeyEvent:' cls = NSApplication.sharedApplication().class__() self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel) - newmethod = objc.selector(self.tkProcessKeyEvent, selector = self.tkProcessKeyEvent_old.selector, signature = self.tkProcessKeyEvent_old.signature) + newmethod = objc.selector( + self.tkProcessKeyEvent, + selector=self.tkProcessKeyEvent_old.selector, + signature=self.tkProcessKeyEvent_old.signature + ) objc.classAddMethod(cls, sel, newmethod) - # Monkey-patch tk (tkMacOSXKeyEvent.c) to: - # - workaround crash on OSX 10.9 & 10.10 on seeing a composing character - # - notice when modifier key state changes - # - keep a copy of NSEvent.charactersIgnoringModifiers, which is what we need for the hotkey - # (Would like to use a decorator but need to ensure the application is created before this is installed) - def tkProcessKeyEvent(self, cls, theEvent): + def tkProcessKeyEvent(self, cls, the_event): # noqa: N802 + """ + Monkey-patch tk (tkMacOSXKeyEvent.c). + + - workaround crash on OSX 10.9 & 10.10 on seeing a composing character + - notice when modifier key state changes + - keep a copy of NSEvent.charactersIgnoringModifiers, which is what we need for the hotkey + + (Would like to use a decorator but need to ensure the application is created before this is installed) + :param cls: ??? + :param the_event: tk event + :return: ??? + """ if self.acquire_state: - if theEvent.type() == NSFlagsChanged: - self.acquire_key = theEvent.modifierFlags() & NSDeviceIndependentModifierFlagsMask + if the_event.type() == NSFlagsChanged: + self.acquire_key = the_event.modifierFlags() & NSDeviceIndependentModifierFlagsMask self.acquire_state = HotkeyMgr.ACQUIRE_NEW # suppress the event by not chaining the old function - return theEvent - elif theEvent.type() in (NSKeyDown, NSKeyUp): - c = theEvent.charactersIgnoringModifiers() - self.acquire_key = (c and ord(c[0]) or 0) | (theEvent.modifierFlags() & NSDeviceIndependentModifierFlagsMask) + return the_event + + elif the_event.type() in (NSKeyDown, NSKeyUp): + c = the_event.charactersIgnoringModifiers() + self.acquire_key = (c and ord(c[0]) or 0) | \ + (the_event.modifierFlags() & NSDeviceIndependentModifierFlagsMask) self.acquire_state = HotkeyMgr.ACQUIRE_NEW # suppress the event by not chaining the old function - return theEvent + return the_event # replace empty characters with charactersIgnoringModifiers to avoid crash - elif theEvent.type() in (NSKeyDown, NSKeyUp) and not theEvent.characters(): - theEvent = NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_(theEvent.type(), theEvent.locationInWindow(), theEvent.modifierFlags(), theEvent.timestamp(), theEvent.windowNumber(), theEvent.context(), theEvent.charactersIgnoringModifiers(), theEvent.charactersIgnoringModifiers(), theEvent.isARepeat(), theEvent.keyCode()) - return self.tkProcessKeyEvent_old(cls, theEvent) + elif the_event.type() in (NSKeyDown, NSKeyUp) and not the_event.characters(): + the_event = NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( # noqa: E501 + the_event.type(), + the_event.locationInWindow(), + the_event.modifierFlags(), + the_event.timestamp(), + the_event.windowNumber(), + the_event.context(), + the_event.charactersIgnoringModifiers(), + the_event.charactersIgnoringModifiers(), + the_event.isARepeat(), + the_event.keyCode() + ) + return self.tkProcessKeyEvent_old(cls, the_event) def _observe(self): # Must be called after root.mainloop() so that the app's message loop has been created @@ -109,29 +152,35 @@ if platform == 'darwin': # noqa: C901 if self.keycode or self.modifiers: self.root.after(HotkeyMgr.POLL, self._poll) - def unregister(self): + def unregister(self) -> None: + """Remove hotkey registration.""" self.keycode = None self.modifiers = None @objc.callbackFor(NSEvent.addGlobalMonitorForEventsMatchingMask_handler_) - def _handler(self, event): + def _handler(self, event) -> None: # use event.charactersIgnoringModifiers to handle composing characters like Alt-e - if (event.modifierFlags() & HotkeyMgr.MODIFIERMASK) == self.modifiers and ord(event.charactersIgnoringModifiers()[0]) == self.keycode: + if ((event.modifierFlags() & HotkeyMgr.MODIFIERMASK) == self.modifiers + and ord(event.charactersIgnoringModifiers()[0]) == self.keycode): if config.get_int('hotkey_always'): self.activated = True - else: # Only trigger if game client is front process + + else: # Only trigger if game client is front process front = NSWorkspace.sharedWorkspace().frontmostApplication() if front and front.bundleIdentifier() == 'uk.co.frontier.EliteDangerous': self.activated = True - def acquire_start(self): + def acquire_start(self) -> None: + """Start acquiring hotkey state via polling.""" self.acquire_state = HotkeyMgr.ACQUIRE_ACTIVE self.root.after_idle(self._acquire_poll) - def acquire_stop(self): + def acquire_stop(self) -> None: + """Stop acquiring hotkey state.""" self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE - def _acquire_poll(self): + def _acquire_poll(self) -> None: + """Perform a poll of current hotkey state.""" if config.shutting_down: return @@ -140,52 +189,87 @@ if platform == 'darwin': # noqa: C901 if self.acquire_state: if self.acquire_state == HotkeyMgr.ACQUIRE_NEW: # Abuse tkEvent's keycode field to hold our acquired key & modifier - self.root.event_generate('', keycode = self.acquire_key) + self.root.event_generate('', keycode=self.acquire_key) self.acquire_state = HotkeyMgr.ACQUIRE_ACTIVE self.root.after(50, self._acquire_poll) - def fromevent(self, event): - # Return configuration (keycode, modifiers) or None=clear or False=retain previous - (keycode, modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000) # Set by _acquire_poll() - if keycode and not (modifiers & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)): + def fromevent(self, event) -> Optional[Union[bool, Tuple]]: + """ + Return configuration (keycode, modifiers) or None=clear or False=retain previous. + + :param event: tk event ? + :return: False to retain previous, None to not use, else (keycode, modifiers) + """ + (keycode, modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000) # Set by _acquire_poll() + if (keycode + and not (modifiers & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask))): if keycode == 0x1b: # Esc = retain previous self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE return False - elif keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]: # BkSp, Del, Clear = clear hotkey + + # BkSp, Del, Clear = clear hotkey + elif keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]: self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE return None - elif keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a: # don't allow keys needed for typing in System Map + + # don't allow keys needed for typing in System Map + elif keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a: NSBeep() self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE return None + return (keycode, modifiers) - def display(self, keycode, modifiers): - # Return displayable form + def display(self, keycode, modifiers) -> str: + """ + Return displayable form of given hotkey + modifiers. + + :param keycode: + :param modifiers: + :return: string form + """ text = '' - if modifiers & NSControlKeyMask: text += u'⌃' - if modifiers & NSAlternateKeyMask: text += u'⌥' - if modifiers & NSShiftKeyMask: text += u'⇧' - if modifiers & NSCommandKeyMask: text += u'⌘' - if (modifiers & NSNumericPadKeyMask) and keycode <= 0x7f: text += u'№' + if modifiers & NSControlKeyMask: + text += u'⌃' + + if modifiers & NSAlternateKeyMask: + text += u'⌥' + + if modifiers & NSShiftKeyMask: + text += u'⇧' + + if modifiers & NSCommandKeyMask: + text += u'⌘' + + if (modifiers & NSNumericPadKeyMask) and keycode <= 0x7f: + text += u'№' + if not keycode: pass + elif ord(NSF1FunctionKey) <= keycode <= ord(NSF35FunctionKey): - text += 'F%d' % (keycode + 1 - ord(NSF1FunctionKey)) - elif keycode in HotkeyMgr.DISPLAY: # specials + text += f'F{keycode + 1 - ord(NSF1FunctionKey)}' + + elif keycode in HotkeyMgr.DISPLAY: # specials text += HotkeyMgr.DISPLAY[keycode] - elif keycode < 0x20: # control keys + + elif keycode < 0x20: # control keys text += chr(keycode+0x40) - elif keycode < 0xf700: # key char + + elif keycode < 0xf700: # key char text += chr(keycode).upper() + else: text += u'⁈' + return text def play_good(self): + """Play the 'good' sound.""" self.snd_good.play() def play_bad(self): + """Play the 'bad' sound.""" self.snd_bad.play() @@ -295,9 +379,9 @@ elif platform == 'win32': def __init__(self): self.root = None self.thread = None - with open(join(config.respath, 'snd_good.wav'), 'rb') as sg: + with open(pathlib.Path(config.respath) / 'snd_good.wav', 'rb') as sg: self.snd_good = sg.read() - with open(join(config.respath, 'snd_bad.wav'), 'rb') as sb: + with open(pathlib.Path(config.respath) / 'snd_bad.wav', 'rb') as sb: self.snd_bad = sb.read() atexit.register(self.unregister) From 42cd2c501ecebe95d899db09cd1b9617c1f2c05f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 16:54:13 +0100 Subject: [PATCH 547/727] hotkey: win32 flake8 linting --- hotkey.py | 298 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 196 insertions(+), 102 deletions(-) diff --git a/hotkey.py b/hotkey.py index bb26f5ab..a185c822 100644 --- a/hotkey.py +++ b/hotkey.py @@ -32,10 +32,10 @@ if platform == 'darwin': # noqa: C901 # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/#//apple_ref/doc/constant_group/Function_Key_Unicodes DISPLAY = { 0x03: u'⌅', 0x09: u'⇥', 0xd: u'↩', 0x19: u'⇤', 0x1b: u'esc', 0x20: u'⏘', 0x7f: u'⌫', - 0xf700: u'↑', 0xf701: u'↓', 0xf702: u'←', 0xf703: u'→', + 0xf700: u'↑', 0xf701: u'↓', 0xf702: u'←', 0xf703: u'→', 0xf727: u'Ins', - 0xf728: u'⌦', 0xf729: u'↖', 0xf72a: u'Fn', 0xf72b: u'↘', - 0xf72c: u'⇞', 0xf72d: u'⇟', 0xf72e: u'PrtScr', 0xf72f: u'ScrollLock', + 0xf728: u'⌦', 0xf729: u'↖', 0xf72a: u'Fn', 0xf72b: u'↘', + 0xf72c: u'⇞', 0xf72d: u'⇟', 0xf72e: u'PrtScr', 0xf72f: u'ScrollLock', 0xf730: u'Pause', 0xf731: u'SysReq', 0xf732: u'Break', 0xf733: u'Reset', 0xf739: u'⌧', } @@ -122,6 +122,7 @@ if platform == 'darwin': # noqa: C901 # replace empty characters with charactersIgnoringModifiers to avoid crash elif the_event.type() in (NSKeyDown, NSKeyUp) and not the_event.characters(): the_event = NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( # noqa: E501 + # noqa: E501 the_event.type(), the_event.locationInWindow(), the_event.modifierFlags(), @@ -203,7 +204,7 @@ if platform == 'darwin': # noqa: C901 (keycode, modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000) # Set by _acquire_poll() if (keycode and not (modifiers & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask))): - if keycode == 0x1b: # Esc = retain previous + if keycode == 0x1b: # Esc = retain previous self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE return False @@ -254,7 +255,7 @@ if platform == 'darwin': # noqa: C901 text += HotkeyMgr.DISPLAY[keycode] elif keycode < 0x20: # control keys - text += chr(keycode+0x40) + text += chr(keycode + 0x40) elif keycode < 0xf700: # key char text += chr(keycode).upper() @@ -281,78 +282,117 @@ elif platform == 'win32': import winsound from ctypes.wintypes import DWORD, HWND, LONG, LPWSTR, MSG, ULONG, WORD - RegisterHotKey = ctypes.windll.user32.RegisterHotKey - UnregisterHotKey = ctypes.windll.user32.UnregisterHotKey - MOD_ALT = 0x0001 - MOD_CONTROL = 0x0002 - MOD_SHIFT = 0x0004 - MOD_WIN = 0x0008 + RegisterHotKey = ctypes.windll.user32.RegisterHotKey + UnregisterHotKey = ctypes.windll.user32.UnregisterHotKey + MOD_ALT = 0x0001 + MOD_CONTROL = 0x0002 + MOD_SHIFT = 0x0004 + MOD_WIN = 0x0008 MOD_NOREPEAT = 0x4000 - GetMessage = ctypes.windll.user32.GetMessageW - TranslateMessage = ctypes.windll.user32.TranslateMessage - DispatchMessage = ctypes.windll.user32.DispatchMessageW + GetMessage = ctypes.windll.user32.GetMessageW + TranslateMessage = ctypes.windll.user32.TranslateMessage + DispatchMessage = ctypes.windll.user32.DispatchMessageW PostThreadMessage = ctypes.windll.user32.PostThreadMessageW - WM_QUIT = 0x0012 - WM_HOTKEY = 0x0312 - WM_APP = 0x8000 - WM_SND_GOOD = WM_APP + 1 - WM_SND_BAD = WM_APP + 2 + WM_QUIT = 0x0012 + WM_HOTKEY = 0x0312 + WM_APP = 0x8000 + WM_SND_GOOD = WM_APP + 1 + WM_SND_BAD = WM_APP + 2 - GetKeyState = ctypes.windll.user32.GetKeyState - MapVirtualKey = ctypes.windll.user32.MapVirtualKeyW - VK_BACK = 0x08 - VK_CLEAR = 0x0c - VK_RETURN = 0x0d - VK_SHIFT = 0x10 - VK_CONTROL = 0x11 - VK_MENU = 0x12 - VK_CAPITAL = 0x14 - VK_MODECHANGE= 0x1f - VK_ESCAPE = 0x1b - VK_SPACE = 0x20 - VK_DELETE = 0x2e - VK_LWIN = 0x5b - VK_RWIN = 0x5c - VK_NUMPAD0 = 0x60 - VK_DIVIDE = 0x6f - VK_F1 = 0x70 - VK_F24 = 0x87 + GetKeyState = ctypes.windll.user32.GetKeyState + MapVirtualKey = ctypes.windll.user32.MapVirtualKeyW + VK_BACK = 0x08 + VK_CLEAR = 0x0c + VK_RETURN = 0x0d + VK_SHIFT = 0x10 + VK_CONTROL = 0x11 + VK_MENU = 0x12 + VK_CAPITAL = 0x14 + VK_MODECHANGE = 0x1f + VK_ESCAPE = 0x1b + VK_SPACE = 0x20 + VK_DELETE = 0x2e + VK_LWIN = 0x5b + VK_RWIN = 0x5c + VK_NUMPAD0 = 0x60 + VK_DIVIDE = 0x6f + VK_F1 = 0x70 + VK_F24 = 0x87 VK_OEM_MINUS = 0xbd - VK_NUMLOCK = 0x90 - VK_SCROLL = 0x91 - VK_PROCESSKEY= 0xe5 + VK_NUMLOCK = 0x90 + VK_SCROLL = 0x91 + VK_PROCESSKEY = 0xe5 VK_OEM_CLEAR = 0xfe - GetForegroundWindow = ctypes.windll.user32.GetForegroundWindow - GetWindowText = ctypes.windll.user32.GetWindowTextW + GetWindowText = ctypes.windll.user32.GetWindowTextW GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int] GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW - def WindowTitle(h): + def window_title(h) -> str: + """ + Determine the title for a window. + + :param h: Window handle. + :return: Window title. + """ if h: - l = GetWindowTextLength(h) + 1 - buf = ctypes.create_unicode_buffer(l) - if GetWindowText(h, buf, l): + title_length = GetWindowTextLength(h) + 1 + buf = ctypes.create_unicode_buffer(title_length) + if GetWindowText(h, buf, title_length): return buf.value + return '' - class MOUSEINPUT(ctypes.Structure): - _fields_ = [('dx', LONG), ('dy', LONG), ('mouseData', DWORD), ('dwFlags', DWORD), ('time', DWORD), ('dwExtraInfo', ctypes.POINTER(ULONG))] + """Mouse Input structure.""" + + _fields_ = [ + ('dx', LONG), + ('dy', LONG), + ('mouseData', DWORD), + ('dwFlags', DWORD), + ('time', DWORD), + ('dwExtraInfo', ctypes.POINTER(ULONG)) + ] class KEYBDINPUT(ctypes.Structure): - _fields_ = [('wVk', WORD), ('wScan', WORD), ('dwFlags', DWORD), ('time', DWORD), ('dwExtraInfo', ctypes.POINTER(ULONG))] + """Keyboard Input structure.""" + + _fields_ = [ + ('wVk', WORD), + ('wScan', WORD), + ('dwFlags', DWORD), + ('time', DWORD), + ('dwExtraInfo', ctypes.POINTER(ULONG)) + ] class HARDWAREINPUT(ctypes.Structure): - _fields_ = [('uMsg', DWORD), ('wParamL', WORD), ('wParamH', WORD)] + """Hardware Input structure.""" - class INPUT_union(ctypes.Union): - _fields_ = [('mi', MOUSEINPUT), ('ki', KEYBDINPUT), ('hi', HARDWAREINPUT)] + _fields_ = [ + ('uMsg', DWORD), + ('wParamL', WORD), + ('wParamH', WORD) + ] + + class INPUTUNION(ctypes.Union): + """Input union.""" + + _fields_ = [ + ('mi', MOUSEINPUT), + ('ki', KEYBDINPUT), + ('hi', HARDWAREINPUT) + ] class INPUT(ctypes.Structure): - _fields_ = [('type', DWORD), ('union', INPUT_union)] + """Input structure.""" + + _fields_ = [ + ('type', DWORD), + ('union', INPUTUNION) + ] SendInput = ctypes.windll.user32.SendInput SendInput.argtypes = [ctypes.c_uint, ctypes.POINTER(INPUT), ctypes.c_int] @@ -361,19 +401,20 @@ elif platform == 'win32': INPUT_KEYBOARD = 1 INPUT_HARDWARE = 2 - class HotkeyMgr: + """Hot key management.""" # https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx # Limit ourselves to symbols in Windows 7 Segoe UI - DISPLAY = { 0x03: 'Break', 0x08: 'Bksp', 0x09: u'↹', 0x0c: 'Clear', 0x0d: u'↵', 0x13: 'Pause', - 0x14: u'Ⓐ', 0x1b: 'Esc', - 0x20: u'⏘', 0x21: 'PgUp', 0x22: 'PgDn', 0x23: 'End', 0x24: 'Home', - 0x25: u'←', 0x26: u'↑', 0x27: u'→', 0x28: u'↓', - 0x2c: 'PrtScn', 0x2d: 'Ins', 0x2e: 'Del', 0x2f: 'Help', - 0x5d: u'▤', 0x5f: u'☾', - 0x90: u'➀', 0x91: 'ScrLk', - 0xa6: u'⇦', 0xa7: u'⇨', 0xa9: u'⊗', 0xab: u'☆', 0xac: u'⌂', 0xb4: u'✉', + DISPLAY = { + 0x03: 'Break', 0x08: 'Bksp', 0x09: u'↹', 0x0c: 'Clear', 0x0d: u'↵', 0x13: 'Pause', + 0x14: u'Ⓐ', 0x1b: 'Esc', + 0x20: u'⏘', 0x21: 'PgUp', 0x22: 'PgDn', 0x23: 'End', 0x24: 'Home', + 0x25: u'←', 0x26: u'↑', 0x27: u'→', 0x28: u'↓', + 0x2c: 'PrtScn', 0x2d: 'Ins', 0x2e: 'Del', 0x2f: 'Help', + 0x5d: u'▤', 0x5f: u'☾', + 0x90: u'➀', 0x91: 'ScrLk', + 0xa6: u'⇦', 0xa7: u'⇨', 0xa9: u'⊗', 0xab: u'☆', 0xac: u'⌂', 0xb4: u'✉', } def __init__(self): @@ -385,7 +426,7 @@ elif platform == 'win32': self.snd_bad = sb.read() atexit.register(self.unregister) - def register(self, root, keycode, modifiers): + def register(self, root: tk.Tk, keycode, modifiers) -> None: """Register the hotkey handler.""" self.root = root @@ -395,13 +436,17 @@ elif platform == 'win32': if keycode or modifiers: logger.debug('Creating thread worker...') - self.thread = threading.Thread(target=self.worker, name=f'Hotkey "{keycode}:{modifiers}"', args=(keycode, modifiers)) + self.thread = threading.Thread( + target=self.worker, + name=f'Hotkey "{keycode}:{modifiers}"', + args=(keycode, modifiers) + ) self.thread.daemon = True logger.debug('Starting thread worker...') self.thread.start() logger.debug('Done.') - def unregister(self): + def unregister(self) -> None: """Unregister the hotkey handling.""" thread = self.thread @@ -418,7 +463,7 @@ elif platform == 'win32': logger.debug('Done.') - def worker(self, keycode, modifiers): + def worker(self, keycode, modifiers) -> None: # noqa: CCR001 """Handle hotkeys.""" logger.debug('Begin...') # Hotkey must be registered by the thread that handles it @@ -427,7 +472,7 @@ elif platform == 'win32': self.thread = None return - fake = INPUT(INPUT_KEYBOARD, INPUT_union(ki=KEYBDINPUT(keycode, keycode, 0, 0, None))) + fake = INPUT(INPUT_KEYBOARD, INPUTUNION(ki=KEYBDINPUT(keycode, keycode, 0, 0, None))) msg = MSG() logger.debug('Entering GetMessage() loop...') @@ -438,7 +483,7 @@ elif platform == 'win32': if ( config.get_int('hotkey_always') - or WindowTitle(GetForegroundWindow()).startswith('Elite - Dangerous') + or window_title(GetForegroundWindow()).startswith('Elite - Dangerous') ): if not config.shutting_down: logger.debug('Sending event <>') @@ -458,7 +503,7 @@ elif platform == 'win32': elif msg.message == WM_SND_BAD: logger.debug('WM_SND_BAD') - winsound.PlaySound(self.snd_bad, winsound.SND_MEMORY) # synchronous + winsound.PlaySound(self.snd_bad, winsound.SND_MEMORY) # synchronous else: logger.debug('Something else') @@ -470,86 +515,135 @@ elif platform == 'win32': self.thread = None logger.debug('Done.') - def acquire_start(self): + def acquire_start(self) -> None: + """Start acquiring hotkey state via polling.""" pass - def acquire_stop(self): + def acquire_stop(self) -> None: + """Stop acquiring hotkey state.""" pass - def fromevent(self, event): - # event.state is a pain - it shows the state of the modifiers *before* a modifier key was pressed. - # event.state *does* differentiate between left and right Ctrl and Alt and between Return and Enter - # by putting KF_EXTENDED in bit 18, but RegisterHotKey doesn't differentiate. - modifiers = ((GetKeyState(VK_MENU) & 0x8000) and MOD_ALT) | ((GetKeyState(VK_CONTROL) & 0x8000) and MOD_CONTROL) | ((GetKeyState(VK_SHIFT) & 0x8000) and MOD_SHIFT) | ((GetKeyState(VK_LWIN) & 0x8000) and MOD_WIN) | ((GetKeyState(VK_RWIN) & 0x8000) and MOD_WIN) + def fromevent(self, event) -> Optional[Union[bool, Tuple]]: # noqa: CCR001 + """ + Return configuration (keycode, modifiers) or None=clear or False=retain previous. + + event.state is a pain - it shows the state of the modifiers *before* a modifier key was pressed. + event.state *does* differentiate between left and right Ctrl and Alt and between Return and Enter + by putting KF_EXTENDED in bit 18, but RegisterHotKey doesn't differentiate. + + :param event: tk event ? + :return: False to retain previous, None to not use, else (keycode, modifiers) + """ + modifiers = ((GetKeyState(VK_MENU) & 0x8000) and MOD_ALT) \ + | ((GetKeyState(VK_CONTROL) & 0x8000) and MOD_CONTROL) \ + | ((GetKeyState(VK_SHIFT) & 0x8000) and MOD_SHIFT) \ + | ((GetKeyState(VK_LWIN) & 0x8000) and MOD_WIN) \ + | ((GetKeyState(VK_RWIN) & 0x8000) and MOD_WIN) keycode = event.keycode - if keycode in [ VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN ]: + if keycode in [VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN]: return (0, modifiers) + if not modifiers: - if keycode == VK_ESCAPE: # Esc = retain previous + if keycode == VK_ESCAPE: # Esc = retain previous return False - elif keycode in [ VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR ]: # BkSp, Del, Clear = clear hotkey + + elif keycode in [VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR]: # BkSp, Del, Clear = clear hotkey return None - elif keycode in [ VK_RETURN, VK_SPACE, VK_OEM_MINUS] or ord('A') <= keycode <= ord('Z'): # don't allow keys needed for typing in System Map + + elif keycode in [VK_RETURN, VK_SPACE, VK_OEM_MINUS] or ord('A') <= keycode <= ord( + 'Z'): # don't allow keys needed for typing in System Map winsound.MessageBeep() return None - elif keycode in [ VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY ] or VK_CAPITAL <= keycode <= VK_MODECHANGE: # ignore unmodified mode switch keys + + elif (keycode in [VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY] + or VK_CAPITAL <= keycode <= VK_MODECHANGE): # ignore unmodified mode switch keys return (0, modifiers) # See if the keycode is usable and available - if RegisterHotKey(None, 2, modifiers|MOD_NOREPEAT, keycode): + if RegisterHotKey(None, 2, modifiers | MOD_NOREPEAT, keycode): UnregisterHotKey(None, 2) return (keycode, modifiers) + else: winsound.MessageBeep() return None - def display(self, keycode, modifiers): + def display(self, keycode, modifiers) -> str: + """ + Return displayable form of given hotkey + modifiers. + + :param keycode: + :param modifiers: + :return: string form + """ text = '' - if modifiers & MOD_WIN: text += u'❖+' - if modifiers & MOD_CONTROL: text += u'Ctrl+' - if modifiers & MOD_ALT: text += u'Alt+' - if modifiers & MOD_SHIFT: text += u'⇧+' - if VK_NUMPAD0 <= keycode <= VK_DIVIDE: text += u'№' + if modifiers & MOD_WIN: + text += u'❖+' + + if modifiers & MOD_CONTROL: + text += u'Ctrl+' + + if modifiers & MOD_ALT: + text += u'Alt+' + + if modifiers & MOD_SHIFT: + text += u'⇧+' + + if VK_NUMPAD0 <= keycode <= VK_DIVIDE: + text += u'№' if not keycode: pass + elif VK_F1 <= keycode <= VK_F24: - text += 'F%d' % (keycode + 1 - VK_F1) - elif keycode in HotkeyMgr.DISPLAY: # specials + text += f'F{keycode + 1 - VK_F1}' + + elif keycode in HotkeyMgr.DISPLAY: # specials text += HotkeyMgr.DISPLAY[keycode] + else: - c = MapVirtualKey(keycode, 2) # printable ? - if not c: # oops not printable + c = MapVirtualKey(keycode, 2) # printable ? + if not c: # oops not printable text += u'⁈' - elif c < 0x20: # control keys - text += chr(c+0x40) + + elif c < 0x20: # control keys + text += chr(c + 0x40) + else: text += chr(c).upper() + return text - def play_good(self): + def play_good(self) -> None: + """Play the 'good' sound.""" if self.thread: PostThreadMessage(self.thread.ident, WM_SND_GOOD, 0, 0) - def play_bad(self): + def play_bad(self) -> None: + """Play the 'bad' sound.""" if self.thread: PostThreadMessage(self.thread.ident, WM_SND_BAD, 0, 0) -else: # Linux +else: # Linux class HotkeyMgr: + """Hot key management.""" - def register(self, root, keycode, modifiers): + def register(self, root, keycode, modifiers) -> None: + """Register the hotkey handler.""" pass - def unregister(self): + def unregister(self) -> None: + """Unregister the hotkey handling.""" pass - def play_good(self): + def play_good(self) -> None: + """Play the 'good' sound.""" pass - def play_bad(self): + def play_bad(self) -> None: + """Play the 'bad' sound.""" pass # singleton From 1073a15fa2516c94187dbf4ed2ab4996a8de5627 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 16:55:15 +0100 Subject: [PATCH 548/727] Need tkinter always, not just TYPE_CHECKING --- hotkey.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hotkey.py b/hotkey.py index a185c822..8255bcf4 100644 --- a/hotkey.py +++ b/hotkey.py @@ -2,16 +2,13 @@ # -*- coding: utf-8 -*- import pathlib +import tkinter as tk from sys import platform from typing import TYPE_CHECKING, Optional, Tuple, Union from config import config from EDMCLogging import get_main_logger -# isort: off -if TYPE_CHECKING: - import tkinter as tk -# isort: on logger = get_main_logger() From 8aa0337ff45cae22d1d34b99ea87b76452b55f7e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 17:00:51 +0100 Subject: [PATCH 549/727] Small imports tidy up. --- hotkey.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hotkey.py b/hotkey.py index 8255bcf4..ba8c4560 100644 --- a/hotkey.py +++ b/hotkey.py @@ -4,12 +4,11 @@ import pathlib import tkinter as tk from sys import platform -from typing import TYPE_CHECKING, Optional, Tuple, Union +from typing import Optional, Tuple, Union from config import config from EDMCLogging import get_main_logger - logger = get_main_logger() if platform == 'darwin': # noqa: C901 From e0a3f1ad537232aa1c91ea291fc44ef539f56eac Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 17:16:54 +0100 Subject: [PATCH 550/727] hotkey: Basic conversion to Abstract class, and implementation per platform --- hotkey.py | 861 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 449 insertions(+), 412 deletions(-) diff --git a/hotkey.py b/hotkey.py index ba8c4560..256ed2f5 100644 --- a/hotkey.py +++ b/hotkey.py @@ -1,9 +1,11 @@ """Handle keyboard input for manual update triggering.""" # -*- coding: utf-8 -*- +import abc import pathlib +import sys import tkinter as tk -from sys import platform +from abc import abstractmethod from typing import Optional, Tuple, Union from config import config @@ -11,7 +13,32 @@ from EDMCLogging import get_main_logger logger = get_main_logger() -if platform == 'darwin': # noqa: C901 + +class AbstractHotkeyMgr(abc.abstractmethod): + """Abstract root class of all platforms specific HotKeyMgr.""" + + @abstractmethod + def register(self, root, keycode, modifiers) -> None: + """Register the hotkey handler.""" + pass + + @abstractmethod + def unregister(self) -> None: + """Unregister the hotkey handling.""" + pass + + @abstractmethod + def play_good(self) -> None: + """Play the 'good' sound.""" + pass + + @abstractmethod + def play_bad(self) -> None: + """Play the 'bad' sound.""" + pass + + +if sys.platform == 'darwin': import objc from AppKit import ( @@ -20,257 +47,258 @@ if platform == 'darwin': # noqa: C901 NSFlagsChanged, NSKeyDown, NSKeyDownMask, NSKeyUp, NSNumericPadKeyMask, NSShiftKeyMask, NSSound, NSWorkspace ) - class HotkeyMgr: - """Hot key management.""" - MODIFIERMASK = NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask | NSNumericPadKeyMask - POLL = 250 - # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/#//apple_ref/doc/constant_group/Function_Key_Unicodes - DISPLAY = { - 0x03: u'⌅', 0x09: u'⇥', 0xd: u'↩', 0x19: u'⇤', 0x1b: u'esc', 0x20: u'⏘', 0x7f: u'⌫', - 0xf700: u'↑', 0xf701: u'↓', 0xf702: u'←', 0xf703: u'→', - 0xf727: u'Ins', - 0xf728: u'⌦', 0xf729: u'↖', 0xf72a: u'Fn', 0xf72b: u'↘', - 0xf72c: u'⇞', 0xf72d: u'⇟', 0xf72e: u'PrtScr', 0xf72f: u'ScrollLock', - 0xf730: u'Pause', 0xf731: u'SysReq', 0xf732: u'Break', 0xf733: u'Reset', - 0xf739: u'⌧', - } - (ACQUIRE_INACTIVE, ACQUIRE_ACTIVE, ACQUIRE_NEW) = range(3) +class MacHotkeyMgr(AbstractHotkeyMgr): + """Hot key management.""" - def __init__(self): - self.root = None + MODIFIERMASK = NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask | NSNumericPadKeyMask + POLL = 250 + # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/#//apple_ref/doc/constant_group/Function_Key_Unicodes + DISPLAY = { + 0x03: u'⌅', 0x09: u'⇥', 0xd: u'↩', 0x19: u'⇤', 0x1b: u'esc', 0x20: u'⏘', 0x7f: u'⌫', + 0xf700: u'↑', 0xf701: u'↓', 0xf702: u'←', 0xf703: u'→', + 0xf727: u'Ins', + 0xf728: u'⌦', 0xf729: u'↖', 0xf72a: u'Fn', 0xf72b: u'↘', + 0xf72c: u'⇞', 0xf72d: u'⇟', 0xf72e: u'PrtScr', 0xf72f: u'ScrollLock', + 0xf730: u'Pause', 0xf731: u'SysReq', 0xf732: u'Break', 0xf733: u'Reset', + 0xf739: u'⌧', + } + (ACQUIRE_INACTIVE, ACQUIRE_ACTIVE, ACQUIRE_NEW) = range(3) - self.keycode = 0 - self.modifiers = 0 - self.activated = False - self.observer = None + def __init__(self): + self.root = None - self.acquire_key = 0 - self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE + self.keycode = 0 + self.modifiers = 0 + self.activated = False + self.observer = None - self.tkProcessKeyEvent_old = None + self.acquire_key = 0 + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE - self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_( - pathlib.Path(config.respath_path) / 'snd_good.wav', False + self.tkProcessKeyEvent_old = None + + self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_( + pathlib.Path(config.respath_path) / 'snd_good.wav', False + ) + self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_( + pathlib.Path(config.respath_path) / 'snd_bad.wav', False + ) + + def register(self, root: tk.Tk, keycode, modifiers) -> None: + """ + Register current hotkey for monitoring. + + :param root: parent window. + :param keycode: Key to monitor. + :param modifiers: Any modifiers to take into account. + """ + self.root = root + self.keycode = keycode + self.modifiers = modifiers + self.activated = False + + if keycode: + if not self.observer: + self.root.after_idle(self._observe) + self.root.after(MacHotkeyMgr.POLL, self._poll) + + # Monkey-patch tk (tkMacOSXKeyEvent.c) + if not self.tkProcessKeyEvent_old: + sel = b'tkProcessKeyEvent:' + cls = NSApplication.sharedApplication().class__() + self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel) + newmethod = objc.selector( + self.tkProcessKeyEvent, + selector=self.tkProcessKeyEvent_old.selector, + signature=self.tkProcessKeyEvent_old.signature ) - self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_( - pathlib.Path(config.respath_path) / 'snd_bad.wav', False + objc.classAddMethod(cls, sel, newmethod) + + def tkProcessKeyEvent(self, cls, the_event): # noqa: N802 + """ + Monkey-patch tk (tkMacOSXKeyEvent.c). + + - workaround crash on OSX 10.9 & 10.10 on seeing a composing character + - notice when modifier key state changes + - keep a copy of NSEvent.charactersIgnoringModifiers, which is what we need for the hotkey + + (Would like to use a decorator but need to ensure the application is created before this is installed) + :param cls: ??? + :param the_event: tk event + :return: ??? + """ + if self.acquire_state: + if the_event.type() == NSFlagsChanged: + self.acquire_key = the_event.modifierFlags() & NSDeviceIndependentModifierFlagsMask + self.acquire_state = MacHotkeyMgr.ACQUIRE_NEW + # suppress the event by not chaining the old function + return the_event + + elif the_event.type() in (NSKeyDown, NSKeyUp): + c = the_event.charactersIgnoringModifiers() + self.acquire_key = (c and ord(c[0]) or 0) | \ + (the_event.modifierFlags() & NSDeviceIndependentModifierFlagsMask) + self.acquire_state = MacHotkeyMgr.ACQUIRE_NEW + # suppress the event by not chaining the old function + return the_event + + # replace empty characters with charactersIgnoringModifiers to avoid crash + elif the_event.type() in (NSKeyDown, NSKeyUp) and not the_event.characters(): + the_event = NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( # noqa: E501 + # noqa: E501 + the_event.type(), + the_event.locationInWindow(), + the_event.modifierFlags(), + the_event.timestamp(), + the_event.windowNumber(), + the_event.context(), + the_event.charactersIgnoringModifiers(), + the_event.charactersIgnoringModifiers(), + the_event.isARepeat(), + the_event.keyCode() ) + return self.tkProcessKeyEvent_old(cls, the_event) - def register(self, root: tk.Tk, keycode, modifiers) -> None: - """ - Register current hotkey for monitoring. + def _observe(self): + # Must be called after root.mainloop() so that the app's message loop has been created + self.observer = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, self._handler) - :param root: parent window. - :param keycode: Key to monitor. - :param modifiers: Any modifiers to take into account. - """ - self.root = root - self.keycode = keycode - self.modifiers = modifiers + def _poll(self): + if config.shutting_down: + return + + # No way of signalling to Tkinter from within the callback handler block that doesn't + # cause Python to crash, so poll. + if self.activated: self.activated = False + self.root.event_generate('<>', when="tail") - if keycode: - if not self.observer: - self.root.after_idle(self._observe) - self.root.after(HotkeyMgr.POLL, self._poll) + if self.keycode or self.modifiers: + self.root.after(MacHotkeyMgr.POLL, self._poll) - # Monkey-patch tk (tkMacOSXKeyEvent.c) - if not self.tkProcessKeyEvent_old: - sel = b'tkProcessKeyEvent:' - cls = NSApplication.sharedApplication().class__() - self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel) - newmethod = objc.selector( - self.tkProcessKeyEvent, - selector=self.tkProcessKeyEvent_old.selector, - signature=self.tkProcessKeyEvent_old.signature - ) - objc.classAddMethod(cls, sel, newmethod) + def unregister(self) -> None: + """Remove hotkey registration.""" + self.keycode = None + self.modifiers = None - def tkProcessKeyEvent(self, cls, the_event): # noqa: N802 - """ - Monkey-patch tk (tkMacOSXKeyEvent.c). + @objc.callbackFor(NSEvent.addGlobalMonitorForEventsMatchingMask_handler_) + def _handler(self, event) -> None: + # use event.charactersIgnoringModifiers to handle composing characters like Alt-e + if ((event.modifierFlags() & MacHotkeyMgr.MODIFIERMASK) == self.modifiers + and ord(event.charactersIgnoringModifiers()[0]) == self.keycode): + if config.get_int('hotkey_always'): + self.activated = True - - workaround crash on OSX 10.9 & 10.10 on seeing a composing character - - notice when modifier key state changes - - keep a copy of NSEvent.charactersIgnoringModifiers, which is what we need for the hotkey - - (Would like to use a decorator but need to ensure the application is created before this is installed) - :param cls: ??? - :param the_event: tk event - :return: ??? - """ - if self.acquire_state: - if the_event.type() == NSFlagsChanged: - self.acquire_key = the_event.modifierFlags() & NSDeviceIndependentModifierFlagsMask - self.acquire_state = HotkeyMgr.ACQUIRE_NEW - # suppress the event by not chaining the old function - return the_event - - elif the_event.type() in (NSKeyDown, NSKeyUp): - c = the_event.charactersIgnoringModifiers() - self.acquire_key = (c and ord(c[0]) or 0) | \ - (the_event.modifierFlags() & NSDeviceIndependentModifierFlagsMask) - self.acquire_state = HotkeyMgr.ACQUIRE_NEW - # suppress the event by not chaining the old function - return the_event - - # replace empty characters with charactersIgnoringModifiers to avoid crash - elif the_event.type() in (NSKeyDown, NSKeyUp) and not the_event.characters(): - the_event = NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( # noqa: E501 - # noqa: E501 - the_event.type(), - the_event.locationInWindow(), - the_event.modifierFlags(), - the_event.timestamp(), - the_event.windowNumber(), - the_event.context(), - the_event.charactersIgnoringModifiers(), - the_event.charactersIgnoringModifiers(), - the_event.isARepeat(), - the_event.keyCode() - ) - return self.tkProcessKeyEvent_old(cls, the_event) - - def _observe(self): - # Must be called after root.mainloop() so that the app's message loop has been created - self.observer = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSKeyDownMask, self._handler) - - def _poll(self): - if config.shutting_down: - return - - # No way of signalling to Tkinter from within the callback handler block that doesn't - # cause Python to crash, so poll. - if self.activated: - self.activated = False - self.root.event_generate('<>', when="tail") - - if self.keycode or self.modifiers: - self.root.after(HotkeyMgr.POLL, self._poll) - - def unregister(self) -> None: - """Remove hotkey registration.""" - self.keycode = None - self.modifiers = None - - @objc.callbackFor(NSEvent.addGlobalMonitorForEventsMatchingMask_handler_) - def _handler(self, event) -> None: - # use event.charactersIgnoringModifiers to handle composing characters like Alt-e - if ((event.modifierFlags() & HotkeyMgr.MODIFIERMASK) == self.modifiers - and ord(event.charactersIgnoringModifiers()[0]) == self.keycode): - if config.get_int('hotkey_always'): + else: # Only trigger if game client is front process + front = NSWorkspace.sharedWorkspace().frontmostApplication() + if front and front.bundleIdentifier() == 'uk.co.frontier.EliteDangerous': self.activated = True - else: # Only trigger if game client is front process - front = NSWorkspace.sharedWorkspace().frontmostApplication() - if front and front.bundleIdentifier() == 'uk.co.frontier.EliteDangerous': - self.activated = True + def acquire_start(self) -> None: + """Start acquiring hotkey state via polling.""" + self.acquire_state = MacHotkeyMgr.ACQUIRE_ACTIVE + self.root.after_idle(self._acquire_poll) - def acquire_start(self) -> None: - """Start acquiring hotkey state via polling.""" - self.acquire_state = HotkeyMgr.ACQUIRE_ACTIVE - self.root.after_idle(self._acquire_poll) + def acquire_stop(self) -> None: + """Stop acquiring hotkey state.""" + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE - def acquire_stop(self) -> None: - """Stop acquiring hotkey state.""" - self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE + def _acquire_poll(self) -> None: + """Perform a poll of current hotkey state.""" + if config.shutting_down: + return - def _acquire_poll(self) -> None: - """Perform a poll of current hotkey state.""" - if config.shutting_down: - return + # No way of signalling to Tkinter from within the monkey-patched event handler that doesn't + # cause Python to crash, so poll. + if self.acquire_state: + if self.acquire_state == MacHotkeyMgr.ACQUIRE_NEW: + # Abuse tkEvent's keycode field to hold our acquired key & modifier + self.root.event_generate('', keycode=self.acquire_key) + self.acquire_state = MacHotkeyMgr.ACQUIRE_ACTIVE + self.root.after(50, self._acquire_poll) - # No way of signalling to Tkinter from within the monkey-patched event handler that doesn't - # cause Python to crash, so poll. - if self.acquire_state: - if self.acquire_state == HotkeyMgr.ACQUIRE_NEW: - # Abuse tkEvent's keycode field to hold our acquired key & modifier - self.root.event_generate('', keycode=self.acquire_key) - self.acquire_state = HotkeyMgr.ACQUIRE_ACTIVE - self.root.after(50, self._acquire_poll) + def fromevent(self, event) -> Optional[Union[bool, Tuple]]: + """ + Return configuration (keycode, modifiers) or None=clear or False=retain previous. - def fromevent(self, event) -> Optional[Union[bool, Tuple]]: - """ - Return configuration (keycode, modifiers) or None=clear or False=retain previous. + :param event: tk event ? + :return: False to retain previous, None to not use, else (keycode, modifiers) + """ + (keycode, modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000) # Set by _acquire_poll() + if (keycode + and not (modifiers & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask))): + if keycode == 0x1b: # Esc = retain previous + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE + return False - :param event: tk event ? - :return: False to retain previous, None to not use, else (keycode, modifiers) - """ - (keycode, modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000) # Set by _acquire_poll() - if (keycode - and not (modifiers & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask))): - if keycode == 0x1b: # Esc = retain previous - self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE - return False + # BkSp, Del, Clear = clear hotkey + elif keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]: + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE + return None - # BkSp, Del, Clear = clear hotkey - elif keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]: - self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE - return None + # don't allow keys needed for typing in System Map + elif keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a: + NSBeep() + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE + return None - # don't allow keys needed for typing in System Map - elif keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a: - NSBeep() - self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE - return None + return (keycode, modifiers) - return (keycode, modifiers) + def display(self, keycode, modifiers) -> str: + """ + Return displayable form of given hotkey + modifiers. - def display(self, keycode, modifiers) -> str: - """ - Return displayable form of given hotkey + modifiers. + :param keycode: + :param modifiers: + :return: string form + """ + text = '' + if modifiers & NSControlKeyMask: + text += u'⌃' - :param keycode: - :param modifiers: - :return: string form - """ - text = '' - if modifiers & NSControlKeyMask: - text += u'⌃' + if modifiers & NSAlternateKeyMask: + text += u'⌥' - if modifiers & NSAlternateKeyMask: - text += u'⌥' + if modifiers & NSShiftKeyMask: + text += u'⇧' - if modifiers & NSShiftKeyMask: - text += u'⇧' + if modifiers & NSCommandKeyMask: + text += u'⌘' - if modifiers & NSCommandKeyMask: - text += u'⌘' + if (modifiers & NSNumericPadKeyMask) and keycode <= 0x7f: + text += u'№' - if (modifiers & NSNumericPadKeyMask) and keycode <= 0x7f: - text += u'№' + if not keycode: + pass - if not keycode: - pass + elif ord(NSF1FunctionKey) <= keycode <= ord(NSF35FunctionKey): + text += f'F{keycode + 1 - ord(NSF1FunctionKey)}' - elif ord(NSF1FunctionKey) <= keycode <= ord(NSF35FunctionKey): - text += f'F{keycode + 1 - ord(NSF1FunctionKey)}' + elif keycode in MacHotkeyMgr.DISPLAY: # specials + text += MacHotkeyMgr.DISPLAY[keycode] - elif keycode in HotkeyMgr.DISPLAY: # specials - text += HotkeyMgr.DISPLAY[keycode] + elif keycode < 0x20: # control keys + text += chr(keycode + 0x40) - elif keycode < 0x20: # control keys - text += chr(keycode + 0x40) + elif keycode < 0xf700: # key char + text += chr(keycode).upper() - elif keycode < 0xf700: # key char - text += chr(keycode).upper() + else: + text += u'⁈' - else: - text += u'⁈' + return text - return text + def play_good(self): + """Play the 'good' sound.""" + self.snd_good.play() - def play_good(self): - """Play the 'good' sound.""" - self.snd_good.play() - - def play_bad(self): - """Play the 'bad' sound.""" - self.snd_bad.play() + def play_bad(self): + """Play the 'bad' sound.""" + self.snd_bad.play() -elif platform == 'win32': +if sys.platform == 'win32': import atexit import ctypes @@ -397,250 +425,259 @@ elif platform == 'win32': INPUT_KEYBOARD = 1 INPUT_HARDWARE = 2 - class HotkeyMgr: - """Hot key management.""" - # https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx - # Limit ourselves to symbols in Windows 7 Segoe UI - DISPLAY = { - 0x03: 'Break', 0x08: 'Bksp', 0x09: u'↹', 0x0c: 'Clear', 0x0d: u'↵', 0x13: 'Pause', - 0x14: u'Ⓐ', 0x1b: 'Esc', - 0x20: u'⏘', 0x21: 'PgUp', 0x22: 'PgDn', 0x23: 'End', 0x24: 'Home', - 0x25: u'←', 0x26: u'↑', 0x27: u'→', 0x28: u'↓', - 0x2c: 'PrtScn', 0x2d: 'Ins', 0x2e: 'Del', 0x2f: 'Help', - 0x5d: u'▤', 0x5f: u'☾', - 0x90: u'➀', 0x91: 'ScrLk', - 0xa6: u'⇦', 0xa7: u'⇨', 0xa9: u'⊗', 0xab: u'☆', 0xac: u'⌂', 0xb4: u'✉', - } +class WindowsHotkeyMgr(AbstractHotkeyMgr): + """Hot key management.""" - def __init__(self): - self.root = None - self.thread = None - with open(pathlib.Path(config.respath) / 'snd_good.wav', 'rb') as sg: - self.snd_good = sg.read() - with open(pathlib.Path(config.respath) / 'snd_bad.wav', 'rb') as sb: - self.snd_bad = sb.read() - atexit.register(self.unregister) + # https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx + # Limit ourselves to symbols in Windows 7 Segoe UI + DISPLAY = { + 0x03: 'Break', 0x08: 'Bksp', 0x09: u'↹', 0x0c: 'Clear', 0x0d: u'↵', 0x13: 'Pause', + 0x14: u'Ⓐ', 0x1b: 'Esc', + 0x20: u'⏘', 0x21: 'PgUp', 0x22: 'PgDn', 0x23: 'End', 0x24: 'Home', + 0x25: u'←', 0x26: u'↑', 0x27: u'→', 0x28: u'↓', + 0x2c: 'PrtScn', 0x2d: 'Ins', 0x2e: 'Del', 0x2f: 'Help', + 0x5d: u'▤', 0x5f: u'☾', + 0x90: u'➀', 0x91: 'ScrLk', + 0xa6: u'⇦', 0xa7: u'⇨', 0xa9: u'⊗', 0xab: u'☆', 0xac: u'⌂', 0xb4: u'✉', + } - def register(self, root: tk.Tk, keycode, modifiers) -> None: - """Register the hotkey handler.""" - self.root = root + def __init__(self): + self.root = None + self.thread = None + with open(pathlib.Path(config.respath) / 'snd_good.wav', 'rb') as sg: + self.snd_good = sg.read() + with open(pathlib.Path(config.respath) / 'snd_bad.wav', 'rb') as sb: + self.snd_bad = sb.read() + atexit.register(self.unregister) - if self.thread: - logger.debug('Was already registered, unregistering...') - self.unregister() + def register(self, root: tk.Tk, keycode, modifiers) -> None: + """Register the hotkey handler.""" + self.root = root - if keycode or modifiers: - logger.debug('Creating thread worker...') - self.thread = threading.Thread( - target=self.worker, - name=f'Hotkey "{keycode}:{modifiers}"', - args=(keycode, modifiers) - ) - self.thread.daemon = True - logger.debug('Starting thread worker...') - self.thread.start() - logger.debug('Done.') - - def unregister(self) -> None: - """Unregister the hotkey handling.""" - thread = self.thread - - if thread: - logger.debug('Thread is/was running') - self.thread = None - logger.debug('Telling thread WM_QUIT') - PostThreadMessage(thread.ident, WM_QUIT, 0, 0) - logger.debug('Joining thread') - thread.join() # Wait for it to unregister hotkey and quit - - else: - logger.debug('No thread') + if self.thread: + logger.debug('Was already registered, unregistering...') + self.unregister() + if keycode or modifiers: + logger.debug('Creating thread worker...') + self.thread = threading.Thread( + target=self.worker, + name=f'Hotkey "{keycode}:{modifiers}"', + args=(keycode, modifiers) + ) + self.thread.daemon = True + logger.debug('Starting thread worker...') + self.thread.start() logger.debug('Done.') - def worker(self, keycode, modifiers) -> None: # noqa: CCR001 - """Handle hotkeys.""" - logger.debug('Begin...') - # Hotkey must be registered by the thread that handles it - if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode): - logger.debug("We're not the right thread?") - self.thread = None - return + def unregister(self) -> None: + """Unregister the hotkey handling.""" + thread = self.thread - fake = INPUT(INPUT_KEYBOARD, INPUTUNION(ki=KEYBDINPUT(keycode, keycode, 0, 0, None))) + if thread: + logger.debug('Thread is/was running') + self.thread = None + logger.debug('Telling thread WM_QUIT') + PostThreadMessage(thread.ident, WM_QUIT, 0, 0) + logger.debug('Joining thread') + thread.join() # Wait for it to unregister hotkey and quit - msg = MSG() - logger.debug('Entering GetMessage() loop...') - while GetMessage(ctypes.byref(msg), None, 0, 0) != 0: - logger.debug('Got message') - if msg.message == WM_HOTKEY: - logger.debug('WM_HOTKEY') + else: + logger.debug('No thread') - if ( - config.get_int('hotkey_always') - or window_title(GetForegroundWindow()).startswith('Elite - Dangerous') - ): - if not config.shutting_down: - logger.debug('Sending event <>') - self.root.event_generate('<>', when="tail") + logger.debug('Done.') - else: - logger.debug('Passing key on') - UnregisterHotKey(None, 1) - SendInput(1, fake, ctypes.sizeof(INPUT)) - if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode): - logger.debug("We aren't registered for this ?") - break + def worker(self, keycode, modifiers) -> None: # noqa: CCR001 + """Handle hotkeys.""" + logger.debug('Begin...') + # Hotkey must be registered by the thread that handles it + if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode): + logger.debug("We're not the right thread?") + self.thread = None + return - elif msg.message == WM_SND_GOOD: - logger.debug('WM_SND_GOOD') - winsound.PlaySound(self.snd_good, winsound.SND_MEMORY) # synchronous + fake = INPUT(INPUT_KEYBOARD, INPUTUNION(ki=KEYBDINPUT(keycode, keycode, 0, 0, None))) - elif msg.message == WM_SND_BAD: - logger.debug('WM_SND_BAD') - winsound.PlaySound(self.snd_bad, winsound.SND_MEMORY) # synchronous + msg = MSG() + logger.debug('Entering GetMessage() loop...') + while GetMessage(ctypes.byref(msg), None, 0, 0) != 0: + logger.debug('Got message') + if msg.message == WM_HOTKEY: + logger.debug('WM_HOTKEY') + + if ( + config.get_int('hotkey_always') + or window_title(GetForegroundWindow()).startswith('Elite - Dangerous') + ): + if not config.shutting_down: + logger.debug('Sending event <>') + self.root.event_generate('<>', when="tail") else: - logger.debug('Something else') - TranslateMessage(ctypes.byref(msg)) - DispatchMessage(ctypes.byref(msg)) + logger.debug('Passing key on') + UnregisterHotKey(None, 1) + SendInput(1, fake, ctypes.sizeof(INPUT)) + if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode): + logger.debug("We aren't registered for this ?") + break - logger.debug('Exited GetMessage() loop.') - UnregisterHotKey(None, 1) - self.thread = None - logger.debug('Done.') + elif msg.message == WM_SND_GOOD: + logger.debug('WM_SND_GOOD') + winsound.PlaySound(self.snd_good, winsound.SND_MEMORY) # synchronous - def acquire_start(self) -> None: - """Start acquiring hotkey state via polling.""" - pass - - def acquire_stop(self) -> None: - """Stop acquiring hotkey state.""" - pass - - def fromevent(self, event) -> Optional[Union[bool, Tuple]]: # noqa: CCR001 - """ - Return configuration (keycode, modifiers) or None=clear or False=retain previous. - - event.state is a pain - it shows the state of the modifiers *before* a modifier key was pressed. - event.state *does* differentiate between left and right Ctrl and Alt and between Return and Enter - by putting KF_EXTENDED in bit 18, but RegisterHotKey doesn't differentiate. - - :param event: tk event ? - :return: False to retain previous, None to not use, else (keycode, modifiers) - """ - modifiers = ((GetKeyState(VK_MENU) & 0x8000) and MOD_ALT) \ - | ((GetKeyState(VK_CONTROL) & 0x8000) and MOD_CONTROL) \ - | ((GetKeyState(VK_SHIFT) & 0x8000) and MOD_SHIFT) \ - | ((GetKeyState(VK_LWIN) & 0x8000) and MOD_WIN) \ - | ((GetKeyState(VK_RWIN) & 0x8000) and MOD_WIN) - keycode = event.keycode - - if keycode in [VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN]: - return (0, modifiers) - - if not modifiers: - if keycode == VK_ESCAPE: # Esc = retain previous - return False - - elif keycode in [VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR]: # BkSp, Del, Clear = clear hotkey - return None - - elif keycode in [VK_RETURN, VK_SPACE, VK_OEM_MINUS] or ord('A') <= keycode <= ord( - 'Z'): # don't allow keys needed for typing in System Map - winsound.MessageBeep() - return None - - elif (keycode in [VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY] - or VK_CAPITAL <= keycode <= VK_MODECHANGE): # ignore unmodified mode switch keys - return (0, modifiers) - - # See if the keycode is usable and available - if RegisterHotKey(None, 2, modifiers | MOD_NOREPEAT, keycode): - UnregisterHotKey(None, 2) - return (keycode, modifiers) + elif msg.message == WM_SND_BAD: + logger.debug('WM_SND_BAD') + winsound.PlaySound(self.snd_bad, winsound.SND_MEMORY) # synchronous else: + logger.debug('Something else') + TranslateMessage(ctypes.byref(msg)) + DispatchMessage(ctypes.byref(msg)) + + logger.debug('Exited GetMessage() loop.') + UnregisterHotKey(None, 1) + self.thread = None + logger.debug('Done.') + + def acquire_start(self) -> None: + """Start acquiring hotkey state via polling.""" + pass + + def acquire_stop(self) -> None: + """Stop acquiring hotkey state.""" + pass + + def fromevent(self, event) -> Optional[Union[bool, Tuple]]: # noqa: CCR001 + """ + Return configuration (keycode, modifiers) or None=clear or False=retain previous. + + event.state is a pain - it shows the state of the modifiers *before* a modifier key was pressed. + event.state *does* differentiate between left and right Ctrl and Alt and between Return and Enter + by putting KF_EXTENDED in bit 18, but RegisterHotKey doesn't differentiate. + + :param event: tk event ? + :return: False to retain previous, None to not use, else (keycode, modifiers) + """ + modifiers = ((GetKeyState(VK_MENU) & 0x8000) and MOD_ALT) \ + | ((GetKeyState(VK_CONTROL) & 0x8000) and MOD_CONTROL) \ + | ((GetKeyState(VK_SHIFT) & 0x8000) and MOD_SHIFT) \ + | ((GetKeyState(VK_LWIN) & 0x8000) and MOD_WIN) \ + | ((GetKeyState(VK_RWIN) & 0x8000) and MOD_WIN) + keycode = event.keycode + + if keycode in [VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN]: + return (0, modifiers) + + if not modifiers: + if keycode == VK_ESCAPE: # Esc = retain previous + return False + + elif keycode in [VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR]: # BkSp, Del, Clear = clear hotkey + return None + + elif keycode in [VK_RETURN, VK_SPACE, VK_OEM_MINUS] or ord('A') <= keycode <= ord( + 'Z'): # don't allow keys needed for typing in System Map winsound.MessageBeep() return None - def display(self, keycode, modifiers) -> str: - """ - Return displayable form of given hotkey + modifiers. + elif (keycode in [VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY] + or VK_CAPITAL <= keycode <= VK_MODECHANGE): # ignore unmodified mode switch keys + return (0, modifiers) - :param keycode: - :param modifiers: - :return: string form - """ - text = '' - if modifiers & MOD_WIN: - text += u'❖+' + # See if the keycode is usable and available + if RegisterHotKey(None, 2, modifiers | MOD_NOREPEAT, keycode): + UnregisterHotKey(None, 2) + return (keycode, modifiers) - if modifiers & MOD_CONTROL: - text += u'Ctrl+' + else: + winsound.MessageBeep() + return None - if modifiers & MOD_ALT: - text += u'Alt+' + def display(self, keycode, modifiers) -> str: + """ + Return displayable form of given hotkey + modifiers. - if modifiers & MOD_SHIFT: - text += u'⇧+' + :param keycode: + :param modifiers: + :return: string form + """ + text = '' + if modifiers & MOD_WIN: + text += u'❖+' - if VK_NUMPAD0 <= keycode <= VK_DIVIDE: - text += u'№' + if modifiers & MOD_CONTROL: + text += u'Ctrl+' - if not keycode: - pass + if modifiers & MOD_ALT: + text += u'Alt+' - elif VK_F1 <= keycode <= VK_F24: - text += f'F{keycode + 1 - VK_F1}' + if modifiers & MOD_SHIFT: + text += u'⇧+' - elif keycode in HotkeyMgr.DISPLAY: # specials - text += HotkeyMgr.DISPLAY[keycode] + if VK_NUMPAD0 <= keycode <= VK_DIVIDE: + text += u'№' + + if not keycode: + pass + + elif VK_F1 <= keycode <= VK_F24: + text += f'F{keycode + 1 - VK_F1}' + + elif keycode in WindowsHotkeyMgr.DISPLAY: # specials + text += WindowsHotkeyMgr.DISPLAY[keycode] + + else: + c = MapVirtualKey(keycode, 2) # printable ? + if not c: # oops not printable + text += u'⁈' + + elif c < 0x20: # control keys + text += chr(c + 0x40) else: - c = MapVirtualKey(keycode, 2) # printable ? - if not c: # oops not printable - text += u'⁈' + text += chr(c).upper() - elif c < 0x20: # control keys - text += chr(c + 0x40) + return text - else: - text += chr(c).upper() + def play_good(self) -> None: + """Play the 'good' sound.""" + if self.thread: + PostThreadMessage(self.thread.ident, WM_SND_GOOD, 0, 0) - return text + def play_bad(self) -> None: + """Play the 'bad' sound.""" + if self.thread: + PostThreadMessage(self.thread.ident, WM_SND_BAD, 0, 0) - def play_good(self) -> None: - """Play the 'good' sound.""" - if self.thread: - PostThreadMessage(self.thread.ident, WM_SND_GOOD, 0, 0) - def play_bad(self) -> None: - """Play the 'bad' sound.""" - if self.thread: - PostThreadMessage(self.thread.ident, WM_SND_BAD, 0, 0) +class LinuxHotKeyMgr(AbstractHotkeyMgr): + """Hot key management.""" -else: # Linux + pass - class HotkeyMgr: - """Hot key management.""" - def register(self, root, keycode, modifiers) -> None: - """Register the hotkey handler.""" - pass +def get_hotkeymgr(*args, **kwargs) -> AbstractHotkeyMgr: + """ + Determine platform-specific HotkeyMgr. - def unregister(self) -> None: - """Unregister the hotkey handling.""" - pass + :param args: + :param kwargs: + :return: Appropriate class instance. + :raises ValueError: If unsupported platform. + """ + if sys.platform == 'darwin': + return MacHotkeyMgr(*args, **kwargs) - def play_good(self) -> None: - """Play the 'good' sound.""" - pass + elif sys.platform == 'win32': + return WindowsHotkeyMgr(*args, **kwargs) + + elif sys.platform == 'linux': + return LinuxHotKeyMgr(*args, **kwargs) + + else: + raise ValueError(f'Unknown platform: {sys.platform}') - def play_bad(self) -> None: - """Play the 'bad' sound.""" - pass # singleton -hotkeymgr = HotkeyMgr() +hotkeymgr = get_hotkeymgr() From 9c8714177e658c66e7ff65e871da6bf349816ef2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 17:27:57 +0100 Subject: [PATCH 551/727] hotkey: Now runs on win32, despite MacHotkeyMgr class. --- hotkey.py | 172 +++++++++++++++++++++++++++--------------------------- 1 file changed, 87 insertions(+), 85 deletions(-) diff --git a/hotkey.py b/hotkey.py index 256ed2f5..ff97ec4e 100644 --- a/hotkey.py +++ b/hotkey.py @@ -14,7 +14,7 @@ from EDMCLogging import get_main_logger logger = get_main_logger() -class AbstractHotkeyMgr(abc.abstractmethod): +class AbstractHotkeyMgr(abc.ABC): """Abstract root class of all platforms specific HotKeyMgr.""" @abstractmethod @@ -51,7 +51,6 @@ if sys.platform == 'darwin': class MacHotkeyMgr(AbstractHotkeyMgr): """Hot key management.""" - MODIFIERMASK = NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask | NSNumericPadKeyMask POLL = 250 # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/#//apple_ref/doc/constant_group/Function_Key_Unicodes DISPLAY = { @@ -66,6 +65,8 @@ class MacHotkeyMgr(AbstractHotkeyMgr): (ACQUIRE_INACTIVE, ACQUIRE_ACTIVE, ACQUIRE_NEW) = range(3) def __init__(self): + self.MODIFIERMASK = NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask \ + | NSNumericPadKeyMask self.root = None self.keycode = 0 @@ -182,112 +183,113 @@ class MacHotkeyMgr(AbstractHotkeyMgr): self.keycode = None self.modifiers = None - @objc.callbackFor(NSEvent.addGlobalMonitorForEventsMatchingMask_handler_) - def _handler(self, event) -> None: - # use event.charactersIgnoringModifiers to handle composing characters like Alt-e - if ((event.modifierFlags() & MacHotkeyMgr.MODIFIERMASK) == self.modifiers - and ord(event.charactersIgnoringModifiers()[0]) == self.keycode): - if config.get_int('hotkey_always'): - self.activated = True - - else: # Only trigger if game client is front process - front = NSWorkspace.sharedWorkspace().frontmostApplication() - if front and front.bundleIdentifier() == 'uk.co.frontier.EliteDangerous': + if sys.platform == 'darwin': # noqa: C901 + @objc.callbackFor(NSEvent.addGlobalMonitorForEventsMatchingMask_handler_) + def _handler(self, event) -> None: + # use event.charactersIgnoringModifiers to handle composing characters like Alt-e + if ((event.modifierFlags() & self.MODIFIERMASK) == self.modifiers + and ord(event.charactersIgnoringModifiers()[0]) == self.keycode): + if config.get_int('hotkey_always'): self.activated = True - def acquire_start(self) -> None: - """Start acquiring hotkey state via polling.""" - self.acquire_state = MacHotkeyMgr.ACQUIRE_ACTIVE - self.root.after_idle(self._acquire_poll) + else: # Only trigger if game client is front process + front = NSWorkspace.sharedWorkspace().frontmostApplication() + if front and front.bundleIdentifier() == 'uk.co.frontier.EliteDangerous': + self.activated = True - def acquire_stop(self) -> None: - """Stop acquiring hotkey state.""" - self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE + def acquire_start(self) -> None: + """Start acquiring hotkey state via polling.""" + self.acquire_state = MacHotkeyMgr.ACQUIRE_ACTIVE + self.root.after_idle(self._acquire_poll) - def _acquire_poll(self) -> None: - """Perform a poll of current hotkey state.""" - if config.shutting_down: - return + def acquire_stop(self) -> None: + """Stop acquiring hotkey state.""" + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE - # No way of signalling to Tkinter from within the monkey-patched event handler that doesn't - # cause Python to crash, so poll. - if self.acquire_state: - if self.acquire_state == MacHotkeyMgr.ACQUIRE_NEW: - # Abuse tkEvent's keycode field to hold our acquired key & modifier - self.root.event_generate('', keycode=self.acquire_key) - self.acquire_state = MacHotkeyMgr.ACQUIRE_ACTIVE - self.root.after(50, self._acquire_poll) + def _acquire_poll(self) -> None: + """Perform a poll of current hotkey state.""" + if config.shutting_down: + return - def fromevent(self, event) -> Optional[Union[bool, Tuple]]: - """ - Return configuration (keycode, modifiers) or None=clear or False=retain previous. + # No way of signalling to Tkinter from within the monkey-patched event handler that doesn't + # cause Python to crash, so poll. + if self.acquire_state: + if self.acquire_state == MacHotkeyMgr.ACQUIRE_NEW: + # Abuse tkEvent's keycode field to hold our acquired key & modifier + self.root.event_generate('', keycode=self.acquire_key) + self.acquire_state = MacHotkeyMgr.ACQUIRE_ACTIVE + self.root.after(50, self._acquire_poll) - :param event: tk event ? - :return: False to retain previous, None to not use, else (keycode, modifiers) - """ - (keycode, modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000) # Set by _acquire_poll() - if (keycode - and not (modifiers & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask))): - if keycode == 0x1b: # Esc = retain previous - self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE - return False + def fromevent(self, event) -> Optional[Union[bool, Tuple]]: + """ + Return configuration (keycode, modifiers) or None=clear or False=retain previous. - # BkSp, Del, Clear = clear hotkey - elif keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]: - self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE - return None + :param event: tk event ? + :return: False to retain previous, None to not use, else (keycode, modifiers) + """ + (keycode, modifiers) = (event.keycode & 0xffff, event.keycode & 0xffff0000) # Set by _acquire_poll() + if (keycode + and not (modifiers & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask))): + if keycode == 0x1b: # Esc = retain previous + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE + return False - # don't allow keys needed for typing in System Map - elif keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a: - NSBeep() - self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE - return None + # BkSp, Del, Clear = clear hotkey + elif keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]: + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE + return None - return (keycode, modifiers) + # don't allow keys needed for typing in System Map + elif keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a: + NSBeep() + self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE + return None - def display(self, keycode, modifiers) -> str: - """ - Return displayable form of given hotkey + modifiers. + return (keycode, modifiers) - :param keycode: - :param modifiers: - :return: string form - """ - text = '' - if modifiers & NSControlKeyMask: - text += u'⌃' + def display(self, keycode, modifiers) -> str: + """ + Return displayable form of given hotkey + modifiers. - if modifiers & NSAlternateKeyMask: - text += u'⌥' + :param keycode: + :param modifiers: + :return: string form + """ + text = '' + if modifiers & NSControlKeyMask: + text += u'⌃' - if modifiers & NSShiftKeyMask: - text += u'⇧' + if modifiers & NSAlternateKeyMask: + text += u'⌥' - if modifiers & NSCommandKeyMask: - text += u'⌘' + if modifiers & NSShiftKeyMask: + text += u'⇧' - if (modifiers & NSNumericPadKeyMask) and keycode <= 0x7f: - text += u'№' + if modifiers & NSCommandKeyMask: + text += u'⌘' - if not keycode: - pass + if (modifiers & NSNumericPadKeyMask) and keycode <= 0x7f: + text += u'№' - elif ord(NSF1FunctionKey) <= keycode <= ord(NSF35FunctionKey): - text += f'F{keycode + 1 - ord(NSF1FunctionKey)}' + if not keycode: + pass - elif keycode in MacHotkeyMgr.DISPLAY: # specials - text += MacHotkeyMgr.DISPLAY[keycode] + elif ord(NSF1FunctionKey) <= keycode <= ord(NSF35FunctionKey): + text += f'F{keycode + 1 - ord(NSF1FunctionKey)}' - elif keycode < 0x20: # control keys - text += chr(keycode + 0x40) + elif keycode in MacHotkeyMgr.DISPLAY: # specials + text += MacHotkeyMgr.DISPLAY[keycode] - elif keycode < 0xf700: # key char - text += chr(keycode).upper() + elif keycode < 0x20: # control keys + text += chr(keycode + 0x40) - else: - text += u'⁈' + elif keycode < 0xf700: # key char + text += chr(keycode).upper() - return text + else: + text += u'⁈' + + return text def play_good(self): """Play the 'good' sound.""" From 9f1ae40775e7688bb5098cb89464be31da994f3f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 17:51:45 +0100 Subject: [PATCH 552/727] hotkey: Make LinuxHotkeyMgr 'pass' implementations. We do need to 'implement' them, but it's a all a no-op on Linux. --- hotkey.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hotkey.py b/hotkey.py index ff97ec4e..7b653f61 100644 --- a/hotkey.py +++ b/hotkey.py @@ -654,9 +654,27 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr): class LinuxHotKeyMgr(AbstractHotkeyMgr): - """Hot key management.""" + """ + Hot key management. - pass + Not actually implemented on Linux. It's a no-op instead. + """ + + def register(self, root, keycode, modifiers) -> None: + """Register the hotkey handler.""" + pass + + def unregister(self) -> None: + """Unregister the hotkey handling.""" + pass + + def play_good(self) -> None: + """Play the 'good' sound.""" + pass + + def play_bad(self) -> None: + """Play the 'bad' sound.""" + pass def get_hotkeymgr(*args, **kwargs) -> AbstractHotkeyMgr: From 6a403a54827e02c5d68afcdb63a5c4c1b9d971c6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 18:07:49 +0100 Subject: [PATCH 553/727] hotkey: Final mypy lints * Ignore types on the darwin stuff in-class if from platform specific imports. * None of the HotkeyMgr __init__ methods take any args, so don't try to pass any through. Stops mypy complaints. --- hotkey.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hotkey.py b/hotkey.py index 7b653f61..5a72cde1 100644 --- a/hotkey.py +++ b/hotkey.py @@ -107,14 +107,14 @@ class MacHotkeyMgr(AbstractHotkeyMgr): # Monkey-patch tk (tkMacOSXKeyEvent.c) if not self.tkProcessKeyEvent_old: sel = b'tkProcessKeyEvent:' - cls = NSApplication.sharedApplication().class__() - self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel) - newmethod = objc.selector( + cls = NSApplication.sharedApplication().class__() # type: ignore + self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel) # type: ignore + newmethod = objc.selector( # type: ignore self.tkProcessKeyEvent, selector=self.tkProcessKeyEvent_old.selector, signature=self.tkProcessKeyEvent_old.signature ) - objc.classAddMethod(cls, sel, newmethod) + objc.classAddMethod(cls, sel, newmethod) # type: ignore def tkProcessKeyEvent(self, cls, the_event): # noqa: N802 """ @@ -444,9 +444,9 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr): 0xa6: u'⇦', 0xa7: u'⇨', 0xa9: u'⊗', 0xab: u'☆', 0xac: u'⌂', 0xb4: u'✉', } - def __init__(self): - self.root = None - self.thread = None + def __init__(self) -> None: + self.root: tk.Tk = None # type: ignore + self.thread: threading.Thread = None # type: ignore with open(pathlib.Path(config.respath) / 'snd_good.wav', 'rb') as sg: self.snd_good = sg.read() with open(pathlib.Path(config.respath) / 'snd_bad.wav', 'rb') as sb: @@ -479,7 +479,7 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr): if thread: logger.debug('Thread is/was running') - self.thread = None + self.thread = None # type: ignore logger.debug('Telling thread WM_QUIT') PostThreadMessage(thread.ident, WM_QUIT, 0, 0) logger.debug('Joining thread') @@ -496,7 +496,7 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr): # Hotkey must be registered by the thread that handles it if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode): logger.debug("We're not the right thread?") - self.thread = None + self.thread = None # type: ignore return fake = INPUT(INPUT_KEYBOARD, INPUTUNION(ki=KEYBDINPUT(keycode, keycode, 0, 0, None))) @@ -539,7 +539,7 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr): logger.debug('Exited GetMessage() loop.') UnregisterHotKey(None, 1) - self.thread = None + self.thread = None # type: ignore logger.debug('Done.') def acquire_start(self) -> None: @@ -677,7 +677,7 @@ class LinuxHotKeyMgr(AbstractHotkeyMgr): pass -def get_hotkeymgr(*args, **kwargs) -> AbstractHotkeyMgr: +def get_hotkeymgr() -> AbstractHotkeyMgr: """ Determine platform-specific HotkeyMgr. @@ -687,13 +687,13 @@ def get_hotkeymgr(*args, **kwargs) -> AbstractHotkeyMgr: :raises ValueError: If unsupported platform. """ if sys.platform == 'darwin': - return MacHotkeyMgr(*args, **kwargs) + return MacHotkeyMgr() elif sys.platform == 'win32': - return WindowsHotkeyMgr(*args, **kwargs) + return WindowsHotkeyMgr() elif sys.platform == 'linux': - return LinuxHotKeyMgr(*args, **kwargs) + return LinuxHotKeyMgr() else: raise ValueError(f'Unknown platform: {sys.platform}') From e67e0a03fa95ad153f50cfa975a97b625aec6313 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 13:24:35 +0100 Subject: [PATCH 554/727] dashboard.py: Fix flake8 lints --- dashboard.py | 81 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/dashboard.py b/dashboard.py index 71b16f4c..e98af412 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,42 +1,51 @@ +"""Handle the game Status.json file.""" + import json -from calendar import timegm -from os.path import isdir, isfile, join, getsize -from sys import platform import time +import tkinter as tk +from calendar import timegm +from os.path import getsize, isdir, isfile, join +from sys import platform from config import config from EDMCLogging import get_main_logger logger = get_main_logger() -if platform=='darwin': - from watchdog.observers import Observer +if platform == 'darwin': from watchdog.events import FileSystemEventHandler + from watchdog.observers import Observer -elif platform=='win32': - from watchdog.observers import Observer +elif platform == 'win32': from watchdog.events import FileSystemEventHandler + from watchdog.observers import Observer else: # Linux's inotify doesn't work over CIFS or NFS, so poll - FileSystemEventHandler = object # dummy + FileSystemEventHandler = object # dummy -# Status.json handler class Dashboard(FileSystemEventHandler): + """Status.json handler.""" _POLL = 1 # Fallback polling interval - def __init__(self): - FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog + def __init__(self) -> None: + FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog self.root = None - self.currentdir = None # The actual logdir that we're monitoring + self.currentdir = None # The actual logdir that we're monitoring self.observer = None - self.observed = None # a watchdog ObservedWatch, or None if polling - self.status = {} # Current status for communicating status back to main thread + self.observed = None # a watchdog ObservedWatch, or None if polling + self.status = {} # Current status for communicating status back to main thread - def start(self, root, started): - """Start monitoring of Journal directory.""" + def start(self, root: tk.Tk, started: int) -> bool: + """ + Start monitoring of Journal directory. + + :param root: tkinter parent window. + :param started: unix epoch timestamp of LoadGame event. Ref: monitor.started. + :return: Successful start. + """ logger.debug('Starting...') self.root = root self.session_start = started @@ -90,7 +99,7 @@ class Dashboard(FileSystemEventHandler): return True - def stop(self): + def stop(self) -> None: """Stop monitoring dashboard.""" logger.debug('Stopping monitoring Dashboard') self.currentdir = None @@ -105,7 +114,7 @@ class Dashboard(FileSystemEventHandler): self.status = {} logger.debug('Done.') - def close(self): + def close(self) -> None: """Close down dashboard.""" logger.debug('Calling self.stop()') self.stop() @@ -123,28 +132,45 @@ class Dashboard(FileSystemEventHandler): logger.debug('Done.') - def poll(self, first_time=False): + def poll(self, first_time: bool = False) -> None: + """ + Poll Status.json via calling self.process() once a second. + + :param first_time: True if first call of this. + """ if not self.currentdir: # Stopped self.status = {} + else: self.process() if first_time: # Watchdog thread - emitter = self.observed and self.observer._emitter_for_watch[self.observed] # Note: Uses undocumented attribute + if self.observed: + emitter = self.observer._emitter_for_watch[self.observed] # Note: Uses undocumented attribute + if emitter and emitter.is_alive(): - return # Watchdog thread still running - stop polling + return # Watchdog thread still running - stop polling - self.root.after(self._POLL * 1000, self.poll) # keep polling + self.root.after(self._POLL * 1000, self.poll) # keep polling - def on_modified(self, event): - # watchdog callback - DirModifiedEvent on macOS, FileModifiedEvent on Windows - if event.is_directory or (isfile(event.src_path) and getsize(event.src_path)): # Can get on_modified events when the file is emptied + def on_modified(self, event) -> None: + """ + Watchdog callback - DirModifiedEvent on macOS, FileModifiedEvent on Windows. + + :param event: Watchdog event. + """ + if event.is_directory or (isfile(event.src_path) and getsize(event.src_path)): + # Can get on_modified events when the file is emptied self.process(event.src_path if not event.is_directory else None) - # Can be called either in watchdog thread or, if polling, in main thread. - def process(self, logfile=None): + def process(self) -> None: + """ + Process the contents of current Status.json file. + + Can be called either in watchdog thread or, if polling, in main thread. + """ if config.shutting_down: return @@ -166,5 +192,6 @@ class Dashboard(FileSystemEventHandler): except Exception: logger.exception('Processing Status.json') + # singleton dashboard = Dashboard() From 04506899cc26a034139c0f0b4fce52f1f87ecf40 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 14:50:58 +0100 Subject: [PATCH 555/727] dashboard.py: mypy lints Despite it being unused I restored the `logfile` argument to `Dashboard.process()`. It's set in a call to it. Further investigation if/when we do a proper code cleanup. --- dashboard.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/dashboard.py b/dashboard.py index e98af412..bdd6e151 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,11 +1,13 @@ """Handle the game Status.json file.""" import json +import pathlib import time import tkinter as tk from calendar import timegm -from os.path import getsize, isdir, isfile, join +from os.path import getsize, isdir, isfile from sys import platform +from typing import Any, Dict from config import config from EDMCLogging import get_main_logger @@ -32,11 +34,11 @@ class Dashboard(FileSystemEventHandler): def __init__(self) -> None: FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog - self.root = None - self.currentdir = None # The actual logdir that we're monitoring - self.observer = None + self.root: tk.Tk = None # type: ignore + self.currentdir: str = None # type: ignore # The actual logdir that we're monitoring + self.observer: Observer = None # type: ignore self.observed = None # a watchdog ObservedWatch, or None if polling - self.status = {} # Current status for communicating status back to main thread + self.status: Dict[str, Any] = {} # Current status for communicating status back to main thread def start(self, root: tk.Tk, started: int) -> bool: """ @@ -102,7 +104,7 @@ class Dashboard(FileSystemEventHandler): def stop(self) -> None: """Stop monitoring dashboard.""" logger.debug('Stopping monitoring Dashboard') - self.currentdir = None + self.currentdir = None # type: ignore if self.observed: logger.debug('Was observed') @@ -150,7 +152,7 @@ class Dashboard(FileSystemEventHandler): if self.observed: emitter = self.observer._emitter_for_watch[self.observed] # Note: Uses undocumented attribute - if emitter and emitter.is_alive(): + if emitter and emitter.is_alive(): # type: ignore return # Watchdog thread still running - stop polling self.root.after(self._POLL * 1000, self.poll) # keep polling @@ -165,7 +167,7 @@ class Dashboard(FileSystemEventHandler): # Can get on_modified events when the file is emptied self.process(event.src_path if not event.is_directory else None) - def process(self) -> None: + def process(self, logfile: str = None) -> None: """ Process the contents of current Status.json file. @@ -175,7 +177,7 @@ class Dashboard(FileSystemEventHandler): return try: - with open(join(self.currentdir, 'Status.json'), 'rb') as h: + with open(pathlib.Path(self.currentdir) / 'Status.json', 'rb') as h: data = h.read().strip() if data: # Can be empty if polling while the file is being re-written From 4d9e8e3f30f21c95f04d0c51f1083dc802bf8daf Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 18:15:47 +0100 Subject: [PATCH 556/727] dashboard: Convert open(pathlib) to pathlib.open() --- dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard.py b/dashboard.py index bdd6e151..649fb6f3 100644 --- a/dashboard.py +++ b/dashboard.py @@ -177,7 +177,7 @@ class Dashboard(FileSystemEventHandler): return try: - with open(pathlib.Path(self.currentdir) / 'Status.json', 'rb') as h: + with (pathlib.Path(self.currentdir) / 'Status.json').open('rb') as h: data = h.read().strip() if data: # Can be empty if polling while the file is being re-written From 5cc80174d2b490698bc3ad45a73a09a6cd52ea0c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 12:29:21 +0100 Subject: [PATCH 557/727] commodity.py: Fix flake8 lints --- commodity.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/commodity.py b/commodity.py index a3fd0fc4..5d2c2dd4 100644 --- a/commodity.py +++ b/commodity.py @@ -1,29 +1,34 @@ -# Export various CSV formats +"""Export various CSV formats.""" # -*- coding: utf-8 -*- -from os.path import join -import hashlib import time +from os.path import join from config import config from edmc_data import commodity_bracketmap as bracketmap - # DEFAULT means semi-colon separation # CSV means comma separation (COMMODITY_DEFAULT, COMMODITY_CSV) = range(2) -def export(data, kind=COMMODITY_DEFAULT, filename=None): +def export(data, kind=COMMODITY_DEFAULT, filename=None) -> None: + """ + Export commodity data from the given CAPI data. + + :param data: CAPI data. + :param kind: The type of file to write. + :param filename: Filename to write to, or None for a standard format name. + :return: + """ querytime = config.get_int('querytime', default=int(time.time())) if not filename: - filename = '{system}.{starport}.{time}.{kind}'.format( - system=data['lastSystem']['name'].strip(), - starport=data['lastStarport']['name'].strip(), - time=time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)), - kind='csv' - ) + filename_system = data['lastSystem']['name'].strip(), + filename_starport = data['lastStarport']['name'].strip(), + filename_time = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)), + filename_kind = 'csv' + filename = f'{filename_system}.{filename_starport}.{filename_time}.{filename_kind}' filename = join(config.get_str('outdir'), filename) if kind == COMMODITY_CSV: From f3383858c3f674d27556ea6dda32a24f1c503b76 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 12:31:34 +0100 Subject: [PATCH 558/727] commodity.py: Use 'with' for output file. --- commodity.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/commodity.py b/commodity.py index 5d2c2dd4..c82313f1 100644 --- a/commodity.py +++ b/commodity.py @@ -44,27 +44,30 @@ def export(data, kind=COMMODITY_DEFAULT, filename=None) -> None: rowheader = sep.join((data['lastSystem']['name'], data['lastStarport']['name'])) - h = open(filename, 'wt') # codecs can't automatically handle line endings, so encode manually where required - h.write(header) + with open(filename, 'wt') as h: # codecs can't automatically handle line endings, so encode manually where required + h.write(header) - for commodity in data['lastStarport']['commodities']: - line = sep.join(( - rowheader, - commodity['name'], - commodity['sellPrice'] and str(int(commodity['sellPrice'])) or '', - commodity['buyPrice'] and str(int(commodity['buyPrice'])) or '', - str(int(commodity['demand'])) if commodity['demandBracket'] else '', - bracketmap[commodity['demandBracket']], - str(int(commodity['stock'])) if commodity['stockBracket'] else '', - bracketmap[commodity['stockBracket']] - )) + for commodity in data['lastStarport']['commodities']: + line = sep.join(( + rowheader, + commodity['name'], + commodity['sellPrice'] and str(int(commodity['sellPrice'])) or '', + commodity['buyPrice'] and str(int(commodity['buyPrice'])) or '', + str(int(commodity['demand'])) if commodity['demandBracket'] else '', + bracketmap[commodity['demandBracket']], + str(int(commodity['stock'])) if commodity['stockBracket'] else '', + bracketmap[commodity['stockBracket']] + )) - if kind == COMMODITY_DEFAULT: - line = sep.join((line, str(int(commodity['meanPrice'])), str(commodity['id']), data['timestamp'] + '\n')) + if kind == COMMODITY_DEFAULT: + line = sep.join(( + line, + str(int(commodity['meanPrice'])), + str(commodity['id']), + data['timestamp'] + '\n') + ) - else: - line = sep.join((line, data['timestamp'] + '\n')) + else: + line = sep.join((line, data['timestamp'] + '\n')) - h.write(line) - - h.close() + h.write(line) From ce920a170fb2895705e2c1df94f7ec3243e7c5b2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 18:20:05 +0100 Subject: [PATCH 559/727] commodity.py: Make the structure passed to a join() easier to read --- commodity.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/commodity.py b/commodity.py index c82313f1..a7c39e79 100644 --- a/commodity.py +++ b/commodity.py @@ -60,11 +60,13 @@ def export(data, kind=COMMODITY_DEFAULT, filename=None) -> None: )) if kind == COMMODITY_DEFAULT: - line = sep.join(( - line, - str(int(commodity['meanPrice'])), - str(commodity['id']), - data['timestamp'] + '\n') + line = sep.join( + ( + line, + str(int(commodity['meanPrice'])), + str(commodity['id']), + data['timestamp'] + '\n' + ) ) else: From da31886b34e31968c5f40f9027f798b96408596f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 15:12:43 +0100 Subject: [PATCH 560/727] edshipyard.py: flake8 lints --- edshipyard.py | 85 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/edshipyard.py b/edshipyard.py index ad19d518..4acbee93 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -1,11 +1,11 @@ -# Export ship loadout in E:D Shipyard plain text format +"""Export ship loadout in ED Shipyard plain text format.""" import os +import pathlib import pickle import re import time from collections import defaultdict -from os.path import join from typing import Dict, List, Union import outfitting @@ -13,6 +13,9 @@ import util_ships from config import config from edmc_data import edshipyard_slot_map as slot_map from edmc_data import ship_name_map +from EDMCLogging import get_main_logger + +logger = get_main_logger() __Module = Dict[str, Union[str, List[str]]] @@ -21,29 +24,44 @@ ship_map = ship_name_map.copy() # Ship masses # TODO: prefer something other than pickle for this storage (dev readability, security) -ships = pickle.load(open(join(config.respath_path, 'ships.p'), 'rb')) +ships = pickle.load(open(pathlib.Path(config.respath_path) / 'ships.p', 'rb')) -# Export ship loadout in E:D Shipyard plain text format -def export(data, filename=None): - def class_rating(module: __Module): +def export(data, filename=None) -> None: # noqa: C901, CCR001 + """ + Export ship loadout in E:D Shipyard plain text format. + + :param data: CAPI data. + :param filename: Override default file name. + """ + def class_rating(module: __Module) -> str: + """ + Return a string representation of the class of the given module. + + :param module: Module data dict. + :return: Rating of the module. + """ mod_class = module['class'] mod_rating = module['rating'] mod_mount = module.get('mount') mod_guidance = module.get('guidance') - ret = '{mod_class}{rating}'.format(mod_class=mod_class, rating=mod_rating) + ret = f'{mod_class}{mod_rating}' if 'guidance' in module: # Missiles - ret += "/{mount}{guidance}".format( - mount=mod_mount[0] if mod_mount is not None else 'F', - guidance=mod_guidance[0], - ) + if mod_mount is not None: + mount = mod_mount[0] + + else: + mount = 'F' + + guidance = mod_guidance[0], + ret += f'/{mount}{guidance}' elif 'mount' in module: # Hardpoints - ret += "/{mount}".format(mount=mod_mount) + ret += f'/{mod_mount}' elif 'Cabin' in module['name']: # Passenger cabins - ret += "/{name}".format(name=module['name'][0]) + ret += f'/{module["name"][0]}' return ret + ' ' @@ -78,11 +96,11 @@ def export(data, filename=None): # Specials if 'Fuel Tank' in module['name']: fuel += 2**int(module['class']) - name = '{} (Capacity: {})'.format(module['name'], 2**int(module['class'])) + name = f'{module["name"]} (Capacity: {2**int(module["class"])})' elif 'Cargo Rack' in module['name']: cargo += 2**int(module['class']) - name = '{} (Capacity: {})'.format(module['name'], 2**int(module['class'])) + name = f'{module["name"]} (Capacity: {2**int(module["class"])})' else: name = module['name'] @@ -107,13 +125,11 @@ def export(data, filename=None): if slot.lower().startswith('slot'): loadout[slot[-1]].append(cr + name) - elif __debug__ and not slot.lower().startswith('planetaryapproachsuite'): - print('EDShipyard: Unknown slot {}'.format(slot)) + elif not slot.lower().startswith('planetaryapproachsuite'): + logger.debug(f'EDShipyard: Unknown slot {slot}') except AssertionError as e: - if __debug__: - print('EDShipyard: {}'.format(e)) - + logger.debug(f'EDShipyard: {e!r}') continue # Silently skip unrecognized modules except Exception: @@ -124,25 +140,26 @@ def export(data, filename=None): ship = ship_map.get(data['ship']['name'].lower(), data['ship']['name']) if data['ship'].get('shipName') is not None: - _ships = '{}, {}'.format(ship, data['ship']['shipName']) + _ships = f'{ship}, {data["ship"]["shipName"]}' + else: _ships = ship - string = '[{}]\n'.format(_ships) + string = f'[{_ships}]\n' - SLOT_TYPES = ( + slot_types = ( 'H', 'L', 'M', 'S', 'U', None, 'BH', 'RB', 'TM', 'FH', 'EC', 'PC', 'SS', 'FS', None, 'MC', None, '9', '8', '7', '6', '5', '4', '3', '2', '1' ) - for slot in SLOT_TYPES: + for slot in slot_types: if not slot: string += '\n' elif slot in loadout: for name in loadout[slot]: - string += '{}: {}\n'.format(slot, name) + string += f'{slot}: {name}\n' - string += '---\nCargo : {} T\nFuel : {} T\n'.format(cargo, fuel) + string += f'---\nCargo : {cargo} T\nFuel : {fuel} T\n' # Add mass and range assert data['ship']['name'].lower() in ship_name_map, data['ship']['name'] @@ -150,14 +167,13 @@ def export(data, filename=None): try: mass += ships[ship_name_map[data['ship']['name'].lower()]]['hullMass'] - string += 'Mass : {:.2f} T empty\n {:.2f} T full\n'.format(mass, mass + fuel + cargo) + string += f'Mass : {mass:.2f} T empty\n {mass + fuel + cargo:.2f} T full\n' multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 / fsd['fuelpower']) * fsd['optmass'] - string += 'Range : {:.2f} LY unladen\n {:.2f} LY laden\n'.format( - multiplier / (mass + fuel) + jumpboost, - multiplier / (mass + fuel + cargo) + jumpboost - ) + range_unladen = multiplier / (mass + fuel) + jumpboost, + range_laden = multiplier / (mass + fuel + cargo) + jumpboost + string += f'Range : {range_unladen:.2f} LY unladen\n {range_laden:.2f} LY laden\n' except Exception: if __debug__: @@ -174,14 +190,13 @@ def export(data, filename=None): regexp = re.compile(re.escape(ship) + r'\.\d{4}-\d\d-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted([x for x in os.listdir(config.get_str('outdir')) if regexp.match(x)]) if oldfiles: - with open(join(config.get_str('outdir'), oldfiles[-1]), 'rU') as h: + with open(pathlib.Path(config.get_str('outdir')) / oldfiles[-1], 'rU') as h: if h.read() == string: return # same as last time - don't write # Write - filename = join(config.get_str('outdir'), '{}.{}.txt'.format( - ship, time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime))) - ) + timestamp = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)) + filename = pathlib.Path(config.get_str('outdir')) / f'{ship}.{timestamp}.txt' with open(filename, 'wt') as h: h.write(string) From 35e13defb22754b518743d30964512f56fcf060d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 15:23:48 +0100 Subject: [PATCH 561/727] edshipyard.py: Fix erroneous trailing comma Also, although we should perhaps make some attempt to ensure the decimal separator is always a full-stop... it turns out edsy.org doesn't currently support importing this style anyway, so it's moot. --- edshipyard.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/edshipyard.py b/edshipyard.py index 4acbee93..384f4548 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -171,8 +171,10 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 / fsd['fuelpower']) * fsd['optmass'] - range_unladen = multiplier / (mass + fuel) + jumpboost, + range_unladen = multiplier / (mass + fuel) + jumpboost range_laden = multiplier / (mass + fuel + cargo) + jumpboost + # As of 2021-04-07 edsy.org says text import not yet implemented, so ignore the possible issue with + # a locale that uses comma for decimal separator. string += f'Range : {range_unladen:.2f} LY unladen\n {range_laden:.2f} LY laden\n' except Exception: From 11fa46163aa3ab7856ad2d15a72163531a9fc708 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 15:40:31 +0100 Subject: [PATCH 562/727] edshipyard.py: mypy lints That __Module type might be causing more trouble than its worth. Changing the Union to 'Any' didn't help though. --- edshipyard.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/edshipyard.py b/edshipyard.py index 384f4548..a23c2bf4 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -44,7 +44,7 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 mod_class = module['class'] mod_rating = module['rating'] mod_mount = module.get('mount') - mod_guidance = module.get('guidance') + mod_guidance: str = module.get('guidance') # type: ignore ret = f'{mod_class}{mod_rating}' if 'guidance' in module: # Missiles @@ -54,7 +54,7 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 else: mount = 'F' - guidance = mod_guidance[0], + guidance = mod_guidance[0] ret += f'/{mount}{guidance}' elif 'mount' in module: # Hardpoints @@ -88,22 +88,22 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 cr = class_rating(module) mods = v.get('modifications') or v.get('WorkInProgress_modifications') or {} if mods.get('OutfittingFieldType_Mass'): - mass += (module.get('mass', 0) * mods['OutfittingFieldType_Mass']['value']) + mass += float(module.get('mass', 0.0) * mods['OutfittingFieldType_Mass']['value']) else: - mass += module.get('mass', 0) + mass += float(module.get('mass', 0.0)) # type: ignore # Specials if 'Fuel Tank' in module['name']: - fuel += 2**int(module['class']) - name = f'{module["name"]} (Capacity: {2**int(module["class"])})' + fuel += 2**int(module['class']) # type: ignore + name = f'{module["name"]} (Capacity: {2**int(module["class"])})' # type: ignore elif 'Cargo Rack' in module['name']: - cargo += 2**int(module['class']) - name = f'{module["name"]} (Capacity: {2**int(module["class"])})' + cargo += 2**int(module['class']) # type: ignore + name = f'{module["name"]} (Capacity: {2**int(module["class"])})' # type: ignore else: - name = module['name'] + name = module['name'] # type: ignore if name == 'Frame Shift Drive': fsd = module # save for range calculation @@ -114,7 +114,7 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 if mods.get('OutfittingFieldType_MaxFuelPerJump'): fsd['maxfuel'] *= mods['OutfittingFieldType_MaxFuelPerJump']['value'] - jumpboost += module.get('jumpboost', 0) + jumpboost += module.get('jumpboost', 0) # type: ignore for s in slot_map: if slot.lower().startswith(s): @@ -169,7 +169,8 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 mass += ships[ship_name_map[data['ship']['name'].lower()]]['hullMass'] string += f'Mass : {mass:.2f} T empty\n {mass + fuel + cargo:.2f} T full\n' - multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 / fsd['fuelpower']) * fsd['optmass'] + multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 # type: ignore + / fsd['fuelpower']) * fsd['optmass'] # type: ignore range_unladen = multiplier / (mass + fuel) + jumpboost range_laden = multiplier / (mass + fuel + cargo) + jumpboost From dbdf42bb380e84a7284a12d013de19d3e8107f25 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 18:23:27 +0100 Subject: [PATCH 563/727] edshipyard: Use pathlib.Path.open() --- edshipyard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edshipyard.py b/edshipyard.py index a23c2bf4..5c31cb24 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -193,7 +193,7 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 regexp = re.compile(re.escape(ship) + r'\.\d{4}-\d\d-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted([x for x in os.listdir(config.get_str('outdir')) if regexp.match(x)]) if oldfiles: - with open(pathlib.Path(config.get_str('outdir')) / oldfiles[-1], 'rU') as h: + with (pathlib.Path(config.get_str('outdir')) / oldfiles[-1]).open('r') as h: if h.read() == string: return # same as last time - don't write From de9e8e944e0ee803eaab8d63fad339df5ad4dc52 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Apr 2021 18:32:49 +0100 Subject: [PATCH 564/727] edshipyard: cast mod_guidance instead of type ignore --- edshipyard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edshipyard.py b/edshipyard.py index 5c31cb24..d709a2e1 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -44,7 +44,7 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 mod_class = module['class'] mod_rating = module['rating'] mod_mount = module.get('mount') - mod_guidance: str = module.get('guidance') # type: ignore + mod_guidance: str = str(module.get('guidance')) ret = f'{mod_class}{mod_rating}' if 'guidance' in module: # Missiles From a9c4c191e92a5b81d9f574cdcc92c6809b2eac53 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Apr 2021 10:09:16 +0100 Subject: [PATCH 565/727] Don't try to generate a shipyard link if we have no known loadout. This is currently the case on Odyssey Alpha Phase 1 when logging in on-foot. There's no Journal 'Loadout' event, but the CAPI update does let us know we have a Sidewinder active. But `monitor.state['Modules']` is None. --- EDMarketConnector.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index e3312ed1..074e78d1 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1076,16 +1076,20 @@ class AppWindow(object): def shipyard_url(self, shipname: str) -> str: """Despatch a ship URL to the configured handler.""" + if not (loadout := monitor.ship()): + logger.warning('No ship loadout, aborting.') + return '' + if not bool(config.get_int("use_alt_shipyard_open")): return plug.invoke(config.get_str('shipyard_provider'), 'EDSY', 'shipyard_url', - monitor.ship(), + loadout, monitor.is_beta) # Avoid file length limits if possible provider = config.get_str('shipyard_provider', default='EDSY') - target = plug.invoke(provider, 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) + target = plug.invoke(provider, 'EDSY', 'shipyard_url', loadout, monitor.is_beta) file_name = join(config.app_dir_path, "last_shipyard.html") with open(file_name, 'w') as f: From 74656f45c96ae362dde207209cf8ae66408f078a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Apr 2021 10:51:00 +0100 Subject: [PATCH 566/727] Ensure ship type/name is only clickable when we have the data for it. This is keyed off monitor.state['Modules'] because that's what monitor.py EDLogs.ship() uses. --- EDMarketConnector.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 074e78d1..95fff93c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -831,6 +831,13 @@ class AppWindow(object): monitor.state['ShipID'] = data['ship']['id'] monitor.state['ShipType'] = data['ship']['name'].lower() + if not monitor.state['Modules']: + self.ship.configure(state=tk.DISABLED) + + # We might have disabled this in the conditional above. + if monitor.state['Modules']: + self.ship.configure(state=True) + if data['commander'].get('credits') is not None: monitor.state['Credits'] = data['commander']['credits'] monitor.state['Loan'] = data['commander'].get('debt', 0) @@ -938,7 +945,14 @@ class AppWindow(object): if not ship_text: ship_text = '' - self.ship.configure(text=ship_text, url=self.shipyard_url) + # Ensure the ship type/name text is clickable, if it should be. + if monitor.state['Modules']: + ship_state = True + + else: + ship_state = tk.DISABLED + + self.ship.configure(text=ship_text, url=self.shipyard_url, state=ship_state) else: self.cmdr['text'] = '' From 22dbd4e0488fd49347f889ae00fb227de7396c3b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Apr 2021 16:37:50 +0100 Subject: [PATCH 567/727] EDDN: Fix building of "ships this station sells" list. This likely hadn't been tested since a rewrite due to pre-Odyssey alpha having broken CAPI without shipyard_list on normal stations. --- plugins/eddn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index dd3446d3..d700ba2b 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -428,7 +428,7 @@ Msg:\n{msg}''' shipyard: List[Mapping[str, Any]] = sorted( itertools.chain( (ship['name'].lower() for ship in (ships['shipyard_list'] or {}).values()), - ships['unavailable_list'] + (ship['name'].lower() for ship in ships['unavailable_list'] or {}), ) ) # Don't send empty ships list - shipyard data is only guaranteed present if user has visited the shipyard. @@ -550,7 +550,7 @@ Msg:\n{msg}''' ]), }) - this.shipyard = (horizons, shipyard) + # this.shipyard = (horizons, shipyard) def export_journal_entry(self, cmdr: str, is_beta: bool, entry: Mapping[str, Any]) -> None: """ From efebdfdfed4d6ed5f0bd642e245e326b08da03b4 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 9 Apr 2021 18:32:08 +0200 Subject: [PATCH 568/727] Ensured that `emitter` is always bound, even if None --- dashboard.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dashboard.py b/dashboard.py index 649fb6f3..43e7e52b 100644 --- a/dashboard.py +++ b/dashboard.py @@ -82,7 +82,7 @@ class Dashboard(FileSystemEventHandler): elif polling and self.observer: logger.debug('Using polling, stopping observer...') self.observer.stop() - self.observer = None + self.observer = None # type: ignore logger.debug('Done') if not self.observed and not polling: @@ -130,7 +130,7 @@ class Dashboard(FileSystemEventHandler): logger.debug('Joining self.observer...') self.observer.join() logger.debug('Done') - self.observer = None + self.observer = None # type: ignore logger.debug('Done.') @@ -148,6 +148,7 @@ class Dashboard(FileSystemEventHandler): self.process() if first_time: + emitter = None # Watchdog thread if self.observed: emitter = self.observer._emitter_for_watch[self.observed] # Note: Uses undocumented attribute From 1a7bfc8a608b6427e23e068df9c9336ee084c5aa Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 9 Apr 2021 18:32:25 +0200 Subject: [PATCH 569/727] Updated gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index d5414bd5..6cc7b72a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,7 @@ EDMarketConnector.VisualElementsManifest.xml .idea .vscode venv +*.code-workspace +htmlcov/ +.ignored +.coverage \ No newline at end of file From c2fdd0a3197f9ec4b8e8dbea78ff5c216e75832e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 9 Apr 2021 19:23:12 +0100 Subject: [PATCH 570/727] pr-checks: Try not changing options to actions/checkout@v2 --- .github/workflows/pr-checks.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index c5c7a325..20521600 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -25,9 +25,9 @@ jobs: - name: Checkout head commits # https://github.com/actions/checkout uses: actions/checkout@v2 - with: - repository: ${{github.event.pull_request.head.repo.full_name}} - fetch-depth: 0 + #with: + #repository: ${{github.event.pull_request.head.repo.full_name}} + #fetch-depth: 0 # But we do need the base references - name: Fetch base commits From c599a486d673a654f101eff3abe5cd04c3abb4e7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 9 Apr 2021 19:28:48 +0100 Subject: [PATCH 571/727] Restore showing the github context --- .github/workflows/pr-checks.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 20521600..8868a62d 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -17,6 +17,10 @@ jobs: steps: + # Debug show the info we have to work with + - name: Show github context + run: cat $GITHUB_EVENT_PATH + #################################################################### # Checkout the necessary commits #################################################################### From ed8b5730903a9e94cc3e8d0f7f429a796d0a09d3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 9 Apr 2021 19:46:30 +0100 Subject: [PATCH 572/727] pr-checks: Use github.head.sha for checkout ref --- .github/workflows/pr-checks.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 8868a62d..eb173a6e 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -29,7 +29,8 @@ jobs: - name: Checkout head commits # https://github.com/actions/checkout uses: actions/checkout@v2 - #with: + with: + ref: ${{github.head.sha}} #repository: ${{github.event.pull_request.head.repo.full_name}} #fetch-depth: 0 From 51f5cc3a31b3db11bd7224896a157e0e1f923221 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 9 Apr 2021 20:01:25 +0100 Subject: [PATCH 573/727] pr-checks: Try without setting checkout ref Going to test this with new PR from Athanasius account, with a 'behind' develop. --- .github/workflows/pr-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index eb173a6e..ec558fc5 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -30,7 +30,7 @@ jobs: # https://github.com/actions/checkout uses: actions/checkout@v2 with: - ref: ${{github.head.sha}} + #ref: ${{github.head.sha}} #repository: ${{github.event.pull_request.head.repo.full_name}} #fetch-depth: 0 From 06568aeb2ef9acb10e105ba76bd570a832ac9672 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 9 Apr 2021 20:08:07 +0100 Subject: [PATCH 574/727] pr-checks: No 'with:' if the body is empty --- .github/workflows/pr-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index ec558fc5..476eef97 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -29,7 +29,7 @@ jobs: - name: Checkout head commits # https://github.com/actions/checkout uses: actions/checkout@v2 - with: + #with: #ref: ${{github.head.sha}} #repository: ${{github.event.pull_request.head.repo.full_name}} #fetch-depth: 0 From 13824c53bc103f04c8c7931b48f5c7433d046891 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Apr 2021 20:22:20 +0100 Subject: [PATCH 575/727] monitor: Only forget station on Disembark if not from own ship --- monitor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 5d482c1f..03d3ef87 100644 --- a/monitor.py +++ b/monitor.py @@ -623,7 +623,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'Disembark': # We don't yet have a way, other than LoadGame+Location, to detect if we *are* on a station on-foot. - self.station = None + + # If we're not exiting one of these then it's from our own ship, and then we should already have + # self.station set correctly. + if entry['SRV'] or entry['Taxi'] or entry['Multicrew']: + self.station = None + self.state['OnFoot'] = True elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): From dc7f4bdd1cd4d33cfec2a34ae862c444537165b5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 11 Apr 2021 21:44:03 +0100 Subject: [PATCH 576/727] Update bug report template for GitHub no longer having that button You just drag & drop files into the input area now. --- .github/ISSUE_TEMPLATE/bug_report.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 9284b95e..896f0b34 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -17,11 +17,9 @@ assignees: '' - OS: [e.g. Windows 10, Linux Debian 10.6, etc.] - OS Locale: [e.g. English, French, Serbian...] - If applicable: Browser [e.g. chrome, safari] - - Please attach **BOTH** log files as follows: + - Please attach **BOTH** log files, by dragging and dropping them into this input: 1. `%TEMP%\EDMarketConnector.log` from *immediately* after the bug occurs (re-running the application overwrites this file). 1. %TEMP%\EDMarketConnector\EDMarketConnector-debug.log`. See [Debug Log File](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#debug-log-files). NB: If you don't have this log file then you're not running the latest version of the application and should update first to see if we already fixed the bug you're reporting. - - Use the Icon that looks like `_`, `|` and `^` all in one character towards the right of the toolbar above. **Describe the bug** A clear and concise description of what the bug is. From 79729d683e8953ea7585f56f80eb6100946ae4cc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 08:45:10 +0100 Subject: [PATCH 577/727] CQC game mode LoadGame has fewer fields, no Ship --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 03d3ef87..15e5dd50 100644 --- a/monitor.py +++ b/monitor.py @@ -520,7 +520,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Statistics': {}, 'Role': None, }) - if self._RE_SHIP_ONFOOT.search(entry['Ship']): + if entry.get('Ship') is not None and self._RE_SHIP_ONFOOT.search(entry['Ship']): self.state['OnFoot'] = True elif event_type == 'NewCommander': From 9a6b59fbd36f4f8a5f49bc3c7bcc55e00274a4f5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 09:10:25 +0100 Subject: [PATCH 578/727] monitor.py: Initialise EDLogs self.systempopulation This is the *one* field that wasn't always initialised. --- PLUGINS.md | 3 +++ monitor.py | 1 + 2 files changed, 4 insertions(+) diff --git a/PLUGINS.md b/PLUGINS.md index 23016a2b..e327e1da 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -563,6 +563,9 @@ running. In this case you won't receive initial events such as "LoadGame", "Rank", "Location", etc. However the `state` dictionary will reflect the cumulative effect of these missed events. +**NB: Any of the values in this might be `None` if the Cmdr has loaded into +Arena (CQC) from the Main Menu.** + Similarly, a special "ShutDown" entry is sent when the game stops writing to the Journal without writing a "Shutdown" event. This might happen, for example, when the game client crashes. diff --git a/monitor.py b/monitor.py index 15e5dd50..7f0a1ae7 100644 --- a/monitor.py +++ b/monitor.py @@ -105,6 +105,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationtype: Optional[str] = None self.coordinates: Optional[Tuple[float, float, float]] = None self.systemaddress: Optional[int] = None + self.systempopulation: Optional[int] = None self.started: Optional[int] = None # Timestamp of the LoadGame event self.__init_state() From 2686500d6538058680e0ec1dfbf1c013f82acd2d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 11:05:11 +0100 Subject: [PATCH 579/727] companion: Split Frontier Auth URL string over lines This way a change to one part is an easier to read diff. --- companion.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/companion.py b/companion.py index d1aca078..068d1c40 100644 --- a/companion.py +++ b/companion.py @@ -295,7 +295,14 @@ class Auth(object): logger.info(f'Trying auth from scratch for Commander "{self.cmdr}"') challenge = self.base64_url_encode(hashlib.sha256(self.verifier).digest()) webbrowser.open( - f'{SERVER_AUTH}{URL_AUTH}?response_type=code&audience=frontier,steam,epic&scope=capi&client_id={CLIENT_ID}&code_challenge={challenge}&code_challenge_method=S256&state={self.state}&redirect_uri={protocolhandler.redirect}' # noqa: E501 # I cant make this any shorter + f'{SERVER_AUTH}{URL_AUTH}?response_type=code' + f'&audience=frontier,steam,epic' + f'&scope=auth capi' + f'&client_id={CLIENT_ID}' + f'&code_challenge={challenge}' + f'&code_challenge_method=S256' + f'&state={self.state}' + f'&redirect_uri={protocolhandler.redirect}' ) return None From 5c7aa4dfa97a46a58f842a05ef9fb1dbfd8f6956 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 12:03:11 +0100 Subject: [PATCH 580/727] companion: commented-out example of requests/http debug logging --- companion.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/companion.py b/companion.py index 068d1c40..1a0fad67 100644 --- a/companion.py +++ b/companion.py @@ -341,6 +341,13 @@ class Auth(object): 'redirect_uri': protocolhandler.redirect, } + # import http.client as http_client + # http_client.HTTPConnection.debuglevel = 1 + # import logging + # requests_log = logging.getLogger("requests.packages.urllib3") + # requests_log.setLevel(logging.DEBUG) + # requests_log.propagate = True + r = self.session.post(SERVER_AUTH + URL_TOKEN, data=request_data, timeout=auth_timeout) data = r.json() if r.status_code == requests.codes.ok: From ca08339dfe85921078ccb93e48183a9482132455 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 12:37:17 +0100 Subject: [PATCH 581/727] companion: /decode access token and check customer_id matches FID --- companion.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/companion.py b/companion.py index 1a0fad67..0aa2bc20 100644 --- a/companion.py +++ b/companion.py @@ -56,6 +56,7 @@ CLIENT_ID = os.getenv('CLIENT_ID') or 'fb88d428-9110-475f-a3d2-dc151c2b9c7a' SERVER_AUTH = 'https://auth.frontierstore.net' URL_AUTH = '/auth' URL_TOKEN = '/token' +URL_DECODE = '/decode' USER_AGENT = f'EDCD-{appname}-{appversion()}' @@ -307,7 +308,7 @@ class Auth(object): return None - def authorize(self, payload: str) -> str: + def authorize(self, payload: str) -> str: # noqa: CCR001 """Handle oAuth authorization callback. :return: access token if successful, otherwise raises CredentialsError. @@ -349,18 +350,42 @@ class Auth(object): # requests_log.propagate = True r = self.session.post(SERVER_AUTH + URL_TOKEN, data=request_data, timeout=auth_timeout) - data = r.json() + data_token = r.json() if r.status_code == requests.codes.ok: + # Now we need to /decode the token to check the customer_id against FID + r = self.session.get( + SERVER_AUTH + URL_DECODE, + headers={ + 'Authorization': f'Bearer {data_token.get("access_token", "")}', + 'Content-Type': 'application/json', + }, + timeout=auth_timeout + ) + data_decode = r.json() + if r.status_code != requests.codes.ok: + r.raise_for_status() + + if (usr := data_decode.get('usr')) is None: + logger.error('No "usr" in /decode data') + raise CredentialsError("Error: Couldn't check token customer_id") + + if (customer_id := usr.get('customer_id')) is None: + logger.error('No "usr"->"customer_id" in /decode data') + raise CredentialsError("Error: Couldn't check token customer_id") + + if f'F{customer_id}' != monitor.state.get('FID'): + raise CredentialsError("Error: customer_id doesn't match!") + logger.info(f'Frontier CAPI Auth: New token for \"{self.cmdr}\"') cmdrs = config.get_list('cmdrs', default=[]) idx = cmdrs.index(self.cmdr) tokens = config.get_list('fdev_apikeys', default=[]) tokens = tokens + [''] * (len(cmdrs) - len(tokens)) - tokens[idx] = data.get('refresh_token', '') + tokens[idx] = data_token.get('refresh_token', '') config.set('fdev_apikeys', tokens) config.save() # Save settings now for use by command-line app - return str(data.get('access_token')) + return str(data_token.get('access_token')) except Exception as e: logger.exception(f"Frontier CAPI Auth: Can't get token for \"{self.cmdr}\"") From 0575c3ff437fb1fd4f72e503464b3d2715175e66 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 12:38:23 +0100 Subject: [PATCH 582/727] companion: Don't over-write all CredentialsError with generic one --- companion.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/companion.py b/companion.py index 0aa2bc20..a061a74f 100644 --- a/companion.py +++ b/companion.py @@ -387,6 +387,9 @@ class Auth(object): return str(data_token.get('access_token')) + except CredentialsError: + raise + except Exception as e: logger.exception(f"Frontier CAPI Auth: Can't get token for \"{self.cmdr}\"") if r: From ffc8d2fcb8627a4cbf4010516588c5b99d7fd8d5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 12:52:05 +0100 Subject: [PATCH 583/727] Add comment about assuming FID always starts 'F'. --- companion.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/companion.py b/companion.py index a061a74f..f827aa9f 100644 --- a/companion.py +++ b/companion.py @@ -373,6 +373,8 @@ class Auth(object): logger.error('No "usr"->"customer_id" in /decode data') raise CredentialsError("Error: Couldn't check token customer_id") + # All 'FID' seen in Journals so far have been 'F' + # Frontier, Steam and Epic if f'F{customer_id}' != monitor.state.get('FID'): raise CredentialsError("Error: customer_id doesn't match!") From 6532a0f0ed4ace0996e2006bebce17c385eebe87 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 13:51:26 +0100 Subject: [PATCH 584/727] Release 5.0.0-beta5: appversion and changelog --- ChangeLog.md | 39 +++++++++++++++++++++++++++++++++++++++ config.py | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 78ff66bb..e7646d72 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,45 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- +Pre-Release 5.0.0-beta5 +=== + +* Ship Type/Name will now be greyed out, and not clickable, if we don't + currently have loadout information for it. This prevents trying to send an + empty loadout to your shipyard provider. + +* Sanity check a returned Frontier Authentication token to be sure it's for + the current Commander. If it's not you'll see `Error: customer_id doesn't + match!` on the bottom status line. Double-check you're using the correct + credentials when authing! + +* Bug fixed when handling CAPI-sourced shipyard information. This would + currently only have shown up on live for Fleet Carriers due to a Frontier + bug with not returning shipyard data at all for normal stations. + + It has been observed that Frontier has fixed this bug for Odyssey. + +* Don't try to get Ship information from `LoadGame` event if directly in CQC. + +* A lot of general code cleanup relating to: Inara, outfitting, Frontier + CAPI, hotkey (manual Updates), dashboard (Status.json monitoring), + commodities files, ED format ship loadout files. + +* Inara: Don't attempt to send an empty + `setCommanderReputationMajorFaction` API call. This quietens an error + from the Inara API caused when a Cmdr literally has no Major Faction + Reputation yet. + +Plugin Developers +--- + +* Initial support for new Odyssey "MicroResources" (Data, Item, Component + and Consumable) in the "Ship Locker" and "BackPack". NB: Currently the + `ShipLockerMaterials` event omits a `Data` array, so we can't properly + track those. + + See the updated PLUGINS.md for details about this in the `state` dictionary. + Pre-Release 5.0.0-beta4 === diff --git a/config.py b/config.py index d793267c..b78b2c34 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta4' +_static_appversion = '5.0.0-beta5' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From 99d90b52b1657c9f0ccf71436df9288b0aee157e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 14:58:03 +0100 Subject: [PATCH 585/727] translations: Re-order as per l10n.py output & some added * Generic 'Error'. * Strings for Access Token customer_id != FID. * Other strings in companion.py now translating. * Missing colon on Plugins string. --- L10n/en.template | 60 +++++++++++++++++++++++++++++------------------- companion.py | 12 +++++----- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index 1d4f4e07..a7262ed1 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -1,18 +1,12 @@ -/* Label for 'UI Transparency' option in [prefs.py]*/ -"Main window transparency" = "Main window transparency"; +/* Language name */ +"!Language" = "English"; /* Message next to 'UI Transparency' slider [prefs.py] */ "100 means fully opaque.{CR}Window is updated in real time" = "100 means fully opaque.{CR}Window is updated in real time"; -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "UI Scale Percentage"; - /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 means Default{CR}Restart Required for{CR}changes to take effect!"; -/* Language name */ -"!Language" = "English"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "About {APP}"; @@ -52,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Browse..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: No commander data returned"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: No commander data returned"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -136,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Edit"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins Without Python 3.x Support"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -154,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "Error"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Error: Can't connect to EDDN"; @@ -163,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Error: Can't connect to Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Error: Couldn't check token customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Error: customer_id doesn't match!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Error: EDSM {MSG}"; @@ -181,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Error: Invalid Credentials"; +/* [companion.py] */ +"Error: unable to get token" = "Error: unable to get token"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Error: Wrong Cmdr"; @@ -241,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara credentials"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Information on migrating plugins"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Journal directory already locked"; @@ -268,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Loan"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Log Level"; + /* [EDMarketConnector.py] */ "Logging in..." = "Logging in..."; /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Main window transparency"; + /* [prefs.py] */ "Market data in CSV format file" = "Market data in CSV format file"; @@ -316,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Only when Elite: Dangerous is the active app"; @@ -358,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Plugins folder"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins Without Python 3.x Support"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins Without Python 3.x Support"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Information on migrating plugins"; +"Plugins Without Python 3.x Support:" = "Plugins Without Python 3.x Support:"; /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -517,6 +529,9 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "UI Scale Percentage"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Update"; @@ -555,6 +570,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} needs permission to use shortcuts"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Log Level"; diff --git a/companion.py b/companion.py index f827aa9f..7702d046 100644 --- a/companion.py +++ b/companion.py @@ -329,7 +329,7 @@ class Auth(object): (data[k] for k in ('error_description', 'error', 'message') if k in data), '' ) - raise CredentialsError(f'Error: {error!r}') + raise CredentialsError(f'{_("Error")}: {error!r}') r = None try: @@ -367,16 +367,16 @@ class Auth(object): if (usr := data_decode.get('usr')) is None: logger.error('No "usr" in /decode data') - raise CredentialsError("Error: Couldn't check token customer_id") + raise CredentialsError(_("Error: Couldn't check token customer_id")) if (customer_id := usr.get('customer_id')) is None: logger.error('No "usr"->"customer_id" in /decode data') - raise CredentialsError("Error: Couldn't check token customer_id") + raise CredentialsError(_("Error: Couldn't check token customer_id")) # All 'FID' seen in Journals so far have been 'F' # Frontier, Steam and Epic if f'F{customer_id}' != monitor.state.get('FID'): - raise CredentialsError("Error: customer_id doesn't match!") + raise CredentialsError(_("Error: customer_id doesn't match!")) logger.info(f'Frontier CAPI Auth: New token for \"{self.cmdr}\"') cmdrs = config.get_list('cmdrs', default=[]) @@ -397,7 +397,7 @@ class Auth(object): if r: self.dump(r) - raise CredentialsError('unable to get token') from e + raise CredentialsError(_('Error: unable to get token')) from e logger.error(f"Frontier CAPI Auth: Can't get token for \"{self.cmdr}\"") self.dump(r) @@ -405,7 +405,7 @@ class Auth(object): (data[k] for k in ('error_description', 'error', 'message') if k in data), '' ) - raise CredentialsError(f'Error: {error!r}') + raise CredentialsError(f'{_("Error")}: {error!r}') @staticmethod def invalidate(cmdr: str) -> None: From c466d17553d1ae9194cb174aaa432a911428f9df Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 16:20:12 +0100 Subject: [PATCH 586/727] EDMarketConnector: Add CL arg to force use of edmc:// protocol This will be useful when running from source, i.e. in debugger, and wanting to work on the protocol code. --- EDMarketConnector.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 95fff93c..317fef43 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -90,6 +90,11 @@ if __name__ == '__main__': # noqa: C901 action='store_true' ) + parser.add_argument('--force-edmc-protocol', + help='Force use of the edmc:// protocol handler. Error if not on Windows', + action='store_true', + ) + parser.add_argument('edmc', help='Callback from Frontier Auth', nargs='*' From ae2bbc892969abcd0f90e926339d5fa709dd34af Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 16:25:53 +0100 Subject: [PATCH 587/727] Set config flag for --force-edmc-protocol so protocol.py can test it --- EDMarketConnector.py | 9 +++++++++ config.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 317fef43..b996760c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -111,6 +111,15 @@ if __name__ == '__main__': # noqa: C901 if args.force_localserver_for_auth: config.set_auth_force_localserver() + if args.force_edmc_protocol: + if sys.platform == 'win32': + config.set_auth_force_edmc_protocol() + + else: + print("--force-edmc-protocol is only valid on Windows") + parser.print_help() + exit(1) + def handle_edmc_callback_or_foregrounding() -> None: # noqa: CCR001 """Handle any edmc:// auth callback, else foreground existing window.""" logger.trace('Begin...') diff --git a/config.py b/config.py index b78b2c34..6889ee2f 100644 --- a/config.py +++ b/config.py @@ -182,6 +182,7 @@ class AbstractConfig(abc.ABC): __in_shutdown = False # Is the application currently shutting down ? __auth_force_localserver = False # Should we use localhost for auth callback ? + __auth_force_edmc_protocol = False # Should we force edmc:// protocol ? def __init__(self) -> None: self.home_path = pathlib.Path.home() @@ -212,6 +213,19 @@ class AbstractConfig(abc.ABC): """ return self.__auth_force_localserver + def set_auth_force_edmc_protocol(self): + """Set flag to force use of localhost web server for Frontier Auth callback.""" + self.__auth_force_edmc_protocol = True + + @property + def auth_force_edmc_protocol(self) -> bool: + """ + Determine if use of localhost is forced for Frontier Auth callback. + + :return: bool - True if we should use localhost web server. + """ + return self.__auth_force_edmc_protocol + @property def app_dir(self) -> str: """Return a string version of app_dir.""" From cf1655894bb91232e12ede3a4e42d7476127fed1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 16:32:58 +0100 Subject: [PATCH 588/727] protocol: Pay attention to config.auth_force_edmc_protocol --- protocol.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/protocol.py b/protocol.py index eff33e5e..e9c7c4f7 100644 --- a/protocol.py +++ b/protocol.py @@ -113,7 +113,13 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): # noqa: C901 # i protocolhandler.master.after(DarwinProtocolHandler.POLL, protocolhandler.poll) # type: ignore -elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: +elif (config.auth_force_edmc_protocol + or ( + sys.platform == 'win32' + and getattr(sys, 'frozen', False) + and not is_wine + and not config.auth_force_localserver + )): # spell-checker: words HBRUSH HICON WPARAM wstring WNDCLASS HMENU HGLOBAL from ctypes import windll # type: ignore from ctypes import POINTER, WINFUNCTYPE, Structure, byref, c_long, c_void_p, create_unicode_buffer, wstring_at @@ -415,7 +421,14 @@ protocolhandler: GenericProtocolHandler if sys.platform == 'darwin' and getattr(sys, 'frozen', False): protocolhandler = DarwinProtocolHandler() # pyright: reportUnboundVariable=false -elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: +elif ( + sys.platform == 'win32' + and config.auth_force_edmc_protocol or ( + getattr(sys, 'frozen', False) + and not is_wine + and not config.auth_force_localserver + ) + ): protocolhandler = WindowsProtocolHandler() else: protocolhandler = LinuxProtocolHandler() From 4b456b402b6ae7c493d228db8620aa496838402d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 12 Apr 2021 16:35:39 +0100 Subject: [PATCH 589/727] EDMarketConnector: Mutually exclude --force-localserver-for-auth --force-edmc-protocol --- EDMarketConnector.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b996760c..22d91ecd 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -85,15 +85,16 @@ if __name__ == '__main__': # noqa: C901 action='store_true' ) - parser.add_argument('--force-localserver-for-auth', - help='Force EDMC to use a localhost webserver for Frontier Auth callback', - action='store_true' - ) + auth_options = parser.add_mutually_exclusive_group(required=False) + auth_options.add_argument('--force-localserver-for-auth', + help='Force EDMC to use a localhost webserver for Frontier Auth callback', + action='store_true' + ) - parser.add_argument('--force-edmc-protocol', - help='Force use of the edmc:// protocol handler. Error if not on Windows', - action='store_true', - ) + auth_options.add_argument('--force-edmc-protocol', + help='Force use of the edmc:// protocol handler. Error if not on Windows', + action='store_true', + ) parser.add_argument('edmc', help='Callback from Frontier Auth', From 1a9983f33141ba3dfb971e244d319c2962f9dee5 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 12 Apr 2021 19:58:23 +0200 Subject: [PATCH 590/727] Fixed edge case with reading old ship loadout --- monitor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/monitor.py b/monitor.py index 7f0a1ae7..5aa9838a 100644 --- a/monitor.py +++ b/monitor.py @@ -1265,6 +1265,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below except OSError: logger.exception("OSError reading old ship loadout default encoding.") + except ValueError: + # User was on $OtherEncoding, updated windows to be sane and use utf8 everywhere, thus + # the above open() fails, likely with a UnicodeDecodeError, which subclasses UnicodeError which + # subclasses ValueError, this catches ValueError _instead_ of UnicodeDecodeError just to be sure + # that if some other encoding error crops up we grab it too. + logger.exception('ValueError when reading old ship loadout default encoding') + except OSError: logger.exception("OSError reading old ship loadout with default encoding") From d4e7395a44a6b0437d238dd3320bf07924d66d0d Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 13 Apr 2021 00:31:08 +0200 Subject: [PATCH 591/727] Ensured all sets are flushed to disk on linux Fixes 1002 --- config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config.py b/config.py index 6889ee2f..c8edefb1 100644 --- a/config.py +++ b/config.py @@ -996,6 +996,7 @@ class LinuxConfig(AbstractConfig): raise ValueError(f'Unexpected type for value {type(val)=}') self.config.set(self.SECTION, key, to_set) + self.save() def delete(self, key: str, *, suppress=False) -> None: """ From 3341800f713a89071ad0abc67bbfec35503cd612 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 13 Apr 2021 00:32:03 +0200 Subject: [PATCH 592/727] Added missing save to test --- tests/config.py/test_config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/config.py/test_config.py b/tests/config.py/test_config.py index 4e484a2f..0d10a3c2 100644 --- a/tests/config.py/test_config.py +++ b/tests/config.py/test_config.py @@ -137,6 +137,7 @@ class TestNewConfig: assert res == '1337' config.delete(name) + config.save() class TestOldNewConfig: From f99b0445cae31f826546dc4cc3bda213fe955620 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 13 Apr 2021 00:35:01 +0200 Subject: [PATCH 593/727] Also save on delete --- config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config.py b/config.py index c8edefb1..71b95e5c 100644 --- a/config.py +++ b/config.py @@ -1008,6 +1008,7 @@ class LinuxConfig(AbstractConfig): raise ValueError('attempt to use a closed config') self.config.remove_option(self.SECTION, key) + self.save() def save(self) -> None: """ From 224627828644798fb2dd3ecadac4b2f0f85f919b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 12:12:51 +0100 Subject: [PATCH 594/727] Odyssey Suits: Store available data from CAPI. I've gone with 'None' for when there's no data, rather than {}. That makes for simpler checks on if there is data (a dict.get('foo') only checks for that, not the dict structure otherwise). If no 'suit' in the data we assume no Odyssey, but otherwise plough on with dict.get() statements as they'll default to None if it's not present. *Users* of this monitor.state[] extra data get to choose what to do if some data is present but not other. --- companion.py | 23 +++++++++++++++++ edmc_data.py | 5 ++++ monitor.py | 72 +++++++++++++++++++++++++++------------------------- 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/companion.py b/companion.py index 7702d046..6c71080a 100644 --- a/companion.py +++ b/companion.py @@ -589,6 +589,10 @@ class Session(object): # logger.trace('timestamp not in data, adding from response headers') data['timestamp'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', parsedate(r.headers['Date'])) # type: ignore + # Update Odyssey Suit data + if endpoint == URL_QUERY: + self.suit_update(data) + return data def profile(self) -> CAPIData: @@ -632,6 +636,25 @@ class Session(object): return data + def suit_update(self, data: CAPIData) -> None: + """ + Update monitor.state suit data. + + :param data: CAPI data to extra suit data from. + """ + if (current_suit := data.get('suit')) is None: + # Probably no Odyssey on the account, so point attempting more. + return + + monitor.state['SuitCurrent'] = current_suit + monitor.state['Suits'] = data.get('suits') + + if (suit_loadouts := data.get('loadouts')) is None: + logger.warning('CAPI data had "suit" but no (suit) "loadouts"') + + monitor.state['SuitLoadoutCurrent'] = data.get('loadout') + monitor.state['SuitLoadouts'] = suit_loadouts + def close(self) -> None: """Close CAPI authorization session.""" self.state = Session.STATE_INIT diff --git a/edmc_data.py b/edmc_data.py index 1d51d185..61c72bd2 100644 --- a/edmc_data.py +++ b/edmc_data.py @@ -23,6 +23,11 @@ companion_category_map = { 'NonMarketable': False, # Don't appear in the in-game market so don't report } +# Map suit symbol names to English localised names +companion_suit_type_map = { + 'TacticalSuit_Class1': 'Dominator Suit', +} + # Map Coriolis's names to names displayed in the in-game shipyard. coriolis_ship_map = { 'Cobra Mk III': 'Cobra MkIII', diff --git a/monitor.py b/monitor.py index 5aa9838a..7d2e14b3 100644 --- a/monitor.py +++ b/monitor.py @@ -114,42 +114,46 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Cmdr state shared with EDSM and plugins # If you change anything here update PLUGINS.md documentation! self.state: Dict = { - 'Captain': None, # On a crew - 'Cargo': defaultdict(int), - 'Credits': None, - 'FID': None, # Frontier Cmdr ID - 'Horizons': None, # Does this user have Horizons? - 'Loan': None, - 'Raw': defaultdict(int), - 'Manufactured': defaultdict(int), - 'Encoded': defaultdict(int), - 'Engineers': {}, - 'Rank': {}, - 'Reputation': {}, - 'Statistics': {}, - 'Role': None, # Crew role - None, Idle, FireCon, FighterCon - 'Friends': set(), # Online friends - 'ShipID': None, - 'ShipIdent': None, - 'ShipName': None, - 'ShipType': None, - 'HullValue': None, - 'ModulesValue': None, - 'Rebuy': None, - 'Modules': None, - 'CargoJSON': None, # The raw data from the last time cargo.json was read - 'Route': None, # Last plotted route from Route.json file - 'OnFoot': False, # Whether we think you're on-foot - 'Component': defaultdict(int), # Odyssey Components in Ship Locker - 'Item': defaultdict(int), # Odyssey Items in Ship Locker - 'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker - 'Data': defaultdict(int), # Odyssey Data in Ship Locker + 'Captain': None, # On a crew + 'Cargo': defaultdict(int), + 'Credits': None, + 'FID': None, # Frontier Cmdr ID + 'Horizons': None, # Does this user have Horizons? + 'Loan': None, + 'Raw': defaultdict(int), + 'Manufactured': defaultdict(int), + 'Encoded': defaultdict(int), + 'Engineers': {}, + 'Rank': {}, + 'Reputation': {}, + 'Statistics': {}, + 'Role': None, # Crew role - None, Idle, FireCon, FighterCon + 'Friends': set(), # Online friends + 'ShipID': None, + 'ShipIdent': None, + 'ShipName': None, + 'ShipType': None, + 'HullValue': None, + 'ModulesValue': None, + 'Rebuy': None, + 'Modules': None, + 'CargoJSON': None, # The raw data from the last time cargo.json was read + 'Route': None, # Last plotted route from Route.json file + 'OnFoot': False, # Whether we think you're on-foot + 'Component': defaultdict(int), # Odyssey Components in Ship Locker + 'Item': defaultdict(int), # Odyssey Items in Ship Locker + 'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker + 'Data': defaultdict(int), # Odyssey Data in Ship Locker 'BackPack': { # Odyssey BackPack contents - 'Component': defaultdict(int), # BackPack Components - 'Consumable': defaultdict(int), # BackPack Consumables - 'Item': defaultdict(int), # BackPack Items - 'Data': defaultdict(int), # Backpack Data + 'Component': defaultdict(int), # BackPack Components + 'Consumable': defaultdict(int), # BackPack Consumables + 'Item': defaultdict(int), # BackPack Items + 'Data': defaultdict(int), # Backpack Data }, + 'SuitCurrent': None, + 'Suits': None, + 'SuitLoadoutCurrent': None, + 'SuitLoadouts': None, } def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 From 29473de0314af47214e50b77e96fab4c0d1b159c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 12:26:33 +0100 Subject: [PATCH 595/727] PLUGINS.md: Update for all added Odyssey monitor.state fields --- PLUGINS.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index e327e1da..04012421 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -531,6 +531,15 @@ Content of `state` (updated to the current journal entry): | `NavRoute` | `dict` | Last plotted multi-hop route | | `ModuleInfo` | `dict` | Last loaded ModulesInfo.json data | | `OnFoot` | `bool` | Whether the Cmdr is on foot | +| `Component` | `dict` | 'Component' MicroResources in Odyssey, `int` count each. | +| `Item` | `dict` | 'Item' MicroResources in Odyssey, `int` count each. | +| `Consumable` | `dict` | 'Consumable' MicroResources in Odyssey, `int` count each. | +| `Data` | `dict` | 'Data' MicroResources in Odyssey, `int` count each. | +| `BackPack` | `dict` | `dict` of Odyssey MicroResources in backpack. | +| `SuitCurrent` | `dict` | CAPI-returned data of currently worn suit. NB: May be `None` if no data. | +| `Suits` | `dict` | CAPI-returned data of owned suits. NB: May be `None` if no data. | +| `SuitLoadoutCurrent` | `dict` | CAPI-returned data of current Suit Loadout. NB: May be `None` if no data. | +| `SuitLoadouts` | `dict` | CAPI-returned data of all Suit Loadouts. NB: May be `None` if no data. | New in version 4.1.6: @@ -553,8 +562,12 @@ Journal `ModuleInfo` event. `OnFoot` is an indication as to if the player is on-foot, rather than in a vehicle. -`Component` is a dict tracking your 'on-foot' materials for upgrading Suits -and on-foot weapons. +`Component`, `Item`, `Consumable` & `Data` are `dict`s tracking your +Odyssey MicroResources in your Ship Locker. `BacKPack` contains `dict`s for +the same when you're on-foot. + +`SuitCurrent`, `Suits`, `SuitLoadoutCurrent` & `SuitLoadouts` hold CAPI data +relating to suits and their loadouts. ##### Synthetic Events From 0382e4b451f3dfae171b781952c54edb15e1bb7f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 12:48:13 +0100 Subject: [PATCH 596/727] Suits: Add basic UI for suit label and name Currently this will always be there, next commit(s) will sort out it being dynamic. --- EDMarketConnector.py | 56 +++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 22d91ecd..92509b45 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -350,37 +350,48 @@ class AppWindow(object): frame.columnconfigure(1, weight=1) self.cmdr_label = tk.Label(frame) - self.ship_label = tk.Label(frame) - self.system_label = tk.Label(frame) - self.station_label = tk.Label(frame) - - self.cmdr_label.grid(row=1, column=0, sticky=tk.W) - self.ship_label.grid(row=2, column=0, sticky=tk.W) - self.system_label.grid(row=3, column=0, sticky=tk.W) - self.station_label.grid(row=4, column=0, sticky=tk.W) - self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr') + self.ship_label = tk.Label(frame) self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship') + self.suit_label = tk.Label(frame) + self.suit = tk.Label(frame) + self.system_label = tk.Label(frame) + self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system') + self.station_label = tk.Label(frame) + self.station = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.station_url, name='station') # system and station text is set/updated by the 'provider' plugins # eddb, edsm and inara. Look for: # # parent.children['system'] / parent.children['station'] - self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system') - self.station = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.station_url, name='station') - self.cmdr.grid(row=1, column=1, sticky=tk.EW) - self.ship.grid(row=2, column=1, sticky=tk.EW) - self.system.grid(row=3, column=1, sticky=tk.EW) - self.station.grid(row=4, column=1, sticky=tk.EW) + ui_row = 1 + + self.cmdr_label.grid(row=ui_row, column=0, sticky=tk.W) + self.cmdr.grid(row=ui_row, column=1, sticky=tk.EW) + ui_row += 1 + self.ship_label.grid(row=ui_row, column=0, sticky=tk.W) + self.ship.grid(row=ui_row, column=1, sticky=tk.EW) + ui_row += 1 + self.suit_grid_row = ui_row + self.suit_label.grid(row=ui_row, column=0, sticky=tk.W) + self.suit.grid(row=ui_row, column=1, sticky=tk.EW) + ui_row += 1 + self.system_label.grid(row=ui_row, column=0, sticky=tk.W) + self.system.grid(row=ui_row, column=1, sticky=tk.EW) + ui_row += 1 + self.station_label.grid(row=ui_row, column=0, sticky=tk.W) + self.station.grid(row=ui_row, column=1, sticky=tk.EW) + ui_row += 1 for plugin in plug.PLUGINS: appitem = plugin.get_app(frame) if appitem: tk.Frame(frame, highlightthickness=1).grid(columnspan=2, sticky=tk.EW) # separator if isinstance(appitem, tuple) and len(appitem) == 2: - row = frame.grid_size()[1] - appitem[0].grid(row=row, column=0, sticky=tk.W) - appitem[1].grid(row=row, column=1, sticky=tk.EW) + ui_row = frame.grid_size()[1] + appitem[0].grid(row=ui_row, column=0, sticky=tk.W) + appitem[1].grid(row=ui_row, column=1, sticky=tk.EW) + else: appitem.grid(columnspan=2, sticky=tk.EW) @@ -389,11 +400,11 @@ class AppWindow(object): self.theme_button = tk.Label(frame, width=32 if platform == 'darwin' else 28, state=tk.DISABLED) self.status = tk.Label(frame, name='status', anchor=tk.W) - row = frame.grid_size()[1] - self.button.grid(row=row, columnspan=2, sticky=tk.NSEW) - self.theme_button.grid(row=row, columnspan=2, sticky=tk.NSEW) + ui_row = frame.grid_size()[1] + self.button.grid(row=ui_row, columnspan=2, sticky=tk.NSEW) + self.theme_button.grid(row=ui_row, columnspan=2, sticky=tk.NSEW) theme.register_alternate((self.button, self.theme_button, self.theme_button), - {'row': row, 'columnspan': 2, 'sticky': tk.NSEW}) + {'row': ui_row, 'columnspan': 2, 'sticky': tk.NSEW}) self.status.grid(columnspan=2, sticky=tk.EW) self.button.bind('', self.getandsend) theme.button_bind(self.theme_button, self.getandsend) @@ -615,6 +626,7 @@ class AppWindow(object): self.cmdr_label['text'] = _('Cmdr') + ':' # Main window # Multicrew role label in main window self.ship_label['text'] = (monitor.state['Captain'] and _('Role') or _('Ship')) + ':' # Main window + self.suit_label['text'] = _('Suit') + ':' # Main window self.system_label['text'] = _('System') + ':' # Main window self.station_label['text'] = _('Station') + ':' # Main window self.button['text'] = self.theme_button['text'] = _('Update') # Update button in main window From 3baf92706dc97528a62d75247c1d5ee1d1a0c30a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 13:59:41 +0100 Subject: [PATCH 597/727] Suits: Initially don't show 'Suit' row of UI * Don't grid to start with, but store the row it would be on. * `toggle_suit_row()` to toggle it on/off. NB: Might implement a "force to" `visible` argument, but going to test without for now. --- EDMarketConnector.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 92509b45..0a3beee7 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -373,8 +373,9 @@ class AppWindow(object): self.ship.grid(row=ui_row, column=1, sticky=tk.EW) ui_row += 1 self.suit_grid_row = ui_row - self.suit_label.grid(row=ui_row, column=0, sticky=tk.W) - self.suit.grid(row=ui_row, column=1, sticky=tk.EW) + # self.suit_label.grid(row=self.suit_grid_row, column=0, sticky=tk.W) + # self.suit.grid(row=self.suit_grid_row, column=1, sticky=tk.EW) + self.suit_shown = False ui_row += 1 self.system_label.grid(row=ui_row, column=0, sticky=tk.W) self.system.grid(row=ui_row, column=1, sticky=tk.EW) @@ -598,6 +599,23 @@ class AppWindow(object): self.postprefs(False) # Companion login happens in callback from monitor + def toggle_suit_row(self, visible=True) -> None: + """ + Toggle the visibility of the 'Suit' row. + + :param visible: UNIMPLEMENTED + """ + if not self.suit_shown: + self.suit_label.grid(row=self.suit_grid_row, column=0, sticky=tk.W) + self.suit.grid(row=self.suit_grid_row, column=1, sticky=tk.EW) + + else: + # Hide the Suit row + self.suit_label.grid_forget() + self.suit.grid_forget() + + self.suit_shown = not self.suit_shown + def postprefs(self, dologin: bool = True): """Perform necessary actions after the Preferences dialog is applied.""" self.prefsdialog = None From 9ca55e7af75c1c14e8da6cf8cb907151acd345b7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 14:15:45 +0100 Subject: [PATCH 598/727] Suit: Implement auto-toggle of Suit line based on CAPI data * There's a 'visible' argument to force it, default None to ignore. That flag is checked first in the function, and then it sets the 'current' state to the opposite so the following conditional will do the right thing. * Toggling is triggered in AppWindow.getandsend(). --- EDMarketConnector.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 0a3beee7..b695545a 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -599,22 +599,28 @@ class AppWindow(object): self.postprefs(False) # Companion login happens in callback from monitor - def toggle_suit_row(self, visible=True) -> None: + def toggle_suit_row(self, visible: Optional[bool] = None) -> None: """ Toggle the visibility of the 'Suit' row. - :param visible: UNIMPLEMENTED + :param visible: Force visibility to this. """ + if visible is True: + self.suit_shown = False + + elif visible is False: + self.suit_shown = True + if not self.suit_shown: self.suit_label.grid(row=self.suit_grid_row, column=0, sticky=tk.W) self.suit.grid(row=self.suit_grid_row, column=1, sticky=tk.EW) + self.suit_shown = True else: # Hide the Suit row self.suit_label.grid_forget() self.suit.grid_forget() - - self.suit_shown = not self.suit_shown + self.suit_shown = False def postprefs(self, dologin: bool = True): """Perform necessary actions after the Preferences dialog is applied.""" @@ -883,6 +889,12 @@ class AppWindow(object): if monitor.state['Modules']: self.ship.configure(state=True) + if monitor.state.get('SuitCurrent') is not None: + self.toggle_suit_row(visible=True) + + else: + self.toggle_suit_row(visible=False) + if data['commander'].get('credits') is not None: monitor.state['Credits'] = data['commander']['credits'] monitor.state['Loan'] = data['commander'].get('debt', 0) From 29c059c27590395d2473084f0af228492384897d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 15:26:41 +0100 Subject: [PATCH 599/727] Suit: Label and text now properly aligned, and toggling * There was a 'hidden' padx/pady thing going on, not applying because we were hidden/not gridded, so apply in toggle/show. * Make that padx=5 all over use a common constant. * Set Suit text if most recent CAPI data contains the relevant data. If it's not present then hide the Suit row. --- EDMarketConnector.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b695545a..b3e1e1cf 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -316,6 +316,8 @@ class AppWindow(object): EVENT_BUTTON = 4 EVENT_VIRTUAL = 35 + PADX = 5 + def __init__(self, master: tk.Tk): # noqa: C901, CCR001 # TODO - can possibly factor something out self.holdofftime = config.get_int('querytime', default=0) + companion.holdoff @@ -354,7 +356,7 @@ class AppWindow(object): self.ship_label = tk.Label(frame) self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship') self.suit_label = tk.Label(frame) - self.suit = tk.Label(frame) + self.suit = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='suit') self.system_label = tk.Label(frame) self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system') self.station_label = tk.Label(frame) @@ -369,17 +371,19 @@ class AppWindow(object): self.cmdr_label.grid(row=ui_row, column=0, sticky=tk.W) self.cmdr.grid(row=ui_row, column=1, sticky=tk.EW) ui_row += 1 + self.ship_label.grid(row=ui_row, column=0, sticky=tk.W) self.ship.grid(row=ui_row, column=1, sticky=tk.EW) ui_row += 1 + self.suit_grid_row = ui_row - # self.suit_label.grid(row=self.suit_grid_row, column=0, sticky=tk.W) - # self.suit.grid(row=self.suit_grid_row, column=1, sticky=tk.EW) self.suit_shown = False ui_row += 1 + self.system_label.grid(row=ui_row, column=0, sticky=tk.W) self.system.grid(row=ui_row, column=1, sticky=tk.EW) ui_row += 1 + self.station_label.grid(row=ui_row, column=0, sticky=tk.W) self.station.grid(row=ui_row, column=1, sticky=tk.EW) ui_row += 1 @@ -411,7 +415,7 @@ class AppWindow(object): theme.button_bind(self.theme_button, self.getandsend) for child in frame.winfo_children(): - child.grid_configure(padx=5, pady=(platform != 'win32' or isinstance(child, tk.Frame)) and 2 or 0) + child.grid_configure(padx=self.PADX, pady=(platform != 'win32' or isinstance(child, tk.Frame)) and 2 or 0) # The type needs defining for adding the menu entry, but won't be # properly set until later @@ -508,7 +512,7 @@ class AppWindow(object): theme_close.grid(row=0, column=4, padx=2) theme.button_bind(theme_close, self.onexit, image=self.theme_close) self.theme_file_menu = tk.Label(self.theme_menubar, anchor=tk.W) - self.theme_file_menu.grid(row=1, column=0, padx=5, sticky=tk.W) + self.theme_file_menu.grid(row=1, column=0, padx=self.PADX, sticky=tk.W) theme.button_bind(self.theme_file_menu, lambda e: self.file_menu.tk_popup(e.widget.winfo_rootx(), e.widget.winfo_rooty() @@ -525,7 +529,7 @@ class AppWindow(object): lambda e: self.help_menu.tk_popup(e.widget.winfo_rootx(), e.widget.winfo_rooty() + e.widget.winfo_height())) - tk.Frame(self.theme_menubar, highlightthickness=1).grid(columnspan=5, padx=5, sticky=tk.EW) + tk.Frame(self.theme_menubar, highlightthickness=1).grid(columnspan=5, padx=self.PADX, sticky=tk.EW) theme.register(self.theme_minimize) # images aren't automatically registered theme.register(self.theme_close) self.blank_menubar = tk.Frame(frame) @@ -598,6 +602,7 @@ class AppWindow(object): config.delete('logdir', suppress=True) self.postprefs(False) # Companion login happens in callback from monitor + self.toggle_suit_row(visible=False) def toggle_suit_row(self, visible: Optional[bool] = None) -> None: """ @@ -612,8 +617,15 @@ class AppWindow(object): self.suit_shown = True if not self.suit_shown: - self.suit_label.grid(row=self.suit_grid_row, column=0, sticky=tk.W) - self.suit.grid(row=self.suit_grid_row, column=1, sticky=tk.EW) + if platform != 'win32': + pady = 2 + + else: + + pady = 0 + + self.suit_label.grid(row=self.suit_grid_row, column=0, sticky=tk.W, padx=self.PADX, pady=pady) + self.suit.grid(row=self.suit_grid_row, column=1, sticky=tk.EW, padx=self.PADX, pady=pady) self.suit_shown = True else: @@ -890,6 +902,13 @@ class AppWindow(object): self.ship.configure(state=True) if monitor.state.get('SuitCurrent') is not None: + if (loadout := data.get('loadout')) is not None: + if (suit := loadout.get('suit')) is not None: + if (suitname := suit.get('locName')) is not None: + # We've been paranoid about loadout->suit->suitname, now just assume loadouts is there + loadout_name = data['loadouts'][f"{loadout['loadoutSlotId']}"]['name'] + self.suit['text'] = f'{suitname} ({loadout_name})' + self.toggle_suit_row(visible=True) else: From c28dd8c55d7f41e429e1ab80ab79f4e44feee1b3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 16:48:16 +0100 Subject: [PATCH 600/727] Suits: Set/update suit text as necessary. * After any Journal event we might as well set it. * Attempt to update on a `SwitchSuitLoadout` event, assuming the new slot is one we heard about in the last CAPI data. --- EDMarketConnector.py | 15 +++++++++++++++ monitor.py | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b3e1e1cf..6ca1c966 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -604,6 +604,19 @@ class AppWindow(object): self.postprefs(False) # Companion login happens in callback from monitor self.toggle_suit_row(visible=False) + def update_suit_text(self) -> None: + """Update the suit text for current type and loadout.""" + if (suit := monitor.state.get('SuitCurrent')) is None: + return + + suitname = suit['locName'] + + if (suitloadout := monitor.state.get('SuitLoadoutCurrent')) is None: + return + + loadout_name = suitloadout['name'] + self.suit['text'] = f'{suitname} ({loadout_name})' + def toggle_suit_row(self, visible: Optional[bool] = None) -> None: """ Toggle the visibility of the 'Suit' row. @@ -1035,6 +1048,8 @@ class AppWindow(object): self.ship_label['text'] = _('Ship') + ':' # Main window self.ship['text'] = '' + self.update_suit_text() + self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED) # Copy if entry['event'] in ( diff --git a/monitor.py b/monitor.py index 7d2e14b3..cc27865d 100644 --- a/monitor.py +++ b/monitor.py @@ -827,6 +827,33 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if self.state['BackPack'][c][m] < 0: self.state['BackPack'][c][m] = 0 + elif event_type == 'SwitchSuitLoadout': + loadoutid = entry['LoadoutID'] + # Observed LoadoutID in SwitchSuitLoadout events are, e.g. + # 4293000005 for CAPI slot 5. + # This *might* actually be "lower 6 bits", but maybe it's not. + new_slot = loadoutid - 4293000000 + try: + self.state['SuitLoadoutCurrent'] = self.state['SuitLoadouts'][f'{new_slot}'] + + except KeyError: + logger.exception(f"Getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})") + # Might mean that a new suit loadout was created and we need a new CAPI fetch ? + + else: + try: + new_suitid = self.state['SuitLoadoutCurrent']['suit']['suitId'] + + except KeyError: + logger.exception(f"Getting switched-to suit ID from slot {new_slot} ({loadoutid})") + + else: + try: + self.state['SuitCurrent'] = self.state['Suits'][f'{new_suitid}'] + + except KeyError: + logger.exception(f"Getting switched-to suit from slot {new_slot} ({loadoutid}") + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From bb90d0fb590a9ca0bc15e9379c2ccb68eabf61cc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 16:56:48 +0100 Subject: [PATCH 601/727] Suits: If user switches to an unknown loadout, say so --- EDMarketConnector.py | 2 ++ monitor.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 6ca1c966..a1b8ab02 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -607,11 +607,13 @@ class AppWindow(object): def update_suit_text(self) -> None: """Update the suit text for current type and loadout.""" if (suit := monitor.state.get('SuitCurrent')) is None: + self.suit['text'] = f'<{_("Unknown")}>' return suitname = suit['locName'] if (suitloadout := monitor.state.get('SuitLoadoutCurrent')) is None: + self.suit['text'] = '' return loadout_name = suitloadout['name'] diff --git a/monitor.py b/monitor.py index cc27865d..52bb22bc 100644 --- a/monitor.py +++ b/monitor.py @@ -839,6 +839,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below except KeyError: logger.exception(f"Getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})") # Might mean that a new suit loadout was created and we need a new CAPI fetch ? + self.state['SuitCurrent'] = None + self.state['SuitLoadoutCurrent'] = None else: try: From bd61cda6fa384b4fc53aa6dde0aa5dee50e2637a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 17:15:25 +0100 Subject: [PATCH 602/727] Add translation for 'Unknown', e.g. suit loadout. --- L10n/en.template | 3 +++ 1 file changed, 3 insertions(+) diff --git a/L10n/en.template b/L10n/en.template index a7262ed1..dd54a762 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -532,6 +532,9 @@ /* Label for 'UI Scaling' option [prefs.py] */ "UI Scale Percentage" = "UI Scale Percentage"; +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Unknown"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Update"; From 1509bcde2b375f97a8e0975d34b30f1873a7216c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Apr 2021 10:01:36 +0100 Subject: [PATCH 603/727] Suits: Placeholders for DeleteSuitLoadout and CreateSuitLoadout --- monitor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/monitor.py b/monitor.py index 52bb22bc..d21b0bde 100644 --- a/monitor.py +++ b/monitor.py @@ -856,6 +856,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below except KeyError: logger.exception(f"Getting switched-to suit from slot {new_slot} ({loadoutid}") + elif event_type == 'DeleteSuitLoadout': + # We should remove this from the monitor.state record of loadouts + pass + + elif event_type == 'CreateSuitLoadout': + # We know we won't have data for this new one + pass + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From 550ca61e443c06bd4cc41392510e2d819e2c491c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Apr 2021 10:16:34 +0100 Subject: [PATCH 604/727] Suits: Support `DeleteSuitLoadout` event * Factored "find CAPI slot id from journal LoadoutID" into its own function. --- monitor.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/monitor.py b/monitor.py index d21b0bde..05b80c2f 100644 --- a/monitor.py +++ b/monitor.py @@ -829,10 +829,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'SwitchSuitLoadout': loadoutid = entry['LoadoutID'] - # Observed LoadoutID in SwitchSuitLoadout events are, e.g. - # 4293000005 for CAPI slot 5. - # This *might* actually be "lower 6 bits", but maybe it's not. - new_slot = loadoutid - 4293000000 + new_slot = self.suit_loadout_id_from_loadoutid(loadoutid) try: self.state['SuitLoadoutCurrent'] = self.state['SuitLoadouts'][f'{new_slot}'] @@ -857,8 +854,17 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.exception(f"Getting switched-to suit from slot {new_slot} ({loadoutid}") elif event_type == 'DeleteSuitLoadout': - # We should remove this from the monitor.state record of loadouts - pass + # We should remove this from the monitor.state record of loadouts. The slotid + # could end up valid due to CreateSuitLoadout events, but we won't have the + # correct new loadout data until next CAPI pull. + loadoutid = entry['LoadoutID'] + slotid = self.suit_loadout_id_from_loadoutid(loadoutid) + # This might be a Loadout that was created after our last CAPI pull. + try: + self.state['SuitLoadouts'].pop(f'{slotid}') + + except KeyError: + logger.exception(f"slot id {slotid} doesn't exist, not in last CAPI pull ?") elif event_type == 'CreateSuitLoadout': # We know we won't have data for this new one @@ -1068,6 +1074,19 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.debug(f'Invalid journal entry:\n{line!r}\n', exc_info=ex) return {'event': None} + def suit_loadout_id_from_loadoutid(self, journal_loadoutid: int) -> int: + """ + Determine the CAPI-oriented numeric slot id for a Suit Loadout. + + :param journal_loadoutid: Journal `LoadoutID` integer value. + :return: + """ + # Observed LoadoutID in SwitchSuitLoadout events are, e.g. + # 4293000005 for CAPI slot 5. + # This *might* actually be "lower 6 bits", but maybe it's not. + slotid = journal_loadoutid - 4293000000 + return slotid + def canonicalise(self, item: Optional[str]) -> str: """ Produce canonical name for a ship module. From d095e8b054240c3d3d7eabd9a1843d40c1ab3c4a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 10:43:42 +0100 Subject: [PATCH 605/727] Suits: We can't do anything on `SellSuit` yet, placeholder. --- monitor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monitor.py b/monitor.py index 05b80c2f..14043371 100644 --- a/monitor.py +++ b/monitor.py @@ -870,6 +870,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # We know we won't have data for this new one pass + elif event_type == 'SellSuit': + # Remove from known suits + # As of Odyssey Alpha Phase 2, Hotfix 5 (4.0.0.13) this isn't possible as this event + # doesn't contain the specific suit ID as per CAPI `suits` dict. + pass + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From d9d36dd12b14267a2c6a39018906ca54d906f902 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 10:55:51 +0100 Subject: [PATCH 606/727] Suits: Comments about suit/weapon events not having instance ID --- monitor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/monitor.py b/monitor.py index 14043371..7c9cd64c 100644 --- a/monitor.py +++ b/monitor.py @@ -870,12 +870,20 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # We know we won't have data for this new one pass + # `BuySuit` has no useful info as of 4.0.0.13 + elif event_type == 'SellSuit': # Remove from known suits # As of Odyssey Alpha Phase 2, Hotfix 5 (4.0.0.13) this isn't possible as this event # doesn't contain the specific suit ID as per CAPI `suits` dict. pass + # `LoadoutEquipModule` has no instance-specific ID as of 4.0.0.13 + + # `BuyWeapon` has no instance-specific ID as of 4.0.0.13 + # `SellWeapon` has no instance-specific ID as of 4.0.0.13 + # `UpgradeWeapon` has no instance-specific ID as of 4.0.0.13 + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore From 4cf86047eb54b7105d2719bff59ea236e0b2a63a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 13:44:57 +0100 Subject: [PATCH 607/727] .gitignore: ChangeLog.html --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6cc7b72a..7474987d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .gitversion .DS_Store build +ChangeLog.html dist.* dump *.bak @@ -21,4 +22,4 @@ venv *.code-workspace htmlcov/ .ignored -.coverage \ No newline at end of file +.coverage From 8e8e57024d7b9fe04b646e6180ee355c7621f02c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 14:20:00 +0100 Subject: [PATCH 608/727] Suits: Location Ship "TacticalSuit_Class1" is also on-foot This is the 'Dominator' suit. --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 7c9cd64c..251031e5 100644 --- a/monitor.py +++ b/monitor.py @@ -68,7 +68,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below _RE_CANONICALISE = re.compile(r'\$(.+)_name;') _RE_CATEGORY = re.compile(r'\$MICRORESOURCE_CATEGORY_(.+);') _RE_LOGFILE = re.compile(r'^Journal(Alpha|Beta)?\.[0-9]{12}\.[0-9]{2}\.log$') - _RE_SHIP_ONFOOT = re.compile(r'^(FlightSuit|UtilitySuit_Class.)$') + _RE_SHIP_ONFOOT = re.compile(r'^(FlightSuit|UtilitySuit_Class.|TacticalSuit_Class.)$') def __init__(self) -> None: # TODO(A_D): A bunch of these should be switched to default values (eg '' for strings) and no longer be Optional From f6611148e62031f0170c14b412fda793b6490a9b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 16:38:56 +0100 Subject: [PATCH 609/727] Suits: Add Artemis (ExplorationSuit_Class1) suit to ON_FOOT regex --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 251031e5..9c66a386 100644 --- a/monitor.py +++ b/monitor.py @@ -68,7 +68,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below _RE_CANONICALISE = re.compile(r'\$(.+)_name;') _RE_CATEGORY = re.compile(r'\$MICRORESOURCE_CATEGORY_(.+);') _RE_LOGFILE = re.compile(r'^Journal(Alpha|Beta)?\.[0-9]{12}\.[0-9]{2}\.log$') - _RE_SHIP_ONFOOT = re.compile(r'^(FlightSuit|UtilitySuit_Class.|TacticalSuit_Class.)$') + _RE_SHIP_ONFOOT = re.compile(r'^(FlightSuit|UtilitySuit_Class.|TacticalSuit_Class.|ExplorationSuit_Class.)$') def __init__(self) -> None: # TODO(A_D): A bunch of these should be switched to default values (eg '' for strings) and no longer be Optional From 53f82098208b95b0f8ac3bd8127f18d282fc9b45 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 16:56:03 +0100 Subject: [PATCH 610/727] Move AppWindow.dump_capi_data() to be in companion.Session instead It's writing CAPI data to a file, so it should be in companion.py. Also: * Use companion.CAPIData as type, not a Mapping. --- EDMarketConnector.py | 30 ++++++------------------------ companion.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index a1b8ab02..ef0b579e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -12,10 +12,10 @@ import sys import webbrowser from builtins import object, str from os import chdir, environ -from os.path import dirname, isdir, join +from os.path import dirname, join from sys import platform from time import localtime, strftime, time -from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple +from typing import TYPE_CHECKING, Optional, Tuple # Have this as early as possible for people running EDMarketConnector.exe # from cmd.exe or a bat file or similar. Else they might not be in the correct @@ -55,6 +55,7 @@ import killswitch from config import appversion, appversion_nobuild, config, copyright # isort: on +from companion import CAPIData from EDMCLogging import edmclogger, logger, logging from journal_lock import JournalLock, JournalLockResult @@ -755,26 +756,7 @@ class AppWindow(object): self.cooldown() - def dump_capi_data(self, data: Mapping[str, Any]): - """Dump CAPI data to file for examination.""" - if isdir('dump'): - system = data['lastSystem']['name'] - - if data['commander'].get('docked'): - station = f'.{data["lastStarport"]["name"]}' - - else: - station = '' - - timestamp = strftime('%Y-%m-%dT%H.%M.%S', localtime()) - with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: - h.write(json.dumps(dict(data), - ensure_ascii=False, - indent=2, - sort_keys=True, - separators=(',', ': ')).encode('utf-8')) - - def export_market_data(self, data: Mapping[str, Any]) -> bool: # noqa: CCR001 + def export_market_data(self, data: CAPIData) -> bool: # noqa: CCR001 """ Export CAPI market data. @@ -902,7 +884,7 @@ class AppWindow(object): else: if __debug__: # Recording - self.dump_capi_data(data) + companion.session.dump_capi_data(data) if not monitor.state['ShipType']: # Started game in SRV or fighter self.ship['text'] = ship_name_map.get(data['ship']['name'].lower(), data['ship']['name']) @@ -1351,7 +1333,7 @@ class AppWindow(object): self.w.update_idletasks() try: - data = companion.session.station() + data: CAPIData = companion.session.station() self.status['text'] = '' default_extension: str = '' diff --git a/companion.py b/companion.py index 6c71080a..bb9ce713 100644 --- a/companion.py +++ b/companion.py @@ -679,6 +679,25 @@ class Session(object): """Log, as error, status of requests.Response from CAPI request.""" logger.error(f'Frontier CAPI Auth: {r.url} {r.status_code} {r.reason and r.reason or "None"} {r.text}') + def dump_capi_data(self, data: CAPIData) -> None: + """Dump CAPI data to file for examination.""" + if os.path.isdir('dump'): + system = data['lastSystem']['name'] + + if data['commander'].get('docked'): + station = f'.{data["lastStarport"]["name"]}' + + else: + station = '' + + timestamp = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime()) + with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: + h.write(json.dumps(dict(data), + ensure_ascii=False, + indent=2, + sort_keys=True, + separators=(',', ': ')).encode('utf-8')) + def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully simplified """ From 74a3bea61989b6b93d19c4de96e1e76df0b93066 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 18:16:41 +0100 Subject: [PATCH 611/727] CAPI: catch lastStarport->services being an empty list (not dict)o This is caused, at least on Odyssey Alpha Phase 3, 4.0.0.20, by: 1. Jump to a new system. 2. Don't dock yet. 3. Cause CAPI pull with 'Update' button. 4. The PTS CAPI server is returning: "lastStarport": { "faction": "", "id": 3221604096, "minorfaction": "", "name": "", "services": [] }, So actually we need to decide it's not sane at all. --- companion.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/companion.py b/companion.py index bb9ce713..56f7a27b 100644 --- a/companion.py +++ b/companion.py @@ -603,7 +603,7 @@ class Session(object): return data - def station(self) -> CAPIData: + def station(self) -> CAPIData: # noqa: CCR001 """Perform CAPI /profile endpoint query for station data.""" data = self.query(URL_QUERY) if 'commander' not in data: @@ -614,6 +614,13 @@ class Session(object): return data services = data['lastStarport'].get('services', {}) + if not isinstance(services, dict): + # This happens if you're in-ship in-space and force an Update + logger.error(f'services is "{type(services)}", not dict !') + if __debug__: + self.dump_capi_data(data) + + services = {} last_starport_name = data['lastStarport']['name'] last_starport_id = int(data['lastStarport']['id']) @@ -682,13 +689,21 @@ class Session(object): def dump_capi_data(self, data: CAPIData) -> None: """Dump CAPI data to file for examination.""" if os.path.isdir('dump'): - system = data['lastSystem']['name'] + try: + system = data['lastSystem']['name'] - if data['commander'].get('docked'): - station = f'.{data["lastStarport"]["name"]}' + except (KeyError, ValueError): + system = '' - else: - station = '' + try: + if data['commander'].get('docked'): + station = f'.{data["lastStarport"]["name"]}' + + else: + station = '' + + except (KeyError, ValueError): + station = '' timestamp = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime()) with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: From e4f7c998cd8aea82fa5ad34e07ebf9591e7b382c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 15 Apr 2021 19:39:40 +0100 Subject: [PATCH 612/727] companion: Improve station() checks and documentation * Expand on the docstring to point out extra queries might be made. * Add checks for lastStarport and then name within that being properly present and set. --- companion.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/companion.py b/companion.py index 56f7a27b..60f12d4a 100644 --- a/companion.py +++ b/companion.py @@ -604,7 +604,17 @@ class Session(object): return data def station(self) -> CAPIData: # noqa: CCR001 - """Perform CAPI /profile endpoint query for station data.""" + """ + Perform CAPI quer(y|ies) for station data. + + A /profile query is performed to check that we are docked (or on foot) + and the station name and marketid match the prior Docked event. + If they do match, and the services list says they're present, also + retrieve CAPI market and/or shipyard/outfitting data and merge into + the /profile data. + + :return: Possibly augmented CAPI data. + """ data = self.query(URL_QUERY) if 'commander' not in data: logger.error('No commander in returned data') @@ -613,17 +623,33 @@ class Session(object): if not data['commander'].get('docked') and not monitor.state['OnFoot']: return data - services = data['lastStarport'].get('services', {}) + # Sanity checks in case data isn't as we expect, and maybe 'docked' flag + # is also lagging. + if (last_starport := data.get('lastStarport')) is None: + logger.error("No lastStarport in data!") + return data + + if ((last_starport_name := last_starport.get('name')) is None + or last_starport_name == ''): + # This could well be valid if you've been out exploring for a long + # time. + logger.warning("No lastStarport name!") + return data + + services = last_starport.get('services', {}) if not isinstance(services, dict): - # This happens if you're in-ship in-space and force an Update + # Odyssey Alpha Phase 3 4.0.0.20 has been observed having + # this be an empty list when you've jumped to another system + # and not yet docked. As opposed to no services key at all + # or an empty dict. logger.error(f'services is "{type(services)}", not dict !') if __debug__: self.dump_capi_data(data) + # Set an empty dict so as to not have to retest below. services = {} - last_starport_name = data['lastStarport']['name'] - last_starport_id = int(data['lastStarport']['id']) + last_starport_id = int(last_starport.get('id')) if services.get('commodities'): marketdata = self.query(URL_MARKET) From 11082f557b9bc9a421a6fa3bf1d9bc02cf4c17a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Apr 2021 06:03:48 +0000 Subject: [PATCH 613/727] build(deps-dev): bump flake8 from 3.9.0 to 3.9.1 Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.9.0 to 3.9.1. - [Release notes](https://gitlab.com/pycqa/flake8/tags) - [Commits](https://gitlab.com/pycqa/flake8/compare/3.9.0...3.9.1) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6e7338e5..116cdf7e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ wheel # Static analysis tools -flake8==3.9.0 +flake8==3.9.1 flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.4.0 From 98c946fa3184d0d0dbbc5ff2282b281a42a1d946 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 16 Apr 2021 17:11:05 +0200 Subject: [PATCH 614/727] CAPI loadouts changed from dict to list --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index ef0b579e..f49abb4c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -903,7 +903,7 @@ class AppWindow(object): if (suit := loadout.get('suit')) is not None: if (suitname := suit.get('locName')) is not None: # We've been paranoid about loadout->suit->suitname, now just assume loadouts is there - loadout_name = data['loadouts'][f"{loadout['loadoutSlotId']}"]['name'] + loadout_name = data['loadouts'][loadout['loadoutSlotId']]['name'] self.suit['text'] = f'{suitname} ({loadout_name})' self.toggle_suit_row(visible=True) From a3e0823701139c4fc4c04c1c5af004f9dc46434c Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 16 Apr 2021 17:36:53 +0200 Subject: [PATCH 615/727] Added utility sparse list index function Frontier sometimes uses dicts as sparse lists, this should work to index them either way. Doctests included do pass. --- companion.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/companion.py b/companion.py index 60f12d4a..181936ab 100644 --- a/companion.py +++ b/companion.py @@ -22,7 +22,7 @@ from email.utils import parsedate # TODO: see https://github.com/EDCD/EDMarketConnector/issues/569 from http.cookiejar import LWPCookieJar # noqa: F401 - No longer needed but retained in case plugins use it from os.path import join -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import Mapping, OrderedDict, TYPE_CHECKING, Any, Dict, List, Optional, TypeVar, Union import requests @@ -848,5 +848,35 @@ def ship(data: CAPIData) -> CAPIData: return filter_ship(data['ship']) +V = TypeVar('V') + + +def index_possibly_sparse_list(data: Union[Mapping[str, V], List[V]], key: int) -> V: + """ + Index into a "list" that may or may not be sparseified into a dict. + + :param data: List or Dict to index + :param key: Key to use to index + :raises ValueError: When data is of an unexpected type + :return: The value at the key + + >>> data = {"1": "test"} + >>> index_possibly_sparse_list(data, 1) + 'test' + + >>> data = ["test_list"] + >>> index_possibly_sparse_list(data, 0) + 'test_list' + """ + if isinstance(data, list): + return data[key] + + elif isinstance(data, (dict, OrderedDict)): + return data[str(key)] + + else: + raise ValueError(f'Unexpected data type {type(data)}') + + # singleton session = Session() From 6f86e173cd9b45d3936a9847a76f723d6dbbe748 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 16 Apr 2021 17:41:31 +0200 Subject: [PATCH 616/727] indexed sparse list rather than guessing --- EDMarketConnector.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index f49abb4c..f019f8f9 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -55,7 +55,7 @@ import killswitch from config import appversion, appversion_nobuild, config, copyright # isort: on -from companion import CAPIData +from companion import CAPIData, index_possibly_sparse_list from EDMCLogging import edmclogger, logger, logging from journal_lock import JournalLock, JournalLockResult @@ -903,7 +903,10 @@ class AppWindow(object): if (suit := loadout.get('suit')) is not None: if (suitname := suit.get('locName')) is not None: # We've been paranoid about loadout->suit->suitname, now just assume loadouts is there - loadout_name = data['loadouts'][loadout['loadoutSlotId']]['name'] + loadout_name = index_possibly_sparse_list( + data['loadouts'], loadout['loadoutSlotId'] + )['name'] + self.suit['text'] = f'{suitname} ({loadout_name})' self.toggle_suit_row(visible=True) From 0913cff47232795372ad2194d28eda27a8b7b081 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 16 Apr 2021 17:46:22 +0200 Subject: [PATCH 617/727] fixed import order --- companion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion.py b/companion.py index 181936ab..f1f38bd6 100644 --- a/companion.py +++ b/companion.py @@ -22,7 +22,7 @@ from email.utils import parsedate # TODO: see https://github.com/EDCD/EDMarketConnector/issues/569 from http.cookiejar import LWPCookieJar # noqa: F401 - No longer needed but retained in case plugins use it from os.path import join -from typing import Mapping, OrderedDict, TYPE_CHECKING, Any, Dict, List, Optional, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, OrderedDict, TypeVar, Union import requests From eb046737510a4505dc9302ea479b8c58a4e2ca72 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 19 Apr 2021 12:30:24 +0100 Subject: [PATCH 618/727] PLUGINS.md: Document dual-type of Suits, and helper functions. --- PLUGINS.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/PLUGINS.md b/PLUGINS.md index 04012421..e09e8359 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -537,10 +537,17 @@ Content of `state` (updated to the current journal entry): | `Data` | `dict` | 'Data' MicroResources in Odyssey, `int` count each. | | `BackPack` | `dict` | `dict` of Odyssey MicroResources in backpack. | | `SuitCurrent` | `dict` | CAPI-returned data of currently worn suit. NB: May be `None` if no data. | -| `Suits` | `dict` | CAPI-returned data of owned suits. NB: May be `None` if no data. | +| `Suits` | `dict` or `list`[1] | CAPI-returned data of owned suits. NB: Type depends on if array is sparse or not. May be `None` if no data. | | `SuitLoadoutCurrent` | `dict` | CAPI-returned data of current Suit Loadout. NB: May be `None` if no data. | | `SuitLoadouts` | `dict` | CAPI-returned data of all Suit Loadouts. NB: May be `None` if no data. | +[1] - With `Suits` there's a caveat depending on all the slots from 0 are +contiguously used or not. If they are then the type is `list` and +indexing is purely numeric. If not then it's a `dict` and you need to index it +with a string. There is `companion.index_possibly_sparse_list()` to aid +with this, or if you wish to iterate over it use `companion.listify()` to +fill in any gaps and have a `list` to operate on. + New in version 4.1.6: `CargoJSON` contains the raw data from the last read of `Cargo.json` passed From dfc58e0d92c526eb43c9a53824291423369194da Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 19 Apr 2021 12:34:34 +0100 Subject: [PATCH 619/727] Translations: Updated with latest from OneSky --- L10n/cs.strings | 60 +++++++++++++++++++++------------ L10n/de.strings | 63 ++++++++++++++++++++++------------ L10n/es.strings | 72 +++++++++++++++++++++++++++++++++------ L10n/fi.strings | 37 ++++++++++---------- L10n/fr.strings | 22 +++++------- L10n/hu.strings | 1 - L10n/it.strings | 43 +++++++++++------------ L10n/ja.strings | 63 ++++++++++++++++++++++------------ L10n/ko.strings | 63 ++++++++++++++++++++++------------ L10n/lv.strings | 1 - L10n/nl.strings | 22 +++++------- L10n/pl.strings | 43 +++++++++++------------ L10n/pt-BR.strings | 75 +++++++++++++++++++++++++++++++---------- L10n/pt-PT.strings | 63 ++++++++++++++++++++++------------ L10n/ru.strings | 63 ++++++++++++++++++++++------------ L10n/sl.strings | 1 - L10n/sr-Latn-BA.strings | 63 ++++++++++++++++++++++------------ L10n/sr-Latn.strings | 63 ++++++++++++++++++++++------------ L10n/sv-SE.strings | 22 +++++------- L10n/uk.strings | 22 +++++------- L10n/zh-Hans.strings | 63 ++++++++++++++++++++++------------ 21 files changed, 586 insertions(+), 339 deletions(-) diff --git a/L10n/cs.strings b/L10n/cs.strings index 253b8d23..822fd745 100644 --- a/L10n/cs.strings +++ b/L10n/cs.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Procenta UI škálování"; +/* Language name */ +"!Language" = "Čeština"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 znamená plně neprůhledné.{CR}Okno se aktualizuje v reálném čase"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 je výchozí hodnota{CR}je potřeba restartovat,{CR}aby se změna projevila!"; -/* Language name */ -"!Language" = "Čeština"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "O {APP}"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Procházet..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Nebyla vrácena žádná data komandéra"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Nebyla vrácena žádná data komandéra"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Upravit"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Pluginy, které nepodporují Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "Chyba"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Chyba: Nelze se připojit k EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Chyba: Nelze se připojit k Inaře"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Chyba: Nejde ověřit token customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Chyba: customer_id nesouhlasí!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Chyba: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Chyba: Chybné přihlašovací údaje"; +/* [companion.py] */ +"Error: unable to get token" = "Chyba: nepovedlo se získat token"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Chyba: Nesprávný CMDR"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Přihlašovací údaje k Inaře"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informace jak migrovat pluginy."; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Adresář deníku je již uzamčen"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Půjčka"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Míra logování"; + /* [EDMarketConnector.py] */ "Logging in..." = "Přihlašování..."; /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Průhlednost hlavního okna"; + /* [prefs.py] */ "Market data in CSV format file" = "Obchodní data ve formátu CSV"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Jeden nebo více aktivních pluginů ještě stále nepodporuje Python 3.x. Podívejte se na jejich seznam v záložce '{PLUGINS}' v '{FILE}' > '{SETTINGS}'. Zkontrolujte si jestli není dostupná novější verze pluginu, pokud ne, tak kontaktujte vývojáře pluginu o tom, že musí upravit jejich plugin pro Python 3.x.\n\nPlugin můžete vypnout přidáním '{DISABLED}' na konec názvu jeho složky."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Pouze pokud je Elite: Dangerous aktivní"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Složka pluginů"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Pluginy, které nepodporují Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Jeden nebo více aktivních pluginů ještě stále nepodporuje Python 3.x. Podívejte se na jejich seznam v záložce '{PLUGINS}' v '{FILE}' > '{SETTINGS}'. Zkontrolujte si jestli není dostupná novější verze pluginu, pokud ne, tak kontaktujte vývojáře pluginu o tom, že musí upravit jejich plugin pro Python 3.x.\n\nPlugin můžete vypnout přidáním '{DISABLED}' na konec názvu jeho složky."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Pluginy, které nepodporují Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informace jak migrovat pluginy."; +"Plugins Without Python 3.x Support:" = "Pluginy bez podpory Python 3.x:"; /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +529,9 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Procenta UI škálování"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Aktualizovat"; @@ -549,6 +570,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} vyžaduje oprávnění pro použití klávesových zkratek"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Míra logování"; diff --git a/L10n/de.strings b/L10n/de.strings index 492de5de..250733c2 100644 --- a/L10n/de.strings +++ b/L10n/de.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "UI-Skalierung in Prozent"; +/* Language name */ +"!Language" = "Deutsch"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 bedeutet komplett undurchsichtig.{CR}Fenster wird in Echtzeit aktualisiert"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 bedeutet Standardwert{CR}Neustart erforderlich, um{CR}Änderungen zu übernehmen!"; -/* Language name */ -"!Language" = "Deutsch"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "Über {APP}"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Durchsuchen..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Keine Kommandanten-Daten erhalten"; - /* Federation rank. [stats.py] */ "Cadet" = "Kadett"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Keine Kommandanten-Daten erhalten"; + /* CQC rank. [stats.py] */ "Champion" = "Sieger"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Bearbeiten"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins ohne Python 3.x Support"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Unternehmer"; +/* [companion.py] */ +"Error" = "Fehler"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Fehler: Keine Verbindung zum EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Fehler: Verbindung zu Inara fehlgeschlagen"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Fehler: Konnte das Token customer_id nicht prüfen"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Fehler: customer_id stimmt nicht überein!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Fehler: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Fehler: Ungültige Anmeldedaten"; +/* [companion.py] */ +"Error: unable to get token" = "Fehler: konnte Token nicht erhalten"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Fehler: Falscher Kdt."; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara-Anmeldedaten"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informationen zum Migrieren von Plugins"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Journal-Ordner bereits gesperrt"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Kredit"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Log-Level"; + /* [EDMarketConnector.py] */ "Logging in..." = "Anmelden..."; /* Empire rank. [stats.py] */ "Lord" = "Fürst"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Durchsichtigkeit Hauptfenster"; + /* [prefs.py] */ "Market data in CSV format file" = "Marktdaten als CSV Datei"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Eins oder mehr deiner aktivierten Plugins hat noch keinen Support für Python 3.x. Du kannst dir die Liste im '{PLUGINS}'-Tab unter '{FILE}' > '{SETTINGS}' ansehen. Du solltest prüfen, ob es für diese Updates gibt und ansonsten dem Entwickler Bescheid geben, dass sie ihren Code für Python 3.x aktualisieren müssen.\n\nDu kannst ein Plugin deaktivieren, indem du dessen Ordner ein '{DISABLED}' am Ende des Namens anhängst."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Nur wenn Elite: Dangerous geöffnet ist"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Plugin-Ordner"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins ohne Python 3.x Support"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Eins oder mehr deiner aktivierten Plugins hat noch keinen Support für Python 3.x. Du kannst dir die Liste im '{PLUGINS}'-Tab unter '{FILE}' > '{SETTINGS}' ansehen. Du solltest prüfen, ob es für diese Updates gibt und ansonsten dem Entwickler Bescheid geben, dass sie ihren Code für Python 3.x aktualisieren müssen.\n\nDu kannst ein Plugin deaktivieren, indem du dessen Ordner ein '{DISABLED}' am Ende des Namens anhängst."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins ohne Python 3.x Support"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informationen zum Migrieren von Plugins"; +"Plugins Without Python 3.x Support:" = "Plugins ohne Python 3.x Support"; /* Federation rank. [stats.py] */ "Post Captain" = "Kapitän"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Magnat"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "UI-Skalierung in Prozent"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Unbekannt"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Aktualisieren"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} benötigt für Tastenkürzel Systemrechte (Bedienungshilfen)"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Log-Level"; diff --git a/L10n/es.strings b/L10n/es.strings index 8dc4eb49..84533ae4 100644 --- a/L10n/es.strings +++ b/L10n/es.strings @@ -1,6 +1,12 @@ /* Language name */ "!Language" = "Español"; +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 significa completamente opaco.{CR}La ventana se actualiza en tiempo real."; + +/* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ +"100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 significa Por Defecto{CR}Se requiere reiniciar{CR}para que los cambios surtan efecto!"; + /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "Acerca de {APP}"; @@ -43,6 +49,9 @@ /* Federation rank. [stats.py] */ "Cadet" = "Cadete"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: No se devolvió datos de comandante"; + /* CQC rank. [stats.py] */ "Champion" = "Campeón"; @@ -121,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Editar"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins Sin Soporte para Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Élite"; @@ -139,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Empresario"; +/* [companion.py] */ +"Error" = "Error"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Error: No se puede conectar a EDDN"; @@ -148,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Error: No se puede conectar con Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Error: No se pudo comprobar el token customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Error: ¡customer_id no coincide!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Error: EDSM {MSG}"; @@ -166,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Error: Credenciales Inválidas"; +/* [companion.py] */ +"Error: unable to get token" = "Error: no se pudo conseguir el token"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Error: Cmdt Incorrecto"; @@ -220,9 +244,18 @@ /* Hotkey/Shortcut settings prompt on Windows. [prefs.py] */ "Hotkey" = "Tecla de acceso directo"; +/* Changed journal update_lock failed [monitor.py] */ +"Ignore" = "Ignorar"; + /* Section heading in settings. [inara.py] */ "Inara credentials" = "Credenciales de Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Información sobre migración de plugins"; + +/* Changed journal update_lock failed [monitor.py] */ +"Journal directory already locked" = "El Directorio Journal ya está bloqueado"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Tecla de acceso directo"; @@ -247,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Préstamo"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Nivel de registro"; + /* [EDMarketConnector.py] */ "Logging in..." = "Identificándose..."; /* Empire rank. [stats.py] */ "Lord" = "Señor"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Transparencia de la ventana principal"; + /* [prefs.py] */ "Market data in CSV format file" = "Datos de mercado en formato CSV"; @@ -295,6 +334,9 @@ /* [prefs.py] */ "OK" = "Aceptar"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Uno o más de tus plugins habilitados aún no tienen soporte para Python 3.x. Por favor, consulta la lista en la pestaña '{PLUGINS}' de '{FILE}' > '{SETTINGS}'. Deberías comprobar si hay una versión actualizada disponible, si no, avisa al desarrollador de que necesita actualizar el código para Python 3.x.\n\nPuedes deshabilitar un plugin cambiando el nombre de su carpeta para que tenga '{DISABLED}' al final del nombre."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Solo cuando Elite: Dangerous es la aplicación activa"; @@ -337,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Carpeta de Plugins"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins Sin Soporte para Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Uno o más de tus plugins habilitados aún no tienen soporte para Python 3.x. Por favor, consulta la lista en la pestaña '{PLUGINS}' de '{FILE}' > '{SETTINGS}'. Deberías comprobar si hay una versión actualizada disponible, si no, avisa al desarrollador de que necesita actualizar el código para Python 3.x.\n\nPuedes deshabilitar un plugin cambiando el nombre de su carpeta para que tenga '{DISABLED}' al final del nombre."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins sin Soporte para Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Información sobre migración de plugins"; +"Plugins Without Python 3.x Support:" = "Plugins sin soporte para Python 3.x:"; /* Federation rank. [stats.py] */ "Post Captain" = "Capitán de navío"; @@ -403,6 +436,9 @@ /* Help menu item. [EDMarketConnector.py] */ "Release Notes" = "Notas de la versión"; +/* Changed journal update_lock failed [monitor.py] */ +"Retry" = "Reintentar"; + /* Multicrew role label in main window. [EDMarketConnector.py] */ "Role" = "Rol"; @@ -448,6 +484,9 @@ /* Setting to decide which ship outfitting website to link to - either E:D Shipyard or Coriolis. [prefs.py] */ "Shipyard" = "Astillero"; +/* Status line text that appears when process exit sequence starts [EDMarketConnector.py] */ +"Shutting down..." = "Apagando..."; + /* Empire rank. [stats.py] */ "Squire" = "Escudero"; @@ -469,6 +508,9 @@ /* Main window. [EDMarketConnector.py] */ "System" = "Sistema"; +/* Changed journal update_lock failed [monitor.py] */ +"The new Journal Directory location is already locked.{CR}You can either attempt to resolve this and then Retry, or choose to Ignore this." = "La localización Directorio Journal ya está bloqueada.{CR}Puedes intentar resolverlo y pulsar Reintentar, o elegir Ignorar esto."; + /* Appearance setting. [prefs.py] */ "Theme" = "Tema"; @@ -487,9 +529,18 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Magnate"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Porcentaje escala UI"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Desconocido"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Actualizar"; +/* Option to use alternate URL method on shipyard links [prefs.py] */ +"Use alternate URL method" = "Usar método URL alternativo"; + /* Status dialog subtitle - CR value of ship. [stats.py] */ "Value" = "Valor"; @@ -522,4 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} necesita permisos para usar teclas de acceso directo"; - diff --git a/L10n/fi.strings b/L10n/fi.strings index 98782961..f88a42a3 100644 --- a/L10n/fi.strings +++ b/L10n/fi.strings @@ -1,12 +1,9 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Käyttöliittymän skaalausprosentti"; +/* Language name */ +"!Language" = "Suomi"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 tarkoittaa oletusta{CR}Muutosten käyttöönotto{CR}edellyttää uudelleenkäynnistystä!"; -/* Language name */ -"!Language" = "Suomi"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "Ohjelmasta {APP}"; @@ -127,6 +124,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Muokkaa"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Lisäosat ilman Python 3.x -tukea"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -229,6 +229,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inaran kirjautuminen"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Tietoja lisäosien siirrosta"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Näppäimistöoikopolku"; @@ -253,6 +256,9 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Lainaa jäljellä"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Lokin syvyys"; + /* [EDMarketConnector.py] */ "Logging in..." = "Kirjaudutaan..."; @@ -301,6 +307,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Yksi tai useampi käyttämistäsi lisäosista ei sisällä vielä Pyhton 3.x -tukea. Tarkista tiedoston '{FILE}' > '{SETTINGS}' välilehti '{PLUGINS}' lisäosista, onko niistä uudempaa versiota saatavilla; muussa tapauksessa ota yhteyttä sen kehittäjään ja kerro, että sen lähdekoodi on päivitettävä Python 3.x -tasolle.\n\nVoit estää lisäosan toiminnan nimeämällä sen hakemiston siten, että se päättyy tekstiin '{DISABLED}'."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Vain jos Elite:Dangerous on käynnissä"; @@ -343,18 +352,6 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Lisäosien hakemistosijainti"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Lisäosat ilman Python 3.x -tukea"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Yksi tai useampi käyttämistäsi lisäosista ei sisällä vielä Pyhton 3.x -tukea. Tarkista tiedoston '{FILE}' > '{SETTINGS}' välilehti '{PLUGINS}' lisäosista, onko niistä uudempaa versiota saatavilla; muussa tapauksessa ota yhteyttä sen kehittäjään ja kerro, että sen lähdekoodi on päivitettävä Python 3.x -tasolle.\n\nVoit estää lisäosan toiminnan nimeämällä sen hakemiston siten, että se päättyy tekstiin '{DISABLED}'."; - -/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Lisäosat ilman Python 3.x -tukea"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Tietoja lisäosien siirrosta"; - /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -496,6 +493,9 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Käyttöliittymän skaalausprosentti"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Päivitä"; @@ -534,6 +534,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} tarvitsee lupasi pikakuvakkeiden käyttämiseen"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Lokin syvyys"; diff --git a/L10n/fr.strings b/L10n/fr.strings index 617fc168..5dd8c2ba 100644 --- a/L10n/fr.strings +++ b/L10n/fr.strings @@ -121,6 +121,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Édition"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins non compatibles avec Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Élite"; @@ -223,6 +226,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Informations d'identification pour Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informations sur la migration des plugins"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Raccourci clavier"; @@ -295,6 +301,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Un ou plusieurs de vos plugins activés ne sont pas encore compatibles avec Python 3.x. Regardez la liste sur l'onglet '{PLUGINS}' de '{FILE}' > '{SETTINGS}'. Vous devriez vérifier s'il y a une version mise à jour, sinon alertez le développeur qu'il doit mettre à jour le code pour Python 3.x.\n\nVous pouvez désactiver un plugin en renommant son dossier pour qu'il ait '{DISABLED}' à la fin du nom."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Seulement quand Elite: Dangerous est l'application active"; @@ -337,18 +346,6 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Répertoire des plugins"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins non compatibles avec Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Un ou plusieurs de vos plugins activés ne sont pas encore compatibles avec Python 3.x. Regardez la liste sur l'onglet '{PLUGINS}' de '{FILE}' > '{SETTINGS}'. Vous devriez vérifier s'il y a une version mise à jour, sinon alertez le développeur qu'il doit mettre à jour le code pour Python 3.x.\n\nVous pouvez désactiver un plugin en renommant son dossier pour qu'il ait '{DISABLED}' à la fin du nom."; - -/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins non compatibles avec Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informations sur la migration des plugins"; - /* Federation rank. [stats.py] */ "Post Captain" = "Capitaine de Vaisseau"; @@ -522,4 +519,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} a besoin de permissions pour utiliser les raccourcis"; - diff --git a/L10n/hu.strings b/L10n/hu.strings index 18880370..6d5fa988 100644 --- a/L10n/hu.strings +++ b/L10n/hu.strings @@ -507,4 +507,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} engedély szükséges a parancsikon használatához"; - diff --git a/L10n/it.strings b/L10n/it.strings index c6f9258c..81c6cf2e 100644 --- a/L10n/it.strings +++ b/L10n/it.strings @@ -1,12 +1,9 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Percentuale zoom della UI"; +/* Language name */ +"!Language" = "Italiano"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 significa Default{CR}Riavvio Richiesto per{CR}applicare i cambiamenti!"; -/* Language name */ -"!Language" = "Italiano"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "Informazioni su {APP}"; @@ -46,12 +43,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Sfoglia..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Nessun dato sul commandante"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Nessun dato sul commandante"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +127,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Appunti"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins senza Supporto Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -235,6 +235,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Credenziali per Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informazioni sulla migrazione dei plugins"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "cartella Journal già bloccata"; @@ -262,6 +265,9 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Prestito"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Livello di Log"; + /* [EDMarketConnector.py] */ "Logging in..." = "Mi sto loggando..."; @@ -310,6 +316,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Uno o più dei tuoi plugin non ha ancora il supporto per Python 3.x. Per favore guarda la lista '{PLUGINS}' nella tab a '{FILE}' > '{SETTINGS}'. Dovresti controllare se ci sono aggiornamenti, altrimenti avvisa gli sviluppatori che devono aggiornare il codice a Python 3.x.\n\nPuoi disabilitare il plugin rinominando la cartella aggiungendo '{DISABLED}' alla fine del nome."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Solo quando “Elite: Dangerous” è in primo piano"; @@ -352,18 +361,6 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Cartella dei plugins"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins senza Supporto Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Uno o più dei tuoi plugin non ha ancora il supporto per Python 3.x. Per favore guarda la lista '{PLUGINS}' nella tab a '{FILE}' > '{SETTINGS}'. Dovresti controllare se ci sono aggiornamenti, altrimenti avvisa gli sviluppatori che devono aggiornare il codice a Python 3.x.\n\nPuoi disabilitare il plugin rinominando la cartella aggiungendo '{DISABLED}' alla fine del nome."; - -/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins senza Supporto Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informazioni sulla migrazione dei plugins"; - /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +508,9 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Percentuale zoom della UI"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Recupera"; @@ -549,6 +549,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} ha bisogno dei permessi per usare le scorciatoie"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Livello di Log"; diff --git a/L10n/ja.strings b/L10n/ja.strings index 3e933735..312c91e2 100644 --- a/L10n/ja.strings +++ b/L10n/ja.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "UIスケール比率"; +/* Language name */ +"!Language" = "日本語"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100は完全に不透明であることを意味します。{CR}ウィンドウはリアルタイムで更新されます"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100はデフォルトを意味します{CR}変更した値を反映するには{CR}再起動が必要です!"; -/* Language name */ -"!Language" = "日本語"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "{APP} について"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "参照..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: コマンダーのデータが返ってきませんでした"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: コマンダーのデータが返ってきませんでした"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "編集"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: プラグインがPython 3.xをサポートしていません"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "エラー"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "エラー: EDDNに接続できません"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "エラー: Inaraに接続できません"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "エラー: customer_idトークンを確認できませんでした"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "エラー: customer_idがマッチしません!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "エラー: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "エラー: 認証情報に誤りがあります"; +/* [companion.py] */ +"Error: unable to get token" = "エラー: トークンが取得できません"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "エラー: 不適切なCmdr"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara認証情報"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "プラグインの移行に関する情報"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "ジャーナルディレクトリは既にロックされています"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "負債"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "ログレベル"; + /* [EDMarketConnector.py] */ "Logging in..." = "ログイン中..."; /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "メインウィンドウの透明度"; + /* [prefs.py] */ "Market data in CSV format file" = "市場データをCSV形式で記録する"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "了解"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "有効にしている1つ以上のプラグインがPython 3.xをサポートしていません。'{FILE}' > '{SETTINGS}'\nメニューで表示される設定ダイアログの'{PLUGINS}' タブの一覧を確認してください。更新済みのバージョンがあるかを確認し、なければ開発者にPython 3.xに対応するように開発者に連絡してください。\n\nプラグインを無効にするにはフォルダ名の最後に'{DISABLED}'を追加してください。"; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Elite: Dangerousがアクティブの時だけ有効"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "プラグインフォルダ"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: プラグインがPython 3.xをサポートしていません"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "有効にしている1つ以上のプラグインがPython 3.xをサポートしていません。'{FILE}' > '{SETTINGS}'\nメニューで表示される設定ダイアログの'{PLUGINS}' タブの一覧を確認してください。更新済みのバージョンがあるかを確認し、なければ開発者にPython 3.xに対応するように開発者に連絡してください。\n\nプラグインを無効にするにはフォルダ名の最後に'{DISABLED}'を追加してください。"; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "EDMC: プラグインがPython 3.xをサポートしていません"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "プラグインの移行に関する情報"; +"Plugins Without Python 3.x Support:" = "Python 3.xサポートのないプラグイン:"; /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "UIスケール比率"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "不明"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "更新"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} がショートカットを利用するには許可が必要です"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "ログレベル"; diff --git a/L10n/ko.strings b/L10n/ko.strings index 626116fd..05e64913 100644 --- a/L10n/ko.strings +++ b/L10n/ko.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "UI 스케일 백분율"; +/* Language name */ +"!Language" = "한국어(Korean)"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100은 완전히 불투명함을 의미합니다.{CR}창은 실시간으로 업데이트됨"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100은 '기본 설정'을 의미하며{CR}변경사항 적용을 위해{CR}재시작이 요구됩니다!"; -/* Language name */ -"!Language" = "한국어(Korean)"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "{APP} 정보"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "찾아보기..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: 커맨더 정보가 반환되지 않음"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: 커맨더 정보가 반환되지 않음"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "편집"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Python 3.x을 지원하지 않는 플러그인"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "오류"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "오류: EDDN에 연결할 수 없음"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "오류: Inara에 연결할 수 없음"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "오류: customer_id 토큰을 확인할 수 없었음"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "오류: customer_id가 일치하지 않습니다!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "오류: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "오류: 잘못된 자격 증명"; +/* [companion.py] */ +"Error: unable to get token" = "오류: 토큰을 받지 못함"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "오류: 잘못된 Cmdr"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara 계정 정보"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "플러그인 위치 변경에 대한 정보"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "저널 디렉터리가 이미 잠김"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "대출"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "로깅 수준"; + /* [EDMarketConnector.py] */ "Logging in..." = "로그인하는 중..."; /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "메인 창 투명도"; + /* [prefs.py] */ "Market data in CSV format file" = "CSV 형식 파일의 마켓 정보"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "활성화된 플러그인 중 1개 이상이 Python 3.x를 지원하지 않습니다. '{FILE}' > '{SETTINGS}' 에서 '{PLUGINS}' 탭에 들어가 활성화되어있는 플러그인 목록을 확인하십시오. 플러그인들 중 새 버전이 나온 것이 있는지도 확인해보시고, 만약 3.x를 지원하지도, 새 버전도 없다면 해당 플러그인의 개발자에게 코드를 수정하기를 문의하십시오.\n\n플러그인을 비활성화하려면 '{DISABLED}'를 폴더명 뒤에 추가하면 됩니다."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Elite: Dangerous가 활성 창 상태일때만"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "플러그인 폴더"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Python 3.x을 지원하지 않는 플러그인"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "활성화된 플러그인 중 1개 이상이 Python 3.x를 지원하지 않습니다. '{FILE}' > '{SETTINGS}' 에서 '{PLUGINS}' 탭에 들어가 활성화되어있는 플러그인 목록을 확인하십시오. 플러그인들 중 새 버전이 나온 것이 있는지도 확인해보시고, 만약 3.x를 지원하지도, 새 버전도 없다면 해당 플러그인의 개발자에게 코드를 수정하기를 문의하십시오.\n\n플러그인을 비활성화하려면 '{DISABLED}'를 폴더명 뒤에 추가하면 됩니다."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Python 3.x을 지원하지 않는 플러그인"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "플러그인 위치 변경에 대한 정보"; +"Plugins Without Python 3.x Support:" = "Python 3.x을 지원하지 않는 플러그인:"; /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "UI 스케일 백분율"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "알 수 없음"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "새로 고침"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "단축기 사용을 위해선 {APP}이 권한 허용을 필요로 합니다"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "로깅 수준"; diff --git a/L10n/lv.strings b/L10n/lv.strings index 8247abc4..673421ff 100644 --- a/L10n/lv.strings +++ b/L10n/lv.strings @@ -480,4 +480,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} vajag atļaujas lai izmantotu īssceļus"; - diff --git a/L10n/nl.strings b/L10n/nl.strings index 747d4452..3c58da8b 100644 --- a/L10n/nl.strings +++ b/L10n/nl.strings @@ -121,6 +121,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Bewerken"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMS: Plugins zonder Python 3.x ondersteuning"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -223,6 +226,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara inlog gegevens"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informatie over plugins migreren"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Toetscombinaties"; @@ -295,6 +301,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Een of meer ingeschakelde plugins hebben nog geen Python 3.x ondersteuning. Kijk op de lijst op de '{PLUGINS}' tab van '{FILE}' > '{SETTINGS}'. Check of er een bijgewerkte versie beschikbaar is. Laat anders de developer weten dat ze de code moeten updaten voor Python 3.x.\n\nJe kan de plugin uitschakelen door het mapje te hernoemen met '{DISABLED}' aan het eind van de naam."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Alleen wanneer Elite: Dangerous de actieve applicatie is"; @@ -337,18 +346,6 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Plugins map"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMS: Plugins zonder Python 3.x ondersteuning"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Een of meer ingeschakelde plugins hebben nog geen Python 3.x ondersteuning. Kijk op de lijst op de '{PLUGINS}' tab van '{FILE}' > '{SETTINGS}'. Check of er een bijgewerkte versie beschikbaar is. Laat anders de developer weten dat ze de code moeten updaten voor Python 3.x.\n\nJe kan de plugin uitschakelen door het mapje te hernoemen met '{DISABLED}' aan het eind van de naam."; - -/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins zonder Python 3.x support"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informatie over plugins migreren"; - /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -525,4 +522,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} heeft toestemming nodig om toetscombinaties te gebruiken"; - diff --git a/L10n/pl.strings b/L10n/pl.strings index 7f41bbdd..9cf8676a 100644 --- a/L10n/pl.strings +++ b/L10n/pl.strings @@ -1,12 +1,9 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Skalowanie UI"; +/* Language name */ +"!Language" = "Polski"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 oznacza wartość domyślną{CR}Zmiany zostaną wprowadzone po{CR}ponownym uruchomieniu programu!"; -/* Language name */ -"!Language" = "Polski"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "{APP}..."; @@ -46,12 +43,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Przeglądaj..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Nie zwrócono danych dowódcy"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Nie zwrócono danych dowódcy"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +127,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Edycja"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Pluginy Nie Wspierające Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -235,6 +235,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara - uprawnienia"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informacja o migracji pluginów"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Katalog dziennika zablokowany"; @@ -262,6 +265,9 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Pożyczka"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Poziom logowania"; + /* [EDMarketConnector.py] */ "Logging in..." = "Logowanie..."; @@ -310,6 +316,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Co najmniej jeden z uruchomionych pluginów nie wspiera Python 3.x. Sprawdź listę w '{FILE}' > '{SETTINGS}', sekcja '{PLUGINS}'. Upewnij się, że dostępna jest aktualna wersja pluginu, w przeciwnym razie poinformuj twórcę, że należy zaktualizować kod do wersji Python 3.x.\n\nMożesz wyłączyć plugin, dodając '{DISABLED}' na koniec nazwy jego folderu."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Tylko gdy Elite: Dangerous jest aplikacją aktywną"; @@ -352,18 +361,6 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Folder pluginów"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Pluginy Nie Wspierające Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Co najmniej jeden z uruchomionych pluginów nie wspiera Python 3.x. Sprawdź listę w '{FILE}' > '{SETTINGS}', sekcja '{PLUGINS}'. Upewnij się, że dostępna jest aktualna wersja pluginu, w przeciwnym razie poinformuj twórcę, że należy zaktualizować kod do wersji Python 3.x.\n\nMożesz wyłączyć plugin, dodając '{DISABLED}' na koniec nazwy jego folderu."; - -/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Pluginy nie wspierające Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informacja o migracji pluginów"; - /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +508,9 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Skalowanie UI"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Aktualizacja"; @@ -549,6 +549,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} wymaga uprawnień by{CR}móc korzystać ze skrótów klawiszowych."; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Poziom logowania"; diff --git a/L10n/pt-BR.strings b/L10n/pt-BR.strings index 7e6b1e5f..41b66913 100644 --- a/L10n/pt-BR.strings +++ b/L10n/pt-BR.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Porcentagem de escala da IU"; +/* Language name */ +"!Language" = "Português (Brasil)"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 significa totalmente opaco.{CR}A janela é atualizada em tempo real."; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 significa Padrão{CR}Necessário Reiniciar para as{CR}alterações entrarem em vigor!"; -/* Language name */ -"!Language" = "Português (Brasil)"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "Sobre {APP}"; @@ -49,6 +49,9 @@ /* Federation rank. [stats.py] */ "Cadet" = "Aspirante"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Nenhum dado de comandante retornado"; + /* CQC rank. [stats.py] */ "Champion" = "Campeão"; @@ -127,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Editar"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins sem Suporte ao Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -145,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Empresário"; +/* [companion.py] */ +"Error" = "Erro"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Erro: Não é possível conectar-se ao EDDN"; @@ -154,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Erro: Não é possível conectar-se a Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Erro: não foi possível verificar o token customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Erro: customer_id diferente!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Erro: EDSM {MSG}"; @@ -172,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Erro: Credenciais Inválidas"; +/* [companion.py] */ +"Error: unable to get token" = "Erro: não foi possível obter o token"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Erro: Cmdt Errado"; @@ -226,9 +244,18 @@ /* Hotkey/Shortcut settings prompt on Windows. [prefs.py] */ "Hotkey" = "Tecla de atalho"; +/* Changed journal update_lock failed [monitor.py] */ +"Ignore" = "Ignorar"; + /* Section heading in settings. [inara.py] */ "Inara credentials" = "Credenciais do Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informações de migração de plugins"; + +/* Changed journal update_lock failed [monitor.py] */ +"Journal directory already locked" = "Diretório de Jornais já está bloqueado"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Atalho de teclado"; @@ -253,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Empréstimo"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Nível de Log"; + /* [EDMarketConnector.py] */ "Logging in..." = "Efetuando login..."; /* Empire rank. [stats.py] */ "Lord" = "Lorde"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Transparência da janela principal"; + /* [prefs.py] */ "Market data in CSV format file" = "Dados de mercado no arquivo de formato CSV"; @@ -301,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Um ou mais dos plugins habilitados não possuem suporte ao Python 3.x. Você pode ver a lista na guia '{PLUGINS}' em '{FILE}' > '{SETTINGS}'. Você deve verificar se existe versão atualizada ou então avisar o desenvolvedor de que ele precisa atualizar o código para o Python 3.x.\n\nVocê pode desabilitar um plugin renomeando sua pasta para que seu nome termine com '{DISABLED}'."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Somente quando o Elite: Dangerous é o aplicativo ativo"; @@ -343,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Pasta dos plugins"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins sem Suporte ao Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Um ou mais dos plugins habilitados não possuem suporte ao Python 3.x. Você pode ver a lista na guia '{PLUGINS}' em '{FILE}' > '{SETTINGS}'. Você deve verificar se existe versão atualizada ou então avisar o desenvolvedor de que ele precisa atualizar o código para o Python 3.x.\n\nVocê pode desabilitar um plugin renomeando sua pasta para que seu nome termine com '{DISABLED}'."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins sem Suporte ao Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informações de migração de plugins"; +"Plugins Without Python 3.x Support:" = "Plugins sem suporte a Python 3.x:"; /* Federation rank. [stats.py] */ "Post Captain" = "Capitão de Fragata"; @@ -409,6 +436,9 @@ /* Help menu item. [EDMarketConnector.py] */ "Release Notes" = "Notas de atualização"; +/* Changed journal update_lock failed [monitor.py] */ +"Retry" = "Tentar novamente"; + /* Multicrew role label in main window. [EDMarketConnector.py] */ "Role" = "Função"; @@ -454,6 +484,9 @@ /* Setting to decide which ship outfitting website to link to - either E:D Shipyard or Coriolis. [prefs.py] */ "Shipyard" = "Estaleiro"; +/* Status line text that appears when process exit sequence starts [EDMarketConnector.py] */ +"Shutting down..." = "Encerrando..."; + /* Empire rank. [stats.py] */ "Squire" = "Escudeiro"; @@ -475,6 +508,9 @@ /* Main window. [EDMarketConnector.py] */ "System" = "Sistema"; +/* Changed journal update_lock failed [monitor.py] */ +"The new Journal Directory location is already locked.{CR}You can either attempt to resolve this and then Retry, or choose to Ignore this." = "O novo Diretório de Jornais já está bloqueado.{CR}Você pode resolver o problema e Tentar novamente, ou Ignorar o erro."; + /* Appearance setting. [prefs.py] */ "Theme" = "Tema"; @@ -493,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Magnata"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Porcentagem de escala da IU"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Desconhecido"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Atualizar"; @@ -531,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} precisa de permissão para usar atalhos"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Nível de Log"; diff --git a/L10n/pt-PT.strings b/L10n/pt-PT.strings index 9b5ec61e..62aa3814 100644 --- a/L10n/pt-PT.strings +++ b/L10n/pt-PT.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Percentagem da escala de UI"; +/* Language name */ +"!Language" = "Português (Portugal)"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 é completamente opaco.{CR}A janela é actualizada em tempo real."; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 significa Predefinido{CR}Requer reinício para{CR}que as mudanças façam efeito!"; -/* Language name */ -"!Language" = "Português (Portugal)"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "Sobre {APP}"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Procurar..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Dados do Comandante não recebidos"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadete"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Dados do Comandante não recebidos"; + /* CQC rank. [stats.py] */ "Champion" = "Campeão"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Editar"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins sem suporte para Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Empreendedor"; +/* [companion.py] */ +"Error" = "Erro"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Erro: Não é possível conectar ao EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Erro: Não é possível conectar ao Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Erro: Impossível verificar o token de customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Erro: customer_id não foi encontrado!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Erro: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Erro: Credenciais Inválidas"; +/* [companion.py] */ +"Error: unable to get token" = "Erro: Não é possível obter o token"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Erro: Cmdt errado"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Credenciais Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informação para migração de plugins"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Directório do Diário já se encontra bloqueado"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Empréstimo"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Nível de Log"; + /* [EDMarketConnector.py] */ "Logging in..." = "Realizando login..."; /* Empire rank. [stats.py] */ "Lord" = "Lorde"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Transparência da janela principal"; + /* [prefs.py] */ "Market data in CSV format file" = "Ficheiro dos dados de Mercado no formato CSV"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Um ou mais dos plugins activados não possui ainda suporte para Python 3.x. Por favor verifique a lista na aba '{PLUGINS}' em '{FILE}' > '{SETTINGS}'. Deverá verificar se está disponível uma versão mais actualizada, caso contrário, informe o desenvolvedor de que necessita de actualizar o código para suportar Python 3.x.\n\nPode desactivar um plugin colocando '{DISABLED}' no fim do nome da pasta correspondente."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Apenas quando o Elite:Dangerous é a aplicação activa"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Pasta dos Plugins"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins sem suporte para Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Um ou mais dos plugins activados não possui ainda suporte para Python 3.x. Por favor verifique a lista na aba '{PLUGINS}' em '{FILE}' > '{SETTINGS}'. Deverá verificar se está disponível uma versão mais actualizada, caso contrário, informe o desenvolvedor de que necessita de actualizar o código para suportar Python 3.x.\n\nPode desactivar um plugin colocando '{DISABLED}' no fim do nome da pasta correspondente."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins sem suporte para Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informação para migração de plugins"; +"Plugins Without Python 3.x Support:" = "Plugins sem suporte para Python 3.x"; /* Federation rank. [stats.py] */ "Post Captain" = "Capitão de Fragata"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Magnata"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Percentagem da escala de UI"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Desconhecido"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Actualizar"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "A {APP} precisa de autorização para usar atalhos"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Nível de Log"; diff --git a/L10n/ru.strings b/L10n/ru.strings index 934ab0b8..7e2ef8c5 100644 --- a/L10n/ru.strings +++ b/L10n/ru.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Процент масштабирования интерфейса"; +/* Language name */ +"!Language" = "Русский"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 означает полностью непрозрачный.{CR}Окно обновляется в режиме реального времени."; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 - значение по умолчанию{CR}требуется перезапуск для вступления в силу изменений{CR}!"; -/* Language name */ -"!Language" = "Русский"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "О программе {APP}"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Просмотреть..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Нет данных пилота"; - /* Federation rank. [stats.py] */ "Cadet" = "Кадет"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Нет данных пилота"; + /* CQC rank. [stats.py] */ "Champion" = "Чемпион"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Правка"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Без поддержки Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Элита"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Предприниматель"; +/* [companion.py] */ +"Error" = "Ошибка"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Ошибка: не удается подключиться к EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Ошибка: не удается подключиться к Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Ошибка: невозможно проверить токен customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Ошибка: customer_id не совпадает!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Ошибка: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Ошибка: неизвестное имя пользователя или неверный пароль"; +/* [companion.py] */ +"Error: unable to get token" = "Ошибка: не удается получить токен"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Ошибка: неверное имя командира"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Учётные данные Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Информация о мигрирующих плагинах"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Каталог журнала уже заблокирован"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Долг"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Уровень лога"; + /* [EDMarketConnector.py] */ "Logging in..." = "Идет подключение..."; /* Empire rank. [stats.py] */ "Lord" = "Лорд"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Прозрачность главного окна"; + /* [prefs.py] */ "Market data in CSV format file" = "Данные рынков в формате CSV"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Один или несколько ваших подключённых плагинов ещё не имеют поддержки Python 3.x. Пожалуйста, ознакомьтесь со списком во вкладке '{PLUGINS}' '{FILE}' > '{SETTINGS}'. Вы должны проверить наличие обновлённой версии, в противном случае предупредите разработчика о необходимости обновления кода на Python 3.x.\n\nВы можете отключить плагин, переименовав его папку в '{DISABLED}'."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Только когда окно Elite: Dangerous активно"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Папка плагинов"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Без поддержки Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Один или несколько ваших подключённых плагинов ещё не имеют поддержки Python 3.x. Пожалуйста, ознакомьтесь со списком во вкладке '{PLUGINS}' '{FILE}' > '{SETTINGS}'. Вы должны проверить наличие обновлённой версии, в противном случае предупредите разработчика о необходимости обновления кода на Python 3.x.\n\nВы можете отключить плагин, переименовав его папку в '{DISABLED}'."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Плагины без поддержки Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Информация о мигрирующих плагинах"; +"Plugins Without Python 3.x Support:" = "Плагины без поддержки Python 3.x"; /* Federation rank. [stats.py] */ "Post Captain" = "Командир корабля"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Магнат"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Процент масштабирования интерфейса"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Неизвестно"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Обновить данные"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} требуется разрешение на использование глобальных сочетаний клавиш"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Уровень лога"; diff --git a/L10n/sl.strings b/L10n/sl.strings index 2020469c..8601189f 100644 --- a/L10n/sl.strings +++ b/L10n/sl.strings @@ -429,4 +429,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} potrebuje dovoljenja za uporabo bližnjic"; - diff --git a/L10n/sr-Latn-BA.strings b/L10n/sr-Latn-BA.strings index d9dba531..990a91d7 100644 --- a/L10n/sr-Latn-BA.strings +++ b/L10n/sr-Latn-BA.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Procenat UI skaliranja"; +/* Language name */ +"!Language" = "Srpski (Latinica, Bosna i Hercegovina)"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 znači potpuno neprozirno.{CR}Prozor se osvježava u realnom vremenu"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 je standardna vrijednost{CR}Potreban je restart{CR}za primjenu podešavanja!"; -/* Language name */ -"!Language" = "Srpski (Latinica, Bosna i Hercegovina)"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "O {APP}"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Potraži..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Nema podataka o komandantu"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Nema podataka o komandantu"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Uredi"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Dodaci (plugins) bez Python 3.x podrške"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "Greška"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Greška: Nemoguće povezivanje sa EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Greška: Nemoguće povezivanje sa Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Greška: Nemoguća provjera tokena customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Greška: customer_id se ne poklapa!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Greška: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Greška: Neispravni kredencijali"; +/* [companion.py] */ +"Error: unable to get token" = "Greška: Nemoguće dobaviti token"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Greška: Pogrešan Cmdr"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Kredencijali za Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informacije o migraciji dodataka (plugins)"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Journal direktorijum je već zaključan"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Zajam"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Log nivo"; + /* [EDMarketConnector.py] */ "Logging in..." = "Prijavljivanje..."; /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Prozirnost glavnog prozora"; + /* [prefs.py] */ "Market data in CSV format file" = "Fajl sa market podacima u CSV formatu"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Jedan ili više aktiviranih dodataka (plugins) nemaju podršku za Python 3.x. Pogledajte listu u '{PLUGINS}' tabu u '{FILE}' > '{SETTINGS}'. Provjerite da li postoji nadograđena verzija ili obavijesite autora da treba da promijeni kod za Python 3.x.\n\nMožete deaktivirati dodatak (plugin) dodavanjem '{DISABLED}' na kraju imena njegovog foldera."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Samo kada je Elite: Dangerous aktivna aplikacija"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Folder za dodatke (plugins)"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Dodaci (plugins) bez Python 3.x podrške"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Jedan ili više aktiviranih dodataka (plugins) nemaju podršku za Python 3.x. Pogledajte listu u '{PLUGINS}' tabu u '{FILE}' > '{SETTINGS}'. Provjerite da li postoji nadograđena verzija ili obavijesite autora da treba da promijeni kod za Python 3.x.\n\nMožete deaktivirati dodatak (plugin) dodavanjem '{DISABLED}' na kraju imena njegovog foldera."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Dodaci (plugins) bez Python 3.x podrške"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informacije o migraciji dodataka (plugins)"; +"Plugins Without Python 3.x Support:" = "Dodaci (plugins) bez Python 3.x podrške:"; /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Procenat UI skaliranja"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Nepoznato"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Osvježi"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} traži dozvolu da koristi prečice"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Log nivo"; diff --git a/L10n/sr-Latn.strings b/L10n/sr-Latn.strings index 9154e070..e93193d9 100644 --- a/L10n/sr-Latn.strings +++ b/L10n/sr-Latn.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "Procenat UI skaliranja"; +/* Language name */ +"!Language" = "Srpski (Latinica)"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 znači potpuno neprozirno.{CR}Prozor se osvežava u realnom vremenu."; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 znači podrazumevano{CR}Restart je potreban{CR}da bi se promene primenile!"; -/* Language name */ -"!Language" = "Srpski (Latinica)"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "O {APP}"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Potraži..."; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI: Nema podataka o komandiru"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Nema podataka o komandiru"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Izmeni"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Dodaci (plugins) bez Python 3.x podrške"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "Greška"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Greška: Nemoguće povezivanje na EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Greška: Nemoguće povezivanje na Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Greška: Nemoguća provera tokena customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Greška: customer_id se ne poklapa!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Greška: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Greška: Pogrešni kredencijali"; +/* [companion.py] */ +"Error: unable to get token" = "Greška: nemoguće dobaviti token"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Greška: Pogrešan Cmdr"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara kredencijali"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Informacije o migraciji dodataka (plugins)"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "Žurnal direktorijum je već zaključan"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Pozajmica"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Log Nivo"; + /* [EDMarketConnector.py] */ "Logging in..." = "Prijavljivanje..."; /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Prozirnost glavnog prozora"; + /* [prefs.py] */ "Market data in CSV format file" = "Fajl sa market podacima u CSV formatu"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Jedan ili više aktiviranih dodataka (plugins) nemaju podršku za Python 3.x. Pogledajte listu u '{PLUGINS}' tabu u '{FILE}' > '{SETTINGS}'. Proverite da li postoji nadograđena verzija ili obavesite autora da treba da promeni kod za Python 3.x.\n\nMožete deaktivirati dodatak (plugin) dodavanjem '{DISABLED}' na kraju imena njegovog foldera."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Samo kada je Elite: Dangerous aktivna aplikacija"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Folder za dodatke (plugins)"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Dodaci (plugins) bez Python 3.x podrške"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Jedan ili više aktiviranih dodataka (plugins) nemaju podršku za Python 3.x. Pogledajte listu u '{PLUGINS}' tabu u '{FILE}' > '{SETTINGS}'. Proverite da li postoji nadograđena verzija ili obavesite autora da treba da promeni kod za Python 3.x.\n\nMožete deaktivirati dodatak (plugin) dodavanjem '{DISABLED}' na kraju imena njegovog foldera."; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Dodaci (plugins) bez Python 3.x podrške"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Informacije o migraciji dodataka (plugins)"; +"Plugins Without Python 3.x Support:" = "Pluginovi bez podrške za Python 3.x:"; /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Procenat UI skaliranja"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Nepoznato"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Osveži"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} traži dozvolu da koristi skraćenice"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "Log Nivo"; diff --git a/L10n/sv-SE.strings b/L10n/sv-SE.strings index b968a501..82c4ced8 100644 --- a/L10n/sv-SE.strings +++ b/L10n/sv-SE.strings @@ -121,6 +121,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Ändra"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins utan stöd för Python 3.x"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -223,6 +226,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara autentiseringsuppgifter"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Information om migrering av plugins"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Genväg, tangentbord"; @@ -295,6 +301,9 @@ /* [prefs.py] */ "OK" = "OK"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "En eller flera aktiverade plugins har inte stöd för Python 3.x. Var vänlig kontrollera listan med plugins under fliken '{PLUGINS}' under '{FILE}' > '{SETTINGS}'. Kontrollera om det finns en nyare version tillgänglig eller informera utvecklaren.\n\nDu kan också avaktivera din plugin genom att ändra slutet av namnet på mappen till '{DISABLED}'"; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Bara när: Elite Dangerous är det aktiva programmet"; @@ -337,18 +346,6 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Mapp för plugins"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Plugins utan stöd för Python 3.x"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "En eller flera aktiverade plugins har inte stöd för Python 3.x. Var vänlig kontrollera listan med plugins under fliken '{PLUGINS}' under '{FILE}' > '{SETTINGS}'. Kontrollera om det finns en nyare version tillgänglig eller informera utvecklaren.\n\nDu kan också avaktivera din plugin genom att ändra slutet av namnet på mappen till '{DISABLED}'"; - -/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Plugins utan stöd för Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Information om migrering av plugins"; - /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -522,4 +519,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} behöver rättigheter för att använda genvägar"; - diff --git a/L10n/uk.strings b/L10n/uk.strings index ace0df1f..a45be942 100644 --- a/L10n/uk.strings +++ b/L10n/uk.strings @@ -121,6 +121,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "Редагувати"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC: Плагіни без підтримки Python 3.x!"; + /* Top rank. [stats.py] */ "Elite" = "Еліта"; @@ -223,6 +226,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Обліковий запис Inara"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "Інформація про міграцію плагінів"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Сполучення клавіш"; @@ -295,6 +301,9 @@ /* [prefs.py] */ "OK" = "Згода"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Один або кілька увімкнених плагінів ще не підтримують Python 3.x. Перегляньте список на вкладці '{PLUGINS}' в '{FILE}' > '{SETTINGS}'. Ви повинні перевірити, чи є в наявності оновлена ​​версія, інакше повідомити розробника плагіну про те, що їм потрібно оновити код для Python 3.x.\n\nВи можете відключити плагін, перейменувавши його папку додавши '{DISABLED}' в кінці назви."; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "Тільки тоді, коли Elite: Dangerous є активним додатком"; @@ -337,18 +346,6 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Сховище плагінів"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC: Плагіни без підтримки Python 3.x!"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "Один або кілька увімкнених плагінів ще не підтримують Python 3.x. Перегляньте список на вкладці '{PLUGINS}' в '{FILE}' > '{SETTINGS}'. Ви повинні перевірити, чи є в наявності оновлена ​​версія, інакше повідомити розробника плагіну про те, що їм потрібно оновити код для Python 3.x.\n\nВи можете відключити плагін, перейменувавши його папку додавши '{DISABLED}' в кінці назви."; - -/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "Плагіни без підтримки Python 3.x"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "Інформація про міграцію плагінів"; - /* Federation rank. [stats.py] */ "Post Captain" = "Капітан I рангу"; @@ -525,4 +522,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} необхідні дозволи для використання ярликів"; - diff --git a/L10n/zh-Hans.strings b/L10n/zh-Hans.strings index 16d3102d..b7c1f88b 100644 --- a/L10n/zh-Hans.strings +++ b/L10n/zh-Hans.strings @@ -1,12 +1,12 @@ -/* Label for 'UI Scaling' option [prefs.py] */ -"UI Scale Percentage" = "UI 缩放比例"; +/* Language name */ +"!Language" = "简体中文"; + +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 为完全不透明{CR}效果实时更新"; /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 为默认设置{CR}需要重启应用{CR}以使修改生效"; -/* Language name */ -"!Language" = "简体中文"; - /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "关于 {APP}"; @@ -46,12 +46,12 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "浏览…"; -/* No 'commander' data in CAPI [EDMarketConnector.py] */ -"CAPI: No commander data returned" = "CAPI:没有指挥官数据"; - /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI:没有指挥官数据"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -130,6 +130,9 @@ /* Menu title. [EDMarketConnector.py] */ "Edit" = "编辑"; +/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"EDMC: Plugins Without Python 3.x Support" = "EDMC:不支持 Python 3.x 的插件"; + /* Top rank. [stats.py] */ "Elite" = "Elite"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "错误"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "错误:无法连接到 EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "错误:无法连接到 Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "错误:无法检查 customer_id 令牌"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "错误:customer_id 不匹配!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "错误:EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "错误:无效的登录凭证"; +/* [companion.py] */ +"Error: unable to get token" = "错误:无法获取令牌"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "错误:指挥官不一致"; @@ -235,6 +250,9 @@ /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inara 授权凭证"; +/* Settings>Plugins>Information on migrating plugins [prefs.py] */ +"Information on migrating plugins" = "关于插件迁移"; + /* Changed journal update_lock failed [monitor.py] */ "Journal directory already locked" = "日志目录已被锁定"; @@ -262,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "贷款"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "诊断模式"; + /* [EDMarketConnector.py] */ "Logging in..." = "登录中…"; /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "主窗口透明度"; + /* [prefs.py] */ "Market data in CSV format file" = "货物市场数据,以 CSV 文件格式"; @@ -310,6 +334,9 @@ /* [prefs.py] */ "OK" = "确定"; +/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ +"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "一项或多项你所启用的插件尚不支持 Python 3.x,详情请见 {FILE} > {SETTINGS} > {PLUGINS}。请检查上述插件是否有可用的更新,若没有,则应与插件的开发者就 Python 3.x 的支持问题取得联系。\n\n你也可以禁用某一项插件,只需在其文件夹名称的末尾添加 {DISABLED} 即可。"; + /* Hotkey/Shortcut setting. [prefs.py] */ "Only when Elite: Dangerous is the active app" = "仅当 Elite: Dangerous 在前台运行时生效"; @@ -352,17 +379,8 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "插件文件夹"; -/* Popup title: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"EDMC: Plugins Without Python 3.x Support" = "EDMC:不支持 Python 3.x 的插件"; - -/* Popup body: Warning about plugins without Python 3.x support [EDMarketConnector.py] */ -"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "一项或多项你所启用的插件尚不支持 Python 3.x,详情请见 {FILE} > {SETTINGS} > {PLUGINS}。请检查上述插件是否有可用的更新,若没有,则应与插件的开发者就 Python 3.x 的支持问题取得联系。\n\n你也可以禁用某一项插件,只需在其文件夹名称的末尾添加 {DISABLED} 即可。"; - /* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ -"Plugins Without Python 3.x Support" = "不支持 Python 3.x 的插件"; - -/* Settings>Plugins>Information on migrating plugins [prefs.py] */ -"Information on migrating plugins" = "关于插件迁移"; +"Plugins Without Python 3.x Support:" = "不支持 Python 3.x 的插件:"; /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -511,6 +529,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Tycoon"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "UI 缩放比例"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "未知"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "更新"; @@ -549,6 +573,3 @@ /* Shortcut settings prompt on OSX. [prefs.py] */ "{APP} needs permission to use shortcuts" = "{APP} 需要权限以使用快捷键"; - -/* Label for user configured level of logging [prefs.py] */ -"Log Level" = "诊断模式"; From e363e1d0ae522b5354ecd5dd3b165a09f7241ec5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 19 Apr 2021 12:40:18 +0100 Subject: [PATCH 620/727] Pre-Release 5.0.0-beta6: appversion and changelog --- ChangeLog.md | 31 +++++++++++++++++++++++++++++++ config.py | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index e7646d72..194ae41a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,37 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- +Pre-Release 5.0.0-beta6 +=== + +This adds a new UI element 'Suit', below 'Ship' when applicable that +details the type of suit you currently have equipped and its Loadout name. +This UI element is collapsed/hidden if no suit/on-foot state is detected, +i.e. not playing Odyssey (Alpha or otherwise). + +* Updated translations. Once more, thanks to all the translators! + +* There is a new CL arg for EDMarketConnector.exe `--force-edmc-protocol`, but + this is really only of use to core developers (its purpose being to force + use of the edmc:// protocol for Frontier Auth callbacks, even when not + 'frozen'). + +* Slightly improve checking of old ship loadout files before writing a new one. + +* Linux config will be flushed to disk after any change. This means that + EDMC.py can now actually make use of the latest CAPI auth if it's been + updated by EDMarketConnector.py since that started. + +Plugin Developers +--- + +We now have support for Odyssey Suits and their Loadouts. See PLUGINS.md +for details, particuarly the way in which `state[Suits]` might be either a +`list` or a `dict` and how to deal with that. +NB: This data is only guaranteed up to date and correct after a fresh CAPI +data pull, as the current Journal events don't allow for updating it on the +fly (this should change in a future Odyssey patch). + Pre-Release 5.0.0-beta5 === diff --git a/config.py b/config.py index 71b95e5c..e384a993 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta5' +_static_appversion = '5.0.0-beta6' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From 806ac63c38ff0f466f8609d91d64120009474731 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 21 Apr 2021 10:10:14 +0100 Subject: [PATCH 621/727] ChangeLog: Call out that Python 3.9 means no more Windows 7 support --- ChangeLog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 194ae41a..bfb91d49 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,11 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- +**As of release 5.0.0 (including betas) we no longer support Windows 7. +This is due to moving to Python 3.9.x, which itself does not now support +Windows 7. The application (both EDMarketConnector.exe and EDMC.exe) will +crash on startup due to a missing DLL.** + Pre-Release 5.0.0-beta6 === From f7154d8e78151dfa9e74828053fdb7895c51fde1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 23 Apr 2021 06:01:10 +0000 Subject: [PATCH 622/727] build(deps): bump watchdog from 2.0.2 to 2.0.3 Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 2.0.2 to 2.0.3. - [Release notes](https://github.com/gorakhargosh/watchdog/releases) - [Changelog](https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst) - [Commits](https://github.com/gorakhargosh/watchdog/compare/v2.0.2...v2.0.3) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4d15cdef..f7c83c73 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 requests==2.25.1 -watchdog==2.0.2 +watchdog==2.0.3 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From df31aed6c553d6250373029f611391beac0b3e76 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 01:22:01 +0530 Subject: [PATCH 623/727] Added appearance config option and implementation for minimize to tray on close functionality --- EDMarketConnector.py | 31 +++++++++++++++++++++++++++++++ L10n/en.template | 3 +++ prefs.py | 10 ++++++++++ requirements.txt | 1 + 4 files changed, 45 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index f019f8f9..b733a66f 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -9,6 +9,7 @@ import locale import pathlib import re import sys +import threading import webbrowser from builtins import object, str from os import chdir, environ @@ -16,6 +17,7 @@ from os.path import dirname, join from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Optional, Tuple +from infi.systray import SysTrayIcon # Have this as early as possible for people running EDMarketConnector.exe # from cmd.exe or a bat file or similar. Else they might not be in the correct @@ -330,6 +332,18 @@ class AppWindow(object): self.prefsdialog = None + self.only_tray_close = 0 + + def open_window(systray): + self.only_tray_close = 2 + shutdown_thread = threading.Thread(target=systray.shutdown) + shutdown_thread.setDaemon(True) + shutdown_thread.start() + self.w.deiconify() + + menu_options = (("Open", None, open_window),) + self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray) + plug.load_plugins(master) if platform != 'darwin': @@ -1373,6 +1387,23 @@ class AppWindow(object): def onexit(self, event=None) -> None: """Application shutdown procedure.""" + value = bool(config.get_int('close_system_tray')) + + if value: + self.w.withdraw() + self.systray.start() + else: + self.exit() + + def exit_tray(self, systray): + if self.only_tray_close > 0: + self.only_tray_close -= 1 + else: + exit_thread = threading.Thread(target=self.exit) + exit_thread.setDaemon(True) + exit_thread.start() + + def exit(self): config.set_shutdown() # Signal we're in shutdown now. # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 diff --git a/L10n/en.template b/L10n/en.template index dd54a762..3bb2865d 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -19,6 +19,9 @@ /* Appearance setting. [EDMarketConnector.py] */ "Always on top" = "Always on top"; +/* Appearance setting. [EDMarketConnector.py] */ +"Close to system tray" = "Close to system tray"; + /* CQC rank. [stats.py] */ "Amateur" = "Amateur"; diff --git a/prefs.py b/prefs.py index 81c850c8..f62af8c2 100644 --- a/prefs.py +++ b/prefs.py @@ -636,6 +636,7 @@ class PreferencesDialog(tk.Toplevel): # Appearance theme and language setting self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default'))) self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) + self.close_system_tray = tk.BooleanVar(value=bool(config.get_int('close_system_tray'))) self.theme = tk.IntVar(value=config.get_int('theme')) self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')] self.theme_prompts = [ @@ -791,6 +792,14 @@ class PreferencesDialog(tk.Toplevel): ) self.ontop_button.grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting + self.system_tray_button = nb.Checkbutton( + appearance_frame, + text=_('Close to system tray'), + variable=self.close_system_tray, + command=self.themevarchanged + ) + self.system_tray_button.grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting + nb.Label(appearance_frame).grid(sticky=tk.W) # big spacer notebook.add(appearance_frame, text=_('Appearance')) # Tab heading in settings @@ -1163,6 +1172,7 @@ class PreferencesDialog(tk.Toplevel): config.set('ui_scale', self.ui_scale.get()) config.set('ui_transparency', self.transparency.get()) config.set('always_ontop', self.always_ontop.get()) + config.set('close_system_tray', self.close_system_tray.get()) config.set('theme', self.theme.get()) config.set('dark_text', self.theme_colors[0]) config.set('dark_highlight', self.theme_colors[1]) diff --git a/requirements.txt b/requirements.txt index f7c83c73..b157c90b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ certifi==2020.12.5 requests==2.25.1 watchdog==2.0.3 +infi.systray==0.1.12 # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From 94c296a9da8e342ee574c540103384e7bd6ea2c9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Apr 2021 07:15:37 +0000 Subject: [PATCH 624/727] build(deps-dev): bump py2exe from 0.10.3.1 to 0.10.4.0 Bumps [py2exe](https://github.com/py2exe/py2exe) from 0.10.3.1 to 0.10.4.0. - [Release notes](https://github.com/py2exe/py2exe/releases) - [Changelog](https://github.com/py2exe/py2exe/blob/master/ChangeLog) - [Commits](https://github.com/py2exe/py2exe/compare/v0.10.3.1...v0.10.4.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 116cdf7e..74241c63 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -27,7 +27,7 @@ grip==4.5.2 # Packaging # We only need py2exe on windows. -py2exe==0.10.3.1; sys_platform == 'win32' +py2exe==0.10.4.0; sys_platform == 'win32' # Testing pytest==6.2.3 From ecf16762d0764054a9d6ec316ef418406dcedfc9 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 13:37:27 +0530 Subject: [PATCH 625/727] Fixed linting issues with EDMarketConnector.py --- EDMarketConnector.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b733a66f..095e5ed4 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -17,6 +17,7 @@ from os.path import dirname, join from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Optional, Tuple + from infi.systray import SysTrayIcon # Have this as early as possible for people running EDMarketConnector.exe @@ -1395,7 +1396,8 @@ class AppWindow(object): else: self.exit() - def exit_tray(self, systray): + def exit_tray(self, systray) -> None: + """Tray icon is shutting down.""" if self.only_tray_close > 0: self.only_tray_close -= 1 else: @@ -1403,7 +1405,8 @@ class AppWindow(object): exit_thread.setDaemon(True) exit_thread.start() - def exit(self): + def exit(self) -> None: + """Actual application shutdown.""" config.set_shutdown() # Signal we're in shutdown now. # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 From 6c0437642e983c470bb02082b092d4e2a4564d36 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 14:03:22 +0530 Subject: [PATCH 626/727] Formatting fixes --- EDMarketConnector.py | 4 +++- prefs.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 095e5ed4..67f7f706 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -335,7 +335,7 @@ class AppWindow(object): self.only_tray_close = 0 - def open_window(systray): + def open_window(systray) -> None: self.only_tray_close = 2 shutdown_thread = threading.Thread(target=systray.shutdown) shutdown_thread.setDaemon(True) @@ -1393,6 +1393,7 @@ class AppWindow(object): if value: self.w.withdraw() self.systray.start() + else: self.exit() @@ -1400,6 +1401,7 @@ class AppWindow(object): """Tray icon is shutting down.""" if self.only_tray_close > 0: self.only_tray_close -= 1 + else: exit_thread = threading.Thread(target=self.exit) exit_thread.setDaemon(True) diff --git a/prefs.py b/prefs.py index f62af8c2..19289478 100644 --- a/prefs.py +++ b/prefs.py @@ -636,7 +636,7 @@ class PreferencesDialog(tk.Toplevel): # Appearance theme and language setting self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default'))) self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) - self.close_system_tray = tk.BooleanVar(value=bool(config.get_int('close_system_tray'))) + self.close_system_tray = tk.BooleanVar(value=config.get_bool('close_system_tray')) self.theme = tk.IntVar(value=config.get_int('theme')) self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')] self.theme_prompts = [ From fa58d2f0c2bd561f6fdaf67a48c341bb02242f49 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 14:23:08 +0530 Subject: [PATCH 627/727] Added windows OS checks --- EDMarketConnector.py | 38 ++++++++++++++++++++++---------------- prefs.py | 14 +++++++------- requirements.txt | 2 +- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 67f7f706..528584ca 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -9,7 +9,6 @@ import locale import pathlib import re import sys -import threading import webbrowser from builtins import object, str from os import chdir, environ @@ -18,8 +17,6 @@ from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Optional, Tuple -from infi.systray import SysTrayIcon - # Have this as early as possible for people running EDMarketConnector.exe # from cmd.exe or a bat file or similar. Else they might not be in the correct # place for things like config.py reading .gitversion @@ -333,17 +330,21 @@ class AppWindow(object): self.prefsdialog = None - self.only_tray_close = 0 + if platform == 'win32': + import threading + from infi.systray import SysTrayIcon - def open_window(systray) -> None: - self.only_tray_close = 2 - shutdown_thread = threading.Thread(target=systray.shutdown) - shutdown_thread.setDaemon(True) - shutdown_thread.start() - self.w.deiconify() + self.only_tray_close = 0 - menu_options = (("Open", None, open_window),) - self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray) + def open_window(systray) -> None: + self.only_tray_close = 2 + shutdown_thread = threading.Thread(target=systray.shutdown) + shutdown_thread.setDaemon(True) + shutdown_thread.start() + self.w.deiconify() + + menu_options = (("Open", None, open_window),) + self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray) plug.load_plugins(master) @@ -1388,17 +1389,22 @@ class AppWindow(object): def onexit(self, event=None) -> None: """Application shutdown procedure.""" - value = bool(config.get_int('close_system_tray')) + if platform == 'win32': + value = bool(config.get_int('close_system_tray')) - if value: - self.w.withdraw() - self.systray.start() + if value: + self.w.withdraw() + self.systray.start() + + else: + self.exit() else: self.exit() def exit_tray(self, systray) -> None: """Tray icon is shutting down.""" + import threading if self.only_tray_close > 0: self.only_tray_close -= 1 diff --git a/prefs.py b/prefs.py index 19289478..929ddc0c 100644 --- a/prefs.py +++ b/prefs.py @@ -792,13 +792,13 @@ class PreferencesDialog(tk.Toplevel): ) self.ontop_button.grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting - self.system_tray_button = nb.Checkbutton( - appearance_frame, - text=_('Close to system tray'), - variable=self.close_system_tray, - command=self.themevarchanged - ) - self.system_tray_button.grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting + if platform == 'win32': + nb.Checkbutton( + appearance_frame, + text=_('Close to system tray'), + variable=self.close_system_tray, + command=self.themevarchanged + ).grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting nb.Label(appearance_frame).grid(sticky=tk.W) # big spacer diff --git a/requirements.txt b/requirements.txt index b157c90b..cc3d8c4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ certifi==2020.12.5 requests==2.25.1 watchdog==2.0.3 -infi.systray==0.1.12 +infi.systray==0.1.12; sys_platform == 'win32' # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From 2dddf02f9b4023d36e8f17ffce4587de49c8b8b4 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 14:40:11 +0530 Subject: [PATCH 628/727] Comments to describe the hack --- EDMarketConnector.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 528584ca..2ea6f372 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -334,16 +334,24 @@ class AppWindow(object): import threading from infi.systray import SysTrayIcon - self.only_tray_close = 0 + self.only_tray_close = 0 # This is kind of a hack. + # When the tray icon is double click to reopen the EDMC window, I want the tray icon to disappear. To do + # that I have to call the `shutdown()` method of the systray object. Calling the shutdown method triggers + # the method associated with `on_quit` twice, once for WM_DESTROY and again for WM_CLOSE. This is not the + # case when the application is exited by clicking on `Quit` in the tray menu. So, to handle this, we are + # creating this class variable and setting it to 2 when `Open` is called from the tray menu (either by + # clicking open or by double clicking the icon) and decrementing it by 1 when the tray shutdown is triggered def open_window(systray) -> None: self.only_tray_close = 2 + # Shutdown needs to happen in a separate thread to prevent joining with itself shutdown_thread = threading.Thread(target=systray.shutdown) shutdown_thread.setDaemon(True) shutdown_thread.start() self.w.deiconify() menu_options = (("Open", None, open_window),) + # Method associated with on_quit is called whenever the systray is closing self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray) plug.load_plugins(master) @@ -1391,7 +1399,7 @@ class AppWindow(object): """Application shutdown procedure.""" if platform == 'win32': value = bool(config.get_int('close_system_tray')) - + # When exit is called, either exit application or minimize to system tray if value: self.w.withdraw() self.systray.start() @@ -1405,6 +1413,7 @@ class AppWindow(object): def exit_tray(self, systray) -> None: """Tray icon is shutting down.""" import threading + # Hack to see if the tray shutdown has been called by calling quit or calling shutdown if self.only_tray_close > 0: self.only_tray_close -= 1 From b377199119e339921b1b995638809b5ee1ce1f48 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 15:36:43 +0530 Subject: [PATCH 629/727] Changed logic to handle minimize too system tray --- EDMarketConnector.py | 68 +++++++++++++++----------------------------- L10n/en.template | 2 +- prefs.py | 8 +++--- 3 files changed, 28 insertions(+), 50 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 2ea6f372..6d90e03f 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -9,6 +9,7 @@ import locale import pathlib import re import sys +import threading import webbrowser from builtins import object, str from os import chdir, environ @@ -331,28 +332,15 @@ class AppWindow(object): self.prefsdialog = None if platform == 'win32': - import threading from infi.systray import SysTrayIcon - self.only_tray_close = 0 # This is kind of a hack. - # When the tray icon is double click to reopen the EDMC window, I want the tray icon to disappear. To do - # that I have to call the `shutdown()` method of the systray object. Calling the shutdown method triggers - # the method associated with `on_quit` twice, once for WM_DESTROY and again for WM_CLOSE. This is not the - # case when the application is exited by clicking on `Quit` in the tray menu. So, to handle this, we are - # creating this class variable and setting it to 2 when `Open` is called from the tray menu (either by - # clicking open or by double clicking the icon) and decrementing it by 1 when the tray shutdown is triggered - def open_window(systray) -> None: - self.only_tray_close = 2 - # Shutdown needs to happen in a separate thread to prevent joining with itself - shutdown_thread = threading.Thread(target=systray.shutdown) - shutdown_thread.setDaemon(True) - shutdown_thread.start() self.w.deiconify() menu_options = (("Open", None, open_window),) # Method associated with on_quit is called whenever the systray is closing self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray) + self.systray.start() plug.load_plugins(master) @@ -1395,35 +1383,20 @@ class AppWindow(object): logger.debug('"other" exception', exc_info=e) self.status['text'] = str(e) - def onexit(self, event=None) -> None: - """Application shutdown procedure.""" - if platform == 'win32': - value = bool(config.get_int('close_system_tray')) - # When exit is called, either exit application or minimize to system tray - if value: - self.w.withdraw() - self.systray.start() - - else: - self.exit() - - else: - self.exit() - def exit_tray(self, systray) -> None: """Tray icon is shutting down.""" - import threading - # Hack to see if the tray shutdown has been called by calling quit or calling shutdown - if self.only_tray_close > 0: - self.only_tray_close -= 1 + exit_thread = threading.Thread(target=self.onexit) + exit_thread.setDaemon(True) + exit_thread.start() - else: - exit_thread = threading.Thread(target=self.exit) - exit_thread.setDaemon(True) - exit_thread.start() + def onexit(self, event=None) -> None: + """Application shutdown procedure.""" + value = config.get_bool('minimize_system_tray') + if platform == 'win32' and value is not None and value: + shutdown_thread = threading.Thread(target=self.systray.shutdown) + shutdown_thread.setDaemon(True) + shutdown_thread.start() - def exit(self) -> None: - """Actual application shutdown.""" config.set_shutdown() # Signal we're in shutdown now. # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7 @@ -1490,12 +1463,17 @@ class AppWindow(object): self.drag_offset = (None, None) def oniconify(self, event=None) -> None: - """Handle iconification of the application.""" - self.w.overrideredirect(0) # Can't iconize while overrideredirect - self.w.iconify() - self.w.update_idletasks() # Size and windows styles get recalculated here - self.w.wait_visibility() # Need main window to be re-created before returning - theme.active = None # So theme will be re-applied on map + """Handle minimization of the application.""" + value = config.get_bool('minimize_system_tray') + if platform == 'win32' and value is not None and value: + self.w.withdraw() + + else: + self.w.overrideredirect(0) # Can't iconize while overrideredirect + self.w.iconify() + self.w.update_idletasks() # Size and windows styles get recalculated here + self.w.wait_visibility() # Need main window to be re-created before returning + theme.active = None # So theme will be re-applied on map # TODO: Confirm this is unused and remove. def onmap(self, event=None) -> None: diff --git a/L10n/en.template b/L10n/en.template index 3bb2865d..c7379ba7 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -20,7 +20,7 @@ "Always on top" = "Always on top"; /* Appearance setting. [EDMarketConnector.py] */ -"Close to system tray" = "Close to system tray"; +"Minimize to system tray" = "Minimize to system tray"; /* CQC rank. [stats.py] */ "Amateur" = "Amateur"; diff --git a/prefs.py b/prefs.py index 929ddc0c..119b727f 100644 --- a/prefs.py +++ b/prefs.py @@ -636,7 +636,7 @@ class PreferencesDialog(tk.Toplevel): # Appearance theme and language setting self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default'))) self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) - self.close_system_tray = tk.BooleanVar(value=config.get_bool('close_system_tray')) + self.minimize_system_tray = tk.BooleanVar(value=config.get_bool('minimize_system_tray')) self.theme = tk.IntVar(value=config.get_int('theme')) self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')] self.theme_prompts = [ @@ -795,8 +795,8 @@ class PreferencesDialog(tk.Toplevel): if platform == 'win32': nb.Checkbutton( appearance_frame, - text=_('Close to system tray'), - variable=self.close_system_tray, + text=_('Minimize to system tray'), + variable=self.minimize_system_tray, command=self.themevarchanged ).grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting @@ -1172,7 +1172,7 @@ class PreferencesDialog(tk.Toplevel): config.set('ui_scale', self.ui_scale.get()) config.set('ui_transparency', self.transparency.get()) config.set('always_ontop', self.always_ontop.get()) - config.set('close_system_tray', self.close_system_tray.get()) + config.set('minimize_system_tray', self.minimize_system_tray.get()) config.set('theme', self.theme.get()) config.set('dark_text', self.theme_colors[0]) config.set('dark_highlight', self.theme_colors[1]) From fc83dcf0903c938e7159eb84e4569210e1d771fb Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 16:05:40 +0530 Subject: [PATCH 630/727] Added annotations for systray --- EDMarketConnector.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 6d90e03f..1eedb0f3 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -264,6 +264,7 @@ if __name__ == '__main__': # noqa: C901 if TYPE_CHECKING: from logging import trace, TRACE # type: ignore # noqa: F401 import update + from infi.systray import SysTrayIcon # isort: on def _(x: str) -> str: @@ -334,7 +335,7 @@ class AppWindow(object): if platform == 'win32': from infi.systray import SysTrayIcon - def open_window(systray) -> None: + def open_window(systray: 'SysTrayIcon') -> None: self.w.deiconify() menu_options = (("Open", None, open_window),) @@ -1383,7 +1384,7 @@ class AppWindow(object): logger.debug('"other" exception', exc_info=e) self.status['text'] = str(e) - def exit_tray(self, systray) -> None: + def exit_tray(self, systray: 'SysTrayIcon') -> None: """Tray icon is shutting down.""" exit_thread = threading.Thread(target=self.onexit) exit_thread.setDaemon(True) From a52472d6e03955aa224048b35be2c326a9d7bbe0 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Mon, 26 Apr 2021 19:18:47 +0530 Subject: [PATCH 631/727] Fix for tray icon not stopping on app stop when minimize to tray option is disabled --- EDMarketConnector.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 1eedb0f3..30ddc857 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1392,8 +1392,7 @@ class AppWindow(object): def onexit(self, event=None) -> None: """Application shutdown procedure.""" - value = config.get_bool('minimize_system_tray') - if platform == 'win32' and value is not None and value: + if platform == 'win32': shutdown_thread = threading.Thread(target=self.systray.shutdown) shutdown_thread.setDaemon(True) shutdown_thread.start() From 77e6b64c64b92684736a320dc7a4f4e81b4a5e3b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 26 Apr 2021 23:08:08 +0100 Subject: [PATCH 632/727] L10n: Move "Minimize to system tray" to correct position --- L10n/en.template | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index c7379ba7..164e2fd0 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -19,9 +19,6 @@ /* Appearance setting. [EDMarketConnector.py] */ "Always on top" = "Always on top"; -/* Appearance setting. [EDMarketConnector.py] */ -"Minimize to system tray" = "Minimize to system tray"; - /* CQC rank. [stats.py] */ "Amateur" = "Amateur"; @@ -313,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Minimize to system tray"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; From f8f4fa6bb3897387e0fdf45e3a84bac532b707ca Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 26 Apr 2021 23:09:22 +0100 Subject: [PATCH 633/727] L10n: Add 'Suit' to en.template --- L10n/en.template | 3 +++ 1 file changed, 3 insertions(+) diff --git a/L10n/en.template b/L10n/en.template index 164e2fd0..9aa3c3ca 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -505,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Status"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Suit"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; From 96d9a8095612c8c43dcb9ddda5025a039227f941 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 27 Apr 2021 11:54:15 +0100 Subject: [PATCH 634/727] odyssey-4: Add outlines/comments for all upcoming events --- monitor.py | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 186 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 9c66a386..baf79bfb 100644 --- a/monitor.py +++ b/monitor.py @@ -499,6 +499,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.live = True # First event in 3.0 elif event_type == 'LoadGame': + # alpha4 + # Odyssey: bool self.cmdr = entry['Commander'] # 'Open', 'Solo', 'Group', or None for CQC (and Training - but no LoadGame event) self.mode = entry.get('GameMode') @@ -623,11 +625,45 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'Embark': # If we've embarked then we're no longer on the station. + + # alpha4 + # This event is logged when a player (on foot) gets into a ship or SRV + # Parameters: + # • SRV: true if getting into SRV, false if getting into a ship + # • Taxi: true when boarding a taxi transposrt ship + # • Multicrew: true when boarding another player’s vessel + # • ID: player’s ship ID (if players own vessel) + # • StarSystem + # • SystemAddress + # • Body + # • BodyID + # • OnStation: bool + # • OnPlanet: bool + # • StationName (if at a station) + # • StationType + # • MarketID self.station = None self.state['OnFoot'] = False elif event_type == 'Disembark': # We don't yet have a way, other than LoadGame+Location, to detect if we *are* on a station on-foot. + # alpha4 + # This event is logged when the player steps out of a ship or SRV + # + # Parameters: + # • SRV: true if getting out of SRV, false if getting out of a ship + # • Taxi: true when getting out of a taxi transposrt ship + # • Multicrew: true when getting out of another player’s vessel + # • ID: player’s ship ID (if players own vessel) + # • StarSystem + # • SystemAddress + # • Body + # • BodyID + # • OnStation: bool + # • OnPlanet: bool + # • StationName (if at a station) + # • StationType + # • MarketID # If we're not exiting one of these then it's from our own ship, and then we should already have # self.station set correctly. @@ -637,6 +673,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['OnFoot'] = True elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): + # alpha4 - any changes ? + # Location: + # New in Odyssey: + # • Taxi: bool + # • Multicrew: bool + # • InSRV: bool + # • OnFoot: bool if event_type in ('Location', 'CarrierJump'): self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None @@ -734,6 +777,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # be wrong if Cmdr relogs at a Settlement with anything in # backpack. We can't track when they use/pick up items # anyway (Odyssey Alpha Phase 1 Hotfix 2). + # alpha4 - This should be changed self.state['BackPack']['Component'] = defaultdict(int) self.state['BackPack']['Consumable'] = defaultdict(int) self.state['BackPack']['Item'] = defaultdict(int) @@ -754,6 +798,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below ) elif event_type == 'BackPackMaterials': + # alpha4 - + # Lists the contents of the backpack, eg when disembarking from ship + # Assume this reflects the current state when written self.state['BackPack']['Component'] = defaultdict(int) self.state['BackPack']['Consumable'] = defaultdict(int) @@ -777,6 +824,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'BuyMicroResources': # Buying from a Pioneer Supplies, goes directly to ShipLocker. # One event per Item, not an array. + # alpha4 - update current credits ? category = self.category(entry['Category']) name = self.canonicalise(entry['Name']) self.state[category][name] += entry['Count'] @@ -784,6 +832,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'SellMicroResources': # Selling to a Bar Tender on-foot. # One event per whole sale, so it's an array. + # alpha4 - update current credits ? for mr in entry['MicroResources']: category = self.category(mr['Category']) name = self.canonicalise(mr['Name']) @@ -827,7 +876,47 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if self.state['BackPack'][c][m] < 0: self.state['BackPack'][c][m] = 0 + elif event_type == 'CollectItems': + # alpha4 + # When picking up items from the ground + # Parameters: + # • Name + # • Type + # • OwnerID + pass + + elif event_type == 'DropItems': + # alpha4 + # Parameters: + # • Name + # • Type + # • OwnerID + # • MissionID + # • Count + pass + + elif event_type == 'UseConsumable': + # alpha4 + # When using an item from the player’s inventory (backpack) + # + # Parameters: + # • Name + # • Type + pass + elif event_type == 'SwitchSuitLoadout': + # alpha4 + # This event is logged when a player selects a different flight suit from the ship’s locker + # + # Parameters: + # • SuitID + # • SuitName + # • LoadoutID + # • LoadoutName + # • Modules: array of objects + # ◦ SlotName + # ◦ SuitModuleID + # ◦ ModuleName loadoutid = entry['LoadoutID'] new_slot = self.suit_loadout_id_from_loadoutid(loadoutid) try: @@ -853,6 +942,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below except KeyError: logger.exception(f"Getting switched-to suit from slot {new_slot} ({loadoutid}") + elif event_type == 'CreateSuitLoadout': + # We know we won't have data for this new one + # Parameters: + # • SuitID + # • SuitName + # • LoadoutID + # • LoadoutName + pass + elif event_type == 'DeleteSuitLoadout': # We should remove this from the monitor.state record of loadouts. The slotid # could end up valid due to CreateSuitLoadout events, but we won't have the @@ -866,23 +964,109 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below except KeyError: logger.exception(f"slot id {slotid} doesn't exist, not in last CAPI pull ?") - elif event_type == 'CreateSuitLoadout': - # We know we won't have data for this new one + elif event_type == 'RenameSuitLoadout': + # alpha4 + # Parameters: + # • SuitID + # • SuitName + # • LoadoutID + # • Loadoutname pass # `BuySuit` has no useful info as of 4.0.0.13 + elif event_type == 'BuySuit': + # alpha4 - should have 'SuitID' + # update credits + pass elif event_type == 'SellSuit': # Remove from known suits # As of Odyssey Alpha Phase 2, Hotfix 5 (4.0.0.13) this isn't possible as this event # doesn't contain the specific suit ID as per CAPI `suits` dict. + # alpha4 + # This event is logged when a player sells a flight suit + # + # Parameters: + # • Name + # • Price + # • SuitID + # update credits total + pass + + elif event_type == 'UpgradeSuit': + # alpha4 + # This event is logged when the player upgrades their flight suit + # + # Parameters: + # • Name + # • SuitID + # • Class + # • Cost + # Update credits total ? pass # `LoadoutEquipModule` has no instance-specific ID as of 4.0.0.13 + elif event_type == 'LoadoutEquipModule': + # alpha4 - should have necessary IDs + pass + + elif event_type == 'LoadoutRemoveModule': + # alpha4 + # This event is logged when a player removes a weapon from a suit loadout + # + # Parameters: + # • SuitID + # • SuitName + # • LoadoutID + # • LoadoutName + # • ModuleName: weapon or other item removed from loadout + # • SuitModuleID + pass # `BuyWeapon` has no instance-specific ID as of 4.0.0.13 + elif event_type == 'BuyWeapon': + # alpha4 + # Parameters: + # • Name + # • Price + # • SuitModuleID + # update credits + pass + # `SellWeapon` has no instance-specific ID as of 4.0.0.13 + elif event_type == 'SellWeapon': + # alpha4 + # This event is logged when a player sells a hand weapon + # + # Parameters: + # • Name + # • Price + # • SuitModuleID + # Update credits total + pass + # `UpgradeWeapon` has no instance-specific ID as of 4.0.0.13 + elif event_type == 'UpgradeWeapon': + # alpha4 + pass + + # alpha4 + elif event_type == 'ScanOrganic': + pass + + elif event_type == 'SellOrganicData': + # alpha4 - update current credits ? + pass + + # alpha4 - Credits updates + elif event_type == 'BookDropship': + pass + elif event_type == 'BookTaxi': + pass + elif event_type == 'CancelDropship': + pass + elif event_type == 'CancelTaxi': + pass elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json From 7b8c113962a62c63563b9d0cc5e81811ebd0557b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 10:12:49 +0100 Subject: [PATCH 635/727] suits: Record a newly bought suit in monitor.state['Suits'] We can't fill in the 'id' field, but this is likely the FDevID of the suit type ? --- monitor.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index baf79bfb..98dc4593 100644 --- a/monitor.py +++ b/monitor.py @@ -973,10 +973,22 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • Loadoutname pass - # `BuySuit` has no useful info as of 4.0.0.13 elif event_type == 'BuySuit': - # alpha4 - should have 'SuitID' + # alpha4 : + # { "timestamp":"2021-04-29T09:03:37Z", "event":"BuySuit", "Name":"UtilitySuit_Class1", + # "Name_Localised":"Maverick Suit", "Price":150000, "SuitID":1698364934364699 } + self.state['Suits'].update( + {entry['SuitID']: { + 'name': entry['Name'], + 'locName': entry.get('Name_Localised', entry['Name']), + # 'id': ???, # Is this an FDev ID for suit type ? + 'suitId': entry['SuitID'], + 'slots': [], + }} + ) + # update credits + self.state['Credits'] -= entry.get('Price', 0) pass elif event_type == 'SellSuit': From c8d98bba2e2fa780ff5130d95410d1caca3304d7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 10:23:39 +0100 Subject: [PATCH 636/727] suits: Guard against "no CAPI pull yet" on BuySuit --- monitor.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/monitor.py b/monitor.py index 98dc4593..f42b68b1 100644 --- a/monitor.py +++ b/monitor.py @@ -977,19 +977,23 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # alpha4 : # { "timestamp":"2021-04-29T09:03:37Z", "event":"BuySuit", "Name":"UtilitySuit_Class1", # "Name_Localised":"Maverick Suit", "Price":150000, "SuitID":1698364934364699 } - self.state['Suits'].update( - {entry['SuitID']: { - 'name': entry['Name'], - 'locName': entry.get('Name_Localised', entry['Name']), - # 'id': ???, # Is this an FDev ID for suit type ? - 'suitId': entry['SuitID'], - 'slots': [], - }} - ) + new_suit = { + 'name': entry['Name'], + 'locName': entry.get('Name_Localised', entry['Name']), + # 'id': ???, # Is this an FDev ID for suit type ? + 'suitId': entry['SuitID'], + 'slots': [], + } + if self.state['Suits'] is None: + self.state['Suits'] = {entry['SuitID']: new_suit} + + else: + self.state['Suits'].update( + {entry['SuitID']: new_suit} + ) # update credits self.state['Credits'] -= entry.get('Price', 0) - pass elif event_type == 'SellSuit': # Remove from known suits @@ -1002,6 +1006,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • Name # • Price # • SuitID + # alpha4: + # { "timestamp":"2021-04-29T09:15:51Z", "event":"SellSuit", "SuitID":1698364937435505, + # "Name":"explorationsuit_class1", "Name_Localised":"Artemis Suit", "Price":90000 } # update credits total pass From aeca211a88287e9361f6a2e85ced13a460f4472c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 10:26:55 +0100 Subject: [PATCH 637/727] Suits: Handle 'SellSuit' --- monitor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index f42b68b1..b61eb965 100644 --- a/monitor.py +++ b/monitor.py @@ -1009,8 +1009,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # alpha4: # { "timestamp":"2021-04-29T09:15:51Z", "event":"SellSuit", "SuitID":1698364937435505, # "Name":"explorationsuit_class1", "Name_Localised":"Artemis Suit", "Price":90000 } + try: + self.state['Suits'].pop(entry['SuitID']) + + except KeyError: + logger.exception(f"SellSuit for a suit we didn't know about? {entry['SuitID']}") + # update credits total - pass + self.state['Credits'] += entry.get('Price', 0) elif event_type == 'UpgradeSuit': # alpha4 From 29a517ce115f07f0fc2849979bd9c174848c268a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 10:34:03 +0100 Subject: [PATCH 638/727] Suits: Note that we need an 'UpgradeSuit' example still The journal document has to be mistaken about cost being in credits. --- monitor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index b61eb965..c6c2836e 100644 --- a/monitor.py +++ b/monitor.py @@ -1027,7 +1027,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • SuitID # • Class # • Cost - # Update credits total ? + # Update credits total ? It shouldn't even involve credits! + # Actual alpha4 - need to grind mats pass # `LoadoutEquipModule` has no instance-specific ID as of 4.0.0.13 From addb178d3dadea7b0bca427a4c610d6d129c0264 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 11:23:14 +0100 Subject: [PATCH 639/727] Suits: Handle 'CreateSuitLoadout' This entails converting the Journal supplied data into CAPI form. --- monitor.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index c6c2836e..47249e2c 100644 --- a/monitor.py +++ b/monitor.py @@ -949,7 +949,32 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • SuitName # • LoadoutID # • LoadoutName - pass + # alpha4: + # { "timestamp":"2021-04-29T09:37:08Z", "event":"CreateSuitLoadout", "SuitID":1698364940285172, + # "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", "LoadoutID":4293000001, + # "LoadoutName":"Dom L/K/K", "Modules":[ + # { + # "SlotName":"PrimaryWeapon1", + # "SuitModuleID":1698364962722310, + # "ModuleName":"wpn_m_assaultrifle_laser_fauto", + # "ModuleName_Localised":"TK Aphelion" + # }, + # { "SlotName":"PrimaryWeapon2", + # "SuitModuleID":1698364956302993, "ModuleName":"wpn_m_assaultrifle_kinetic_fauto", + # "ModuleName_Localised":"Karma AR-50" }, { "SlotName":"SecondaryWeapon", + # "SuitModuleID":1698292655291850, "ModuleName":"wpn_s_pistol_kinetic_sauto", + # "ModuleName_Localised":"Karma P-15" } ] } + new_loadout = { + 'loadoutSlotId': self.suit_loadout_id_from_loadoutid(entry['LoadoutID']), + 'suit': { + 'name': entry['SuitName'], + 'locName': entry.get('SuitName_Localised', entry['SuitName']), + 'suitId': entry['SuitID'], + }, + 'mame': entry['LoadoutName'], + 'slots': self.suit_loadout_slots_array_to_dict(entry['Modules']), + } + self.state['SuitLoadouts'][new_loadout['loadoutSlotId']] = new_loadout elif event_type == 'DeleteSuitLoadout': # We should remove this from the monitor.state record of loadouts. The slotid @@ -1618,6 +1643,29 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return out + def suit_loadout_slots_array_to_dict(self, loadout: dict) -> dict: + """ + Return a CAPI-style Suit loadout from a Journal style dict. + + :param loadout: e.g. Journal 'CreateSuitLoadout'->'Modules'. + :return: CAPI-style dict for a suit loadout. + """ + loadout_slots = {x['SlotName']: x for x in loadout} + slots = {} + for s in ('PrimaryWeapon1', 'PrimaryWeapon2', 'SecondaryWeapon'): + if loadout_slots.get(s) is None: + continue + + slots[s] = { + 'name': loadout_slots[s]['ModuleName'], + # 'id': None, # FDevID ? + 'weaponrackId': loadout_slots[s]['SuitModuleID'], + 'locName': loadout_slots[s].get('ModuleName_Localised', loadout_slots[s]['ModuleName']), + 'locDescription': '', + } + + return slots + # singleton monitor = EDLogs() From bd1b86d3a3dd1356df733a1cc008b4dba729c91f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 11:30:55 +0100 Subject: [PATCH 640/727] Suits/Loadouts: Always convert to dict form for simpler downstream code. --- PLUGINS.md | 15 +++++++-------- companion.py | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index e09e8359..d596a337 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -537,16 +537,15 @@ Content of `state` (updated to the current journal entry): | `Data` | `dict` | 'Data' MicroResources in Odyssey, `int` count each. | | `BackPack` | `dict` | `dict` of Odyssey MicroResources in backpack. | | `SuitCurrent` | `dict` | CAPI-returned data of currently worn suit. NB: May be `None` if no data. | -| `Suits` | `dict` or `list`[1] | CAPI-returned data of owned suits. NB: Type depends on if array is sparse or not. May be `None` if no data. | +| `Suits` | `dict`[1] | CAPI-returned data of owned suits. NB: May be `None` if no data. | | `SuitLoadoutCurrent` | `dict` | CAPI-returned data of current Suit Loadout. NB: May be `None` if no data. | -| `SuitLoadouts` | `dict` | CAPI-returned data of all Suit Loadouts. NB: May be `None` if no data. | +| `SuitLoadouts` | `dict`[1] | CAPI-returned data of all Suit Loadouts. NB: May be `None` if no data. | -[1] - With `Suits` there's a caveat depending on all the slots from 0 are -contiguously used or not. If they are then the type is `list` and -indexing is purely numeric. If not then it's a `dict` and you need to index it -with a string. There is `companion.index_possibly_sparse_list()` to aid -with this, or if you wish to iterate over it use `companion.listify()` to -fill in any gaps and have a `list` to operate on. +[1] - Some data from the CAPI is sometimes returned as a `list` (when all +members are present) and other times as an integer-keyed `dict` (when at +least one member is missing, so the indices are not contiguous). We choose to +always convert to the integer-keyed `dict` form so that code utilising the data +is simpler. New in version 4.1.6: diff --git a/companion.py b/companion.py index f1f38bd6..4243f817 100644 --- a/companion.py +++ b/companion.py @@ -680,13 +680,24 @@ class Session(object): return monitor.state['SuitCurrent'] = current_suit - monitor.state['Suits'] = data.get('suits') + # It's easier to always have this in the 'sparse array' dict form + suits = data.get('suits') + if isinstance(suits, list): + monitor.state['Suits'] = dict(enumerate(suits)) + + else: + monitor.state['Suits'] = suits if (suit_loadouts := data.get('loadouts')) is None: logger.warning('CAPI data had "suit" but no (suit) "loadouts"') monitor.state['SuitLoadoutCurrent'] = data.get('loadout') - monitor.state['SuitLoadouts'] = suit_loadouts + # It's easier to always have this in the 'sparse array' dict form + if isinstance(suit_loadouts, list): + monitor.state['SuitLoadouts'] = dict(enumerate(suit_loadouts)) + + else: + monitor.state['SuitLoadouts'] = suit_loadouts def close(self) -> None: """Close CAPI authorization session.""" From e24e0b354728101059ac7e655b85bdc009e16cb5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 11:34:29 +0100 Subject: [PATCH 641/727] Suits: Update `DeleteSuitLoadout` code with alpha4 example Also slightly simplified this. Leaving the try/except for now, although it should no longer be necessary. --- monitor.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/monitor.py b/monitor.py index 47249e2c..f265604a 100644 --- a/monitor.py +++ b/monitor.py @@ -977,16 +977,17 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['SuitLoadouts'][new_loadout['loadoutSlotId']] = new_loadout elif event_type == 'DeleteSuitLoadout': - # We should remove this from the monitor.state record of loadouts. The slotid - # could end up valid due to CreateSuitLoadout events, but we won't have the - # correct new loadout data until next CAPI pull. - loadoutid = entry['LoadoutID'] - slotid = self.suit_loadout_id_from_loadoutid(loadoutid) - # This might be a Loadout that was created after our last CAPI pull. + # alpha4: + # { "timestamp":"2021-04-29T10:32:27Z", "event":"DeleteSuitLoadout", "SuitID":1698365752966423, + # "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003, + # "LoadoutName":"Loadout 1" } + + slotid = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) try: self.state['SuitLoadouts'].pop(f'{slotid}') except KeyError: + # This should no longer happen, as we're now handling CreateSuitLoadout properly logger.exception(f"slot id {slotid} doesn't exist, not in last CAPI pull ?") elif event_type == 'RenameSuitLoadout': From e796684fc6c1d6f663453dc310e0516acd909ba8 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 11:40:59 +0100 Subject: [PATCH 642/727] Suits: Handle `RenameSuitLoadout` --- monitor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index f265604a..80adee29 100644 --- a/monitor.py +++ b/monitor.py @@ -997,7 +997,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • SuitName # • LoadoutID # • Loadoutname - pass + # alpha4: + # { "timestamp":"2021-04-29T10:35:55Z", "event":"RenameSuitLoadout", "SuitID":1698365752966423, + # "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003, + # "LoadoutName":"Art L/K" } + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + self.state['SuitLoadouts'][loadout_id]['name'] = entry['LoadoutName'] elif event_type == 'BuySuit': # alpha4 : From 2253e45c18e98f3243aa9384dabf754f6b9706c5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 11:45:06 +0100 Subject: [PATCH 643/727] Suits: Add some paranoia around Loadouts * Initialise to empty dict. * try/except in case CAPI pull hasn't happened yet when parsing Journal events. --- monitor.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/monitor.py b/monitor.py index 80adee29..b969f2d2 100644 --- a/monitor.py +++ b/monitor.py @@ -153,7 +153,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'SuitCurrent': None, 'Suits': None, 'SuitLoadoutCurrent': None, - 'SuitLoadouts': None, + 'SuitLoadouts': {}, } def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 @@ -982,13 +982,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003, # "LoadoutName":"Loadout 1" } - slotid = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) try: - self.state['SuitLoadouts'].pop(f'{slotid}') + self.state['SuitLoadouts'].pop(f'{loadout_id}') except KeyError: # This should no longer happen, as we're now handling CreateSuitLoadout properly - logger.exception(f"slot id {slotid} doesn't exist, not in last CAPI pull ?") + logger.exception(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") elif event_type == 'RenameSuitLoadout': # alpha4 @@ -1002,7 +1002,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003, # "LoadoutName":"Art L/K" } loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) - self.state['SuitLoadouts'][loadout_id]['name'] = entry['LoadoutName'] + try: + self.state['SuitLoadouts'][loadout_id]['name'] = entry['LoadoutName'] + + except KeyError: + logger.exception(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") elif event_type == 'BuySuit': # alpha4 : From 218073ed73dc262098128f4fed268c06e981e1cd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 12:07:48 +0100 Subject: [PATCH 644/727] Suits: Remove weapon from all loadouts if sold. Also update credits total for the sale. --- monitor.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index b969f2d2..90aa94a5 100644 --- a/monitor.py +++ b/monitor.py @@ -1103,8 +1103,22 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • Name # • Price # • SuitModuleID + # alpha4: + # { "timestamp":"2021-04-29T10:50:34Z", "event":"SellWeapon", "Name":"wpn_m_assaultrifle_laser_fauto", + # "Name_Localised":"TK Aphelion", "Price":75000, "SuitModuleID":1698364962722310 } + + # We need to look over all Suit Loadouts for ones that used this specific weapon + # and update them to entirely empty that slot. + for sl in self.state['SuitLoadouts']: + for w in self.state['SuitLoadouts'][sl]['slots']: + if self.state['SuitLoadouts'][sl]['slots'][w]['weaponrackId'] == entry['SuitModuleID']: + self.state['SuitLoadouts'][sl]['slots'].pop(w) + # We've changed the dict, so iteration breaks, but also the weapon + # could only possibly have been here once. + break + # Update credits total - pass + self.state['Credits'] += entry.get('Price', 0) # `UpgradeWeapon` has no instance-specific ID as of 4.0.0.13 elif event_type == 'UpgradeWeapon': From d35f64ebd5d40c93c3071eccf7541f4ef75710f3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 12:21:08 +0100 Subject: [PATCH 645/727] Suits: Handle `LoadoutRemoveModule` Currently this seems to only trigger if you 'overwrite' an equipped weapon with another one. The one being removed will be cited in this event. --- monitor.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index 90aa94a5..76de2d98 100644 --- a/monitor.py +++ b/monitor.py @@ -1066,9 +1066,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Actual alpha4 - need to grind mats pass - # `LoadoutEquipModule` has no instance-specific ID as of 4.0.0.13 elif event_type == 'LoadoutEquipModule': - # alpha4 - should have necessary IDs + # alpha4: + # { "timestamp":"2021-04-29T11:11:13Z", "event":"LoadoutEquipModule", "LoadoutName":"Dom L/K/K", + # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", + # "LoadoutID":4293000001, "SlotName":"PrimaryWeapon2", "ModuleName":"wpn_m_assaultrifle_laser_fauto", + # "ModuleName_Localised":"TK Aphelion", "SuitModuleID":1698372938719590 } pass elif event_type == 'LoadoutRemoveModule': @@ -1082,7 +1085,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • LoadoutName # • ModuleName: weapon or other item removed from loadout # • SuitModuleID - pass + # alpha4 - triggers if selecting an already-equipped weapon into a different slot + # { "timestamp":"2021-04-29T11:11:13Z", "event":"LoadoutRemoveModule", "LoadoutName":"Dom L/K/K", + # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", + # "LoadoutID":4293000001, "SlotName":"PrimaryWeapon1", "ModuleName":"wpn_m_assaultrifle_laser_fauto", + # "ModuleName_Localised":"TK Aphelion", "SuitModuleID":1698372938719590 } + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + self.state['SuitLoadouts'][loadout_id]['slots'].pop(entry['SlotName']) # `BuyWeapon` has no instance-specific ID as of 4.0.0.13 elif event_type == 'BuyWeapon': From d27075cb38342823099e041ca3adbe2bde9fc7ee Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 12:28:45 +0100 Subject: [PATCH 646/727] Suits: Handle `LoadoutEquipModule` event We're assuming weapons only at this point. Might need adjustment when we get access to engineering. --- monitor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 76de2d98..cac535bc 100644 --- a/monitor.py +++ b/monitor.py @@ -1072,7 +1072,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", # "LoadoutID":4293000001, "SlotName":"PrimaryWeapon2", "ModuleName":"wpn_m_assaultrifle_laser_fauto", # "ModuleName_Localised":"TK Aphelion", "SuitModuleID":1698372938719590 } - pass + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + self.state['SuitLoadouts'][loadout_id]['slots'][entry['SlotName']] = { + 'name': entry['ModuleName'], + 'locName': entry.get('ModuleName_Localised', entry['ModuleName']), + 'id': None, + 'weaponrackId': entry['SuitModuleID'], + 'locDescription': '', + } elif event_type == 'LoadoutRemoveModule': # alpha4 From 7b76e327ce76d28dda828b09dc6c0c6e2f441f3e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 12:32:31 +0100 Subject: [PATCH 647/727] Suits: Always set 'id' to None Better to get a `None` value than a KeyError. --- monitor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monitor.py b/monitor.py index cac535bc..c5cf08e8 100644 --- a/monitor.py +++ b/monitor.py @@ -1013,11 +1013,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # { "timestamp":"2021-04-29T09:03:37Z", "event":"BuySuit", "Name":"UtilitySuit_Class1", # "Name_Localised":"Maverick Suit", "Price":150000, "SuitID":1698364934364699 } new_suit = { - 'name': entry['Name'], - 'locName': entry.get('Name_Localised', entry['Name']), - # 'id': ???, # Is this an FDev ID for suit type ? - 'suitId': entry['SuitID'], - 'slots': [], + 'name': entry['Name'], + 'locName': entry.get('Name_Localised', entry['Name']), + 'id': None, # Is this an FDev ID for suit type ? + 'suitId': entry['SuitID'], + 'slots': [], } if self.state['Suits'] is None: self.state['Suits'] = {entry['SuitID']: new_suit} @@ -1698,7 +1698,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below slots[s] = { 'name': loadout_slots[s]['ModuleName'], - # 'id': None, # FDevID ? + 'id': None, # FDevID ? 'weaponrackId': loadout_slots[s]['SuitModuleID'], 'locName': loadout_slots[s].get('ModuleName_Localised', loadout_slots[s]['ModuleName']), 'locDescription': '', From ac4f05269539387181fb0ab6ceb441b99c3683b4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 29 Apr 2021 12:38:01 +0100 Subject: [PATCH 648/727] Suits: Update credits on `BuyWeapon` Also cleaning out some verbose comments. --- monitor.py | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/monitor.py b/monitor.py index c5cf08e8..bea4ab00 100644 --- a/monitor.py +++ b/monitor.py @@ -1082,16 +1082,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below } elif event_type == 'LoadoutRemoveModule': - # alpha4 - # This event is logged when a player removes a weapon from a suit loadout - # - # Parameters: - # • SuitID - # • SuitName - # • LoadoutID - # • LoadoutName - # • ModuleName: weapon or other item removed from loadout - # • SuitModuleID # alpha4 - triggers if selecting an already-equipped weapon into a different slot # { "timestamp":"2021-04-29T11:11:13Z", "event":"LoadoutRemoveModule", "LoadoutName":"Dom L/K/K", # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", @@ -1100,25 +1090,16 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) self.state['SuitLoadouts'][loadout_id]['slots'].pop(entry['SlotName']) - # `BuyWeapon` has no instance-specific ID as of 4.0.0.13 elif event_type == 'BuyWeapon': # alpha4 - # Parameters: - # • Name - # • Price - # • SuitModuleID + # { "timestamp":"2021-04-29T11:10:51Z", "event":"BuyWeapon", "Name":"Wpn_M_AssaultRifle_Laser_FAuto", + # "Name_Localised":"TK Aphelion", "Price":125000, "SuitModuleID":1698372938719590 } # update credits - pass + self.state['Credits'] -= entry.get('Price', 0) - # `SellWeapon` has no instance-specific ID as of 4.0.0.13 elif event_type == 'SellWeapon': - # alpha4 - # This event is logged when a player sells a hand weapon - # - # Parameters: - # • Name - # • Price - # • SuitModuleID + # We're not actually keeping track of all owned weapons, only those in + # Suit Loadouts. # alpha4: # { "timestamp":"2021-04-29T10:50:34Z", "event":"SellWeapon", "Name":"wpn_m_assaultrifle_laser_fauto", # "Name_Localised":"TK Aphelion", "Price":75000, "SuitModuleID":1698364962722310 } @@ -1136,8 +1117,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Update credits total self.state['Credits'] += entry.get('Price', 0) - # `UpgradeWeapon` has no instance-specific ID as of 4.0.0.13 elif event_type == 'UpgradeWeapon': + # We're not actually keeping track of all owned weapons, only those in + # Suit Loadouts. # alpha4 pass From 203fb051b09c9762707f140f2cc768b1a5f2c4f4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 10:47:09 +0100 Subject: [PATCH 649/727] Suits: Simplify `BuySuit` code. --- monitor.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/monitor.py b/monitor.py index bea4ab00..92522bfe 100644 --- a/monitor.py +++ b/monitor.py @@ -1012,20 +1012,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # alpha4 : # { "timestamp":"2021-04-29T09:03:37Z", "event":"BuySuit", "Name":"UtilitySuit_Class1", # "Name_Localised":"Maverick Suit", "Price":150000, "SuitID":1698364934364699 } - new_suit = { + self.state['Suits'][entry['SuitID']] = { 'name': entry['Name'], 'locName': entry.get('Name_Localised', entry['Name']), 'id': None, # Is this an FDev ID for suit type ? 'suitId': entry['SuitID'], 'slots': [], } - if self.state['Suits'] is None: - self.state['Suits'] = {entry['SuitID']: new_suit} - - else: - self.state['Suits'].update( - {entry['SuitID']: new_suit} - ) # update credits self.state['Credits'] -= entry.get('Price', 0) From 30b8a5eeadffc53a0c8f0e237d23b3a2e06032e9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 10:49:39 +0100 Subject: [PATCH 650/727] Suits: Log if a buy/sell event doesn't contain Price --- monitor.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/monitor.py b/monitor.py index 92522bfe..e25a3236 100644 --- a/monitor.py +++ b/monitor.py @@ -1021,7 +1021,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below } # update credits - self.state['Credits'] -= entry.get('Price', 0) + if price := entry.get('Price') is None: + logger.error(f"BuySuit didn't contain Price: {entry}") + + else: + self.state['Credits'] -= price elif event_type == 'SellSuit': # Remove from known suits @@ -1044,7 +1048,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below logger.exception(f"SellSuit for a suit we didn't know about? {entry['SuitID']}") # update credits total - self.state['Credits'] += entry.get('Price', 0) + if price := entry.get('Price') is None: + logger.error(f"SellSuit didn't contain Price: {entry}") + + else: + self.state['Credits'] += price elif event_type == 'UpgradeSuit': # alpha4 @@ -1088,7 +1096,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # { "timestamp":"2021-04-29T11:10:51Z", "event":"BuyWeapon", "Name":"Wpn_M_AssaultRifle_Laser_FAuto", # "Name_Localised":"TK Aphelion", "Price":125000, "SuitModuleID":1698372938719590 } # update credits - self.state['Credits'] -= entry.get('Price', 0) + if price := entry.get('Price') is None: + logger.error(f"BuyWeapon didn't contain Price: {entry}") + + else: + self.state['Credits'] -= price elif event_type == 'SellWeapon': # We're not actually keeping track of all owned weapons, only those in @@ -1108,7 +1120,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below break # Update credits total - self.state['Credits'] += entry.get('Price', 0) + if price := entry.get('Price') is None: + logger.error(f"SellWeapon didn't contain Price: {entry}") + + else: + self.state['Credits'] += price elif event_type == 'UpgradeWeapon': # We're not actually keeping track of all owned weapons, only those in From eed4402340570749dac6ab19003cd52f84f37c14 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 10:53:38 +0100 Subject: [PATCH 651/727] Suits: Init monitor.state['Suits'] to empty dict --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index e25a3236..dbaaa05b 100644 --- a/monitor.py +++ b/monitor.py @@ -151,7 +151,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Data': defaultdict(int), # Backpack Data }, 'SuitCurrent': None, - 'Suits': None, + 'Suits': {}, 'SuitLoadoutCurrent': None, 'SuitLoadouts': {}, } From 8e8c9fa3fff655a27a557b7301ea3da49b8aa044 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 13:50:52 +0100 Subject: [PATCH 652/727] Items: `Data` is now in `BackPackMaterials` as well --- monitor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monitor.py b/monitor.py index dbaaa05b..0dd229a8 100644 --- a/monitor.py +++ b/monitor.py @@ -805,6 +805,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['BackPack']['Component'] = defaultdict(int) self.state['BackPack']['Consumable'] = defaultdict(int) self.state['BackPack']['Item'] = defaultdict(int) + self.state['BackPack']['Data'] = defaultdict(int) clean_components = self.coalesce_cargo(entry['Components']) self.state['BackPack']['Component'].update( @@ -821,6 +822,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below {self.canonicalise(x['Name']): x['Count'] for x in clean_items} ) + clean_data = self.coalesce_cargo(entry['Data']) + self.state['BackPack']['Data'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_data} + ) + elif event_type == 'BuyMicroResources': # Buying from a Pioneer Supplies, goes directly to ShipLocker. # One event per Item, not an array. From 1f8215ed92134530a9fee3fc97fe3bcd7d36ac1a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 13:56:26 +0100 Subject: [PATCH 653/727] Items: `ShipLockerMaterials` now has `Data` But also, we're not getting a `BackPackMaterials` at the same time to be sure of the state of things. --- monitor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index 0dd229a8..d2e0e635 100644 --- a/monitor.py +++ b/monitor.py @@ -772,15 +772,16 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Component'] = defaultdict(int) self.state['Consumable'] = defaultdict(int) self.state['Item'] = defaultdict(int) + self.state['Data'] = defaultdict(int) # TODO: Really we need a full BackPackMaterials event at the same time. # In lieu of that, empty the backpack. This will explicitly # be wrong if Cmdr relogs at a Settlement with anything in - # backpack. We can't track when they use/pick up items - # anyway (Odyssey Alpha Phase 1 Hotfix 2). - # alpha4 - This should be changed + # backpack. + # Still no BackPackMaterials at the same time in 4.0.0.31 self.state['BackPack']['Component'] = defaultdict(int) self.state['BackPack']['Consumable'] = defaultdict(int) self.state['BackPack']['Item'] = defaultdict(int) + self.state['BackPack']['Data'] = defaultdict(int) clean_components = self.coalesce_cargo(entry['Components']) self.state['Component'].update( @@ -797,6 +798,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below {self.canonicalise(x['Name']): x['Count'] for x in clean_items} ) + clean_data = self.coalesce_cargo(entry['Data']) + self.state['Data'].update( + {self.canonicalise(x['Name']): x['Count'] for x in clean_data} + ) + elif event_type == 'BackPackMaterials': # alpha4 - # Lists the contents of the backpack, eg when disembarking from ship From 422b766586b29401b4c9dda8391a84ca497b7fff Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 14:30:37 +0100 Subject: [PATCH 654/727] Items: Decrement BackPack Consumable on `UseConsumable` --- monitor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index d2e0e635..cf6552cb 100644 --- a/monitor.py +++ b/monitor.py @@ -914,7 +914,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Parameters: # • Name # • Type - pass + for c in self.state['BackPackMaterials']['Consumables']: + if c['Name'] == entry['Name']: + c['Count'] -= 1 elif event_type == 'SwitchSuitLoadout': # alpha4 @@ -1144,8 +1146,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # alpha4 pass - # alpha4 elif event_type == 'ScanOrganic': + # Nothing of interest to our state. pass elif event_type == 'SellOrganicData': From f89ed7999e1cc2b43e0e75aa47b59d85105a3335 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 14:44:20 +0100 Subject: [PATCH 655/727] Items: Implement `CollectItems`, `DropItems` and `UseConsumable` The paranoia when subtracting from counts is because of the lack of fresh `BackPackMaterials` if relogging whilst on foot. --- monitor.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index cf6552cb..172c6196 100644 --- a/monitor.py +++ b/monitor.py @@ -895,7 +895,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • Name # • Type # • OwnerID - pass + for i in self.state['BackPackMaterials'][entry['Type']]: + if i['Name'] == entry['Name']: + i['Count'] += entry['Count'] elif event_type == 'DropItems': # alpha4 @@ -905,7 +907,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • OwnerID # • MissionID # • Count - pass + for i in self.state['BackPackMaterials'][entry['Type']]: + if i['Name'] == entry['Name']: + i['Count'] -= entry['Count'] + # Paranoia in case we lost track + if i['Count'] < 0: + i['Count'] = 0 elif event_type == 'UseConsumable': # alpha4 @@ -914,9 +921,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Parameters: # • Name # • Type - for c in self.state['BackPackMaterials']['Consumables']: + for c in self.state['BackPackMaterials']['Consumable']: if c['Name'] == entry['Name']: c['Count'] -= 1 + # Paranoia in case we lost track + if i['Count'] < 0: + i['Count'] = 0 elif event_type == 'SwitchSuitLoadout': # alpha4 From e1a63c2879011311ff99fcf86faa233f239e8dd5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 15:12:12 +0100 Subject: [PATCH 656/727] Items: Correct `UseConsumable` code --- monitor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/monitor.py b/monitor.py index 172c6196..6a0b42dd 100644 --- a/monitor.py +++ b/monitor.py @@ -921,12 +921,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Parameters: # • Name # • Type - for c in self.state['BackPackMaterials']['Consumable']: - if c['Name'] == entry['Name']: - c['Count'] -= 1 + for c in self.state['BackPack']['Consumable']: + if c == entry['Name']: + self.state['BackPack']['Consumable'][c] -= 1 # Paranoia in case we lost track - if i['Count'] < 0: - i['Count'] = 0 + if self.state['BackPack']['Consumable'][c] < 0: + self.state['BackPack']['Consumable'][c] = 0 elif event_type == 'SwitchSuitLoadout': # alpha4 From 60b2045ea4293e2408e7189792621952b78cab81 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 15:21:47 +0100 Subject: [PATCH 657/727] Items: Fix `DropItems` and `CollectItems` Tested as actually working. --- monitor.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/monitor.py b/monitor.py index 6a0b42dd..584ece48 100644 --- a/monitor.py +++ b/monitor.py @@ -895,9 +895,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • Name # • Type # • OwnerID - for i in self.state['BackPackMaterials'][entry['Type']]: - if i['Name'] == entry['Name']: - i['Count'] += entry['Count'] + for i in self.state['BackPack'][entry['Type']]: + if i == entry['Name']: + self.state['BackPack'][entry['Type']][i] += entry['Count'] elif event_type == 'DropItems': # alpha4 @@ -907,12 +907,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • OwnerID # • MissionID # • Count - for i in self.state['BackPackMaterials'][entry['Type']]: - if i['Name'] == entry['Name']: - i['Count'] -= entry['Count'] + for i in self.state['BackPack'][entry['Type']]: + if i == entry['Name']: + self.state['BackPack'][entry['Type']][i] -= entry['Count'] # Paranoia in case we lost track - if i['Count'] < 0: - i['Count'] = 0 + if self.state['BackPack'][entry['Type']][i] < 0: + self.state['BackPack'][entry['Type']][i] = 0 elif event_type == 'UseConsumable': # alpha4 From 6d58863a40a2e1504486a49f8595c240c8a370f7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Apr 2021 15:42:10 +0100 Subject: [PATCH 658/727] Suits: Fix 'mame' typo --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 584ece48..d7714d53 100644 --- a/monitor.py +++ b/monitor.py @@ -995,7 +995,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'locName': entry.get('SuitName_Localised', entry['SuitName']), 'suitId': entry['SuitID'], }, - 'mame': entry['LoadoutName'], + 'name': entry['LoadoutName'], 'slots': self.suit_loadout_slots_array_to_dict(entry['Modules']), } self.state['SuitLoadouts'][new_loadout['loadoutSlotId']] = new_loadout From c867d4c282186b76335a0caeafbd74c3c9143ffa Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 10:14:35 +0100 Subject: [PATCH 659/727] CAPI: Don't auto-update on Taxi `Docked`, but do on `Disembark` in-station Closes #1016 --- EDMarketConnector.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 30ddc857..8c11b1fd 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1109,14 +1109,29 @@ class AppWindow(object): if not config.get_int('hotkey_mute'): hotkeymgr.play_bad() - # Auto-Update after docking, but not if auth callback is pending - if ( - entry['event'] in ('StartUp', 'Location', 'Docked') - and monitor.station - and not config.get_int('output') & config.OUT_MKT_MANUAL - and config.get_int('output') & config.OUT_STATION_ANY - and companion.session.state != companion.Session.STATE_AUTH - ): + auto_update = False + # Only if auth callback is not pending + if companion.session.state != companion.Session.STATE_AUTH: + # Only if configured to do so + if (not config.get_int('output') & config.OUT_MKT_MANUAL + and config.get_int('output') & config.OUT_STATION_ANY): + if entry['event'] in ('StartUp', 'Location', 'Docked') and monitor.station: + # TODO: Can you log out in a docked Taxi and then back in to + # the taxi, so 'Location' should be covered here too ? + if entry['event'] == 'Docked' and entry.get('Taxi'): + # In Odyssey there's a 'Docked' event for an Apex taxi, + # but the CAPI data isn't updated until you Disembark. + auto_update = False + + else: + auto_update = True + + # In Odyssey if you are in a Taxi the `Docked` event for it is before + # the CAPI data is updated, but CAPI *is* updated after you `Disembark`. + elif entry['event'] == 'Disembark' and entry.get('Taxi') and entry.get('OnStation'): + auto_update = True + + if auto_update: self.w.after(int(SERVER_RETRY * 1000), self.getandsend) if entry['event'] == 'ShutDown': From 3ab8b97562d8da81adf499cc181361e65c39f59b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 10:19:10 +0100 Subject: [PATCH 660/727] Suits: We might not know about SuitLoadout being switched to --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index d7714d53..f7ebc937 100644 --- a/monitor.py +++ b/monitor.py @@ -947,7 +947,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['SuitLoadoutCurrent'] = self.state['SuitLoadouts'][f'{new_slot}'] except KeyError: - logger.exception(f"Getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})") + logger.debug(f"Getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})") # Might mean that a new suit loadout was created and we need a new CAPI fetch ? self.state['SuitCurrent'] = None self.state['SuitLoadoutCurrent'] = None From 0e18666054835cd481af39246febe4fe3bb900a9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 10:25:39 +0100 Subject: [PATCH 661/727] Suits: Only process `SwitchSuitLoadout` if we know about Suits and Loadouts --- monitor.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/monitor.py b/monitor.py index f7ebc937..d80262f0 100644 --- a/monitor.py +++ b/monitor.py @@ -943,28 +943,30 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # ◦ ModuleName loadoutid = entry['LoadoutID'] new_slot = self.suit_loadout_id_from_loadoutid(loadoutid) - try: - self.state['SuitLoadoutCurrent'] = self.state['SuitLoadouts'][f'{new_slot}'] - - except KeyError: - logger.debug(f"Getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})") - # Might mean that a new suit loadout was created and we need a new CAPI fetch ? - self.state['SuitCurrent'] = None - self.state['SuitLoadoutCurrent'] = None - - else: + # If this application is run with the latest Journal showing such an event then we won't + # yet have the CAPI data, so no idea about Suits or Loadouts. + if self.state['Suits'] and self.state['SuitLoadouts']: try: - new_suitid = self.state['SuitLoadoutCurrent']['suit']['suitId'] + self.state['SuitLoadoutCurrent'] = self.state['SuitLoadouts'][f'{new_slot}'] except KeyError: - logger.exception(f"Getting switched-to suit ID from slot {new_slot} ({loadoutid})") + logger.debug(f"KeyError getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})") + self.state['SuitCurrent'] = None + self.state['SuitLoadoutCurrent'] = None else: try: - self.state['SuitCurrent'] = self.state['Suits'][f'{new_suitid}'] + new_suitid = self.state['SuitLoadoutCurrent']['suit']['suitId'] except KeyError: - logger.exception(f"Getting switched-to suit from slot {new_slot} ({loadoutid}") + logger.debug(f"KeyError getting switched-to suit ID from slot {new_slot} ({loadoutid})") + + else: + try: + self.state['SuitCurrent'] = self.state['Suits'][f'{new_suitid}'] + + except KeyError: + logger.debug(f"KeyError getting switched-to suit from slot {new_slot} ({loadoutid}") elif event_type == 'CreateSuitLoadout': # We know we won't have data for this new one From 81104ca973f21093ea5365186985504a7d330752 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 10:31:08 +0100 Subject: [PATCH 662/727] Suits: Only debug log if we can't find loadout for DeleteSuitLoadout --- monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index d80262f0..666301b8 100644 --- a/monitor.py +++ b/monitor.py @@ -1014,7 +1014,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below except KeyError: # This should no longer happen, as we're now handling CreateSuitLoadout properly - logger.exception(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") + logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") elif event_type == 'RenameSuitLoadout': # alpha4 From 751002bf1a0f35454801f9e0744fab7e90a53f4e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 10:42:54 +0100 Subject: [PATCH 663/727] Suits: Guards for if we don't have CAPI data yet We still need each try/except in case: 1. Journal has you buying a suit, or creating a SuitLoadout. 2. It then has you selling/deleting a different one. 3. But no CAPI data yet, so we don't know about that different one. --- monitor.py | 86 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/monitor.py b/monitor.py index 666301b8..58f975c8 100644 --- a/monitor.py +++ b/monitor.py @@ -929,18 +929,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['BackPack']['Consumable'][c] = 0 elif event_type == 'SwitchSuitLoadout': - # alpha4 - # This event is logged when a player selects a different flight suit from the ship’s locker - # - # Parameters: - # • SuitID - # • SuitName - # • LoadoutID - # • LoadoutName - # • Modules: array of objects - # ◦ SlotName - # ◦ SuitModuleID - # ◦ ModuleName loadoutid = entry['LoadoutID'] new_slot = self.suit_loadout_id_from_loadoutid(loadoutid) # If this application is run with the latest Journal showing such an event then we won't @@ -1008,13 +996,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003, # "LoadoutName":"Loadout 1" } - loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) - try: - self.state['SuitLoadouts'].pop(f'{loadout_id}') + if self.state['SuitLoadouts']: + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + try: + self.state['SuitLoadouts'].pop(f'{loadout_id}') - except KeyError: - # This should no longer happen, as we're now handling CreateSuitLoadout properly - logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") + except KeyError: + # This should no longer happen, as we're now handling CreateSuitLoadout properly + logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") elif event_type == 'RenameSuitLoadout': # alpha4 @@ -1027,12 +1016,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # { "timestamp":"2021-04-29T10:35:55Z", "event":"RenameSuitLoadout", "SuitID":1698365752966423, # "SuitName":"explorationsuit_class1", "SuitName_Localised":"Artemis Suit", "LoadoutID":4293000003, # "LoadoutName":"Art L/K" } - loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) - try: - self.state['SuitLoadouts'][loadout_id]['name'] = entry['LoadoutName'] + if self.state['SuitLoadouts']: + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + try: + self.state['SuitLoadouts'][loadout_id]['name'] = entry['LoadoutName'] - except KeyError: - logger.exception(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") + except KeyError: + logger.debug(f"loadout slot id {loadout_id} doesn't exist, not in last CAPI pull ?") elif event_type == 'BuySuit': # alpha4 : @@ -1067,18 +1057,19 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # alpha4: # { "timestamp":"2021-04-29T09:15:51Z", "event":"SellSuit", "SuitID":1698364937435505, # "Name":"explorationsuit_class1", "Name_Localised":"Artemis Suit", "Price":90000 } - try: - self.state['Suits'].pop(entry['SuitID']) + if self.state['Suits']: + try: + self.state['Suits'].pop(entry['SuitID']) - except KeyError: - logger.exception(f"SellSuit for a suit we didn't know about? {entry['SuitID']}") + except KeyError: + logger.debug(f"SellSuit for a suit we didn't know about? {entry['SuitID']}") - # update credits total - if price := entry.get('Price') is None: - logger.error(f"SellSuit didn't contain Price: {entry}") + # update credits total + if price := entry.get('Price') is None: + logger.error(f"SellSuit didn't contain Price: {entry}") - else: - self.state['Credits'] += price + else: + self.state['Credits'] += price elif event_type == 'UpgradeSuit': # alpha4 @@ -1091,6 +1082,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • Cost # Update credits total ? It shouldn't even involve credits! # Actual alpha4 - need to grind mats + # if self.state['Suits']: pass elif event_type == 'LoadoutEquipModule': @@ -1099,14 +1091,19 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", # "LoadoutID":4293000001, "SlotName":"PrimaryWeapon2", "ModuleName":"wpn_m_assaultrifle_laser_fauto", # "ModuleName_Localised":"TK Aphelion", "SuitModuleID":1698372938719590 } - loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) - self.state['SuitLoadouts'][loadout_id]['slots'][entry['SlotName']] = { - 'name': entry['ModuleName'], - 'locName': entry.get('ModuleName_Localised', entry['ModuleName']), - 'id': None, - 'weaponrackId': entry['SuitModuleID'], - 'locDescription': '', - } + if self.state['SuitLoadouts']: + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + try: + self.state['SuitLoadouts'][loadout_id]['slots'][entry['SlotName']] = { + 'name': entry['ModuleName'], + 'locName': entry.get('ModuleName_Localised', entry['ModuleName']), + 'id': None, + 'weaponrackId': entry['SuitModuleID'], + 'locDescription': '', + } + + except KeyError: + logger.error(f"LoadoutEquipModule: {entry}") elif event_type == 'LoadoutRemoveModule': # alpha4 - triggers if selecting an already-equipped weapon into a different slot @@ -1114,8 +1111,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # "SuitID":1698364940285172, "SuitName":"tacticalsuit_class1", "SuitName_Localised":"Dominator Suit", # "LoadoutID":4293000001, "SlotName":"PrimaryWeapon1", "ModuleName":"wpn_m_assaultrifle_laser_fauto", # "ModuleName_Localised":"TK Aphelion", "SuitModuleID":1698372938719590 } - loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) - self.state['SuitLoadouts'][loadout_id]['slots'].pop(entry['SlotName']) + if self.state['SuitLoadouts']: + loadout_id = self.suit_loadout_id_from_loadoutid(entry['LoadoutID']) + try: + self.state['SuitLoadouts'][loadout_id]['slots'].pop(entry['SlotName']) + + except KeyError: + logger.error(f"LoadoutRemoveModule: {entry}") elif event_type == 'BuyWeapon': # alpha4 From d74b88658702554baa099e0b20331b83adb9e2bc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 10:46:25 +0100 Subject: [PATCH 664/727] Update credits for `SellOrganicData` --- monitor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 58f975c8..b1a8f987 100644 --- a/monitor.py +++ b/monitor.py @@ -1165,8 +1165,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below pass elif event_type == 'SellOrganicData': - # alpha4 - update current credits ? - pass + for bd in entry['BioData']: + self.state['Credits'] += bd['Value'] + bd['Bonus'] # alpha4 - Credits updates elif event_type == 'BookDropship': From 77d96f61c7a1205d81a04da1f0b66b7954e78a0a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 10:50:20 +0100 Subject: [PATCH 665/727] Odyssey Credits: Update for book/cancel Taxi/Dropship --- monitor.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/monitor.py b/monitor.py index b1a8f987..28d19317 100644 --- a/monitor.py +++ b/monitor.py @@ -1168,15 +1168,17 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below for bd in entry['BioData']: self.state['Credits'] += bd['Value'] + bd['Bonus'] - # alpha4 - Credits updates elif event_type == 'BookDropship': - pass + self.state['Credits'] -= entry['Cost'] + elif event_type == 'BookTaxi': - pass + self.state['Credits'] -= entry['Cost'] + elif event_type == 'CancelDropship': - pass + self.state['Credits'] += entry['Refund'] + elif event_type == 'CancelTaxi': - pass + self.state['Credits'] += entry['Refund'] elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json From 812398ee0d46ce13bfe86bf2a5bd4d398626311e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 12:03:45 +0100 Subject: [PATCH 666/727] Credits: Review and add/tweak code for all Journal events There are a few where either the v30 Journal doc is wrong/has an ommision, or we genuinely don't get the required information. --- monitor.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index 28d19317..e6a873e8 100644 --- a/monitor.py +++ b/monitor.py @@ -552,6 +552,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Rebuy'] = None self.state['Modules'] = None + self.state['Credits'] -= entry['ShipPrice'] + elif event_type == 'ShipyardSwap': self.state['ShipID'] = entry['ShipID'] self.state['ShipIdent'] = None @@ -602,8 +604,21 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Value': entry['BuyPrice'], } + self.state['Credits'] -= entry['BuyPrice'] + + elif event_type == 'ModuleRetrieve': + self.state['Credits'] -= entry['Cost'] + elif event_type == 'ModuleSell': self.state['Modules'].pop(entry['Slot'], None) + self.state['Credits'] += entry['SellPrice'] + + elif event_type == 'ModuleSellRemote': + self.state['Credits'] += entry['SellPrice'] + + elif event_type == 'ModuleStore': + self.state['Modules'].pop(entry['Slot'], None) + self.state['Credits'] -= entry['Cost'] elif event_type == 'ModuleSwap': to_item = self.state['Modules'].get(entry['ToSlot']) @@ -767,6 +782,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean}) + elif event_type == 'CargoTransfer': + # TODO: Transfers between ship and FC/SRV + pass + elif event_type == 'ShipLockerMaterials': # This event has the current totals, so drop any current data self.state['Component'] = defaultdict(int) @@ -836,15 +855,16 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'BuyMicroResources': # Buying from a Pioneer Supplies, goes directly to ShipLocker. # One event per Item, not an array. - # alpha4 - update current credits ? category = self.category(entry['Category']) name = self.canonicalise(entry['Name']) self.state[category][name] += entry['Count'] + self.state['Credits'] -= entry['Price'] + elif event_type == 'SellMicroResources': # Selling to a Bar Tender on-foot. + self.state['Credits'] += entry['Price'] # One event per whole sale, so it's an array. - # alpha4 - update current credits ? for mr in entry['MicroResources']: category = self.category(mr['Category']) name = self.canonicalise(mr['Name']) @@ -1157,7 +1177,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'UpgradeWeapon': # We're not actually keeping track of all owned weapons, only those in # Suit Loadouts. - # alpha4 + # alpha4 - credits? Shouldn't cost any! pass elif event_type == 'ScanOrganic': @@ -1207,6 +1227,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below commodity = self.canonicalise(entry['Type']) self.state['Cargo'][commodity] += entry.get('Count', 1) + if event_type == 'BuyDrones': + self.state['Credits'] -= entry['TotalCost'] + + elif event_type == 'MarketBuy': + self.state['Credits'] -= entry['TotalCost'] + elif event_type in ('EjectCargo', 'MarketSell', 'SellDrones'): commodity = self.canonicalise(entry['Type']) cargo = self.state['Cargo'] @@ -1214,6 +1240,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if cargo[commodity] <= 0: cargo.pop(commodity) + if event_type == 'MarketSell': + self.state['Credits'] += entry['TotalSale'] + + elif event_type == 'SellDrones': + self.state['Credits'] += entry['TotalSale'] + elif event_type == 'SearchAndRescue': for item in entry.get('Items', []): commodity = self.canonicalise(item['Name']) @@ -1295,6 +1327,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below module['Engineering'].pop('ExperimentalEffect_Localised', None) elif event_type == 'MissionCompleted': + self.state['Credits'] += entry['Reward'] + for reward in entry.get('CommodityReward', []): commodity = self.canonicalise(reward['Name']) self.state['Cargo'][commodity] += reward.get('Count', 1) @@ -1378,6 +1412,77 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below else: self.state['Friends'].discard(entry['Name']) + # Try to keep Credits total updated + elif event_type in ('MultiSellExplorationData', 'SellExplorationData'): + self.state['Credits'] += entry['TotalEarnings'] + + elif event_type == 'BuyExplorationData': + self.state['Credits'] -= entry['Cost'] + + elif event_type == 'BuyTradeData': + self.state['Credits'] -= entry['Cost'] + + elif event_type == 'BuyAmmo': + self.state['Credits'] -= entry['Cost'] + + elif event_type == 'CommunityGoalReward': + self.state['Credits'] += entry['Reward'] + + elif event_type == 'CrewHire': + self.state['Credits'] -= entry['Cost'] + + elif event_type == 'FetchRemoteModule': + self.state['Credits'] -= entry['TransferCost'] + + elif event_type == 'MissionAbandoned': + # Is this paid at this point, or just a fine to pay later ? + # self.state['Credits'] -= entry['Fine'] + pass + + elif event_type in ('PayBounties', 'PayFines', 'PayLegacyFines'): + self.state['Credits'] -= entry['Amount'] + + elif event_type == 'RedeemVoucher': + self.state['Credits'] += entry['Amount'] + + elif event_type in ('RefuelAll', 'RefuelPartial', 'Repair', 'RepairAll', 'RestockVehicle'): + self.state['Credits'] -= entry['Cost'] + + elif event_type == 'SellShipOnRebuy': + self.state['Credits'] += entry['ShipPrice'] + + elif event_type == 'ShipyardSell': + self.state['Credits'] += entry['ShipPrice'] + + elif event_type == 'ShipyardTransfer': + self.state['Credits'] -= entry['TransferPrice'] + + elif event_type == 'PowerplayFastTrack': + self.state['Credits'] -= entry['Cost'] + + elif event_type == 'PowerplaySalary': + self.state['Credits'] += entry['Amount'] + + elif event_type == 'SquadronCreated': + # v30 docs don't actually say anything about credits cost + pass + + elif event_type == 'CarrierBuy': + self.state['Credits'] -= entry['Price'] + + elif event_type == 'CarrierBankTransfer': + self.state['Credits'] = entry['PlayerBalance'] + + elif event_type == 'CarrierDecommission': + # v30 doc says nothing about citing the refund amount + pass + + elif event_type == 'NpcCrewPaidWage': + self.state['Credits'] -= entry['Amount'] + + elif event_type == 'Resurrect': + self.state['Credits'] -= entry['Cost'] + return entry except Exception as ex: From 7c7609f2ee70750ba5f44192a76c1d434d4d87cb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 12:15:57 +0100 Subject: [PATCH 667/727] Cargo: Update ship cargo on `CargoTransfer` event We missed this when it was brought in with Fleet Carriers in 2020. --- monitor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index e6a873e8..8bb9cd8b 100644 --- a/monitor.py +++ b/monitor.py @@ -783,8 +783,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Cargo'].update({self.canonicalise(x['Name']): x['Count'] for x in clean}) elif event_type == 'CargoTransfer': - # TODO: Transfers between ship and FC/SRV - pass + for c in entry['Transfers']: + name = self.canonicalise(c['Type']) + if c['Direction'] == 'toship': + self.state['Cargo'][name] += c['Count'] + + else: + # So it's *from* the ship + self.state['Cargo'][name] -= c['Count'] elif event_type == 'ShipLockerMaterials': # This event has the current totals, so drop any current data From f6cb69ebadb2d8d60d2a47ec6d9a5de0bea22de9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 13:12:14 +0100 Subject: [PATCH 668/727] Embark: Keep monitor.station set when Embarking OnStation. --- monitor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index 8bb9cd8b..4f52ea06 100644 --- a/monitor.py +++ b/monitor.py @@ -639,9 +639,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.stationservices = None elif event_type == 'Embark': - # If we've embarked then we're no longer on the station. - - # alpha4 # This event is logged when a player (on foot) gets into a ship or SRV # Parameters: # • SRV: true if getting into SRV, false if getting into a ship @@ -658,6 +655,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • StationType # • MarketID self.station = None + if entry.get('OnStation'): + self.station = entry.get('StationName', '') + self.state['OnFoot'] = False elif event_type == 'Disembark': From 02052dd90ef1538e2b819664d984ab9fb5cc786c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 13:47:52 +0100 Subject: [PATCH 669/727] EDDB: Don't blank station when Embarking OnStation to own ship. --- plugins/eddb.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 2c926152..e5e9f81c 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -123,7 +123,13 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.station_marketid = entry.get('MarketID') or this.station_marketid # We might pick up StationName in DockingRequested, make sure we clear it if leaving - if entry['event'] in ('Undocked', 'FSDJump', 'SupercruiseEntry', 'Embark'): + if entry['event'] in ('Undocked', 'FSDJump', 'SupercruiseEntry'): + this.station = None + this.station_marketid = None + + if entry['event'] == 'Embark' and not entry.get('OnStation'): + # If we're embarking OnStation to a Taxi/Dropship we'll also get an + # Undocked event. this.station = None this.station_marketid = None From 844e6115e31cf1a15adef6c584f25ae012b11fb7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 13:50:45 +0100 Subject: [PATCH 670/727] Also handle Embark (properly) in EDSM and Inara plugins. --- plugins/edsm.py | 6 ++++++ plugins/inara.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/edsm.py b/plugins/edsm.py index 0f6ed269..f4118f56 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -382,6 +382,12 @@ def journal_entry( this.station = None this.station_marketid = None + if entry['event'] == 'Embark' and not entry.get('OnStation'): + # If we're embarking OnStation to a Taxi/Dropship we'll also get an + # Undocked event. + this.station = None + this.station_marketid = None + if config.get_str('station_provider') == 'EDSM': to_set = this.station if not this.station: diff --git a/plugins/inara.py b/plugins/inara.py index 28b19959..c8110ff0 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -395,6 +395,12 @@ def journal_entry( # noqa: C901, CCR001 this.station = None this.station_marketid = None + if entry['event'] == 'Embark' and not entry.get('OnStation'): + # If we're embarking OnStation to a Taxi/Dropship we'll also get an + # Undocked event. + this.station = None + this.station_marketid = None + if config.get_int('inara_out') and not is_beta and not this.multicrew and credentials(cmdr): current_creds = Credentials(this.cmdr, this.FID, str(credentials(this.cmdr))) try: From f9db23e25da98ea8843bad58b01ca360373cbd5d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 17:56:13 +0100 Subject: [PATCH 671/727] Pre-Release 5.0.0-beta7: appversion and changelog --- ChangeLog.md | 42 ++++++++++++++++++++++++++++++++++++++++++ config.py | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index bfb91d49..8ca62fdb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,48 @@ This is due to moving to Python 3.9.x, which itself does not now support Windows 7. The application (both EDMarketConnector.exe and EDMC.exe) will crash on startup due to a missing DLL.** +Pre-Release 5.0.0-beta7 +=== + +* There is a new option on the 'Appearance' tab of Settings 'Minimize to system + tray' for Windows users. When this is active then EDMarketConnector.exe + will indeed minimize to the system tray, and not be on the taskbar. + + The systray icon will always be present, with option 'Open' to restore the + window, along with a 'Quit' option. + + Thanks to Garud for the work on this. + +* More work has been done for Odyssey, with extra and expanded Journal + events now available. Suits and their Loadouts will track better now, + although we still require a CAPI data pull (an 'Update') to be guaranteed + data about them. + +Plugin Developers +--- + +* The `state` passed to plugins has for a long time had a `'Credits'` member, + but until now no effort was made to keep this record of the credits balance + up to date after the initial `LoadGame` event. This has now been addressed, + and the balance should stay in sync as best it can from the available + Journal events. It will always correct back to the actual balance on each + CAPI data pull. + +* `Suits` and `SuitLoadouts` in `state` will now always be a `dict`, even if + the array is not sparse, and will never be `None`. This allows for + consistency in how you access the members. Note that the `id` field found + on e.g. weapon details in suit loadouts may be `None` if we got the data + from the Journal rather than the CAPI data. + +* `BackPack` items will now track better. However note that the lack of a + Journal event when throwing a grenade, along with no `BackPackMaterials` + event if logging in on-foot means that we can't track this inventory + perfectly. + +* Ship `Cargo` in `state` now takes account of any `CargoTransfer` events. + This was added to the game in the Fleet Carriers update, but also covers + transfers to/from an SRV. + Pre-Release 5.0.0-beta6 === diff --git a/config.py b/config.py index e384a993..7ea609a8 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta6' +_static_appversion = '5.0.0-beta7' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From 09cbf1225d52f8a4dc49bee03e1243eeeda2f004 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 17:58:08 +0100 Subject: [PATCH 672/727] Update translations --- L10n/cs.strings | 9 +++++++ L10n/de.strings | 6 +++++ L10n/es.strings | 3 +++ L10n/ja.strings | 6 +++++ L10n/pl.strings | 30 ++++++++++++++++++++++ L10n/pt-BR.strings | 6 +++++ L10n/pt-PT.strings | 6 +++++ L10n/ru.strings | 6 +++++ L10n/sr-Latn-BA.strings | 6 +++++ L10n/sr-Latn.strings | 6 +++++ L10n/uk.strings | 57 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 141 insertions(+) diff --git a/L10n/cs.strings b/L10n/cs.strings index 822fd745..04a566a6 100644 --- a/L10n/cs.strings +++ b/L10n/cs.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Minimalizovat do lišty"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Status"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Oblek"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; @@ -532,6 +538,9 @@ /* Label for 'UI Scaling' option [prefs.py] */ "UI Scale Percentage" = "Procenta UI škálování"; +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Neznámý"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Aktualizovat"; diff --git a/L10n/de.strings b/L10n/de.strings index 250733c2..a87a049c 100644 --- a/L10n/de.strings +++ b/L10n/de.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Fähnrich"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "In die Taskleiste minimieren"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Fast Planlos"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Status"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Anzug"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Landkundiger"; diff --git a/L10n/es.strings b/L10n/es.strings index 84533ae4..ce24523c 100644 --- a/L10n/es.strings +++ b/L10n/es.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Guardiamarina"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Minimizar a la bandeja de sistema"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Casi perdido"; diff --git a/L10n/ja.strings b/L10n/ja.strings index 312c91e2..34c440cf 100644 --- a/L10n/ja.strings +++ b/L10n/ja.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "システムトレイに最小化する"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "ステータス"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "スーツ"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; diff --git a/L10n/pl.strings b/L10n/pl.strings index 9cf8676a..47c166a3 100644 --- a/L10n/pl.strings +++ b/L10n/pl.strings @@ -1,6 +1,9 @@ /* Language name */ "!Language" = "Polski"; +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 oznacza nieprzeźroczyste.{CR}Okno aktualizowane w czasie rzeczywistym."; + /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 oznacza wartość domyślną{CR}Zmiany zostaną wprowadzone po{CR}ponownym uruchomieniu programu!"; @@ -148,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "Błąd"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Błąd: Brak połączenia z EDDN"; @@ -157,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Błąd: Nie można połączyć się z serwisem Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Błąd: Nie można sprawdzić ID klienta z tokenu"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Błąd: ID klienta nie pasuje!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Błąd: EDSM {MSG}"; @@ -175,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Błąd: Dane uwierzytelniające niepoprawne"; +/* [companion.py] */ +"Error: unable to get token" = "Błąd: Nie można pobrać tokenu"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Błąd: Niepoprawny Cmdr"; @@ -274,6 +289,9 @@ /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Przeźroczystość okna głównego"; + /* [prefs.py] */ "Market data in CSV format file" = "Dane rynkowe w formacie CSV"; @@ -292,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Zminimalizuj do zasobnika systemowego"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; @@ -361,6 +382,9 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Folder pluginów"; +/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ +"Plugins Without Python 3.x Support:" = "Pluginy nie obsługiwane przez Python 3.x:"; + /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -481,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Status"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Kombinezon"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; @@ -511,6 +538,9 @@ /* Label for 'UI Scaling' option [prefs.py] */ "UI Scale Percentage" = "Skalowanie UI"; +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Nieznany"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Aktualizacja"; diff --git a/L10n/pt-BR.strings b/L10n/pt-BR.strings index 41b66913..bd9404f1 100644 --- a/L10n/pt-BR.strings +++ b/L10n/pt-BR.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Cabo"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Minimizar para a área de notificação"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Quase perdido"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Status"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Traje"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Cartógrafo"; diff --git a/L10n/pt-PT.strings b/L10n/pt-PT.strings index 62aa3814..17287cad 100644 --- a/L10n/pt-PT.strings +++ b/L10n/pt-PT.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Aspirante"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Minimizar para a barra de tarefas"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Quase sem destino"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Estado"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Fato"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Cartógrafo"; diff --git a/L10n/ru.strings b/L10n/ru.strings index 7e2ef8c5..f6bbe980 100644 --- a/L10n/ru.strings +++ b/L10n/ru.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Гардемарин"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Сворачивать в системный трей"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Почти бесцельный"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Статус"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Костюм"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Изыскатель"; diff --git a/L10n/sr-Latn-BA.strings b/L10n/sr-Latn-BA.strings index 990a91d7..0e83eac4 100644 --- a/L10n/sr-Latn-BA.strings +++ b/L10n/sr-Latn-BA.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Minimiziranje u system tray"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Status"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Odijelo"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; diff --git a/L10n/sr-Latn.strings b/L10n/sr-Latn.strings index e93193d9..30dda2c1 100644 --- a/L10n/sr-Latn.strings +++ b/L10n/sr-Latn.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Minimizuj u sistemsku paletu (SysTray)"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Status"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Odelo"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; diff --git a/L10n/uk.strings b/L10n/uk.strings index a45be942..35e5c954 100644 --- a/L10n/uk.strings +++ b/L10n/uk.strings @@ -1,6 +1,12 @@ /* Language name */ "!Language" = "Українська"; +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 означає повністю непрозоре. {CR} Вікно буде оновлюватись в режимі реального часу"; + +/* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ +"100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 означає, що {CR} потрібно перезапустити за замовчуванням, щоб зміни вступили в силу {CR}!"; + /* App menu entry on OSX. [EDMarketConnector.py] */ "About {APP}" = "Про {APP}"; @@ -43,6 +49,9 @@ /* Federation rank. [stats.py] */ "Cadet" = "Кадет"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: Не отримано данних пілота"; + /* CQC rank. [stats.py] */ "Champion" = "Чемпіон"; @@ -142,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Підприємець"; +/* [companion.py] */ +"Error" = "Помилка"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Помилка: Немає зв'язку з EDDN!"; @@ -151,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Помилка: Немає з'єднання з Inara"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Помилка: Не вдалося перевірити токен customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Error: customer_id не співпадає!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Помилка: EDSM {MSG}!"; @@ -169,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Помилка: Невірні облікові дані!"; +/* [companion.py] */ +"Error: unable to get token" = "Помилка: не вдалося отримати токен"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Помилка! Не той обліковий запис!"; @@ -223,12 +244,18 @@ /* Hotkey/Shortcut settings prompt on Windows. [prefs.py] */ "Hotkey" = "Гаряча клавіша"; +/* Changed journal update_lock failed [monitor.py] */ +"Ignore" = "Ігнорувати"; + /* Section heading in settings. [inara.py] */ "Inara credentials" = "Обліковий запис Inara"; /* Settings>Plugins>Information on migrating plugins [prefs.py] */ "Information on migrating plugins" = "Інформація про міграцію плагінів"; +/* Changed journal update_lock failed [monitor.py] */ +"Journal directory already locked" = "Каталог журналу вже заблокований"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Сполучення клавіш"; @@ -253,12 +280,18 @@ /* Cmdr stats. [stats.py] */ "Loan" = "Борг"; +/* Label for user configured level of logging [prefs.py] */ +"Log Level" = "Рівень подробиць журналу"; + /* [EDMarketConnector.py] */ "Logging in..." = "Вхід в..."; /* Empire rank. [stats.py] */ "Lord" = "Пан"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Прозорість головного вікна"; + /* [prefs.py] */ "Market data in CSV format file" = "Ринкові дані у форматі CSV файлу"; @@ -277,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Гардемарин"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Згорнути програму"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Здебільшого Безцільний"; @@ -346,6 +382,9 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Сховище плагінів"; +/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ +"Plugins Without Python 3.x Support:" = "Плагіни без підтримки Python 3.x:"; + /* Federation rank. [stats.py] */ "Post Captain" = "Капітан I рангу"; @@ -400,6 +439,9 @@ /* Help menu item. [EDMarketConnector.py] */ "Release Notes" = "Інформація про реліз"; +/* Changed journal update_lock failed [monitor.py] */ +"Retry" = "Повторна спроба"; + /* Multicrew role label in main window. [EDMarketConnector.py] */ "Role" = "Посада"; @@ -445,6 +487,9 @@ /* Setting to decide which ship outfitting website to link to - either E:D Shipyard or Coriolis. [prefs.py] */ "Shipyard" = "Корабельна верф"; +/* Status line text that appears when process exit sequence starts [EDMarketConnector.py] */ +"Shutting down..." = "Закриття..."; + /* Empire rank. [stats.py] */ "Squire" = "Зброєносець"; @@ -460,12 +505,18 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Статус"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Костюм"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Геодезист"; /* Main window. [EDMarketConnector.py] */ "System" = "Система"; +/* Changed journal update_lock failed [monitor.py] */ +"The new Journal Directory location is already locked.{CR}You can either attempt to resolve this and then Retry, or choose to Ignore this." = "Нове розташування каталогу журналів уже заблоковано. {CR} Ви можете спробувати вирішити це, а потім повторити спробу, або Ігнорувати це."; + /* Appearance setting. [prefs.py] */ "Theme" = "Тема"; @@ -484,6 +535,12 @@ /* Trade rank. [stats.py] */ "Tycoon" = "Магнат"; +/* Label for 'UI Scaling' option [prefs.py] */ +"UI Scale Percentage" = "Відсоток шкали інтерфейсу користувача"; + +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Невідомо"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Оновлення"; From 316201eb77da75235be306278e8f0b121b0b7850 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 19:32:53 +0100 Subject: [PATCH 673/727] systray: Disable whilst we figure out py2exe packaging issue --- EDMarketConnector.py | 38 +++++++++++++++++++------------------- prefs.py | 18 +++++++++--------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 8c11b1fd..97f517ff 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -9,7 +9,7 @@ import locale import pathlib import re import sys -import threading +# import threading import webbrowser from builtins import object, str from os import chdir, environ @@ -264,7 +264,7 @@ if __name__ == '__main__': # noqa: C901 if TYPE_CHECKING: from logging import trace, TRACE # type: ignore # noqa: F401 import update - from infi.systray import SysTrayIcon + # from infi.systray import SysTrayIcon # isort: on def _(x: str) -> str: @@ -332,16 +332,16 @@ class AppWindow(object): self.prefsdialog = None - if platform == 'win32': - from infi.systray import SysTrayIcon + # if platform == 'win32': + # from infi.systray import SysTrayIcon - def open_window(systray: 'SysTrayIcon') -> None: - self.w.deiconify() + # def open_window(systray: 'SysTrayIcon') -> None: + # self.w.deiconify() - menu_options = (("Open", None, open_window),) - # Method associated with on_quit is called whenever the systray is closing - self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray) - self.systray.start() + # menu_options = (("Open", None, open_window),) + # # Method associated with on_quit is called whenever the systray is closing + # self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray) + # self.systray.start() plug.load_plugins(master) @@ -1399,18 +1399,18 @@ class AppWindow(object): logger.debug('"other" exception', exc_info=e) self.status['text'] = str(e) - def exit_tray(self, systray: 'SysTrayIcon') -> None: - """Tray icon is shutting down.""" - exit_thread = threading.Thread(target=self.onexit) - exit_thread.setDaemon(True) - exit_thread.start() + # def exit_tray(self, systray: 'SysTrayIcon') -> None: + # """Tray icon is shutting down.""" + # exit_thread = threading.Thread(target=self.onexit) + # exit_thread.setDaemon(True) + # exit_thread.start() def onexit(self, event=None) -> None: """Application shutdown procedure.""" - if platform == 'win32': - shutdown_thread = threading.Thread(target=self.systray.shutdown) - shutdown_thread.setDaemon(True) - shutdown_thread.start() + # if platform == 'win32': + # shutdown_thread = threading.Thread(target=self.systray.shutdown) + # shutdown_thread.setDaemon(True) + # shutdown_thread.start() config.set_shutdown() # Signal we're in shutdown now. diff --git a/prefs.py b/prefs.py index 119b727f..65a018a1 100644 --- a/prefs.py +++ b/prefs.py @@ -636,7 +636,7 @@ class PreferencesDialog(tk.Toplevel): # Appearance theme and language setting self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default'))) self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop'))) - self.minimize_system_tray = tk.BooleanVar(value=config.get_bool('minimize_system_tray')) + # self.minimize_system_tray = tk.BooleanVar(value=config.get_bool('minimize_system_tray')) self.theme = tk.IntVar(value=config.get_int('theme')) self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')] self.theme_prompts = [ @@ -792,13 +792,13 @@ class PreferencesDialog(tk.Toplevel): ) self.ontop_button.grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting - if platform == 'win32': - nb.Checkbutton( - appearance_frame, - text=_('Minimize to system tray'), - variable=self.minimize_system_tray, - command=self.themevarchanged - ).grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting + # if platform == 'win32': + # nb.Checkbutton( + # appearance_frame, + # text=_('Minimize to system tray'), + # variable=self.minimize_system_tray, + # command=self.themevarchanged + # ).grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting nb.Label(appearance_frame).grid(sticky=tk.W) # big spacer @@ -1172,7 +1172,7 @@ class PreferencesDialog(tk.Toplevel): config.set('ui_scale', self.ui_scale.get()) config.set('ui_transparency', self.transparency.get()) config.set('always_ontop', self.always_ontop.get()) - config.set('minimize_system_tray', self.minimize_system_tray.get()) + # config.set('minimize_system_tray', self.minimize_system_tray.get()) config.set('theme', self.theme.get()) config.set('dark_text', self.theme_colors[0]) config.set('dark_highlight', self.theme_colors[1]) From 86e6362b88fdf708dca802b1386f0eda0ee61cc0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 19:33:23 +0100 Subject: [PATCH 674/727] Changelog: Remove systray entry --- ChangeLog.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 8ca62fdb..5e6b5be0 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,15 +9,6 @@ crash on startup due to a missing DLL.** Pre-Release 5.0.0-beta7 === -* There is a new option on the 'Appearance' tab of Settings 'Minimize to system - tray' for Windows users. When this is active then EDMarketConnector.exe - will indeed minimize to the system tray, and not be on the taskbar. - - The systray icon will always be present, with option 'Open' to restore the - window, along with a 'Quit' option. - - Thanks to Garud for the work on this. - * More work has been done for Odyssey, with extra and expanded Journal events now available. Suits and their Loadouts will track better now, although we still require a CAPI data pull (an 'Update') to be guaranteed From 818bb56032dc3d30ed01400d17ccf687c3e75a4a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 1 May 2021 19:37:38 +0100 Subject: [PATCH 675/727] requirements: comment out infi.systray for now --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cc3d8c4d..6d977cb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ certifi==2020.12.5 requests==2.25.1 watchdog==2.0.3 -infi.systray==0.1.12; sys_platform == 'win32' +# Commented out because this doesn't package well with py2exe +# infi.systray==0.1.12; sys_platform == 'win32' # argh==0.26.2 watchdog dep # pyyaml==5.3.1 watchdog dep semantic-version==2.8.5 From 10d6c432a49fedb85ba3067980e2a61f61986ace Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 2 May 2021 10:31:57 +0100 Subject: [PATCH 676/727] Append " (beta)" to Cmdr name when appropriate Closes #1021 --- EDMarketConnector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 97f517ff..659c448b 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1048,6 +1048,9 @@ class AppWindow(object): self.ship_label['text'] = _('Ship') + ':' # Main window self.ship['text'] = '' + if monitor.cmdr and monitor.is_beta: + self.cmdr['text'] += ' (beta)' + self.update_suit_text() self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED) # Copy From 22116d46876dcafabc89589db210c3b199501405 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 May 2021 07:01:27 +0000 Subject: [PATCH 677/727] build(deps-dev): bump autopep8 from 1.5.6 to 1.5.7 Bumps [autopep8](https://github.com/hhatto/autopep8) from 1.5.6 to 1.5.7. - [Release notes](https://github.com/hhatto/autopep8/releases) - [Commits](https://github.com/hhatto/autopep8/compare/v1.5.6...v1.5.7) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 74241c63..380f3eea 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -20,7 +20,7 @@ pep8-naming==0.11.1 safety==1.10.3 # Code formatting tools -autopep8==1.5.6 +autopep8==1.5.7 # HTML changelogs grip==4.5.2 From a66f3b24a57acaa835fc54da3638e5586e2bdb63 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 5 May 2021 05:54:38 +0000 Subject: [PATCH 678/727] build(deps): bump watchdog from 2.0.3 to 2.1.0 Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 2.0.3 to 2.1.0. - [Release notes](https://github.com/gorakhargosh/watchdog/releases) - [Changelog](https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst) - [Commits](https://github.com/gorakhargosh/watchdog/compare/v2.0.3...v2.1.0) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6d977cb4..9e51f2be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 requests==2.25.1 -watchdog==2.0.3 +watchdog==2.1.0 # Commented out because this doesn't package well with py2exe # infi.systray==0.1.12; sys_platform == 'win32' # argh==0.26.2 watchdog dep From 60b84b340cd883b62862da5affb036934a4bb93b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 5 May 2021 05:54:45 +0000 Subject: [PATCH 679/727] build(deps-dev): bump pytest from 6.2.3 to 6.2.4 Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.3 to 6.2.4. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.2.3...6.2.4) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 380f3eea..59ed55b7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -30,7 +30,7 @@ grip==4.5.2 py2exe==0.10.4.0; sys_platform == 'win32' # Testing -pytest==6.2.3 +pytest==6.2.4 pytest-cov==2.11.1 # Pytest code coverage support coverage[toml]==5.5 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs # For manipulating folder permissions and the like. From 543e0477c2c1caa6546d731e36938279a0829db3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 May 2021 10:01:07 +0100 Subject: [PATCH 680/727] Don't assume ModuleRetrieve/Store have a Cost. The Journal doc says they do, but one report of ModuleRetrieve saying it doesn't, and ModuleStore does say "Cost (if any)". --- monitor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 4f52ea06..2d87c33f 100644 --- a/monitor.py +++ b/monitor.py @@ -607,7 +607,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Credits'] -= entry['BuyPrice'] elif event_type == 'ModuleRetrieve': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'ModuleSell': self.state['Modules'].pop(entry['Slot'], None) @@ -618,7 +618,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'ModuleStore': self.state['Modules'].pop(entry['Slot'], None) - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'ModuleSwap': to_item = self.state['Modules'].get(entry['ToSlot']) From ea2c59041ce5b0e0d5c410109a95984ebf6ed054 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 May 2021 10:45:45 +0100 Subject: [PATCH 681/727] Update GH windows build to use Python 3.9.5 --- .github/workflows/windows-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 8cc9297c..5bcbc7a9 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: "3.9.4" + python-version: "3.9.5" architecture: "x86" - name: Install python tools From dfb85bae1748cf4d7b6df278e6d11bcc2f4740a6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 May 2021 10:50:51 +0100 Subject: [PATCH 682/727] .python_version -> 3.9.5 --- .python-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.python-version b/.python-version index e0d61b5b..11aaa068 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.9.4 +3.9.5 From 5f29c866e7b2658d6baa14fdeff5017b6b6483dd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 May 2021 11:34:10 +0100 Subject: [PATCH 683/727] Dropship: Set OnFoot for DropshipDeploy, but ignore BookDropship See the comment added to BookDropship code for why we're ignoring it. --- monitor.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/monitor.py b/monitor.py index 2d87c33f..73fb9c83 100644 --- a/monitor.py +++ b/monitor.py @@ -687,6 +687,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['OnFoot'] = True + elif event_type == 'DropshipDeploy': + # We're definitely on-foot now + self.state['OnFoot'] = True + elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): # alpha4 - any changes ? # Location: @@ -1196,6 +1200,16 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'BookDropship': self.state['Credits'] -= entry['Cost'] + # Technically we *might* now not be OnFoot. + # The problem is that this event is recorded both for signing up for + # an on-foot CZ, and when you use the Dropship to return after the + # CZ completes. + # + # In the first case we're still in-station and thus still on-foot. + # + # In the second case we should instantly be in the Dropship and thus + # not still on-foot, BUT it doesn't really matter as the next significant + # event is going to be Disembark to on-foot anyway. elif event_type == 'BookTaxi': self.state['Credits'] -= entry['Cost'] From 692856bbe1a41f51f27a64dcb6009fd012c9f675 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 May 2021 11:42:29 +0100 Subject: [PATCH 684/727] Disembark: Use the alpha4-new flag to detect if on-station --- monitor.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/monitor.py b/monitor.py index 73fb9c83..43170e2b 100644 --- a/monitor.py +++ b/monitor.py @@ -661,8 +661,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['OnFoot'] = False elif event_type == 'Disembark': - # We don't yet have a way, other than LoadGame+Location, to detect if we *are* on a station on-foot. - # alpha4 # This event is logged when the player steps out of a ship or SRV # # Parameters: @@ -680,9 +678,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # • StationType # • MarketID - # If we're not exiting one of these then it's from our own ship, and then we should already have - # self.station set correctly. - if entry['SRV'] or entry['Taxi'] or entry['Multicrew']: + if entry.get('OnStation', False): + self.station = entry.get('StationName', '') + + else: self.station = None self.state['OnFoot'] = True From f1ca2b8283ceec5ab836a79f57ac3df2c3c9c5fb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 May 2021 12:20:24 +0100 Subject: [PATCH 685/727] Separate 'Docked' processing to own conditional. A taxi 'Docked' event has much less data than an own-ship one. Rather than put tortured conditionals into the Location/FSDJump/CarrierJump/Docked conditional I've split Docked into its own. There should always be one of the other events to set things like SystemAddress before a 'Docked' event, so limiting the new conditional to setting/changing only the station-related state variables. --- monitor.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/monitor.py b/monitor.py index 43170e2b..f1faeb18 100644 --- a/monitor.py +++ b/monitor.py @@ -690,7 +690,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # We're definitely on-foot now self.state['OnFoot'] = True - elif event_type in ('Location', 'FSDJump', 'Docked', 'CarrierJump'): + elif event_type == 'Docked': + self.station = entry.get('StationName') # May be None + self.station_marketid = entry.get('MarketID') # May be None + self.stationtype = entry.get('StationType') # May be None + self.stationservices = entry.get('StationServices') # None under E:D < 2.4 + + elif event_type in ('Location', 'FSDJump', 'CarrierJump'): # alpha4 - any changes ? # Location: # New in Odyssey: @@ -710,13 +716,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if 'StarPos' in entry: self.coordinates = tuple(entry['StarPos']) # type: ignore - elif self.system != entry['StarSystem']: - self.coordinates = None # Docked event doesn't include coordinates - self.systemaddress = entry.get('SystemAddress') - if event_type in ('Location', 'FSDJump', 'CarrierJump'): - self.systempopulation = entry.get('Population') + self.systempopulation = entry.get('Population') self.system = 'CQC' if entry['StarSystem'] == 'ProvingGround' else entry['StarSystem'] @@ -729,7 +731,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.station_marketid = entry.get('MarketID') # May be None self.stationtype = entry.get('StationType') # May be None - self.stationservices = entry.get('StationServices') # None under E:D < 2.4 + self.stationservices = entry.get('StationServices') # None in Odyssey for on-foot 'Location' elif event_type == 'ApproachBody': self.planet = entry['Body'] From 55fa06dd73dad6677685fdffbc3a21b34e6e35b4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 5 May 2021 21:21:20 +0100 Subject: [PATCH 686/727] systray: Remove another bit of code. If a user had enabled the 'Minimize to systray' option then this would cause the window to disappear on minimise, with no way to get it back. --- EDMarketConnector.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 659c448b..4fad261b 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1482,16 +1482,11 @@ class AppWindow(object): def oniconify(self, event=None) -> None: """Handle minimization of the application.""" - value = config.get_bool('minimize_system_tray') - if platform == 'win32' and value is not None and value: - self.w.withdraw() - - else: - self.w.overrideredirect(0) # Can't iconize while overrideredirect - self.w.iconify() - self.w.update_idletasks() # Size and windows styles get recalculated here - self.w.wait_visibility() # Need main window to be re-created before returning - theme.active = None # So theme will be re-applied on map + self.w.overrideredirect(0) # Can't iconize while overrideredirect + self.w.iconify() + self.w.update_idletasks() # Size and windows styles get recalculated here + self.w.wait_visibility() # Need main window to be re-created before returning + theme.active = None # So theme will be re-applied on map # TODO: Confirm this is unused and remove. def onmap(self, event=None) -> None: From 6cf1a30482c8cab9ff4754f528e6a0725afcb18c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 6 May 2021 08:51:59 +0100 Subject: [PATCH 687/727] Pre-Release 5.0.0-beta8: appversion and changelog --- ChangeLog.md | 25 +++++++++++++++++++++++++ config.py | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5e6b5be0..edf1cd82 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,31 @@ This is due to moving to Python 3.9.x, which itself does not now support Windows 7. The application (both EDMarketConnector.exe and EDMC.exe) will crash on startup due to a missing DLL.** +Pre-Release 5.0.0-beta8 +=== + +* If the application detects it's running against a non-live (alpha or beta) + version of the game it will append " (beta)" to the Commander name on the + main UI. + +* Don't assume some Journal events always have a 'Cost' value. + +* Removed a stray piece of code relating to the aborted systray + implementation. This would have caused minimising of the application to + hide the window. Only triggered if you'd tried our `develop` branch + whilst the systray code was active, and left the option "Minimize to systray" + active. + +Plugin Developers +--- + +* `monitor.state['OnFoot']` is now set True for a `DropshipDeploy` event. + +* Better detect that we're back on-foot from `Disembark` on a station. + +* Better `Docked` event processing to cater for the more limited form of this + event in an Apex taxi. + Pre-Release 5.0.0-beta7 === diff --git a/config.py b/config.py index 7ea609a8..8eafbe5d 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta7' +_static_appversion = '5.0.0-beta8' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From d475d3194f2b6204c1f3109d2cb12022a2ae4891 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 6 May 2021 11:09:49 +0100 Subject: [PATCH 688/727] PLUGINS.md: Document extra python modules we package for plugins use. --- PLUGINS.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PLUGINS.md b/PLUGINS.md index d596a337..664ccce7 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -77,6 +77,20 @@ reduce noise in HTTP requests `from ttkHyperlinkLabel import HyperlinkLabel` and `import myNotebook as nb` - For creating UI elements. +In addition to the above we also explicitly package the following python +modules for plugin use: + +- shutil +- sqlite3 +- zipfile + +And, of course, anything in the [Python Standard Library](https://docs.python.org/3/library/) +will always be available, dependent on the version of Python we're using to +build Windows installed versions. Check the 'Startup' line in an application +[Debug Log File](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#debug-log-files) +for the version of Python being used. + + --- ## Logging From 985794fbcb7ce4fbcd07d0ea63bb1ab2f4c58f70 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 7 May 2021 12:58:10 +0200 Subject: [PATCH 689/727] Ensure that Section exists on linuxconf When starting EDMC for the first time, linuxconf creates the required file automatically but does _not_ create our config section. This causes a keyerror on any access to config. Simple solution, test that the section exists, if it doesnt, create it (and backup any existing file beforehand) --- config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config.py b/config.py index 8eafbe5d..1a388fce 100644 --- a/config.py +++ b/config.py @@ -843,6 +843,16 @@ class LinuxConfig(AbstractConfig): logger.debug(f'Error occurred while reading in file. Assuming that we are creating a new one: {e}') self.config.add_section(self.SECTION) + # Ensure that our section exists + try: + self.config[self.SECTION].get("this_does_not_exist", fallback=None) + except KeyError: + logger.info("Config section not found. Backing up existing file (if any) and readding a section header") + if self.filename.exists(): + (self.filename.parent / f'{appname}.ini.backup').write_bytes(self.filename.read_bytes()) + + self.config.add_section(self.SECTION) + if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir(): self.set('outdir', self.home) From d3ffe6f0d9c9216b88cead3f5abaee28a5d6e4eb Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 7 May 2021 14:27:32 +0200 Subject: [PATCH 690/727] Removed useless check, added doc comments --- config.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index 1a388fce..67ea52d8 100644 --- a/config.py +++ b/config.py @@ -836,14 +836,10 @@ class LinuxConfig(AbstractConfig): self.filename.parent.mkdir(exist_ok=True, parents=True) self.config: Optional[ConfigParser] = ConfigParser(comment_prefixes=('#',), interpolation=None) + self.config.read(self.filename) # read() ignores files that dont exist - try: - self.config.read(self.filename) - except Exception as e: - logger.debug(f'Error occurred while reading in file. Assuming that we are creating a new one: {e}') - self.config.add_section(self.SECTION) - - # Ensure that our section exists + # Ensure that our section exists. This is here because configparser will happily create files for us, but it + # does not magically create sections try: self.config[self.SECTION].get("this_does_not_exist", fallback=None) except KeyError: From bbd1d7a52b5fbe41dfca63e10e38e6a392c3fadd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 7 May 2021 19:58:16 +0100 Subject: [PATCH 691/727] Pre-Release 5.0.0-rc1 appversion --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 67ea52d8..1fca363f 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-beta8' +_static_appversion = '5.0.0-rc1' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From 3e65fbaa5b09214c1b5e4e7e44917ca268a9cdf0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 7 May 2021 19:58:32 +0100 Subject: [PATCH 692/727] ChangeLog: Merged all 5.0.0-beta entries for a -rc1 version --- ChangeLog.md | 544 +++++++++++++++++++++++---------------------------- 1 file changed, 241 insertions(+), 303 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index edf1cd82..b7bb026f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,350 +1,166 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- -**As of release 5.0.0 (including betas) we no longer support Windows 7. -This is due to moving to Python 3.9.x, which itself does not now support -Windows 7. The application (both EDMarketConnector.exe and EDMC.exe) will -crash on startup due to a missing DLL.** - -Pre-Release 5.0.0-beta8 +Pre-Release 5.0.0-rc1 === +Python 3.9 +--- +* We now test against, and package with, Python 3.9.5. + + **As a consequence of this we no longer support Windows 7. + This is due to Python 3.9.x itself not supporting Windows 7. The + application (both EDMarketConnector.exe and EDMC.exe) will crash on startup + due to a missing DLL.** + + This should have no other impact on users or plugin developers, other + than the latter now being free to use features that were introduced since the + Python 3.7 series. + + Developers can check the contents of the `.python-version` file + in the source (it's not distributed with the Windows installer) for the + currently used version in a given branch. + +Changes and Enhancements +--- * If the application detects it's running against a non-live (alpha or beta) version of the game it will append " (beta)" to the Commander name on the main UI. - -* Don't assume some Journal events always have a 'Cost' value. - -* Removed a stray piece of code relating to the aborted systray - implementation. This would have caused minimising of the application to - hide the window. Only triggered if you'd tried our `develop` branch - whilst the systray code was active, and left the option "Minimize to systray" - active. - -Plugin Developers ---- - -* `monitor.state['OnFoot']` is now set True for a `DropshipDeploy` event. - -* Better detect that we're back on-foot from `Disembark` on a station. - -* Better `Docked` event processing to cater for the more limited form of this - event in an Apex taxi. - -Pre-Release 5.0.0-beta7 -=== - -* More work has been done for Odyssey, with extra and expanded Journal - events now available. Suits and their Loadouts will track better now, - although we still require a CAPI data pull (an 'Update') to be guaranteed - data about them. - -Plugin Developers ---- - -* The `state` passed to plugins has for a long time had a `'Credits'` member, - but until now no effort was made to keep this record of the credits balance - up to date after the initial `LoadGame` event. This has now been addressed, - and the balance should stay in sync as best it can from the available - Journal events. It will always correct back to the actual balance on each - CAPI data pull. - -* `Suits` and `SuitLoadouts` in `state` will now always be a `dict`, even if - the array is not sparse, and will never be `None`. This allows for - consistency in how you access the members. Note that the `id` field found - on e.g. weapon details in suit loadouts may be `None` if we got the data - from the Journal rather than the CAPI data. - -* `BackPack` items will now track better. However note that the lack of a - Journal event when throwing a grenade, along with no `BackPackMaterials` - event if logging in on-foot means that we can't track this inventory - perfectly. - -* Ship `Cargo` in `state` now takes account of any `CargoTransfer` events. - This was added to the game in the Fleet Carriers update, but also covers - transfers to/from an SRV. - -Pre-Release 5.0.0-beta6 -=== - -This adds a new UI element 'Suit', below 'Ship' when applicable that -details the type of suit you currently have equipped and its Loadout name. -This UI element is collapsed/hidden if no suit/on-foot state is detected, -i.e. not playing Odyssey (Alpha or otherwise). * Updated translations. Once more, thanks to all the translators! -* There is a new CL arg for EDMarketConnector.exe `--force-edmc-protocol`, but - this is really only of use to core developers (its purpose being to force - use of the edmc:// protocol for Frontier Auth callbacks, even when not +* We now sanity check a returned Frontier Authentication token to be sure + it's for the current Commander. If it's not you'll see + `Error: customer_id doesn't match!` on the bottom status line. Double-check + you're using the correct credentials when authing! + +* New 'Main window transparency' slider on `Settings` > `Appearance`. + +* New command-line argument for EDMarketConnector.exe `--reset-ui`. This will: + + 1. Reset to the default Theme. + 2. Reset the UI transparency to fully opaque. + + The intention is this can be used if you've lost sight of the main window + due to tweaking these options. + +* New CL arg for EDMarketConnector.exe `--force-edmc-protocol`. + This is really only of use to core developers (its purpose being to force + use of the edmc:// protocol for Frontier Auth callbacks, even when not 'frozen'). -* Slightly improve checking of old ship loadout files before writing a new one. - -* Linux config will be flushed to disk after any change. This means that - EDMC.py can now actually make use of the latest CAPI auth if it's been +* Linux config will be flushed to disk after any change. This means that + EDMC.py can now actually make use of the latest CAPI auth if it's been updated by EDMarketConnector.py since that started. -Plugin Developers ---- + If you want to run multiple instances of the application under Linux then + please check the updated [Troubleshooting: Multi-Accounting](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#multi-accounting) + wiki page. -We now have support for Odyssey Suits and their Loadouts. See PLUGINS.md -for details, particuarly the way in which `state[Suits]` might be either a -`list` or a `dict` and how to deal with that. -NB: This data is only guaranteed up to date and correct after a fresh CAPI -data pull, as the current Journal events don't allow for updating it on the -fly (this should change in a future Odyssey patch). - -Pre-Release 5.0.0-beta5 -=== - -* Ship Type/Name will now be greyed out, and not clickable, if we don't - currently have loadout information for it. This prevents trying to send an - empty loadout to your shipyard provider. - -* Sanity check a returned Frontier Authentication token to be sure it's for - the current Commander. If it's not you'll see `Error: customer_id doesn't - match!` on the bottom status line. Double-check you're using the correct - credentials when authing! - -* Bug fixed when handling CAPI-sourced shipyard information. This would - currently only have shown up on live for Fleet Carriers due to a Frontier - bug with not returning shipyard data at all for normal stations. - - It has been observed that Frontier has fixed this bug for Odyssey. - -* Don't try to get Ship information from `LoadGame` event if directly in CQC. - -* A lot of general code cleanup relating to: Inara, outfitting, Frontier - CAPI, hotkey (manual Updates), dashboard (Status.json monitoring), - commodities files, ED format ship loadout files. - -* Inara: Don't attempt to send an empty - `setCommanderReputationMajorFaction` API call. This quietens an error - from the Inara API caused when a Cmdr literally has no Major Faction - Reputation yet. - -Plugin Developers ---- - -* Initial support for new Odyssey "MicroResources" (Data, Item, Component - and Consumable) in the "Ship Locker" and "BackPack". NB: Currently the - `ShipLockerMaterials` event omits a `Data` array, so we can't properly - track those. - - See the updated PLUGINS.md for details about this in the `state` dictionary. - -Pre-Release 5.0.0-beta4 -=== - -* Now using Python 3.9.4. - -* Some initial support for things new in Odyssey has been added. We can - detect when you're on-foot and at a station, so as to leverage Frontier - CAPI to send data about the station to EDDN etc. - - **NB: Due to shortcomings in Journal support we can only detect your - 'station' location on orbital stations, and only when you first login - there, not for subsequent Disembarking at one, and not at all for surface - ports, let alone surface settlements.** - - More support, for things like the 'ShipLocker' inventory of all the new - materials, will be added in a subsequent beta. - -* A little TRACE logging output has been commented out for now. - -Plugin Developers ---- - -* All static data that is cleared for use by plugins is now in the file - `edmc_data.py` and should be imported from there, not *any* other module. - - The one thing we didn't move was the 'bracket map' dictionaries in td.py - as they're for use only by the code in that file. - - All future such data will be added to this file, and we'll endeavour not - to make breaking changes to any of it without increasing our Major version. - -* We now change the current working directory of EDMarketConnector.exe to - its location as soon as possible in its execution. We're also now more - paranoid about ensuring we reference the full path to the `.gitversion` file. - - However, no plugin should itself call `os.chdir(...)` or equivalent. You'll - change the current working directory for all core code and other plugins as - well (it's global to the whole **process**, not per-thread). Use full - absolute paths instead (`pathlib` is what to use for this) - - -Pre-Release 5.0.0-beta3 -=== - -This pre-release allows for using the application with the Odyssey Phase 1 -Alpha without constant complaints of 'Error: Frontier server is lagging'. -Work is on-going for supporting any new items and features in the Alpha, -but this application should now be usable with it. Please -[report](https://github.com/EDCD/EDMarketConnector/issues/new?assignees=&labels=bug%2C+unconfirmed&template=bug_report.md&title=) -any EDMC errors you experience! - -* Add support for detecting if a player is on-foot. This is then used to - prevent false 'Frontier server lagging' messages. - - Note that currently your on-foot location can only be detected when you - login, and not when you disembark from an Apex shuttle anywhere. - * Linux and macOS: You can now set a font name and size in your config file. - Ensuring this is a TTF font, rather than a bitmap font, should allow the + Ensuring this is a TTF font, rather than a bitmap font, should allow the application UI scaling to work. - - 1. 'font' - the font name to attempt using - 2. 'font_size' - the font size to attempt using. - + + 1. 'font' - the font name to attempt using + 2. 'font_size' - the font size to attempt using. + There is no UI for this in Preferences, you will need to edit your [config file](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#location-of-configuration-files) to set or change it, and then restart the application. - - This is not supported on Windows so as not to risk weird bugs. UI + + This is not supported on Windows so as not to risk weird bugs. UI Scaling works on Windows without this. - -* Code to do with processing Journal events was reworked and noisy logging - reduced as a consequence. - -Plugin Authors ---- -* The new materials added in Odyssey (for things like Suit and on-foot - Weapon upgrades) are now tracked in the `state['Component']` dictionary. - - NB: Only from the `MissionCompleted` event at this point, support still - needs adding for the `ShipLockerMaterials` event to synchronise totals at - login. - -* `companion.ship_map` was moved to `util_ships.ship_map` so as to avoid an - import loop from some other changes. - -Pre-Release 5.0.0-beta2 -=== - -* Support the 'JournalAlpha' files from the Odyssey Alpha. We've confirmed - any data from these is correctly tagged as 'beta' for the is_beta flag - passed to plugins. - - Any data from Odyssey Alpha is sent to EDDN using the test schemas. - - No data from Odyssey Alpha is sent to the EDSM or Inara APIs. - -* Fix ship loadout export to files to not trip up in the face of file encoding - issues. This relates to the 'Ship Loadout' option on the 'Output' tab of - Settings/Preferences. - -Plugin Authors ---- - -* `config.appversion()` now returns a `semantic_version.Version`. In contexts - where you're expecting a string this should mostly just work. If needs - be wrap it in a `str()`. - -* Example plugin - [plugintest](https://github.com/EDCD/EDMarketConnector/tree/main/docs/examples/plugintest) - updated. This includes an example of how to check core EDMC version if needs - be. This example is also in - [PLUGINS.md](https://github.com/EDCD/EDMarketConnector/blob/main/PLUGINS.md#checking-core-edmc-version). - -Pre-Release 5.0.0-beta1 -=== - -This release comes after some substantial code cleanup and is our first based -on Python 3.9 rather than 3.7. Other than what is noted in this changelog -it should have the same functionality as 4.2.4. - -* We are now testing and building with Python 3.9 (3.9.2 specifically at - this point). This should have no impact on users or plugin developers, other - than the latter now being free to use features that were introduced since the - Python 3.7 series. - - For developers you can check the contents of the `.python-version` file - in the source (it's not distributed with the Windows installer) for the - currently used version in a given branch. - -* We now also cite the git 'short hash' in the version string. For a Windows - install of the application this is sourced from the `.gitversion` file +* We now also cite the git 'short hash' in the version string. For a Windows + install of the application this is sourced from the `.gitversion` file (written during the build process). - + When running from source we attempt to use the command `git rev-parse --short HEAD` to obtain this. If this doesn't work it will be set to 'UNKNOWN'. -* New 'Main window transparency' slider on `Settings` > `Appearance`. - -* New command-line argument for EDMarketConnector.exe `--reset-ui`. This will: - - 1. Reset to the default Theme. - 2. Reset the UI transparency to fully opaque. - - The intention is this can be used if you've lost sight of the main window - due to tweaking these options. - * We have added a 'killswitch' feature to turn off specific functionality if it - is found to have a bug. An example use of this would be in an "oh - shit! we're sending bad data to EDDN!" moment so as to protect EDDN + is found to have a bug. An example use of this would be in an "oh + shit! we're sending bad data to EDDN!" moment so as to protect EDDN listeners such as EDDB. - - If we ever have to use this we'll announce it clearly and endeavour to - get a fixed version of the program released ASAP. We will **NOT** be + + If we ever have to use this we'll announce it clearly and endeavour to + get a fixed version of the program released ASAP. We will **NOT** be using this merely to try and get some laggards to upgrade. -* Our logging code will make best efforts to still show class name and - other such fields if it has trouble finding any of the required data for - the calling frame. This means no longer seeing `??:??:??` when there is +* Our logging code will make best efforts to still show class name and + other such fields if it has trouble finding any of the required data for + the calling frame. This means no longer seeing `??:??:??` when there is an issue with this. * macOS: We've managed to test the latest code on macOS Catalina. Other than [keyboard shortcut support not working](https://github.com/EDCD/EDMarketConnector/issues/906) it appears to be working. - -* We've pulled the latest Coriolis data which might have caused changes to + +* We've pulled the latest Coriolis data which might have caused changes to ship and module names as written out to some files. -Plugin Developers ------------------ +Odyssey +--- -* config.py has undergone a major rewrite. You should no longer be using - `config.get(...)` or `config.getint(...)`, which will both give a - deprecation warning. - Use instead the correct config.get_ function: - - * `config.get_list()` - * `config.get_str()` - * `config.get_bool()` - * `config.get_int()` - - Setting still uses `config.set(...)`. +This adds a new UI element 'Suit', below 'Ship' when applicable that +details the type of suit you currently have equipped and its Loadout name. +This UI element is collapsed/hidden if no suit/on-foot state is detected, +i.e. not playing Odyssey (Alpha or otherwise). -* The files `stations.p` and `systems.p` have been removed from the Windows - Installer. These were never intended for third-party use. Their core - code use was for generating EDDB-id links, but we long since changed the - EDDB plugin's handlers for that to use alternate URL formats based on - game IDs or names. - - If you were using either to lookup EDDB IDs for systems and/or stations - then please see how `system_url()` and `station_url` now work in - `plugins/eddb.py`. - - This change also removed the core (not plugin) `eddb.py` file which - generated these files. You can find it still in the git history if needs - be. It had gotten to the stage where generating `systems.p` took many - hours and required 64-bit Python to have any hope of working due to - memory usage. - -* Support has been added for the `NavRoute` (not `Route` as v28 of the - official Journal documentation erroneously labels it) Journal event and - its associated file `NavRoute.json`. See [PLUGINS.md:Events documentation](https://github.com/EDCD/EDMarketConnector/blob/main/PLUGINS.md#journal-entry) - -* Similarly there is now support for the `ModuleInfo` event and its - associated `ModulesInfo.json` file. +* More work has been done for Odyssey, with extra and expanded Journal + events now available. Suits and their Loadouts will track better now, + although we still require a CAPI data pull (an 'Update') to be guaranteed + data about them. + +* Some initial support for things new in Odyssey has been added. We can + detect when you're on-foot and at a station, so as to leverage Frontier + CAPI to send data about the station to EDDN etc. + + **NB: Due to shortcomings in Journal support we can only detect your + 'station' location on orbital stations, and only when you first login + there, not for subsequent Disembarking at one, and not at all for surface + ports, let alone surface settlements.** + + More support, for things like the 'ShipLocker' inventory of all the new + materials, will be added in a subsequent beta. + +* Add support for detecting if a player is on-foot. This is then used to + prevent false 'Frontier server lagging' messages. + + Note that currently your on-foot location can only be detected when you + login, and not when you disembark from an Apex shuttle anywhere. + +Bug Fixes +--- + +* Fix ship loadout export to files to not trip up in the face of file encoding + issues. This relates to the 'Ship Loadout' option on the 'Output' tab of + Settings/Preferences. + +* Ship Type/Name will now be greyed out, and not clickable, if we don't + currently have loadout information for it. This prevents trying to send an + empty loadout to your shipyard provider. + +* Bug fixed when handling CAPI-sourced shipyard information. This happens + due to a Frontier bug with not returning shipyard data at all for normal + stations. + + It has been observed that Frontier has fixed this bug for Odyssey. + +* Don't try to get Ship information from `LoadGame` event if directly in CQC. + +* Inara: Don't attempt to send an empty + `setCommanderReputationMajorFaction` API call. This quietens an error + from the Inara API caused when a Cmdr literally has no Major Faction + Reputation yet. Code Clean Up ------------- -* Some code to do with processing Journal events has been re-factored. +* Code pertaining to processing Journal events was reworked and noisy logging + reduced as a consequence. + +* A little TRACE logging output has been commented out for now. * The code for `File` > `Status` has been cleaned up. @@ -353,6 +169,128 @@ Code Clean Up * Code handling the Frontier Authorisation callback on Windows has been cleaned up. +* A lot of general code cleanup relating to: Inara, outfitting, Frontier + CAPI, hotkey (manual Updates), dashboard (Status.json monitoring), + commodities files, and ED format ship loadout files. + +Plugin Developers +--- + +* The files `stations.p` and `systems.p` have been removed from the Windows + Installer. These were never intended for third-party use. Their core + code use was for generating EDDB-id URLs, but we long since changed the + EDDB plugin's handlers for that to use alternate URL formats based on + game IDs or names. + + If you were using either to lookup EDDB IDs for systems and/or stations + then please see how `system_url()` and `station_url` now work in + `plugins/eddb.py`. + + This change also removed the core (not plugin) `eddb.py` file which + generated these files. You can find it still in the git history if needs + be. It had gotten to the stage where generating `systems.p` took many + hours and required 64-bit Python to have any hope of working due to + memory usage. + +* All static data that is cleared for use by plugins is now in the file + `edmc_data.py` and should be imported from there, not *any* other module. + + The one thing we didn't move was the 'bracket map' dictionaries in `td.py` + as they're for use only by the code in that file. + + All future such data will be added to this file, and we'll endeavour not + to make breaking changes to any of it without increasing our Major version. + +* `config.appversion()` is now a function that returns a `semantic_version.Version`. + In contexts where you're expecting a string this should mostly + just work. If needs be wrap it in `str()`. + +* Example plugin + [plugintest](https://github.com/EDCD/EDMarketConnector/tree/main/docs/examples/plugintest) + updated. This includes an example of how to check core EDMC version if needs + be. This example is also in + [PLUGINS.md](https://github.com/EDCD/EDMarketConnector/blob/main/PLUGINS.md#checking-core-edmc-version). + +* `config.py` has undergone a major rewrite. You should no longer be using + `config.get(...)` or `config.getint(...)`, which will both give a + deprecation warning. + Use instead the correct `config.get_()` function: + + * `config.get_list()` + * `config.get_str()` + * `config.get_bool()` + * `config.get_int()` + + Setting still uses `config.set(...)`. + +* We now change the current working directory of EDMarketConnector.exe to + its location as soon as possible in its execution. We're also + paranoid about ensuring we reference the full path to the `.gitversion` file. + + However, no plugin should itself call `os.chdir(...)` or equivalent. You'll + change the current working directory for all core code and other plugins as + well (it's global to the whole **process**, not per-thread). Use full + absolute paths instead (`pathlib` is what to use for this) + +* The `state` passed to plugins in `journal_entry()` calls (which is + actually `monitor.state` in the core code) has received many additions + relating to Odyssey, as well as other fixes and enhancements. + + 1. Support has been added for the `NavRoute` (not `Route` as v28 of the + official Journal documentation erroneously labels it) Journal event and + its associated file `NavRoute.json`. See [PLUGINS.md:Events documentation](https://github.com/EDCD/EDMarketConnector/blob/main/PLUGINS.md#journal-entry) + + 1. Similarly, there is now support for the `ModuleInfo` event and its + associated `ModulesInfo.json` file. + + 1. `state['Credits']` - until now no effort was made to keep this + record of the credits balance up to date after the initial `LoadGame` + event. This has now been addressed, and the balance should stay in sync + as best it can from the available Journal events. It will always correct + back to the actual balance on each CAPI data pull or game relog/restart. + + 1. `state['Cargo']` now takes account of any `CargoTransfer` events. + This was added to the game in the Fleet Carriers update, but also covers + transfers to/from an SRV. + + 1. `state['OnFoot']` is a new boolean, set true whenever we detect + the Cmdr is on-foot, i.e. not in any type of vehicle (Cmdr's own ship, + multi-crew in another Cmdr's ship, Apex taxi, or a Dropship). + + 1. `state['Suits']` and `state['SuitLoadouts']` added as `dict`s containing + information about the Cmdr's owned Suits and the Loadouts the Cmdr has + defined to utilise them (and on-foot weapons). + Note that in the raw CAPI data these are arrays if all members + contiguously exist, else a dictionary, but we have chosen to always coerce + these to a python `dict` for simplicity. They will be empty `dict`s, not + `None` if there is no data. + The `id` field found on e.g. weapon details in suit loadouts may be `None` + if we got the data from the Journal rather than the CAPI data. + NB: This data is only guaranteed up to date and correct after a fresh CAPI + data pull, as the current Journal events don't allow for updating it on the + fly (this should change in a future Odyssey patch). + + 1. `state['SuitCurrent']` and `state['SuitLoadoutCurrent']` contain the + obvious "currently in use" data as per the Suits/SuitLoadouts. + + 1. Tracking of the new Odyssey 'Microresources' has been added: + 1. `Component` - `dict` for 'Ship Locker' inventory. + 1. `Item` - `dict` for 'Ship Locker' inventory. + 1. `Consumable` - `dict` for 'Ship Locker' inventory. + 1. `Data` - `dict` for 'Ship Locker' inventory. + 1. `BackPack` - on-foot inventory, a `dict` containing again + dicts for `Component`, `Item`, `Consumable` and `Data`. + However note that the lack of a Journal event when throwing a grenade, + along with no `BackPackMaterials` event if logging in on-foot means that + we can't track the BackPack inventory perfectly. + + See the updated `PLUGINS.md` file for details. + +* Note that during the Odyssey Alpha it was observed that the CAPI `data['commander']['docked']` + boolean was **always true** if the Cmdr was in their ship. This is a + regression from pre-Odyssey behaviour. The core EDMC code copes with + this. + Release 4.2.7 === From 3e7ffaacf52bce903268c66b53c7808f153bf1a4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 7 May 2021 20:09:56 +0100 Subject: [PATCH 693/727] ChangeLog: Cleanup up Odyssey section & misc tweaks. --- ChangeLog.md | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index b7bb026f..7b941d82 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -46,7 +46,7 @@ Changes and Enhancements * New CL arg for EDMarketConnector.exe `--force-edmc-protocol`. This is really only of use to core developers (its purpose being to force - use of the edmc:// protocol for Frontier Auth callbacks, even when not + use of the `edmc://` protocol for Frontier Auth callbacks, even when not 'frozen'). * Linux config will be flushed to disk after any change. This means that @@ -102,33 +102,22 @@ Changes and Enhancements Odyssey --- -This adds a new UI element 'Suit', below 'Ship' when applicable that -details the type of suit you currently have equipped and its Loadout name. -This UI element is collapsed/hidden if no suit/on-foot state is detected, -i.e. not playing Odyssey (Alpha or otherwise). +* A new UI element 'Suit' now appears below 'Ship' when applicable. It + details the type of suit you currently have equipped and its Loadout name. + This UI element is collapsed/hidden if no suit/on-foot state is detected, + e.g. not playing Odyssey. -* More work has been done for Odyssey, with extra and expanded Journal - events now available. Suits and their Loadouts will track better now, - although we still require a CAPI data pull (an 'Update') to be guaranteed - data about them. - -* Some initial support for things new in Odyssey has been added. We can - detect when you're on-foot and at a station, so as to leverage Frontier - CAPI to send data about the station to EDDN etc. - - **NB: Due to shortcomings in Journal support we can only detect your - 'station' location on orbital stations, and only when you first login - there, not for subsequent Disembarking at one, and not at all for surface - ports, let alone surface settlements.** - - More support, for things like the 'ShipLocker' inventory of all the new - materials, will be added in a subsequent beta. - -* Add support for detecting if a player is on-foot. This is then used to - prevent false 'Frontier server lagging' messages. - - Note that currently your on-foot location can only be detected when you - login, and not when you disembark from an Apex shuttle anywhere. +* Note that we can only reliably know about Suits and their Loadouts from a + CAPI data pull (which is what we do automatically on docking if + configured to do so, or when you press the 'Update' button). We do + attempt to gather this data from Journal events as well, but if you + switch to a Suit Loadout that hasn't been mentioned in them yet we won't + be able to display that until the next CAPI data pull. + +If anyone becomes aware of a 'suit loadouts' site/tool, a la Coriolis/EDSY +but for Odyssey Suits, do let us know so we can add support for it! +We're already kicking around ideas to e.g. place JSON text in the clipboard +if the Suit Loadout is clicked. Bug Fixes --- @@ -232,7 +221,7 @@ Plugin Developers well (it's global to the whole **process**, not per-thread). Use full absolute paths instead (`pathlib` is what to use for this) -* The `state` passed to plugins in `journal_entry()` calls (which is +* The `state` dict passed to plugins in `journal_entry()` calls (which is actually `monitor.state` in the core code) has received many additions relating to Odyssey, as well as other fixes and enhancements. From 7b8ba8a5a6e9c98c2a209b544b002a573e357580 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 7 May 2021 20:12:21 +0100 Subject: [PATCH 694/727] ChangeLog: Leading blurb on Odyssey section --- ChangeLog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 7b941d82..4806b0e5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -102,6 +102,12 @@ Changes and Enhancements Odyssey --- +Every effort was made during the Odyssey Alphas to ensure that this +application will continue to function correctly with it. As always, make a +[Bug Report](https://github.com/EDCD/EDMarketConnector/issues/new?assignees=&labels=bug%2C+unconfirmed&template=bug_report.md&title=) +if you find anything not working, but be sure to check our +[Known Issues](https://github.com/EDCD/EDMarketConnector/issues/618) first. + * A new UI element 'Suit' now appears below 'Ship' when applicable. It details the type of suit you currently have equipped and its Loadout name. This UI element is collapsed/hidden if no suit/on-foot state is detected, From b1dc984e3278ff727e4266c2d3a99bda21c0d550 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 7 May 2021 20:48:06 +0100 Subject: [PATCH 695/727] ChangeLog: wiki entry, not page & linkify plugin available imports --- ChangeLog.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4806b0e5..a187d22d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -55,7 +55,7 @@ Changes and Enhancements If you want to run multiple instances of the application under Linux then please check the updated [Troubleshooting: Multi-Accounting](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#multi-accounting) - wiki page. + wiki entry. * Linux and macOS: You can now set a font name and size in your config file. Ensuring this is a TTF font, rather than a bitmap font, should allow the @@ -187,7 +187,9 @@ Plugin Developers hours and required 64-bit Python to have any hope of working due to memory usage. -* All static data that is cleared for use by plugins is now in the file +* All static data that is + [cleared for use by plugins](https://github.com/EDCD/EDMarketConnector/blob/main/PLUGINS.md#available-imports) + is now in the file `edmc_data.py` and should be imported from there, not *any* other module. The one thing we didn't move was the 'bracket map' dictionaries in `td.py` From d7c63c35c33a64409671132f86c71b5a5acadf35 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 8 May 2021 10:10:22 +0100 Subject: [PATCH 696/727] ChangeLog: Linkify python 3.9.x not supporting Windows 7. --- ChangeLog.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index a187d22d..818e8404 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,9 +9,10 @@ Python 3.9 * We now test against, and package with, Python 3.9.5. **As a consequence of this we no longer support Windows 7. - This is due to Python 3.9.x itself not supporting Windows 7. The - application (both EDMarketConnector.exe and EDMC.exe) will crash on startup - due to a missing DLL.** + This is due to + [Python 3.9.x itself not supporting Windows 7](https://www.python.org/downloads/windows/). + The application (both EDMarketConnector.exe and EDMC.exe) will crash on + startup due to a missing DLL.** This should have no other impact on users or plugin developers, other than the latter now being free to use features that were introduced since the From 2d423347552a42682b563c7cea22c89f18b0955c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 8 May 2021 10:32:47 +0100 Subject: [PATCH 697/727] ChangeLog: Misc tweaks: * () on `station_url` (and tweak earlier grammar). * Missing full stop. * Mention SRV as "not on foot" as well. * Suits/Loadouts use CAPI key names, nor Journal ones. * Link to issue about Odyssey CAPI data['commander']['docked'] always being true if not on foot. --- ChangeLog.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 818e8404..7c0d4264 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -173,13 +173,13 @@ Plugin Developers --- * The files `stations.p` and `systems.p` have been removed from the Windows - Installer. These were never intended for third-party use. Their core - code use was for generating EDDB-id URLs, but we long since changed the + Installer. These were never intended for third-party use. Their use in + core code was for generating EDDB-id URLs, but we long since changed the EDDB plugin's handlers for that to use alternate URL formats based on game IDs or names. If you were using either to lookup EDDB IDs for systems and/or stations - then please see how `system_url()` and `station_url` now work in + then please see how `system_url()` and `station_url()` now work in `plugins/eddb.py`. This change also removed the core (not plugin) `eddb.py` file which @@ -228,7 +228,7 @@ Plugin Developers However, no plugin should itself call `os.chdir(...)` or equivalent. You'll change the current working directory for all core code and other plugins as well (it's global to the whole **process**, not per-thread). Use full - absolute paths instead (`pathlib` is what to use for this) + absolute paths instead (`pathlib` is what to use for this). * The `state` dict passed to plugins in `journal_entry()` calls (which is actually `monitor.state` in the core code) has received many additions @@ -253,7 +253,7 @@ Plugin Developers 1. `state['OnFoot']` is a new boolean, set true whenever we detect the Cmdr is on-foot, i.e. not in any type of vehicle (Cmdr's own ship, - multi-crew in another Cmdr's ship, Apex taxi, or a Dropship). + SRV, multi-crew in another Cmdr's ship, Apex taxi, or a Dropship). 1. `state['Suits']` and `state['SuitLoadouts']` added as `dict`s containing information about the Cmdr's owned Suits and the Loadouts the Cmdr has @@ -262,6 +262,8 @@ Plugin Developers contiguously exist, else a dictionary, but we have chosen to always coerce these to a python `dict` for simplicity. They will be empty `dict`s, not `None` if there is no data. + We use the CAPI data names for keys, not the Journal ones - e.g. `slots` + for weapons equipped, not `Modules`. The `id` field found on e.g. weapon details in suit loadouts may be `None` if we got the data from the Journal rather than the CAPI data. NB: This data is only guaranteed up to date and correct after a fresh CAPI @@ -284,10 +286,12 @@ Plugin Developers See the updated `PLUGINS.md` file for details. -* Note that during the Odyssey Alpha it was observed that the CAPI `data['commander']['docked']` - boolean was **always true** if the Cmdr was in their ship. This is a - regression from pre-Odyssey behaviour. The core EDMC code copes with - this. +* Note that during the Odyssey Alpha it was observed that the CAPI + `data['commander']['docked']` boolean was **always true** if the Cmdr was + in their ship. This is a regression from pre-Odyssey behaviour. The + core EDMC code copes with this. Please add a reproduction to the issue + about this: + [PTS CAPI saying Commander is Docked after jumping to new system](https://issues.frontierstore.net/issue-detail/28638). Release 4.2.7 === From aaf1fda1a102d9196b2016b5219394bbf25bc88c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 8 May 2021 19:25:38 +0100 Subject: [PATCH 698/727] Credits: Be paranoid about all related Journal events MissionCompleted doesn't contain 'Reward' if you pick an option without a credits amount (rather than being there but with zero value). Let's not wait to find out about other exceptions, just utilise entry.get(, 0) on them all. --- monitor.py | 73 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/monitor.py b/monitor.py index f1faeb18..7ecddcb5 100644 --- a/monitor.py +++ b/monitor.py @@ -552,7 +552,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Rebuy'] = None self.state['Modules'] = None - self.state['Credits'] -= entry['ShipPrice'] + self.state['Credits'] -= entry.get('ShipPrice', 0) elif event_type == 'ShipyardSwap': self.state['ShipID'] = entry['ShipID'] @@ -604,17 +604,17 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Value': entry['BuyPrice'], } - self.state['Credits'] -= entry['BuyPrice'] + self.state['Credits'] -= entry.get('BuyPrice', 0) elif event_type == 'ModuleRetrieve': self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'ModuleSell': self.state['Modules'].pop(entry['Slot'], None) - self.state['Credits'] += entry['SellPrice'] + self.state['Credits'] += entry.get('SellPrice', 0) elif event_type == 'ModuleSellRemote': - self.state['Credits'] += entry['SellPrice'] + self.state['Credits'] += entry.get('SellPrice', 0) elif event_type == 'ModuleStore': self.state['Modules'].pop(entry['Slot'], None) @@ -870,11 +870,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below name = self.canonicalise(entry['Name']) self.state[category][name] += entry['Count'] - self.state['Credits'] -= entry['Price'] + self.state['Credits'] -= entry.get('Price', 0) elif event_type == 'SellMicroResources': # Selling to a Bar Tender on-foot. - self.state['Credits'] += entry['Price'] + self.state['Credits'] += entry.get('Price', 0) # One event per whole sale, so it's an array. for mr in entry['MicroResources']: category = self.category(mr['Category']) @@ -1197,10 +1197,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif event_type == 'SellOrganicData': for bd in entry['BioData']: - self.state['Credits'] += bd['Value'] + bd['Bonus'] + self.state['Credits'] += bd.get('Value', 0) + bd.get('Bonus', 0) elif event_type == 'BookDropship': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) # Technically we *might* now not be OnFoot. # The problem is that this event is recorded both for signing up for # an on-foot CZ, and when you use the Dropship to return after the @@ -1213,13 +1213,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # event is going to be Disembark to on-foot anyway. elif event_type == 'BookTaxi': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'CancelDropship': - self.state['Credits'] += entry['Refund'] + self.state['Credits'] += entry.get('Refund', 0) elif event_type == 'CancelTaxi': - self.state['Credits'] += entry['Refund'] + self.state['Credits'] += entry.get('Refund', 0) elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json @@ -1249,10 +1249,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below self.state['Cargo'][commodity] += entry.get('Count', 1) if event_type == 'BuyDrones': - self.state['Credits'] -= entry['TotalCost'] + self.state['Credits'] -= entry.get('TotalCost', 0) elif event_type == 'MarketBuy': - self.state['Credits'] -= entry['TotalCost'] + self.state['Credits'] -= entry.get('TotalCost', 0) elif event_type in ('EjectCargo', 'MarketSell', 'SellDrones'): commodity = self.canonicalise(entry['Type']) @@ -1262,10 +1262,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below cargo.pop(commodity) if event_type == 'MarketSell': - self.state['Credits'] += entry['TotalSale'] + self.state['Credits'] += entry.get('TotalSale', 0) elif event_type == 'SellDrones': - self.state['Credits'] += entry['TotalSale'] + self.state['Credits'] += entry.get('TotalSale', 0) elif event_type == 'SearchAndRescue': for item in entry.get('Items', []): @@ -1348,7 +1348,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below module['Engineering'].pop('ExperimentalEffect_Localised', None) elif event_type == 'MissionCompleted': - self.state['Credits'] += entry['Reward'] + self.state['Credits'] += entry.get('Reward', 0) for reward in entry.get('CommodityReward', []): commodity = self.canonicalise(reward['Name']) @@ -1435,74 +1435,75 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Try to keep Credits total updated elif event_type in ('MultiSellExplorationData', 'SellExplorationData'): - self.state['Credits'] += entry['TotalEarnings'] + self.state['Credits'] += entry.get('TotalEarnings', 0) elif event_type == 'BuyExplorationData': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'BuyTradeData': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'BuyAmmo': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'CommunityGoalReward': - self.state['Credits'] += entry['Reward'] + self.state['Credits'] += entry.get('Reward', 0) elif event_type == 'CrewHire': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'FetchRemoteModule': - self.state['Credits'] -= entry['TransferCost'] + self.state['Credits'] -= entry.get('TransferCost', 0) elif event_type == 'MissionAbandoned': # Is this paid at this point, or just a fine to pay later ? - # self.state['Credits'] -= entry['Fine'] + # self.state['Credits'] -= entry.get('Fine', 0) pass elif event_type in ('PayBounties', 'PayFines', 'PayLegacyFines'): - self.state['Credits'] -= entry['Amount'] + self.state['Credits'] -= entry.get('Amount', 0) elif event_type == 'RedeemVoucher': - self.state['Credits'] += entry['Amount'] + self.state['Credits'] += entry.get('Amount', 0) elif event_type in ('RefuelAll', 'RefuelPartial', 'Repair', 'RepairAll', 'RestockVehicle'): - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'SellShipOnRebuy': - self.state['Credits'] += entry['ShipPrice'] + self.state['Credits'] += entry.get('ShipPrice', 0) elif event_type == 'ShipyardSell': - self.state['Credits'] += entry['ShipPrice'] + self.state['Credits'] += entry.get('ShipPrice', 0) elif event_type == 'ShipyardTransfer': - self.state['Credits'] -= entry['TransferPrice'] + self.state['Credits'] -= entry.get('TransferPrice', 0) elif event_type == 'PowerplayFastTrack': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) elif event_type == 'PowerplaySalary': - self.state['Credits'] += entry['Amount'] + self.state['Credits'] += entry.get('Amount', 0) elif event_type == 'SquadronCreated': # v30 docs don't actually say anything about credits cost pass elif event_type == 'CarrierBuy': - self.state['Credits'] -= entry['Price'] + self.state['Credits'] -= entry.get('Price', 0) elif event_type == 'CarrierBankTransfer': - self.state['Credits'] = entry['PlayerBalance'] + if (newbal := entry.get('PlayerBalance')): + self.state['Credits'] = newbal elif event_type == 'CarrierDecommission': # v30 doc says nothing about citing the refund amount pass elif event_type == 'NpcCrewPaidWage': - self.state['Credits'] -= entry['Amount'] + self.state['Credits'] -= entry.get('Amount', 0) elif event_type == 'Resurrect': - self.state['Credits'] -= entry['Cost'] + self.state['Credits'] -= entry.get('Cost', 0) return entry From 316bbba99d6a66de46f151c429ecc5bc78018fe0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 9 May 2021 10:29:50 +0100 Subject: [PATCH 699/727] edmc_data: Add Status.json flags2 constants --- edmc_data.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/edmc_data.py b/edmc_data.py index 61c72bd2..be1db743 100644 --- a/edmc_data.py +++ b/edmc_data.py @@ -416,6 +416,20 @@ FlagsAverageAltitude = 1 << 29 # Altitude from Average radius FlagsFsdJump = 1 << 30 FlagsSrvHighBeam = 1 << 31 +# Status.json / Dashboard flags2 +Flags2OnFoot = 1 << 0 +Flags2InTaxi = 1 << 1 # (or dropship/shuttle) +Flags2InMulticrew = 1 << 2 # (ie in someone else’s ship) +Flags2OnFootInStation = 1 << 3 +Flags2OnFootOnPlanet = 1 << 4 +Flags2AimDownSight = 1 << 5 +Flags2LowOxygen = 1 << 6 +Flags2LowHealth = 1 << 7 +Flags2Cold = 1 << 8 +Flags2Hot = 1 << 9 +Flags2VeryCold = 1 << 10 +Flags2VeryHot = 1 << 11 + # Dashboard GuiFocus constants GuiFocusNoFocus = 0 GuiFocusInternalPanel = 1 # right hand side From 63a0456a9ff6bea15afc24fbcf816c37fc9ec5f1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 9 May 2021 10:32:58 +0100 Subject: [PATCH 700/727] PLUGINS.md: Fix Flags to reference `edmc_data`, not `plug`. --- PLUGINS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 664ccce7..a438b8fd 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -674,7 +674,7 @@ before returning from this function. import plug def dashboard_entry(cmdr: str, is_beta: bool, entry: Dict[str, Any]): - is_deployed = entry['Flags'] & plug.FlagsHardpointsDeployed + is_deployed = entry['Flags'] & edmc_data.FlagsHardpointsDeployed sys.stderr.write("Hardpoints {}\n".format(is_deployed and "deployed" or "stowed")) ``` @@ -693,7 +693,7 @@ typically about once a second when in orbital flight. For more info on `Status.json`, See the "Status File" section in the Frontier [Journal documentation](https://forums.frontier.co.uk/showthread.php/401661). That includes the available `entry` properties and the list of `"Flags"`. -Refer to the source code of [plug.py](./plug.py) for the list of available +Refer to [edmc_data.py](./edmc_data.py) for the list of available constants. --- From 8abaa2674a326345e3fbaf00993f8940710cf534 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 07:15:42 +0000 Subject: [PATCH 701/727] build(deps-dev): bump flake8 from 3.9.1 to 3.9.2 Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.9.1 to 3.9.2. - [Release notes](https://gitlab.com/pycqa/flake8/tags) - [Commits](https://gitlab.com/pycqa/flake8/compare/3.9.1...3.9.2) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 59ed55b7..aa0f574b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ wheel # Static analysis tools -flake8==3.9.1 +flake8==3.9.2 flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 flake8-comprehensions==3.4.0 From 92e580e0c7a8f6db294c3959b5bfbb3fab1ca6c5 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 10 May 2021 15:24:26 +0200 Subject: [PATCH 702/727] Fixed error when logging out of a class var This also adds an insane amount of paranoia around getting SOMETHING dumped when an exception happens. Fixes #1044 --- EDMCLogging.py | 127 +++++++++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 52 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index d4836ad6..93f0b1c5 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -41,10 +41,12 @@ import logging.handlers import os import pathlib import tempfile +from contextlib import suppress # So that any warning about accessing a protected member is only in one place. from sys import _getframe as getframe from threading import get_native_id as thread_native_id from typing import TYPE_CHECKING, Tuple, cast +from traceback import print_exc from config import appcmdname, appname, config @@ -85,7 +87,10 @@ logging.Logger.trace = lambda self, message, *args, **kwargs: self._log( # type ) if TYPE_CHECKING: + from types import FrameType + # Fake type that we can use here to tell type checkers that trace exists + class LoggerMixin(logging.Logger): """LoggerMixin is a fake class that tells type checkers that trace exists on a given type.""" @@ -318,65 +323,83 @@ class EDMCContextFilter(logging.Filter): # We've given up, so just return '??' to signal we couldn't get the info return '??', '??', module_name + try: + args, _, _, value_dict = inspect.getargvalues(frame) + if len(args) and args[0] in ('self', 'cls'): + frame_class: 'object' = value_dict[args[0]] - args, _, _, value_dict = inspect.getargvalues(frame) - if len(args) and args[0] in ('self', 'cls'): - frame_class: 'object' = value_dict[args[0]] + if frame_class: + # See https://en.wikipedia.org/wiki/Name_mangling#Python for how name mangling works. + # For more detail, see _Py_Mangle in CPython's Python/compile.c. + name = frame_info.function + class_name = frame_class.__class__.__name__.lstrip("_") + if name.startswith("__") and not name.endswith("__") and class_name: + name = f'_{class_name}{frame_info.function}' - if frame_class: - # See https://en.wikipedia.org/wiki/Name_mangling#Python for how name mangling works. - # For more detail, see _Py_Mangle in CPython's Python/compile.c. - name = frame_info.function - class_name = frame_class.__class__.__name__.lstrip("_") - if name.startswith("__") and not name.endswith("__") and class_name: - name = f'_{class_name}{frame_info.function}' + # Find __qualname__ of the caller + fn = inspect.getattr_static(frame_class, name, None) + if fn is None: + # For some reason getattr_static cant grab this. Try and grab it with getattr, bail out + # if we get a RecursionError indicating a property + try: + fn = getattr(frame_class, name, None) + except RecursionError: + print( + "EDMCLogging:EDMCContextFilter:caller_attributes():" + "Failed to get attribute for function info. Bailing out" + ) + # class_name is better than nothing for __qualname__ + return class_name, class_name, module_name - # Find __qualname__ of the caller - fn = inspect.getattr_static(frame_class, name, None) - if fn is None: - # For some reason getattr_static cant grab this. Try and grab it with getattr, bail out - # if we get a RecursionError indicating a property - try: - fn = getattr(frame_class, name, None) - except RecursionError: - print( - "EDMCLogging:EDMCContextFilter:caller_attributes():" - "Failed to get attribute for function info. Bailing out" - ) - # class_name is better than nothing for __qualname__ - return class_name, class_name, module_name + if fn is not None: + if isinstance(fn, property): + class_name = str(frame_class) + # If somehow you make your __class__ or __class__.__qualname__ recursive, + # I'll be impressed. + if hasattr(frame_class, '__class__') and hasattr(frame_class.__class__, "__qualname__"): + class_name = frame_class.__class__.__qualname__ + caller_qualname = f"{class_name}.{name}(property)" - if fn is not None: - if isinstance(fn, property): - class_name = str(frame_class) - # If somehow you make your __class__ or __class__.__qualname__ recursive, I'll be impressed. - if hasattr(frame_class, '__class__') and hasattr(frame_class.__class__, "__qualname__"): - class_name = frame_class.__class__.__qualname__ - caller_qualname = f"{class_name}.{name}(property)" + else: + caller_qualname = f"" - else: - caller_qualname = f"" + elif hasattr(fn, '__qualname__') and fn.__qualname__: + caller_qualname = fn.__qualname__ - elif fn.__qualname__: - caller_qualname = fn.__qualname__ + # Find containing class name(s) of caller, if any + if ( + frame_class.__class__ and hasattr(frame_class.__class__, '__qualname__') + and frame_class.__class__.__qualname__ + ): + caller_class_names = frame_class.__class__.__qualname__ - # Find containing class name(s) of caller, if any - if frame_class.__class__ and frame_class.__class__.__qualname__: - caller_class_names = frame_class.__class__.__qualname__ + # It's a call from the top level module file + elif frame_info.function == '': + caller_class_names = '' + caller_qualname = value_dict['__name__'] - # It's a call from the top level module file - elif frame_info.function == '': - caller_class_names = '' - caller_qualname = value_dict['__name__'] + elif frame_info.function != '': + caller_class_names = '' + caller_qualname = frame_info.function - elif frame_info.function != '': - caller_class_names = '' - caller_qualname = frame_info.function + module_name = cls.munge_module_name(frame_info, module_name) - module_name = cls.munge_module_name(frame_info, module_name) + except Exception as e: + print("ALERT! Something went VERY wrong in handling finding info to log") + print("ALERT! Information is as follows") + with suppress(Exception): - # https://docs.python.org/3.7/library/inspect.html#the-interpreter-stack - del frame + print(f"ALERT! {e=}") + print_exc() + print(f"ALERT! {frame=}") + with suppress(Exception): + print(f"ALERT! {fn=}") # type: ignore + with suppress(Exception): + print(f"ALERT! {cls=}") + + finally: # Ensure this always happens + # https://docs.python.org/3.7/library/inspect.html#the-interpreter-stack + del frame if caller_qualname == '': print('ALERT! Something went wrong with finding caller qualname for logging!') @@ -398,19 +421,19 @@ class EDMCContextFilter(logging.Filter): # Go up through stack frames until we find the first with a # type(f_locals.self) of logging.Logger. This should be the start # of the frames internal to logging. - frame: 'frame' = getframe(0) + frame: 'FrameType' = getframe(0) while frame: if isinstance(frame.f_locals.get('self'), logging.Logger): - frame = frame.f_back # Want to start on the next frame below + frame = cast('FrameType', frame.f_back) # Want to start on the next frame below break - frame = frame.f_back + frame = cast('FrameType', frame.f_back) # Now continue up through frames until we find the next one where # that is *not* true, as it should be the call site of the logger # call while frame: if not isinstance(frame.f_locals.get('self'), logging.Logger): break # We've found the frame we want - frame = frame.f_back + frame = cast('FrameType', frame.f_back) return frame @classmethod From 36ccead469c221d83166ee91e18c3484a300fee3 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 10 May 2021 15:29:04 +0200 Subject: [PATCH 703/727] added test for classvar logging --- tests/EDMCLogging.py/test_logging_classvar.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/EDMCLogging.py/test_logging_classvar.py diff --git a/tests/EDMCLogging.py/test_logging_classvar.py b/tests/EDMCLogging.py/test_logging_classvar.py new file mode 100644 index 00000000..9cd68b64 --- /dev/null +++ b/tests/EDMCLogging.py/test_logging_classvar.py @@ -0,0 +1,44 @@ +import sys + +sys.path += "../" # Dont ask me why for this one it breaks, it just does. +from typing import TYPE_CHECKING # noqa: E402 + +from EDMCLogging import get_plugin_logger # noqa: E402 + +if TYPE_CHECKING: + from _pytest.logging import LogCaptureFixture + +logger = get_plugin_logger('EDMCLogging.py') + + +class ClassVarLogger: + """Test class with logger attached.""" + + @classmethod + def set_logger(cls, logger): + """Set the passed logger onto the _class_.""" + ClassVarLogger.logger = logger + + +def log_stuff(msg: str): + """Wrapper logger func.""" + ClassVarLogger.logger.debug(msg) # type: ignore # its there + + +def test_class_logger(caplog: 'LogCaptureFixture'): + """ + Test that logging from a class variable doesn't explode. + + In writting a plugin that uses a class variable to hold the logger, EDMCLoggings cleverness to extract data + regarding the qualified name of a function falls flat, as a class variable does not have a qualname, and at the time + we did not check for its existence before using it. + """ + ClassVarLogger.set_logger(logger) + ClassVarLogger.logger.debug('test') # type: ignore # its there + ClassVarLogger.logger.info('test2') # type: ignore # its there + log_stuff('test3') # type: ignore # its there + + # Dont move these, it relies on the line numbres. + assert 'EDMarketConnector.EDMCLogging.py:test_logging_classvar.py:37 test' in caplog.text + assert 'EDMarketConnector.EDMCLogging.py:test_logging_classvar.py:38 test2' in caplog.text + assert 'EDMarketConnector.EDMCLogging.py:test_logging_classvar.py:25 test3' in caplog.text From 5fea307fd7de3e2635d8379db658acba9c932af8 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 10 May 2021 15:30:47 +0200 Subject: [PATCH 704/727] Fixed quotes --- EDMCLogging.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 93f0b1c5..4aa3d0c7 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -385,17 +385,17 @@ class EDMCContextFilter(logging.Filter): module_name = cls.munge_module_name(frame_info, module_name) except Exception as e: - print("ALERT! Something went VERY wrong in handling finding info to log") - print("ALERT! Information is as follows") + print('ALERT! Something went VERY wrong in handling finding info to log') + print('ALERT! Information is as follows') with suppress(Exception): - print(f"ALERT! {e=}") + print(f'ALERT! {e=}') print_exc() - print(f"ALERT! {frame=}") + print(f'ALERT! {frame=}') with suppress(Exception): - print(f"ALERT! {fn=}") # type: ignore + print(f'ALERT! {fn=}') # type: ignore with suppress(Exception): - print(f"ALERT! {cls=}") + print(f'ALERT! {cls=}') finally: # Ensure this always happens # https://docs.python.org/3.7/library/inspect.html#the-interpreter-stack From 71f2246cf41494a7257813b1586418e34609bc95 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 10 May 2021 15:34:02 +0200 Subject: [PATCH 705/727] Missed an import --- EDMCLogging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 4aa3d0c7..3376cbbe 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -45,8 +45,8 @@ from contextlib import suppress # So that any warning about accessing a protected member is only in one place. from sys import _getframe as getframe from threading import get_native_id as thread_native_id -from typing import TYPE_CHECKING, Tuple, cast from traceback import print_exc +from typing import TYPE_CHECKING, Tuple, cast from config import appcmdname, appname, config From 4db654226913e5efa3a5d2a6b7952cd533aaaa07 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 10 May 2021 15:22:56 +0100 Subject: [PATCH 706/727] EDMCLogging: No fn.__qualname__ ? Just use `name`. --- EDMCLogging.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EDMCLogging.py b/EDMCLogging.py index 3376cbbe..6633064e 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -363,6 +363,9 @@ class EDMCContextFilter(logging.Filter): else: caller_qualname = f"" + elif not hasattr(fn, '__qualname__'): + caller_qualname = name + elif hasattr(fn, '__qualname__') and fn.__qualname__: caller_qualname = fn.__qualname__ From bf54af721180fe5c5abd85f463cd091970f71712 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 10 May 2021 15:34:49 +0100 Subject: [PATCH 707/727] Lint new EDMCLogging test --- tests/EDMCLogging.py/test_logging_classvar.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/EDMCLogging.py/test_logging_classvar.py b/tests/EDMCLogging.py/test_logging_classvar.py index 9cd68b64..3bedb0f5 100644 --- a/tests/EDMCLogging.py/test_logging_classvar.py +++ b/tests/EDMCLogging.py/test_logging_classvar.py @@ -1,3 +1,4 @@ +"""Test that logging works correctly from a class-definition caller.""" import sys sys.path += "../" # Dont ask me why for this one it breaks, it just does. @@ -15,17 +16,17 @@ class ClassVarLogger: """Test class with logger attached.""" @classmethod - def set_logger(cls, logger): + def set_logger(cls, logger) -> None: """Set the passed logger onto the _class_.""" - ClassVarLogger.logger = logger + ClassVarLogger.logger = logger # type: ignore -def log_stuff(msg: str): - """Wrapper logger func.""" +def log_stuff(msg: str) -> None: + """Wrap logging in another function.""" ClassVarLogger.logger.debug(msg) # type: ignore # its there -def test_class_logger(caplog: 'LogCaptureFixture'): +def test_class_logger(caplog: 'LogCaptureFixture') -> None: """ Test that logging from a class variable doesn't explode. From 4149bebe1475f7e8a08f5a91be46303893850ec4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 May 2021 05:19:29 +0000 Subject: [PATCH 708/727] build(deps): bump watchdog from 2.1.0 to 2.1.1 Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 2.1.0 to 2.1.1. - [Release notes](https://github.com/gorakhargosh/watchdog/releases) - [Changelog](https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst) - [Commits](https://github.com/gorakhargosh/watchdog/compare/v2.1.0...v2.1.1) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9e51f2be..ee9255db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2020.12.5 requests==2.25.1 -watchdog==2.1.0 +watchdog==2.1.1 # Commented out because this doesn't package well with py2exe # infi.systray==0.1.12; sys_platform == 'win32' # argh==0.26.2 watchdog dep From 7a3cda67610afff909ee3bee5d642f4b548eb214 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 May 2021 05:19:40 +0000 Subject: [PATCH 709/727] build(deps-dev): bump flake8-comprehensions from 3.4.0 to 3.5.0 Bumps [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/adamchainz/flake8-comprehensions/releases) - [Changelog](https://github.com/adamchainz/flake8-comprehensions/blob/main/HISTORY.rst) - [Commits](https://github.com/adamchainz/flake8-comprehensions/compare/3.4.0...3.5.0) Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index aa0f574b..cfa41fe6 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ wheel flake8==3.9.2 flake8-annotations-coverage==0.0.5 flake8-cognitive-complexity==0.1.0 -flake8-comprehensions==3.4.0 +flake8-comprehensions==3.5.0 flake8-docstrings==1.6.0 isort==5.8.0 flake8-isort==4.0.0 From 1b7f5e2b060b2c66ee58bfcad5f944ab8601bfa1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 11 May 2021 08:32:07 +0100 Subject: [PATCH 710/727] PLUGINS.md: Document config methods workaround for <5.0.0 --- PLUGINS.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/PLUGINS.md b/PLUGINS.md index a438b8fd..f8156107 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -329,12 +329,28 @@ You can use `set()` and `get_$type()` (where type is one of: `int`, `bool`, settings in a platform-independent way. Previously this was done with a single set and two get methods, the new methods provide better type safety. +If you want to maintain compatibility with pre-5.0.0 versions of this +application (please encourage plugin users to update!) then you'll need to +do something like: + +```python +from config import config + +config_getstring = getattr(config, 'get_str', getattr(config, 'get')) +config_getbool = getattr(config, 'get_bool', getattr(config, 'get')) +config_getlist = getattr(config, 'get_list', getattr(config, 'get')) +config_getinteger = getattr(config, 'get_int', getattr(config, 'getint')) + +... +somebool = config_getbool('myplugin_bool') +``` + **Be sure to use a unique prefix for any settings you save so as not to clash with core EDMC or other plugins.** Use `number_from_string()` from EDMC's `l10n.Locale` object to parse input numbers in a locale-independent way. NB: the old CamelCase versions of -`number_from_string` and `string_from_number` do still exist, but arexi +`number_from_string` and `string_from_number` do still exist, but are deprecated. They will continue to work, but will throw warnings. Note that in the following example the function signature defines that it From e5bbf73acbdb64d7a7e3c95279105da79a4e9996 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 11 May 2021 21:46:14 +0100 Subject: [PATCH 711/727] docs/plugintest: Example of forwards-compatible config functions --- docs/examples/plugintest/load.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index 9f243d93..4f75c866 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -11,7 +11,20 @@ import zipfile import semantic_version from SubA import SubA -from config import appname, appversion +from config import appname, appversion, config + +# For compatibility with pre-5.0.0 +if not hasattr(config, 'get_int'): + config.get_int = config.getint + +if not hasattr(config, 'get_str'): + config.get_str = config.get + +if not hasattr(config, 'get_bool'): + config.get_bool = config.get + +if not hasattr(config, 'get_list'): + config.get_list = config.get # This could also be returned from plugin_start3() plugin_name = os.path.basename(os.path.dirname(__file__)) @@ -101,6 +114,22 @@ def plugin_start3(plugin_dir: str) -> str: # From 5.0.0-beta1 it's a function, returning semantic_version.Version core_version = appversion() + config.set('plugintest_bool', True) + somebool = config.get_bool('plugintest_bool') + logger.debug(f'Stored bool: {somebool=}') + + config.set('plugintest_str', 'Test String') + somestr = config.get_str('plugintest_str') + logger.debug(f'Stored str: {somestr=}') + + config.set('plugintest_int', 42) + someint = config.get_int('plugintest_int') + logger.debug(f'Stored int: {someint=}') + + config.set('plugintest_list', ['test', 'one', 'two']) + somelist = config.get_list('plugintest_list') + logger.debug(f'Stored list: {somelist=}') + logger.info(f'Core EDMC version: {core_version}') # And then compare like this if core_version < semantic_version.Version('5.0.0-beta1'): From 682c48e5ac5479d98d11b081318b8a6754f68fb1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 11 May 2021 21:48:03 +0100 Subject: [PATCH 712/727] PLUGINS: Document better config forwards compatibility code --- PLUGINS.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index f8156107..656a0274 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -331,18 +331,24 @@ set and two get methods, the new methods provide better type safety. If you want to maintain compatibility with pre-5.0.0 versions of this application (please encourage plugin users to update!) then you'll need to -do something like: +include this code in at least once in your plugin (no harm in putting it in +all modules/files): ```python from config import config -config_getstring = getattr(config, 'get_str', getattr(config, 'get')) -config_getbool = getattr(config, 'get_bool', getattr(config, 'get')) -config_getlist = getattr(config, 'get_list', getattr(config, 'get')) -config_getinteger = getattr(config, 'get_int', getattr(config, 'getint')) +# For compatibility with pre-5.0.0 +if not hasattr(config, 'get_int'): + config.get_int = config.getint -... -somebool = config_getbool('myplugin_bool') +if not hasattr(config, 'get_str'): + config.get_str = config.get + +if not hasattr(config, 'get_bool'): + config.get_bool = config.get + +if not hasattr(config, 'get_list'): + config.get_list = config.get ``` **Be sure to use a unique prefix for any settings you save so as not to clash From b8a9ec130329b8d749710d99d24c551e7bbca144 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 11 May 2021 21:50:58 +0100 Subject: [PATCH 713/727] ChangeLog: Cite the 'good' config forwards-compatibility for plugins --- ChangeLog.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 7c0d4264..930c7dea 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -221,6 +221,28 @@ Plugin Developers Setting still uses `config.set(...)`. + For ease of maintaining compatibility with pre-5.0.0 versions include + this code in at least one module/file (no harm in it being in all that + manipulate plugin config): + +``` +from config import config + +# For compatibility with pre-5.0.0 +if not hasattr(config, 'get_int'): + config.get_int = config.getint + +if not hasattr(config, 'get_str'): + config.get_str = config.get + +if not hasattr(config, 'get_bool'): + config.get_bool = config.get + +if not hasattr(config, 'get_list'): + config.get_list = config.get +``` + + * We now change the current working directory of EDMarketConnector.exe to its location as soon as possible in its execution. We're also paranoid about ensuring we reference the full path to the `.gitversion` file. From 41adf596ce9ad33c9379ed57e6411f0348e51211 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 11 May 2021 22:46:39 +0100 Subject: [PATCH 714/727] PLUGINS/config: Better forwards-compatibility example --- PLUGINS.md | 2 +- docs/examples/plugintest/load.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 656a0274..6c1c0e12 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -345,7 +345,7 @@ if not hasattr(config, 'get_str'): config.get_str = config.get if not hasattr(config, 'get_bool'): - config.get_bool = config.get + config.get_bool = lambda key: bool(config.getint(key)) if not hasattr(config, 'get_list'): config.get_list = config.get diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index 4f75c866..2639cfd9 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -21,7 +21,7 @@ if not hasattr(config, 'get_str'): config.get_str = config.get if not hasattr(config, 'get_bool'): - config.get_bool = config.get + config.get_bool = lambda key: bool(config.getint(key)) if not hasattr(config, 'get_list'): config.get_list = config.get @@ -116,19 +116,19 @@ def plugin_start3(plugin_dir: str) -> str: config.set('plugintest_bool', True) somebool = config.get_bool('plugintest_bool') - logger.debug(f'Stored bool: {somebool=}') + logger.debug(f'Stored bool: {somebool=} ({type(somebool)})') config.set('plugintest_str', 'Test String') somestr = config.get_str('plugintest_str') - logger.debug(f'Stored str: {somestr=}') + logger.debug(f'Stored str: {somestr=} ({type(somestr)})') config.set('plugintest_int', 42) someint = config.get_int('plugintest_int') - logger.debug(f'Stored int: {someint=}') + logger.debug(f'Stored int: {someint=} ({type(someint)})') config.set('plugintest_list', ['test', 'one', 'two']) somelist = config.get_list('plugintest_list') - logger.debug(f'Stored list: {somelist=}') + logger.debug(f'Stored list: {somelist=} ({type(somelist)})') logger.info(f'Core EDMC version: {core_version}') # And then compare like this From 04b29928ed2c46aa0e1c7aa67732a1be16f32149 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 11 May 2021 22:47:21 +0100 Subject: [PATCH 715/727] ChangeLog: Better config forwards-compatibility --- ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 930c7dea..f472bef5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -236,7 +236,7 @@ if not hasattr(config, 'get_str'): config.get_str = config.get if not hasattr(config, 'get_bool'): - config.get_bool = config.get + config.get_bool = lambda key: bool(config.getint(key)) if not hasattr(config, 'get_list'): config.get_list = config.get From d02ede356e7991ee7238dfb840fa9a08bef40068 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 May 2021 05:16:52 +0000 Subject: [PATCH 716/727] build(deps): bump actions/setup-python from 2 to 2.2.2 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 2.2.2. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v2...v2.2.2) Signed-off-by: dependabot[bot] --- .github/workflows/pr-checks.yml | 2 +- .github/workflows/push-checks.yml | 2 +- .github/workflows/windows-build.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 476eef97..a02a04d3 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -53,7 +53,7 @@ jobs: # Get Python set up #################################################################### - name: Set up Python 3.9 - uses: actions/setup-python@v2 + uses: actions/setup-python@v2.2.2 with: python-version: 3.9 - name: Install dependencies diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index 362d75ab..088d9f29 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -21,7 +21,7 @@ jobs: with: fetch-depth: 0 - name: Set up Python 3.9 - uses: actions/setup-python@v2 + uses: actions/setup-python@v2.2.2 with: python-version: 3.9 - name: Install dependencies diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 5bcbc7a9..b3ae7f22 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v2.2.2 with: python-version: "3.9.5" architecture: "x86" From 735f1bb846c65abd79b83ba269c913507ad69344 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 May 2021 07:13:48 +0000 Subject: [PATCH 717/727] build(deps): bump actions/checkout from 2 to 2.3.4 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 2.3.4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v2.3.4) Signed-off-by: dependabot[bot] --- .github/workflows/pr-checks.yml | 2 +- .github/workflows/push-checks.yml | 2 +- .github/workflows/windows-build.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index a02a04d3..318ff80f 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -28,7 +28,7 @@ jobs: # based on. - name: Checkout head commits # https://github.com/actions/checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 #with: #ref: ${{github.head.sha}} #repository: ${{github.event.pull_request.head.repo.full_name}} diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index 088d9f29..8438a9a2 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2.3.4 with: fetch-depth: 0 - name: Set up Python 3.9 diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index b3ae7f22..f42937f9 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -16,7 +16,7 @@ jobs: shell: powershell steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2.3.4 - uses: actions/setup-python@v2.2.2 with: python-version: "3.9.5" From 6d6ff00490607797531d661f63d9c2f9cbaa8a23 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 08:17:31 +0100 Subject: [PATCH 718/727] ChangeLog: Be explicit about the steps for config update. --- ChangeLog.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f472bef5..015cead3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -221,9 +221,12 @@ Plugin Developers Setting still uses `config.set(...)`. - For ease of maintaining compatibility with pre-5.0.0 versions include - this code in at least one module/file (no harm in it being in all that - manipulate plugin config): + So: + + 1. Replace all instances of `config.get()` and `config.getint()` as above. + 2. For ease of maintaining compatibility with pre-5.0.0 versions include + this code in at least one module/file (no harm in it being in all that + manipulate plugin config): ``` from config import config From 00f4e00dc8b7e3105f6c8ac132a5f59bab2560f3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 08:46:01 +0100 Subject: [PATCH 719/727] ChangeLog: Inform general users about potential plugin issues. --- ChangeLog.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 015cead3..3aa0625f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -24,6 +24,20 @@ Python 3.9 Changes and Enhancements --- + +* Due to some Plugin API changes (see below) users might need to update + their plugins. A check of all the + [Plugins we know about](https://github.com/EDCD/EDMarketConnector/wiki/Plugins#available-plugins---confirmed-working-under-python-37) + only found one with an issue related to the move to `edmc_data.py`, the + developer was informed and the issue addressed. + + Other plugins should, at most, log deprecation warnings about the + `config` changes (again, see below). + + **In the first instance please report any issues with plugins to *their* + developers, not us. They can contact us about EDMC core code issues if + they find such in their investigations.** + * If the application detects it's running against a non-live (alpha or beta) version of the game it will append " (beta)" to the Commander name on the main UI. From c2f4e4fbda1f88c2c8ccb1f5d6435ce308f78840 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 09:36:00 +0100 Subject: [PATCH 720/727] ChangeLog: Document back/forwards compatible config.appversion --- ChangeLog.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 3aa0625f..0dc8fe3d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -216,6 +216,17 @@ Plugin Developers * `config.appversion()` is now a function that returns a `semantic_version.Version`. In contexts where you're expecting a string this should mostly just work. If needs be wrap it in `str()`. + + For backwards compatibility with pre-5.0.0 you can use: + +```python + from config import appversion + + if callable(appversion): + edmc_version = appversion() + else: + edmc_version = appversion +``` * Example plugin [plugintest](https://github.com/EDCD/EDMarketConnector/tree/main/docs/examples/plugintest) From b3495df1b608bfb10486816aa55fa257fd18bc32 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 09:53:44 +0100 Subject: [PATCH 721/727] PLUGINS: Tweak config.appversion section --- PLUGINS.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 6c1c0e12..e5355faa 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -189,7 +189,10 @@ include variables, and even the returns of functions, in the output. ## Checking core EDMC version If you have code that needs to act differently under different versions of -this application then you can check the core version using: +this application then you can check utilise `config.appversion`. + +Prior to version 5.0.0 this was a simple string. From 5.0.0 onwards it is, +instead, a function which returns an instance of `semantic_version.Version`. ```python import semantic_version @@ -252,7 +255,7 @@ application crashes or hangs. ### Use a thread for long-running code -By default your plugin code will be running in the main thread. So, if you +By default, your plugin code will be running in the main thread. So, if you perform some operation that takes significant time (more than a second) you will be blocking both the core code from continuing *and* any other plugins from running their main-thread code. From 7f45953012f32cfb392be1a619e005fe4e3a17dd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 10:56:43 +0100 Subject: [PATCH 722/727] plugins/station: *Do* set station from BodyType/Body always The 'if not this.station' was early paranoia when first getting things working with Odyssey. It prevents a relog from Horizons (i.e. different location) from correctly picking up an Odyssey login station when on-foot in concourse. Also, EDSM was defaulting wrongly for this.station_marketid. Not that the plugin even *uses* that at this time. --- plugins/eddb.py | 2 +- plugins/edsm.py | 4 ++-- plugins/inara.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index e5e9f81c..cd51b49c 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -118,7 +118,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.station = entry.get('StationName') or this.station # on_foot station detection - if not this.station and entry['event'] == 'Location' and entry['BodyType'] == 'Station': + if entry['event'] == 'Location' and entry['BodyType'] == 'Station': this.station = entry['Body'] this.station_marketid = entry.get('MarketID') or this.station_marketid diff --git a/plugins/edsm.py b/plugins/edsm.py index f4118f56..43a3c8ff 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -373,10 +373,10 @@ def journal_entry( this.station = entry.get('StationName', this.station) # on_foot station detection - if not this.station and entry['event'] == 'Location' and entry['BodyType'] == 'Station': + if entry['event'] == 'Location' and entry['BodyType'] == 'Station': this.station = entry['Body'] - this.station_marketid = entry.get('MarketID', this.station) + this.station_marketid = entry.get('MarketID', this.station_marketid) # We might pick up StationName in DockingRequested, make sure we clear it if leaving if entry['event'] in ('Undocked', 'FSDJump', 'SupercruiseEntry'): this.station = None diff --git a/plugins/inara.py b/plugins/inara.py index c8110ff0..4f76b603 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -386,7 +386,7 @@ def journal_entry( # noqa: C901, CCR001 this.station = entry.get('StationName', this.station) # on_foot station detection - if not this.station and entry['event'] == 'Location' and entry['BodyType'] == 'Station': + if entry['event'] == 'Location' and entry['BodyType'] == 'Station': this.station = entry['Body'] this.station_marketid = entry.get('MarketID', this.station_marketid) or this.station_marketid From 7b67ac41188c2685022957b11cdb7c789a0fa968 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 14:10:15 +0100 Subject: [PATCH 723/727] Translations: Updated with latest OneSky --- L10n/fi.strings | 45 +++++++++++++++++++++++++++++++++++++++++++++ L10n/ko.strings | 6 ++++++ 2 files changed, 51 insertions(+) diff --git a/L10n/fi.strings b/L10n/fi.strings index f88a42a3..7f577415 100644 --- a/L10n/fi.strings +++ b/L10n/fi.strings @@ -1,6 +1,9 @@ /* Language name */ "!Language" = "Suomi"; +/* Message next to 'UI Transparency' slider [prefs.py] */ +"100 means fully opaque.{CR}Window is updated in real time" = "100 tarkoittaa täysin peittävää.{CR}Ikkuna päivittyy reaaliajassa."; + /* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ "100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 tarkoittaa oletusta{CR}Muutosten käyttöönotto{CR}edellyttää uudelleenkäynnistystä!"; @@ -46,6 +49,9 @@ /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: tietoja ei löytynyt"; + /* CQC rank. [stats.py] */ "Champion" = "Champion"; @@ -145,6 +151,9 @@ /* Trade rank. [stats.py] */ "Entrepreneur" = "Entrepreneur"; +/* [companion.py] */ +"Error" = "Virhe"; + /* [eddn.py] */ "Error: Can't connect to EDDN" = "Virhe: ei saatu yhteyttä EDDN:ään"; @@ -154,6 +163,12 @@ /* [inara.py] */ "Error: Can't connect to Inara" = "Virhe: Ei yhteyttä Inaraan"; +/* [companion.py] */ +"Error: Couldn't check token customer_id" = "Virhe: Ei kyetty tarkastamaan polettia customer_id"; + +/* [companion.py] */ +"Error: customer_id doesn't match!" = "Virhe: customer_id ei löydy vastaavuutta!"; + /* [edsm.py] */ "Error: EDSM {MSG}" = "Virhe: EDSM {MSG}"; @@ -172,6 +187,9 @@ /* [companion.py] */ "Error: Invalid Credentials" = "Virhe: kirjautuminen ei kelpaa"; +/* [companion.py] */ +"Error: unable to get token" = "Virhe: ei kyetty saamaan polettia"; + /* Raised when the user has multiple accounts and the username/password setting is not for the account they're currently playing OR the user has reset their Cmdr and the Companion API server is still returning data for the old Cmdr. [companion.py] */ "Error: Wrong Cmdr" = "Virhe: väärä komentaja"; @@ -226,12 +244,18 @@ /* Hotkey/Shortcut settings prompt on Windows. [prefs.py] */ "Hotkey" = "Pikanäppäin"; +/* Changed journal update_lock failed [monitor.py] */ +"Ignore" = "Älä huomioi"; + /* Section heading in settings. [inara.py] */ "Inara credentials" = "Inaran kirjautuminen"; /* Settings>Plugins>Information on migrating plugins [prefs.py] */ "Information on migrating plugins" = "Tietoja lisäosien siirrosta"; +/* Changed journal update_lock failed [monitor.py] */ +"Journal directory already locked" = "Journal -hakemisto on jo lukittu"; + /* Hotkey/Shortcut settings prompt on OSX. [prefs.py] */ "Keyboard shortcut" = "Näppäimistöoikopolku"; @@ -265,6 +289,9 @@ /* Empire rank. [stats.py] */ "Lord" = "Lord"; +/* Label for 'UI Transparency' option in [prefs.py] */ +"Main window transparency" = "Pääikkunan läpinäkyvyys"; + /* [prefs.py] */ "Market data in CSV format file" = "Markkinadata CSV -formaatissa"; @@ -283,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "Pienennä tehtäväpalkkiin"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; @@ -352,6 +382,9 @@ /* Section heading in settings. [prefs.py] */ "Plugins folder" = "Lisäosien hakemistosijainti"; +/* Settings>Plugins>Plugins without Python 3.x support [prefs.py] */ +"Plugins Without Python 3.x Support:" = "Lisäosat, joissa ei ole Python 3.x -tukea:"; + /* Federation rank. [stats.py] */ "Post Captain" = "Post Captain"; @@ -406,6 +439,9 @@ /* Help menu item. [EDMarketConnector.py] */ "Release Notes" = "Julkaisutiedot"; +/* Changed journal update_lock failed [monitor.py] */ +"Retry" = "Yritä uudelleen"; + /* Multicrew role label in main window. [EDMarketConnector.py] */ "Role" = "Rooli"; @@ -469,12 +505,18 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "Tila"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "Asuste"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; /* Main window. [EDMarketConnector.py] */ "System" = "Järjestelmä"; +/* Changed journal update_lock failed [monitor.py] */ +"The new Journal Directory location is already locked.{CR}You can either attempt to resolve this and then Retry, or choose to Ignore this." = "Uusi Journal -hakemisto on jo lukittu.{CR}Voit joko yrittää ratkaista tämän ja yrittää uudelleen, tai jättää asian huomiotta."; + /* Appearance setting. [prefs.py] */ "Theme" = "Teema"; @@ -496,6 +538,9 @@ /* Label for 'UI Scaling' option [prefs.py] */ "UI Scale Percentage" = "Käyttöliittymän skaalausprosentti"; +/* General 'Unknown', e.g. suit loadout */ +"Unknown" = "Tuntematon"; + /* Update button in main window. [EDMarketConnector.py] */ "Update" = "Päivitä"; diff --git a/L10n/ko.strings b/L10n/ko.strings index 05e64913..3f0f45ce 100644 --- a/L10n/ko.strings +++ b/L10n/ko.strings @@ -310,6 +310,9 @@ /* Federation rank. [stats.py] */ "Midshipman" = "Midshipman"; +/* Appearance setting. [EDMarketConnector.py] */ +"Minimize to system tray" = "시스템 트레이로 최소화"; + /* Explorer rank. [stats.py] */ "Mostly Aimless" = "Mostly Aimless"; @@ -502,6 +505,9 @@ /* Menu item. [EDMarketConnector.py] */ "Status" = "상태"; +/* 'Suit' label in main UI' [EDMarketConnector.py] */ +"Suit" = "슈트"; + /* Explorer rank. [stats.py] */ "Surveyor" = "Surveyor"; From d68d56050ac5e4c8bbbf4933a06ac93ee197e271 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 14:11:15 +0100 Subject: [PATCH 724/727] coriolis-data: Fresh pull, script caused no change to {ships,modules}.p --- coriolis-data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coriolis-data b/coriolis-data index a4f5d3fb..e499f684 160000 --- a/coriolis-data +++ b/coriolis-data @@ -1 +1 @@ -Subproject commit a4f5d3fb8176b808618962aceda27efda8947df2 +Subproject commit e499f68469bb4c3d7cecbc91ab67bd4a0bc40993 From 6c590b0c398607999954b64b4f08c9bd6068d385 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 14:19:33 +0100 Subject: [PATCH 725/727] Release 5.0.0: appversion and ChangeLog --- ChangeLog.md | 51 +++++++++++++++++++++++++++++++++++++-------------- config.py | 2 +- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 0dc8fe3d..52c22958 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,7 +1,7 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- -Pre-Release 5.0.0-rc1 +Release 5.0.0 === Python 3.9 @@ -22,21 +22,38 @@ Python 3.9 in the source (it's not distributed with the Windows installer) for the currently used version in a given branch. -Changes and Enhancements +This Update Is Mandatory --- -* Due to some Plugin API changes (see below) users might need to update - their plugins. A check of all the - [Plugins we know about](https://github.com/EDCD/EDMarketConnector/wiki/Plugins#available-plugins---confirmed-working-under-python-37) - only found one with an issue related to the move to `edmc_data.py`, the - developer was informed and the issue addressed. - - Other plugins should, at most, log deprecation warnings about the - `config` changes (again, see below). - - **In the first instance please report any issues with plugins to *their* - developers, not us. They can contact us about EDMC core code issues if - they find such in their investigations.** +This release is a **mandatory upgrade for the release of Elite Dangerous +Odyssey**. Any bug reports against earlier releases, pertaining to Odyssey or +not, will be directed to reproduce them with 5.0.0 or later. There are also +minor bugs in 4.2.7 and earlier that have been fixed in this version. There +will **NOT** be another 4.2.x release. + +The major version has been incremented not for Odyssey support, but because +we have made some minor breaking changes to the APIs we provide for plugin +developers. + +Due to these plugin API changes (see below) users might need to update their +plugins. A check of all the +[Plugins we know about](https://github.com/EDCD/EDMarketConnector/wiki/Plugins#available-plugins---confirmed-working-under-python-37) +only found one with an issue related to the move to `edmc_data.py`, the +developer was informed and the issue addressed. + +Other plugins should, at most, log deprecation warnings about the +`config` changes (again, see below). + +**In the first instance please report any issues with plugins to *their* +developers, not us. They can contact us about EDMC core code issues if +they find such in their investigations.** + +All plugin developers would benefit from having a GitHub account and then +setting up a watch on [EDMarketConnector](https://github.com/EDCD/EDMarketConnector/) +of at least 'Releases' under 'Custom'. + +Changes and Enhancements +--- * If the application detects it's running against a non-live (alpha or beta) version of the game it will append " (beta)" to the Commander name on the @@ -270,6 +287,8 @@ if not hasattr(config, 'get_list'): config.get_list = config.get ``` +* Utilising our provided logging from a class-level, i.e. not a solid + instance of a class, property/function will now work. * We now change the current working directory of EDMarketConnector.exe to its location as soon as possible in its execution. We're also @@ -336,6 +355,10 @@ if not hasattr(config, 'get_list'): See the updated `PLUGINS.md` file for details. +* As `Status.json`, and thus the EDMC 'dashboard' output now has a 'flags2' + key we have added the associated constants to `edmc_data.py` with a + `Flags2` prefix on the names. + * Note that during the Odyssey Alpha it was observed that the CAPI `data['commander']['docked']` boolean was **always true** if the Cmdr was in their ship. This is a regression from pre-Odyssey behaviour. The diff --git a/config.py b/config.py index 1fca363f..f92eea4c 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.0.0-rc1' +_static_appversion = '5.0.0' copyright = '© 2015-2019 Jonathan Harris, 2020-2021 EDCD' update_feed = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' From 08499625f53ac583bb10b4ce09ddd66aa029b219 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 14:41:06 +0100 Subject: [PATCH 726/727] 5.0.0: Include --reset-ui .bat, and mention killswitches docs --- ChangeLog.md | 6 ++++++ EDMarketConnector.wxs | 4 ++++ setup.py | 3 +-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 52c22958..1ccdcd91 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -75,6 +75,9 @@ Changes and Enhancements The intention is this can be used if you've lost sight of the main window due to tweaking these options. + + There is a new file `EDMarketConnector - reset-ui.bat` to make utilising + this easy on Windows. * New CL arg for EDMarketConnector.exe `--force-edmc-protocol`. This is really only of use to core developers (its purpose being to force @@ -118,6 +121,9 @@ Changes and Enhancements If we ever have to use this we'll announce it clearly and endeavour to get a fixed version of the program released ASAP. We will **NOT** be using this merely to try and get some laggards to upgrade. + + Plugin Developers: See [Killswitches.md](./docs/Killswitches.md) for more + information about this. * Our logging code will make best efforts to still show class name and other such fields if it has trouble finding any of the required data for diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index 67fa5366..c24a594f 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -239,6 +239,9 @@ + + + @@ -621,6 +624,7 @@ + diff --git a/setup.py b/setup.py index 525dc313..372b4477 100755 --- a/setup.py +++ b/setup.py @@ -18,8 +18,6 @@ from os.path import exists, isdir, join from tempfile import gettempdir from typing import Any, Generator, Set -import semantic_version - from config import ( appcmdname, applongname, appname, appversion, appversion_nobuild, copyright, git_shorthash_from_head, update_feed, update_interval @@ -223,6 +221,7 @@ elif sys.platform == 'win32': f'{appname}.ico', 'EDMarketConnector - TRACE.bat', 'EDMarketConnector - localserver-auth.bat', + 'EDMarketConnector - reset-ui.bat', ]), ('L10n', [join('L10n', x) for x in os.listdir('L10n') if x.endswith('.strings')]), ('plugins', PLUGINS), From c6712a7860ac4a4d71d549b98d3ebc0ec47f166e Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 12 May 2021 14:53:00 +0100 Subject: [PATCH 727/727] ChangeLog: beta/rc testers *might* need to manuall uninstall first. --- ChangeLog.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 1ccdcd91..daef2530 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -52,6 +52,13 @@ All plugin developers would benefit from having a GitHub account and then setting up a watch on [EDMarketConnector](https://github.com/EDCD/EDMarketConnector/) of at least 'Releases' under 'Custom'. +NB: If you had any beta or -rc1 of 5.0.0 installed and see anything weird +with this full release it would be advisable to manually uninstall, confirm +the installation directory (default `c:\Program Files (x86)\EDMarketConnector`) +is empty, and then re-install 5.0.0 to be sure you have a clean, working, +install. Anyone upgrading from 4.2.7 or earlier shouldn't see any issues +with this. + Changes and Enhancements ---