**kwargs): super(BtrfsChrootManager, self).__init__(*args, **kwargs) self.newsvcmd = newsvcmd self.snapsvcmd = snapsvcmd self.delsvcmd = delsvcmd self.targetname = targetname def create_new(self, name, packagemanager, repos, logstore): templatepath = os.path.join(self.topdir, self.targetname) rootpath = self.path_from_name(name) if not os.path.exists(templatepath): self.su().btrfs_create(rootpath) root = ChrootRootManager.create_new(self, name, packagemanager, repos, logstore) self.su().btrfs_snapshot(rootpath, templatepath) else: self.su().btrfs_snapshot(templatepath, rootpath) root = Chroot(self, rootpath, self._root_arch(packagemanager)) self._update_latest_link(rootpath) return root root_managers = Registry("root type") root_managers.register("chroot", ChrootRootManager) root_managers.register("chroot-with-cache", CompressedChrootManager) root_managers.register("chroot-with-btrfs", BtrfsChrootManager) def get_root_manager(suwrapper, rootconf, globalconf): klass_ = root_managers.get_class(rootconf.root_type) instance = klass_(**klass_.load_config(suwrapper, rootconf, globalconf)) return instance
return self.suwrapper.add_user(username, uid, gid, self.path) def run_package_manager(self, pmname, pmargs, outputlogger=None): return self.suwrapper.run_package_manager(pmname, pmargs, root=self.path, arch=self.arch, outputlogger=outputlogger) def run_as(self, args, user, timeout=None, outputlogger=None): return self.suwrapper.run_as(args, user=user, root=self.path, arch=self.arch, timeout=timeout, outputlogger=outputlogger) def post_root_command(self): return self.suwrapper.post_root_command(root=self.path, arch=self.arch) def interactive_prepare_conf(self, username): return self.suwrapper.interactive_prepare_conf(username, root=self.path, arch=self.arch) def interactive_shell(self, username): return self.suwrapper.interactive_shell(username, root=self.path, arch=self.arch) def __getattr__(self, name): return getattr(self.suwrapper, name) su_wrappers = Registry("sudo wrapper") su_wrappers.register("jurt-root-wrapper", JurtRootWrapper) def get_su_wrapper(targetname, suconf, globalconf): klass = su_wrappers.get_class(suconf.su_type) return klass(**klass.load_config(targetname, suconf, globalconf))
def get_output_handler(self, name, trap=None): path = os.path.join(self.path, name) + ".log" fileobj = OutputLogger(path, trap=trap, outputfile=self.outputfile) logger.debug("created log file %s" % (path)) fileobj.start() self.logfiles.append(path) return fileobj def done(self): pass def logs(self): found = [] for subid, pkg in self.subpackages: for path in pkg.logfiles: found.append((subid, path)) return self.id, found def subpackage(self, subid): logger = Logger(subid, self.path, outputfile=self.outputfile) self.subpackages.append((subid, logger)) return logger loggers = Registry("logger type") loggers.register("default", LoggerFactory) def get_logger_factory(loggerconf, globalconf): instance = loggers.get_instance(loggerconf.logger_type, loggerconf, globalconf) return instance
for opt, value in opts: if opt == "--root" or opt == "--urpmi-root": absroot = os.path.abspath(value) + "/" if not absroot.startswith(absrootsdir): raise CommandValidationError, "%s should be " "based on %s" % (opt, absrootsdir) # run as root def cmd_args(self, pmtype, args): if pmtype == "urpmi": return self.urpmicmd[:] + args elif pmtype == "urpmi.addmedia": return self.addmediacmd[:] + args elif pmtype == "urpmi.update": return self.updatecmd[:] + args else: raise PackageManagerError, "invalid package manager" # run as root def allowed_pm_commands(self): return self.allowedpmcmds[:] package_managers = Registry("package manager type") package_managers.register("urpmi", URPMIPackageManager) def get_package_manager(pmconf, globalconf): klass = package_managers.get_class(pmconf.pm_type) instance = klass(**klass.load_config(pmconf, globalconf)) return instance
for arg in args: if "=" in args: name, value = arg.split("=", 1) if name in ("rpm-root", "data-dir"): absroot = os.path.abspath(value) + "/" if not absroot.startswith(absrootsdir): raise CommandValidationError, "%s should be "\ "based on %s" % (opt, absrootsdir) def cmd_args(self, pmtype, args): if pmtype == "smart.install": return self.installcmd[:] + args elif pmtype == "smart.addchannel": return self.addchannelcmd[:] + args elif pmtype == "smart.update": return self.updatecmd[:] + args else: raise PackageManagerError, "invalid package manager" def allowed_pm_commands(self): return self.allowedrpmcmds + self.allowedsmartcmds package_managers = Registry("package manager type") package_managers.register("urpmi", URPMIPackageManager) package_managers.register("smart+urpmi", SmartPackageManager) def get_package_manager(pmconf, globalconf): instance = package_managers.get_instance(pmconf.pm_type, pmconf, globalconf) return instance
if existing: name = id root = self.rootmanager.get_root_by_name(name, self.packagemanager) else: root = self.rootmanager.create_new(id, self.packagemanager, self.repos, logstore) root.mount() try: username, uid = self.build_user_info() if not existing and not latest: self.packagemanager.setup_repositories(root, self.repos, logstore) root.add_user(username, uid) root.interactive_prepare(username, uid, self.packagemanager, self.repos, logstore) homedir = self.build_user_home(username) self.packagemanager.build_prepare(root, homedir, username, uid) root.interactive_shell(username) finally: root.umount() def set_interactive(self): self.interactive = True build_types = Registry("builder type") build_types.register("default", Builder) def get_builder(rootmanager, packagemanager, buildconf, globalconf): klass_ = build_types.get_class(buildconf.build_type) instance = klass_(**klass_.load_config(rootmanager, packagemanager, buildconf, globalconf)) return instance