@@ -995,6 +995,58 @@ def action_sync(args, config):
995995 )
996996 synchronizer .run ()
997997
998+ def action_query (args , config ):
999+ """Action for 'query' command."""
1000+ staff , modules = staff_modules (config )
1001+ pkglist = sorted (Package .list (config , staff , modules , args .packages ),
1002+ key = attrgetter ('name' ))
1003+
1004+ tbl = TextTable ()
1005+ tbl .fmt = args .fmt or '%name %module %maintainers %version %release ' \
1006+ '%modulemanager'
1007+ tbl .show_header = args .headers
1008+ tbl .color = True
1009+
1010+ supported_keys = set (('name' , 'module' , 'origin' , 'reason' , 'tests' ,
1011+ 'version' , 'arch' , 'release' , 'changelogname' ,
1012+ 'changelogtime' , 'maintainers' , 'modulemanager' ,
1013+ 'buildrequires' ))
1014+ diff_keys = set (tbl .pattern_fields ()) - supported_keys
1015+ if diff_keys :
1016+ raise RiftError (f"Unknown placeholder(s): { ', ' .join (diff_keys )} "
1017+ f"(supported keys are: { ', ' .join (supported_keys )} )" )
1018+
1019+ for pkg in pkglist :
1020+ logging .debug ('Loading package %s' , pkg .name )
1021+ try :
1022+ pkg .load ()
1023+ spec = Spec (config = config )
1024+ if args .spec :
1025+ spec .filepath = pkg .specfile
1026+ spec .load ()
1027+ except RiftError as exp :
1028+ logging .error ("%s: %s" , pkg .name , str (exp ))
1029+ continue
1030+
1031+ date = str (time .strftime ("%Y-%m-%d" , time .localtime (spec .changelog_time )))
1032+ modulemanager = staff .get (modules .get (pkg .module ).get ('manager' )[0 ])
1033+ tbl .append ({'name' : pkg .name ,
1034+ 'module' : pkg .module ,
1035+ 'origin' : pkg .origin ,
1036+ 'reason' : pkg .reason ,
1037+ 'tests' : str (len (list (pkg .tests ()))),
1038+ 'version' : spec .version ,
1039+ 'arch' : spec .arch ,
1040+ 'release' : spec .release ,
1041+ 'changelogname' : spec .changelog_name ,
1042+ 'changelogtime' : date ,
1043+ 'buildrequires' : spec .buildrequires ,
1044+ 'modulemanager' : modulemanager ['email' ],
1045+ 'maintainers' : ', ' .join (pkg .maintainers )})
1046+ print (tbl )
1047+
1048+ return 0
1049+
9981050def create_staging_repo (config ):
9991051 """
10001052 Create and return staging temporary repository with a 2-tuple containing
@@ -1104,55 +1156,9 @@ def action(config, args):
11041156 elif args .command == 'validdiff' :
11051157 return action_validdiff (args , config )
11061158
1159+ # QUERY
11071160 elif args .command == 'query' :
1108-
1109- staff , modules = staff_modules (config )
1110- pkglist = sorted (Package .list (config , staff , modules , args .packages ),
1111- key = attrgetter ('name' ))
1112-
1113- tbl = TextTable ()
1114- tbl .fmt = args .fmt or '%name %module %maintainers %version %release ' \
1115- '%modulemanager'
1116- tbl .show_header = args .headers
1117- tbl .color = True
1118-
1119- supported_keys = set (('name' , 'module' , 'origin' , 'reason' , 'tests' ,
1120- 'version' , 'arch' , 'release' , 'changelogname' ,
1121- 'changelogtime' , 'maintainers' , 'modulemanager' ,
1122- 'buildrequires' ))
1123- diff_keys = set (tbl .pattern_fields ()) - supported_keys
1124- if diff_keys :
1125- raise RiftError (f"Unknown placeholder(s): { ', ' .join (diff_keys )} "
1126- f"(supported keys are: { ', ' .join (supported_keys )} )" )
1127-
1128- for pkg in pkglist :
1129- logging .debug ('Loading package %s' , pkg .name )
1130- try :
1131- pkg .load ()
1132- spec = Spec (config = config )
1133- if args .spec :
1134- spec .filepath = pkg .specfile
1135- spec .load ()
1136- except RiftError as exp :
1137- logging .error ("%s: %s" , pkg .name , str (exp ))
1138- continue
1139-
1140- date = str (time .strftime ("%Y-%m-%d" , time .localtime (spec .changelog_time )))
1141- modulemanager = staff .get (modules .get (pkg .module ).get ('manager' )[0 ])
1142- tbl .append ({'name' : pkg .name ,
1143- 'module' : pkg .module ,
1144- 'origin' : pkg .origin ,
1145- 'reason' : pkg .reason ,
1146- 'tests' : str (len (list (pkg .tests ()))),
1147- 'version' : spec .version ,
1148- 'arch' : spec .arch ,
1149- 'release' : spec .release ,
1150- 'changelogname' : spec .changelog_name ,
1151- 'changelogtime' : date ,
1152- 'buildrequires' : spec .buildrequires ,
1153- 'modulemanager' : modulemanager ['email' ],
1154- 'maintainers' : ', ' .join (pkg .maintainers )})
1155- print (tbl )
1161+ return action_query (args , config )
11561162
11571163 elif args .command == 'changelog' :
11581164
0 commit comments