create appimage_install function
This commit is contained in:
parent
4d53cbd48c
commit
2b59ebcea8
4 changed files with 41 additions and 29 deletions
|
@ -28,3 +28,4 @@ def initialize():
|
|||
install_via_pip("requests")
|
||||
install_via_pip("PyYAML")
|
||||
install_via_pip("inquirer")
|
||||
install_via_pip("tqdm")
|
||||
|
|
|
@ -1,24 +1,12 @@
|
|||
import requests
|
||||
from pathlib import Path
|
||||
|
||||
from src.setup.system import appimagelauncher
|
||||
|
||||
from src.util import appimage_install
|
||||
|
||||
name = "Notesnook"
|
||||
|
||||
|
||||
def setup():
|
||||
"""FOSS video editing utility"""
|
||||
"""FOSS Note taking utility"""
|
||||
|
||||
download_path = f"{Path.home()}/Applications/notesnook_linux_x86_64.AppImage"
|
||||
download_url = (
|
||||
"https://notesnook.com/releases/linux/notesnook_linux_x86_64.AppImage"
|
||||
)
|
||||
|
||||
appimagelauncher.setup()
|
||||
|
||||
print(f"Downloading AppImage file to {download_path}")
|
||||
Path(download_path).mkdir(parents=True, exist_ok=True)
|
||||
open(download_path, "wb").write(
|
||||
requests.get(download_url, allow_redirects=True).content
|
||||
appimage_install(
|
||||
"https://notesnook.com/releases/linux/notesnook_linux_x86_64.AppImage",
|
||||
"notesnook_linux_x86_64",
|
||||
)
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
from src.util import paru_install
|
||||
|
||||
name = "AppImage Launcher"
|
||||
|
||||
|
||||
def setup():
|
||||
"""Manages AppImage files"""
|
||||
|
||||
paru_install("appimagelauncher")
|
38
src/util.py
38
src/util.py
|
@ -1,10 +1,13 @@
|
|||
from importlib.machinery import SourceFileLoader
|
||||
from os import system, makedirs, popen
|
||||
from os.path import dirname
|
||||
from os import system, makedirs, popen, remove
|
||||
from os.path import dirname, exists
|
||||
from tqdm.auto import tqdm
|
||||
from pathlib import Path
|
||||
import requests
|
||||
import zipfile
|
||||
import shutil
|
||||
|
||||
from src.log import error
|
||||
from src.log import error, log
|
||||
import src.constants
|
||||
|
||||
|
||||
|
@ -46,6 +49,35 @@ def flatpak_install(packages: str) -> None:
|
|||
system(f"flatpak install -y {packages}")
|
||||
|
||||
|
||||
def appimage_install(file_url: str, file_name: str) -> None:
|
||||
"""
|
||||
Install app by downloading .AppImage file to ~/Applications
|
||||
"""
|
||||
|
||||
download_path = f"{Path.home()}/Applications/{file_name}.AppImage"
|
||||
|
||||
# install AppImageLauncher if it's not installed already
|
||||
if system("command -v AppImageLauncher &> /dev/null"):
|
||||
paru_install("appimagelauncher")
|
||||
|
||||
log(f" Downloading AppImage file to {download_path}")
|
||||
log(f" URL: {file_url}")
|
||||
|
||||
Path(download_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if exists(download_path):
|
||||
remove(download_path)
|
||||
|
||||
with requests.get(file_url, stream=True) as r:
|
||||
total_length = int(r.headers.get("Content-Length"))
|
||||
|
||||
# show progress bar
|
||||
with tqdm.wrapattr(r.raw, "read", total=total_length, desc="") as raw:
|
||||
# save to file
|
||||
with open(download_path, "wb") as output:
|
||||
shutil.copyfileobj(raw, output)
|
||||
|
||||
|
||||
def smart_mkdir(path: str) -> None:
|
||||
"""
|
||||
Recursively create directories if it doesn't exist already.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue