2018-06-25 19:49:40 +04:00
""" Find outdated tasks """
from __future__ import print_function
import errno
2018-08-13 12:56:07 +04:00
import json
2018-06-25 19:49:40 +04:00
import logging
import os
import sys
from port_stats import lists
2018-06-26 13:03:42 +04:00
from port_stats import rpm_ffi
2018-06-25 19:49:40 +04:00
from port_stats import tasks
from port_stats import utils
2019-01-17 13:25:22 +04:00
LOG = logging . getLogger ( __name__ )
2018-06-25 19:49:40 +04:00
def subtask_srpm_nevr ( task , subtask_id ) :
try :
nevr_file = os . path . join ( task [ ' task_path ' ] , ' gears ' ,
str ( subtask_id ) , ' nevr ' )
with open ( nevr_file , ' r ' ) as f :
data = f . read ( )
name , evr = data . strip ( ) . split ( ' \t ' )
return name , evr
except OSError as e :
if e . errno == errno . ENOENT :
return None , None
2023-03-10 14:42:01 +04:00
except Exception :
2018-06-25 19:49:40 +04:00
pass
LOG . info ( ' Failed to parse subtask NEVR for %s %s ' , task , subtask_id )
return None , None
def is_outdated ( task , package_evrs ) :
2019-02-04 21:02:19 +04:00
if ' /archive/ ' in task [ ' task_path ' ] :
2018-06-25 19:49:40 +04:00
return False
2023-03-10 14:42:01 +04:00
for subid , subtask in utils . items ( task [ ' subtasks ' ] ) :
2018-06-25 19:49:40 +04:00
if list ( subtask . keys ( ) ) == [ ' userid ' ] :
continue
if ' srpm ' not in subtask :
return False
name , evr = subtask_srpm_nevr ( task , subid )
if name is None or evr is None :
return False
2018-06-26 13:03:42 +04:00
existing_nevr = package_evrs . get ( name )
if existing_nevr is None :
2018-06-25 19:49:40 +04:00
return False
2018-06-26 13:03:42 +04:00
task_evr = rpm_ffi . parse_evr ( evr )
2021-09-08 12:11:39 +04:00
if rpm_ffi . evr_cmp ( task_evr , existing_nevr . evr ) > 0 :
2018-06-25 19:49:40 +04:00
return False
return True
2021-08-12 15:05:36 +04:00
def main ( config_path , repo , owner = ' all ' ) :
2018-06-25 19:49:40 +04:00
logging . basicConfig (
format = ' %(asctime)s %(levelname)-5s %(name)s - %(message)s ' ,
datefmt = ' % Y- % m- %d % H: % M: % S ' ,
stream = sys . stderr , level = logging . INFO )
2018-08-13 12:56:07 +04:00
with open ( config_path ) as f :
config = json . load ( f )
repo_cfg = config [ ' repos ' ] [ repo ]
nevrs = lists . read_srclists ( repo_cfg [ ' path ' ] , repo_cfg [ ' arch ' ] )
2018-06-26 13:03:42 +04:00
existing = dict ( ( p . name , p ) for p in nevrs )
2018-06-25 19:49:40 +04:00
2018-08-13 12:56:07 +04:00
task_list = tasks . load_tasks ( config [ ' tasks ' ] , repo )
2018-06-25 19:49:40 +04:00
2021-08-12 15:05:36 +04:00
outdated = ( task for task in task_list
if task [ ' repo ' ] == repo and is_outdated ( task , existing ) )
if owner and owner != ' all ' :
outdated = ( task for task in outdated
if task [ ' owner ' ] == owner )
2018-06-25 19:49:40 +04:00
for task in outdated :
print ( tasks . format_task ( task ) )
2018-08-13 12:56:07 +04:00
2018-06-25 19:49:40 +04:00
if __name__ == ' __main__ ' :
sys . exit ( main ( * sys . argv [ 1 : ] ) )