Esempio n. 1
0
def search(word: str, exact_name: bool = False) -> List[dict]:
    apps = []

    res = system.run_cmd('{} find "{}"'.format(BASE_CMD, word), print_error=False)

    if res:
        res = res.split('\n')

        if not res[0].startswith('No matching'):
            for idx, app_str in enumerate(res):
                if idx > 0 and app_str:
                    app_data = [word for word in app_str.split(' ') if word]

                    if exact_name and app_data[0] != word:
                        continue

                    apps.append({
                        'name': app_data[0],
                        'version': app_data[1],
                        'publisher': app_data[2],
                        'notes': app_data[3] if app_data[3] != '-' else None,
                        'summary': app_data[4] if len(app_data) == 5 else '',
                        'rev': None,
                        'tracking': None,
                        'type': None
                    })

                if exact_name and len(apps) > 0:
                    break

    return apps
Esempio n. 2
0
def get_app_commits(app_ref: str, origin: str) -> List[str]:
    log = system.run_cmd('{} remote-info --log {} {}'.format(
        BASE_CMD, origin, app_ref))

    if log:
        return re.findall(r'Commit+:\s(.+)', log)
    else:
        raise NoInternetException()
Esempio n. 3
0
def list_installed(extra_fields: bool = True) -> List[dict]:
    apps_str = system.run_cmd('{} list'.format(BASE_CMD))

    if apps_str:
        version = get_version()
        app_lines = apps_str.split('\n')
        return [
            app_str_to_json(line, version, extra_fields=extra_fields)
            for line in app_lines if line
        ]

    return []
Esempio n. 4
0
def get_snapd_version():
    res = system.run_cmd('{} --version'.format(BASE_CMD), print_error=False)

    if not res:
        return None
    else:
        lines = res.split('\n')

        if lines and len(lines) >= 2:
            version = lines[1].split(' ')[-1].strip()
            return version.lower() if version else None
        else:
            return None
Esempio n. 5
0
def read_installed() -> List[dict]:
    res = system.run_cmd('{} list'.format(BASE_CMD), print_error=False)

    apps = []

    if res and len(res) > 0:
        lines = res.split('\n')

        if not lines[0].startswith('error'):
            for idx, app_str in enumerate(lines):
                if idx > 0 and app_str:
                    apps.append(app_str_to_json(app_str))

    return apps
Esempio n. 6
0
def get_app_commits_data(app_ref: str, origin: str) -> List[dict]:
    log = system.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):
        commit[data[0].strip().lower()] = data[1].strip()

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

    return commits
Esempio n. 7
0
def get_info(app_name: str, attrs: tuple = None):
    full_info_lines = system.run_cmd('{} info {}'.format(BASE_CMD, app_name))

    data = {}

    if full_info_lines:
        re_attrs = r'\w+' if not attrs else '|'.join(attrs)
        info_map = re.findall(r'({}):\s+(.+)'.format(re_attrs), full_info_lines)

        for info in info_map:
            data[info[0]] = info[1].strip()

        if not attrs or 'description' in attrs:
            desc = re.findall(r'\|\n+((\s+.+\n+)+)', full_info_lines)
            data['description'] = ''.join([w.strip() for w in desc[0][0].strip().split('\n')]).replace('.', '.\n') if desc else None

        if not attrs or 'commands' in attrs:
            commands = re.findall(r'commands:\s*\n*((\s+-\s.+\s*\n)+)', full_info_lines)
            data['commands'] = commands[0][0].replace('-', '').strip().split('\n') if commands else None

    return data
Esempio n. 8
0
def get_app_info(app_id: str, branch: str):
    return system.run_cmd('{} info {} {}'.format(BASE_CMD, app_id, branch))
Esempio n. 9
0
def get_version():
    res = system.run_cmd('{} --version'.format(BASE_CMD), print_error=False)
    return res.split(' ')[1].strip() if res else None
Esempio n. 10
0
def has_remotes_set() -> bool:
    return bool(system.run_cmd('{} remotes'.format(BASE_CMD)).strip())
Esempio n. 11
0
def set_default_remotes():
    system.run_cmd(
        'flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo'
    )
Esempio n. 12
0
def search(word: str, app_id: bool = False) -> List[dict]:
    cli_version = get_version()

    res = system.run_cmd('{} search {}'.format(BASE_CMD, word))

    found = []

    split_res = res.split('\n')

    if split_res and split_res[0].lower() != 'no matches found':
        for info in split_res:
            if info:
                info_list = info.split('\t')
                if cli_version >= '1.3.0':
                    id_ = info_list[2].strip()

                    if app_id and id_ != word:
                        continue

                    version = info_list[3].strip()
                    app = {
                        'name': info_list[0].strip(),
                        'description': info_list[1].strip(),
                        'id': id_,
                        'version': version,
                        'latest_version': version,
                        'branch': info_list[4].strip(),
                        'origin': info_list[5].strip(),
                        'runtime': False,
                        'arch': None,  # unknown at this moment,
                        'ref': None  # unknown at this moment
                    }
                elif cli_version >= '1.2.0':
                    id_ = info_list[1].strip()

                    if app_id and id_ != word:
                        continue

                    desc = info_list[0].split('-')
                    version = info_list[2].strip()
                    app = {
                        'name': desc[0].strip(),
                        'description': desc[1].strip(),
                        'id': id_,
                        'version': version,
                        'latest_version': version,
                        'branch': info_list[3].strip(),
                        'origin': info_list[4].strip(),
                        'runtime': False,
                        'arch': None,  # unknown at this moment,
                        'ref': None  # unknown at this moment
                    }
                else:
                    id_ = info_list[0].strip()

                    if app_id and id_ != word:
                        continue

                    version = info_list[1].strip()
                    app = {
                        'name': '',
                        'description': info_list[4].strip(),
                        'id': id_,
                        'version': version,
                        'latest_version': version,
                        'branch': info_list[2].strip(),
                        'origin': info_list[3].strip(),
                        'runtime': False,
                        'arch': None,  # unknown at this moment,
                        'ref': None  # unknown at this moment
                    }

                found.append(app)

                if app_id and len(found) > 0:
                    break

    return found
Esempio n. 13
0
def list_updates_as_str():
    return system.run_cmd('{} update'.format(BASE_CMD),
                          ignore_return_code=True)