-
Notifications
You must be signed in to change notification settings - Fork 8
/
fetch-dot-source
executable file
·78 lines (67 loc) · 2.27 KB
/
fetch-dot-source
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
#!/usr/bin/env python3
import logging
import getopt
import sys
import os
from osgbuild.main import log, log_consolehandler
from osgbuild.error import Error
from osgbuild.fetch_sources import C, process_dot_source
def usage(exit):
print("Usage: {script} [-d destdir] [options] upstream.source [...]\n\n"
"Options:\n"
" -d destdir specify output location\n"
" -n do not require matching hashes (nocheck)\n"
" -s extract rpm spec from git sources (want_spec)\n"
" -v verbose; set loglevel to DEBUG\n"
" -q quiet; set loglevel to WARNING (no INFO msgs)\n"
" -c cachepfx specify upstream cache location prefix\n"
" -a set upstream cache prefix to UW AFS location\n"
.format(script=os.path.basename(__file__)))
sys.exit(exit)
def setloglevel(level):
log.setLevel(level)
log_consolehandler.setLevel(level)
options = dict(
cache_prefix = C.WEB_CACHE_PREFIX,
destdir = '.',
nocheck = False,
want_spec = False
)
try:
ops, dot_sources = getopt.getopt(sys.argv[1:], 'd:hnsvqc:a')
except getopt.GetoptError:
usage(2)
if not dot_sources:
usage(2)
for op,val in ops:
if op == '-n': options['nocheck'] = True
elif op == '-s': options['want_spec'] = True
elif op == '-d': options['destdir'] = val
elif op == '-c': options['cache_prefix'] = val
elif op == '-a': options['cache_prefix'] = C.AFS_CACHE_PREFIX
elif op == '-v': setloglevel(logging.DEBUG)
elif op == '-q': setloglevel(logging.WARNING)
elif op == '-h': usage(0)
def main():
for src in dot_sources:
files = process_dot_source(sfilename=src, **options)
for f in files:
print(f)
try:
main()
except KeyboardInterrupt:
print("-" * 79, file=sys.stderr)
print("Interrupted", file=sys.stderr)
print("-" * 79, file=sys.stderr)
sys.exit(3)
except Error as err:
print("-" * 79, file=sys.stderr)
print(err, file=sys.stderr)
print("-" * 79, file=sys.stderr)
sys.exit(4)
except Exception as err:
print("-" * 79, file=sys.stderr)
print("Unhandled exception:", file=sys.stderr)
print(err, file=sys.stderr)
print("-" * 79, file=sys.stderr)
sys.exit(1)