Skip to content

Commit

Permalink
Refactor using python-common-utility (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaGombosER authored Sep 6, 2024
1 parent 4e77bd1 commit f894d21
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 80 deletions.
1 change: 1 addition & 0 deletions .devcontainer
Submodule .devcontainer added at 190f80
30 changes: 0 additions & 30 deletions .github/workflows/python-release.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/python-test.yml

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/test_and_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test and Release

on:
push:
branches: main
tags: v*.*.*

pull_request:
branches: [ "main" ]
types:
- synchronize
- opened
- reopened

concurrency:
group: ${{ github.workflow }}-${{ github.sha }}
cancel-in-progress: true

jobs:
test:
name: Build and test

runs-on: ubuntu-latest

permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
contents: write
statuses: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python-apt-dev python3-apt
- name: Verify changes
uses: EffectiveRange/python-verify-github-action@v1
with:
coverage-threshold: '95'

release:
if: startsWith(github.ref, 'refs/tags/')
needs: test

name: Publish and release

runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python-apt-dev python3-apt
- name: Package and publish
uses: EffectiveRange/python-package-github-action@v2
with:
debian-dist-type: 'fpm-deb'
- name: Release
uses: EffectiveRange/version-release-github-action@v1
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule ".devcontainer"]
path = .devcontainer
url = https://github.com/EffectiveRange/devcontainer-defs
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

[![Test and Release](https://github.com/EffectiveRange/debian-package-installer/actions/workflows/test_and_release.yml/badge.svg)](https://github.com/EffectiveRange/debian-package-installer/actions/workflows/test_and_release.yml)
[![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/EffectiveRange/debian-package-installer/python-coverage-comment-action-data/endpoint.json)](https://htmlpreview.github.io/?https://github.com/EffectiveRange/debian-package-installer/blob/python-coverage-comment-action-data/htmlcov/index.html)

# debian-package-installer

Debian package installer that supports installing from APT repository, .deb file URL and .deb GitHub release asset
Expand Down Expand Up @@ -59,7 +63,7 @@ pip install .

### Command line reference

```commandline
```bash
$ bin/debian-package-installer.py --help
usage: debian-package-installer.py [-h] [-f LOG_FILE] [-l LOG_LEVEL] [-s SOURCE_CONFIG] [-d DOWNLOAD] package_config
Expand All @@ -80,7 +84,7 @@ options:

### Example

```commandline
```bash
$ bin/debian-package-installer.py ~/config/package-config.json
```

Expand Down Expand Up @@ -115,7 +119,7 @@ Example configuration (example `package-config.json` config file content):

Needs root privileges to add APT keys:

```commandline
```bash
$ sudo bin/debian-package-installer.py ~/config/package-config.json -s ~/config/source-config.json
```

Expand Down Expand Up @@ -146,7 +150,7 @@ Example source configuration (example `source-config.json` config file content):

Output:

```commandline
```bash
2024-07-04T07:16:37.793684Z [info ] Starting package installer [PackageInstallerApp] app_version=1.0.0 application=debian-package-installer arguments={'log_file': None, 'log_level': 'info', 'source_config': 'build/source-config.json', 'download': '/tmp/packages', 'package_config': 'build/package-config.json'} hostname=Legion7iPro
2024-07-04T07:16:37.794110Z [info ] Local file path provided, skipping download [FileDownloader] app_version=1.0.0 application=debian-package-installer file=/home/attilagombos/EffectiveRange/debian-package-installer/build/source-config.json hostname=Legion7iPro
2024-07-04T07:16:37.906907Z [info ] Local file path provided, skipping download [FileDownloader] app_version=1.0.0 application=debian-package-installer file=/home/attilagombos/EffectiveRange/debian-package-installer/build/package-config.json hostname=Legion7iPro
Expand Down
9 changes: 5 additions & 4 deletions bin/debian-package-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from apt.cache import Cache
from aptsources.sourceslist import SourcesList
from common_utility import JsonLoader, SessionProvider, FileDownloader
from context_logger import get_logger, setup_logging
from package_downloader import FileDownloader, DebDownloader, AssetDownloader, RepositoryProvider, \
SessionProvider, JsonLoader
from package_downloader import DebDownloader, AssetDownloader, RepositoryProvider

from package_installer import PackageInstaller, DebInstaller, AptInstaller, DebProvider, SourceAdder, KeyAdder

Expand Down Expand Up @@ -48,8 +48,9 @@ def main() -> None:

package_config_path = file_downloader.download(arguments.package_config, skip_if_exists=False)

package_installer = PackageInstaller(package_config_path, json_loader,
apt_cache, apt_installer, deb_installer, source_adder)
package_installer = PackageInstaller(
package_config_path, json_loader, apt_cache, apt_installer, deb_installer, source_adder
)

package_installer.install_packages()

Expand Down
15 changes: 12 additions & 3 deletions package_installer/packageInstaller.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# SPDX-FileCopyrightText: 2024 Ferenc Nandor Janky <[email protected]>
# SPDX-FileCopyrightText: 2024 Attila Gombos <[email protected]>
# SPDX-License-Identifier: MIT

from typing import Optional

from apt import Cache
from common_utility import IJsonLoader
from context_logger import get_logger
from package_downloader import IJsonLoader, PackageConfig
from package_downloader import PackageConfig

from package_installer import IAptInstaller, IDebInstaller, ISourceAdder

Expand All @@ -14,8 +16,15 @@

class PackageInstaller(object):

def __init__(self, config_path: str, json_loader: IJsonLoader, apt_cache: Cache, apt_installer: IAptInstaller,
deb_installer: IDebInstaller, source_adder: Optional[ISourceAdder] = None) -> None:
def __init__(
self,
config_path: str,
json_loader: IJsonLoader,
apt_cache: Cache,
apt_installer: IAptInstaller,
deb_installer: IDebInstaller,
source_adder: Optional[ISourceAdder] = None,
) -> None:
self._config_path = config_path
self._json_loader = json_loader
self._apt_cache = apt_cache
Expand Down
12 changes: 9 additions & 3 deletions package_installer/sourceAdder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from urllib.parse import urlparse

from aptsources.sourceslist import SourcesList, SourceEntry
from common_utility import IJsonLoader, IFileDownloader
from context_logger import get_logger
from package_downloader import IFileDownloader, IJsonLoader

from package_installer import SourceConfig, IKeyAdder

Expand All @@ -21,8 +21,14 @@ def add_sources(self) -> None:

class SourceAdder(ISourceAdder):

def __init__(self, config_path: str, json_loader: IJsonLoader, sources_list: SourcesList, key_adder: IKeyAdder,
file_downloader: IFileDownloader) -> None:
def __init__(
self,
config_path: str,
json_loader: IJsonLoader,
sources_list: SourcesList,
key_adder: IKeyAdder,
file_downloader: IFileDownloader,
) -> None:
self._config_path = config_path
self._json_loader = json_loader
self._sources_list = sources_list
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[pack-python]
packaging =
wheel
fpm-deb

[mypy]
packages = bin,package_installer
strict = True
Expand Down
19 changes: 12 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@


def get_python_apt_version() -> str:
proc = subprocess.Popen(['dpkg-query', '-W', '-f', '${Version}', 'python3-apt'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.Popen(
['dpkg-query', '-W', '-f', '${Version}', 'python3-apt'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)

out, _ = proc.communicate()

Expand All @@ -20,7 +21,10 @@ def get_python_apt_version() -> str:
version = 'a1ecf380cb6688a239c30f2786424f864e9b32af'
return version

logging.error('Failed to get python-apt version. Please install python3-apt debian package.')
logging.error(
'Failed to get python-apt version. Please install python3-apt and python-apt-dev debian packages:\n'
'"sudo apt install -y python3-apt python-apt-dev"'
)

exit(1)

Expand All @@ -39,8 +43,9 @@ def clean_version(version: str) -> str:
packages=['package_installer'],
scripts=['bin/debian-package-installer.py'],
package_data={'package_installer': ['py.typed']},
install_requires=[f'python-apt@git+https://salsa.debian.org/apt-team/python-apt@{get_python_apt_version()}',
'python-context-logger@git+https://github.com/EffectiveRange/python-context-logger.git@latest',
'debian-package-downloader'
'@git+https://github.com/EffectiveRange/debian-package-downloader.git@latest']
install_requires=[
f'python-apt@git+https://salsa.debian.org/apt-team/python-apt@{get_python_apt_version()}',
'python-context-logger@git+https://github.com/EffectiveRange/python-context-logger.git@latest',
'debian-package-downloader@git+https://github.com/EffectiveRange/debian-package-downloader.git@latest',
],
)
Empty file removed tests/__init__.py
Empty file.

0 comments on commit f894d21

Please sign in to comment.