''' Description: <独步天下> 生成装服配置文件,CRT文件并上传到SVN 脚本 Create Date: 2013-07-25 ''' import os import shutil import sys import saveLog from autoUtil import isIP, runCmd, wToCfg from dbtx.Merge.etc import DIRs, dbHost, dbPort, dbUser, dbPass, dbName, cfgDemo from dbtxMySQL import ClassDb saveLog.set_logger(filename="%sdbtx_AutomaticInstall.log" % DIRs['LOG_DIR']) ## 定义日志文件 class AutoGen(): def __init__(self, *kwargs): self.kwargs = kwargs def ctCrt(self): ''' 创建CRT文件,并上传到SVN ''' sAgent, sID, sIP = self.kwargs[1], self.kwargs[2], self.kwargs[0] if isIP(sIP): upCmd = "bash %s %s %s %s" % (DIRs['GEN_CRT_SCPT'], sAgent, sID, sIP) if runCmd(upCmd) != 0: ## 如果命令返回值不为0,表示更新SVN失败 saveLog.error("%s %s %s, Gen CRT file and SVN up error." % (sAgent, sID, sIP)) return
# -*- coding: utf-8 -*- import saveLog import os saveLog.set_logger(filename=u"D:\\GitHub\\giter\\python\\Update\\dbtx_Update.log" ) ## 定义日志文件 saveLog.info("init maintain....") class MaintainInit: def __init__(self,date,dbo,iLanguages,andsql,steps): self.date = date # 日期 self.dbo = dbo # 数据库连接类 self.iLanguage_locked = 1 self.iLanguages = iLanguages self.andSql = andsql self.steps = steps # 从dbtx_maintain_plan表获取今天维护计划 def __TodayMaintainPlans(self): sql = 'SELECT iId,iLanguage,sVersion,sTargetVersion,DATE(dCreateTime) AS iDate,TIME(dCreateTime) AS iTime,sContents,sDesc FROM dbtx_maintain_plan WHERE iStatus = 1 AND iLanguage = %d AND DATE(dCreateTime) = "%s";' % (int(self.iLanguage_locked),self.date) maintain_plan = self.dbo.fetchone() if self.dbo.query(sql) else () if maintain_plan: self.maintain_plan = maintain_plan return True else: self.__exit('没有维护计划',2) return False
#!/usr/bin/env python ## -*- coding:utf-8 -*- ## Author: HongJun ''' Description: 安全删除目录/文件,避免误删 Create Date: 2013-04-18 ''' import os, sys, shutil, time, datetime import saveLog saveLog.set_logger(filename="/var/log/delete/deleteRecords.log") ## 定义日志文件 ## 获取当天时间 def getToday(timeFormat="%Y-%m-%d"): return time.strftime(timeFormat,time.localtime()) class HumanRmCmd(): ''' 安全删除目录/文件,避免误删 ''' def __init__(self, *kargs): self.args = kargs self.riskDirList = ['usr','proc','opt','src','var','data','tmp'] self.sysDirList = ['bin','sbin','lib','etc','sys','dev'] self.riskFileList = ['mysql1.sock','mysql2.sock','passwd','shadow','grub.conf','rc.local','authorized_keys','sshd_config'] self.tmpDir = "/backup/delete/%s/" % getToday() if not os.path.exists(self.tmpDir): os.makedirs(self.tmpDir)
## Author: HongJun ''' Description: 独步天下 ----快速合服 生成合服配置文件 类 Create Date: 2014-09-13 ''' import os import shutil import time import saveLog from dbtxMySQL import ClassDb from etc.config import DIRs, dbHost, dbPort, dbUser, dbPass, dbName, cfgDemo saveLog.set_logger(filename="%sdbtx_Merge.log" % DIRs['LOG_DIR']) ## 定义日志文件 def wToCfg(cfgFile, content): ''' 定义写入配置文件的函数,传入两个参数: 1: 配置文件的文件名; 2: 配置文件内容 ''' CfgObj = open(cfgFile, 'w') CfgObj.write(content) CfgObj.close() ## 获取当前时间 def getTimeNow(timeFormat="%Y-%m-%d %X"): return time.strftime(timeFormat,time.localtime())