From 91e69ce7e326ec5354e91b525501e757c1c895e6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 26 Jun 2016 14:56:02 +0530 Subject: [PATCH] A spot of refactoring --- setup.py | 2 +- setup/__init__.py | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 0ea37864bd..ecbf05a501 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def check_version_info(): raise SystemExit('calibre requires python >= 2.7.9 and < 3. Current python version: %s' % vi) 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 from setup import prints, get_warnings diff --git a/setup/__init__.py b/setup/__init__.py index 77d3c4bb94..25cc7e449b 100644 --- a/setup/__init__.py +++ b/setup/__init__.py @@ -27,6 +27,19 @@ __version__ = __appname__ = modules = functions = basenames = scripts = None _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(): global _cache_dir_built 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 does not exist. ''' - 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 + return newer(targets, sources) def info(self, *args, **kwargs): prints(*args, **kwargs)