public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/config/
Date: Fri,  6 Jul 2012 22:19:08 +0000 (UTC)	[thread overview]
Message-ID: <1341612624.415683e88e8dedcc7b84c3691213dfca2033b93f.dywi@gentoo> (raw)

commit:     415683e88e8dedcc7b84c3691213dfca2033b93f
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jul  6 22:10:24 2012 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jul  6 22:10:24 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=415683e8

ConfigTree: fix merge_with (<dict>)

the config tree will now be merged recursively with the given dict

	modified:   roverlay/config/tree.py

---
 roverlay/config/tree.py |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/roverlay/config/tree.py b/roverlay/config/tree.py
index 426343e..dd14fb7 100644
--- a/roverlay/config/tree.py
+++ b/roverlay/config/tree.py
@@ -44,7 +44,19 @@ class ConfigTree ( object ):
 		return ConfigLoader ( self )
 	# --- end of get_loader (...) ---
 
-	def merge_with ( self, _dict, allow_empty_value=False ):
+	def merge_with ( self, _dict ):
+		def merge_dict ( pos, dict_to_merge ):
+			# this uses references where possible (no copy.[deep]copy,..)
+			for key, val in dict_to_merge.items():
+				if not key in pos:
+					pos [key] = val
+				elif isinstance ( pos [key], dict ):
+					merge_dict ( pos [key], val )
+				else:
+					pos [key] = val
+		# --- end of merge_dict (...) ---
+
+
 		# strategy = theirs
 		# unsafe operation (empty values,...)
 		if not _dict:
@@ -53,16 +65,15 @@ class ConfigTree ( object ):
 		elif not isinstance ( _dict, dict ):
 			raise Exception ( "bad usage" )
 
-		elif allow_empty_value:
-			self._config.update ( _dict )
-
-		elif sys.version_info >= ( 2, 7 ):
-			u = { k : v for ( k, v ) in _dict.items() if v or v == 0 }
-			self._config.update ( u )
 		else:
-			# FIXME remove < 2.7 statement, roverlay (probably) doesn't work
-			# with python version prior to 2.7
-			u = dict ( x for x in _dict.items() if x [1] or x [1] == 0 )
+			if sys.version_info >= ( 2, 7 ):
+				u = { k : v for ( k, v ) in _dict.items() if v or v == 0 }
+			else:
+				# FIXME remove < 2.7 statement, roverlay (probably) doesn't work
+				# with python version prior to 2.7
+				u = dict ( kv for kv in _dict.items() if kv [1] or kv [1] == 0 )
+
+			merge_dict ( self._config, u )
 
 	# --- end of merge_with (...) ---
 



             reply	other threads:[~2012-07-06 22:19 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06 22:19 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-30  5:31 [gentoo-commits] proj/R_overlay:master commit in: roverlay/config/ Benda XU
2018-05-28  8:41 Benda XU
2014-08-23 19:03 André Erdmann
2014-08-23 19:03 André Erdmann
2014-04-01 16:38 André Erdmann
2014-04-01 16:38 André Erdmann
2014-04-01 16:38 André Erdmann
2014-01-26 19:06 André Erdmann
2013-09-13 15:10 André Erdmann
2013-09-11 11:14 André Erdmann
2013-09-11 10:30 André Erdmann
2013-09-11 10:27 André Erdmann
2013-09-11 10:27 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-06 17:27 André Erdmann
2013-09-04 10:16 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-12  8:18 André Erdmann
2013-08-09 15:27 André Erdmann
2013-08-09 15:27 André Erdmann
2013-08-06 10:58 André Erdmann
2013-08-05 11:44 André Erdmann
2013-08-02 13:39 André Erdmann
2013-07-30 18:40 André Erdmann
2013-07-29 14:56 André Erdmann
2013-07-24 17:45 André Erdmann
2013-07-16 16:36 André Erdmann
2013-07-12 13:57 André Erdmann
2013-07-12 13:57 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-12 13:57 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-11 16:29 André Erdmann
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-10 16:16 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-30 15:58 André Erdmann
2013-06-19 18:59 André Erdmann
2013-06-13 16:34 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-18 14:12 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-04 21:06 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-09 20:45 André Erdmann
2013-01-28 23:54 André Erdmann
2013-01-28 23:54 André Erdmann
2012-08-09  9:26 André Erdmann
2012-08-08 23:46 André Erdmann
2012-08-02 15:14 André Erdmann
2012-08-01 21:10 André Erdmann
2012-07-11 18:43 André Erdmann
2012-07-06 22:19 André Erdmann
2012-07-05 16:00 André Erdmann
2012-07-03 17:48 André Erdmann
2012-06-29 22:48 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-25 18:19 André Erdmann
2012-06-25 18:19 André Erdmann

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=1341612624.415683e88e8dedcc7b84c3691213dfca2033b93f.dywi@gentoo \
    --to=dywi@mailerd.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-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