[TASK] Init
This commit is contained in:
78
in
Executable file
78
in
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
#pylint: disable=invalid-name
|
||||
'''
|
||||
aptly-resource out
|
||||
|
||||
https://github.com/gopythongo/aptly-api-client
|
||||
|
||||
HTTPS_PROXY="http://localhost:8080" \
|
||||
CURL_CA_BUNDLE="$HOME/.mitmproxy/mitmproxy-ca-cert.pem" \
|
||||
./out_test.py
|
||||
|
||||
'''
|
||||
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import requests
|
||||
import semver
|
||||
|
||||
root = os.path.dirname(os.path.abspath(__file__))
|
||||
config = json.loads(sys.stdin.read())
|
||||
directory = sys.argv[1]
|
||||
|
||||
version = config['version']['version']
|
||||
|
||||
package_file_uri = config['source']['repo_uri'] \
|
||||
+ '/' + config['source']['repo'] \
|
||||
+ '/dists' \
|
||||
+ '/' + config['source']['distribution'] \
|
||||
+ '/' + config['source']['component'] \
|
||||
+ '/binary-' + config['source']['architecture'] \
|
||||
+ '/Packages'
|
||||
|
||||
packages_data = requests.get(package_file_uri).text
|
||||
packages_data_blocks = packages_data.strip().split('\n\n')
|
||||
|
||||
match = False
|
||||
|
||||
for packages_data_block in packages_data_blocks:
|
||||
packages_data_block_rows = packages_data_block.split('\n')
|
||||
package = {}
|
||||
for packages_data_block_row in packages_data_block_rows:
|
||||
package_data = packages_data_block_row.split(': ')
|
||||
|
||||
package[package_data[0]] = package_data[1]
|
||||
|
||||
if package['Package'] != config['source']['package']:
|
||||
continue
|
||||
|
||||
if semver.compare(version, package['Version']) != 0:
|
||||
continue
|
||||
|
||||
match = package
|
||||
|
||||
if not match:
|
||||
sys.exit('Package not found')
|
||||
|
||||
package_uri = config['source']['repo_uri'] \
|
||||
+ '/' + config['source']['repo'] \
|
||||
+ '/' + match['Filename']
|
||||
|
||||
package_filename = package_uri.rsplit('/', 1)[1]
|
||||
package_filepath = directory + '/' + package_filename
|
||||
|
||||
with requests.get(package_uri, stream = True) as r:
|
||||
with open(package_filepath, 'wb') as f:
|
||||
shutil.copyfileobj(r.raw, f)
|
||||
|
||||
with open(directory + '/filemane', 'wb') as f:
|
||||
f.write(package_filename.encode())
|
||||
|
||||
print(json.dumps({
|
||||
'version': {'version': match['Version']},
|
||||
'metadata': [
|
||||
{'name': 'sha256', 'value': match['SHA256']}
|
||||
]
|
||||
}))
|
||||
Reference in New Issue
Block a user