Skip to content

Commit

Permalink
Deploy MIME and libcloudproviders files
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAssassin committed Aug 24, 2023
1 parent 7492fd7 commit e713953
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
7 changes: 2 additions & 5 deletions ldnp/appdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import shlex
from pathlib import Path
from typing import Iterable

from xdg.DesktopEntry import DesktopEntry

Expand All @@ -15,14 +14,12 @@ class AppDir:

DESKTOP_FILES_RELATIVE_LOCATION = "usr/share/applications"
ICONS_RELATIVE_LOCATION = "usr/share/icons"
MIME_FILES_RELATIVE_LOCATION = "usr/share/mime"
CLOUDPROVIDERS_FILES_RELATIVE_LOCATION = "usr/share/cloud-providers"

def __init__(self, path: str | os.PathLike):
self.path = Path(path)

def find_desktop_files(self) -> Iterable[Path]:
rv = glob.glob(str(self.path / self.__class__.DESKTOP_FILES_RELATIVE_LOCATION / "*.desktop"))
return map(Path, rv)

def root_desktop_file(self) -> DesktopEntry:
desktop_files = glob.glob(str(self.path / "*.desktop"))

Expand Down
44 changes: 31 additions & 13 deletions ldnp/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,24 @@ def find_desktop_files(self) -> Iterable[Path]:
rv = glob.glob(str(self.appdir_install_path / AppDir.DESKTOP_FILES_RELATIVE_LOCATION / "*.desktop"))
return map(Path, rv)

def find_icons(self) -> Iterable[Path]:
for path in map(
Path,
glob.glob(
str(self.appdir_install_path / AppDir.ICONS_RELATIVE_LOCATION / "**" / "*.*"),
recursive=True,
include_hidden=True,
),
):
@staticmethod
def _find_file_paths_in_directory(directory: Path) -> Iterable[Path]:
for path in map(Path, glob.glob(str(directory / "**" / "*.*"), recursive=True, include_hidden=True)):
if not path.is_file():
continue
yield path

def find_icons(self) -> Iterable[Path]:
return self._find_file_paths_in_directory(self.appdir_install_path / AppDir.ICONS_RELATIVE_LOCATION)

def find_mime_files(self) -> Iterable[Path]:
return self._find_file_paths_in_directory(self.appdir_install_path / AppDir.MIME_FILES_RELATIVE_LOCATION)

def find_cloudproviders_files(self) -> Iterable[Path]:
return self._find_file_paths_in_directory(
self.appdir_install_path / AppDir.CLOUDPROVIDERS_FILES_RELATIVE_LOCATION
)

def copy_data_to_usr(self):
def create_relative_symlink(src: Path, dst: Path):
# to calculate the amount of parent directories we need to move up, we can't use relative_to directly
Expand Down Expand Up @@ -129,11 +134,24 @@ def create_binary_script(script_path: str | os.PathLike, target_binary: str | os
self.appdir_installed_path / "usr/bin" / exec_binary,
)

for icon in self.find_icons():
icon_relative_path = icon.relative_to(self.appdir_install_path)
dst = self.context.install_root_dir / icon_relative_path
def deploy_file_as_is(path):
logger.debug(f"deploying file {path} as-is")
relative_path = path.relative_to(self.appdir_install_path)
dst = self.context.install_root_dir / relative_path
os.makedirs(dst.parent, mode=0o755, exist_ok=True)
create_relative_symlink(icon, dst)
create_relative_symlink(path, dst)

# icon files can just be symlinked, there is no reason _ever_ to modify them
for icon in self.find_icons():
deploy_file_as_is(icon)

# MIME files just describe a type and shouldn't contain any paths, therefore we can just link them
for mime_file in self.find_mime_files():
deploy_file_as_is(mime_file)

# same goes for libcloudproviders configuration data, which just describe some D-Bus endpoints
for cloudproviders_file in self.find_cloudproviders_files():
deploy_file_as_is(cloudproviders_file)

def copy_appdir_contents(self):
if os.path.exists(self.appdir_install_path):
Expand Down

0 comments on commit e713953

Please sign in to comment.