@@ -46,7 +46,7 @@ def iter_all_visits() -> Iterator[Res[DbVisit]]:
4646 yield e
4747
4848
49- def _do_index () -> Iterable [Exception ]:
49+ def _do_index (dry : bool = False ) -> Iterable [Exception ]:
5050 # also keep & return errors for further display
5151 errors : List [Exception ] = []
5252 def it ():
@@ -55,17 +55,23 @@ def it():
5555 errors .append (v )
5656 yield v
5757
58- dump_errors = visits_to_sqlite (it ())
59- for e in dump_errors :
60- logger .exception (e )
61- errors .append (e )
58+ if dry :
59+ res = list (it ())
60+ logger .warning ("DRY MODE: won't modify the database. Printing the results out" )
61+ for v in res :
62+ print (v )
63+ else :
64+ dump_errors = visits_to_sqlite (it ())
65+ for e in dump_errors :
66+ logger .exception (e )
67+ errors .append (e )
6268 return errors
6369
6470
65- def do_index (config_file : Path ) -> None :
71+ def do_index (config_file : Path , dry : bool = False ) -> None :
6672 config .load_from (config_file ) # meh.. should be cleaner
6773 try :
68- errors = list (_do_index ())
74+ errors = list (_do_index (dry = dry ))
6975 finally :
7076 config .reset ()
7177 if len (errors ) > 0 :
@@ -249,6 +255,7 @@ def main() -> None:
249255 subp = p .add_subparsers (dest = 'mode' , )
250256 ep = subp .add_parser ('index' , help = 'Create/update the link database' , formatter_class = F )
251257 ep .add_argument ('--config' , type = Path , default = default_config_path (), help = 'Config path' )
258+ ep .add_argument ('--dry' , action = 'store_true' , help = "Dry run, won't touch the database, only print the results out" )
252259 # TODO use some way to override or provide config only via cmdline?
253260 ep .add_argument ('--intermediate' , required = False , help = "Used for development, you don't need it" )
254261
@@ -310,7 +317,7 @@ def main() -> None:
310317
311318 with get_tmpdir () as tdir : # TODO??
312319 if args .mode == 'index' :
313- do_index (config_file = args .config )
320+ do_index (config_file = args .config , dry = args . dry )
314321 elif args .mode == 'serve' :
315322 server .run (args )
316323 elif args .mode == 'demo' :
0 commit comments