From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 52EFA1381F3 for ; Thu, 19 Sep 2013 15:00:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0E410E0AD9; Thu, 19 Sep 2013 15:00:39 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 91B43E0AD2 for ; Thu, 19 Sep 2013 15:00:38 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 98CD633E958 for ; Thu, 19 Sep 2013 15:00:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 33AD9E530A for ; Thu, 19 Sep 2013 15:00:36 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1379602763.ff58bf49699682c31786b05072e7fe65bb3bb50e.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/fsutil.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: ff58bf49699682c31786b05072e7fe65bb3bb50e X-VCS-Branch: master Date: Thu, 19 Sep 2013 15:00:36 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: a03a9726-e667-47e1-9f76-f595e81dee7f X-Archives-Hash: d1dc150ba4c9e429ef5a8fa1d0dcbbab commit: ff58bf49699682c31786b05072e7fe65bb3bb50e Author: André Erdmann mailerd de> AuthorDate: Thu Sep 19 14:59:23 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Thu Sep 19 14:59:23 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=ff58bf49 fsutil: accept file_key function --- roverlay/fsutil.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/roverlay/fsutil.py b/roverlay/fsutil.py index b8a69ab..7fede96 100644 --- a/roverlay/fsutil.py +++ b/roverlay/fsutil.py @@ -44,12 +44,14 @@ def walk_up ( dirpath, topdown=False, max_iter=None ): def get_fs_dict ( initial_root, create_item=None, dict_cls=dict, dirname_filter=None, filename_filter=None, - include_root=False, prune_empty=False, + include_root=False, prune_empty=False, file_key=None, ): # http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/ fsdict = dict_cls() my_root = os.path.abspath ( initial_root ) + get_file_key = ( lambda x: x ) if file_key is None else file_key + dictpath_begin = ( 1 + ( my_root.rfind ( os.sep ) if include_root else len ( my_root ) ) ) @@ -69,11 +71,13 @@ def get_fs_dict ( parent = functools.reduce ( dict_cls.get, dictpath[:-1], fsdict ) if create_item is None: - parent [dictpath[-1]] = dict_cls.fromkeys ( filenames ) + parent [dictpath[-1]] = dict_cls.fromkeys ( + map ( get_file_key, filenames ) + ) else: parent [dictpath[-1]] = dict_cls ( ( - fname, + get_file_key ( fname ), create_item ( ( root + os.sep + fname ), fname, root ) ) for fname in filenames