Exemplo n.º 1
0
def set_default_remotes(installation: str,
                        root_password: str = None) -> SimpleProcess:
    cmd = [
        'flatpak', 'remote-add', '--if-not-exists', 'flathub',
        'https://flathub.org/repo/flathub.flatpakrepo',
        '--{}'.format(installation)
    ]
    return SimpleProcess(cmd, root_password=root_password)
Exemplo n.º 2
0
    def _get_axel_process(self, url: str, output_path: str, cwd: str,
                          root_password: str, threads: int) -> SimpleProcess:
        cmd = ['axel', url, '-n', str(threads), '-4', '-c', '-T', '5']

        if output_path:
            cmd.append('--output={}'.format(output_path))

        return SimpleProcess(cmd=cmd, cwd=cwd, root_password=root_password)
Exemplo n.º 3
0
def downgrade(app_ref: str, commit: str, installation: str, root_password: str) -> SimpleProcess:
    cmd = ['flatpak', 'update', '--no-related', '--no-deps', '--commit={}'.format(commit), app_ref, '-y', '--{}'.format(installation)]

    return SimpleProcess(cmd=cmd,
                         root_password=root_password if installation=='system' else None,
                         extra_paths={EXPORTS_PATH},
                         success_phrases={'Changes complete.', 'Updates complete.'},
                         wrong_error_phrases={'Warning'})
Exemplo n.º 4
0
def install(app_id: str, origin: str, installation: str,
            version: Version) -> SimpleProcess:
    return SimpleProcess(
        cmd=('flatpak', 'install', origin, app_id, '-y', f'--{installation}'),
        extra_paths={EXPORTS_PATH},
        lang=DEFAULT_LANG if version < VERSION_1_12 else None,
        wrong_error_phrases={'Warning'} if version < VERSION_1_12 else None,
        shell=True)
Exemplo n.º 5
0
    def _get_wget_process(self, url: str, output_path: str, cwd: str) -> SimpleProcess:
        cmd = ['wget', url, '--continue', '--retry-connrefused', '--tries=10', '--no-config']

        if output_path:
            cmd.append('-O')
            cmd.append(output_path)

        return SimpleProcess(cmd=cmd, cwd=cwd)
Exemplo n.º 6
0
def install_and_stream(app_name: str, confinement: str, root_password: str) -> SimpleProcess:

    install_cmd = [BASE_CMD, 'install', app_name]  # default

    if confinement == 'classic':
        install_cmd.append('--classic')

    # return new_root_subprocess(install_cmd, root_password)
    return SimpleProcess(install_cmd, root_password=root_password)
Exemplo n.º 7
0
def download(root_password: str, *pkgnames: str) -> SimpleProcess:
    return SimpleProcess(cmd=['pacman', '-Swdd', *pkgnames, '--noconfirm'],
                         root_password=root_password,
                         error_phrases={
                             'error: failed to prepare transaction',
                             'error: failed to commit transaction',
                             'error: target not found'
                         },
                         shell=True)
Exemplo n.º 8
0
def is_api_available() -> Tuple[bool, str]:
    output = StringIO()
    for o in SimpleProcess(['snap', 'search']).instance.stdout:
        if o:
            output.write(o.decode())

    output.seek(0)
    output = output.read()
    return 'error:' not in output, output
Exemplo n.º 9
0
    def request_reboot(self, msg: str) -> bool:
        if self.request_confirmation(title=self.i18n['action.request_reboot.title'],
                                     body=msg,
                                     confirmation_label=self.i18n['yes'].capitalize(),
                                     deny_label=self.i18n['bt.not_now']):
            ProcessHandler(self).handle_simple(SimpleProcess(['reboot']))
            return True

        return False
Exemplo n.º 10
0
    def _rm_bad_file(self, file_name: str, output_path: str, cwd,
                     handler: ProcessHandler, root_password: Optional[str]):
        to_delete = output_path if output_path else f'{cwd}/{file_name}'

        if to_delete and os.path.exists(to_delete):
            self.logger.info(f'Removing downloaded file {to_delete}')
            success, _ = handler.handle_simple(
                SimpleProcess(['rm', '-rf', to_delete],
                              root_password=root_password))
            return success
Exemplo n.º 11
0
def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> List[str]:
    try:
        p = SimpleProcess(['flatpak', 'remote-info', '--log', origin, app_ref, '--{}'.format(installation)])
        success, output = handler.handle_simple(p)
        if output.startswith('error:'):
            return
        else:
            return re.findall(r'Commit+:\s(.+)', output)
    except:
        raise NoInternetException()
Exemplo n.º 12
0
def get_dependencies_to_remove(pkgs: Iterable[str],
                               root_password: str) -> Dict[str, str]:
    proc = SimpleProcess(cmd=['pacman', '-R', *pkgs, '--confirm'],
                         root_password=root_password)
    success, output = ProcessHandler().handle_simple(proc)

    if not output:
        return {}

    return {t[1]: t[0] for t in RE_REMOVE_TRANSITIVE_DEPS.findall(output)}
Exemplo n.º 13
0
 def remove(self,
            packages: Iterable[str],
            root_password: Optional[str],
            purge: bool = False) -> SimpleProcess:
     return SimpleProcess(cmd=self.gen_remove_cmd(packages,
                                                  purge).split(' '),
                          shell=True,
                          root_password=root_password,
                          extra_env=self.vars_fixes,
                          preserve_env=self._preserve_env)
Exemplo n.º 14
0
def update(app_ref: str, installation: str, related: bool = False, deps: bool = False) -> SimpleProcess:
    cmd = ['flatpak', 'update', '-y', app_ref, '--{}'.format(installation)]

    if not related:
        cmd.append('--no-related')

    if not deps:
        cmd.append('--no-deps')

    return SimpleProcess(cmd=cmd, extra_paths={EXPORTS_PATH}, shell=True)
Exemplo n.º 15
0
    def _trim_disk(self, root_password: Optional[str]):
        self.change_status('{}...'.format(self.i18n['action.disk_trim'].capitalize()))
        self.change_substatus('')

        success, output = ProcessHandler(self).handle_simple(SimpleProcess(['fstrim', '/', '-v'], root_password=root_password))

        if not success:
            self.show_message(title=self.i18n['success'].capitalize(),
                              body=self.i18n['action.disk_trim.error'],
                              type_=MessageType.ERROR)
Exemplo n.º 16
0
def install(url: str, name: str, output_dir: str, electron_version: Optional[str], cwd: str, system: bool, extra_options: List[str] = None) -> SimpleProcess:
    cmd = [NATIVEFIER_BIN_PATH if not system else 'nativefier', url, '--name', name, output_dir]

    if electron_version:
        cmd.append('-e')
        cmd.append(electron_version)

    if extra_options:
        cmd.extend(extra_options)

    return SimpleProcess(cmd, cwd=cwd, extra_paths=NODE_PATHS if not system else None)
Exemplo n.º 17
0
    def _rm_bad_file(self, file_name: str, output_path: str, cwd,
                     handler: ProcessHandler, root_password: str):
        to_delete = output_path if output_path else '{}/{}'.format(
            cwd, file_name)

        if to_delete and os.path.exists(to_delete):
            self.logger.info('Removing downloaded file {}'.format(to_delete))
            success, _ = handler.handle_simple(
                SimpleProcess(['rm', '-rf', to_delete],
                              root_password=root_password))
            return success
Exemplo n.º 18
0
    def _get_axel_process(self, url: str, output_path: str, cwd: str,
                          root_password: str, threads: int) -> SimpleProcess:
        cmd = [
            'axel', url, '--num-connections={}'.format(threads), '--ipv4',
            '--no-clobber', '--timeout=5'
        ]

        if output_path:
            cmd.append('--output={}'.format(output_path))

        return SimpleProcess(cmd=cmd, cwd=cwd, root_password=root_password)
Exemplo n.º 19
0
def refresh_and_stream(app_name: str,
                       root_password: str,
                       channel: Optional[str] = None) -> SimpleProcess:
    cmd = [BASE_CMD, 'refresh', app_name]

    if channel:
        cmd.append('--channel={}'.format(channel))

    return SimpleProcess(cmd=cmd,
                         root_password=root_password,
                         error_phrases={'no updates available'},
                         shell=True)
Exemplo n.º 20
0
def remove_several(pkgnames: Iterable[str],
                   root_password: str,
                   skip_checks: bool = False) -> SimpleProcess:
    cmd = ['pacman', '-R', *pkgnames, '--noconfirm']

    if skip_checks:
        cmd.append('-dd')

    return SimpleProcess(cmd=cmd,
                         root_password=root_password,
                         wrong_error_phrases={'warning:'},
                         shell=True)
Exemplo n.º 21
0
    def _get_wget_process(self, url: str, output_path: str, cwd: str,
                          root_password: str) -> SimpleProcess:
        cmd = [
            'wget', url, '-c', '--retry-connrefused', '-t', '10',
            '--no-config', '-nc'
        ]

        if output_path:
            cmd.append('-O')
            cmd.append(output_path)

        return SimpleProcess(cmd=cmd, cwd=cwd, root_password=root_password)
Exemplo n.º 22
0
def refresh_and_stream(app_name: str,
                       root_password: Optional[str],
                       channel: Optional[str] = None) -> SimpleProcess:
    cmd = ['snap', 'refresh', app_name]

    if channel:
        cmd.append(f'--channel={channel}')

    return SimpleProcess(cmd=cmd,
                         root_password=root_password,
                         lang=None,
                         shell=True)
Exemplo n.º 23
0
    def _get_axel_process(self, url: str, output_path: str, cwd: str,
                          root_password: Optional[str],
                          threads: int) -> SimpleProcess:
        cmd = ['axel', url, '-n', str(threads), '-4', '-c', '-T', '5']

        if not self.check_ssl:
            cmd.append('-k')

        if output_path:
            cmd.append(f'--output={output_path}')

        return SimpleProcess(cmd=cmd, cwd=cwd, root_password=root_password)
Exemplo n.º 24
0
def downgrade(app_ref: str, commit: str, installation: str,
              root_password: Optional[str], version: Version) -> SimpleProcess:
    cmd = ('flatpak', 'update', '--no-related', '--no-deps',
           f'--commit={commit}', app_ref, '-y', f'--{installation}')

    return SimpleProcess(
        cmd=cmd,
        root_password=root_password if installation == 'system' else None,
        extra_paths={EXPORTS_PATH},
        lang=DEFAULT_LANG if version < VERSION_1_12 else None,
        success_phrases={'Changes complete.', 'Updates complete.'}
        if version < VERSION_1_12 else None,
        wrong_error_phrases={'Warning'} if version < VERSION_1_12 else None)
Exemplo n.º 25
0
def install_and_stream(app_name: str,
                       confinement: str,
                       root_password: str,
                       channel: Optional[str] = None) -> SimpleProcess:

    install_cmd = [BASE_CMD, 'install', app_name]  # default

    if confinement == 'classic':
        install_cmd.append('--classic')

    if channel:
        install_cmd.append('--channel={}'.format(channel))

    return SimpleProcess(install_cmd, root_password=root_password, shell=True)
Exemplo n.º 26
0
def make(pkgdir: str, optimize: bool,
         handler: ProcessHandler) -> Tuple[bool, str]:
    cmd = ['makepkg', '-ALcsmf', '--skipchecksums']

    if optimize:
        if os.path.exists(CUSTOM_MAKEPKG_FILE):
            handler.watcher.print(
                'Using custom makepkg.conf -> {}'.format(CUSTOM_MAKEPKG_FILE))
            cmd.append('--config={}'.format(CUSTOM_MAKEPKG_FILE))
        else:
            handler.watcher.print(
                'Custom optimized makepkg.conf ( {} ) not found'.format(
                    CUSTOM_MAKEPKG_FILE))

    return handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir))
Exemplo n.º 27
0
    def _get_wget_process(self, url: str, output_path: str, cwd: str,
                          root_password: Optional[str]) -> SimpleProcess:
        cmd = [
            'wget', url, '-c', '--retry-connrefused', '-t', '10',
            '--no-config', '-nc'
        ]

        if not self.check_ssl:
            cmd.append('--no-check-certificate')

        if output_path:
            cmd.append('-O')
            cmd.append(output_path)

        return SimpleProcess(cmd=cmd, cwd=cwd, root_password=root_password)
Exemplo n.º 28
0
    def _install_node_lib(self, name: str, version: str, handler: ProcessHandler):
        lib_repr = '{}{}'.format(name, '@{}'.format(version) if version else '')
        self.logger.info("Installing {}".format(lib_repr))

        if handler and handler.watcher:
            handler.watcher.change_substatus(self.i18n['web.environment.install'].format(bold(lib_repr)))

        proc = SimpleProcess([NPM_BIN_PATH, 'install', lib_repr], cwd=ENV_PATH, extra_paths=NODE_PATHS)

        installed = handler.handle_simple(proc)[0]

        if installed:
            self.logger.info("{} successfully installed".format(lib_repr))

        return installed
Exemplo n.º 29
0
def upgrade_several(
        pkgnames: Iterable[str],
        root_password: str,
        overwrite_conflicting_files: bool = False) -> SimpleProcess:
    cmd = ['pacman', '-S', *pkgnames, '--noconfirm']

    if overwrite_conflicting_files:
        cmd.append('--overwrite=*')

    return SimpleProcess(cmd=cmd,
                         root_password=root_password,
                         error_phrases={
                             'error: failed to prepare transaction',
                             'error: failed to commit transaction',
                             'error: target not found'
                         })
Exemplo n.º 30
0
def check(pkgdir: str, handler: ProcessHandler) -> dict:
    res = {}
    success, output = handler.handle_simple(
        SimpleProcess(
            ['makepkg', '-ALcf', '--check', '--noarchive', '--nobuild'],
            cwd=pkgdir))

    if 'Missing dependencies' in output:
        res['missing_deps'] = RE_DEPS_PATTERN.findall(output)

    gpg_keys = RE_UNKNOWN_GPG_KEY.findall(output)

    if gpg_keys:
        res['gpg_key'] = gpg_keys[0]

    return res