Specifications

69
print '(using setting: append to IMEI#.txt)'
print """ Messages shorter than expected have missing values replaced with ?
* Any massage longer than expected is decoded up to the expected length
* All original files can be found in the subfolder of the relevant IMEI
* Set bool FilterMalformed to control where these data get appended"""
DoSort = ''
#print '\n'
while ModifiedFiles:#so that it only asks if any file has actually been modified
DoSort = raw_input('New lines were appended. Time-sort the %i relevant .txt files?
[Y/N]'%len(ModifiedFiles))
if DoSort.upper() in ('Y', 'N'): break
if DoSort.upper() == 'Y':#however the -X.txt garbage files are never sorted since we don't
know what is in them
for FileName in ModifiedFiles:
print '%s - reading' %FileName,
while True:
try:
with open(FileName, 'r') as InFile:
FileContent = InFile.readlines()
break
except IOError:
while True:
AbortOrRetry = raw_input('ERROR while opening %s: Abort or Retry?
[A/R]' %FileName)
if AbortOrRetry.upper() in ('A', 'R'): break
if AbortOrRetry.upper() == 'A': break
print 'ok, sorting' ,
try:
FileContent.sort()
except NameError:
continue
#os.rename(FileName, FileName + '.old')#TODO: for debug only
print 'ok, writing...' ,
while True:
try:
with open(FileName, 'w') as OutFile:
OutFile.writelines(FileContent)
break
except IOError:
while True:
AbortOrRetry = raw_input('ERROR while opening %s: Abort or Retry?
[A/R]' %FileName)
if AbortOrRetry.upper() in ('A', 'R'): break
if AbortOrRetry.upper() == 'A': break
print 'done!'