can execute files and install packages
This commit is contained in:
parent
230cf99f06
commit
f611ef603b
3 changed files with 42 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
@ -15,3 +16,11 @@ def set_execution_rights(file: Path):
|
|||
def save_and_make_executable(destination: Path, content: bytes):
|
||||
save(destination, content)
|
||||
set_execution_rights(destination)
|
||||
|
||||
|
||||
def install_package(file: Path) -> None:
|
||||
subprocess.Popen(("apt", "install", "-f", str(file)))
|
||||
|
||||
|
||||
def run(file: Path) -> None:
|
||||
subprocess.Popen((str(file)))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from majordome import local_files
|
||||
|
@ -49,3 +50,26 @@ def test_download_and_make_executable(clean_tmpdir):
|
|||
assert tmp_file.read_bytes() == file_content
|
||||
|
||||
assert tmp_file.stat().st_mode == 0o100775
|
||||
|
||||
|
||||
def test_install_package():
|
||||
file = Path("/home/stan/Téléchargements/freetube_0.23.2_amd64.deb")
|
||||
|
||||
local_files.install_package(file)
|
||||
|
||||
apt = subprocess.Popen(("apt", "list", "--installed"), stdout=subprocess.PIPE)
|
||||
output = subprocess.check_output(("grep", "freetube"), stdin=apt.stdout)
|
||||
apt.wait()
|
||||
assert "0.23.2" in output.decode("utf-8")
|
||||
|
||||
|
||||
def test_run():
|
||||
file = Path("/home/stan/Logiciels/Nextcloud-3.14.2-x86_64.AppImage")
|
||||
|
||||
local_files.run(file)
|
||||
|
||||
ps = subprocess.Popen(("ps", "-ef"), stdout=subprocess.PIPE)
|
||||
output = subprocess.check_output(("grep", str(file)), stdin=ps.stdout)
|
||||
ps.wait()
|
||||
assert output is not None
|
||||
assert str(file) in output.decode("utf-8")
|
||||
|
|
|
@ -3,10 +3,17 @@ from pathlib import Path
|
|||
from majordome import main
|
||||
|
||||
|
||||
def test_download_and_save_latest_asset(freetube_url, freetube_amd64_deb_mnemonic):
|
||||
def test_download_and_save_latest_asset(
|
||||
freetube_url, freetube_amd64_deb_mnemonic, freetube_tag_name_mnemonic
|
||||
):
|
||||
destination = Path(__file__).parent / "tmp"
|
||||
|
||||
main.download_latest(freetube_url, freetube_amd64_deb_mnemonic, destination)
|
||||
main.download_latest(
|
||||
freetube_url,
|
||||
freetube_amd64_deb_mnemonic,
|
||||
freetube_tag_name_mnemonic,
|
||||
destination,
|
||||
)
|
||||
|
||||
files = list(destination.glob("*"))
|
||||
assert len(files) == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue