8 from collections
import defaultdict
9 from tempfile
import NamedTemporaryFile
11 re_platformdir
= re
.compile('^(\w+)-(\d+)-([^-]+)$')
13 if __name__
== "__main__":
14 parser
= argparse
.ArgumentParser(description
="Spider repo RPMs")
15 parser
.add_argument('yumroot', type=str, help='YUM root path')
16 parser
.add_argument('target', type=str, help='Target URL or filename')
18 args
= parser
.parse_args()
20 platforms
= defaultdict(list)
21 for repodir
in os
.listdir('{0}/reporpms'.format(args
.yumroot
)):
22 m
= re_platformdir
.match(repodir
)
27 platforms
['{0}-{1}'.format(platname
, platver
)].append(arch
)
29 j
= json
.dumps({'platforms': platforms
})
31 if args
.target
.startswith('http://') or args
.target
.startswith('https://'):
36 'Content-type': 'application/json',
37 'Host': 'www.postgresql.org',
40 if r
.status_code
!= 200:
41 print("Failed to upload, code: %s" % r
.status_code
)
44 if r
.text
!= "NOT CHANGED" and r
.text
!= "OK":
45 print("Failed to upload: %s" % x
)
48 with
NamedTemporaryFile(mode
='w', dir=os
.path
.dirname(os
.path
.abspath(args
.target
))) as f
:
51 if os
.path
.isfile(args
.target
):
52 os
.unlink(args
.target
)
53 os
.link(f
.name
, args
.target
)