Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# (c) Stefan Countryman, 2019 

2 

3import logging 

4from time import sleep 

5from llama.dev.clean import ( 

6 __doc__, 

7 LOGFILE, 

8 TEST_ARCHIVE, 

9 cleanup_testevents, 

10 set_flags_oldevents, 

11) 

12from llama.cli import ( 

13 CliParser, 

14 get_logging_cli, 

15) 

16from llama.flags.cli import Parsers as FlagParsers 

17from llama.run import Parsers as RunParsers 

18 

19LOGGER = logging.getLogger(__name__) 

20 

21 

22def get_parser(): 

23 """Get CLI parser.""" 

24 parser = CliParser( 

25 prog="llama dev clean", 

26 description=__doc__, 

27 parents=( 

28 RunParsers().eventfiltering, 

29 FlagParsers().flags, 

30 get_logging_cli(LOGFILE, 'info'), 

31 ), 

32 ) 

33 parser.add_argument('--repeat', type=float, help=""" 

34 If provided, run again every ``REPEAT`` seconds.""") 

35 parser.add_argument('--dry-run', action='store_true', help=""" 

36 If provided, don't actually do anything; just log what would be 

37 done.""") 

38 parser.add_argument('--testevents', action='store_true', help=""" 

39 Clean up matching event files created by GCN listeners, LVAlert 

40 listeners, and the like and move them to ``--test-archive-dir``.""") 

41 parser.add_argument('--test-archive-dir', default=TEST_ARCHIVE, help=f""" 

42 The destination directory for archived events if ``--testevents`` is 

43 specified. (default: {TEST_ARCHIVE})""") 

44 return parser 

45 

46 

47def main(): 

48 """Run LLAMA cleanup.""" 

49 parser = get_parser() 

50 args = parser.parse_args() 

51 assert args.run 

52 while True: 

53 if args.dry_run: 

54 LOGGER.info("BEGIN DRY RUN") 

55 for run in args.run: 

56 LOGGER.info("Running with run downselection %s, args %s ", 

57 run.downselection, args) 

58 if args.testevents: 

59 cleanup_testevents(run, args.test_archive_dir, args.dry_run) 

60 if args.flags: 

61 set_flags_oldevents(run, args.dry_run, args.flags) 

62 if args.dry_run: 

63 LOGGER.info("END DRY RUN") 

64 if args.repeat is None: 

65 break 

66 LOGGER.info("Sleeping for %s seconds before repeating", args.repeat) 

67 sleep(args.repeat)