BmnRoot
Loading...
Searching...
No Matches
check_success.py
Go to the documentation of this file.
1import os, re
2import sys, getopt
3import glob
4import mmap
5
6# GLOBAL CONSTANTS
7success_marker = "FINISH (event"
8
9# MAIN CODE
10try:
11 options, remainder = getopt.getopt(sys.argv[1:], "hi:r",["help", "input", "remove"])
12except getopt.GetoptError:
13 print 'USAGE: python check_success.py -i \"[<input_direcory>,<regular_expression_files>]\" [--remove]\n'
14 sys.exit(1)
15
16file_list = ""
17remove_option = False
18for opt, arg in options:
19 if opt in ('-h', '--help'):
20 print 'USAGE: python check_success.py -i \"[<input_direcory>,<regular_expression_files>]\" [--remove]\n'
21 sys.exit(0)
22 elif opt in ('-i', '--input'):
23 file_list = arg
24 elif opt in ('-r', '--remove'):
25 remove_option = True
26
27if file_list == "":
28 print 'USAGE: python check_success.py -i \"[<input_direcory>,<regular_expression_files>]\"\n'
29 sys.exit(2)
30
31if file_list.endswith("/"):
32 file_list += "*"
33else:
34 if os.path.isdir(file_list):
35 file_list += "/*"
36#print('file_list = ' + file_list)
37
38is_nfound = False
39file_count = 0
40# cycle to check all files
41for file in glob.glob(file_list):
42 if not os.path.isfile(file): continue
43 #print('Current file: '+ file)
44 file_count += 1
45 delete_flag = False
46 with open(file) as fp:
47 s = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ)
48 if s.find(success_marker) == -1:
49 is_nfound = True
50 print(file + ': marker not found')
51 elif remove_option == True:
52 delete_flag = True
53 if delete_flag == True:
54 os.remove(file)
55
56if file_count == 0:
57 print('There are no files in "'+ file_list + '" or directory does not exist')
58else:
59 if is_nfound == False:
60 print('All files are correct in "'+ file_list)