Ejemplo n.º 1
0
def install_from_zip(file_):
    """
    Execute all the setup steps for a module installation. Takes either a
    filename or a file-like object (which should already be opened).
    Raises an IOError if the zip file reading failed, and a ValueError if the
    module is already installed.
    """
    with zipfile.ZipFile(file_) as zf:
        toplevel_directories = [n for n in zf.namelist() \
                if n.endswith('/') and n.count('/') == 1]

        # validate zip format
        if len(toplevel_directories) != 1:
            msg = 'Archive should only have one directory at its root'
            raise IOError(msg)

        # validate against already installed modules
        module_name = toplevel_directories[0][:-1]
        if is_installed(module_name):
            raise ValueError('Module already installed')

        # extract zip file
        zf.extractall(path.modules_directory())

    # run the "install" command
    if not run_module_command(module_name, 'install'):
        uninstall(module_name)
        return False

    # start the module
    instance.invoke(module_name)
    return True
Ejemplo n.º 2
0
def install_from_zip(file_):
    """
    Execute all the setup steps for a module installation. Takes either a
    filename or a file-like object (which should already be opened).
    Raises an IOError if the zip file reading failed, and a ValueError if the
    module is already installed.
    """
    with zipfile.ZipFile(file_) as zf:
        toplevel_directories = [n for n in zf.namelist() \
                if n.endswith('/') and n.count('/') == 1]

        # validate zip format
        if len(toplevel_directories) != 1:
            msg = 'Archive should only have one directory at its root'
            raise IOError(msg)

        # validate against already installed modules
        module_name = toplevel_directories[0][:-1]
        if is_installed(module_name):
            raise ValueError('Module already installed')

        # extract zip file
        zf.extractall(path.modules_directory())

    # run the "install" command
    if not run_module_command(module_name, 'install'):
        uninstall(module_name)
        return False

    # start the module
    instance.invoke(module_name)
    return True
Ejemplo n.º 3
0
def get_installed_modules(detailed=False):
    """
    Return a list of all installed modules in the installation directory.
    Detailed information can be given (eg. module configuration) by setting the
    "detailed" argument to true.
    """
    module_list = []
    for module_name in os.listdir(path.modules_directory()):
        if not is_installed(module_name):
            continue
        if detailed:
            module_config = get_config(module_name)
            module_name = { MODULE_NAME_ENTRY: module_name }
            module_name.update(module_config)
        module_list.append(module_name)
    return module_list
Ejemplo n.º 4
0
def get_installed_modules(detailed=False):
    """
    Return a list of all installed modules in the installation directory.
    Detailed information can be given (eg. module configuration) by setting the
    "detailed" argument to true.
    """
    module_list = []
    for module_name in os.listdir(path.modules_directory()):
        if not is_installed(module_name):
            continue
        if detailed:
            module_config = get_config(module_name)
            module_name = {MODULE_NAME_ENTRY: module_name}
            module_name.update(module_config)
        module_list.append(module_name)
    return module_list