Форум сайта python.su
Добрый день панове.
import os, sys,shutil,re,time
def fmove(p1,p2):
if not os.path.exists(p1):return p1+' does not exists '
if not os.path.exists(p2):return p2+' does not exists '
shutil.move(p1,p2)
return False
class logscan:
def __init__(self):
self.inname='./in/'
self.tmpname='./in/temp/'
self.badname='./in/temp/bad/'
self.okayinname='./in/temp/okayin/'
self.sleeptime=5
def scaner(self):
# if tmp : print tmp
tmp=os.listdir(self.inname)
# print tmp
for f in tmp:
pathname = os.path.normpath(os.path.join(self.inname, f))
if os.path.isfile(pathname) and not os.path.islink(pathname):
self.logistic(pathname)
break
def logistic(self,pathname):
(dirname,filename)=os.path.split(pathname)
print 'found = ' ,filename,
m = fmove(pathname,self.tmpname)
if m :
print m
return
else:
print ', moved',
self.tester(filename)
def tester(self,filename):
print ', tst:',
os.chdir(self.tmpname)
res = os.popen3('7z t '+filename+ ' ', 't')[1].read()
res2=re.search('(Everything is Ok)',res)
if res2:
print res2.group(),
else:
res2=re.search('(Error:)(.*)\n',res)
if res2:print res2.group(),
#print res2
print ', ',
def run(self):
while True:
fff=self.scaner()
if fff : self.logistic(fff)
time.sleep(self.sleeptime)
###############################################################################
print '<<<start>>>'
l=logscan()
l.run()
<<<start>>>тоесть при втором вызове os.listdir(self.inname) выпадает ошибка.
found = 111114.008 , moved , tst: Everything is Ok ,
Traceback (most recent call last):
File “<string>”, line 74, in run_nodebug
File “D:\_code\h_logscan\LogScan.py”, line 71, in <module>
l.run()
File “D:\_code\h_logscan\LogScan.py”, line 61, in run
fff=self.scaner()
File “D:\_code\h_logscan\LogScan.py”, line 26, in scaner
tmp=os.listdir(self.inname)
WindowsError: : ‘./in/*.*’
Отредактировано (Янв. 27, 2009 12:58:58)
Офлайн
хм.
расскажи другому - сам поймешь.
я менял активную директорию,
os.chdir(self.tmpname)
Офлайн