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#!/usr/bin/env python 

2# (c) Stefan Countryman 2017-2019 

3 

4""" 

5Display the current status of some event directory. Defaults to the 

6current directory if no argument provided. Specify the pipeline (collection of 

7files) whose status you would like to see using pipeline flags or just show the 

8status of the entire ``llama.pipeline.DEFAULT_PIPELINE``. 

9""" 

10 

11import sys 

12import shutil 

13from subprocess import Popen, PIPE 

14from llama.run import Parsers as RunParsers 

15from llama.cli import CliParser 

16 

17 

18def get_parser(): 

19 """Get a CLI argument parser.""" 

20 parser = CliParser(description=__doc__, prefix_chars='-+', 

21 parents=( 

22 RunParsers(run=['.']).pipeline_and_eventfiltering, 

23 )) 

24 parser.add_argument('--cruft', action='store_true', help=""" 

25 If provided, print a list of files in the directory 

26 that are not part of the selected pipeline. (Note that 

27 if you downselect from the default pipeline, the cruft 

28 list will include files from the default pipeline that 

29 are not part of your downselection.)""") 

30 parser.add_argument('--ascii', action='store_true', help=""" 

31 If provided, print status in pure ascii with no color 

32 or highlighting.""") 

33 parser.add_argument('--noplot', default=None, action='store_false', 

34 help="If provided, don't plot the Pipeline graph.") 

35 parser.add_argument('--nopager', action='store_false', help=""" 

36 If provided, do not launch a pager for viewing the 

37 ``Event`` summary when the width of the summary is 

38 greater than that of the TTY.""") 

39 return parser 

40 

41 

42def main(): 

43 parser = get_parser() 

44 args = parser.parse_args() 

45 

46 # highlight terms specified with -f or +f 

47 hlargnames = ['f', 'filehandlers'] 

48 prefixes = '+-' 

49 hlparser = CliParser(parents=(parser,), conflict_handler='resolve', 

50 prefix_chars=prefixes) 

51 for prefix in prefixes: 

52 hlparser.add_argument(prefix+hlargnames[0], 2*prefix+hlargnames[1], 

53 nargs='+', action='append') 

54 hlargs = [n for l in hlparser.parse_args().filehandlers or [] 

55 for n in l] 

56 

57 stdout = [sys.stdout.buffer] 

58 proc = None 

59 

60 for run in args.run: 

61 try: 

62 for i, event in enumerate(run.events): 

63 if i > 0: 

64 stdout[0].write(b'\n'+b'='*40+b'\n\n') 

65 report = event.printstatus(cruft=args.cruft, highlight=hlargs, 

66 plot=args.noplot, unicode=not 

67 args.ascii) 

68 if i == 0: 

69 if args.nopager and sys.stdout.isatty(): 

70 tty = shutil.get_terminal_size() 

71 if tty.columns < max(len(l) for l in 

72 report.split('\n')): 

73 try: 

74 proc = Popen(['less', '-SR'], stdin=PIPE) 

75 stdout[0] = proc.stdin 

76 except FileNotFoundError: 

77 pass 

78 stdout[0].write(report.encode()+b'\n') 

79 except BrokenPipeError: 

80 if proc: 

81 sys.exit() 

82 raise 

83 finally: 

84 if proc: 

85 proc.communicate() 

86 

87 

88if __name__ == "__main__": 

89 main()