A spot of refactoring

This commit is contained in:
Kovid Goyal 2016-06-26 14:56:02 +05:30
parent 37da6dc36a
commit 91e69ce7e3
2 changed files with 15 additions and 12 deletions

View File

@ -15,7 +15,7 @@ def check_version_info():
raise SystemExit('calibre requires python >= 2.7.9 and < 3. Current python version: %s' % vi) raise SystemExit('calibre requires python >= 2.7.9 and < 3. Current python version: %s' % vi)
check_version_info() check_version_info()
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import setup.commands as commands import setup.commands as commands
from setup import prints, get_warnings from setup import prints, get_warnings

View File

@ -27,6 +27,19 @@ __version__ = __appname__ = modules = functions = basenames = scripts = None
_cache_dir_built = False _cache_dir_built = False
def newer(targets, sources):
if isinstance(targets, basestring):
targets = [targets]
if isinstance(sources, basestring):
sources = [sources]
for f in targets:
if not os.path.exists(f):
return True
ttimes = map(lambda x: os.stat(x).st_mtime, targets)
stimes = map(lambda x: os.stat(x).st_mtime, sources)
newest_source, oldest_target = max(stimes), min(ttimes)
return newest_source > oldest_target
def build_cache_dir(): def build_cache_dir():
global _cache_dir_built global _cache_dir_built
ans = os.path.join(os.path.dirname(SRC), '.build-cache') ans = os.path.join(os.path.dirname(SRC), '.build-cache')
@ -226,17 +239,7 @@ class Command(object):
Return True if sources is newer that targets or if targets Return True if sources is newer that targets or if targets
does not exist. does not exist.
''' '''
if isinstance(targets, basestring): return newer(targets, sources)
targets = [targets]
if isinstance(sources, basestring):
sources = [sources]
for f in targets:
if not os.path.exists(f):
return True
ttimes = map(lambda x: os.stat(x).st_mtime, targets)
stimes = map(lambda x: os.stat(x).st_mtime, sources)
newest_source, oldest_target = max(stimes), min(ttimes)
return newest_source > oldest_target
def info(self, *args, **kwargs): def info(self, *args, **kwargs):
prints(*args, **kwargs) prints(*args, **kwargs)