示例#1
0
def deploy(distribution, target):
    """Convert `distribution` into Rez package at `target`"""

    name = distribution.name

    maker = PackageMaker(name)
    maker.version = distribution.version
    maker.requires = distribution.requirements
    maker.url = distribution.url
    maker.description = distribution.description
    maker.variants = distribution.variants

    commands = set()
    for relpath, alias, args in distribution.binaries():

        # Temporarily expose app dir to PATH
        # TODO: Implement Scoop's "shims" for this purpose
        # Reason they aren't implemented at the moment is
        # because shims carry an absolute path to their
        # executable, which we can't put into a package as
        # packages may come from differently mounted paths
        # or network locations at any given time.
        dirname = os.path.dirname(relpath).replace("\\", "/")
        commands.add("env.PATH.prepend(r'{root}/app/%s')" % dirname)

    maker.commands = "\n".join(commands)

    package = maker.get_package()
    variant = next(package.iter_variants())
    root = variant.install(target).root

    appdir = os.path.join(root, "app")
    bindir = os.path.join(root, "bin")

    try:
        os.makedirs(root)
        os.makedirs(bindir)
    except OSError as e:
        if e.errno == errno.EEXIST:
            # That's ok
            pass
        else:
            raise

    shutil.copytree(distribution.root, appdir)

    # NOTE: Currently unused, see note above
    for relpath, alias, args in distribution.binaries():
        fname = os.path.basename(relpath)
        name, ext = os.path.splitext(fname)
        args = " ".join(args)

        bat = os.path.join(bindir, (alias or name) + ".bat")
        with open(bat, "w") as f:
            f.write("\n".join([
                "@echo off",
                "call %~dp0../app/{relpath} {args} %*".format(**locals())
            ]))
示例#2
0
def deploy(distribution, target):
    """Convert `distribution` into Rez package at `target`"""

    name = distribution.name

    maker = PackageMaker(name)
    maker.version = distribution.version
    maker.requires = distribution.requirements
    maker.url = distribution.url
    maker.description = distribution.description
    maker.variants = distribution.variants

    commands = set()
    for relpath, alias, args in distribution.binaries():

        # Temporarily expose app dir to PATH
        # TODO: Implement Scoop's "shims" for this purpose
        # Reason they aren't implemented at the moment is
        # because shims carry an absolute path to their
        # executable, which we can't put into a package as
        # packages may come from differently mounted paths
        # or network locations at any given time.
        dirname = os.path.dirname(relpath).replace("\\", "/")
        commands.add("env.PATH.prepend(r'{root}/app/%s')" % dirname)

    # Handle PATH environment variables
    # NOTE: This presumes all environment variables are paths,
    # and that they branch out from the app/ directory. There may(?)
    # be variables that aren't paths too
    for key, value in distribution.envs():
        commands.add("env.%s.prepend('{root}/app/%s')" % (key, value))

    # Handle the odd case of no commands being present
    # This is probably a bad package then
    if not commands:
        print("WARNING: No commands made by this package, "
              "inspect it to see if it's allright")
        commands.add("pass")

    maker.commands = "\n".join(commands)

    package = maker.get_package()
    variant = next(package.iter_variants())
    root = variant.install(target).root

    appdir = os.path.join(root, "app")
    bindir = os.path.join(root, "bin")

    try:
        os.makedirs(root)
        os.makedirs(bindir)
    except OSError as e:
        if e.errno == errno.EEXIST:
            # That's ok
            pass
        else:
            raise

    shutil.copytree(distribution.root, appdir)

    # NOTE: Currently unused, see note above
    for relpath, alias, args in distribution.binaries():
        fname = os.path.basename(relpath)
        name, ext = os.path.splitext(fname)
        args = " ".join(args)

        bat = os.path.join(bindir, (alias or name) + ".bat")
        with open(bat, "w") as f:
            f.write("\n".join([
                "@echo off",
                "call %~dp0../app/{relpath} {args} %*".format(**locals())
            ]))