Example #1
0
def ensure_service(service_name: str, user: bool = False) -> None:
    if user:
        if cmd_output(
                f"systemctl --user is-enabled {service_name}")[0] == "enabled":
            return

        print(f"Enabling user systemd service: {service_name}")
        subprocess.run(
            ["systemctl", "--user", "enable", "--now", service_name])
    else:
        if cmd_output(f"systemctl is-enabled {service_name}")[0] == "enabled":
            return

        print(f"Enabling systemd service: {service_name}")
        subprocess.run(["sudo", "systemctl", "enable", "--now", service_name])
Example #2
0
def installed_pkgs() -> Set[str]:
    return {line.split(" ")[0] for line in cmd_output("pacman -Q")}
Example #3
0
import shutil
import subprocess
import urllib.request as urllib
from tempfile import NamedTemporaryFile
from typing import Set

from cfgtools.system import SystemPackage
from cfgtools.utils import cmd_output

IS_UBUNTU = (
    shutil.which("lsb_release") is not None
    and cmd_output("lsb_release -i")[0] == "Distributor ID:	Ubuntu"
)


def installed_packages() -> Set[str]:
    return {pkg for pkg in cmd_output("dpkg-query -W --showformat='${Package}\n'")}


class Apt(SystemPackage):
    def __init__(self, name: str):
        self.name = name
        if IS_UBUNTU:
            super().__init__()

    def __repr__(self):
        return f"{self.__class__} {self.name}"

    @classmethod
    def dry_run(cls, *pkgs: "Apt") -> None:
        wanted = {pkg.name for pkg in pkgs}
Example #4
0
def installed_packages() -> Set[str]:
    return {pkg for pkg in cmd_output("dpkg-query -W --showformat='${Package}\n'")}
Example #5
0
File: nix.py Project: jdost/configs
def installed_pkgs() -> Set[str]:
    return {pkg.split('-', 1)[0] for pkg in cmd_output("nix-env --query")}