Ejemplo n.º 1
0
def install(package_name):
    """Installs a holodeck package.

    Args:
        package_name (:obj:`str`): The name of the package to install
    """
    _check_for_old_versions()
    holodeck_path = util.get_holodeck_path()

    packages = available_packages()
    if package_name not in packages:
        print("Package not found. Available package are:", file=sys.stderr)
        pprint.pprint(packages, width=10, indent=4, stream=sys.stderr)
        return

    # example: %backend%/packages/0.1.0/DefaultWorlds/Linux.zip
    binary_url = "{backend_url}packages/{holodeck_version}/{package_name}/{platform}.zip".format(
        backend_url=BACKEND_URL,
        holodeck_version=util.get_holodeck_version(),
        package_name=package_name,
        platform=util.get_os_key())

    install_path = os.path.join(holodeck_path, "worlds", package_name)

    print("Installing {} from {} to {}".format(package_name, binary_url,
                                               install_path))

    _download_binary(binary_url, install_path)
Ejemplo n.º 2
0
def _iter_packages():
    path = util.get_holodeck_path()
    worlds_path = os.path.join(path, "worlds")
    if not os.path.exists(worlds_path):
        os.makedirs(worlds_path)
    for dir_name in os.listdir(worlds_path):
        full_path = os.path.join(worlds_path, dir_name)
        if os.path.isdir(full_path):
            for file_name in os.listdir(full_path):
                if file_name == "config.json":
                    with open(os.path.join(full_path, file_name), 'r') as f:
                        config = json.load(f)
                    yield config, full_path
Ejemplo n.º 3
0
def _find_file_in_worlds_dir(filename):
    """
    Recursively tries to find filename in the worlds directory of holodeck

    Args:
        filename (:obj:`str`): Pattern to try and match (fnmatch)

    Returns:
        :obj:`str`: The path or an empty string if the file was not found

    """
    for root, _, filenames in os.walk(util.get_holodeck_path(), "worlds"):
        for match in fnmatch.filter(filenames, filename):
            return os.path.join(root, match)
    return ""
Ejemplo n.º 4
0
def install(package_name):
    """Installs a holodeck package.

    Args:
        package_name (str): The name of the package to install
    """
    holodeck_path = util.get_holodeck_path()
    binary_website = "https://s3.amazonaws.com/holodeckworlds/"

    if package_name not in packages:
        raise HolodeckException("Unknown package name " + package_name)
    package_url = packages[package_name]

    print("Installing " + package_name + " at " + holodeck_path)
    install_path = os.path.join(holodeck_path, "worlds")
    binary_url = binary_website + util.get_os_key() + "_" + package_url
    _download_binary(binary_url, install_path)
    if os.name == "posix":
        _make_binary_excecutable(package_name, install_path)
Ejemplo n.º 5
0
def get_scenario(scenario_name):
    """Gets the scenario configuration associated with the given name

    Args:
        scenario_name (:obj:`str`): name of the configuration to load - eg "UrbanCity-Follow"
            Must be an exact match. Name must be unique among all installed packages

    Returns:
        :obj:`dict`: A dictionary containing the configuration file

    """
    config_path = _find_file_in_worlds_dir(scenario_name + ".json")

    if config_path == "":
        raise FileNotFoundError(
            "The file `{file}.json` could not be found in {path}. "
            "Make sure the package that contains {file} " \
            "is installed.".format(file=scenario_name, path=util.get_holodeck_path()))

    return load_scenario_file(config_path)
Ejemplo n.º 6
0
def install(package_name, url=None):
    """Installs a holodeck package.

    Args:
        package_name (:obj:`str`): The name of the package to install
    """

    if package_name is None and url is None:
        raise HolodeckException(
            "You must specify the URL or a valid package name")

    _check_for_old_versions()
    holodeck_path = util.get_holodeck_path()

    if url is None:
        # If the URL is none, we need to derive it
        packages = available_packages()
        if package_name not in packages:
            print("Package not found. Available packages are:",
                  file=sys.stderr)
            pprint.pprint(packages, width=10, indent=4, stream=sys.stderr)
            return

        # example: %backend%/packages/0.1.0/DefaultWorlds/Linux.zip
        url = "{backend_url}packages/{holodeck_version}/{package_name}/{platform}.zip".format(
            backend_url=BACKEND_URL,
            holodeck_version=util.get_holodeck_version(),
            package_name=package_name,
            platform=util.get_os_key())

    install_path = os.path.join(holodeck_path, "worlds", package_name)

    print("Installing {} from {} to {}".format(package_name, url,
                                               install_path))

    _download_binary(url, install_path)