- #!/usr/bin/python
- from pyinotify import *
- import os, os.path
- flags = IN_CLOSE_WRITE|IN_CREATE|IN_Q_OVERFLOW
- dirs = {}
- base = '/log/lighttpd/cache/p_w_picpaths/icon/u241'
- base = 'tmp'
- class UpdateParentDir(ProcessEvent):
- def process_IN_CLOSE_WRITE(self, event):
- print 'modify', event.pathname
- mtime = os.path.getmtime(event.pathname)
- p = event.path
- while p.startswith(base):
- m = os.path.getmtime(p)
- if m < mtime:
- print 'update', p
- os.utime(p, (mtime,mtime))
- elif m > mtime:
- mtime = m
- p = os.path.dirname(p)
- process_IN_MODIFY = process_IN_CLOSE_WRITE
- def process_IN_Q_OVERFLOW(self, event):
- print 'over flow'
- max_queued_events.value *= 2
- def process_default(self, event):
- pass
- wm = WatchManager()
- notifier = Notifier(wm, UpdateParentDir())
- dirs.update(wm.add_watch(base, flags, rec=True, auto_add=True))
- notifier.loop()
- #!/usr/bin/python
- import sys,time,re,urllib
- import os,os.path
- from os.path import exists, isdir, getmtime
- src = sys.argv[1]
- dst = sys.argv[2]
- def local_mirror(src, dst):
- if exists(dst) and mtime == getmtime(dst):
- return
- if not isdir(src):
- print 'update:', dst
- open(dst,'wb').write(open(src).read())
- else:
- if not exists(dst):
- os.makedirs(dst)
- for filename in os.listdir(src):
- local_mirror(os.path.join(src,filename), os.path.join(dst,filename))
- os.utime(dst, (mtime,mtime))
- def get_info(path):
- f = urllib.urlopen(path)
- mtime = f.headers.get('Last-Modified')
- if mtime:
- mtime = time.mktime(time.strptime(mtime, '%a, %d %b %Y %H:%M:%S %Z'))
- content = f.read()
- f.close()
- return int(mtime), content
- p = re.compile(r'([\d.]+?) +([\w/]+)')
- def remote_mirror(src, dst):
- mtime, content = get_info(src)
- if exists(dst) and mtime == int(getmtime(dst)):
- return
- print 'update:', dst, src
- if not src.endswith('/'):
- open(dst,'wb').write(content)
- else:
- if not exists(dst):
- os.makedirs(dst)
- for mt,filename in p.findall(content):
- mt = int(float(mt))
- lpath = dst+filename
- if not exists(lpath) or int(getmtime(lpath)) != mt:
- remote_mirror(src+filename, lpath)
- os.utime(dst, (mtime,mtime))
- if src.startswith('http://'):
- mirror = remote_mirror
- else:
- mirror = local_mirror
- while True:
- mirror(src, dst)
- time.sleep(1)
- #!/usr/bin/python
- import os,os.path
- import web
- import time
- root = 'tmp'
- HTTP_HEADER_TIME = '%a, %d %b %Y %H:%M:%S %Z'
- class FileServer:
- def GET(self, path):
- path = root + path
- if not os.path.exists(path):
- return 404
- mtime = time.localtime(os.path.getmtime(path))
- web.header('Last-Modified', time.strftime(HTTP_HEADER_TIME, mtime))
- if os.path.isdir(path):
- for file in os.listdir(path):
- if file.startswith('.'): continue
- p = os.path.join(path,file)
- m = os.path.getmtime(p)
- if os.path.isdir(p):
- file += '/'
- print m, file
- else:
- print open(path,'rb').read()
- urls = (
- "(/.*)", "FileServer",
- )
- if __name__ == '__main__':
- web.run(urls, globals())
-
大量小文件的实时同步方案(python…
<!DOCTYPE html PUBLIC "-//W3C//DT
修改时间 python 根目录 -
Linux删除大量小文件的两种方案场景介绍
关于Linux上删除小文件写过这篇《Linux下如何快速删除大量碎小的文件?》,碰巧看到社群的技术文章《Linux 删除大量小文件的
linux 运维 服务器 sed oracle
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M
















