dots/addins/package.xsh

41 lines
960 B
Text
Raw Normal View History

2021-09-22 07:52:45 +00:00
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':
2021-09-23 01:39:20 +00:00
if !(npm list -g --parseable --silent @(self.name)).returncode == 0:
2021-09-22 07:52:45 +00:00
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':
2021-09-23 01:39:20 +00:00
$(npm install -g --silent --yes @(self.name))
2021-09-22 07:52:45 +00:00
elif self.source == 'pacman':
$(pacman -Syu @(self.name))
else:
print(f"unsupported package manager '{source}'.")
2021-09-23 01:39:20 +00:00