履歴をしらべてコピーする。
履歴を調べて古かったらコピーするというスクリプトを書いてみた。 makefileの代わりに
import sys import os import shutil import re # pathlistで指定したフォルダのファイルに対応するファイルがbasepath以下にある場合、basepathの方が古くなっていたらコピーする。 basepath = "./tmp/" pathlist = ["./dist","./html","./lib"] def fileList(path): list = [] for root,dirs,files in os.walk(path): t = [os.path.join(root,f) for f in files] list.extend(t) return list def isLeftPathIsNew(path1, path2): if not os.path.exists(path1): return False if not os.path.exists(path2): return False time1 = os.stat(path1).st_mtime time2 = os.stat(path2).st_mtime # print(path1 + str(time1) + ">=" + path2 + str(time2)) if time1 >= time2: return True return False for path in pathlist: # print("\n") fList = fileList(path) for f in fList: reg = r'\..*' if re.match(reg, os.path.basename(f)): # print("Skip" + f) continue tf = basepath + f[2:] if isLeftPathIsNew(tf,f): # print("new!"+tf) continue else: print("old!"+tf) dir = os.path.dirname(tf) if not os.path.exists(dir): print("makedir", dir) os.makedirs(dir) shutil.copy(f,tf)