2022-10-17 14:53:18 +02:00
|
|
|
#!/usr/bin/python3
|
2022-10-17 14:46:51 +02:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import pathlib
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import osc.core
|
|
|
|
|
2022-11-02 08:50:54 +01:00
|
|
|
from lib.git_exporter import GitExporter
|
2022-10-17 19:54:47 +02:00
|
|
|
from lib.importer import Importer
|
2022-11-02 07:59:25 +01:00
|
|
|
from lib.test_exporter import TestExporter
|
2022-10-17 14:46:51 +02:00
|
|
|
|
|
|
|
URL_OBS = "https://api.opensuse.org"
|
|
|
|
URL_IBS = "https://api.suse.de"
|
|
|
|
|
|
|
|
# The order is relevant (from older to newer initial codebase)
|
2022-11-02 07:59:25 +01:00
|
|
|
# TODO: make something with these, for now we look purely at openSUSE:Factory
|
2022-10-17 14:46:51 +02:00
|
|
|
PROJECTS = [
|
|
|
|
# ("SUSE:SLE-12:GA", "SLE_12", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12:Update", "SLE_12", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP1:GA", "SLE_12_SP1", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP1:Update", "SLE_12_SP1", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP2:GA", "SLE_12_SP2", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP2:Update", "SLE_12_SP2", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP3:GA", "SLE_12_SP3", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP3:Update", "SLE_12_SP3", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP4:GA", "SLE_12_SP4", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP4:Update", "SLE_12_SP4", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP5:GA", "SLE_12_SP5", URL_IBS),
|
|
|
|
# ("SUSE:SLE-12-SP5:Update", "SLE_12_SP5", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15:GA", "SLE_15", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15:Update", "SLE_15", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP1:GA", "SLE_15_SP1", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP1:Update", "SLE_15_SP1", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP2:GA", "SLE_15_SP2", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP2:Update", "SLE_15_SP2", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP3:GA", "SLE_15_SP3", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP3:Update", "SLE_15_SP3", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP4:GA", "SLE_15_SP4", URL_IBS),
|
|
|
|
# ("SUSE:SLE-15-SP4:Update", "SLE_15_SP4", URL_IBS),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-11-04 07:48:17 +01:00
|
|
|
def export_package(package, repodir, cachedir, gc):
|
|
|
|
exporter = GitExporter(URL_OBS, "openSUSE:Factory", package, repodir, cachedir)
|
|
|
|
exporter.set_gc_interval(gc)
|
|
|
|
exporter.export_as_git()
|
|
|
|
|
|
|
|
|
2022-10-17 14:46:51 +02:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="OBS history importer into git")
|
2022-11-03 20:14:56 +01:00
|
|
|
parser.add_argument("packages", help="OBS package names", nargs="*")
|
2022-10-17 14:46:51 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"-r",
|
|
|
|
"--repodir",
|
|
|
|
required=False,
|
2022-11-03 20:14:56 +01:00
|
|
|
default=pathlib.Path("repos"),
|
2022-10-17 14:46:51 +02:00
|
|
|
type=pathlib.Path,
|
|
|
|
help="Local git repository directory",
|
|
|
|
)
|
2022-11-03 13:17:49 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-c",
|
|
|
|
"--cachedir",
|
|
|
|
required=False,
|
|
|
|
type=pathlib.Path,
|
|
|
|
help="Local cache directory",
|
|
|
|
)
|
2022-10-17 14:46:51 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"-g",
|
|
|
|
"--gc",
|
|
|
|
metavar="N",
|
|
|
|
type=int,
|
|
|
|
default=200,
|
|
|
|
help="Garbage recollect and pack the git history each N commits",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--level",
|
|
|
|
"-l",
|
|
|
|
default="INFO",
|
|
|
|
help="logging level",
|
|
|
|
)
|
2022-10-21 09:48:31 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--export",
|
|
|
|
action="store_true",
|
2022-11-01 11:23:40 +01:00
|
|
|
help="Export database fields for the given package as YAML",
|
2022-10-21 09:48:31 +02:00
|
|
|
)
|
2022-10-17 14:46:51 +02:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.level:
|
|
|
|
numeric_level = getattr(logging, args.level.upper(), None)
|
|
|
|
if not isinstance(numeric_level, int):
|
|
|
|
print(f"Invalid log level: {args.level}")
|
|
|
|
sys.exit(-1)
|
|
|
|
logging.basicConfig(level=numeric_level)
|
|
|
|
if numeric_level == logging.DEBUG:
|
|
|
|
osc.conf.config["debug"] = True
|
|
|
|
requests_log = logging.getLogger("requests.packages.urllib3")
|
|
|
|
requests_log.setLevel(logging.DEBUG)
|
|
|
|
requests_log.propagate = True
|
|
|
|
|
2022-10-21 09:48:31 +02:00
|
|
|
if args.export:
|
2022-11-04 09:58:36 +01:00
|
|
|
if len(args.packages) != 1:
|
2022-11-03 20:14:56 +01:00
|
|
|
print("Can only export one package")
|
|
|
|
sys.exit(1)
|
|
|
|
TestExporter(args.packages[0]).run()
|
2022-10-21 09:48:31 +02:00
|
|
|
return
|
|
|
|
|
2022-11-03 13:17:49 +01:00
|
|
|
if not args.cachedir:
|
|
|
|
args.cachedir = pathlib.Path("~/.cache/git-import/").expanduser()
|
|
|
|
|
2022-11-03 20:14:56 +01:00
|
|
|
importer = Importer(URL_OBS, "openSUSE:Factory", args.packages)
|
2022-11-01 11:23:40 +01:00
|
|
|
importer.import_into_db()
|
2022-11-11 16:33:44 +01:00
|
|
|
for package in args.packages:
|
|
|
|
export_package(package, args.repodir, args.cachedir, args.gc)
|
2022-10-17 14:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|