From c54a920d60415f19b3a42796193d87b6b21c84a1 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 12 Jul 2009 20:45:53 +0000 Subject: Remove leading slash from appropriate paths inside portage.const, so that lstrip(os.sep) is not needed for os.path.join() calls. Thanks to Fabian Groffen for this patch. svn path=/main/trunk/; revision=13821 --- pym/_emerge/actions.py | 9 +++++---- pym/portage/__init__.py | 31 +++++++++++++++---------------- pym/portage/const.py | 6 +++--- pym/portage/output.py | 8 +++++++- pym/portage/sets/__init__.py | 2 +- pym/portage/sets/files.py | 7 +++++-- pym/portage/update.py | 3 +-- 7 files changed, 37 insertions(+), 29 deletions(-) (limited to 'pym') diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index f7ec0a15b..0a48271c5 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -2203,12 +2203,13 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): chk_updated_cfg_files("/", settings.get("CONFIG_PROTECT","").split()) if myaction != "metadata": - if os.access(portage.USER_CONFIG_PATH + "/bin/post_sync", os.X_OK): + postsync = os.path.join(settings["PORTAGE_CONFIGROOT"], + portage.USER_CONFIG_PATH, "bin", "post_sync") + if os.access(postsync, os.X_OK): retval = portage.process.spawn( - [os.path.join(portage.USER_CONFIG_PATH, "bin", "post_sync"), - dosyncuri], env=settings.environ()) + [postsync, dosyncuri], env=settings.environ()) if retval != os.EX_OK: - print red(" * ")+bold("spawn failed of "+ portage.USER_CONFIG_PATH + "/bin/post_sync") + print red(" * ") + bold("spawn failed of " + postsync) if(mybestpv != mypvs) and not "--quiet" in myopts: print diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 5b74e1797..4dc62fa5a 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -1309,7 +1309,7 @@ class config(object): if not config_profile_path: config_profile_path = \ - os.path.join(config_root, PROFILE_PATH.lstrip(os.path.sep)) + os.path.join(config_root, PROFILE_PATH) if os.path.isdir(config_profile_path): self.profile_path = config_profile_path else: @@ -1325,7 +1325,7 @@ class config(object): self.module_priority = ["user","default"] self.modules = {} self.modules["user"] = getconfig( - os.path.join(config_root, MODULES_FILE_PATH.lstrip(os.path.sep))) + os.path.join(config_root, MODULES_FILE_PATH)) if self.modules["user"] is None: self.modules["user"] = {} self.modules["default"] = { @@ -1389,7 +1389,7 @@ class config(object): self.profiles = [] if local_config and self.profiles: custom_prof = os.path.join( - config_root, CUSTOM_PROFILE_PATH.lstrip(os.path.sep)) + config_root, CUSTOM_PROFILE_PATH) if os.path.exists(custom_prof): self.user_profile_dir = custom_prof self.profiles.append(custom_prof) @@ -1465,7 +1465,7 @@ class config(object): del rawpuseforce make_conf = getconfig( - os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)), + os.path.join(config_root, MAKE_CONF_FILE), tolerant=tolerant, allow_sourcing=True) if make_conf is None: make_conf = {} @@ -1561,7 +1561,7 @@ class config(object): self.configdict["defaults"]=self.configlist[-1] self.mygcfg = getconfig( - os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)), + os.path.join(config_root, MAKE_CONF_FILE), tolerant=tolerant, allow_sourcing=True, expand=expand_map) if self.mygcfg is None: self.mygcfg = {} @@ -1610,8 +1610,7 @@ class config(object): self.pkeywordsdict = {} self._plicensedict = {} self.punmaskdict = {} - abs_user_config = os.path.join(config_root, - USER_CONFIG_PATH.lstrip(os.path.sep)) + abs_user_config = os.path.join(config_root, USER_CONFIG_PATH) # locations for "categories" and "arch.list" files locations = [os.path.join(self["PORTDIR"], "profiles")] @@ -1838,7 +1837,7 @@ class config(object): ("sandbox" in self.features or "usersandbox" in self.features): if self.profile_path is not None and \ os.path.realpath(self.profile_path) == \ - os.path.realpath(PROFILE_PATH): + os.path.realpath(os.path.join(config_root, PROFILE_PATH)): """ Don't show this warning when running repoman and the sandbox feature came from a profile that doesn't belong to the user.""" @@ -1960,7 +1959,7 @@ class config(object): noiselevel=-1) abs_profile_path = os.path.join(self["PORTAGE_CONFIGROOT"], - PROFILE_PATH.lstrip(os.path.sep)) + PROFILE_PATH) if not self.profile_path or (not os.path.islink(abs_profile_path) and \ not os.path.exists(os.path.join(abs_profile_path, "parent")) and \ os.path.exists(os.path.join(self["PORTDIR"], "profiles"))): @@ -1970,7 +1969,7 @@ class config(object): writemsg("!!! (You can safely ignore this message when syncing. It's harmless.)\n\n\n") abs_user_virtuals = os.path.join(self["PORTAGE_CONFIGROOT"], - USER_VIRTUALS_FILE.lstrip(os.path.sep)) + USER_VIRTUALS_FILE) if os.path.exists(abs_user_virtuals): writemsg("\n!!! /etc/portage/virtuals is deprecated in favor of\n") writemsg("!!! /etc/portage/profile/virtuals. Please move it to\n") @@ -3781,7 +3780,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", check_config_instance(mysettings) custommirrors = grabdict(os.path.join(mysettings["PORTAGE_CONFIGROOT"], - CUSTOM_MIRRORS_FILE.lstrip(os.path.sep)), recursive=1) + CUSTOM_MIRRORS_FILE), recursive=1) mymirrors=[] @@ -5430,7 +5429,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m mysettings["T"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "temp") mysettings["PORTAGE_BASHRC"] = os.path.join( - mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_FILE.lstrip(os.path.sep)) + mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_FILE) mysettings["EBUILD_EXIT_STATUS_FILE"] = os.path.join( mysettings["PORTAGE_BUILDDIR"], ".exit_status") @@ -7527,7 +7526,7 @@ def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_lo if os.path.isdir(profdir): locations.append(profdir) locations.append(os.path.join(settings["PORTAGE_CONFIGROOT"], - USER_CONFIG_PATH.lstrip(os.path.sep))) + USER_CONFIG_PATH)) locations.reverse() pmasklists = [(x, grablines(os.path.join(x, "package.mask"), recursive=1)) for x in locations] @@ -8404,9 +8403,9 @@ def init_legacy_globals(): selinux_enabled = settings.selinux_enabled() thirdpartymirrors = settings.thirdpartymirrors() usedefaults = settings.use_defs - profiledir = None - if os.path.isdir(PROFILE_PATH): - profiledir = PROFILE_PATH + profiledir = os.path.join(settings["PORTAGE_CONFIGROOT"], PROFILE_PATH) + if not os.path.isdir(profiledir): + profiledir = None def flushmtimedb(record): writemsg("portage.flushmtimedb() is DEPRECATED\n") # ======================================================================== diff --git a/pym/portage/const.py b/pym/portage/const.py index 155279c05..1b838e62f 100644 --- a/pym/portage/const.py +++ b/pym/portage/const.py @@ -15,7 +15,7 @@ PRIVATE_PATH = "var/lib/portage" CACHE_PATH = "/var/cache/edb" DEPCACHE_PATH = CACHE_PATH+"/dep" -USER_CONFIG_PATH = "/etc/portage" +USER_CONFIG_PATH = "etc/portage" MODULES_FILE_PATH = USER_CONFIG_PATH+"/modules" CUSTOM_PROFILE_PATH = USER_CONFIG_PATH+"/profile" GLOBAL_CONFIG_PATH = "/usr/share/portage/config" @@ -26,7 +26,7 @@ PORTAGE_BIN_PATH = PORTAGE_BASE_PATH+"/bin" PORTAGE_PYM_PATH = PORTAGE_BASE_PATH+"/pym" PORTAGE_PACKAGE_ATOM = "sys-apps/portage" NEWS_LIB_PATH = "/var/lib/gentoo" -PROFILE_PATH = "/etc/make.profile" +PROFILE_PATH = "etc/make.profile" LOCALE_DATA_PATH = PORTAGE_BASE_PATH+"/locale" EBUILD_SH_BINARY = PORTAGE_BIN_PATH+"/ebuild.sh" @@ -38,7 +38,7 @@ MOVE_BINARY = "/bin/mv" PRELINK_BINARY = "/usr/sbin/prelink" WORLD_FILE = PRIVATE_PATH + "/world" -MAKE_CONF_FILE = "/etc/make.conf" +MAKE_CONF_FILE = "etc/make.conf" MAKE_DEFAULTS_FILE = PROFILE_PATH + "/make.defaults" DEPRECATED_PROFILE_FILE = PROFILE_PATH+"/deprecated" USER_VIRTUALS_FILE = USER_CONFIG_PATH+"/virtuals" diff --git a/pym/portage/output.py b/pym/portage/output.py index ee792280a..4c533c427 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -150,7 +150,13 @@ def _parse_color_map(onerror=None): @rtype: dict @return: a dictionary mapping color classes to color codes """ - myfile = COLOR_MAP_FILE + # FIXME: use config_root iso / (breaks Prefix) + # We can use ObjectProxy to implement lazy initialization of + # codes and _styles, and add an init(config_root="/") function + # that can be called in order adjust the location that color.map + # is read from. + global codes, _styles + myfile = os.path.join('/', COLOR_MAP_FILE) ansi_code_pattern = re.compile("^[0-9;]*m$") quotes = '\'"' def strip_quotes(token): diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py index 80aa608f6..2d85007ec 100644 --- a/pym/portage/sets/__init__.py +++ b/pym/portage/sets/__init__.py @@ -192,7 +192,7 @@ def load_default_config(settings, trees): setconfigpaths.append(os.path.join(settings["PORTDIR"], "sets.conf")) setconfigpaths += [os.path.join(x, "sets.conf") for x in settings["PORTDIR_OVERLAY"].split()] setconfigpaths.append(os.path.join(settings["PORTAGE_CONFIGROOT"], - USER_CONFIG_PATH.lstrip(os.path.sep), "sets.conf")) + USER_CONFIG_PATH, "sets.conf")) return SetConfig(setconfigpaths, settings, trees) # adhoc test code diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index 9ebff10f2..aa4d6aac9 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -111,7 +111,9 @@ class StaticFileSet(EditablePackageSet): def multiBuilder(self, options, settings, trees): rValue = {} - directory = options.get("directory", os.path.join(settings["PORTAGE_CONFIGROOT"], USER_CONFIG_PATH.lstrip(os.sep), "sets")) + directory = options.get("directory", + os.path.join(settings["PORTAGE_CONFIGROOT"], + USER_CONFIG_PATH, "sets")) name_pattern = options.get("name_pattern", "${name}") if not "$name" in name_pattern and not "${name}" in name_pattern: raise SetConfigError(_("name_pattern doesn't include ${name} placeholder")) @@ -163,7 +165,8 @@ class ConfigFileSet(PackageSet): def multiBuilder(self, options, settings, trees): rValue = {} - directory = options.get("directory", os.path.join(settings["PORTAGE_CONFIGROOT"], USER_CONFIG_PATH.lstrip(os.sep))) + directory = options.get("directory", + os.path.join(settings["PORTAGE_CONFIGROOT"], USER_CONFIG_PATH)) name_pattern = options.get("name_pattern", "sets/package_$suffix") if not "$suffix" in name_pattern and not "${suffix}" in name_pattern: raise SetConfigError(_("name_pattern doesn't include $suffix placeholder")) diff --git a/pym/portage/update.py b/pym/portage/update.py index 70ff68664..c7001803a 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -152,8 +152,7 @@ def update_config_files(config_root, protect, protect_mask, update_iter): myxfiles = ["package.mask", "package.unmask", \ "package.keywords", "package.use"] myxfiles += [os.path.join("profile", x) for x in myxfiles] - abs_user_config = os.path.join(config_root, - USER_CONFIG_PATH.lstrip(os.path.sep)) + abs_user_config = os.path.join(config_root, USER_CONFIG_PATH) recursivefiles = [] for x in myxfiles: config_file = os.path.join(abs_user_config, x) -- cgit v1.2.3-1-g7c22