I am trying to compare a file stored in a list to the same file located on a server that may be W2K3 or W2K8. I am trying to use a single function to this but am stuck at this if statement. I am trying to figure out how to get the proper directory path into os.walk():
if osVer == 'serverW2k3':
continue
elif osVer == 'serverW2k8':
for folder, subfolders, files in os.walk():
I did have this working before but had repeating lines so I wanted to simplify the code.
Here is the full class:
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)
Your question is a bit unclear, and your sample code obviously isn’t your real code (you can’t call os.walk with no params), but I think I can guess what you’re after.
First, change
fileChecklike this:Now, in
__init__, do the last part like this: