def prepare_agent_test_env(): """ Constructs the skeleton of directories if it not there already. :return: """ pod_folder = tempfile.mkdtemp() if 'AVA_POD' in os.environ: del os.environ['AVA_POD'] os.environ.setdefault('AVA_POD', pod_folder) assert os.path.exists(pod_folder) from ava.runtime import environ environ.get_environ(reset=True) base_dir = base_path() src_dir = os.path.join(base_dir, 'pod') # copy files from base_dir to user_dir subdirs = os.listdir(src_dir) for d in subdirs: src_path = os.path.join(src_dir, d) dst_path = os.path.join(pod_folder, d) ignore_pattern = shutil.ignore_patterns("__init__.py") if os.path.isdir(src_path): shutil.copytree(src_path, dst_path, ignore=ignore_pattern) else: shutil.copy2(src_path, dst_path) return pod_folder
def init_app_dir(folder=None): """ Constructs the skeleton of directories if it not there already. :return: """ if folder is None: folder = get_app_dir() _logger.debug("Initializing app folder...") if os.path.exists(folder): _logger.info("App folder '%s' exists, abort initialization." % folder) return os.makedirs(folder) src_dir = os.path.join(base_path(), 'pod') # copy files from base_dir to user_dir subdirs = os.listdir(src_dir) # ignore_pattern = shutil.ignore_patterns("__init__.py") for d in subdirs: src_path = os.path.join(src_dir, d) dst_path = os.path.join(folder, d) if os.path.isdir(src_path): shutil.copytree(src_path, dst_path) else: shutil.copy2(src_path, dst_path)
def prepare_agent_test_env(): """ Constructs the skeleton of directories if it not there already. :return: """ pod_folder = tempfile.mkdtemp() if defines.POD_ENV_NAME in os.environ: del os.environ[defines.POD_ENV_NAME] os.environ.setdefault(defines.POD_ENV_NAME, pod_folder) assert os.path.exists(pod_folder) from ava.runtime import environ environ.get_environ(reset=True) base_dir = base_path() src_dir = os.path.join(base_dir, defines.POD_FOLDER_NAME) # copy files from base_dir to user_dir subdirs = os.listdir(src_dir) for d in subdirs: src_path = os.path.join(src_dir, d) dst_path = os.path.join(pod_folder, d) ignore_pattern = shutil.ignore_patterns("__init__.py") if os.path.isdir(src_path): shutil.copytree(src_path, dst_path, ignore=ignore_pattern) else: shutil.copy2(src_path, dst_path) return pod_folder
def __init__(self): self.logger = logging.getLogger(__name__) # Determines the location of the base directory which contains files # for a specific user. # This script assumes it is located at 'ava/runtime' sub-directory. from ava.util import base_path self.base_dir = base_path() # Determines the location of the home directory. self.pod_dir = os.path.join(self.base_dir, POD_DIR_NAME) self.pod_dir = os.environ.get(POD_DIR_ENV, self.pod_dir) self.pod_dir = os.path.abspath(self.pod_dir) if not os.path.isdir(self.pod_dir): self.logger.error("Invalid pod folder: %s" % self.pod_dir) sys.exit(-1) # print("POD folder: %s" % self.pod_dir) self.conf_dir = os.path.join(self.pod_dir, CONF_DIR_NAME) self.pkgs_dir = os.path.join(self.pod_dir, PKGS_DIR_NAME) self.data_dir = os.path.join(self.pod_dir, DATA_DIR_NAME) self.logs_dir = os.path.join(self.pod_dir, LOGS_DIR_NAME) self.mods_dir = os.path.join(self.pod_dir, MODS_DIR_NAME) # Flag indicating if the runtime is launched by a shell. self.has_shell = False
def init_app_dir(folder=None): """ Constructs the skeleton of directories if it not there already. :return: """ if folder is None: folder = get_app_dir() print("Initializing app user folder: %s" % folder) if os.path.exists(folder): _logger.warning("App user folder '%s' exists, abort initialization." % folder) return os.makedirs(folder) src_dir = os.path.join(base_path(), POD_FOLDER_NAME) # copy files from base_dir to user_dir subdirs = os.listdir(src_dir) # ignore_pattern = shutil.ignore_patterns("__init__.py") subdirs.append('logs') subdirs.append('data') subdirs.append('mods') subdirs.append('jobs') subdirs.append('pkgs') subdirs.append('scripts') for d in subdirs: src_path = os.path.join(src_dir, d) dst_path = os.path.join(folder, d) if os.path.isdir(src_path): if not os.path.exists(dst_path): shutil.copytree(src_path, dst_path) elif os.path.isfile(src_path): shutil.copy2(src_path, dst_path) for d in subdirs: dst_path = os.path.join(folder, d) if not os.path.exists(dst_path): os.makedirs(dst_path)
def prepare_agent_test_env(): """ Constructs the skeleton of directories if it not there already. :return: """ pod_folder = tempfile.mkdtemp() os.environ.setdefault('AVA_POD', pod_folder) base_dir = base_path() src_dir = os.path.join(base_dir, 'pod') # copy files from base_dir to user_dir subdirs = os.listdir(src_dir) for d in subdirs: src_path = os.path.join(src_dir, d) dst_path = os.path.join(pod_folder, d) if os.path.isdir(src_path): shutil.copytree(src_path, dst_path) else: shutil.copy2(src_path, dst_path)
def __init__(self, home=None, a_profile=None): # Determines the location of the base directory which contains files shared by all users. # This script assumes it is located at 'eavatar/runtime' sub-directory. from ava.util import base_path self.base_dir = base_path() # Determines the location of the home directory. self.home_dir = os.path.join(self.base_dir, HOME_DIR_NAME) self.home_dir = os.path.abspath(self.home_dir) self.conf_dir = os.path.join(self.home_dir, CONF_DIR_NAME) self.pkgs_dir = os.path.join(self.home_dir, PKGS_DIR_NAME) self.data_dir = os.path.join(self.home_dir, DATA_DIR_NAME) self.logs_dir = os.path.join(self.home_dir, LOGS_DIR_NAME) _logger.debug("Home dir: %s", self.home_dir) # Flag indicating if the runtime is launched by a shell. self.has_shell = False self.shell_port = 0
def test_base_path_should_contain_pod_folder(): basedir = base_path() source_pod_folder = os.path.join(basedir, defines.POD_FOLDER_NAME) assert os.path.exists(source_pod_folder) assert os.path.isdir(source_pod_folder)
def setUp(self): self.conf_file = os.path.join(base_path(), 'tests', 'data', 'test.yml')