python自动同步脚本

python自动同步脚本

ID:14323050

大小:41.50 KB

页数:5页

时间:2018-07-27

python自动同步脚本_第1页
python自动同步脚本_第2页
python自动同步脚本_第3页
python自动同步脚本_第4页
python自动同步脚本_第5页
资源描述:

《python自动同步脚本》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、#!/usr/bin/envpython#coding:utf-8importos,sys,re,shutilimportwin32api,win32file,time,threadingfromConfigParserimportConfigParserfromwin32conimport*MARKFILE='_.m'#删除目录时没通知删除文件时通知目录#安装pywinhttp://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win32-py2.6.exe/

2、downloadclassworker(threading.Thread):def__init__(self,config):#printconfigconfig['shadowRoot']='.sr'self.mkIfNotExit(config['shadowRoot'])self.config=configself.regex=re.compile(config['filter'])self.synList(self.config['from'])threading.Thread.__init__(self,name="thread1")defmkI

3、fNotExit(self,path,isfile=0):if(notos.path.exists(path)):if(notisfile):os.mkdir(path)else:#printpathtry:shutil.copyfile(MARKFILE,path)except:pass#shutil.copy('_.m',path)return1else:return0defupdateMtime(self,df,mtime):os.utime(df,(mtime,mtime))defsynFolder(self,path):if(self.confi

4、g['protocol']=='FILE'):if(notos.path.exists(path)):print'mkdir:',pathos.mkdir(path)defsynFile(self,source,to):if(self.config['protocol']=='FILE'):print'upload:',to#目录不存在创建shutil.copyfile(source,to)defuploadFile(self,source,relatpath):if(self.regex.search(relatpath)):return1to=os.p

5、ath.join(self.config['to'],relatpath)if(os.path.isdir(source)):self.synFolder(to)else:self.synFile(source,to)#print'source:',source,'to:',todefcheckStat(self,path):'''检测'''relatpath=self.getRelatePath(path)if(self.regex.search(relatpath)):return1data=os.path.join(self.config['shad

6、owRoot'],relatpathorself.config['sec'].decode('utf-8'))if(len(relatpath)<1):self.config['shadowRoot']=dataresult=0if(self.mkIfNotExit(data,os.path.isfile(path))):'''新创建同步'''self.uploadFile(path,relatpath)elif(os.path.getmtime(path)>os.path.getmtime(data)):'''修改过同步修改记录时间'''self.upl

7、oadFile(path,relatpath)self.updateMtime(data,os.path.getmtime(path))else:result=1#printrelatpath,os.path.getmtime(path),data,result#printrelatpath,os.path.getmtime(path),datareturnresultdefsynList(self,dirName):'''对比目录'''#printdirNametry:if(self.checkStat(dirName)):return1else:ls=

8、os.listdir(dirName)forlinls:temp=

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。