Merge pull request #1212 from davvid/dev
[git-cola.git] / extras / build_util.py
blobe14ac715ad390e64e126326edf651b55f13928e6
1 from __future__ import absolute_import, division, print_function, unicode_literals
2 import os
3 try:
4 from shutil import which # pylint: disable=unused-import
5 except ImportError:
6 # pylint: disable=unused-import
7 from distutils.spawn import find_executable as which # noqa
10 def encode(string):
11 try:
12 result = string.encode('utf-8')
13 except (ValueError, UnicodeEncodeError):
14 result = string
15 return result
18 def make_string(x):
19 if x:
20 x = str(x)
21 return x
24 def stringify_options(items):
25 return [[make_string(x) for x in i] for i in items]
28 def stringify_list(items):
29 return [make_string(i) for i in items]
32 def newer(a, b):
33 """Return True if a is newer than b"""
34 try:
35 stat_a = os.stat(a)
36 stat_b = os.stat(b)
37 except OSError:
38 return True
39 return stat_a.st_mtime >= stat_b.st_mtime