Esempio 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
Esempio 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
Esempio n. 3
0
def use_module(module_name):
    """
    Shortcut for referencing a module through network, given its module name.
    """
    name = path.realname(module_name)
    if not instance.status(name):
        logger.info('Trying to launch the `%s` dependancy module.',
                module_name)
        instance.invoke(name, True)
        t = time.time()
        while not is_ready(module_name):
            time.sleep(0.1)
            if time.time() - t > SOCKET_TIMEOUT:
                logger.error('Cannot launch the `%s` dependency: abort',
                        module_name)
                return kill()
        logger.info('`%s` dependancy module successfully launched.',
                module_name)
    return Network(name=module_name)