1.1 --- a/common.py Mon Feb 20 18:50:16 2017 +0100
1.2 +++ b/common.py Tue Feb 21 00:20:43 2017 +0100
1.3 @@ -23,7 +23,7 @@
1.4 from compiler.transformer import Transformer
1.5 from errors import InspectError
1.6 from os import listdir, makedirs, remove
1.7 -from os.path import exists, isdir, join, split
1.8 +from os.path import exists, getmtime, isdir, join, split
1.9 from results import ConstantValueRef, LiteralSequenceRef, NameRef
1.10 import compiler.ast
1.11
1.12 @@ -76,6 +76,36 @@
1.13 else:
1.14 remove(path)
1.15
1.16 +def copy(source, target, only_if_newer=True):
1.17 +
1.18 + "Copy a text file from 'source' to 'target'."
1.19 +
1.20 + if isdir(target):
1.21 + target = join(target, split(source)[-1])
1.22 +
1.23 + if only_if_newer and not is_newer(source, target):
1.24 + return
1.25 +
1.26 + infile = open(source)
1.27 + outfile = open(target, "w")
1.28 +
1.29 + try:
1.30 + outfile.write(infile.read())
1.31 + finally:
1.32 + outfile.close()
1.33 + infile.close()
1.34 +
1.35 +def is_newer(source, target):
1.36 +
1.37 + "Return whether 'source' is newer than 'target'."
1.38 +
1.39 + if exists(target):
1.40 + target_mtime = getmtime(target)
1.41 + source_mtime = getmtime(source)
1.42 + return source_mtime > target_mtime
1.43 +
1.44 + return True
1.45 +
1.46 class CommonModule:
1.47
1.48 "A common module representation."