25
25
log = logging .getLogger (__name__ )
26
26
log .addHandler (logging .StreamHandler (sys .stdout ))
27
27
28
- parser = argparse .ArgumentParser (description = 'Fetch package version updates by using datagrepper log of anitya emitted messages and issue rebuilds of the respective COPR packages for each such update. Requires httpie package.' )
29
28
30
- parser .add_argument ('--backend' , action = 'store' , default = 'pypi' , choices = ['pypi' , 'rubygems' ],
31
- help = 'only check for updates from backend BACKEND, default pypi' )
32
- parser .add_argument ('--delta' , action = 'store' , type = int , metavar = 'SECONDS' , default = 86400 ,
33
- help = 'ignore updates older than SECONDS, default 86400' )
34
- parser .add_argument ('-v' , '--version' , action = 'version' , version = '1.0' ,
35
- help = 'print program version and exit' )
29
+ def _get_parser ():
30
+ parser = argparse .ArgumentParser (description = 'Fetch package version updates by using datagrepper log of anitya emitted messages and issue rebuilds of the respective COPR packages for each such update. Requires httpie package.' )
36
31
37
- args = parser .parse_args ()
32
+ parser .add_argument ('--backend' , action = 'store' , default = 'pypi' , choices = ['pypi' , 'rubygems' ],
33
+ help = 'only check for updates from backend BACKEND, default pypi' )
34
+ parser .add_argument ('--delta' , action = 'store' , type = int , metavar = 'SECONDS' , default = 86400 ,
35
+ help = 'ignore updates older than SECONDS, default 86400' )
36
+ parser .add_argument ('-v' , '--version' , action = 'version' , version = '1.0' ,
37
+ help = 'print program version and exit' )
38
+ return parser
38
39
39
40
40
41
def run_cmd (cmd ):
@@ -58,27 +59,27 @@ def to_json(data_bytes):
58
59
log .exception (str (e ))
59
60
return data_json
60
61
61
- def get_updates_messages ():
62
+ def get_updates_messages (delta ):
62
63
cmd_binary = 'curl'
63
64
url_template = 'https://apps.fedoraproject.org/datagrepper/raw?category=anitya&delta={delta}&topic=org.release-monitoring.prod.anitya.project.version.update&rows_per_page=64&order=asc&page={page}'
64
- get_updates_cmd = [cmd_binary , url_template .format (delta = args . delta , page = 1 )]
65
+ get_updates_cmd = [cmd_binary , url_template .format (delta = delta , page = 1 )]
65
66
result_json = to_json (run_cmd (get_updates_cmd ))
66
67
messages = result_json ['raw_messages' ]
67
68
pages = result_json ['pages' ]
68
69
69
70
for p in range (2 , pages + 1 ):
70
- get_updates_cmd = [cmd_binary , url_template .format (delta = args . delta , page = p )]
71
+ get_updates_cmd = [cmd_binary , url_template .format (delta = delta , page = p )]
71
72
result_json = to_json (run_cmd (get_updates_cmd ))
72
73
messages += result_json ['raw_messages' ]
73
74
74
75
return messages
75
76
76
- def get_updated_packages (updates_messages ):
77
+ def get_updated_packages (updates_messages , backend ):
77
78
updated_packages = {}
78
79
for message in updates_messages :
79
80
update = message ['msg' ]
80
81
project = update ['project' ]
81
- if args . backend . lower () != project ['backend' ].lower ():
82
+ if backend != project ['backend' ].lower ():
82
83
continue
83
84
updated_packages [project ['name' ].lower ()] = project ['version' ]
84
85
return updated_packages
@@ -111,15 +112,14 @@ def build(self, copr, new_updated_version):
111
112
background = True ,
112
113
)
113
114
114
-
115
115
def package_from_source (backend , source_json ):
116
116
try :
117
117
return {
118
118
'pypi' : PyPIPackage ,
119
119
'rubygems' : RubyGemsPackage ,
120
120
}[backend ](source_json )
121
121
except KeyError :
122
- raise Exception ('Unsupported backend {0} passed as command-line argument' .format (args . backend ))
122
+ raise Exception ('Unsupported backend {0} passed as command-line argument' .format (backend ))
123
123
124
124
125
125
def is_prerelease (version : str ) -> bool :
@@ -139,12 +139,14 @@ def is_prerelease(version: str) -> bool:
139
139
return False
140
140
141
141
def main ():
142
- updated_packages = get_updated_packages (get_updates_messages ())
142
+ args = _get_parser ().parse_args ()
143
+ backend = args .backend .lower ()
144
+ updated_packages = get_updated_packages (get_updates_messages (args .delta ), backend )
143
145
log .info ("Updated packages per datagrepper %s" , len (updated_packages ))
144
146
for package , last_build in PackagesLogic .webhook_package_candidates (
145
147
helpers .BuildSourceEnum (args .backend .lower ())):
146
148
source_json = json .loads (package .source_json )
147
- rebuilder = package_from_source (args . backend . lower () , source_json )
149
+ rebuilder = package_from_source (backend , source_json )
148
150
log .debug (
149
151
"candidate %s package %s in %s" ,
150
152
args .backend ,
0 commit comments