我正在尝试将存储在列表中的文件与位于可能是 W2K3 或 W2K8 的服务器上的同一文件进行比较。我正在尝试对此使用单个函数,但我被困在这个 if 语句中。我试图弄清楚如何将正确的目录路径放入os.walk():
if osVer == 'serverW2k3':
continue
elif osVer == 'serverW2k8':
for folder, subfolders, files in os.walk():
我之前确实有这个工作,但有重复的行,所以我想简化代码。这是完整的课程:
class checkstatus:
def __init__(self):
print 'Checking Status...'
chkbkpstats = csv.reader(file('c://temp//networkerservers.csv'))
srvrs = []
for row in chkbkpstats:
srvrs.append({'Name' : row[0], 'Instance' : row[1]})
for srvr in srvrs:
srvrName = (srvr['Name'])
srvrInst = (srvr['Instance'])
w2k3Chk = r'\\%s\d$\DA$Utils\log\networker' % srvrName
w2k8Chk = r'\\%s\c$\ProgramData\SQL\DA$Utils\log\networker' % srvrName
try:
c = wmi.WMI(srvr['Name'])
except:
print 'Error connecting to %s to check OS version' % srvrName
else:
osVer = c.Win32_OperatingSystem()[0].Caption
if '2003' in osVer:
return 'serverW2k3'
#self.fileCheck(w2k3Chk, w2k8Chk, srvrInst, srvrName)
elif '2008' in osVer:
return 'serverW2k8'
#self.fileCheck(w2k3Chk, w2k8Chk, srvrInst, srvrName)
def fileCheck(self, w2k3Chk, w2k8Chk, srvrInst, srvrName, osVer):
found = False
if osVer == 'serverW2k3':
continue
elif osVer == 'serverW2k8':
for folder, subfolders, files in os.walk():
for sqlFile in files:
if sqlFile == srvrInst + ".log":
found = True
print 'The Backup For %s on %s Still Running' % (srvrInst, srvrName)
elif sqlFile == (srvrInst + ".ok"):
found = True
print 'The Backup For %s on %s Completed Successfully' % (srvrInst, srvrName)
elif sqlFile == (srvrInst + ".err"):
found = True
print 'The Backup For %s on %s Has Failed' % (srvrInst, srvrName)
if not found:
print 'No file for %s found on %s' % (srvrInst, srvrName)