Ejemplo n.º 1
0
def get_app_commits_data(app_ref: str, origin: str) -> List[dict]:
    log = run_cmd('{} remote-info --log {} {}'.format(BASE_CMD, origin,
                                                      app_ref))

    if not log:
        raise NoInternetException()

    res = re.findall(r'(Commit|Subject|Date):\s(.+)', log)

    commits = []

    commit = {}

    for idx, data in enumerate(res):
        attr = data[0].strip().lower()
        commit[attr] = data[1].strip()

        if attr == 'date':
            commit[attr] = datetime.strptime(commit[attr],
                                             '%Y-%m-%d %H:%M:%S +0000')

        if (idx + 1) % 3 == 0:
            commits.append(commit)
            commit = {}

    return commits
Ejemplo n.º 2
0
def get_app_commits_data(app_ref: str,
                         origin: str,
                         installation: str,
                         full_str: bool = True) -> List[dict]:
    log = run_cmd('{} remote-info --log {} {} --{}'.format(
        'flatpak', origin, app_ref, installation))

    if not log:
        raise NoInternetException()

    res = re.findall(r'(Commit|Subject|Date):\s(.+)', log)

    commits = []

    commit = {}

    for idx, data in enumerate(res):
        attr = data[0].strip().lower()
        commit[attr] = data[1].strip()

        if attr == 'commit':
            commit[attr] = commit[attr] if full_str else commit[attr][0:8]

        if attr == 'date':
            commit[attr] = datetime.strptime(commit[attr],
                                             '%Y-%m-%d %H:%M:%S +0000')

        if (idx + 1) % 3 == 0:
            commits.append(commit)
            commit = {}

    return commits
Ejemplo n.º 3
0
    def search(self, word: str, disk_loader: DiskCacheLoader = None, limit: int = -1) -> SearchResult:
        ti = time.time()
        self._wait_to_be_ready()

        res = SearchResult([], [], 0)

        if internet.is_available(self.context.http_client, self.context.logger):
            norm_word = word.strip().lower()
            disk_loader = self.disk_loader_factory.new()
            disk_loader.start()

            threads = []

            for man in self.managers:
                t = Thread(target=self._search, args=(norm_word, man, disk_loader, res))
                t.start()
                threads.append(t)

            for t in threads:
                t.join()

            if disk_loader:
                disk_loader.stop_working()
                disk_loader.join()

            res.installed = self._sort(res.installed, norm_word)
            res.new = self._sort(res.new, norm_word)
            res.total = len(res.installed) + len(res.new)
        else:
            raise NoInternetException()

        tf = time.time()
        self.logger.info('Took {0:.2f} seconds'.format(tf - ti))
        return res
Ejemplo n.º 4
0
    def change_channel(self, pkg: SnapApplication, root_password: str,
                       watcher: ProcessWatcher) -> bool:
        if not internet.is_available():
            raise NoInternetException()

        try:
            channel = self._request_channel_installation(
                pkg=pkg,
                snap_config=None,
                snapd_client=SnapdClient(self.logger),
                watcher=watcher,
                exclude_current=True)

            if not channel:
                watcher.show_message(
                    title=self.i18n['snap.action.channel.label'],
                    body=self.i18n['snap.action.channel.error.no_channel'])
                return False

            return ProcessHandler(watcher).handle_simple(
                snap.refresh_and_stream(app_name=pkg.name,
                                        root_password=root_password,
                                        channel=channel))[0]
        except:
            return False
Ejemplo n.º 5
0
def get_app_commits(app_ref: str, origin: str) -> List[str]:
    log = run_cmd('{} remote-info --log {} {}'.format(BASE_CMD, origin,
                                                      app_ref))

    if log:
        return re.findall(r'Commit+:\s(.+)', log)
    else:
        raise NoInternetException()
Ejemplo n.º 6
0
    def execute_custom_action(self, action: CustomSoftwareAction, pkg: SoftwarePackage, root_password: str, watcher: ProcessWatcher):
        if action.requires_internet and not self.context.is_internet_available():
            raise NoInternetException()

        man = action.manager if action.manager else self._get_manager_for(pkg)

        if man:
            return eval('man.{}({}root_password=root_password, watcher=watcher)'.format(action.manager_method, 'pkg=pkg, ' if pkg else ''))
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
    def search(self,
               words: str,
               disk_loader: DiskCacheLoader = None,
               limit: int = -1,
               is_url: bool = False) -> SearchResult:
        ti = time.time()
        self._wait_to_be_ready()

        res = SearchResult.empty()

        if self.context.is_internet_available():
            norm_query = sanitize_command_input(words).lower()
            self.logger.info(f"Search query: {norm_query}")

            if norm_query:
                is_url = bool(RE_IS_URL.match(norm_query))
                disk_loader = self.disk_loader_factory.new()
                disk_loader.start()

                threads = []

                for man in self.managers:
                    t = Thread(target=self._search,
                               args=(norm_query, is_url, man, disk_loader,
                                     res))
                    t.start()
                    threads.append(t)

                for t in threads:
                    t.join()

                if disk_loader:
                    disk_loader.stop_working()
                    disk_loader.join()

            # res.installed = self._sort(res.installed, norm_word)
            # res.new = self._sort(res.new, norm_word)
        else:
            raise NoInternetException()

        res.update_total()
        tf = time.time()
        self.logger.info(f'Took {tf - ti:.8f} seconds')
        return res
Ejemplo n.º 9
0
    def search(self,
               words: str,
               disk_loader: DiskCacheLoader = None,
               limit: int = -1,
               is_url: bool = False) -> SearchResult:
        ti = time.time()
        self._wait_to_be_ready()

        res = SearchResult.empty()

        if self.context.is_internet_available():
            norm_word = words.strip().lower()

            url_words = RE_IS_URL.match(norm_word)
            disk_loader = self.disk_loader_factory.new()
            disk_loader.start()

            threads = []

            for man in self.managers:
                t = Thread(target=self._search,
                           args=(norm_word, url_words, man, disk_loader, res))
                t.start()
                threads.append(t)

            for t in threads:
                t.join()

            if disk_loader:
                disk_loader.stop_working()
                disk_loader.join()

            res.installed = self._sort(res.installed, norm_word)
            res.new = self._sort(res.new, norm_word)
        else:
            raise NoInternetException()

        res.update_total()
        tf = time.time()
        self.logger.info('Took {0:.8f} seconds'.format(tf - ti))
        return res