-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrippums.py
93 lines (76 loc) · 2.38 KB
/
rippums.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
import argparse
import json
import logging
import random
import subprocess
import os
import functools
import signal
import json
from support.builder import Builder
from support.env import *
from support.api_client import fclient_all_pkgs
from support.vcs import vcs_commit_and_push
from support.rpm import rpm_install_rpms, rpm_can_build
class Rippums:
log = logging.getLogger('fedorip')
skiplist = []
def __init__(self):
self.log.setLevel(logging.DEBUG)
sh = logging.StreamHandler()
sh.setLevel(logging.INFO)
sh.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
self.log.addHandler(sh)
if os.path.exists('skiplist.json'):
skl = open('skiplist.json', 'r')
self.skiplist = json.loads(skl.read())
skl.close()
signal.signal(signal.SIGINT, self.handle_sigint)
def handle_sigint(self, signum, frame):
self.log.error('OK! Stopping + dumping skiplist')
f = open('skiplist.json', 'w')
f.write(json.dumps(self.skiplist))
f.close()
exit(0)
def start(self, pattern):
for frame in fclient_all_pkgs(pattern):
self.log.info(
'QUERY: %s, PAGE: %d/%d' % (
pattern,
frame['pagination']['page'],
frame['pagination']['pages']
)
)
for pkg in frame['projects']:
self.log.info('Attempting %s' % pkg['name'])
if pkg['name'] in self.skiplist:
self.log.info('Package %s in skiplist', pkg['name'])
continue
self.skiplist.append(pkg['name'])
can_build = rpm_can_build(pkg['name'])
if not can_build:
self.log.info('Skipping %s', pkg['name'])
continue
rip_results = Builder().build(pkg['name'])
rip_results['installed'] = rpm_install_rpms(rip_results['rpms_out'])
if not len(rip_results['installed']):
continue
vcs_commit_and_push(rip_results)
f = open('skiplist.json', 'w')
f.write(json.dumps(self.skiplist))
f.close()
exit(0)
def parse_args():
parser = argparse.ArgumentParser(description='rippums!!!!')
parser.add_argument(
'--fetch-pattern',
help='Get all packages matching pattern, save to rippums.json',
default=False,
type=str,
required=True
)
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
Rippums().start(args.fetch_pattern)