diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-03-05 09:10:24 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-03-05 12:56:41 +0100 |
commit | f3139399b273fdf405f20cba32a08262cd933d6e (patch) | |
tree | deed895170c12f8478af44a73b23b63b75239957 /utils.py | |
parent | 2b94776295e1d9f882096b4f2c7ca0a93a20b20c (diff) | |
parent | b57c557c8cd1012851f8a245075591dc33be425b (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.9
Change-Id: I452d3a0a04e282b678879132ca1b3a272910ef04
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 35 |
1 files changed, 31 insertions, 4 deletions
@@ -323,7 +323,7 @@ def makefile(dst, content=None, vars=None): def copydir(src, dst, filter=None, ignore=None, force=True, recursive=True, vars=None, - dir_filter_function=None, force_copy_symlinks=False): + dir_filter_function=None, file_filter_function=None, force_copy_symlinks=False): if vars is not None: src = src.format(**vars) @@ -357,10 +357,12 @@ def copydir(src, dst, filter=None, ignore=None, force=True, recursive=True, vars if recursive: results.extend( copydir(srcname, dstname, filter, ignore, force, recursive, - vars, dir_filter_function, force_copy_symlinks)) + vars, dir_filter_function, file_filter_function, + force_copy_symlinks)) else: - if (filter is not None and not filter_match(name, filter)) or \ - (ignore is not None and filter_match(name, ignore)): + if (file_filter_function is not None and not file_filter_function(name, srcname)) \ + or (filter is not None and not filter_match(name, filter)) \ + or (ignore is not None and filter_match(name, ignore)): continue if not os.path.exists(dst): os.makedirs(dst) @@ -983,3 +985,28 @@ def rpathsHasOrigin(rpaths): if match: return True return False + +def memoize(function): + """ Decorator to wrap a function with a memoizing callable. + It returns cached values when the wrapped function is called with the same arguments. + """ + memo = {} + def wrapper(*args): + if args in memo: + return memo[args] + else: + rv = function(*args) + memo[args] = rv + return rv + return wrapper + +def get_python_dict(python_script_path): + try: + with open(python_script_path) as f: + python_dict = {} + code = compile(f.read(), python_script_path, 'exec') + exec(code, {}, python_dict) + return python_dict + except IOError as e: + print("get_python_dict: Couldn't get dict from python file: {}.".format(python_script_path)) + raise |