diff --git a/README.md b/README.md new file mode 100644 index 00000000..62b911d8 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +## fpakman +Graphical interface for Flatpak application management. It has also a tray icon to let the user known when new updates are available. +Wriiten in Python for QT5. + +### Roadmap +- Test installer for Ubuntu +- Load the database in a thread when the application starts. It will prevent the delay of showing the icon. +- Locales +- System notification whe new updates +- Search and install applications. \ No newline at end of file diff --git a/app.py b/app.py old mode 100644 new mode 100755 diff --git a/core/flatpak.py b/core/flatpak.py index 89b4a6f5..fb049174 100755 --- a/core/flatpak.py +++ b/core/flatpak.py @@ -1,7 +1,8 @@ import re -import subprocess from typing import List +from core import system + def app_str_to_json(line: str, version: str) -> dict: @@ -40,22 +41,17 @@ def app_str_to_json(line: str, version: str) -> dict: return app -def _run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False) -> str: - res = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE) - return res.stdout.decode() if ignore_return_code or res.returncode == expected_code else None - - def get_version(): - res = _run_cmd('flatpak --version') + res = system.run_cmd('flatpak --version') return res.split(' ')[1].strip() if res else None def get_app_info(app_id: str): - return _run_cmd('flatpak info ' + app_id) + return system.run_cmd('flatpak info ' + app_id) def list_installed() -> List[dict]: - apps_str = _run_cmd('flatpak list') + apps_str = system.run_cmd('flatpak list') if apps_str: version = get_version() @@ -66,8 +62,8 @@ def list_installed() -> List[dict]: def update(ref: str): - return bool(_run_cmd('flatpak update -y ' + ref)) + return bool(system.run_cmd('flatpak update -y ' + ref)) def list_updates_as_str(): - return _run_cmd('flatpak update', ignore_return_code=True) + return system.run_cmd('flatpak update', ignore_return_code=True) diff --git a/core/system.py b/core/system.py new file mode 100644 index 00000000..dcd9a138 --- /dev/null +++ b/core/system.py @@ -0,0 +1,6 @@ +import subprocess + + +def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False) -> str: + res = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE) + return res.stdout.decode() if ignore_return_code or res.returncode == expected_code else None diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..aea3a644 --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +/home/dafiti/workspace/fpakman/env/bin/python /home/dafiti/workspace/fpakman/app.py \ No newline at end of file diff --git a/sandbox_installer.py b/sandbox_installer.py new file mode 100755 index 00000000..f51adb5b --- /dev/null +++ b/sandbox_installer.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +################################################################ +# It installs the application without compromising you system. # +# libraries. 'qt5' is required to be installed. # +# # +# If you use GTK, install 'libappindicator3' also. # +# # +# EXECUTE THIS SCRIPT INSIDE THE PROJECT FOLDER AS ROOT # +# # +################################################################ +import os +import sys +from shutil import rmtree + +from core import system, flatpak + +if not os.geteuid() == 0: + sys.exit("\nOnly root can run this script\n") + + +link_path = '/usr/local/bin/fpakman' +runner_file = 'run.sh' +env_name = 'env' + + +def log(msg: str): + print('[fpakman] {}'.format(msg)) + + +if os.path.exists(link_path): + log('already installed') + log('Do you wish to uninstall it ? (y/N)') + uninstall = input() + + if uninstall.lower() == 'y': + + try: + os.unlink(link_path) + except: + log("Could not remove the runner syslink '{}'".format(link_path)) + log("Aborting...") + exit(1) + + if os.path.exists('{}/{}'.format(os.getcwd(), env_name)): + try: + rmtree(env_name) + except: + log("Could not remove the virtualenv '{}'".format(env_name)) + log("Aborting") + exit(1) + + if os.path.exists('{}/{}'.format(os.getcwd(), runner_file)): + + try: + os.remove(runner_file) + except: + log("Could not remove the runner file '{}'".format(runner_file)) + log("Aborting...") + exit(1) + + log("Successfully uninstalled") + + else: + log('Aborting...') +else: + if flatpak.get_version is None: + print('flatpak seems not to be installed. Aborting...') + exit(1) + + if not os.path.exists('env'): + log("Creating a new 'virtualenv' as '{}'...".format(env_name)) + res = system.run_cmd('python3 -m venv ' + env_name) + + if res is None: + log("Could create a virtualenv for installation. Check if 'virtualenv' is installed.") + log('Aborting...') + exit(1) + + res = system.run_cmd('env/bin/pip install -r requirements.txt') + + if res: + log("Creating runner as '{}'".format(runner_file)) + with open('run.sh', 'w+') as f: + f.write('#!/bin/bash\n{d}/env/bin/python {d}/app.py'.format(d=os.getcwd())) + + system.run_cmd('chmod +x ' + runner_file) + + log("Creating syslink as '{}'".format(link_path)) + + try: + os.link('{}/{}'.format(os.getcwd(), runner_file), link_path) + except: + log("Could not create the syslink") + log("Aborting...") + exit(1) + + log('Successfully installed') + else: + log('Could not install python requirements to the virtualenv') + log('Aborting...') + exit(1)