This is a small program that I have written before to clean up the backup file, and I wanted to do it in batches, but the syntax of the batch was complicated and bizarre, and finally I wrote a python Because our game automatically generates a backup every hour, the function of this program is to skip the latest 7*24 backup and delete the other time longer. #表示注释
#-*-coding:cp936-*-
Import OS #os是python自带的一个扩展库 for system-related operations
Skipnum = 7 #保留文件夹的数目 (hours * days)
print ' \n************* erase time over ' + str (SKIPNUM/24) + ' days ' automatic backup file **************\n\n '
Backupdir = Os.path.abspath (__file__) + ' \ ... \.. ' + ' \\servedatabase_autobackup ' For dir in Os.listdir (backupdir): #os. Listdir (XXX) function returns a list of files If dir[-4:] = = '. Map ': Mapdir = backupdir + ' \ \ ' + dir print ' Purging backup directory: ' + os.path.abspath (mapdir) Subdirs = Os.listdir (mapdir) #获取文件列表 Subdirs.reverse () #逆序 i = 0 For SubDir in Subdirs: I+=1 If i > Skipnum: print ' Purging Backup: ' + subdir Os.system (' rmdir ' + mapdir + ' \ ' + subdir + '/s/q ') #相当于执行控制台命令 |
Because no one in the server program is in charge during the holidays, our server program incorrectly generates the Error Reporting dialog box, which is the role of the python to periodically look for the error dialog box and turn it off, and then restart the service side.
#-*-coding:cp936-*-
Import Win32API
Import Win32gui
Import time
Import OS
Print "Monitor process running ..."
#工作路径
Workdir = "d:/work/xxxxxxxxx/"
#要进行监控的程序
Winlist = []
Winlist.append (["Xxx-xxxx Server", "Xxx_r.bat"])
Winlist.append (["Yyy-yyyy Server", "Yyy_r.bat"])
Winlist.append (["Zzz-zzzz Server", "Zzz_r.bat"])
while (1):
#寻找 the Error Reporting window and turn off
W = Win32gui. FindWindow (0, "Error Reporting")
while (w!= 0):
Win32API. SendMessage (w,16)
W = Win32gui. FindWindow (0, "Error Reporting")
Time.sleep (2)
#寻找 the "Python Error" window and turn off
W = Win32gui. FindWindow (0, "Python.exe")
while (w!= 0):
Win32API. SendMessage (w,16)
W = Win32gui. FindWindow (0, "Python.exe")
Time.sleep (2)
#检查进程是否存在, start the process if it does not exist
For WL in Winlist:
s = Win32gui. FindWindow (0,wl[0])
If s = 0:
Print str (time.localtime ()) + "start" + wl[1]
#写日志
File_object = open (Workdir + ' runLog.txt ', ' w+ ')
File_object.write (str (time.localtime ()) + "start" + wl[1])
File_object.close ()
#启动
Win32API. ShellExecute (0, "", Workdir + wl[1], "", Workdir, True)
Time.sleep (5) #每启动一个后的等待时间
Time.sleep (#每一轮循环等待时间)
This is an extension library for writing simple 2d games http://www.pygame.org/news.html
Just looked at a few days ago, there are many small examples to see