-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_sofia.py
More file actions
executable file
·62 lines (49 loc) · 2.21 KB
/
cmd_sofia.py
File metadata and controls
executable file
·62 lines (49 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Execute command line commands to extract (specified) history files from Sofia
# and perform input string search and output only those history info matching string
import subprocess
import os
import glob
import collections
import itertools
import sys
import re
print('Enter the PAC name EG : RCS_BXSX')
pac_name = input()
print('Enter the FROM PAC version EG : 31.29-0')
from_pac = input()
print('Enter the TO PAC version EG : 30.23-0')
to_pac = input()
print('Enter the search string EG : OSC or SmartBCCH')
search_string = input()
#This command could have multiple commands separated by a new line \n
#strCommandLine = 'slist -hist -from_version 31.29-0 -to_version 30.23-0 RCS_BXSX'
print('Processing....please note the farther the FROM and TO PACs are, the longer the process takes.')
# Need to have PAC number as input as well
string = 'slist -hist -from_version ' + str(from_pac) + ' -to_version ' + str(to_pac) + ' ' + str(pac_name)
strCommandLine = string
file = open(str(pac_name) + '.txt', 'w')
ret = subprocess.call(strCommandLine, stdout=file)
count = 0
addr_pattern = re.compile(
r'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -',
flags=re.IGNORECASE
)
if ret == 0:
path = 'C:\\Python_programs'
for infile in glob.glob( os.path.join(path, 'RCS_BXSX*') ):
with open(infile) as f:
before = collections.deque(maxlen=20)
sys.stdout = open( str(pac_name) + '_extract.txt', 'w')
for line in f:
if search_string in line:
if addr_pattern.search(line):
sys.stdout.writelines(before)
sys.stdout.writelines(before)
sys.stdout.write(line)
sys.stdout.writelines(itertools.islice(f, 15))
count = count + 1
before.append(line)
if count == 0:
print('I am sorry, couldnt find the string you entered in the given PACs. You could try again by changing from and to version of PAC')
else:
print('Failed to download History/Pac files from Sofia. Check if the PAC version is entered correctly or for connectivity issues!')