本文整理汇总了Python中MyUtil.cur_file_dir方法的典型用法代码示例。如果您正苦于以下问题:Python MyUtil.cur_file_dir方法的具体用法?Python MyUtil.cur_file_dir怎么用?Python MyUtil.cur_file_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyUtil
的用法示例。
在下文中一共展示了MyUtil.cur_file_dir方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cronAdd
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def cronAdd(cmds, cmd):
"""增加守护进程列表的方法
cmd=cronadd,cronadd=*;*;*;*;*;c:\WINDOWS\NOTEPAD.EXE;NOTEPAD.EXE
"""
try:
if not 'cronadd' in cmds.keys():
return "-1", "Lost cronadd.缺少cronadd参数".decode('gbk').encode("utf-8")
cronNew = cmds['cronadd'].upper() + '\n'
if not cronNew.find(';'):
return "-1", "parameter Error.请使用;分号为分隔符".decode('gbk').encode("utf-8")
cronNew = cronNew.replace(';', ',')
if os.path.isfile(MyUtil.cur_file_dir() + '\\crontab.ini'):
f = open(MyUtil.cur_file_dir() + '\\crontab.ini', "r+")
cronMatch = False
for eachLine in f:
if cronNew == eachLine.upper():
cronMatch = True
break
else:
cronMatch = False
str1 = 'Find duplicate cron.'
if not cronMatch:
f.write(cronNew + '\n')
str1 = 'cronadd OK.'
f.close()
return "1", str1
else:
return "-1", 'crontab.ini not found.'
except:
return "-1", "CronAdd.Error"
示例2: SvcDoRun
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def SvcDoRun(self):
try:
global LOG,DBIP,DBPort,_3ds,log,socksize,innerIP,CPUCores
socksize = 64000
_3ds = MyUtil._secret()
cf1 = ConfigParser.ConfigParser()
cf1.read(MyUtil.cur_file_dir() + "\\agent.ini")
agentpath = cf1.get("main", "path").decode('gbk').encode("utf-8")
agentlogfile = cf1.get("main", "agentlogfile").decode('gbk').encode("utf-8")
MyUtil.DBIP = cf1.get("main", "DBIP").decode('gbk').encode("utf-8")
MyUtil.DBPort = cf1.get("main", "DBPort").decode('gbk').encode("utf-8")
LOG = os.path.join(agentpath,agentlogfile)
#创建日志实例
log = MyUtil.CLogInfo(LOG)
cf = ConfigParser.ConfigParser()
cf.read(MyUtil.cur_file_dir()+"\\auto.ini")
#强制读取配置文件中的IP地址设置,当前的问题是第一次必须手工更改配置文件中的IP,否则传出的IP错误
innerIP = cf.get("Configuration", "localip").decode('gbk').encode("utf-8")
try:
CPUCores = cf.get("Configuration","cpucores").decode('gbk').encode("utf-8")
CPUCores = int(CPUCores)
except:
CPUCores = int('1')
rc = runCron()
rc.run()
except:
#print "main Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1])
pass
示例3: setLocalIP
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def setLocalIP():
#强写本地IP地址到配置文件中去
cf1 = ConfigParser.ConfigParser()
cf1.read(MyUtil.cur_file_dir() + "\\auto.ini")
ipMac = ServerInfo.GetinnerIPMac()
innerIP = str(ipMac[0])
cf1.set("Configuration", "localIP", innerIP)
cf1.write(open(MyUtil.cur_file_dir() + "\\auto.ini", "w"))
示例4: writeCfgfile
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def writeCfgfile(setIP,setinnerMAC,setWAIIP,setOS,setCodeSet,setCPUCores,setHostname,setPlatform,setSysDir,setCPUInfo,setPHMEM):
#强写本地IP地址到配置文件中去
cf1 = ConfigParser.ConfigParser()
cf1.read(MyUtil.cur_file_dir()+"/auto.ini")
cf1.set("Configuration", "localIP", setIP)
cf1.set("Configuration","localMACAddress",setinnerMAC)
cf1.set("Configuration","OuterIP",setWAIIP)
cf1.set("Configuration","OS",setOS)
cf1.set("Configuration","CodeSet",setCodeSet)
cf1.set("Configuration","CPUCores",setCPUCores)
cf1.set("Configuration","hostname",setHostname)
cf1.set("Configuration","Platform",setPlatform)
cf1.set("Configuration","CPUInfo",setCPUInfo)
cf1.set("Configuration","SystemDirectory",setSysDir)
cf1.set("Configuration","Physicalmemory",setPHMEM)
cf1.write(open(MyUtil.cur_file_dir()+"/auto.ini", "w"))
示例5: updateselflog
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def updateselflog(data):
"""写日志方法
"""
f = open(MyUtil.cur_file_dir()+"\\updateself.log","w")
f.write(data)
f.close()
示例6: updateselflog
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def updateselflog(data):
"""写日志方法
"""
f = open(MyUtil.cur_file_dir()+"/updateself.log","w")
f.write(data)
f.close()
#if __name__ == '__main__':
# serverIp = "172.18.165.253"
# serverPort = 50000
# aa = updateSelf(1,2)
# print aa[1].decode('utf-8').encode("gbk")
示例7: readCron
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def readCron(self,csvfile):
'''首次读入定时调度配置,确认当前时间,设定离下一分钟的秒数,分析定时调度
*,*,*,*,*,c:\WINDOWS\NOTEPAD.EXE
*,*,*,*,*,e:\1.bat
'''
try:
self.writeLog("readCron:"+str(csvfile))
if os.path.isfile(csvfile):
spamReader = csv.reader(open(csvfile))
#初始化内存中的列表,计数器,注意这样会强制占用列表0单位
global AMinutes,AHours,ADays,AMonths,AWeeks,ACmd,AExe
AMinutes=['AMinutes']
AHours=['AHours']
ADays=['ADays']
AMonths=['AMonths']
AWeeks=['AWeeks']
ACmd=['cmd']
AExe=["exe"]
listcount=1
if os.path.isfile(csvfile):
f = open(csvfile,"r")
for eachline in f:
e = eachline.split(',')
if len(e) == 7:
AMinutes.append(e[0])
AHours.append(e[1])
ADays.append(e[2])
AMonths.append(e[3])
AWeeks.append(e[4])
ACmd.append(e[5])
AExe.append(e[6])
listcount=listcount+1
else:
pass
f.close()
#永久守护CMDServer程序
AMinutes.append('*')
AHours.append('*')
ADays.append('*')
AMonths.append('*')
AWeeks.append('*')
ACmd.append(MyUtil.cur_file_dir()+'/CMDServer4Linux')
AExe.append('CMDServer4Linux')
listcount = listcount+1
return listcount
else:
pass
self.writeLog("readCron else:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
except:
self.writeLog("readCron Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
示例8: cronRemove
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def cronRemove(cmds, cmd):
"""删除已有守护进程列表的方法
cmd=cronremove,cronremove=*;*;*;*;*;c:\windows\notepad.exe
"""
try:
if not 'cronremove' in cmds.keys():
return "-1", "Lost cronremove.缺少cronremove参数".decode('gbk').encode("utf-8")
cronNew = cmds['cronremove'].upper() + '\n'
if not cronNew.find(';'):
return "-1", "parameter Error.请使用;分号为分隔符".decode('gbk').encode("utf-8")
cronNew = cronNew.replace(';', ',')
crons = ''
if os.path.isfile(MyUtil.cur_file_dir() + '\\crontab.ini'):
f = open(MyUtil.cur_file_dir() + '\\crontab.ini', "r+")
cronMatch = False
for eachLine in f:
if cronNew == eachLine.upper():
cronMatch = True
break
else:
crons += eachLine
cronMatch = False
f.close()
print crons
if cronMatch:
f = open(MyUtil.cur_file_dir() + '\\crontab.ini', "w")
f.write(crons + '\n')
str1 = 'cronRemove OK.'
f.close()
else:
str1 = cmds['cronremove'] + ' Cron not found.'
return "1", str1
else:
return "-1", 'crontab.ini not found.'
except:
return "-1", "CronRemove.Error"
示例9: run
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def run(self):
'''首次读入定时调度配置,确认当前时间,设定离下一分钟的秒数,分析定时调度'''
self.writeLog('Agent4Linux start.')
while True:
try:
nowTime=string.split(time.strftime('%w,%m,%d,%H,%M,%S',time.localtime(time.time())), sep=',')
timesWait=60-int(nowTime[5])
#读入定时作业用的配置文件
listcount=self.readCron(MyUtil.cur_file_dir()+'/crontab.ini')
cf = ConfigParser.ConfigParser()
cf.read(MyUtil.cur_file_dir()+"/agent.ini")
MonitorProcess = cf.get("main", "MonitorProcess").encode("utf-8").split(',')
allProcess = []
_allPro = []
_allProcess = []
_allProcess = ServerInfo.getAllProcessNameId()
for ProcessList in _allProcess:
allProcess.append(ProcessList[0])
_allPro = ServerInfo.getAllProcessInfo()
insertTime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
#循环需要定时守护的进程数
for i in range(1,int(listcount)):
#如果当前进程中不存在守护的进程,调用定时守护启动程序,并发送重启信息给DB
if not str(AExe[i]).upper() in allProcess:
self.Cronjob(i,nowTime)
send = MyUtil.SendMsgToDB()
send.send(_3ds.Encrypt('processRestart;'+str(innerIP)+";"+str(AExe[i])+";"+str(ACmd[i])+";"+str(insertTime)))
send.sock.recv(socksize)
send.send(_3ds.Encrypt('end'))
send.closeSock()
else:
pass
#如果当前进程中存在要监控的进程,循环找出该进程的相关信息发送至DB服务器
for MProcess in MonitorProcess:
ProcessStatus = 'NOTRUN'
for MPro in _allPro:
#如果进程在所有进程中找到一个相同的就发进程状态消息
if str(MProcess).upper() == str(MPro[0]).upper():
send = MyUtil.SendMsgToDB()
#发现psutil取出的进程CPU使用率,需要除CPU个数,否则不准
send.send(_3ds.Encrypt('insertProLog;'+innerIP+";"+str(MPro[0])+";"+str(MPro[1])+";"+str(MPro[2])+";"+str(MPro[3])+";"+str(int(MPro[4])/CPUCores)+";"+str(insertTime)))
send.sock.recv(socksize)
send.send(_3ds.Encrypt('end'))
send.closeSock()
ProcessStatus = 'running'
break
else:
ProcessStatus = 'NOTRUN'
#如果全部检查后进程状态为未运行,发送进程未启动信息
if ProcessStatus == 'NOTRUN':
try:
send = MyUtil.SendMsgToDB()
send.send(_3ds.Encrypt('NotRUNProess;'+innerIP+";"+str(MProcess).upper()+";"+str(insertTime)))
send.sock.recv(socksize)
send.send(_3ds.Encrypt('end'))
except:
self.writeLog("runCron.send.Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
finally:
send.closeSock()
time.sleep(timesWait)
except:
self.writeLog("runCron Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
time.sleep(timesWait)
示例10: writeLog
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
self.writeLog("process: "+ACmd[i]+" not found, restart.")
return
except Exception, e:
self.writeLog("Cronjob Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
def writeLog(self,info):
log.output(info)
if __name__ == '__main__':
global LOG,DBIP,DBPort,_3ds,log,socksize,innerIP,CPUCores
socksize = 64000
_3ds = MyUtil._secret()
cf1 = ConfigParser.ConfigParser()
cf1.read(MyUtil.cur_file_dir() + "/agent.ini")
agentpath = cf1.get("main", "path").encode("utf-8")
agentlogfile = cf1.get("main", "agentlogfile").encode("utf-8")
MyUtil.DBIP = cf1.get("main", "DBIP").encode("utf-8")
MyUtil.DBPort = cf1.get("main", "DBPort").encode("utf-8")
LOG = os.path.join(agentpath,agentlogfile)
#创建日志实例
log = MyUtil.CLogInfo(LOG)
#Hostname = ServerInfo.hostname()
cf = ConfigParser.ConfigParser()
cf.read(MyUtil.cur_file_dir()+"/auto.ini")
#强制读取配置文件中的IP地址设置,当前的问题是第一次必须手工更改配置文件中的IP,否则传出的IP错误
innerIP = cf.get("Configuration", "localip").encode("utf-8")
try:
CPUCores = cf.get("Configuration","CPUCores").encode("utf-8")
示例11: initServerMap
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
# CMDServer支持的命令列表
agentCmds = [
"downloads",
"cronlist",
"cronadd",
"cronremove",
"agentlist",
"command",
"updateself",
"version",
"password",
"unzip",
]
cf = ConfigParser.ConfigParser()
cf.read(MyUtil.cur_file_dir() + "\\IOMServer.ini")
path = MyUtil.cur_file_dir()
# path = cf.get("main", "path")
logfile = cf.get("main", "logfile")
serverIP = cf.get("main", "IP")
port = cf.getint("main", "port")
DBUtil.DBHost = cf.get("main", "DBHost")
DBUtil.DBPort = cf.get("main", "DBPort")
DBUtil.DBUser = cf.get("main", "DBUser")
DBUtil.DBPwd = cf.get("main", "DBPwd")
try:
# 从数据库中取出agent服务器列表
initServerMap()
except:
print u"initServerMap Error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1])
示例12: updateSelf
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def updateSelf(cmd,cmdStr):
"""2011-01-13 update self
"""
try:
print "updateself step 1"
path = MyUtil.cur_file_dir()
cmdStr = "cmd=downloads,file=update4Linux.zip,updateself=updateself,path="+path
cmd = MyUtil.splitCmd(cmdStr)
reStr = downloads(cmd, cmdStr)
if reStr[0] == int('-1'):
return reStr[1]
rs =""
print "updateself step 2 ", reStr
if reStr[0] == int('2'):
"""解压update.zip至当前目录下的update.tmp中"""
zipout = MyUtil.UnZIP("update4Linux.zip", "update.tmp")
print "updateself step 3 unzip. zipout = ",zipout[0]
if zipout[0] == '1':
rs += zipout[1]
'''检验update.tmp/config.ini是否存在'''
if os.path.isfile("update.tmp/config.ini"):
print "updateself step 4 check config.ini"
'''读取config.ini的配置'''
cf = ConfigParser.ConfigParser()
cf.read("update.tmp/config.ini")
md5Files = cf.get("filemd5","md5Files")
uAgent = cf.get("main", "updateAgentService")
uCMDServer = cf.get("main", "updateCMDServer")
uRunPro = cf.get("main", "RunPrograms")
uremove = cf.get("main", "removeFiles")
'''对需要的文件做MD5验证,通过则下一步'''
md5FilePath = (MyUtil.cur_file_dir()+"/update.tmp/")
_md5Files = md5Files.split(',')
MD5Flag = False
if _md5Files != None and md5FilePath != None and _md5Files != '' and md5FilePath != '':
for filemd5 in _md5Files:
'''循环比对指定文件的MD5码值'''
fileName,rightMD5 = filemd5.split(":")
filePath = md5FilePath + fileName
ret = string.split(md5sum(filePath))
if ret[0] == "-1" or ret[0] == "-2":
MD5Flag = False
elif ret[1] == rightMD5:
MD5Flag = True
print "updateself step 5 check MD5, MD5Flag =",MD5Flag
if MD5Flag:
'''根据配置运行'''
print "updateself step 6 update Agent4Linux =",uAgent.upper()
if uAgent.upper() == "YES":
'''如果要更新Agent,则先杀掉进程,调用自更新脚本复制文件和启动服务'''
_allpronameid = ServerInfo.getAllProcessNameId()
for _name,_id in _allpronameid:
if _name.upper() == "Agent4Linux".upper():
p = ServerInfo.Kill_Process_pid(_id)
str1 = "find process "+str(_name)+", pid = "+str(_id)+", kill it!\n"
rs += str1
try:
os.chmod(MyUtil.cur_file_dir()+"/updateself.sh",0755)
p = os.popen(MyUtil.cur_file_dir()+"/updateself.sh")
str1 = p.readlines()
for s in str1:
rs += s
p.close()
except:
print "updateAgent4LinuxError:"+str(sys.exc_info()[0]) + str(sys.exc_info()[1])
pass
print "updateself step 7, RunProcess= ",uRunPro.upper()
if uRunPro.upper() <> "NO" :
"""如果不是NO,则把要运行的程序绝对路径和执行名放在参数中,以逗号隔开
"""
try:
Pros = uRunPro.split(",")
for Pro in Pros:
p = os.popen(Pro)
str1 = p.readlines()
for s in str1:
rs += s
p.close()
except:
pass
print "updateself step 8, RemoveFile= ",uremove.upper()
"""如果不是NO,则把要删除的文件绝对路径放在参数中,以逗号隔开
"""
if uremove.upper() <> "NO":
try:
removefiles = uremove.split(",")
for rfile in removefiles:
shutil.rmtree(rfile)
except:
pass
print "updateself step 9, Update CMDServer4Linux = ",uCMDServer.upper()
if uCMDServer.upper() == "YES":
'''如果需要更新CMDServer4Linux,调用updateCMDServer.sh完成更新'''
# _allpronameid = getAllProcessNameId()
# for _name,_id in _allpronameid:
# if _name.upper() == "CMDServer4Linux".upper():
# p = Kill_Process_pid(_id)
#.........这里部分代码省略.........
示例13: updateSelf
# 需要导入模块: import MyUtil [as 别名]
# 或者: from MyUtil import cur_file_dir [as 别名]
def updateSelf(cmd,cmdStr):
"""2011-01-13 update self
"""
try:
#print "updateself step 1"
path = MyUtil.cur_file_dir()
cmdStr = "cmd=downloads,file=update.zip,updateself=updateself,path="+path
cmd = MyUtil.splitCmd(cmdStr)
reStr = downloads(cmd, cmdStr)
if reStr[0] == int('-1'):
return reStr[1]
rs =""
#print "updateself step 2 ", reStr
if reStr[0] == int('2'):
"""解压update.zip至当前目录下的update.tmp中"""
zipout = MyUtil.UnZIP("update.zip", "update.tmp")
#print "updateself step 3 unzip. zipout = ",zipout[0]
if zipout[0] == '1':
rs += zipout[1]
'''检验update.tmp/config.ini是否存在'''
if os.path.isfile("update.tmp/config.ini"):
#print "updateself step 4 check config.ini"
'''读取config.ini的配置'''
cf = ConfigParser.ConfigParser()
cf.read("update.tmp\\config.ini")
md5Files = cf.get("filemd5","md5Files")
uAgent = cf.get("main", "updateAgentService")
uCMDServer = cf.get("main", "updateCMDServer")
uRunPro = cf.get("main", "RunPrograms")
uremove = cf.get("main", "removeFiles")
'''对需要的文件做MD5验证,通过则下一步'''
md5FilePath = (MyUtil.cur_file_dir()+"\\update.tmp\\")
_md5Files = md5Files.split(',')
MD5Flag = False
if _md5Files != None and md5FilePath != None and _md5Files != '' and md5FilePath != '':
for filemd5 in _md5Files:
'''循环比对指定文件的MD5码值'''
fileName,rightMD5 = filemd5.split(":")
filePath = md5FilePath + fileName
ret = string.split(md5sum(filePath))
if ret[0] == "-1" or ret[0] == "-2":
MD5Flag = False
elif ret[1] == rightMD5:
MD5Flag = True
#print "updateself step 5 check MD5, MD5Flag =",MD5Flag
if MD5Flag:
'''根据配置运行'''
#print "updateself step 6 update AgentService =",uAgent.upper()
if uAgent.upper() == "YES":
'''如果要更新Agentservices,则先杀掉进程,卸载服务,然后复制文件'''
'''再安装服务,运行服务。'''
p = os.popen(ServerInfo.sysDir()+'\\taskkill /IM AgentService.exe /F')
str1 = p.readlines()
for s in str1:
rs += s.decode('gbk').encode("utf-8")
p.close()
p = os.popen(ServerInfo.sysDir()+'\\sc delete AgentService 2>&1')
str1 = p.readlines()
for s in str1:
rs += s.decode('gbk').encode("utf-8")
p.close()
try:
shutil.copy2(md5FilePath+"AgentService.exe", os.path.join(MyUtil.cur_file_dir()+"\\AgentService.exe"))
except:
#print "AgentService copy Error.",sys.exc_info()[0],sys.exc_info()[1]
pass
try:
shutil.copy2(md5FilePath+"w9xpopen.exe", os.path.join(MyUtil.cur_file_dir()+"\\w9xpopen.exe"))
except:
pass
try:
shutil.copy2(md5FilePath+"MSVCR71.dll", os.path.join(MyUtil.cur_file_dir()+"\\MSVCR71.dll"))
except:
pass
try:
shutil.copy2(md5FilePath+"setCfg.exe", os.path.join(MyUtil.cur_file_dir()+"\\setCfg.exe"))
except:
pass
p = os.popen("setCfg.exe 2>&1")
str1 = p.readlines()
for s in str1:
rs += s.decode('gbk').encode("utf-8")
p.close()
p = os.popen(MyUtil.cur_file_dir()+"\\AgentService.exe -install 2>&1")
str1 = p.readlines()
for s in str1:
rs += s.decode('gbk').encode("utf-8")
p.close()
p = os.popen(ServerInfo.sysDir()+"\\sc config AgentService start= auto")
str1 = p.readlines()
for s in str1:
rs += s.decode('gbk').encode("utf-8")
p.close()
p = os.popen(ServerInfo.sysDir()+"\\sc start AgentService")
str1 = p.readlines()
for s in str1:
rs += s.decode('gbk').encode("utf-8")
p.close()
#.........这里部分代码省略.........