Skip to content

Commit

Permalink
Tool black: auto-format Python code
Browse files Browse the repository at this point in the history
  • Loading branch information
oddstr13 committed Jun 10, 2024
1 parent e4d8084 commit 7763762
Show file tree
Hide file tree
Showing 54 changed files with 6,655 additions and 4,833 deletions.
81 changes: 37 additions & 44 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,48 @@ def create_addon_xml(config: dict, source: str, py_version: str) -> None:
Create addon.xml from template file
"""
# Load template file
with open('{}/.build/template.xml'.format(source), 'r') as f:
with open("{}/.build/template.xml".format(source), "r") as f:
tree = ET.parse(f)
root = tree.getroot()

# Populate dependencies in template
dependencies = config['dependencies'].get(py_version)
dependencies = config["dependencies"].get(py_version)
for dep in dependencies:
ET.SubElement(root.find('requires'), 'import', attrib=dep)
ET.SubElement(root.find("requires"), "import", attrib=dep)

# Populate version string
addon_version = config.get('version')
root.attrib['version'] = '{}+{}'.format(addon_version, py_version)
addon_version = config.get("version")
root.attrib["version"] = "{}+{}".format(addon_version, py_version)

# Populate Changelog
date = datetime.today().strftime('%Y-%m-%d')
changelog = config.get('changelog')
for section in root.findall('extension'):
news = section.findall('news')
date = datetime.today().strftime("%Y-%m-%d")
changelog = config.get("changelog")
for section in root.findall("extension"):
news = section.findall("news")
if news:
news[0].text = 'v{} ({}):\n{}'.format(addon_version, date, changelog)
news[0].text = "v{} ({}):\n{}".format(addon_version, date, changelog)

# Format xml tree
indent(root)

# Write addon.xml
tree.write('{}/addon.xml'.format(source), encoding='utf-8', xml_declaration=True)
tree.write("{}/addon.xml".format(source), encoding="utf-8", xml_declaration=True)


def zip_files(py_version: str, source: str, target: str, dev: bool) -> None:
"""
Create installable addon zip archive
"""
archive_name = 'plugin.video.jellyfin+{}.zip'.format(py_version)
archive_name = "plugin.video.jellyfin+{}.zip".format(py_version)

with zipfile.ZipFile('{}/{}'.format(target, archive_name), 'w') as z:
with zipfile.ZipFile("{}/{}".format(target, archive_name), "w") as z:
for root, dirs, files in os.walk(args.source):
for filename in filter(file_filter, files):
file_path = os.path.join(root, filename)
if dev or folder_filter(file_path):
relative_path = os.path.join('plugin.video.jellyfin', os.path.relpath(file_path, source))
relative_path = os.path.join(
"plugin.video.jellyfin", os.path.relpath(file_path, source)
)
z.write(file_path, relative_path)


Expand All @@ -83,10 +85,12 @@ def file_filter(file_name: str) -> bool:
True if file_name is meant to be included
"""
return (
not (file_name.startswith('plugin.video.jellyfin') and file_name.endswith('.zip'))
and not file_name.endswith('.pyo')
and not file_name.endswith('.pyc')
and not file_name.endswith('.pyd')
not (
file_name.startswith("plugin.video.jellyfin") and file_name.endswith(".zip")
)
and not file_name.endswith(".pyo")
and not file_name.endswith(".pyc")
and not file_name.endswith(".pyd")
)


Expand All @@ -95,13 +99,13 @@ def folder_filter(folder_name: str) -> bool:
True if folder_name is meant to be included
"""
filters = [
'.ci',
'.git',
'.github',
'.build',
'.mypy_cache',
'.pytest_cache',
'__pycache__',
".ci",
".git",
".github",
".build",
".mypy_cache",
".pytest_cache",
"__pycache__",
]
for f in filters:
if f in folder_name.split(os.path.sep):
Expand All @@ -110,33 +114,22 @@ def folder_filter(folder_name: str) -> bool:
return True


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Build flags:")
parser.add_argument("--version", type=str, choices=("py2", "py3"), default="py3")

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Build flags:')
parser.add_argument(
'--version',
type=str,
choices=('py2', 'py3'),
default='py3')
parser.add_argument("--source", type=Path, default=Path(__file__).absolute().parent)

parser.add_argument(
'--source',
type=Path,
default=Path(__file__).absolute().parent)
parser.add_argument("--target", type=Path, default=Path(__file__).absolute().parent)

parser.add_argument(
'--target',
type=Path,
default=Path(__file__).absolute().parent)

parser.add_argument('--dev', dest='dev', action='store_true')
parser.add_argument("--dev", dest="dev", action="store_true")
parser.set_defaults(dev=False)

args = parser.parse_args()

# Load config file
config_path = os.path.join(args.source, 'release.yaml')
with open(config_path, 'r') as fh:
config_path = os.path.join(args.source, "release.yaml")
with open(config_path, "r") as fh:
release_config = yaml.safe_load(fh)

create_addon_xml(release_config, args.source, args.version)
Expand Down
76 changes: 36 additions & 40 deletions jellyfin_kodi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,73 +18,69 @@


def get_addon_name():

''' Used for logging.
'''
return xbmcaddon.Addon(addon_id()).getAddonInfo('name').upper()
"""Used for logging."""
return xbmcaddon.Addon(addon_id()).getAddonInfo("name").upper()


def get_version():
return xbmcaddon.Addon(addon_id()).getAddonInfo('version')
return xbmcaddon.Addon(addon_id()).getAddonInfo("version")


def get_platform():

if xbmc.getCondVisibility('system.platform.osx'):
if xbmc.getCondVisibility("system.platform.osx"):
return "OSX"
elif xbmc.getCondVisibility('System.HasAddon(service.coreelec.settings)'):
elif xbmc.getCondVisibility("System.HasAddon(service.coreelec.settings)"):
return "CoreElec"
elif xbmc.getCondVisibility('System.HasAddon(service.libreelec.settings)'):
elif xbmc.getCondVisibility("System.HasAddon(service.libreelec.settings)"):
return "LibreElec"
elif xbmc.getCondVisibility('System.HasAddon(service.osmc.settings)'):
elif xbmc.getCondVisibility("System.HasAddon(service.osmc.settings)"):
return "OSMC"
elif xbmc.getCondVisibility('system.platform.atv2'):
elif xbmc.getCondVisibility("system.platform.atv2"):
return "ATV2"
elif xbmc.getCondVisibility('system.platform.ios'):
elif xbmc.getCondVisibility("system.platform.ios"):
return "iOS"
elif xbmc.getCondVisibility('system.platform.windows'):
elif xbmc.getCondVisibility("system.platform.windows"):
return "Windows"
elif xbmc.getCondVisibility('system.platform.android'):
elif xbmc.getCondVisibility("system.platform.android"):
return "Linux/Android"
elif xbmc.getCondVisibility('system.platform.linux.raspberrypi'):
elif xbmc.getCondVisibility("system.platform.linux.raspberrypi"):
return "Linux/RPi"
elif xbmc.getCondVisibility('system.platform.linux'):
elif xbmc.getCondVisibility("system.platform.linux"):
return "Linux"
else:
return "Unknown"


def get_device_name():

''' Detect the device name. If deviceNameOpt, then
use the device name in the add-on settings.
Otherwise, fallback to the Kodi device name.
'''
if not settings('deviceNameOpt.bool'):
device_name = xbmc.getInfoLabel('System.FriendlyName')
"""Detect the device name. If deviceNameOpt, then
use the device name in the add-on settings.
Otherwise, fallback to the Kodi device name.
"""
if not settings("deviceNameOpt.bool"):
device_name = xbmc.getInfoLabel("System.FriendlyName")
else:
device_name = settings('deviceName')
device_name = device_name.replace("\"", "_")
device_name = settings("deviceName")
device_name = device_name.replace('"', "_")
device_name = device_name.replace("/", "_")

return device_name


def get_device_id(reset=False):
"""Return the device_id if already loaded.
It will load from jellyfin_guid file. If it's a fresh
setup, it will generate a new GUID to uniquely
identify the setup for all users.
''' Return the device_id if already loaded.
It will load from jellyfin_guid file. If it's a fresh
setup, it will generate a new GUID to uniquely
identify the setup for all users.
window prop: jellyfin_deviceId
'''
client_id = window('jellyfin_deviceId')
window prop: jellyfin_deviceId
"""
client_id = window("jellyfin_deviceId")

if client_id:
return client_id

directory = translate_path('special://profile/addon_data/plugin.video.jellyfin/')
directory = translate_path("special://profile/addon_data/plugin.video.jellyfin/")

if not xbmcvfs.exists(directory):
xbmcvfs.mkdir(directory)
Expand All @@ -97,27 +93,27 @@ def get_device_id(reset=False):
LOG.debug("Generating a new GUID.")

client_id = str(create_id())
file_guid = xbmcvfs.File(jellyfin_guid, 'w')
file_guid = xbmcvfs.File(jellyfin_guid, "w")
file_guid.write(client_id)

file_guid.close()
LOG.debug("DeviceId loaded: %s", client_id)
window('jellyfin_deviceId', value=client_id)
window("jellyfin_deviceId", value=client_id)

return client_id


def reset_device_id():

window('jellyfin_deviceId', clear=True)
window("jellyfin_deviceId", clear=True)
get_device_id(True)
dialog("ok", "{jellyfin}", translate(33033))
xbmc.executebuiltin('RestartApp')
xbmc.executebuiltin("RestartApp")


def get_info():
return {
'DeviceName': get_device_name(),
'Version': get_version(),
'DeviceId': get_device_id()
"DeviceName": get_device_name(),
"Version": get_version(),
"DeviceId": get_device_id(),
}
Loading

0 comments on commit 7763762

Please sign in to comment.