Beispiel #1
0
    def __init__(self, app_name=APP_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 ..util import base_path

        self.base_dir = base_path()
        _logger.info("Work folder: %s" % self.base_dir)

        # Determines the location of the home directory.

        # self.pod_dir = os.path.join(self.base_dir, POD_DIR_NAME)
        self.pod_dir = get_app_dir(app_name)
        self.pod_dir = os.environ.get(POD_DIR_ENV, self.pod_dir)
        self.pod_dir = os.path.abspath(self.pod_dir)

        _logger.info("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
Beispiel #2
0
    def __init__(self, app_name=APP_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 ..util import base_path

        self.base_dir = base_path()
        _logger.info("Work folder: %s" % self.base_dir)

        # Determines the location of the home directory.

        # self.pod_dir = os.path.join(self.base_dir, POD_DIR_NAME)
        self.pod_dir = get_app_dir(app_name)
        self.pod_dir = os.environ.get(POD_DIR_ENV, self.pod_dir)
        self.pod_dir = os.path.abspath(self.pod_dir)

        _logger.info("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
Beispiel #3
0
def launch(inbox, outbox):
    app_dir = get_app_dir()
    _logger.info("App dir: %s" % app_dir)

    if not os.path.exists(app_dir):
        init_app_dir(app_dir)

    if not os.path.isdir(app_dir):
        _logger.error("Invalid app folder: %s" % app_dir)
        sys.exit(-1)

    start_agent(inbox, outbox)
Beispiel #4
0
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)