17
17
# along with Patchman. If not, see <http://www.gnu.org/licenses/>
18
18
19
19
20
+ import click
20
21
import os
21
22
import sys
22
23
import argparse
@@ -122,7 +123,7 @@ def refresh_repos(repo=None, force=False):
122
123
info_message .send (sender = None , text = '' )
123
124
124
125
125
- def list_repos (repos = None ):
126
+ def show_repos (repos = None ):
126
127
""" Print info about a list of repositories
127
128
Defaults to all repos
128
129
"""
@@ -131,7 +132,7 @@ def list_repos(repos=None):
131
132
repo .show ()
132
133
133
134
134
- def list_hosts (hosts = None ):
135
+ def show_hosts (hosts = None ):
135
136
""" Print info about a list of hosts
136
137
Defaults to all hosts
137
138
"""
@@ -224,6 +225,21 @@ def clean_repos():
224
225
repo .delete ()
225
226
update_pbar (i + 1 )
226
227
228
+ def list_reports (s_host = None , processed = False ):
229
+ """ List reports for all hosts, specify host for a single host.
230
+ """
231
+ hosts = get_hosts (s_host , 'Listing Reports' )
232
+
233
+ for host in hosts :
234
+ info_message .send (sender = None , text = str (host ))
235
+ reports = Report .objects .filter (host = host , processed = processed )
236
+
237
+ if s_host is None :
238
+ reports = Report .objects .filter (processed = processed )
239
+
240
+ for i , report in enumerate (reports ):
241
+ print (report )
242
+
227
243
228
244
def clean_reports (s_host = None ):
229
245
""" Delete old reports for all hosts, specify host for a single host.
@@ -270,8 +286,9 @@ def clean_tags():
270
286
update_pbar (i + 1 )
271
287
272
288
273
- def host_updates_alt (host = None ):
289
+ def find_host_updates_bulk (host = None ):
274
290
""" Find updates for all hosts, specify host for a single host
291
+ This algo works faster for updating multiple similar hosts
275
292
"""
276
293
updated_hosts = []
277
294
hosts = get_hosts (host , 'Finding updates' )
@@ -322,7 +339,7 @@ def host_updates_alt(host=None):
322
339
info_message .send (sender = None , text = text )
323
340
324
341
325
- def host_updates (host = None ):
342
+ def find_host_updates (host = None ):
326
343
""" Find updates for all hosts, specify host for a single host
327
344
"""
328
345
hosts = get_hosts (host , 'Finding updates' )
@@ -436,7 +453,7 @@ def toggle_host_check_dns(hosts=None, check_dns=True):
436
453
host .save ()
437
454
438
455
439
- def dns_checks (host = None ):
456
+ def check_host_dns (host = None ):
440
457
""" Check all hosts for reverse DNS mismatches, specify host for a single
441
458
host
442
459
"""
@@ -476,7 +493,7 @@ def clean_updates():
476
493
""" Removes PackageUpdate objects that are no longer
477
494
linked to any hosts
478
495
"""
479
- package_updates = list (PackageUpdate .objects .all ())
496
+ package_updates = list (PackageUpdate .objects .all (). distinct () )
480
497
481
498
for update in package_updates :
482
499
if update .host_set .count () == 0 :
@@ -497,7 +514,7 @@ def clean_updates():
497
514
duplicate .delete ()
498
515
499
516
500
- def dbcheck ():
517
+ def clean_db ():
501
518
""" Runs all clean_* functions to check database consistency
502
519
"""
503
520
clean_updates ()
@@ -509,7 +526,7 @@ def dbcheck():
509
526
clean_tags ()
510
527
511
528
512
- def collect_args ():
529
+ def collect_args1 ():
513
530
""" Collect argparse arguments
514
531
"""
515
532
parser = argparse .ArgumentParser (description = 'Patchman CLI tool' )
@@ -588,7 +605,7 @@ def collect_args():
588
605
return parser
589
606
590
607
591
- def process_args (args ):
608
+ def process_args1 (args ):
592
609
""" Process command line arguments
593
610
"""
594
611
@@ -672,15 +689,114 @@ def process_args(args):
672
689
return showhelp
673
690
674
691
675
- def main ():
676
-
677
- parser = collect_args ()
678
- args = parser .parse_args ()
679
- set_verbosity (not args .quiet )
680
- showhelp = process_args (args )
681
- if showhelp :
682
- parser .print_help ()
683
-
692
+ @click .group ()
693
+ @click .option ('-q' , '--quiet' , is_flag = True , default = False )
694
+ @click .option ('-f' , '--force' , is_flag = True , default = False )
695
+ @click .pass_context
696
+ def cli (ctx , quiet , force ):
697
+ set_verbosity (not quiet )
698
+ ctx .ensure_object (dict )
699
+ ctx .obj ['force' ] = force
700
+
701
+ @cli .group ('host' )
702
+ def host ():
703
+ pass
704
+
705
+ @host .command ()
706
+ @click .option ('-H' , '--host' )
707
+ def show (host ):
708
+ show_hosts (host )
709
+
710
+ @host .command ()
711
+ @click .option ('-H' , '--host' )
712
+ def find_updates (host ):
713
+ find_host_updates (host )
714
+
715
+ @host .command ()
716
+ @click .option ('-H' , '--host' )
717
+ def find_updates_bulk (host ):
718
+ find_host_updates_bulk (host )
719
+
720
+ @host .command ()
721
+ @click .option ('-A' , required = True )
722
+ @click .option ('-B' , required = True )
723
+ def diff (A , B ):
724
+ diff_hosts (A , B )
725
+
726
+ @host .command ()
727
+ @click .option ('-H' , '--host' )
728
+ def check_dns (host ):
729
+ check_host_dns (host )
730
+
731
+ @host .group ('set' )
732
+ def host_set ():
733
+ pass
734
+
735
+ @cli .group ('repo' )
736
+ def repo ():
737
+ pass
738
+
739
+ @repo .command ()
740
+ @click .option ('-R' , '--repo' )
741
+ @click .pass_context
742
+ def refresh (ctx , repo ):
743
+ refresh_repos (repo , ctx .obj ['force' ])
744
+
745
+ @repo .command ()
746
+ @click .option ('-R' , '--repo' )
747
+ def show (repo ):
748
+ show_repos (repo )
749
+
750
+ @host_set .command ()
751
+ @click .pass_context
752
+ def dns (ctx ):
753
+ click .echo ('Settings host DNS' )
754
+
755
+
756
+ @cli .group ('report' )
757
+ @click .pass_context
758
+ @click .option ('-H' , '--host' )
759
+ def report (ctx , host = None ):
760
+ pass
761
+
762
+ @report .command ()
763
+ @click .option ('-H' , '--host' )
764
+ @click .option ('-a' , '--all-reports' , is_flag = True , default = False , help = 'include processed reports' )
765
+ def list (host , all_reports ):
766
+ list_reports (host , not all_reports )
767
+ #FIXME
768
+
769
+ @report .command ()
770
+ @click .option ('-H' , '--host' )
771
+ @click .pass_context
772
+ def process (ctx , host ):
773
+ process_reports (host , ctx .obj ['force' ])
774
+
775
+ @report .command ()
776
+ @click .option ('-H' , '--host' )
777
+ def clean (host ):
778
+ clean_reports (host )
779
+
780
+ @cli .group ('database' )
781
+ def database ():
782
+ pass
783
+
784
+ @database .command ()
785
+ def clean ():
786
+ clean_db ()
787
+
788
+ @cli .group ('errata' )
789
+ def errata ():
790
+ pass
791
+
792
+ @errata .command ()
793
+ @click .pass_context
794
+ def download (ctx ):
795
+ update_errata (ctx .obj ['force' ])
796
+
797
+ @errata .command ()
798
+ def apply ():
799
+ mark_errata_security_updates ()
684
800
685
801
if __name__ == '__main__' :
686
- main ()
802
+ cli ()
0 commit comments