svn hostcopy 并自动删除超过七天的归档,svnhostcopy,#!/usr/bin/p


#!/usr/bin/pythonimport os, sys,datetime,time                                                                                                          from stat  import *  import shutil                                                                                                                                                                                                                                                    path='E:\\svnbak\\'                                                                                                                                                                                                                                  filelist=[]                                                                                                                            filelist=os.listdir(path)def delete_file_folder(src):    '''delete files and folders'''    if os.path.isfile(src):        try:            os.remove(src)        except:            pass    elif os.path.isdir(src):        for item in os.listdir(src):            itemsrc=os.path.join(src,item)            delete_file_folder(itemsrc)         try:            os.rmdir(src)        except:            passfor file in filelist:    if os.path.isdir(file):        continue    else:        t1 = time.gmtime(os.stat(path+file)[ST_MTIME])          t11 =  time.strftime('%Y-%m-%d',t1)         print t11          year,month,day=t11.split('-')                                                                                                          t111= datetime.datetime(int(year),int(month),int(day))                                                                                 t2 = time.gmtime()                                                                                                                     t22 =  time.strftime('%Y-%m-%d',t2)                                                                                                    year,month,day=t22.split('-')                                                                                                          t222= datetime.datetime(int(year),int(month),int(day))                                                                                 days =  (t222-t111).days        print str(t22)    if days>=7 :         try:            print "I will delete file "+path+file                                                                                                                               os.delete_file_folder(os.opath.abspath(os.path.join(path,file)))              print "I will delete file "+path+file        except Exception, e:            print eimport subprocessstr_cmd='svnadmin hotcopy  D:\\Repositories\\hannel E:\\svnbak\\data'+t22+'  --clean-logs'  p = subprocess.call(str_cmd)    

评论关闭