ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/PDFExportToDataLoad/SingleTiffToLFP.py
Revision: 186
Committed: Thu Nov 1 15:07:13 2012 UTC (13 years, 4 months ago) by nino.borges
Content type: text/x-python
Original Path: Python/NinoCode/Active_prgs/Concordance/SingleTiffToLFP.py
File size: 3042 byte(s)
Log Message:
added iproHelpertools to toolbox

File Contents

# User Rev Content
1 ninoborges 8 """
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
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     if __name__ == '__main__':
49     #startDir = r"\\lisdisdss01\dis20\c_d\37771188\20100503"
50 nino.borges 186 startDir = r"N:\04\046\0464660088\20121023\IMAGES"
51     #extension = ".tif"
52     extension = ".jpg"
53 ninoborges 8 lfpFileOBJ = open(startDir + "\\new_load.lfp",'w')
54     datFileOBJ = open(startDir + "\\new_load.dat",'w')
55     dirList = []
56     #prefix = "U0000000"
57 nino.borges 186 prefix = "Blimling00"
58 ninoborges 8 #prefix = "CLARKE-NH-000"
59     #prefix = "PRH-R 0"
60     #prefix = "BAY-TTC_00"
61     #prefix = "MCYQAA000"
62 nino.borges 186 startNumb = 7438
63 ninoborges 8 for file in os.listdir(startDir):
64     if os.path.splitext(file)[1] == extension:
65     dirList.append(file)
66     filesMatrix = CreateDictionary(dirList)
67     curNumb = startNumb
68     fileMatrixList = filesMatrix.keys()
69     fileMatrixList.sort()
70     for k in fileMatrixList:
71     values = filesMatrix[k]
72     datFileOBJ.write(prefix + str(curNumb))
73     #AddToDAT(prefix + str(curNumb),prefix+str(endNumb), datFileOBJ)
74     AddLfpParent(values[0], lfpFileOBJ, prefix, curNumb)
75     curNumb +=1
76     if len(values) > 1:
77     for value in values[1:]:
78     AddLfpChild(value, lfpFileOBJ, prefix, curNumb)
79     curNumb +=1
80     datFileOBJ.write("|" + prefix + str(curNumb-1)+"|"+ time.strftime('%Y%m%d') +"|"+ k +"\n")
81    
82    
83     # AddToFile(startDir, file, outputFile)