Der Code ist noch nicht aufgeräumt aber zum schauen richt es wohl, hier habe ich jetzt mal eine Leerzeile gelöscht und unten steht der Traceback!
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: cp1252 -*-
import os, time, re, sys
class pathWalk:
"""
Liest das Dateisystem aus und speichert Verz.-/Datei-Namen
"""
def __init__( self, path, logIndexFile, logFile, compareFile, pathForFiles):
"""
path - Verz. welches inkl. allen Unterverz. ausgelesen werden soll.
indexFile - gibt den Bezeichner der anzulegenden Indexdatei.
saveFiles - legt fest ob Dateien auch ausgelesen werden sollen.
"""
self.path=path
# Allgemeine Log-Datei
self.logFileName=logFile
#self.logFile=logFile
# Indexlog
self.logIndexFileName=logIndexFile
self.logIndexFile=logIndexFile
# Zwischenspeicherindexdatei für Vergleich
self.compareIndexFileName=compareFile
self.compareIndexFile=compareFile
self.pathForFiles=pathForFiles
#self.test=test
def writeLog(self, entry, modus):
if modus==0:
#self.logFileName=str(self.logFileName)+'('+str(sys.platform)+')'
print 'No logfile. Create new one with label : '+str(self.logFileName)
os.chdir(self.pathForFiles)
#self.logFile=file(self.logFileName, 'w') #Dateiobjekt erzeugen und zum schreiben öffnen
logFile=file(self.logFileName, 'w') #Dateiobjekt erzeugen und zum schreiben öffnen
if modus==1:
logFile=file(self.logFileName, 'a')
for element in entry:
logFile.write('\n'+str(element))
logFile.flush()
if modus==2:
logFile=file(self.logFileName, 'a')
logFile.write('\n'+str(entry))
logFile.flush()
if modus==3:
logFile.close()
def courts(self,pathCourtsFile,courtsFileName):
courtPLZList=[]
pathCourtsFile=os.path.join(pathCourtsFile,courtsFileName)
tempFileObject=file(str(pathCourtsFile),'r')
for line in tempFileObject.readlines():
if re.match('RG',line):
courtPLZList.append(line[0:7])
return courtPLZList
def makeLogList(self,log):
logList=[]
tempFileObject=file(str(log),'r')
for line in tempFileObject.readlines():
if re.match('{',line):
logList.append(line)
return logList
# Pruefen, ob Pfad vorhanden (und Zugriff OK -> muss noch geschrieben werden)
def checkIfAccess(self):
pathValue=os.path.exists(self.path)
# Existiert der Pfad?
if pathValue==True:
return 'OK'
else:
return
# Schreibe Log-Datei
# - als String der Eintrag oder Liste , abhängig vom modus
# -> entry Bsp.: 'Erfolg'
# - als normaler Wert (integer)
# -> modus=0 das erste mal schreiben, modus=1 an bestehendes Log eine Liste von
# Einträgen anhängen, modus=2 an bestehendes Log einen Eintrag anhängen.
# Erzeuge den Vergleichsindex der später benötigt wird um festzulegen welche Dateien übertragen werden müssen
def getCompareIndex(self):
self.writeCompareIndex('',0)
entry=[]
entry.append('#############################################################################################')
entry.append('############################ Log für den Vergleichsindex #################################')
entry.append('#############################################################################################\n\n')
self.writeCompareIndex(entry,1)
tempFileObject=file(str(self.logIndexFileName),'r')
for line in tempFileObject.readlines():
if re.match('RG',line):
self.writeCompareIndex(line,2)
self.writeCompareIndex('',3)
# Durchlaufe Pfad und dokumentiere Verzeichnisse und Dateien
def walk(self, courtPLZList):
self.writeIndexLog('',0)
self.writeIndexLog('#############################################################################################',2)
self.writeIndexLog('############################ Log für den kompletten Index ###############################',2)
self.writeIndexLog('#############################################################################################\n\n',2)
self.writeIndexLog("Zu untersuchende Gerichtspostleitzahlen :\n",2)
self.writeIndexLog(courtPLZList,1)
startTime = time.time()
savePath=self.path
dirs_id=0
files_id=0
for court in courtPLZList:
self.path=os.path.join(savePath, court)
for root, dirs, files in os.walk(self.path):
self.writeIndexLog('\n=====================================================',2)
self.writeIndexLog('Searchpath :'+str(root),2)
quantity=0
for element in dirs:
quantity+=1
self.writeIndexLog('Quantity of directories in current searchpath :'+str(quantity),2)
dirs_id=dirs_id+quantity
if quantity!=0:
self.writeIndexLog('Names of directories in current searchpath :\n',2)
self.writeIndexLog(dirs,1)
else:
self.writeIndexLog('No directories in current searchpath!',2)
quantity=0
for element in files:
quantity+=1
self.writeIndexLog('Quantity of files in current searchpath :'+str(quantity),2)
files_id=files_id+quantity
if quantity!=0:
self.writeIndexLog('Names of files in current searchpath :',2)
self.writeIndexLog(files,4)
else:
self.writeIndexLog('No files in current searchpath!',2)
self.writeIndexLog('=====================================================',2)
self.writeIndexLog(str(dirs_id)+' directories searched.',2)
self.writeIndexLog(str(files_id)+' files found in this directories.',2)
endTime = time.time()
print 'Processing duration (only searching): %s' % (endTime - startTime)
self.writeIndexLog('Processing duration (only searching): %s' % (endTime - startTime),2)
self.writeIndexLog('',3)
# Schreibe Vergleichsindex
def writeCompareIndex(self,entry,modus):
if modus==0:
#self.compareIndexFileName=str(self.compareIndexFileName)+'('+str(sys.platform)+')'
print 'No comparefile. Create new one with label : '+str(self.compareIndexFileName)
os.chdir(self.pathForFiles)
self.compareIndexFile=file(self.compareIndexFileName, 'w') #Dateiobjekt erzeugen und zum schreiben öffnen
if modus==1:
self.compareIndexFile=file(self.compareIndexFileName, 'a')
for element in entry:
self.compareIndexFile.write('\n'+str(element))
self.compareIndexFile.flush()
if modus==2:
self.compareIndexFile=file(self.compareIndexFileName, 'a')
self.compareIndexFile.write('\n'+str(entry))
self.compareIndexFile.flush()
if modus==3:
self.compareIndexFile=file(self.compareIndexFileName, 'a')
self.compareIndexFile.close()
if modus==5:
return self.compareIndexFile.closed
# Erzeuge Dateien für Tar-Programm
def tarFiles(self):
counter=0
nameTarObject={}
filesTarObject=[]
dataContainerUnixCompareIndex=[]
dataContainerWindowsCompareIndex=[]
dataContainerForTar=[]
checkIZN=0
checkRUZ=0
# Log-Eintrag, prüfen ob beide Vergleichsindexdateien vorhanden
for element in os.listdir(self.pathForFiles):
#print element
#checkIZN+=1
if re.search('IZN',element) and re.search('unix',element):
checkIZN+=1
compareIndexFileUnix=element
if re.search('RUZ',element) and re.search('win',element):
checkRUZ+=1
compareIndexFileWindows=element
print checkIZN
print 'checkRUZ: '+str(checkRUZ)
if checkRUZ!=0:
print checkIZN+checkRUZ
compareIndexFileUnix=self.pathForFiles+'/'+ compareIndexFileUnix
print 'compareIndexFileUnix : '+str(compareIndexFileUnix)
compareIndexFileWindows=self.pathForFiles+'/'+compareIndexFileWindows
print 'compareIndexFileWindows : '+str(compareIndexFileWindows)
tempFileObjectUnix=file(str(compareIndexFileUnix),'r')
tempFileObjectWindows=file(str(compareIndexFileWindows),'r')
for line in tempFileObjectUnix.readlines():
if line[0]=='R':
dataContainerUnixCompareIndex.append(line)
#print 'dataContainerUnixCompareIndex\n'+str(dataContainerUnixCompareIndex)
for line in tempFileObjectWindows.readlines():
if line[0]=='R':
dataContainerWindowsCompareIndex.append(line)
#print '\ndataContainerWindowsCompareIndex\n'+str(dataContainerWindowsCompareIndex)
else:
entry=[]
entry.append("ERROR : Es muß eine Vergleichsindexdatei vom IZN [...(unix)] und eine vom RUZ [...(win32)] im Verzeichnis '"+str(self.pathForFiles)+"' geben!")
entry.append(" Die Dateien werden automatisch Plattformabhängig mit dem entsprechenden Präfix ergänzt. Also [...(unix)] für IZN und [...(win32)] für das RUZ.")
self.writeLog(entry,1)
def writeIndexLog(self, entry, modus):
if modus==0:
print 'No logindexfile. Create new one with label : '+str(self.logIndexFileName)
os.chdir(self.pathForFiles)
self.logFile=file(self.logIndexFileName, 'w') #Dateiobjekt erzeugen und zum schreiben öffnen
if modus==1:
i=-1
for element in entry:
if i==7:
i=-1
self.logFile.write('\n')
self.logFile.flush()
i+=1
self.logFile.write("|| "+str(element)+" || ")
self.logFile.flush()
if modus==2:
self.logFile.write('\n'+str(entry))
self.logFile.flush()
if modus==3:
self.logFile.close()
if modus==4:
for element in entry:
self.logFile.write('\n'+str(element))
self.logFile.flush()
if modus==5:
return self.logFile.closed
def print_process(self,i, total, begin):
i += 1
tresh = total / 10
#if tresh == 0:
# tresh = 1
if i % tresh == 0:
print "%3.i%% %4.i/%i" % ( round(float(i)/total*100), i, total)
def tarWin( self, pathTarProgram, pathTarArchiv):
startTime = time.time()
pathTarObject=[] #'d:/TiF_Tree/RG08209/V/0039/003900'
nameTarArchiv='' #RG30175V003900.tar'
print 'Create Tar-Archiv ...'
RG_PLZ=''
RG_Art=''
RG_Nr_Mod=''
RG_Nr=''
for line in tempFileObject.readlines():
if line[0]=='R':
tmpPath=''''''
RG_PLZ='/'+str(line[0:7])
RG_Art='/'+str(line[7])
RG_Nr_Mod='/'+str(line[8:12])
RG_Nr='/'+str(line[8:14])
tmpPath=str(RG_PLZ)+str(RG_Art)+str(RG_Nr_Mod)+str(RG_Nr)
pathTarObject.append(tmpPath)
print 'Diese Pfade mit allen Inhalten werden getart: '
print pathTarObject # Pfad ist relativ zu Einstiegspfad
os.chdir(pathTarArchiv)
date=str(time.localtime()[0])+'_'+str(time.localtime()[1])+'_'+str(time.localtime()[2])
command='mkdir '+date
os.system(command)
part=date
pathTarArchiv=pathTarArchiv+'/'+part+'/'
#print pathTarArchiv
os.chdir(pathTarProgram)
#print os.getcwd()
for tarPath in pathTarObject:
RG_PLZ=str(tarPath[1:8])
RG_Art=str(tarPath[9])
RG_Nr=str(tarPath[16:21])
nameTarArchiv=RG_PLZ+RG_Art+RG_Nr+'.tar'
print 'Name: '+str(nameTarArchiv)
command='Tar-nt.exe -cPf '+pathTarArchiv + nameTarArchiv + ' ' + str(self.path)+tarPath
print command
os.system(command)
endTime = time.time()
print 'Processing duration (taring): %s' % (endTime - startTime)
Traceback (most recent call last):
File "D:\ActiveState Komodo 3.1\dbgp\pythonlib\dbgp\client.py", line 1799, in runMain
self.dbg.runfile(debug_args[0], debug_args)
File "D:\ActiveState Komodo 3.1\dbgp\pythonlib\dbgp\client.py", line 1524, in runfile
h_execfile(file, args, module=main, tracer=self)
File "D:\ActiveState Komodo 3.1\dbgp\pythonlib\dbgp\client.py", line 590, in __init__
execfile(file, globals, locals)
File "E:\Skripte\classDefinitionv6.py", line 300
RG_Nr_Mod='/'+str(line[8:12])
RG_Nr='/'+str(line[8:14])
^
SyntaxError: invalid syntax
Wenn ich die Leeerzeile wieder einfüge geht es wieder ????
Danke, für eure Hilfe.