From 0075f044f7253fc7af118255c1d9b349a0707136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Tue, 10 Dec 2024 00:17:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=85=20add=20fetch=5Frepo=20subcommand?= =?UTF-8?q?=20(based=20on=20fetchsrclibs=20plugin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We've been using fetchsrclibs plugin for downloading source-code for apps and srclibs. This change copies to plugin script into fdroidserver as a subcommand. It also renames it from fetchsrclibs to fetch_repo because it's fetching the git repo in Repo: --- fdroidserver/__main__.py | 1 + fdroidserver/fetch_repo.py | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 fdroidserver/fetch_repo.py diff --git a/fdroidserver/__main__.py b/fdroidserver/__main__.py index 90e05ac1..e7506268 100755 --- a/fdroidserver/__main__.py +++ b/fdroidserver/__main__.py @@ -69,6 +69,7 @@ COMMANDS_INTERNAL = [ "destroy", "exec", "execute_sudo", + "fetch_repo", "install_ndk", "make_source_tarball", "prepare_source", diff --git a/fdroidserver/fetch_repo.py b/fdroidserver/fetch_repo.py new file mode 100644 index 00000000..727af50a --- /dev/null +++ b/fdroidserver/fetch_repo.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# +# fetch_repo.py - part of the F-Droid server tools +# Copyright (C) 2024-2025, Michael Pöhn +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""Subcommand for fetching Repo: to set up source code to build.""" + +import argparse +import logging +import sys +import traceback + +from fdroidserver import common, metadata + + +def fetch_repo_wrapper(app, build): + vcs, _ignored = common.setup_vcs(app) + vcs.gotorevision(build.commit, refresh=True) + if build.submodules: # TODO move to separate subcommand: fetch_submodules + vcs.initsubmodules() + else: + vcs.deinitsubmodules() + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + common.setup_global_opts(parser) + parser.add_argument( + "APPID:VERCODE", + help="Application ID with Version Code in the form APPID:VERCODE", + ) + options = common.parse_args(parser) + common.set_console_logging(options.verbose) + + try: + appid, vercode = common.split_pkg_arg(options.__dict__['APPID:VERCODE']) + app, build = metadata.get_single_build(appid, vercode) + fetch_repo_wrapper(app, build) + except Exception as e: + if options.verbose: + logging.error(traceback.format_exc()) + else: + logging.error(e) + sys.exit(1) + + +if __name__ == "__main__": + main()