dots/addins/package.xsh
2021-09-22 21:39:20 -04:00

40 lines
960 B
Text

from .version import Version
v = Version()
class Package:
def __init__(self, name, source):
self.name = name
self.source = source
self._installed = None
@property
def installed(self):
self._installed = self._get_installed()
return self._installed
def _get_installed(self) -> bool:
if self.source == 'apt':
if !(dpkg -s @(self.name)).returncode == 0:
return True
else:
return False
if self.source == 'npm':
if !(npm list -g --parseable --silent @(self.name)).returncode == 0:
return True
else:
return False
else:
return None
def install(self):
if self.installed:
print(f"package '{self.name}' already installed.")
elif self.source == 'apt':
$(sudo apt-get install -qq --yes @(self.name))
elif self.source == 'npm':
$(npm install -g --silent --yes @(self.name))
elif self.source == 'pacman':
$(pacman -Syu @(self.name))
else:
print(f"unsupported package manager '{source}'.")