1
0
Fork 0

create appimage_install function

This commit is contained in:
Kim, Jimin 2022-11-12 00:46:23 +09:00
parent 4d53cbd48c
commit 2b59ebcea8
4 changed files with 41 additions and 29 deletions

View file

@ -28,3 +28,4 @@ def initialize():
install_via_pip("requests")
install_via_pip("PyYAML")
install_via_pip("inquirer")
install_via_pip("tqdm")

View file

@ -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",
)

View file

@ -1,9 +0,0 @@
from src.util import paru_install
name = "AppImage Launcher"
def setup():
"""Manages AppImage files"""
paru_install("appimagelauncher")

View file

@ -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.