Last active
January 4, 2016 13:35
-
-
Save wangxiaodong/1b3e52d44becd6bc9df5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf8 -*- | |
import subprocess | |
import os | |
import threading | |
import time | |
import sys | |
rep = [("www.google.com/", "android.local/"), | |
("developer.android.com/", "android.local/"), | |
("apis.google.com/", "android.local/")] | |
DOC_PATH = 这里设置好sdk文档的目录 | |
cmd = "sed -i .bak \"s|%(find_string)s|%(replace_string)s|g\" %(filename)s" | |
class TaskInfo(object): | |
def __init__(self): | |
self.finish = False | |
self.handled = 0 | |
self.current = "" | |
self.printing = False | |
taskInfo = TaskInfo() | |
def worker(): | |
for root, dirs, files in os.walk(DOC_PATH): | |
for i in files: | |
if os.path.splitext(i)[1] not in ['.html']: | |
continue | |
abspath = os.path.join(root, i) | |
taskInfo.current = abspath | |
for ori, dest in rep: | |
command = cmd % dict( | |
find_string=ori, replace_string=dest, filename=abspath) | |
subprocess.call(command, shell=True) | |
subprocess.call("rm " + abspath + '.bak', shell=True) | |
taskInfo.handled += 1 | |
taskInfo.finish = True | |
t = threading.Thread(target=worker) | |
t.setDaemon(True) | |
t.start() | |
printing = False | |
starttime = time.time() | |
def display(): | |
max = 60 | |
sys.stdout.write('\b'*max) | |
sys.stdout.flush() | |
s0 = "[%d:%d]" % (time.time() - starttime, taskInfo.handled) | |
sys.stdout.write(s0) | |
sys.stdout.write(taskInfo.current[len(s0)-max:]) | |
sys.stdout.flush() | |
taskInfo.printing = True | |
def timeout(): | |
taskInfo.printing = False | |
print time.ctime(starttime) | |
while not taskInfo.finish: | |
if not taskInfo.printing: | |
display() | |
threading.Timer(0.1, timeout).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment