Esempio n. 1
0
def remove_several(pkgnames: Iterable[str],
                   root_password: str) -> SystemProcess:
    cmd = ['pacman', '-R', *pkgnames, '--noconfirm']
    if root_password:
        return SystemProcess(new_root_subprocess(cmd, root_password),
                             wrong_error_phrase='warning:')
    else:
        return SystemProcess(new_subprocess(cmd),
                             wrong_error_phrase='warning:')
Esempio n. 2
0
    def uninstall(self, pkg: AppImage, root_password: Optional[str], watcher: ProcessWatcher, disk_loader: DiskCacheLoader = None) -> TransactionResult:
        if os.path.exists(pkg.get_disk_cache_path()):
            handler = ProcessHandler(watcher)

            if not handler.handle(SystemProcess(new_subprocess(['rm', '-rf', pkg.get_disk_cache_path()]))):
                watcher.show_message(title=self.i18n['error'], body=self.i18n['appimage.uninstall.error.remove_folder'].format(bold(pkg.get_disk_cache_path())))
                return TransactionResult.fail()

            de_path = self._gen_desktop_entry_path(pkg)
            if os.path.exists(de_path):
                os.remove(de_path)

            self.revert_ignored_update(pkg)

        if pkg.symlink and os.path.islink(pkg.symlink):
            self.logger.info(f"Removing symlink '{pkg.symlink}'")

            try:
                os.remove(pkg.symlink)
                self.logger.info(f"symlink '{pkg.symlink}' successfully removed")
            except:
                msg = f"could not remove symlink '{pkg.symlink}'"
                self.logger.error(msg)

                if watcher:
                    watcher.print(f"[error] {msg}")

        self._add_self_latest_version(pkg)  # only for self installation
        return TransactionResult(success=True, installed=None, removed=[pkg])
Esempio n. 3
0
    def upgrade(self, requirements: UpgradeRequirements, root_password: str, watcher: ProcessWatcher) -> bool:
        flatpak_version = flatpak.get_version()
        for req in requirements.to_upgrade:
            watcher.change_status("{} {} ({})...".format(self.i18n['manage_window.status.upgrading'], req.pkg.name, req.pkg.version))
            related, deps = False, False
            ref = req.pkg.ref

            if req.pkg.partial and flatpak_version < '1.5':
                related, deps = True, True
                ref = req.pkg.base_ref

            try:
                res = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.update(app_ref=ref,
                                                                                          installation=req.pkg.installation,
                                                                                          related=related,
                                                                                          deps=deps)))

                watcher.change_substatus('')
                if not res:
                    self.logger.warning("Could not upgrade '{}'".format(req.pkg.id))
                    return False
            except:
                watcher.change_substatus('')
                self.logger.error("An error occurred while upgrading '{}'".format(req.pkg.id))
                traceback.print_exc()
                return False

        watcher.change_substatus('')
        return True
Esempio n. 4
0
    def _get_aria2c_process(self, url: str, output_path: str, cwd: str) -> SystemProcess:
        cmd = ['aria2c', url,
               '--no-conf',
               '--max-connection-per-server=16',
               '--split=16',
               '--enable-color=false',
               '--stderr=true',
               '--summary-interval=0',
               '--disable-ipv6',
               '--min-split-size=1M',
               '--allow-overwrite=true',
               '--continue=true',
               '--timeout=5',
               '--max-file-not-found=3',
               '--remote-time=true']

        if output_path:
            output_split = output_path.split('/')
            cmd.append('--dir=' + '/'.join(output_split[:-1]))
            cmd.append('--out=' + output_split[-1])

        return SystemProcess(new_subprocess(cmd=cmd, cwd=cwd),
                             skip_stdout=True,
                             check_error_output=False,
                             success_phrases=['download completed'],
                             output_delay=0.001)
Esempio n. 5
0
    def uninstall(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:
        uninstalled = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.uninstall(pkg.ref)))

        if self.suggestions_cache:
            self.suggestions_cache.delete(pkg.id)

        return uninstalled
Esempio n. 6
0
    def downgrade(self, pkg: FlatpakApplication, root_password: str,
                  watcher: ProcessWatcher) -> bool:
        handler = ProcessHandler(watcher)
        pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation)

        watcher.change_progress(10)
        watcher.change_substatus(self.i18n['flatpak.downgrade.commits'])
        commits = flatpak.get_app_commits(pkg.ref, pkg.origin,
                                          pkg.installation, handler)

        if commits is None:
            return False

        commit_idx = commits.index(pkg.commit)

        # downgrade is not possible if the app current commit in the first one:
        if commit_idx == len(commits) - 1:
            watcher.show_message(
                self.i18n['flatpak.downgrade.impossible.title'],
                self.i18n['flatpak.downgrade.impossible.body'],
                MessageType.WARNING)
            return False

        commit = commits[commit_idx + 1]
        watcher.change_substatus(self.i18n['flatpak.downgrade.reverting'])
        watcher.change_progress(50)
        success = handler.handle(
            SystemProcess(
                subproc=flatpak.downgrade(pkg.ref, commit, pkg.installation,
                                          root_password),
                success_phrases=['Changes complete.', 'Updates complete.'],
                wrong_error_phrase='Warning'))
        watcher.change_progress(100)
        return success
Esempio n. 7
0
    def install(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:

        config = read_config()

        install_level = config['installation_level']

        if install_level is not None:
            self.logger.info("Default Flaptak installation level defined: {}".format(install_level))

            if install_level not in ('user', 'system'):
                watcher.show_message(title=self.i18n['error'].capitalize(),
                                     body=self.i18n['flatpak.install.bad_install_level.body'].format(field=bold('installation_level'),
                                                                                                     file=bold(CONFIG_FILE)),
                                     type_=MessageType.ERROR)
                return False

            pkg.installation = install_level
        else:
            user_level = watcher.request_confirmation(title=self.i18n['flatpak.install.install_level.title'],
                                                      body=self.i18n['flatpak.install.install_level.body'].format(bold(pkg.name)),
                                                      confirmation_label=self.i18n['no'].capitalize(),
                                                      deny_label=self.i18n['yes'].capitalize())
            pkg.installation = 'user' if user_level else 'system'

        remotes = flatpak.list_remotes()

        handler = ProcessHandler(watcher)

        if pkg.installation == 'user' and not remotes['user']:
            handler.handle_simple(flatpak.set_default_remotes('user'))
        elif pkg.installation == 'system' and not remotes['system']:
            if user.is_root():
                handler.handle_simple(flatpak.set_default_remotes('system'))
            else:
                user_password, valid = watcher.request_root_password()
                if not valid:
                    watcher.print('Operation aborted')
                    return False
                else:
                    if not handler.handle_simple(flatpak.set_default_remotes('system', user_password)):
                        watcher.show_message(title=self.i18n['error'].capitalize(),
                                             body=self.i18n['flatpak.remotes.system_flathub.error'],
                                             type_=MessageType.ERROR)
                        watcher.print("Operation cancelled")
                        return False

        res = handler.handle(SystemProcess(subproc=flatpak.install(str(pkg.id), pkg.origin, pkg.installation), wrong_error_phrase='Warning'))

        if res:
            try:
                fields = flatpak.get_fields(str(pkg.id), pkg.branch, ['Ref', 'Branch'])

                if fields:
                    pkg.ref = fields[0]
                    pkg.branch = fields[1]
            except:
                traceback.print_exc()

        return res
Esempio n. 8
0
    def _get_wget_process(self, url: str, output_path: str, cwd: str) -> SystemProcess:
        cmd = ['wget', url]

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

        return SystemProcess(new_subprocess(cmd, cwd=cwd))
Esempio n. 9
0
File: gpg.py Progetto: vinifmor/bauh
def receive_key(key: str, server: Optional[str] = None) -> SystemProcess:
    cmd = ['gpg']

    if server:
        cmd.extend(['--keyserver', server])

    cmd.extend(['--recv-key', key])

    return SystemProcess(new_subprocess(cmd), check_error_output=False)
Esempio n. 10
0
    def uninstall(self, pkg: SnapApplication, root_password: str,
                  watcher: ProcessWatcher) -> bool:
        uninstalled = ProcessHandler(watcher).handle(
            SystemProcess(
                subproc=snap.uninstall_and_stream(pkg.name, root_password)))

        if self.suggestions_cache:
            self.suggestions_cache.delete(pkg.name)

        return uninstalled
Esempio n. 11
0
    def install(self, pkg: SnapApplication, root_password: str,
                watcher: ProcessWatcher) -> bool:
        res, output = ProcessHandler(watcher).handle_simple(
            snap.install_and_stream(pkg.name, pkg.confinement, root_password))

        if 'error:' in output:
            res = False
            if 'not available on stable' in output:
                channels = RE_AVAILABLE_CHANNELS.findall(output)

                if channels:
                    opts = [
                        InputOption(label=c[0], value=c[1]) for c in channels
                    ]
                    channel_select = SingleSelectComponent(
                        type_=SelectViewType.RADIO,
                        label='',
                        options=opts,
                        default_option=opts[0])
                    body = '<p>{}.</p>'.format(
                        self.i18n['snap.install.available_channels.message'].
                        format(bold(self.i18n['stable']), bold(pkg.name)))
                    body += '<p>{}:</p>'.format(
                        self.i18n['snap.install.available_channels.help'])

                    if watcher.request_confirmation(
                            title=self.
                            i18n['snap.install.available_channels.title'],
                            body=body,
                            components=[channel_select],
                            confirmation_label=self.i18n['continue'],
                            deny_label=self.i18n['cancel']):
                        self.logger.info(
                            "Installing '{}' with the custom command '{}'".
                            format(pkg.name, channel_select.value))
                        res = ProcessHandler(watcher).handle(
                            SystemProcess(
                                new_root_subprocess(
                                    channel_select.value.value.split(' '),
                                    root_password=root_password)))

                        if res:
                            pkg.has_apps_field = snap.has_apps_field(
                                pkg.name, self.ubuntu_distro)

                        return res
                else:
                    self.logger.error(
                        "Could not find available channels in the installation output: {}"
                        .format(output))
        else:
            pkg.has_apps_field = snap.has_apps_field(pkg.name,
                                                     self.ubuntu_distro)

        return res
Esempio n. 12
0
def install_as_process(pkgpath: str,
                       root_password: str,
                       aur: bool,
                       pkgdir: str = '.') -> SystemProcess:
    if aur:
        cmd = ['pacman', '-U', pkgpath,
               '--noconfirm']  # pkgpath = install file path
    else:
        cmd = ['pacman', '-S', pkgpath, '--noconfirm']  # pkgpath = pkgname

    return SystemProcess(new_root_subprocess(cmd, root_password, cwd=pkgdir),
                         wrong_error_phrase='warning:')
Esempio n. 13
0
    def uninstall(self, pkg: AppImage, root_password: str, watcher: ProcessWatcher) -> bool:
        if os.path.exists(pkg.get_disk_cache_path()):
            handler = ProcessHandler(watcher)

            if not handler.handle(SystemProcess(new_subprocess(['rm', '-rf', pkg.get_disk_cache_path()]))):
                watcher.show_message(title=self.i18n['error'], body=self.i18n['appimage.uninstall.error.remove_folder'].format(bold(pkg.get_disk_cache_path())))
                return False

            de_path = self._gen_desktop_entry_path(pkg)
            if os.path.exists(de_path):
                os.remove(de_path)

        return True
Esempio n. 14
0
    def update(self, pkg: FlatpakApplication, root_password: str,
               watcher: ProcessWatcher) -> bool:
        related, deps = False, False
        ref = pkg.ref

        if pkg.partial and flatpak.get_version() < '1.5':
            related, deps = True, True
            ref = pkg.base_ref

        return ProcessHandler(watcher).handle(
            SystemProcess(subproc=flatpak.update(app_ref=ref,
                                                 installation=pkg.installation,
                                                 related=related,
                                                 deps=deps)))
Esempio n. 15
0
    def install(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:
        res = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.install(pkg.id, pkg.origin), wrong_error_phrase='Warning'))

        if res:
            try:
                fields = flatpak.get_fields(pkg.id, pkg.branch, ['Ref', 'Branch'])

                if fields:
                    pkg.ref = fields[0]
                    pkg.branch = fields[1]
            except:
                traceback.print_exc()

        return res
Esempio n. 16
0
    def uninstall(self, pkg: SnapApplication, root_password: str,
                  watcher: ProcessWatcher,
                  disk_loader: DiskCacheLoader) -> TransactionResult:
        uninstalled = ProcessHandler(watcher).handle(
            SystemProcess(
                subproc=snap.uninstall_and_stream(pkg.name, root_password)))

        if uninstalled:
            if self.suggestions_cache:
                self.suggestions_cache.delete(pkg.name)

            return TransactionResult(success=True,
                                     installed=None,
                                     removed=[pkg])

        return TransactionResult.fail()
Esempio n. 17
0
    def _uninstall(self, pkg_name: str, root_password: str,
                   handler: ProcessHandler) -> bool:
        res = handler.handle(
            SystemProcess(
                new_root_subprocess(['pacman', '-R', pkg_name, '--noconfirm'],
                                    root_password)))

        if res:
            cached_paths = [
                ArchPackage.disk_cache_path(pkg_name, 'aur'),
                ArchPackage.disk_cache_path(pkg_name, 'mirror')
            ]

            for path in cached_paths:
                if os.path.exists(path):
                    shutil.rmtree(path)
                    break

        return res
Esempio n. 18
0
    def downgrade(self, pkg: ArchPackage, root_password: str,
                  watcher: ProcessWatcher) -> bool:

        handler = ProcessHandler(watcher)
        app_build_dir = '{}/build_{}'.format(BUILD_DIR, int(time.time()))
        watcher.change_progress(5)

        try:
            if not os.path.exists(app_build_dir):
                build_dir = handler.handle(
                    SystemProcess(
                        new_subprocess(['mkdir', '-p', app_build_dir])))

                if build_dir:
                    watcher.change_progress(10)
                    watcher.change_substatus(self.i18n['arch.clone'].format(
                        bold(pkg.name)))
                    clone = handler.handle(
                        SystemProcess(subproc=new_subprocess(
                            ['git', 'clone',
                             URL_GIT.format(pkg.name)],
                            cwd=app_build_dir),
                                      check_error_output=False))
                    watcher.change_progress(30)
                    if clone:
                        watcher.change_substatus(
                            self.i18n['arch.downgrade.reading_commits'])
                        clone_path = '{}/{}'.format(app_build_dir, pkg.name)
                        pkgbuild_path = '{}/PKGBUILD'.format(clone_path)

                        commits = run_cmd("git log", cwd=clone_path)
                        watcher.change_progress(40)

                        if commits:
                            commit_list = re.findall(r'commit (.+)\n', commits)
                            if commit_list:
                                if len(commit_list) > 1:
                                    for idx in range(1, len(commit_list)):
                                        commit = commit_list[idx]
                                        with open(pkgbuild_path) as f:
                                            pkgdict = aur.map_pkgbuild(
                                                f.read())

                                        if not handler.handle(
                                                SystemProcess(
                                                    subproc=new_subprocess(
                                                        [
                                                            'git', 'reset',
                                                            '--hard', commit
                                                        ],
                                                        cwd=clone_path),
                                                    check_error_output=False)):
                                            watcher.print(
                                                'Could not downgrade anymore. Aborting...'
                                            )
                                            return False

                                        if '{}-{}'.format(
                                                pkgdict.get('pkgver'),
                                                pkgdict.get(
                                                    'pkgrel')) == pkg.version:
                                            # current version found
                                            watcher.change_substatus(self.i18n[
                                                'arch.downgrade.version_found']
                                                                     )
                                            break

                                    watcher.change_substatus(
                                        self.
                                        i18n['arch.downgrade.install_older'])
                                    return self._make_pkg(pkg.name,
                                                          pkg.maintainer,
                                                          root_password,
                                                          handler,
                                                          app_build_dir,
                                                          clone_path,
                                                          dependency=False,
                                                          skip_optdeps=True)
                                else:
                                    watcher.show_message(
                                        title=self.
                                        i18n['arch.downgrade.error'],
                                        body=self.
                                        i18n['arch.downgrade.impossible'].
                                        format(pkg.name),
                                        type_=MessageType.ERROR)
                                    return False

                        watcher.show_message(
                            title=self.i18n['error'],
                            body=self.i18n['arch.downgrade.no_commits'],
                            type_=MessageType.ERROR)
                        return False

        finally:
            if os.path.exists(app_build_dir):
                handler.handle(
                    SystemProcess(
                        subproc=new_subprocess(['rm', '-rf', app_build_dir])))

        return False
Esempio n. 19
0
    def install(self, pkg: SnapApplication, root_password: str,
                disk_loader: DiskCacheLoader,
                watcher: ProcessWatcher) -> TransactionResult:
        info_path = self.get_info_path()

        if not info_path:
            self.logger.warning(
                'Information directory was not found. It will not be possible to determine if the installed application can be launched'
            )

        # retrieving all installed so it will be possible to know the additional installed runtimes after the operation succeeds
        installed_names = snap.list_installed_names()

        res, output = ProcessHandler(watcher).handle_simple(
            snap.install_and_stream(pkg.name, pkg.confinement, root_password))

        if 'error:' in output:
            res = False
            if 'not available on stable' in output:
                channels = RE_AVAILABLE_CHANNELS.findall(output)

                if channels:
                    opts = [
                        InputOption(label=c[0], value=c[1]) for c in channels
                    ]
                    channel_select = SingleSelectComponent(
                        type_=SelectViewType.RADIO,
                        label='',
                        options=opts,
                        default_option=opts[0])
                    body = '<p>{}.</p>'.format(
                        self.i18n['snap.install.available_channels.message'].
                        format(bold(self.i18n['stable']), bold(pkg.name)))
                    body += '<p>{}:</p>'.format(
                        self.i18n['snap.install.available_channels.help'])

                    if watcher.request_confirmation(
                            title=self.
                            i18n['snap.install.available_channels.title'],
                            body=body,
                            components=[channel_select],
                            confirmation_label=self.i18n['continue'],
                            deny_label=self.i18n['cancel']):
                        self.logger.info(
                            "Installing '{}' with the custom command '{}'".
                            format(pkg.name, channel_select.value))
                        res = ProcessHandler(watcher).handle(
                            SystemProcess(
                                new_root_subprocess(
                                    channel_select.value.value.split(' '),
                                    root_password=root_password)))

                        if res and info_path:
                            pkg.has_apps_field = snap.has_apps_field(
                                pkg.name, info_path)

                        return self._gen_installation_response(
                            success=res,
                            pkg=pkg,
                            installed=installed_names,
                            disk_loader=disk_loader)
                else:
                    self.logger.error(
                        "Could not find available channels in the installation output: {}"
                        .format(output))
        else:
            if info_path:
                pkg.has_apps_field = snap.has_apps_field(pkg.name, info_path)

        return self._gen_installation_response(success=res,
                                               pkg=pkg,
                                               installed=installed_names,
                                               disk_loader=disk_loader)
Esempio n. 20
0
 def update(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:
     return ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.update(pkg.ref)))
Esempio n. 21
0
def receive_key(key: str, root_password: Optional[str]) -> SystemProcess:
    return SystemProcess(new_root_subprocess(['pacman-key', '-r', key],
                                             root_password=root_password),
                         check_error_output=False)
Esempio n. 22
0
    def install(self, pkg: AppImage, root_password: str,
                watcher: ProcessWatcher) -> bool:
        handler = ProcessHandler(watcher)

        out_dir = INSTALLATION_PATH + pkg.name.lower()
        counter = 0
        while True:
            if os.path.exists(out_dir):
                self.logger.info(
                    "Installation dir '{}' already exists. Generating a different one"
                    .format(out_dir))
                out_dir += '-{}'.format(counter)
                counter += 1
            else:
                break

        Path(out_dir).mkdir(parents=True, exist_ok=True)
        pkg.install_dir = out_dir

        if pkg.imported:

            downloaded, file_name = True, pkg.local_file_path.split('/')[-1]

            file_path = out_dir + '/' + file_name

            try:
                moved, output = handler.handle_simple(
                    SimpleProcess(['mv', pkg.local_file_path, file_path]))
            except:
                self.logger.error("Could not rename file '' as '{}'".format(
                    pkg.local_file_path, file_path))
                moved = False

            if not moved:
                watcher.show_message(
                    title=self.i18n['error'].capitalize(),
                    body=self.i18n['appimage.install.imported.rename_error'].
                    format(bold(pkg.local_file_path.split('/')[-1]),
                           bold(output)),
                    type_=MessageType.ERROR)
                return False

        else:
            appimage_url = pkg.url_download_latest_version if pkg.update else pkg.url_download
            file_name = appimage_url.split('/')[-1]
            pkg.version = pkg.latest_version
            pkg.url_download = appimage_url

            file_path = out_dir + '/' + file_name
            downloaded = self.file_downloader.download(
                file_url=pkg.url_download,
                watcher=watcher,
                output_path=file_path,
                cwd=str(Path.home()))

        if downloaded:
            watcher.change_substatus(
                self.i18n['appimage.install.permission'].format(
                    bold(file_name)))
            permission_given = handler.handle(
                SystemProcess(new_subprocess(['chmod', 'a+x', file_path])))

            if permission_given:

                watcher.change_substatus(
                    self.i18n['appimage.install.extract'].format(
                        bold(file_name)))

                try:
                    res, output = handler.handle_simple(
                        SimpleProcess([file_path, '--appimage-extract'],
                                      cwd=out_dir))

                    if 'Error: Failed to register AppImage in AppImageLauncherFS' in output:
                        watcher.show_message(
                            title=self.i18n['error'],
                            body=self.
                            i18n['appimage.install.appimagelauncher.error'].
                            format(appimgl=bold('AppImageLauncher'),
                                   app=bold(pkg.name)),
                            type_=MessageType.ERROR)
                        handler.handle(
                            SystemProcess(
                                new_subprocess(['rm', '-rf', out_dir])))
                        return False
                except:
                    watcher.show_message(title=self.i18n['error'],
                                         body=traceback.format_exc(),
                                         type_=MessageType.ERROR)
                    traceback.print_exc()
                    handler.handle(
                        SystemProcess(new_subprocess(['rm', '-rf', out_dir])))
                    return False

                watcher.change_substatus(
                    self.i18n['appimage.install.desktop_entry'])
                extracted_folder = '{}/{}'.format(out_dir, 'squashfs-root')

                if os.path.exists(extracted_folder):
                    desktop_entry = self._find_desktop_file(extracted_folder)

                    with open('{}/{}'.format(extracted_folder,
                                             desktop_entry)) as f:
                        de_content = f.read()

                    de_content = RE_DESKTOP_EXEC.sub(
                        'Exec={}\n'.format(file_path), de_content)

                    extracted_icon = self._find_icon_file(extracted_folder)

                    if extracted_icon:
                        icon_path = out_dir + '/logo.' + extracted_icon.split(
                            '.')[-1]
                        shutil.copy(
                            '{}/{}'.format(extracted_folder, extracted_icon),
                            icon_path)
                        de_content = RE_DESKTOP_ICON.sub(
                            'Icon={}\n'.format(icon_path), de_content)
                        pkg.icon_path = icon_path

                    Path(DESKTOP_ENTRIES_PATH).mkdir(parents=True,
                                                     exist_ok=True)

                    with open(self._gen_desktop_entry_path(pkg), 'w+') as f:
                        f.write(de_content)

                    shutil.rmtree(extracted_folder)
                    return True
                else:
                    watcher.show_message(
                        title=self.i18n['error'],
                        body='Could extract content from {}'.format(
                            bold(file_name)),
                        type_=MessageType.ERROR)
        else:
            watcher.show_message(
                title=self.i18n['error'],
                body=self.i18n['appimage.install.download.error'].format(
                    bold(pkg.url_download)),
                type_=MessageType.ERROR)

        handler.handle(SystemProcess(new_subprocess(['rm', '-rf', out_dir])))
        return False
Esempio n. 23
0
    def _install_from_aur(self,
                          pkgname: str,
                          maintainer: str,
                          root_password: str,
                          handler: ProcessHandler,
                          dependency: bool,
                          skip_optdeps: bool = False,
                          change_progress: bool = True) -> bool:
        app_build_dir = '{}/build_{}'.format(BUILD_DIR, int(time.time()))

        try:
            if not os.path.exists(app_build_dir):
                build_dir = handler.handle(
                    SystemProcess(
                        new_subprocess(['mkdir', '-p', app_build_dir])))
                self._update_progress(handler.watcher, 10, change_progress)

                if build_dir:
                    file_url = URL_PKG_DOWNLOAD.format(pkgname)
                    file_name = file_url.split('/')[-1]
                    handler.watcher.change_substatus('{} {}'.format(
                        self.i18n['arch.downloading.package'],
                        bold(file_name)))
                    download = handler.handle(
                        SystemProcess(new_subprocess(['wget', file_url],
                                                     cwd=app_build_dir),
                                      check_error_output=False))

                    if download:
                        self._update_progress(handler.watcher, 30,
                                              change_progress)
                        handler.watcher.change_substatus('{} {}'.format(
                            self.i18n['arch.uncompressing.package'],
                            bold(file_name)))
                        uncompress = handler.handle(
                            SystemProcess(
                                new_subprocess([
                                    'tar', 'xvzf', '{}.tar.gz'.format(pkgname)
                                ],
                                               cwd=app_build_dir)))
                        self._update_progress(handler.watcher, 40,
                                              change_progress)

                        if uncompress:
                            uncompress_dir = '{}/{}'.format(
                                app_build_dir, pkgname)
                            return self._make_pkg(
                                pkgname=pkgname,
                                maintainer=maintainer,
                                root_password=root_password,
                                handler=handler,
                                build_dir=app_build_dir,
                                project_dir=uncompress_dir,
                                dependency=dependency,
                                skip_optdeps=skip_optdeps,
                                change_progress=change_progress)
        finally:
            if os.path.exists(app_build_dir):
                handler.handle(
                    SystemProcess(new_subprocess(['rm', '-rf',
                                                  app_build_dir])))

        return False
Esempio n. 24
0
def sign_key(key: str, root_password: str) -> SystemProcess:
    return SystemProcess(new_root_subprocess(
        ['pacman-key', '--lsign-key', key], root_password=root_password),
                         check_error_output=False)
Esempio n. 25
0
 def downgrade(self, pkg: SnapApplication, root_password: str,
               watcher: ProcessWatcher) -> bool:
     return ProcessHandler(watcher).handle(
         SystemProcess(subproc=snap.downgrade_and_stream(
             pkg.name, root_password),
                       wrong_error_phrase=None))
Esempio n. 26
0
    def install(self, pkg: SnapApplication, root_password: str,
                disk_loader: DiskCacheLoader,
                watcher: ProcessWatcher) -> TransactionResult:
        # retrieving all installed so it will be possible to know the additional installed runtimes after the operation succeeds
        if not snap.is_installed():
            watcher.print("'snap' seems not to be installed")
            return TransactionResult.fail()

        if not snapd.is_running():
            watcher.print("'snapd' seems not to be running")
            return TransactionResult.fail()

        installed_names = {
            s['name']
            for s in SnapdClient(self.logger).list_all_snaps()
        }

        client = SnapdClient(self.logger)
        snap_config = read_config()

        try:
            channel = self._request_channel_installation(
                pkg=pkg,
                snap_config=snap_config,
                snapd_client=client,
                watcher=watcher)
            pkg.channel = channel
        except:
            watcher.print('Aborted by user')
            return TransactionResult.fail()

        res, output = ProcessHandler(watcher).handle_simple(
            snap.install_and_stream(app_name=pkg.name,
                                    confinement=pkg.confinement,
                                    root_password=root_password,
                                    channel=channel))

        if 'error:' in output:
            res = False
            if 'not available on stable' in output:
                channels = RE_AVAILABLE_CHANNELS.findall(output)

                if channels:
                    opts = [
                        InputOption(label=c[0], value=c[1]) for c in channels
                    ]
                    channel_select = SingleSelectComponent(
                        type_=SelectViewType.RADIO,
                        label='',
                        options=opts,
                        default_option=opts[0])
                    body = '<p>{}.</p>'.format(
                        self.i18n['snap.install.available_channels.message'].
                        format(bold(self.i18n['stable']), bold(pkg.name)))
                    body += '<p>{}:</p>'.format(
                        self.i18n['snap.install.available_channels.help'])

                    if watcher.request_confirmation(
                            title=self.
                            i18n['snap.install.available_channels.title'],
                            body=body,
                            components=[channel_select],
                            confirmation_label=self.i18n['continue'],
                            deny_label=self.i18n['cancel']):
                        self.logger.info(
                            "Installing '{}' with the custom command '{}'".
                            format(pkg.name, channel_select.value))
                        res = ProcessHandler(watcher).handle(
                            SystemProcess(
                                new_root_subprocess(
                                    channel_select.value.value.split(' '),
                                    root_password=root_password)))
                        return self._gen_installation_response(
                            success=res,
                            pkg=pkg,
                            installed=installed_names,
                            disk_loader=disk_loader)
                else:
                    self.logger.error(
                        "Could not find available channels in the installation output: {}"
                        .format(output))

        return self._gen_installation_response(success=res,
                                               pkg=pkg,
                                               installed=installed_names,
                                               disk_loader=disk_loader)
Esempio n. 27
0
 def refresh(self, pkg: SnapApplication, root_password: str,
             watcher: ProcessWatcher) -> bool:
     return ProcessHandler(watcher).handle(
         SystemProcess(
             subproc=snap.refresh_and_stream(pkg.name, root_password)))
Esempio n. 28
0
    def _install(self, pkg: AppImage, watcher: ProcessWatcher, pre_downloaded_file: Optional[Tuple[str, str]] = None) \
            -> TransactionResult:

        handler = ProcessHandler(watcher)
        out_dir = f'{INSTALLATION_DIR}/{pkg.get_clean_name()}'
        counter = 0
        while True:
            if os.path.exists(out_dir):
                self.logger.info(f"Installation dir '{out_dir}' already exists. Generating a different one")
                out_dir += f'-{counter}'
                counter += 1
            else:
                break

        Path(out_dir).mkdir(parents=True, exist_ok=True)
        pkg.install_dir = out_dir

        if pkg.imported:

            downloaded, file_name = True, pkg.local_file_path.split('/')[-1]

            install_file_path = out_dir + '/' + file_name

            try:
                moved, output = handler.handle_simple(SimpleProcess(['mv', pkg.local_file_path, install_file_path]))
            except:
                output = ''
                self.logger.error(f"Could not rename file '{pkg.local_file_path}' as '{install_file_path}'")
                moved = False

            if not moved:
                watcher.show_message(title=self.i18n['error'].capitalize(),
                                     body=self.i18n['appimage.install.imported.rename_error'].format(bold(pkg.local_file_path.split('/')[-1]),
                                                                                                     bold(output)),
                                     type_=MessageType.ERROR)

                return TransactionResult.fail()

        else:
            download_data = pre_downloaded_file if pre_downloaded_file else self._download(pkg, watcher)

            if not download_data:
                return TransactionResult.fail()

            file_name, download_path = download_data[0], download_data[1]

            install_file_path = f'{out_dir}/{file_name}'

            try:
                shutil.move(download_path, install_file_path)
            except OSError:
                watcher.show_message(title=self.i18n['error'],
                                     body=self.i18n['error.mvfile'].formmat(src=bold(download_path),
                                                                            dest=bold(install_file_path)))
                return TransactionResult.fail()

        watcher.change_substatus(self.i18n['appimage.install.permission'].format(bold(file_name)))
        permission_given = handler.handle(SystemProcess(new_subprocess(['chmod', 'a+x', install_file_path])))

        if permission_given:

            watcher.change_substatus(self.i18n['appimage.install.extract'].format(bold(file_name)))

            try:
                res, output = handler.handle_simple(
                    SimpleProcess([install_file_path, '--appimage-extract'], cwd=out_dir))

                if 'Error: Failed to register AppImage in AppImageLauncherFS' in output:
                    watcher.show_message(title=self.i18n['error'],
                                         body=self.i18n['appimage.install.appimagelauncher.error'].format(
                                             appimgl=bold('AppImageLauncher'), app=bold(pkg.name)),
                                         type_=MessageType.ERROR)
                    handler.handle(SystemProcess(new_subprocess(['rm', '-rf', out_dir])))
                    return TransactionResult.fail()
            except:
                watcher.show_message(title=self.i18n['error'],
                                     body=traceback.format_exc(),
                                     type_=MessageType.ERROR)
                traceback.print_exc()
                handler.handle(SystemProcess(new_subprocess(['rm', '-rf', out_dir])))
                return TransactionResult.fail()

            watcher.change_substatus(self.i18n['appimage.install.desktop_entry'])
            extracted_folder = f'{out_dir}/squashfs-root'

            if os.path.exists(extracted_folder):
                desktop_entry = self._find_desktop_file(extracted_folder)

                with open(f'{extracted_folder}/{desktop_entry}') as f:
                    de_content = f.read()

                if de_content:
                    de_content = replace_desktop_entry_exec_command(desktop_entry=de_content,
                                                                    appname=pkg.name,
                                                                    file_path=install_file_path)
                extracted_icon = self._find_icon_file(extracted_folder)

                if extracted_icon:
                    icon_path = out_dir + '/logo.' + extracted_icon.split('/')[-1].split('.')[-1]
                    shutil.copy(extracted_icon, icon_path)

                    if de_content:
                        de_content = RE_DESKTOP_ICON.sub(f'Icon={icon_path}\n', de_content)

                    pkg.icon_path = icon_path

                if not de_content:
                    de_content = pkg.to_desktop_entry()

                Path(DESKTOP_ENTRIES_DIR).mkdir(parents=True, exist_ok=True)

                with open(self._gen_desktop_entry_path(pkg), 'w+') as f:
                    f.write(de_content)

                try:
                    shutil.rmtree(extracted_folder)
                except:
                    traceback.print_exc()

                SymlinksVerifier.create_symlink(app=pkg, file_path=install_file_path, logger=self.logger,
                                                watcher=watcher)
                return TransactionResult(success=True, installed=[pkg], removed=[])
            else:
                watcher.show_message(title=self.i18n['error'],
                                     body=f'Could extract content from {bold(file_name)}',
                                     type_=MessageType.ERROR)

        handler.handle(SystemProcess(new_subprocess(['rm', '-rf', out_dir])))
        return TransactionResult.fail()
Esempio n. 29
0
 def install(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool:
     return ProcessHandler(watcher).handle(SystemProcess(subproc=snap.install_and_stream(pkg.name, pkg.confinement, root_password)))
Esempio n. 30
0
def receive_key(key: str) -> SystemProcess:
    return SystemProcess(new_subprocess(['gpg', '--recv-key', key]),
                         check_error_output=False)