-
Notifications
You must be signed in to change notification settings - Fork 7
/
update_catalogs.py
executable file
·114 lines (99 loc) · 4.72 KB
/
update_catalogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
# Copyright (c) 2015 Nuxi, https://nuxi.nl/
#
# SPDX-License-Identifier: BSD-2-Clause
import logging
import os
from src import config
from src import util
from src.catalog import ArchLinuxCatalog, CygwinCatalog, DebianCatalog, FreeBSDCatalog, HomebrewCatalog, NetBSDCatalog, OpenBSDCatalog, RedHatCatalog
from src.catalog_set import CatalogSet
from src.repository import Repository
# Setup logging
logging.basicConfig(level=logging.INFO)
# Public location where package distfiles are stored.
DIR_DISTFILES = '/usr/local/www/nuxi.nl/public/distfiles/third_party'
# Temporary directory where intermediate build results are stored.
DIR_TMP = '/usr/local/www/nuxi.nl/repo.tmp'
# Final location of the catalogs.
DIR_ARCHLINUX_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/archlinux'
DIR_CYGWIN_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/cygwin'
DIR_DEBIAN_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/debian'
DIR_FREEBSD_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/freebsd'
DIR_HOMEBREW_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/homebrew'
DIR_NETBSD_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/netbsd'
DIR_OPENBSD_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/openbsd'
DIR_REDHAT_CATALOG = '/usr/local/www/nuxi.nl/public/distfiles/cloudabi-ports/redhat'
# Location of the catalog signing keys.
ARCHLINUX_PRIVATE_KEY = '31344B15'
CYGWIN_PRIVATE_KEY = 'A4836F43'
DEBIAN_PRIVATE_KEY = '31344B15'
FREEBSD_PRIVATE_KEY = '/home/ed/.cloudabi-ports-freebsd.key'
REDHAT_PRIVATE_KEY = '31344B15'
# The Homebrew repository needs to know its own URL.
HOMEBREW_URL = 'https://nuxi.nl/distfiles/cloudabi-ports/homebrew/'
# Zap the old temporary directory.
util.remove_and_make_dir(DIR_TMP)
# Parse all of the BUILD rules.
repo = Repository(os.path.join(DIR_TMP, 'install'))
# repo = Repository(os.path.join(os.getcwd(), '_obj/install'))
for filename in util.walk_files(os.path.join(os.getcwd(), 'packages')):
if os.path.basename(filename) == 'BUILD':
repo.add_build_file(filename, DIR_DISTFILES)
target_packages = repo.get_target_packages()
# The catalogs that we want to create.
archlinux_path = os.path.join(DIR_TMP, 'archlinux')
archlinux_catalog = ArchLinuxCatalog(DIR_ARCHLINUX_CATALOG, archlinux_path)
cygwin_path = os.path.join(DIR_TMP, 'cygwin')
cygwin_catalog = CygwinCatalog(DIR_CYGWIN_CATALOG, cygwin_path)
debian_path = os.path.join(DIR_TMP, 'debian')
debian_catalog = DebianCatalog(DIR_DEBIAN_CATALOG, debian_path)
freebsd_path = os.path.join(DIR_TMP, 'freebsd')
freebsd_catalog = FreeBSDCatalog(DIR_FREEBSD_CATALOG, freebsd_path)
homebrew_path = os.path.join(DIR_TMP, 'homebrew')
homebrew_catalog = HomebrewCatalog(DIR_HOMEBREW_CATALOG, homebrew_path,
HOMEBREW_URL)
netbsd_path = os.path.join(DIR_TMP, 'netbsd')
netbsd_catalog = NetBSDCatalog(DIR_NETBSD_CATALOG, netbsd_path)
openbsd_path = os.path.join(DIR_TMP, 'openbsd')
openbsd_catalog = OpenBSDCatalog(DIR_OPENBSD_CATALOG, openbsd_path)
redhat_path = os.path.join(DIR_TMP, 'redhat')
redhat_catalog = RedHatCatalog(DIR_REDHAT_CATALOG, redhat_path)
# Build all packages.
catalog_set = CatalogSet({
archlinux_catalog,
cygwin_catalog,
debian_catalog,
freebsd_catalog,
homebrew_catalog,
netbsd_catalog,
openbsd_catalog,
redhat_catalog,
})
for package in target_packages.values():
catalog_set.package_and_insert(package, os.path.join(DIR_TMP, 'catalog'))
archlinux_catalog.finish(ARCHLINUX_PRIVATE_KEY)
cygwin_catalog.finish(CYGWIN_PRIVATE_KEY)
debian_catalog.finish(DEBIAN_PRIVATE_KEY)
freebsd_catalog.finish(FREEBSD_PRIVATE_KEY)
redhat_catalog.finish(REDHAT_PRIVATE_KEY)
# Finish up and put the new catalogs in place.
os.rename(DIR_ARCHLINUX_CATALOG, os.path.join(DIR_TMP, 'archlinux.old'))
os.rename(archlinux_path, DIR_ARCHLINUX_CATALOG)
os.rename(DIR_CYGWIN_CATALOG, os.path.join(DIR_TMP, 'cygwin.old'))
os.rename(cygwin_path, DIR_CYGWIN_CATALOG)
os.rename(DIR_DEBIAN_CATALOG, os.path.join(DIR_TMP, 'debian.old'))
os.rename(debian_path, DIR_DEBIAN_CATALOG)
os.rename(DIR_FREEBSD_CATALOG, os.path.join(DIR_TMP, 'freebsd.old'))
os.rename(freebsd_path, DIR_FREEBSD_CATALOG)
os.rename(DIR_HOMEBREW_CATALOG, os.path.join(DIR_TMP, 'homebrew.old'))
os.rename(homebrew_path, DIR_HOMEBREW_CATALOG)
os.rename(DIR_NETBSD_CATALOG, os.path.join(DIR_TMP, 'netbsd.old'))
os.rename(netbsd_path, DIR_NETBSD_CATALOG)
os.rename(DIR_OPENBSD_CATALOG, os.path.join(DIR_TMP, 'openbsd.old'))
os.rename(openbsd_path, DIR_OPENBSD_CATALOG)
os.rename(DIR_REDHAT_CATALOG, os.path.join(DIR_TMP, 'redhat.old'))
os.rename(redhat_path, DIR_REDHAT_CATALOG)
# Zap the temporary directories.
util.remove(config.DIR_BUILDROOT)
util.remove(DIR_TMP)