Esempio n. 1
0
def apply(context, args):
    parser = argparse.ArgumentParser()
    parser.add_argument("--overlay", action="store_true", help="use overlay")
    parser.add_argument("--envvar", type=str, action="append", default=[], help="variable in NAME=VALUE format")
    parser.add_argument("command", type=str, help="command to execute inside chroot")
    args = parser.parse_args(args)
    envvars = dict(map(lambda x:collect.parse_var(x), args.envvar))
    command = context.apply_variables(args.command)
    print "$exec '%s'" % command
    if args.overlay:
        print "Using overlay"
        overlay_dir = os.path.normpath(context.destination) + ".overlay"
        overlay_root = overlay_dir + "/root"
        overlay_work = overlay_dir + "/work"
        collect.mkdir_p(overlay_root)
        collect.mkdir_p(overlay_work)
        try:
            overlayfs_opts = "lowerdir=%s,upperdir=%s,workdir=%s" % (context.source,context.destination,overlay_work)
            subprocess.check_call(["mount","-t","overlay","overlay","-o",overlayfs_opts,overlay_root])
            try:
                do_chroot(overlay_root, command, envvars)
            finally:
                subprocess.check_call(["umount", overlay_root])
        finally:
            shutil.rmtree(overlay_dir)
    else:
        do_chroot(context.destination, command, envvars)
Esempio n. 2
0
def apply(context, args):
    parser = argparse.ArgumentParser()
    parser.add_argument("--overlay", action="store_true", help="use overlay")
    parser.add_argument("--envvar",
                        type=str,
                        action="append",
                        default=[],
                        help="variable in NAME=VALUE format")
    parser.add_argument("--store",
                        type=str,
                        default=None,
                        help="variable name to store result")
    parser.add_argument("command",
                        type=str,
                        help="command to execute inside chroot")
    args = parser.parse_args(args)
    envvars = dict(map(lambda x: collect.parse_var(x), args.envvar))
    command = context.apply_variables(args.command)
    print "$exec '%s'" % command
    output = ""
    if args.overlay:
        print "Using overlay"
        overlay_dir = os.path.normpath(context.destination) + ".overlay"
        overlay_root = overlay_dir + "/root"
        overlay_work = overlay_dir + "/work"
        collect.mkdir_p(overlay_root)
        collect.mkdir_p(overlay_work)
        try:
            overlayfs_opts = "lowerdir=%s,upperdir=%s,workdir=%s" % (
                context.source, context.destination, overlay_work)
            subprocess.check_call([
                "mount", "-t", "overlay", "overlay", "-o", overlayfs_opts,
                overlay_root
            ])
            try:
                output = do_chroot(overlay_root, command, envvars)
            finally:
                subprocess.check_call(["umount", overlay_root])
        finally:
            shutil.rmtree(overlay_dir)
    else:
        output = do_chroot(context.destination, command, envvars)

    if args.store is not None:
        context.set_variable(args.store, output.strip())
Esempio n. 3
0
import argparse, os
import collect

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--source",
                        type=str,
                        default="/",
                        help="source directory")
    parser.add_argument("--var",
                        type=str,
                        action="append",
                        default=[],
                        help="variable")
    parser.add_argument("lstfile", type=str, help=".lst file")
    parser.add_argument("destination", type=str, help="destination directory")
    args = parser.parse_args()

    if os.getuid() != 0: raise Exception("You must be a root user.")

    destination = args.destination
    if destination.strip() == "": destination = "."
    if os.path.abspath(destination) in ["/", "//"]:
        raise Exception(
            "Setting system root directory as destination is totally insane.")

    context = collect.Context(
        args.source, destination,
        dict(map(lambda x: collect.parse_var(x), args.var)))
    collect.run(args.lstfile, context)
Esempio n. 4
0
            elif line[0] == "$copy":
                print os.path.join("files", line[1])
            elif line[0] == "$patch":
                print os.path.join("files", line[2])
            elif line[0] == "$set":
                if len(line) != 3:
                    raise Exception("$set directive gets 2 args")
                context.set_variable(line[1], context.apply_variables(line[2]))

    context.mark_lstfile_as_processed(lstfile)
    print lstfile


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--source",
                        type=str,
                        default="/",
                        help="source directory")
    parser.add_argument("--var",
                        type=str,
                        action="append",
                        default=[],
                        help="variable")
    parser.add_argument("lstfile", type=str, help=".lst file")
    args = parser.parse_args()

    context = collect.Context(
        args.source, None, dict(map(lambda x: collect.parse_var(x), args.var)))
    process_lstfile(args.lstfile, context)
Esempio n. 5
0
import argparse, os
import collect

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--source", type=str, default="/", help="source directory")
    parser.add_argument("--var", type=str, action="append", default=[], help="variable")
    parser.add_argument("lstfile", type=str, help=".lst file")
    parser.add_argument("destination", type=str, help="destination directory")
    args = parser.parse_args()

    if os.getuid() != 0:
        raise Exception("You must be a root user.")

    destination = args.destination
    if destination.strip() == "":
        destination = "."
    if os.path.abspath(destination) in ["/", "//"]:
        raise Exception("Setting system root directory as destination is totally insane.")

    context = collect.Context(args.source, destination, dict(map(lambda x: collect.parse_var(x), args.var)))
    collect.run(args.lstfile, context)