public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Brian Dolbec <dolsen@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH v3 1/2] dblink: case insensitive support for bug #524236
Date: Mon, 17 Nov 2014 14:09:06 -0800	[thread overview]
Message-ID: <20141117140906.7187e794.dolsen@gentoo.org> (raw)
In-Reply-To: <1416256178-18009-1-git-send-email-zmedico@gentoo.org>

On Mon, 17 Nov 2014 12:29:37 -0800
Zac Medico <zmedico@gentoo.org> wrote:

> This adds a dblink._contents attribute with methods that provide
> an interface for contents operations with "implicit" case handling.
> The new methods are implemented in a separate
> ContentsCaseSensitivityManager class, in order to avoid adding more
> bloat to vartree.py.
> 
> X-Gentoo-Bug: 524236
> X-Gentoo-Url: https://bugs.gentoo.org/show_bug.cgi?id=524236
> ---
...
> +class ContentsCaseSensitivityManager(object):
> +	"""
> +	Implicitly handles case transformations that are needed for
> +	case-insensitive support.
> +	"""
> +
> +	def __init__(self, db):
> +		"""
> +		@param db: A dblink instance
> +		@type db: vartree.dblink
> +		"""


Thank you :)  looks much better now ;)

Both 1/2, 2/2 look good now.  Clear to merge :)



> +		self.getcontents = db.getcontents
> +
> +		if "case-insensitive-fs" in db.settings.features:
> +			self.unmap_key =
> self._unmap_key_case_insensitive
> +			self.contains =
> self._contains_case_insensitive
> +			self.keys = self._keys_case_insensitive
> +
> +		self._contents_insensitive = None
> +		self._reverse_key_map = None
> +
> +	def clear_cache(self):
> +		"""
> +		Clear all cached contents data.
> +		"""
> +		self._contents_insensitive = None
> +		self._reverse_key_map = None
> +
> +	def keys(self):
> +		"""
> +		Iterate over all contents keys, which are
> transformed to
> +		lowercase when appropriate, for use in
> case-insensitive
> +		comparisons.
> +		@rtype: iterator
> +		@return: An iterator over all the contents keys
> +		"""
> +		return iter(self.getcontents())
> +
> +	def contains(self, key):
> +		"""
> +		Check if the given key is contained in the contents,
> using
> +		case-insensitive comparison when appropriate.
> +		@param key: A filesystem path (including ROOT and
> EPREFIX)
> +		@type key: str
> +		@rtype: bool
> +		@return: True if the given key is contained in the
> contents,
> +			False otherwise
> +		"""
> +		return key in self.getcontents()
> +
> +	def unmap_key(self, key):
> +		"""
> +		Map a key (from the keys method) back to its
> case-preserved
> +		form.
> +		@param key: A filesystem path (including ROOT and
> EPREFIX)
> +		@type key: str
> +		@rtype: str
> +		@return: The case-preserved form of key
> +		"""
> +		return key
> +
> +	def _case_insensitive_init(self):
> +		"""
> +		Initialize data structures for case-insensitive
> support.
> +		"""
> +		self._contents_insensitive = dict(
> +			(k.lower(), v) for k, v in
> self.getcontents().items())
> +		self._reverse_key_map = dict(
> +			(k.lower(), k) for k in self.getcontents())
> +
> +	def _keys_case_insensitive(self):
> +		if self._contents_insensitive is None:
> +			self._case_insensitive_init()
> +		return iter(self._contents_insensitive)
> +
> +	_keys_case_insensitive.__doc__ = keys.__doc__
> +
> +	def _contains_case_insensitive(self, key):
> +		if self._contents_insensitive is None:
> +			self._case_insensitive_init()
> +		return key.lower() in self._contents_insensitive
> +
> +	_contains_case_insensitive.__doc__ = contains.__doc__
> +
> +	def _unmap_key_case_insensitive(self, key):
> +		if self._reverse_key_map is None:
> +			self._case_insensitive_init()
> +		return self._reverse_key_map[key]
> +
> +	_unmap_key_case_insensitive.__doc__ = unmap_key.__doc__
> diff --git a/pym/portage/dbapi/vartree.py
> b/pym/portage/dbapi/vartree.py index 8b06f4c..81059b1 100644
> --- a/pym/portage/dbapi/vartree.py
> +++ b/pym/portage/dbapi/vartree.py
> @@ -69,6 +69,7 @@ from _emerge.EbuildPhase import EbuildPhase
>  from _emerge.emergelog import emergelog
>  from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
>  from _emerge.SpawnProcess import SpawnProcess
> +from ._ContentsCaseSensitivityManager import
> ContentsCaseSensitivityManager 
>  import errno
>  import fnmatch
> @@ -1525,6 +1526,7 @@ class dblink(object):
>  		# When necessary, this attribute is modified for
>  		# compliance with RESTRICT=preserve-libs.
>  		self._preserve_libs = "preserve-libs" in
> mysettings.features
> +		self._contents = ContentsCaseSensitivityManager(self)
>  
>  	def __hash__(self):
>  		return hash(self._hash_key)
> @@ -1612,6 +1614,7 @@ class dblink(object):
>  		self.contentscache = None
>  		self._contents_inodes = None
>  		self._contents_basenames = None
> +		self._contents.clear_cache()
>  
>  	def getcontents(self):
>  		"""



-- 
Brian Dolbec <dolsen>



      parent reply	other threads:[~2014-11-17 22:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13  1:22 [gentoo-portage-dev] [PATCH] FEATURES=case-insensitive-fs for bug #524236 Zac Medico
2014-11-13 10:29 ` Alexander Berntsen
2014-11-13 17:58   ` Zac Medico
2014-11-16 10:41     ` [gentoo-portage-dev] [PATCH 1/2] dblink: case insensitive support " Zac Medico
2014-11-16 10:41       ` [gentoo-portage-dev] [PATCH 2/2] FEATURES=case-insensitive-fs " Zac Medico
2014-11-16 18:11       ` [gentoo-portage-dev] [PATCH 1/2] dblink: case insensitive support " Brian Dolbec
2014-11-17  1:29         ` [gentoo-portage-dev] [PATCH v2 " Zac Medico
2014-11-17  1:29           ` [gentoo-portage-dev] [PATCH v2 2/2] FEATURES=case-insensitive-fs " Zac Medico
2014-11-17  4:58           ` [gentoo-portage-dev] [PATCH v2 1/2] dblink: case insensitive support " Brian Dolbec
2014-11-17 20:29             ` [gentoo-portage-dev] [PATCH v3 " Zac Medico
2014-11-17 20:29               ` [gentoo-portage-dev] [PATCH v3 2/2] FEATURES=case-insensitive-fs " Zac Medico
2014-11-17 22:09               ` Brian Dolbec [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141117140906.7187e794.dolsen@gentoo.org \
    --to=dolsen@gentoo.org \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox