Repository navigation
Expand file tree
/
Copy pathchangeUDP.py
More file actions
executable file
·127 lines (101 loc) · 3.59 KB
/
Copy pathchangeUDP.py
File metadata and controls
executable file
·127 lines (101 loc) · 3.59 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/python
from argparse import ArgumentParser
import os
parser = ArgumentParser(description="Script to generate an OSSI file for mass"
" Uniform Dialing Plan (UDP) changes")
parser.add_argument('-i', '--infile', dest='extfile',
help="specify input file. Default is extfile",
default='extensions')
parser.add_argument('-o', '--outfile', dest='outfile',
help="specify output file. Default is extfile.OSSI",
default='extfile.OSSI')
parser.add_argument('-c', '--checktype', dest='checktype',
help='Sanity checking type. Default is strict (die if file is not clean)',
default='strict')
parser.add_argument('-d', '--code', dest='acmint', help="digits to insert")
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help="verbosity of checking. Default is True',",
default=False)
args = parser.parse_args()
extensions = open(args.extfile, 'r')
outfile = open(args.outfile, 'w')
sanity = args.checktype
failcount = 0
successcount = 0
# declare field addresses
# these are the CM database addresses used to identify
# different fields within CM forms
matchingpattern = "f6c01ff01"
length = "fec36ff01"
delete = "fec37ff01"
insert = "f6c02ff01"
net = "f6c03ff01"
# declare UDP parameters
# this should eventually be moved to command line arguments
acmlen = 5
acmdel = 1
# acmint = 142
acmnet = 'aar'
def extsanitycheck():
global failcount
counter = 1
for line in extensions:
try:
int(line)
except ValueError:
failcount += 1
if args.verbose:
print "Error on line ", counter
counter += 1
return failcount
# reading extensions from the file:
# splitlines was used rather than 'for each line in' because
# that format included the newline character, which was
# printed in the output file, resulting in an uneeded blank line
# when reading with split lists, a list was created, and [0] retrieves
# the first value
def createOSSI():
extensions.seek(0)
currentline = 0
global successcount
global failcount
failcount = 0
for line in extensions:
currentline += 1
currext = line.splitlines()[0]
try:
int(currext)
print >> outfile, 'cchange uniform-dialplan 99999'
print >> outfile, matchingpattern
print >> outfile, '%s%s' % ('d', currext)
print >> outfile, length
print >> outfile, "%s%s" % ('d', acmlen)
print >> outfile, delete
print >> outfile, "%s%s" % ('d', acmdel)
print >> outfile, insert
print >> outfile, "%s%s" % ('d', args.acmint)
print >> outfile, net
print >> outfile, "%s%s" % ('d', acmnet)
print >> outfile, 't'
print >> outfile
successcount += 1
except:
failcount += 1
return successcount, failcount
def main():
extsanitycheck()
if failcount > 0 and sanity == 'strict':
print
print '****not creating OSSI file because it isn\'t clean.'
print 'There are ', failcount, 'errors in the file.\nPlease correct them.'
outfile.close()
os.remove(args.outfile)
else:
createOSSI()
print "Processed ", successcount, ' extensions.'
if failcount > 0:
print failcount, "lines were skipped because of errors on the line."
print "OSSI file is ", args.outfile
main()
extensions.close()
outfile.close()