diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ed75f53..4d44d0d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -44,9 +44,7 @@ jobs: path: Plugger.bundle - name: Install Python 2.7 - uses: actions/setup-python@v4 - with: - python-version: '2.7' + uses: LizardByte/.github/actions/setup_python2@nightly - name: Set up Python 2.7 Dependencies working-directory: Plugger.bundle diff --git a/.github/workflows/localize.yml b/.github/workflows/localize.yml index d05080a..4f22b83 100644 --- a/.github/workflows/localize.yml +++ b/.github/workflows/localize.yml @@ -6,7 +6,7 @@ on: branches: [nightly] paths: # prevents workflow from running unless these files change - '.github/workflows/localize.yml' - - 'Contents/Scripts/plugger.po' + - 'Contents/Strings/plugger.po' - 'Contents/Code/**.py' - 'Contents/Resources/web/templates/**' workflow_dispatch: @@ -43,7 +43,7 @@ jobs: git diff Contents/Scripts/plugger.po # set the variable with minimal output, replacing `\t` with ` ` - OUTPUT=$(git diff --numstat locale/retroarcher.po | sed -e "s#\t# #g") + OUTPUT=$(git diff --numstat Contents/Strings/plugger.po | sed -e "s#\t# #g") echo "git_diff=${OUTPUT}" >> $GITHUB_ENV - name: git reset diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 2248c74..fcd1f0d 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -19,9 +19,7 @@ jobs: uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '2.7' + uses: LizardByte/.github/actions/setup_python2@nightly - name: Install python dependencies shell: bash @@ -33,5 +31,6 @@ jobs: python -m pip --no-python-version-warning --disable-pip-version-check install -r requirements.txt - name: Test with pytest + shell: bash # our Python 2.7 setup action doesn't support PowerShell run: | python -m pytest -v diff --git a/Contents/Code/const.py b/Contents/Code/const.py index 8184096..892c633 100644 --- a/Contents/Code/const.py +++ b/Contents/Code/const.py @@ -9,10 +9,20 @@ else: # the code is running outside of Plex from plexhints.core_kit import Core # core kit -bundle_identifier = 'dev.lizardbyte.plugger' +# plex constants app_support_directory = Core.app_support_path +plex_base_url = 'http://127.0.0.1:32400' +plex_token = os.environ.get('PLEXTOKEN') plugin_directory = os.path.join(app_support_directory, 'Plug-ins') plugin_logs_directory = os.path.join(app_support_directory, 'Logs', 'PMS Plugin Logs') +plugin_support_directory = os.path.join(app_support_directory, 'Plug-in Support') +plugin_support_caches_directory = os.path.join(plugin_support_directory, 'Caches') +plugin_support_data_directory = os.path.join(plugin_support_directory, 'Data') +plugin_support_databases_directory = os.path.join(plugin_support_directory, 'Databases') +plugin_support_metadata_combination_directory = os.path.join(plugin_support_directory, 'Metadata Combination') +plugin_support_preferences_directory = os.path.join(plugin_support_directory, 'Preferences') system_plugins_directory = Core.bundled_plugins_path -plex_base_url = 'http://127.0.0.1:32400' -plex_token = os.environ.get('PLEXTOKEN') + +# plugger constants +bundle_identifier = 'dev.lizardbyte.plugger' +plugger_data_directory = os.path.join(plugin_support_data_directory, bundle_identifier) diff --git a/Contents/Code/plugin_manager.py b/Contents/Code/plugin_manager.py new file mode 100644 index 0000000..63378d6 --- /dev/null +++ b/Contents/Code/plugin_manager.py @@ -0,0 +1,58 @@ +# plex debugging +try: + import plexhints # noqa: F401 +except ImportError: + pass +else: # the code is running outside of Plex + from plexhints.log_kit import Log # log kit + +# local imports +from const import plugger_data_directory, plugin_directory + +# servers version newer than 1.13 cannot view plugin routes, maybe we can do something with this later +# https://www.reddit.com/r/PleX/comments/ig64mz/comment/jhk5jbu/?utm_source=share&utm_medium=web2x&context=3 + + +def initialize_install(plugin_data): + # type: (dict) -> bool + """ + Initialize the plugin installation process. + + Parses the plugin data for further processing depending on the conditions. + + Parameters + ---------- + plugin_data : dict + The plugin data to process. + + Returns + ------- + bool + Whether or not the plugin was successfully installed/migrated/updated. + """ + Log.Debug("{}: {}".format("plugger_support_directory", plugger_data_directory)) + Log.Debug("{}: {}".format("plugin_directory", plugin_directory)) + + Log.Debug('Initializing plugin installation process for "{}"'.format(plugin_data['plugin']['full_name'])) + for k, v in plugin_data.items(): + Log.Debug("{}: {}".format(k, v)) + return True + + +def uninstall_plugin(plugin_name): + # type: (str) -> bool + """ + Uninstall a plugin. + + Parameters + ---------- + plugin_name : str + The name of the plugin to uninstall. + + Returns + ------- + bool + Whether or not the plugin was successfully uninstalled. + """ + Log.Debug("Uninstalling plugin: {}".format(plugin_name)) + return True diff --git a/Contents/Code/webapp.py b/Contents/Code/webapp.py index d9d671c..4305184 100644 --- a/Contents/Code/webapp.py +++ b/Contents/Code/webapp.py @@ -22,6 +22,7 @@ from flask_babel import Babel import polib import requests +from werkzeug.utils import secure_filename # local imports from const import bundle_identifier, plex_base_url, plex_token, plugin_directory, plugin_logs_directory, \ @@ -208,11 +209,14 @@ def image(img): >>> image('favicon.ico') """ directory = os.path.join(app.static_folder, 'images') - filename = img + filename = os.path.basename(secure_filename(filename=img)) # sanitize the input if os.path.isfile(os.path.join(directory, filename)): - file_extension = filename.split('.')[-1] - return send_from_directory(directory=directory, filename=filename, mimetype=mime_type_map[file_extension]) + file_extension = filename.rsplit('.', 1)[-1] + if file_extension in mime_type_map: + return send_from_directory(directory=directory, filename=filename, mimetype=mime_type_map[file_extension]) + else: + return Response(response='Invalid file type', status=400, mimetype='text/plain') else: return Response(response='Image not found', status=404, mimetype='text/plain') diff --git a/Contents/DefaultPrefs.json b/Contents/DefaultPrefs.json index b4ee560..43ab2ba 100644 --- a/Contents/DefaultPrefs.json +++ b/Contents/DefaultPrefs.json @@ -2,7 +2,7 @@ { "id": "enum_locale", "type": "enum", - "label": "Locale", + "label": "Web UI Locale", "default": "en", "values": [ "de", diff --git a/Contents/Resources/web/templates/home.html b/Contents/Resources/web/templates/home.html index 79f8fa9..3ce543f 100644 --- a/Contents/Resources/web/templates/home.html +++ b/Contents/Resources/web/templates/home.html @@ -101,7 +101,7 @@