mirror of
https://git.launchpad.net/livecd-rootfs
synced 2025-06-01 13:13:39 +00:00
update-source-catalog: support version 2 scheme
Version 1 of install-sources.yaml is a top-level list of the sources to be offered. Version 2 extends this by placing the list under a top-level key `sources`, adding a `version` field, and adding a `kernel` field which supplants the current kernel-meta-package file. `kernel.default` is read to know which kernel to use - unless we need to fallback to the bridge kernel.
This commit is contained in:
parent
9b1ea66dc8
commit
9b42f898bf
@ -185,7 +185,7 @@ build_layered_squashfs () {
|
|||||||
if [ -f config/seeded-languages ]; then
|
if [ -f config/seeded-languages ]; then
|
||||||
usc_opts="$usc_opts --langs $(cat config/seeded-languages)"
|
usc_opts="$usc_opts --langs $(cat config/seeded-languages)"
|
||||||
fi
|
fi
|
||||||
/usr/share/livecd-rootfs/update-source-catalog $usc_opts
|
/usr/share/livecd-rootfs/update-source-catalog source $usc_opts
|
||||||
else
|
else
|
||||||
echo "No catalog entry template for $pass"
|
echo "No catalog entry template for $pass"
|
||||||
fi
|
fi
|
||||||
|
@ -56,4 +56,4 @@ PROJECT_FULL=$PROJECT${SUBARCH:+-$SUBARCH}
|
|||||||
usc_opts="--output livecd.${PROJECT_FULL}.install-sources.yaml \
|
usc_opts="--output livecd.${PROJECT_FULL}.install-sources.yaml \
|
||||||
--template config/edge.catalog-in.yaml \
|
--template config/edge.catalog-in.yaml \
|
||||||
--size 0"
|
--size 0"
|
||||||
/usr/share/livecd-rootfs/update-source-catalog $usc_opts
|
/usr/share/livecd-rootfs/update-source-catalog source $usc_opts
|
||||||
|
@ -7,82 +7,113 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('--output', required=True)
|
|
||||||
parser.add_argument('--size', required=True)
|
|
||||||
parser.add_argument('--squashfs', default='')
|
|
||||||
parser.add_argument('--translations')
|
|
||||||
parser.add_argument('--template')
|
|
||||||
parser.add_argument('--langs', default=None)
|
|
||||||
|
|
||||||
opts = parser.parse_args(sys.argv[1:])
|
def get_opts():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
subparsers = parser.add_subparsers(dest="subcommand")
|
||||||
|
|
||||||
if os.path.exists(opts.output):
|
parser_source = subparsers.add_parser('source')
|
||||||
with open(opts.output) as fp:
|
parser_source.add_argument('--output', required=True)
|
||||||
output = yaml.safe_load(fp)
|
parser_source.add_argument('--template', required=True)
|
||||||
else:
|
parser_source.add_argument('--size', required=True)
|
||||||
output = []
|
parser_source.add_argument('--squashfs', default='')
|
||||||
|
parser_source.add_argument('--translations')
|
||||||
|
parser_source.add_argument('--langs')
|
||||||
|
parser_source.set_defaults(func=on_source)
|
||||||
|
|
||||||
|
parser_merge = subparsers.add_parser('merge')
|
||||||
|
parser_merge.add_argument('--output', required=True)
|
||||||
|
parser_merge.add_argument('--template', required=True)
|
||||||
|
parser_merge.set_defaults(func=on_merge)
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
with open(opts.template) as fp:
|
def yaml_load(filename):
|
||||||
template = yaml.safe_load(fp)
|
with open(filename) as fp:
|
||||||
|
return yaml.safe_load(fp)
|
||||||
|
|
||||||
|
|
||||||
id = template['id']
|
def yaml_dump(filename, content):
|
||||||
for entry in output:
|
with open(filename, 'w') as fp:
|
||||||
# First, look if this source catalogue template id is already present.
|
yaml.dump(content, fp)
|
||||||
# If so, use the template to extend the existing entry with additional
|
|
||||||
# variations.
|
|
||||||
if entry['id'] == id:
|
|
||||||
if 'variations' not in template:
|
|
||||||
print("Non unique id in source catalog but no variations!")
|
|
||||||
sys.exit(1)
|
|
||||||
for variation in template['variations'].values():
|
|
||||||
variation['size'] = int(opts.size)
|
|
||||||
entry.setdefault('variations', {}).update(template['variations'])
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
# No entry with this id found, so add a new one.
|
|
||||||
|
|
||||||
if 'variations' in template:
|
|
||||||
for variation in template['variations'].values():
|
def on_source(opts, output):
|
||||||
if variation['path'] == opts.squashfs:
|
template = yaml_load(opts.template)
|
||||||
|
|
||||||
|
id = template['id']
|
||||||
|
for entry in output["sources"]:
|
||||||
|
# First, look if this source catalogue template id is already present.
|
||||||
|
# If so, use the template to extend the existing entry with additional
|
||||||
|
# variations.
|
||||||
|
if entry['id'] == id:
|
||||||
|
if 'variations' not in template:
|
||||||
|
print("Non unique id in source catalog but no variations!")
|
||||||
|
sys.exit(1)
|
||||||
|
for variation in template['variations'].values():
|
||||||
variation['size'] = int(opts.size)
|
variation['size'] = int(opts.size)
|
||||||
|
entry.setdefault('variations', {}).update(template['variations'])
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# No entry with this id found, so add a new one.
|
||||||
|
|
||||||
template['size'] = int(opts.size)
|
if 'variations' in template:
|
||||||
template['path'] = opts.squashfs
|
for variation in template['variations'].values():
|
||||||
|
if variation['path'] == opts.squashfs:
|
||||||
|
variation['size'] = int(opts.size)
|
||||||
|
|
||||||
en_name = template['name']
|
template['size'] = int(opts.size)
|
||||||
en_description = template['description']
|
template['path'] = opts.squashfs
|
||||||
|
|
||||||
template['name'] = {'en': en_name}
|
en_name = template['name']
|
||||||
template['description'] = {'en': en_description}
|
en_description = template['description']
|
||||||
|
|
||||||
if opts.translations:
|
template['name'] = {'en': en_name}
|
||||||
for mo in glob.glob(os.path.join(opts.translations, '*.mo')):
|
template['description'] = {'en': en_description}
|
||||||
with open(mo, 'rb') as fp:
|
|
||||||
t = gettext.GNUTranslations(fp=fp)
|
|
||||||
t_name = t.gettext(en_name)
|
|
||||||
if t_name != en_name:
|
|
||||||
lang = os.path.splitext(os.path.basename(mo))[0]
|
|
||||||
template['name'][lang] = t_name
|
|
||||||
t_description = t.gettext(en_description)
|
|
||||||
if t_description != en_description:
|
|
||||||
lang = os.path.splitext(os.path.basedescription(mo))[0]
|
|
||||||
template['description'][lang] = t_description
|
|
||||||
if opts.langs is not None:
|
|
||||||
template['preinstalled_langs'] = opts.langs.split(',')
|
|
||||||
|
|
||||||
output.append(template)
|
if opts.translations:
|
||||||
|
for mo in glob.glob(os.path.join(opts.translations, '*.mo')):
|
||||||
|
with open(mo, 'rb') as fp:
|
||||||
|
t = gettext.GNUTranslations(fp=fp)
|
||||||
|
t_name = t.gettext(en_name)
|
||||||
|
if t_name != en_name:
|
||||||
|
lang = os.path.splitext(os.path.basename(mo))[0]
|
||||||
|
template['name'][lang] = t_name
|
||||||
|
t_description = t.gettext(en_description)
|
||||||
|
if t_description != en_description:
|
||||||
|
lang = os.path.splitext(os.path.basedescription(mo))[0]
|
||||||
|
template['description'][lang] = t_description
|
||||||
|
if opts.langs is not None:
|
||||||
|
template['preinstalled_langs'] = opts.langs.split(',')
|
||||||
|
|
||||||
default_count = 0
|
output["sources"].append(template)
|
||||||
for entry in output:
|
|
||||||
if entry.get('default', False):
|
|
||||||
default_count += 1
|
|
||||||
|
|
||||||
if default_count > 1:
|
default_count = 0
|
||||||
print("Too many defaults in source catalog!")
|
for entry in output["sources"]:
|
||||||
sys.exit(1)
|
if entry.get('default', False):
|
||||||
|
default_count += 1
|
||||||
|
|
||||||
with open(opts.output, 'w') as fp:
|
if default_count > 1:
|
||||||
yaml.dump(output, fp)
|
print("Too many defaults in source catalog!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def on_merge(opts, output):
|
||||||
|
output.update(yaml_load(opts.template))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
opts = get_opts()
|
||||||
|
|
||||||
|
if os.path.exists(opts.output):
|
||||||
|
output = yaml_load(opts.output)
|
||||||
|
else:
|
||||||
|
output = {
|
||||||
|
"version": 2,
|
||||||
|
"sources": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
opts.func(opts, output)
|
||||||
|
|
||||||
|
yaml_dump(opts.output, output)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user