Example #1
0
def main(options=None, args=None, config=None, apprepo=None, console=None):
    """

    :param options:
    :param args:
    :param config:
    :param apprepo:
    :param console:
    :param hasher:
    :return:
    """
    if not options.version_token: raise Exception('Version token is empty')
    if not options.version_name: raise Exception('Version name is empty')
    if not options.version_hash: raise Exception('Version hash is empty')
    if not options.version_description: raise Exception('Unknown description')
    if not options.version_ipfs_cid:
        raise Exception('Unknown version_ipfs_cid')

    package_version = apprepo.package_ipfs_cid_new(
        config.get('user.token',
                   None), options.version_token, options.version_name,
        options.version_description, options.version_hash,
        options.version_ipfs_cid, options.version_ipfs_gateway)

    if not package_version:
        raise Exception('{} package version not found'.format(
            options.version_token))

    yield console.green("[done] {}: {}...".format(options.version_name,
                                                  options.version_ipfs_cid))
def main(options=None, args=None, config=None, apprepo=None):
    from bs4 import BeautifulSoup

    def strip_tags(html=None):
        if html is None: return None

        soup = BeautifulSoup(html, "html5lib")
        [x.extract() for x in soup.find_all('script')]
        [x.extract() for x in soup.find_all('style')]
        [x.extract() for x in soup.find_all('meta')]
        [x.extract() for x in soup.find_all('noscript')]
        [x.extract() for x in soup.find_all('iframe')]
        return soup.text

    string = ' '.join(args).strip('\'" ')
    if not string: raise Exception('search string can not be empty')

    for entity in apprepo.search(string):
        lines = []
        lines.append(console.green("[found] "))

        lines.append(
            console.blue("{}: {} ({})".format(entity['slug'] or 'Unknown',
                                              entity['name'] or 'Unknown',
                                              entity['version'] or 'Unknown')))

        lines.append(
            console.comment(" - {}".format(
                strip_tags(entity['description']) or 'Unknown')))

        yield "".join(lines)

    return 0
def main(options=None, args=None, appimagetool=None):
    for appimage in appimagetool.collection():
        yield console.green("[found]: {}, {}, {}, {}".format(
            os.path.basename(appimage.path) if os.path.exists(appimage.path) else "---",
            os.path.basename(appimage.desktop) if os.path.exists(appimage.desktop) else "---",
            os.path.basename(appimage.icon) if glob.glob(appimage.icon) else "---",
            os.path.basename(appimage.alias) if os.path.exists(appimage.alias) else "---",
        ))
def main(options=None,
         args=None,
         config=None,
         apprepo=None,
         appimagetool=None,
         console=None,
         hasher=None):
    authentication = config.get('user.token', None)
    if not authentication: raise Exception('Authentication token is empty')

    assert (hasattr(options, 'version_token'))
    assert (hasattr(options, 'version_description'))
    assert (hasattr(options, 'version_name'))

    source = args[0] or None
    if not source: raise Exception('Please provide a file to upload')
    if not args: raise Exception('AppImage path is empty')

    token = options.version_token,
    if not token: raise Exception('Version token is empty')

    name = options.version_name,
    if not name: raise Exception('Version name is empty')

    if not os.path.exists(source):
        raise Exception('{} does not exist or is not a file'.format(source))
    if not os.path.isfile(source):
        raise Exception('{} does not exist or is not a file'.format(source))

    latest = apprepo.package_by_token(options.version_token)
    if not latest:
        raise Exception('{} package version not found'.format(
            options.version_token))

    latest_hash = latest.get('hash', None)
    latest_package = latest.get('package', None)

    if latest_hash and len(latest_hash):
        if latest_hash == hasher(source):
            yield console.blue(
                "[skipped] {} this version was already uploaded...".format(
                    latest_package))
            return

    source = appimage.AppImage(source)
    if not options.skip_check and not appimagetool.check(source):
        raise Exception('{} unknown AppImage format'.format(source))

    yield console.comment("[uploading] {}...".format(source))

    apprepo.upload(source.path, authentication, token, name,
                   options.version_description)

    yield console.green("[done] {}...".format(source))
def main(options=None, args=None, appimagetool=None, console=None):
    profile = os.path.expanduser('~/.profile')
    if not os.path.exists(profile) or not os.path.isfile(profile):
        yield "[{}] ~/.profile does not exist, creating...".format(
            console.blue('notice'))
        with open(profile, 'w+') as stream:
            stream.write('PATH=~/.local/bin:$PATH')
            stream.close()

    if not options.synchronize_remote_only:
        yield console.blue("[integration]: synchronizing")

        for appimage in appimagetool.collection():
            alias = appimage.alias
            if not alias: continue

            desktop = appimage.desktop
            if not desktop: continue

            icon = appimage.icon
            if not icon: continue

            if os.path.exists(appimage.desktop) \
                    and os.path.exists(appimage.alias) \
                    and os.path.exists(appimage.icon):
                yield console.comment("[integration]: done, {}".format(
                    os.path.basename(appimage.path)))

                continue

            yield console.comment("[integration]: missed, {}".format(appimage))

            try:
                appimage = appimagetool.integrate(appimage)
                if not appimage: raise ValueError('Integration failed')

                yield console.green("[integration]: {}, {}, {}, {}".format(
                    os.path.basename(appimage.path)
                    if os.path.exists(appimage.path) else "---",
                    os.path.basename(appimage.desktop)
                    if os.path.exists(appimage.desktop) else "---",
                    os.path.basename(appimage.icon)
                    if glob.glob(appimage.icon) else "---",
                    os.path.basename(appimage.alias)
                    if os.path.exists(appimage.alias) else "---",
                ))

            except Exception as ex:
                yield console.error("[error]: {}, {}".format(
                    appimage.path, ex))
def help(options=None, arguments=None, application=None):
    yield console.header('Usage: console.py [options] [arguments]')
    for (name, description, command) in application.get_commands():
        yield "{:<23} {}".format(console.green(name), console.comment(description))