This repository was archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpush.py
76 lines (63 loc) · 2.76 KB
/
rpush.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
# -*- coding: utf-8 -*-
"""\
Pybit producer of jobs. This is mostly to be used in testing.
Author: Michael Mulich
Copyright (c) 2012 Rice University
Parts of the client code are derived from the PyBit client implementation at
https://github.com/nicholasdavidson/pybit licensed under GPL2.1.
This software is subject to the provisions of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3.0 (AGPL).
See LICENSE.txt for details.
"""
import json
import argparse
import requests
def create_job(args):
"""Creates a job in PyBit"""
url = "http://{0}:{1}/api/job/".format(args.host, args.port)
auth = (args.user, args.password,)
data = {'package': args.id,
'version': args.version,
'uri': args.uri,
'arch': args.platform,
'dist': args.project,
'suite': args.suite,
'format': args.format,
}
data = json.dumps(data)
headers = {'content-type': 'application/json'}
resp = requests.post(url, data=data, auth=auth, headers=headers)
if resp.status_code != 200:
raise Exception("Failed to add the package with the following data:"
"\ndata: {0}"
"\nresponse status: {1}"
"\nresponse body: {2}"
.format(data, resp.status_code, resp.text))
def main(argv=None):
"""Command line utility"""
parser = argparse.ArgumentParser(description="PyBit builder for rhaptos")
# PyBit connection information
parser.add_argument('--host', default='localhost',
help="PyBit web frontend hostname")
parser.add_argument('--port', type=int, default=8080,
help="Port that the PyBit frontend runs on")
parser.add_argument('--user', default='admin',
help="Username for auth against PyBit")
parser.add_argument('--password', default='pass',
help="password for auth against PyBit")
# Job information
parser.add_argument('id', help="module/collection id")
parser.add_argument('version',
help="version of the module/collection")
parser.add_argument('uri', help="URI to the module/collection")
parser.add_argument('--platform', default='any',
help="platform to build for, default is any")
parser.add_argument('--suite', default='latex',
help="build suite to use, default is latex")
parser.add_argument('--project', default='cnx',
help="build for a specific project, default is cnx")
parser.add_argument('--format', default='pdf',
help="build format, default is pdf")
args = parser.parse_args(argv)
create_job(args)
if __name__ == '__main__':
main()