-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpad_file.py
53 lines (42 loc) · 1.21 KB
/
pad_file.py
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
import os
import getopt
import sys
def GetFileLength(f):
if type(f) == file:
return os.fstat(f.fileno())[6]
if type(f) == str:
return os.stat(f)[6]
def main():
inputFile = ''
outputFile = ''
padSize=1024*128
try:
opts, args = getopt.getopt(sys.argv[1:],"i:o:s:")
if len(opts) <3:
print 'Usage: paf_file -i <input file> -o <output file> -s <size>'
sys.exit(2)
except getopt.GetoptError:
print 'Usage: paf_file -i <input file> -o <output file> -s <size>'
sys.exit(2)
for opt, arg in opts:
if opt == '-i':
inputFile=arg
elif opt == '-o':
outputFile=arg
elif opt == '-s':
padSize=int(arg)
inf = open(inputFile,'rb')
outf = open(outputFile,'wb')
infSize=GetFileLength(inf)
if infSize<=padSize :
data=inf.read() #read_all
outf.write(data)
while(infSize < padSize):
outf.write('\0')
infSize+=1
else:
print "pad size is smaller than input file!!!"
inf.close()
outf.close()
if __name__ == "__main__":
main()