@@ -1035,6 +1035,58 @@ def action_sync(args, config):
10351035 )
10361036 synchronizer .run ()
10371037
1038+ def action_query (args , config ):
1039+ """Action for 'query' command."""
1040+ staff , modules = staff_modules (config )
1041+ pkglist = sorted (Package .list (config , staff , modules , args .packages ),
1042+ key = attrgetter ('name' ))
1043+
1044+ tbl = TextTable ()
1045+ tbl .fmt = args .fmt or '%name %module %maintainers %version %release ' \
1046+ '%modulemanager'
1047+ tbl .show_header = args .headers
1048+ tbl .color = True
1049+
1050+ supported_keys = set (('name' , 'module' , 'origin' , 'reason' , 'tests' ,
1051+ 'version' , 'arch' , 'release' , 'changelogname' ,
1052+ 'changelogtime' , 'maintainers' , 'modulemanager' ,
1053+ 'buildrequires' ))
1054+ diff_keys = set (tbl .pattern_fields ()) - supported_keys
1055+ if diff_keys :
1056+ raise RiftError (f"Unknown placeholder(s): { ', ' .join (diff_keys )} "
1057+ f"(supported keys are: { ', ' .join (supported_keys )} )" )
1058+
1059+ for pkg in pkglist :
1060+ logging .debug ('Loading package %s' , pkg .name )
1061+ try :
1062+ pkg .load ()
1063+ spec = Spec (config = config )
1064+ if args .spec :
1065+ spec .filepath = pkg .specfile
1066+ spec .load ()
1067+ except RiftError as exp :
1068+ logging .error ("%s: %s" , pkg .name , str (exp ))
1069+ continue
1070+
1071+ date = str (time .strftime ("%Y-%m-%d" , time .localtime (spec .changelog_time )))
1072+ modulemanager = staff .get (modules .get (pkg .module ).get ('manager' )[0 ])
1073+ tbl .append ({'name' : pkg .name ,
1074+ 'module' : pkg .module ,
1075+ 'origin' : pkg .origin ,
1076+ 'reason' : pkg .reason ,
1077+ 'tests' : str (len (list (pkg .tests ()))),
1078+ 'version' : spec .version ,
1079+ 'arch' : spec .arch ,
1080+ 'release' : spec .release ,
1081+ 'changelogname' : spec .changelog_name ,
1082+ 'changelogtime' : date ,
1083+ 'buildrequires' : spec .buildrequires ,
1084+ 'modulemanager' : modulemanager ['email' ],
1085+ 'maintainers' : ', ' .join (pkg .maintainers )})
1086+ print (tbl )
1087+
1088+ return 0
1089+
10381090def create_staging_repo (config ):
10391091 """
10401092 Create and return staging temporary repository with a 2-tuple containing
@@ -1149,55 +1201,9 @@ def action(config, args):
11491201 elif args .command == 'validdiff' :
11501202 return action_validdiff (args , config )
11511203
1204+ # QUERY
11521205 elif args .command == 'query' :
1153-
1154- staff , modules = staff_modules (config )
1155- pkglist = sorted (Package .list (config , staff , modules , args .packages ),
1156- key = attrgetter ('name' ))
1157-
1158- tbl = TextTable ()
1159- tbl .fmt = args .fmt or '%name %module %maintainers %version %release ' \
1160- '%modulemanager'
1161- tbl .show_header = args .headers
1162- tbl .color = True
1163-
1164- supported_keys = set (('name' , 'module' , 'origin' , 'reason' , 'tests' ,
1165- 'version' , 'arch' , 'release' , 'changelogname' ,
1166- 'changelogtime' , 'maintainers' , 'modulemanager' ,
1167- 'buildrequires' ))
1168- diff_keys = set (tbl .pattern_fields ()) - supported_keys
1169- if diff_keys :
1170- raise RiftError (f"Unknown placeholder(s): { ', ' .join (diff_keys )} "
1171- f"(supported keys are: { ', ' .join (supported_keys )} )" )
1172-
1173- for pkg in pkglist :
1174- logging .debug ('Loading package %s' , pkg .name )
1175- try :
1176- pkg .load ()
1177- spec = Spec (config = config )
1178- if args .spec :
1179- spec .filepath = pkg .specfile
1180- spec .load ()
1181- except RiftError as exp :
1182- logging .error ("%s: %s" , pkg .name , str (exp ))
1183- continue
1184-
1185- date = str (time .strftime ("%Y-%m-%d" , time .localtime (spec .changelog_time )))
1186- modulemanager = staff .get (modules .get (pkg .module ).get ('manager' )[0 ])
1187- tbl .append ({'name' : pkg .name ,
1188- 'module' : pkg .module ,
1189- 'origin' : pkg .origin ,
1190- 'reason' : pkg .reason ,
1191- 'tests' : str (len (list (pkg .tests ()))),
1192- 'version' : spec .version ,
1193- 'arch' : spec .arch ,
1194- 'release' : spec .release ,
1195- 'changelogname' : spec .changelog_name ,
1196- 'changelogtime' : date ,
1197- 'buildrequires' : spec .buildrequires ,
1198- 'modulemanager' : modulemanager ['email' ],
1199- 'maintainers' : ', ' .join (pkg .maintainers )})
1200- print (tbl )
1206+ return action_query (args , config )
12011207
12021208 elif args .command == 'changelog' :
12031209
0 commit comments