on org.sil.Bloom help sign in
flathub/compose-url-sources
91 lines 3.4 kB history raw
1#!/usr/bin/env xonsh
3# Generate flatpak sources from URLs
4#
5# Copyright (c) 2021 SIL International. MIT License.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
14# The above copyright notice and this permission notice shall be included in all
15# copies or substantial portions of the Software.
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
25# Output a flatpak yaml sources list from an input yaml file specifying files at
26# base URLs. Files will be downloaded (and cached) to compute their checksums.
27# Usage: compose-url-sources input.yml output.yml
28# Dependencies: xonsh wget
30# Input should be formatted like the following example:
31# - name: My Assembly
32# baseurl: https://www.example.com/my-assembly/
33# dest: dependencies
34# files:
35# - My.Assembly.dll
36# - My.Assembly.dll.config
37# - name: Something else
38# baseurl: https://project.example.com/something-else/
39# dest: other-dependencies
40# files:
41# - deps.tar.xz
42# - icon.png
43# output.yml will then specify to download the following files:
44# https://www.example.com/my-assembly/My.Assembly.dll
45# https://www.example.com/my-assembly/My.Assembly.dll.config
46# https://project.example.com/something-else/deps.tar.xz
47# https://project.example.com/something-else/icon.png
49import sys
50import yaml
51$RAISE_SUBPROC_ERROR = True
53# trace on
54# $XONSH_TRACE_SUBPROC = True
56inputsPath = sys.argv[1]
57outputSourcesPath = sys.argv[2]
59nugetSources = []
60if 'XDG_CACHE_HOME' in ${...}:
61 cacheHome = $XDG_CACHE_HOME
62else:
63 cacheHome = '{}/.cache'.format($HOME)
64cachePath = '{}/nuget-sources-flatpak'.format(cacheHome)
65mkdir -p @(cachePath)
67def processInputSourcesList(path):
68 with open(path, 'r') as inputStream:
69 inputSources = yaml.safe_load(inputStream)
70 for source in inputSources:
71 print('Processing group {} ...'.format(source['name']))
72 for file in source['files']:
73 prepareSourceRecord(source['name'], source['baseurl'], source['dest'], file)
75def prepareSourceRecord(name, baseurl, dest, file):
76 url = '{}{}'.format(baseurl, file)
77 cacheOutputPath = '{}/{}'.format(cachePath, file)
78 wget @(url) -O @(cacheOutputPath)
79 pathToCachedFile = '{}/{}'.format(cachePath,file)
80 sha512 = $(sha512sum @(pathToCachedFile) | perl -p -e 's/ .*$//').rstrip()
81 nugetSources.append({
82 'type': 'file',
83 'url': url,
84 'sha512': sha512,
85 'dest': dest
86 })
88processInputSourcesList(inputsPath)
90with open(outputSourcesPath, 'w') as out:
91 yaml.dump(nugetSources, out)