-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnokiaFileCommandLine.py
33 lines (25 loc) · 1.19 KB
/
nokiaFileCommandLine.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
import os
import sys
from optparse import OptionParser
from phosher.nokiaFile import NokiaFile
from phosher.general.util import *
def main():
userOptions = OptionParser()
userOptions.add_option("-i", "--input", dest="inputFile", type="string", help="Input file")
userOptions.add_option("-o", "--output", dest="outputFile", type="string", help="Where to save plain data")
userOptions.add_option("-v", "--verbose", dest="isVerbose", action="store_true", help="Set verbose output on")
userOptions.set_defaults(inputFile=None, outputFile=None, isVerbose=False)
(options, args) = userOptions.parse_args(sys.argv[1:])
inputFile = options.inputFile
outputFile = options.outputFile
isVerbose = options.isVerbose
inputFile = cmdLineInputFile({}, inputFile)
outputFile = cmdLineOutputFile({}, outputFile, inputFile)
data = file(inputFile, 'rb').read()
if len(data) < 0x100:
raise Exception("Input file too short to be a NokiaFile")
nokiaFile = NokiaFile(data, isVerbose=isVerbose)
if None != outputFile:
file(outputFile, 'wb').write(nokiaFile.plain)
if __name__ == "__main__":
main()