Add logic to enable self-update only for pipx
MODIFY
plextraktsync/cli.py
plextraktsync/cli.py
from plextraktsync.commands.inspect import inspect
from plextraktsync.commands.login import login
from plextraktsync.commands.plex_login import plex_login
-from plextraktsync.commands.self_update import self_update
+from plextraktsync.commands.self_update import self_update, enable_self_update
from plextraktsync.commands.sync import sync
from plextraktsync.commands.trakt_login import trakt_login
from plextraktsync.commands.unmatched import unmatched
@@ -30,6 +30,7 @@ def cli(ctx):
cli.add_command(inspect)
cli.add_command(login)
cli.add_command(plex_login)
+if enable_self_update():
cli.add_command(self_update)
cli.add_command(sync)
cli.add_command(trakt_login)

MODIFY
plextraktsync/commands/self_update.py
plextraktsync/commands/self_update.py
+import json
+import subprocess
+from json import JSONDecodeError
from os import system
+from typing import List, Union
import click
+from plextraktsync.version import version as get_version
+
+
+def execx(command: Union[str, List[str]]):
+ if isinstance(command, str):
+ command = command.split(' ')
+
+ process = subprocess.Popen(command, stdout=subprocess.PIPE)
+ return process.communicate()[0]
+
+
+def pipx_installed(package: str):
+ try:
+ output = execx('pipx list --json')
+ except FileNotFoundError:
+ return None
+ if not output:
+ return None
+
+ try:
+ install_data = json.loads(output)
+ except JSONDecodeError:
+ return None
+ if install_data is None:
+ return None
+
+ try:
+ package = install_data['venvs'][package]['metadata']['main_package']
+ except KeyError:
+ return None
+
+ return package
+
+
+def enable_self_update():
+ package = pipx_installed('plextraktsync')
+
+ return package is not None
+
@click.command()
def self_update():

Add logic to enable self-update only for pipx