#!/usr/bin/env python
#coding: UTF8
Import Os,sys
Import datetime,shutil,subprocess
From Config.config import Slow_config
Class Cut_mysql (object):
Mysql_user,mysql_pass,date_day,slow_log_name,slow_log_path,mysqlsla_log_name,mysqldumpslow_log_name,new_log_ Path,new_log_name,cut_command,mysqlsla_cmd,mysqldumpslow_cmd = Slow_config
def __init__ (self):
Self.mysql_slow ()
def mysql_slow (self):
Os.chdir (Self.slow_log_path)
If Self.new_log_path in Os.listdir (Self.slow_log_path):
Pass
Else
Os.mkdir (Self.slow_log_path+self.new_log_path)
If Self.slow_log_name in Os.listdir (Self.slow_log_path):
Os.rename (Self.slow_log_name,self.new_log_name)
If Self.new_log_name in Os.listdir (Self.slow_log_path+self.new_log_path):
Pass
Else
Shutil.move (Self.new_log_name,self.slow_log_path+self.new_log_path)
Reload_slow=subprocess. Popen (Self.cut_command,shell=true)
Self.mysql_slow_show ()
def mysql_slow_show (self):
Cmd_list=[self.mysqlsla_cmd,self.mysqldumpslow_cmd]
For I in Cmd_list:
Seiri_log=subprocess. Popen (I,shell=true)
This article is from the "Original Python publishing area" blog, so be sure to keep this source http://cuihailong.blog.51cto.com/2923450/1409565