예제 #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))
예제 #2
0
    def install(*package_names) -> None:

        upgrade()

        cache = Cache()
        cache.update()
        cache.open()

        for name in package_names:

            if name not in cache:
                logger.error('Package %s not found!' % (name, ))
                continue

            package = cache[name]

            if package.is_installed:
                logger.warning('Package %s already installed!' % (name, ))
                continue

            package.mark_install()

        cache.commit(TextFetchProgress(), InstallProgress())

        cache.close()
예제 #3
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))
예제 #4
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))
예제 #5
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))
예제 #6
0
 def build(fp,
           tag,
           logs=False,
           remove=True,
           timeout=300,
           pull_image=True,
           **kwargs):
     logger.info('Building image %s from %s' % (tag, fp))
     try:
         image, log = get_client().images.build(path=fp,
                                                tag=tag,
                                                rm=remove,
                                                timeout=timeout,
                                                pull=pull_image,
                                                **kwargs)
         if logs:
             return (image, log)
         else:
             return image
     except BuildError:
         logger.error('Build for image from %s failed' % (fp, ))
예제 #7
0
 def get(name) -> Image:
     try:
         return get_client().images.get(name)
     except ImageNotFound:
         logger.error('Image %s not found..' % (name, ))