From ec08dcf11891ece2dcf26452717637e7ed9623f3 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Tue, 27 Feb 2024 17:33:07 +0300 Subject: [PATCH] Added debugpy to container. --- .vscode/launch.json | 18 +++++++++++++++++- Pipfile | 1 + Pipfile.lock | 31 ++++++++++++++++++++++++++++++- app/Config.py | 16 ++++++++++++++-- 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index aec48f1b..b1c83b86 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -36,10 +36,26 @@ } }, { - "name": "Python: attach to process.", + "name": "Python: Attach To Process", "type": "debugpy", "request": "attach", "processId": "${command:pickProcess}", + }, + { + "name": "Python: Attach To Container", + "type": "debugpy", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/app/app" + } + ], + "justMyCode": true } ] } diff --git a/Pipfile b/Pipfile index dfb06ce6..d292e3e4 100644 --- a/Pipfile +++ b/Pipfile @@ -12,6 +12,7 @@ coloredlogs = "*" aiocron = "*" python-dotenv = "*" python-magic = "*" +debugpy = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 5ddda689..e3f8b966 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ff439968ef47903738a8fd477d19d86abf8650ce4c46f1f603e3f8472148ec0f" + "sha256": "969599ea205de43f64d64331fc3307bb0d9be1dc1830c57b51f93c607d2bbe1f" }, "pipfile-spec": 6, "requires": { @@ -355,6 +355,35 @@ "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0.1" }, + "debugpy": { + "hashes": [ + "sha256:016a9fcfc2c6b57f939673c874310d8581d51a0fe0858e7fac4e240c5eb743cb", + "sha256:0de56aba8249c28a300bdb0672a9b94785074eb82eb672db66c8144fff673146", + "sha256:1a9fe0829c2b854757b4fd0a338d93bc17249a3bf69ecf765c61d4c522bb92a8", + "sha256:28acbe2241222b87e255260c76741e1fbf04fdc3b6d094fcf57b6c6f75ce1242", + "sha256:3a79c6f62adef994b2dbe9fc2cc9cc3864a23575b6e387339ab739873bea53d0", + "sha256:3bda0f1e943d386cc7a0e71bfa59f4137909e2ed947fb3946c506e113000f741", + "sha256:3ebb70ba1a6524d19fa7bb122f44b74170c447d5746a503e36adc244a20ac539", + "sha256:58911e8521ca0c785ac7a0539f1e77e0ce2df753f786188f382229278b4cdf23", + "sha256:6df9aa9599eb05ca179fb0b810282255202a66835c6efb1d112d21ecb830ddd3", + "sha256:7a3afa222f6fd3d9dfecd52729bc2e12c93e22a7491405a0ecbf9e1d32d45b39", + "sha256:7eb7bd2b56ea3bedb009616d9e2f64aab8fc7000d481faec3cd26c98a964bcdd", + "sha256:92116039b5500633cc8d44ecc187abe2dfa9b90f7a82bbf81d079fcdd506bae9", + "sha256:a2e658a9630f27534e63922ebf655a6ab60c370f4d2fc5c02a5b19baf4410ace", + "sha256:bfb20cb57486c8e4793d41996652e5a6a885b4d9175dd369045dad59eaacea42", + "sha256:caad2846e21188797a1f17fc09c31b84c7c3c23baf2516fed5b40b378515bbf0", + "sha256:d915a18f0597ef685e88bb35e5d7ab968964b7befefe1aaea1eb5b2640b586c7", + "sha256:dda73bf69ea479c8577a0448f8c707691152e6c4de7f0c4dec5a4bc11dee516e", + "sha256:e38beb7992b5afd9d5244e96ad5fa9135e94993b0c551ceebf3fe1a5d9beb234", + "sha256:edcc9f58ec0fd121a25bc950d4578df47428d72e1a0d66c07403b04eb93bcf98", + "sha256:efd3fdd3f67a7e576dd869c184c5dd71d9aaa36ded271939da352880c012e703", + "sha256:f696d6be15be87aef621917585f9bb94b1dc9e8aced570db1b8a6fc14e8f9b42", + "sha256:fd97ed11a4c7f6d042d320ce03d83b20c3fb40da892f994bc041bbc415d7a099" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==1.8.1" + }, "frozenlist": { "hashes": [ "sha256:04ced3e6a46b4cfffe20f9ae482818e34eba9b5fb0ce4056e4cc9b6e212d09b7", diff --git a/app/Config.py b/app/Config.py index 0c6137b2..7f57051c 100644 --- a/app/Config.py +++ b/app/Config.py @@ -41,11 +41,13 @@ class Config: version: str = APP_VERSION + debug: bool = False + new_version_available: bool = False _int_vars: tuple = ('port', 'max_workers',) _immutable: tuple = ('version', '__instance', 'ytdl_options', 'new_version_available') - _boolean_vars: tuple = ('keep_archive', 'ytdl_debug', 'temp_keep', 'allow_manifestless',) + _boolean_vars: tuple = ('keep_archive', 'ytdl_debug', 'debug', 'temp_keep', 'allow_manifestless',) @staticmethod def get_instance(): @@ -63,7 +65,9 @@ class Config: self.temp_path = os.environ.get('YTP_TEMP_PATH', None) or os.path.join(baseDefaultPath, 'var', 'tmp') self.config_path = os.environ.get('YTP_CONFIG_PATH', None) or os.path.join(baseDefaultPath, 'var', 'config') - self.download_path = os.environ.get('YTP_DOWNLOAD_PATH', None) or os.path.join(baseDefaultPath, 'var', 'downloads') + self.download_path = os.environ.get( + 'YTP_DOWNLOAD_PATH', None) or os.path.join( + baseDefaultPath, 'var', 'downloads') envFile: str = os.path.join(self.config_path, '.env') @@ -122,6 +126,14 @@ class Config: LOG = logging.getLogger('config') + if self.debug: + try: + import debugpy + debugpy.listen(("0.0.0.0", 5678)) + LOG.info("starting debugpy server on [0.0.0.0:5678]") + except ImportError: + LOG.error("debugpy not found, please install it with 'pip install debugpy'") + optsFile: str = os.path.join(self.config_path, 'ytdlp.json') if os.path.exists(optsFile) and os.path.getsize(optsFile) > 0: LOG.info(f'Loading yt-dlp custom options from "{optsFile}"')