14
14
"""
15
15
import logging
16
16
import sys
17
+ import time
17
18
from datetime import date , timedelta
18
19
19
20
from .core import reformat_change
@@ -47,6 +48,18 @@ def format_changes(after: date, submit: bool = False):
47
48
reformat_change (context , change ["id" ], change ["current_revision" ], submit )
48
49
49
50
51
+ def daemon_mode (timeout : int , after : date , submit : bool = False ):
52
+ logger = logging .getLogger ("daemon" )
53
+ logger .info ("Starting daemon with timeout set to %i seconds" % timeout )
54
+ if not submit :
55
+ logger .warning ("Running in dry-run mode (submit is set to false)" )
56
+ while True :
57
+ logger .info ("Starting daemon run" )
58
+ format_changes (after , submit )
59
+ logger .info ("Daemon run finished. Sleeping for %i seconds" % timeout )
60
+ time .sleep (timeout )
61
+
62
+
50
63
if __name__ == "__main__" :
51
64
import argparse
52
65
@@ -55,8 +68,14 @@ def format_changes(after: date, submit: bool = False):
55
68
description = "Automates running `haiku-format` on changes on Haiku's Gerrit instance" )
56
69
parser .add_argument ("--days" , type = int , default = 3 ,
57
70
help = "Number of days in the past to select changes for reformatting" )
71
+ parser .add_argument ("--timeout" , type = int , default = 300 ,
72
+ help = "Time in seconds to wait between runs when in daemon mode" )
73
+ parser .add_argument ('--daemon' , action = "store_true" , help = "submit" )
58
74
parser .add_argument ('--submit' , action = "store_true" , help = "submit the reviews to gerrit" )
59
75
args = parser .parse_args ()
60
76
logging .basicConfig (stream = sys .stdout , level = logging .INFO )
61
77
start_date = date .today () - timedelta (days = args .days )
62
- format_changes (start_date , args .submit )
78
+ if args .daemon :
79
+ daemon_mode (args .timeout , start_date , args .submit )
80
+ else :
81
+ format_changes (start_date , args .submit )
0 commit comments