ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/PDFExportToDataLoad/Trunk/SingleTiffToLFP.py
Revision: 447
Committed: Sat Sep 7 23:22:19 2013 UTC (12 years, 6 months ago) by nino.borges
Content type: text/x-python
File size: 3230 byte(s)
Log Message:
Updated the main method because it was missing extensions where there was mixed case and extra f in tiff.

File Contents

# Content
1 """
2 SingleTiffToLFP
3 Created by Emanuel Borges
4 3.22.07
5
6 This program will take a dir of single page tiffs and create an LPF from the tiffs
7 found there. It will know the doc boundaries because the tiffs are <foo>_<pageno>.tif
8 The program will also create a .dat file from the boundaries too.
9
10 First it packs it into a sortable hash with a sortable list as it's value, then unpacks
11 this list into the two files.
12
13 <FileNameSansExt:[File1,File2,File3]
14
15 Currently it only does one dir, since the dict would get Garbage collected but the
16 dict function could be turned into a class.
17 """
18
19 import os, time, NinoGenTools
20
21 def CreateDictionary(contentsOfDir):
22 mainDict = {}
23 for file in contentsOfDir:
24 name = os.path.splitext(file)[0]
25 name = name.split("_Page_")[0]
26 if name in mainDict.keys():
27 filesList = mainDict.get(name)
28 filesList.append(file)
29 mainDict[name] = filesList
30 else:
31 mainDict[name]=[file]
32 return mainDict
33
34 def AddLfpParent(file, outputOBJ,prefix, curNumb):
35 outputOBJ.write("IM,%s,D,0,@%s;;%s;2\n"% (prefix+str(curNumb),time.strftime('%Y%m%d'),file))
36
37 def AddLfpChild(file, outputOBJ,prefix, curNumb):
38 outputOBJ.write("IM,%s,,0,@%s;;%s;2\n"% (prefix+str(curNumb),time.strftime('%Y%m%d'),file))
39
40 def AddToDAT(beg,end, outputOBJ):
41 """This only works if the file is named the bates..."""
42 outputOBJ.write(beg + "," + end + ","+(time.strftime('%Y%m%d')+"\n"))
43
44 def AddToFile(startDir, file, outputFile):
45 output = open(outputFile, "a")
46 output.write("IM,PP002561,D,1,@%s;;%s;2\n"% (time.strftime('%Y%m%d'),file))
47
48 def Process(startDir,prefix,startNumb,counterBase,extension =".tif"):
49 lfpFileOBJ = open(startDir + "\\new_load.lfp",'w')
50 datFileOBJ = open(startDir + "\\new_load.dat",'w')
51 dirList = []
52 counterObject = NinoGenTools.Counter()
53
54 for file in os.listdir(startDir):
55 if os.path.splitext(file)[1].upper() == extension.upper():
56 dirList.append(file)
57 elif os.path.splitext(file)[1].upper() == extension.upper()+"F":
58 dirList.append(file)
59 filesMatrix = CreateDictionary(dirList)
60 counterObject.inc(startNumb)
61 fileMatrixList = filesMatrix.keys()
62 fileMatrixList.sort()
63 for k in fileMatrixList:
64 values = filesMatrix[k]
65 datFileOBJ.write(prefix + "%0*d"% (counterBase,counterObject.count))
66 AddLfpParent(values[0], lfpFileOBJ, prefix, "%0*d"% (counterBase,counterObject.count))
67 counterObject.inc(1)
68 if len(values) > 1:
69 for value in values[1:]:
70 AddLfpChild(value, lfpFileOBJ, prefix, "%0*d"% (counterBase,counterObject.count))
71 counterObject.inc(1)
72
73 datFileOBJ.write("|" + prefix + "%0*d"% (counterBase,counterObject.count - 1)+"|"+ time.strftime('%Y%m%d') +"|"+ k +"\n")
74
75
76 if __name__ == '__main__':
77 #startDir = r"\\lisdisdss01\dis20\c_d\37771188\20100503"
78 startDir = r"C:\Test_dir"
79 extension = ".tif"
80 #extension = ".jpg"
81 prefix = 'tst-'
82 startNumb = 7438
83 counterBase = 8
84 Process(startDir,prefix,startNumb,counterBase,extension)