import contextlib from os.path import exists, join from os import getcwd, chdir, makedirs, walk, uname import shutil from fnmatch import fnmatch from tempfile import mkdtemp from pythonforandroid.logger import (logger, Err_Fore, error, info) build_platform = '{system}-{machine}'.format( system=uname()[0], machine=uname()[-1]).lower() """the build platform in the format `system-machine`. We use this string to define the right build system when compiling some recipes or to get the right path for clang compiler""" @contextlib.contextmanager def current_directory(new_dir): cur_dir = getcwd() logger.info(''.join((Err_Fore.CYAN, '-> directory context ', new_dir, Err_Fore.RESET))) chdir(new_dir) yield logger.info(''.join((Err_Fore.CYAN, '<- directory context ', cur_dir, Err_Fore.RESET))) chdir(cur_dir) @contextlib.contextmanager def temp_directory(): temp_dir = mkdtemp() try: logger.debug(''.join((Err_Fore.CYAN, ' + temp directory used ', temp_dir, Err_Fore.RESET))) yield temp_dir finally: shutil.rmtree(temp_dir) logger.debug(''.join((Err_Fore.CYAN, ' - temp directory deleted ', temp_dir, Err_Fore.RESET))) def ensure_dir(filename):