#!/usr/bin/env python3
#
# an fdroid plugin for setting up srclibs
#
# The 'fdroid build' gitlab-ci job uses --on-server, which does not
# set up the srclibs.  This plugin does the missing setup.

import argparse
import os
import pprint
from fdroidserver import _, common, metadata

fdroid_summary = 'prepare the srclibs for `fdroid build --on-server`'


def main():
    common.config = {
        'accepted_formats': 'yml',
        'sdk_path': os.getenv('ANDROID_HOME'),
    }
    common.fill_config_defaults(common.config)
    parser = argparse.ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
    common.setup_global_opts(parser)
    parser.add_argument("appid", nargs='*', help=_("applicationId with optional versionCode in the form APPID[:VERCODE]"))
    metadata.add_metadata_arguments(parser)
    options = parser.parse_args()
    common.options = options
    pkgs = common.read_pkg_args(options.appid, True)
    allapps = metadata.read_metadata(xref=False)
    apps = common.read_app_args(options.appid, allapps, True)
    srclib_dir = os.path.join('build', 'srclib')
    os.makedirs(srclib_dir, exist_ok=True)
    srclibpaths = []
    for appid, app in apps.items():
        for build in app.builds:
            for lib in build.srclibs:
                srclibpaths.append(common.getsrclib(lib, srclib_dir, build=build))
    print('Set up srclibs:')
    pprint.pprint(srclibpaths)

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
#
# an fdroid plugin for setting up srclibs
#
# The 'fdroid build' gitlab-ci job uses --on-server, which does not
# set up the srclibs.  This plugin does the missing setup.

import argparse
import os
import pprint
from fdroidserver import _, common, metadata

fdroid_summary = 'prepare the srclibs for `fdroid build --on-server`'


def main():
    common.config = {
        'accepted_formats': 'yml',
        'sdk_path': os.getenv('ANDROID_HOME'),
    }
    common.fill_config_defaults(common.config)
    parser = argparse.ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
    common.setup_global_opts(parser)
    parser.add_argument("appid", nargs='*', help=_("applicationId with optional versionCode in the form APPID[:VERCODE]"))
    metadata.add_metadata_arguments(parser)
    options = parser.parse_args()
    common.options = options
    pkgs = common.read_pkg_args(options.appid, True)
    allapps = metadata.read_metadata(pkgs)
    apps = common.read_app_args(options.appid, allapps, True)
    srclib_dir = os.path.join('build', 'srclib')
    os.makedirs(srclib_dir, exist_ok=True)
    srclibpaths = []
    for appid, app in apps.items():
        for build in app.builds:
            for lib in build.srclibs:
                srclibpaths.append(common.getsrclib(lib, srclib_dir, build=build))
    print('Set up srclibs:')
    pprint.pprint(srclibpaths)

if __name__ == "__main__":
    main()

fix fdroid_fetchsrclibs.py for fdroidserver 2.0 API