Example #1
0
 def upgrade() -> None:
     logger.info('Upgrading snap packages')
     err, code = execute('snap refresh', onlyerror=True)
     if code != 0:
         logger.error(
             'Cannot upgrade snap packages (exited with %s). Stderr:\n%s' %
             (code, err))
Example #2
0
def install(*package_names) -> None:
    for name in package_names:
        logger.info('Installing pip package %s' % (name, ))
        err, code = execute('python3 -m pip install --upgrade %s' % (name, ),
                            check=False,
                            onlyerror=True)
        if code != 0:
            logger.error('Pip package %s cannot be installed. Stderr:\n%s' %
                         (name, err))
Example #3
0
def remove(*package_names) -> None:
    for name in package_names:
        logger.info('Removing pip package %s' % (name, ))
        err, code = execute('python3 -m pip uninstall %s' % (name, ),
                            check=False,
                            onlyerror=True)
        if code != 0:
            logger.error('Pip package %s cannot be removed. Stderr:\n%s' %
                         (name, err))
Example #4
0
    def install(*package_names) -> None:

        for name in package_names:

            logger.info('Installing snap package %s' % (name, ))
            if execute('snap info %s' % (name, ), onlycode=True) != 0:
                logger.error('Snap package %s not found!' % (name, ))
                continue

            if name in list_all():
                logger.warning('Snap package %s already installed!' % (name, ))
                continue

            err, code = execute('snap install %s' % (name, ),
                                check=False,
                                onlyerror=True)
            if code != 0:
                logger.error(
                    'Snap package %s cannot be installed (exited with %s). Stderr:\n%s'
                    % (name, code, err))
Example #5
0
 def list_all() -> list:
     packages_raw = execute('snap list', combine=True, code=False)
     packages_pre = packages_raw.rsplit('\n')[1:-1]
     packages_post = [e[0:e.find(' ')] for e in packages_pre]
     return packages_post
Example #6
0
def command_exists(name) -> bool:
    if execute('command -v %s' % (name, ), check=False, onlycode=True) == 0:
        return True
    else:
        return False