public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
  2013-06-20 23:40 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-06-22 15:24 ` André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-06-22 15:24 UTC (permalink / raw
  To: gentoo-commits

commit:     b703c26878c27f803d22d6a6b80bbaf2464c3dfe
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jun 20 23:26:56 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jun 20 23:26:56 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=b703c268

roverlay/util: fix synop(False)

---
 roverlay/util/common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index d8ad4b7..6deee14 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -147,7 +147,7 @@ def sysnop ( nop_returns_success=True, format_str=None, old_formatting=False ):
    if nop_returns_success:
       candidates = ( '/bin/true', '/bin/echo' )
    else:
-      candidates = ( '/bin/false' )
+      candidates = ( '/bin/false', )
 
    for c in candidates:
       if os.path.isfile ( c ):


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-07-12 13:57 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-07-12 13:57 UTC (permalink / raw
  To: gentoo-commits

commit:     261ca9169d73c7ae3799b7c3b0506457af6fe3f2
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jul 12 13:43:08 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jul 12 13:43:08 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=261ca916

roverlay/util/mapreader: fix log_unparseable

---
 roverlay/util/mapreader.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/roverlay/util/mapreader.py b/roverlay/util/mapreader.py
index c2cce1f..19d4129 100644
--- a/roverlay/util/mapreader.py
+++ b/roverlay/util/mapreader.py
@@ -126,7 +126,7 @@ class MapFileParser ( object ):
       pass
    # --- end of read_lines_begin (...) ---
 
-   def read_lines ( self, lines ):
+   def read_lines ( self, lines, src=None ):
       self.read_lines_begin()
       self.stop_reading = False
       ret = True
@@ -134,7 +134,9 @@ class MapFileParser ( object ):
          if not self.add ( line ):
             ret = False
             self.log_unparseable (
-               "{f}: cannot parse line {n:d}".format ( f=filepath, n=lino+1 )
+               "{f}: cannot parse line {n:d}: {txt!r}".format (
+                  f=( src or "<input>" ), n=lino+1, txt=line
+               )
             )
 
          if self.stop_reading:
@@ -148,11 +150,11 @@ class MapFileParser ( object ):
       try:
          if handle_compressed:
             ret = self.read_lines (
-               roverlay.util.fileio.read_text_file ( filepath )
+               roverlay.util.fileio.read_text_file ( filepath ), filepath
             )
          else:
             with open ( filepath, 'rt' ) as FH:
-               ret = self.read_lines ( FH.readlines() )
+               ret = self.read_lines ( FH.readlines(), filepath )
       except IOError:
          self.logger.error (
             "Could not read file {!r}.".format ( filepath )


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
  2013-07-18 19:25 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-07-23  7:51 ` André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-07-23  7:51 UTC (permalink / raw
  To: gentoo-commits

commit:     316ff643c54198004c14dd579863dedc80c99112
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul 18 19:21:27 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul 18 19:21:27 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=316ff643

roverlay/util/mapread: has_context()

---
 roverlay/util/mapreader.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/roverlay/util/mapreader.py b/roverlay/util/mapreader.py
index 19d4129..5333bd9 100644
--- a/roverlay/util/mapreader.py
+++ b/roverlay/util/mapreader.py
@@ -43,6 +43,13 @@ class MapFileParser ( object ):
       self._items       = list()
    # --- end of zap (...) ---
 
+   def has_context ( self ):
+      return (
+         self._deptype_once != deptype.NONE
+         or self._next is not None
+      )
+   # --- end of has_context (...) ---
+
    def make_result ( self ):
       return self._items
    # --- end of make_result (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-07-23 14:57 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-07-23 14:57 UTC (permalink / raw
  To: gentoo-commits

commit:     eb054c34b1af6b908d4df808742113d42e218d12
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jul 23 09:31:34 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jul 23 09:31:34 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=eb054c34

roverlay/util/common: try_unlink()

Remove a file if it exists and ignore errors caused by non-existence.

---
 roverlay/util/common.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index a2c155a..f27593a 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -8,9 +8,10 @@
 
 __all__= [
    'dodir', 'for_all_files', 'get_dict_hash', 'keepenv', 'priosort', 'sysnop',
-   'getsize', 'is_vcs_dir', 'headtail'
+   'getsize', 'is_vcs_dir', 'headtail', 'try_unlink',
 ]
 
+import errno
 import os
 import sys
 import logging
@@ -26,6 +27,21 @@ def headtail ( iterable ):
    return ( iterable[0], iterable[1:] )
 # --- end of headtail #py2 (...) ---
 
+def try_unlink ( fspath ):
+   """Tries to remove a file. Does not fail if the file did not exist.
+
+   arguments:
+   * fspath --
+   """
+   try:
+      os.unlink ( fspath )
+   except OSError as oserr:
+      if oserr.errno == errno.ENOENT:
+         pass
+      else:
+         raise
+# --- end of try_unlink (...) ---
+
 def for_all_files (
    files_or_dirs, func,
    args=(), kwargs={}, file_filter=None, ignore_missing=False


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
  2013-07-23 14:57 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-07-23 14:57 ` André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-07-23 14:57 UTC (permalink / raw
  To: gentoo-commits

commit:     db75bfc7ca865feff6421995ed6baf7638a437d9
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jul 23 13:31:02 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jul 23 13:31:02 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=db75bfc7

roverlay/util, try_unlink(): return true/false

---
 roverlay/util/common.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index f27593a..f3126ad 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -30,6 +30,8 @@ def headtail ( iterable ):
 def try_unlink ( fspath ):
    """Tries to remove a file. Does not fail if the file did not exist.
 
+   Returns: True if a file has been removed, else False.
+
    arguments:
    * fspath --
    """
@@ -37,9 +39,11 @@ def try_unlink ( fspath ):
       os.unlink ( fspath )
    except OSError as oserr:
       if oserr.errno == errno.ENOENT:
-         pass
+         return False
       else:
          raise
+   else:
+      return True
 # --- end of try_unlink (...) ---
 
 def for_all_files (


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-07-29 14:56 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-07-29 14:56 UTC (permalink / raw
  To: gentoo-commits

commit:     bd4d15d2b69ba58903fa27623de0308d7aea075b
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Jul 29 14:51:21 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Jul 29 14:51:21 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=bd4d15d2

roverlay/util: add dodir_for_file to __all__

---
 roverlay/util/common.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index f3126ad..6053015 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -7,7 +7,8 @@
 """provides utility functions commonly used"""
 
 __all__= [
-   'dodir', 'for_all_files', 'get_dict_hash', 'keepenv', 'priosort', 'sysnop',
+   'dodir', 'dodir_for_file',
+   'for_all_files', 'get_dict_hash', 'keepenv', 'priosort', 'sysnop',
    'getsize', 'is_vcs_dir', 'headtail', 'try_unlink',
 ]
 


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-07-30 18:40 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-07-30 18:40 UTC (permalink / raw
  To: gentoo-commits

commit:     f478491cb7bada1a009c63b02f40103149fc0abd
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jul 30 16:01:52 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jul 30 16:01:52 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=f478491c

roverlay/util: objects.py

---
 roverlay/util/objects.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
new file mode 100644
index 0000000..dd19046
--- /dev/null
+++ b/roverlay/util/objects.py
@@ -0,0 +1,69 @@
+# R overlay --
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+class MethodNotImplementedError ( NotImplementedError ):
+   def __init__ ( self, obj, method, msg=None ):
+      if isinstance ( obj, str ):
+         obj_name = obj
+      elif hasattr ( obj, '__class__' ):
+         obj_name = obj.__class__.__name__
+      elif hasattr ( obj, '__name__' ):
+         obj_name = obj.__name__
+      else:
+         obj_name = repr ( obj )
+
+      if isinstance ( method, str ):
+         method_name = method
+      elif hasattr ( method, '__name__' ):
+         method_name = method.__name__
+      else:
+         method_name = repr ( method )
+
+      method_str = "{}.{}()".format ( obj_name, method_name )
+
+      if msg:
+         super ( MethodNotImplementedError, self ).__init__ (
+            method_str + ': ' + str ( msg )
+         )
+      else:
+         super ( MethodNotImplementedError, self ).__init__ ( method_str )
+   # --- end of __init__ (...) ---
+
+# --- end of MethodNotImplementedError ---
+
+class MethodNotImplemented ( MethodNotImplementedError ):
+   # compat class
+   pass
+# --- end of MethodNotImplemented ---
+
+class AbstractMethodError ( MethodNotImplementedError ):
+   def __init__ ( self, obj, method ):
+      super ( AbstractMethodError, self ).__init__ (
+         obj, method, "has to be implemented by derived classes"
+      )
+
+# --- end of AbstractMethodError ---
+
+def _get_exception_wrapper ( err_cls, func ):
+   def wrapped ( obj, *args, **kwargs ):
+      raise err_cls ( obj, func )
+   # --- end of wrapped (...) ---
+
+   if func is not None:
+      wrapped.__name__ = func.__name__
+      wrapped.__doc__  = func.__doc__
+      wrapped.__dict__.update ( func.__dict__ )
+   return wrapped
+
+# --- end of _get_exception_wrapper (...) ---
+
+def abstractmethod ( func=None ):
+   return _get_exception_wrapper ( AbstractMethodError, func )
+# --- end of abstractmethod (...) ---
+
+def not_implemented ( func=None ):
+   return _get_exception_wrapper ( MethodNotImplementedError, func )
+# --- end of not_implemented (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-01 12:44 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-01 12:44 UTC (permalink / raw
  To: gentoo-commits

commit:     8a86ced14011b1c5581566551847efe21e5df932
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug  1 12:31:14 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug  1 12:31:14 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=8a86ced1

roverlay/util/hashpool: Hashjob -> HashJob

---
 roverlay/util/hashpool.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/roverlay/util/hashpool.py b/roverlay/util/hashpool.py
index 921a968..c3e1a79 100644
--- a/roverlay/util/hashpool.py
+++ b/roverlay/util/hashpool.py
@@ -24,12 +24,16 @@ def _calculate_hashes ( hash_job, hashes ):
    )
 # --- end of _calculate_hashes (...) ---
 
-class Hashjob ( object ):
+
+class HashJob ( object ):
    def __init__ ( self, filepath, hashdict=None ):
+      super ( HashJob ).__init__()
       self.filepath = filepath
       self.hashdict = dict() if hashdict is None else hashdict
    # --- end of __init__ (...) ---
 
+# --- end of HashJob ---
+
 
 class HashPool ( object ):
    def __init__ ( self, hashes, max_workers ):
@@ -40,7 +44,7 @@ class HashPool ( object ):
    # --- end of __init__ (...) ---
 
    def add ( self, backref, filepath, hashdict=None ):
-      self._jobs [backref] = Hashjob ( filepath, hashdict )
+      self._jobs [backref] = HashJob ( filepath, hashdict )
    # --- end of add (...) ---
 
    def run ( self ):
@@ -64,3 +68,5 @@ class HashPool ( object ):
    def get ( self, backref ):
       return self._jobs [backref].hashdict
    # --- end of get (...) ---
+
+# --- end of HashPool ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-13  8:56 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-13  8:56 UTC (permalink / raw
  To: gentoo-commits

commit:     f3c5f50a1323d18d09672d4b7a855287c995d9d7
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Aug 13 08:37:26 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Aug 13 08:37:26 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=f3c5f50a

roveray/util: keepenv_v()

keepenv_v(args) is the fixed-arg form of keepenv(*args)

---
 roverlay/util/common.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index 8449b2c..5407508 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -8,8 +8,8 @@
 
 __all__= [
    'dodir', 'dodir_for_file',
-   'for_all_files', 'get_dict_hash', 'keepenv', 'priosort', 'sysnop',
-   'getsize', 'is_vcs_dir', 'headtail', 'try_unlink',
+   'for_all_files', 'get_dict_hash', 'keepenv', 'keepenv_v',
+   'priosort', 'sysnop', 'getsize', 'is_vcs_dir', 'headtail', 'try_unlink',
 ]
 
 import errno
@@ -116,7 +116,7 @@ def get_dict_hash ( kwargs ):
    )
 # --- end of get_dict_hash (...) ---
 
-def keepenv ( *to_keep ):
+def keepenv_v ( to_keep ):
    """Selectively imports os.environ.
 
    arguments:
@@ -158,6 +158,10 @@ def keepenv ( *to_keep ):
 
    # -- for
    return myenv
+# --- end of keepenv_v (...) ---
+
+def keepenv ( *to_keep ):
+   return keepenv_v ( to_keep )
 # --- end of keepenv (...) ---
 
 def sysnop ( nop_returns_success=True, format_str=None, old_formatting=False ):


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-16  6:44 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-16  6:44 UTC (permalink / raw
  To: gentoo-commits

commit:     7346994e0bf44e59dff13bab42edc90a60ef77d9
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 16 06:43:13 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 16 06:43:13 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=7346994e

roverlay/util/hashpool: add missing 'import sys'

---
 roverlay/util/hashpool.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/roverlay/util/hashpool.py b/roverlay/util/hashpool.py
index c3e1a79..70d3d55 100644
--- a/roverlay/util/hashpool.py
+++ b/roverlay/util/hashpool.py
@@ -7,10 +7,12 @@
 try:
    import concurrent.futures
 except ImportError:
+   import sys
    sys.stderr.write (
       '!!! concurrent.futures is not available.\n'
       '    Falling back to single-threaded variants.\n\n'
    )
+   del sys
    HAVE_CONCURRENT_FUTURES = False
 else:
    HAVE_CONCURRENT_FUTURES = True


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-22  9:01 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-22  9:01 UTC (permalink / raw
  To: gentoo-commits

commit:     2f5e40896c821d2a52c3ef53163a953217b0a366
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug 22 08:50:28 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug 22 08:50:28 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=2f5e4089

hashpool: fixup

* run properly in no-thread/mutliproc mode
* check if thread/proc executor has been aborted
* HashFunction can now be pickled
* run_as_completed() function for getting results as soon as they're available

---
 roverlay/util/hashpool.py | 103 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 84 insertions(+), 19 deletions(-)

diff --git a/roverlay/util/hashpool.py b/roverlay/util/hashpool.py
index 70d3d55..61d8336 100644
--- a/roverlay/util/hashpool.py
+++ b/roverlay/util/hashpool.py
@@ -5,6 +5,12 @@
 # either version 2 of the License, or (at your option) any later version.
 
 try:
+   import copyreg
+except ImportError:
+   # python 2
+   import copy_reg as copyreg
+
+try:
    import concurrent.futures
 except ImportError:
    import sys
@@ -20,11 +26,31 @@ else:
 
 import roverlay.digest
 
-def _calculate_hashes ( hash_job, hashes ):
-   hash_job.hashdict.update (
-      roverlay.digest.multihash_file ( hash_job.filepath, hashes )
-   )
-# --- end of _calculate_hashes (...) ---
+class HashFunction ( object ):
+
+   def __init__ ( self, hashes ):
+      super ( HashFunction, self ).__init__()
+      self.hashes = frozenset ( hashes )
+   # --- end of __init__ (...) ---
+
+   def multihash_file ( self, filepath ):
+      return roverlay.digest.multihash_file ( filepath, self.hashes )
+   # --- end of multihash_file (...) ---
+
+   def calculate ( self, hash_job ):
+      hash_job.hashdict.update ( self.multihash_file ( hash_job.filepath ) )
+      return hash_job
+   # --- end of calculate (...) ---
+
+   __call__ = calculate
+
+   def pack ( self ):
+      return ( self.__class__, ( self.hashes, ) )
+   # --- end of pickle (...) ---
+
+# --- end of HashFunction ---
+
+copyreg.pickle ( HashFunction, HashFunction.pack )
 
 
 class HashJob ( object ):
@@ -37,30 +63,69 @@ class HashJob ( object ):
 # --- end of HashJob ---
 
 
+
 class HashPool ( object ):
-   def __init__ ( self, hashes, max_workers ):
+   def __init__ ( self, hashes, max_workers, use_threads=None ):
       super ( HashPool, self ).__init__()
-      self.hashes      = frozenset ( hashes )
+      self.hashfunc    = HashFunction ( hashes )
       self._jobs       = dict()
-      self.max_workers = int ( max_workers )
+      self.max_workers = (
+         int ( max_workers ) if max_workers is not None else max_workers
+      )
+
+      if use_threads or use_threads is None:
+         self.executor_cls = concurrent.futures.ThreadPoolExecutor
+      else:
+         self.executor_cls = concurrent.futures.ProcessPoolExecutor
    # --- end of __init__ (...) ---
 
    def add ( self, backref, filepath, hashdict=None ):
       self._jobs [backref] = HashJob ( filepath, hashdict )
    # --- end of add (...) ---
 
+   def get_executor ( self ):
+      return self.executor_cls ( self.max_workers )
+   # --- end of get_executor (...) ---
+
+   def is_concurrent ( self ):
+      return HAVE_CONCURRENT_FUTURES and (
+         self.max_workers is None or self.max_workers > 0
+      )
+   # --- end of is_concurrent (...) ---
+
+   def run_as_completed ( self ):
+      if self.is_concurrent():
+         with self.get_executor() as exe:
+            for backref, hash_job in zip (
+               self._jobs.keys(),
+               exe.map ( self.hashfunc, self._jobs.values() )
+            ):
+               yield ( backref, hash_job.hashdict )
+      else:
+         for backref, hash_job in self._jobs.items():
+            self.hashfunc.calculate ( hash_job )
+            yield ( backref, hash_job.hashdict )
+   # --- end of run_as_completed (...) ---
+
    def run ( self ):
-      #with concurrent.futures.ProcessPoolExecutor ( self.max_workers ) as exe:
-      with concurrent.futures.ThreadPoolExecutor ( self.max_workers ) as exe:
-         running_jobs = frozenset (
-            exe.submit ( _calculate_hashes, job, self.hashes )
-            for job in self._jobs.values()
-         )
-
-         # wait
-         for finished_job in concurrent.futures.as_completed ( running_jobs ):
-            if finished_job.exception() is not None:
-               raise finished_job.exception()
+      if self.is_concurrent():
+         with self.get_executor() as exe:
+            running_jobs =  frozenset (
+               exe.submit ( self.hashfunc, job )
+               for job in self._jobs.values()
+            )
+
+            # wait
+            for finished_job in (
+               concurrent.futures.as_completed ( running_jobs )
+            ):
+               if finished_job.exception() is not None:
+                  raise finished_job.exception()
+               elif finished_job.cancelled():
+                  break
+      else:
+         for hash_job in self._jobs.values():
+            self.hashfunc.calculate ( hash_job )
    # --- end of run (...) ---
 
    def reset ( self ):


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-23 13:51 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-23 13:51 UTC (permalink / raw
  To: gentoo-commits

commit:     e92513a705c2912db28e6f7358aa4d7bf19ae3c7
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug 22 14:30:27 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug 22 14:30:27 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=e92513a7

roverlay/util/common: for_all_files_decorator()

This allows to create recursive file-related functions for functions that
accept a single file arg (and possibly other args).

---
 roverlay/util/common.py | 123 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 100 insertions(+), 23 deletions(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index 5407508..24008ad 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -8,10 +8,13 @@
 
 __all__= [
    'dodir', 'dodir_for_file',
-   'for_all_files', 'get_dict_hash', 'keepenv', 'keepenv_v',
-   'priosort', 'sysnop', 'getsize', 'is_vcs_dir', 'headtail', 'try_unlink',
+   'for_all_files_decorator', 'for_all_files',
+   'get_dict_hash', 'keepenv', 'keepenv_v',
+   'priosort', 'sysnop', 'getsize', 'is_vcs_dir', 'is_not_vcs_dir',
+    'headtail', 'try_unlink',
 ]
 
+
 import errno
 import os
 import sys
@@ -47,16 +50,17 @@ def try_unlink ( fspath ):
       return True
 # --- end of try_unlink (...) ---
 
-def for_all_files (
-   files_or_dirs, func,
-   args=(), kwargs={}, file_filter=None, ignore_missing=False
+def for_all_files_decorator (
+   func, args=(), kwargs={},
+   file_filter=None, ignore_missing=False, dir_filter=True,
+   kwargs_union=0, topdown=True, onerror=None, followlinks=False,
 ):
    """
-   Runs "func ( <file>, *args, **kwargs )" for each <file> in files_or_dirs.
+   Returns a function that runs "func ( <file>, *args, **kwargs )"
+   for each <file> in files_or_dirs (its first argument).
    Dirs will be recursively "expanded" (= for all files/dirs in dir...).
 
    arguments:
-   * files_or_dirs  -- an iterable with files or dirs
    * func           -- function that will be called for each file
    * args           -- args that will be passed to each func call
                         Defaults to () (empty tuple)
@@ -68,23 +72,92 @@ def for_all_files (
    * ignore_missing -- if True: do not raise an exception if a file/dir is
                                 missing
                         Defaults to False
+   * dir_filter     -- if True         : vcs dirs will be ignored
+                       else if not None: dir will be ignored unless
+                                         this function returns True for <dir>
+                        Defaults to True
+   * kwargs_union   -- an int that controls how/which kwargs are passed to func
+                       0: always pass decorator kwargs
+                       1: update decorator kwargs with caller kwargs
+                       2: update caller kwargs with decorator kwargs
+   * topdown        -- see os.walk(). Defaults to True.
+   * onerror        -- see os.walk(). Defaults to None.
+   * followlinks    -- see os.walk(). Defaults to False.
+   """
+   OUR_DIR_FILTER = None if dir_filter is None else (
+      is_not_vcs_dir if dir_filter is True else dir_filter
+   )
+
+   def wrapped ( files_or_dirs, *their_args, **their_kwargs ):
+      my_args = their_args or args
+      if kwargs_union == 0:
+         my_kwargs = kwargs
+      elif kwargs_union == 1:
+         my_kwargs = dict ( kwargs )
+         my_kwargs.update ( their_kwargs )
+      else:
+         my_kwargs = dict ( their_kwargs )
+         my_kwargs.update ( kwargs )
+
+
+      func_result = dict()
+
+      for item in (
+         files_or_dirs if (
+            not isinstance ( files_or_dirs, str )
+            and hasattr ( files_or_dirs, '__iter__' )
+         )
+         else ( files_or_dirs, )
+      ):
+         if os.path.isfile ( item ):
+            if file_filter is None or file_filter ( item ):
+               func_result [item] = func ( item, *args, **kwargs )
+         elif os.path.isdir ( item ):
+            partial_result = dict()
+            for root, dirnames, filenames in os.walk (
+               item,
+               topdown=topdown, onerror=onerror, followlinks=followlinks
+            ):
+               if OUR_DIR_FILTER is None or OUR_DIR_FILTER ( root ):
+                  for filename in filenames:
+                     fpath = root + os.sep + filename
+                     if file_filter is None or file_filter ( fpath ):
+                        partial_result [fpath ] = func (
+                           fpath, *args, **kwargs
+                        )
+               # -- end if OUR_DIR_FILTER
+            # -- end for root...
+            func_result [item] = partial_result
+            partial_result = None
+
+         elif os.access ( item, os.F_OK ):
+            raise Exception ( "{}: neither a file nor a dir.".format ( item ) )
+
+         elif not ignore_missing:
+            raise Exception ( "{!r} does not exist!".format ( item ) )
+      # -- end for item
+
+      return func_result
+   # --- end of wrapped (...) ---
+
+   wrapped.__name__ = func.__name__
+   wrapped.__doc__  = func.__doc__
+   wrapped.__dict__.update ( func.__dict__ )
+   return wrapped
+# --- end of for_all_files_decorator (...) ---
+
+def for_all_files (
+   files_or_dirs, func, args=(), kwargs={},
+   file_filter=None, ignore_missing=False, dir_filter=True
+):
+   """Wraps func and calls it several times (for each file).
+   See for_all_files_decorator() for details.
    """
-   # alternative: os.walk()
-   def recursive_do ( fpath ):
-      if os.path.isfile ( fpath ):
-         if file_filter is None or file_filter ( fpath ):
-            func ( fpath, *args, **kwargs )
-      elif os.path.isdir ( fpath ):
-         for fname in os.listdir ( fpath ):
-            recursive_do ( fpath + os.sep + fname )
-      elif os.access ( fpath, os.F_OK ):
-         raise Exception ( "{}: neither a file nor a dir.".format ( fpath ) )
-      elif not ignore_missing:
-         raise Exception ( "{!r} does not exist!".format ( fpath ) )
-   # --- end of recursive_do (...) ---
-
-   for f in files_or_dirs:
-      recursive_do ( f )
+   return for_all_files_decorator (
+      func, args=args, kwargs=kwargs, file_filter=file_filter,
+      ignore_missing=ignore_missing, dir_filter=dir_filter,
+      kwargs_union=0
+   ) ( files_or_dirs )
 # --- end of for_all_files (...) ---
 
 def priosort ( iterable ):
@@ -244,3 +317,7 @@ def is_vcs_dir ( dirpath ):
    """
    return os.path.basename ( dirpath.rstrip ( os.sep ) ) in VCS_DIRNAMES
 # --- end of is_vcs_dir (...) ---
+
+def is_not_vcs_dir ( dirpath ):
+   return not is_vcs_dir ( dirpath )
+# --- end of is_not_vcs_dir (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-23 13:52 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-23 13:52 UTC (permalink / raw
  To: gentoo-commits

commit:     1bd7938e8f3d9ba59fae9bdae378ec2120c3ca8b
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 23 11:17:13 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 23 11:17:13 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=1bd7938e

roverlay/util/namespace:

This is (mostly) a copy of the package rules' namespace object, but aims to be
generic. Supports creation of objects with hashable args / kwarg items only,
currently.

---
 roverlay/util/namespace.py | 144 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 144 insertions(+)

diff --git a/roverlay/util/namespace.py b/roverlay/util/namespace.py
new file mode 100644
index 0000000..86d102f
--- /dev/null
+++ b/roverlay/util/namespace.py
@@ -0,0 +1,144 @@
+# R overlay -- generic namespace
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+#import weakref
+
+import roverlay.util.common
+import roverlay.util.objects
+
+DEBUG_GET_OBJECT = False
+
+
+if DEBUG_GET_OBJECT:
+   def debug_get_object ( msg, cls, args, kwargs ):
+      print (
+         "[ObjectNamespace] {:<17} :: {}, {}, {}".format (
+            msg, cls, args, kwargs
+         )
+      )
+   # --- end of debug_get_object (...) ---
+# -- end if
+
+
+class Namespaceable ( object ):
+   @classmethod
+   def from_namespace ( cls, namespace, *args, **kwargs ):
+      return namespace.get_object_v ( cls, args, kwargs )
+   # --- end of from_namespace (...) ---
+
+   def __init__ ( self, *args, **kwargs ):
+      super ( Namespaceable, self ).__init__()
+   # --- end of __init__ (...) ---
+
+# --- end of Namespaceable ---
+
+class AbstractNamespace ( object ):
+
+   def __init__ ( self, *args, **kwargs ):
+      super ( AbstractNamespace, self ).__init__()
+   # --- end of __init__ (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def zap ( self, zap_object_db=False ):
+      pass
+   # --- end of zap (...) ---
+
+   def get_dict_hash ( self, d ):
+      # note that this doesn't handle "recursive" dicts
+      return roverlay.util.common.get_dict_hash ( d )
+   # --- end of get_dict_hash (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def get_object_v ( self, cls, args, kwargs ):
+      """Returns the desired object.
+
+      The object will be created if it does not already exist in the
+      object db of this namespace.
+
+      !!! The object has to be "shareable", i.e. it must not be modified
+          after constructing it (unless such a side-effect is intentional).
+
+      arguments:
+      * cls      --
+      * *args    --
+      * **kwargs --
+      """
+      pass
+   # --- end of get_object_v (...) ---
+
+   def get_object ( self, cls, *args, **kwargs ):
+      """Like get_object_v(), but accepts a variable number of args."""
+      return self.get_object_v ( cls, args, kwargs )
+   # --- end of get_object (...) ---
+
+# --- end of AbstractNamespace ---
+
+
+class NullNamespace ( AbstractNamespace ):
+
+   def zap ( self, *args, **kwargs ):
+      pass
+   # --- end of zap (...) ---
+
+   def get_object_v ( self, cls, args, kwargs ):
+      return cls ( *args, **kwargs )
+   # --- end of get_object_v (...) ---
+
+# --- end of NullNamespace ---
+
+
+class SimpleNamespace ( AbstractNamespace ):
+   """A namespace that caches all created objects."""
+
+   def zap ( self, zap_object_db=False ):
+      if zap_object_db:
+         self._objects.clear()
+   # --- end of zap (...) ---
+
+   def __init__ ( self ):
+      super ( SimpleNamespace, self ).__init__()
+
+      # object db
+      #  dict (
+      #     class => dict (
+      #        tuple(hash(args),hash(kwargs)) => instance
+      #     )
+      #  )
+      #
+      self._objects = dict()
+   # --- end of __init__ (...) ---
+
+   def get_object_v ( self, cls, args, kwargs ):
+      ident = (
+         hash ( args ) if args else 0,
+         self.get_dict_hash ( kwargs ) if kwargs else 0,
+      )
+
+      objects = self._objects.get ( cls, None )
+
+      if objects is None:
+         if DEBUG_GET_OBJECT:
+            debug_get_object ( "miss/new cls, obj", cls, args, kwargs )
+
+         c = cls ( *args, **kwargs )
+         self._objects [cls] = { ident : c }
+
+      else:
+         c = objects.get ( ident, None )
+
+         if c is None:
+            if DEBUG_GET_OBJECT:
+               debug_get_object ( "miss/new obj", cls, args, kwargs )
+
+            c = cls ( *args, **kwargs )
+            objects [ident] = c
+         elif DEBUG_GET_OBJECT:
+            debug_get_object ( "hit/exist", cls, args, kwargs )
+
+      return c
+   # --- end of get_object_v (...) ---
+
+# --- end of SimpleNamespace ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-23 13:52 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-23 13:52 UTC (permalink / raw
  To: gentoo-commits

commit:     88f8e25ce883c7980246df78b151bff188b6f2b6
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 23 11:16:18 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 23 11:16:18 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=88f8e25c

roverlay/util: dictwalk

Provides classes/functions for manipulating/accessing a tree-like dict
structure.

---
 roverlay/util/dictwalk.py | 145 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 145 insertions(+)

diff --git a/roverlay/util/dictwalk.py b/roverlay/util/dictwalk.py
new file mode 100644
index 0000000..a98b695
--- /dev/null
+++ b/roverlay/util/dictwalk.py
@@ -0,0 +1,145 @@
+# R overlay -- roverlay package, dictwalk
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+import roverlay.util.namespace
+import roverlay.util.objects
+
+
+def dictwalk_create_parent_v ( root, path, dict_create=None, cautious=True ):
+   """Creates a dict tree structure using keys the given path. The last path
+   element will not be created.
+
+   Returns a 3-tuple
+      ( <parent of the last path element>,
+         <last path element>, <last path element exists>,
+      )
+
+   arguments:
+   * root        -- dict root
+   * path        -- path (list of keys)
+   * dict_create -- constructor for dicts
+   * cautious    -- do not create (dict) nodes if an element already exists
+                    at a position. Defaults to True, which typically raises
+                    a KeyError/TypeError if such an issue is (not) detected.
+                    **NOT IMPLEMENTED**, always using cautious behavior
+   """
+   dcreate    = type ( root ) if dict_create is None else dict_create
+   last_index = len ( path ) - 1
+   pos        = root
+   next_pos   = None
+
+   for index, key in enumerate ( path ):
+      if index == last_index:
+         return ( pos, key, key in pos )
+      elif key not in pos:
+         next_pos  = dcreate()
+         pos [key] = next_pos
+         pos       = next_pos
+         next_pos  = None
+      else:
+         pos       = pos [key]
+   # -- end for
+
+   raise Exception ( "unreachable code." )
+# --- end of dictwalk_create_parent_v (...) ---
+
+def dictwalk_create_element_v (
+   root, path, constructor, overwrite=False, **kw
+):
+   parent, key, have_key = dictwalk_create_parent_v ( root, path, **kw )
+   if have_key and not overwrite:
+      return parent[key]
+   else:
+      new_elem = constructor()
+      parent[key] = new_elem
+      return new_elem
+# --- end of dictwalk_create_element_v (...) ---
+
+def dictwalk_create_parent ( root, *path ):
+   return dictwalk_create_parent_v ( root, path )
+# --- end of dictwalk_create_parent (...) ---
+
+class DictWalker ( roverlay.util.namespace.Namespaceable ):
+
+   DEFAULT_CONTAINER_TYPE = list
+
+   def __init__ ( self, *args, **kwargs ):
+      super ( DictWalker, self ).__init__()
+      self.container_type = kwargs.get (
+         'container_type', self.__class__.DEFAULT_CONTAINER_TYPE
+      )
+
+      self.add_value = (
+         self._append_value if hasattr ( self.container_type, 'append' )
+         else self._add_value
+      )
+   # --- end of __init__ (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def get_root ( self, *args, **kwargs ):
+      pass
+   # --- end of get_root (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def get_keypath ( self, *args, **kwargs ):
+      pass
+   # --- end of get_keypath (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def store_value ( self, value, *args, **kwargs ):
+      pass
+   # --- end of store_value (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def get_value_container ( *args, **kwargs ):
+      pass
+   # --- end of get_value_container (...) ---
+
+   def _add_value ( self, value, *args, **kwargs ):
+      self.get_value_container ( *args, **kwargs ).add ( value )
+   # --- end of _add_value (...) ---
+
+   def _append_value ( self, value, *args, **kwargs ):
+      self.get_value_container ( *args, **kwargs ).append ( value )
+   # --- end of _append_value (...) ---
+
+# --- end of DictWalker ---
+
+
+class FixedKeyDictWalker ( DictWalker ):
+
+   def __init__ ( self, keypath, *args, **kwargs ):
+      super ( FixedKeyDictWalker, self ).__init__ ( *args, **kwargs )
+
+      if isinstance ( keypath, str ) or not hasattr ( keypath, '__iter__' ):
+         self.keypath = ( keypath, )
+      else:
+         self.keypath = keypath
+   # --- end of __init__ (...) ---
+
+   #get_root() has to be implemented by derived classes
+
+   def get_keypath ( self ):
+      return self.keypath
+   # --- end of get_keypath (...) ---
+
+   def store_value ( self, value, *args, **kwargs ):
+      parent, key, have_key = dictwalk_create_parent_v (
+         self.get_root ( *args, **kwargs ), self.keypath
+      )
+      ret         = parent[key] if have_key else None
+      parent[key] = value
+      return ret
+   # --- end of store_value (...) ---
+
+   def get_value_container ( self, *args, **kwargs ):
+      return dictwalk_create_element_v (
+         self.get_root ( *args, **kwargs ), self.keypath, self.container_type,
+         overwrite=False
+      )
+   # --- end of get_value_container (...) ---
+
+# --- end of FixedKeyDictWalker ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-23 13:52 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-23 13:52 UTC (permalink / raw
  To: gentoo-commits

commit:     d0954117899d73fcca82f66a933974d9c39966fd
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 23 13:37:22 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 23 13:37:22 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=d0954117

roverlay/util/namespace: add default values

for args, kwargs to get_object_v()

---
 roverlay/util/namespace.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/roverlay/util/namespace.py b/roverlay/util/namespace.py
index 86d102f..5dce92e 100644
--- a/roverlay/util/namespace.py
+++ b/roverlay/util/namespace.py
@@ -52,7 +52,7 @@ class AbstractNamespace ( object ):
    # --- end of get_dict_hash (...) ---
 
    @roverlay.util.objects.abstractmethod
-   def get_object_v ( self, cls, args, kwargs ):
+   def get_object_v ( self, cls, args=(), kwargs={} ):
       """Returns the desired object.
 
       The object will be created if it does not already exist in the
@@ -83,7 +83,7 @@ class NullNamespace ( AbstractNamespace ):
       pass
    # --- end of zap (...) ---
 
-   def get_object_v ( self, cls, args, kwargs ):
+   def get_object_v ( self, cls, args=(), kwargs={} ):
       return cls ( *args, **kwargs )
    # --- end of get_object_v (...) ---
 
@@ -111,7 +111,7 @@ class SimpleNamespace ( AbstractNamespace ):
       self._objects = dict()
    # --- end of __init__ (...) ---
 
-   def get_object_v ( self, cls, args, kwargs ):
+   def get_object_v ( self, cls, args=(), kwargs={} ):
       ident = (
          hash ( args ) if args else 0,
          self.get_dict_hash ( kwargs ) if kwargs else 0,


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-29 12:36 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-29 12:36 UTC (permalink / raw
  To: gentoo-commits

commit:     c5c196a9a80e19a1f61379db1c9b9592cf6a1fc6
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug 29 09:14:37 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug 29 09:14:37 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=c5c196a9

roverlay/util/objects: weak-referenced object view

expose a (sub-)set of an object's information without depending on its existence
(= keeping it in memory due to reference count).

---
 roverlay/util/objects.py | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index dd19046..28cc4e8 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -4,6 +4,8 @@
 # Distributed under the terms of the GNU General Public License;
 # either version 2 of the License, or (at your option) any later version.
 
+import weakref
+
 class MethodNotImplementedError ( NotImplementedError ):
    def __init__ ( self, obj, method, msg=None ):
       if isinstance ( obj, str ):
@@ -67,3 +69,40 @@ def abstractmethod ( func=None ):
 def not_implemented ( func=None ):
    return _get_exception_wrapper ( MethodNotImplementedError, func )
 # --- end of not_implemented (...) ---
+
+
+class ObjectView ( object ):
+
+   class ObjectDisappeared ( Exception ):
+      pass
+   # --- end of ObjectDisappeared ---
+
+   def __init__ ( self, obj ):
+      super ( ObjectView, self ).__init__()
+      self.obj_ref = weakref.ref ( obj ) if obj is not None else None
+   # --- end of __init__ (...) ---
+
+   def __bool__ ( self ):
+      return ( self.obj_ref is not None and self.obj_ref() is not None )
+   # --- end of __bool__ (...) ---
+
+   def deref_unsafe ( self ):
+      return None if self.obj_ref is None else self.obj_ref()
+   # --- end of deref_unsafe (...) ---
+
+   def deref_safe ( self ):
+      obj = None if self.obj_ref is None else self.obj_ref()
+      if obj is None:
+         raise self.__class__.ObjectDisappeared()
+      else:
+         return obj
+   # --- end of deref_safe (...) ---
+
+   deref = deref_safe
+
+   @abstractmethod
+   def update ( self ):
+      pass
+   # --- end of update (...) ---
+
+# --- end of ObjectView ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-29 12:36 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-29 12:36 UTC (permalink / raw
  To: gentoo-commits

commit:     758592e4107cae1a93c936062f0bda2bc9fc6dd5
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug 29 12:24:54 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug 29 12:24:54 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=758592e4

roverlay/util/objects: more weak referencing

This functionality will (primarily) be used for handling distmap/mirror
directory file collisions.

---
 roverlay/util/objects.py | 154 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 135 insertions(+), 19 deletions(-)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index 28cc4e8..ce4eccb 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -6,6 +6,85 @@
 
 import weakref
 
+class ObjectDisappeared ( Exception ):
+   pass
+# --- end of ObjectDisappeared ---
+
+class SafeWeakRef ( weakref.ref ):
+
+   def deref_unsafe ( self ):
+      return super ( SafeWeakRef, self ).__call__()
+   # --- end of deref_unsafe (...) ---
+
+   def deref_safe ( self ):
+      obj = super ( SafeWeakRef, self ).__call__()
+      if obj is not None:
+         return obj
+      else:
+         raise ObjectDisappeared()
+   # --- end of deref_safe (...) ---
+
+   __call__ = deref_safe
+   deref    = deref_safe
+
+   def __bool__ ( self ):
+      return self.deref_unsafe() is not None
+   # --- end of __bool__ (...) ---
+
+   def __repr__ ( self ):
+      obj = self.deref_unsafe()
+      if obj:
+         return "<{} at 0x{:x} to {!r} at 0x{:x}>".format (
+            self.__class__.__name__, id ( self ),
+            obj.__class__.__name__, id ( obj )
+         )
+      else:
+         return "<{} at 0x{:x} to None>".format (
+            self.__class__.__name__, id ( self )
+         )
+   # --- end of __repr__ (...) ---
+
+# --- end of SafeWeakRef ---
+
+
+class NoneRef ( object ):
+
+   def __init__ ( self, obj=None ):
+      super ( NoneRef, self ).__init__()
+      assert obj is None
+   # --- end of NoneRef (...) ---
+
+   def deref_unsafe ( self ):
+      return None
+   # --- end of deref_unsafe (...) ---
+
+   def deref_safe ( self ):
+      raise ObjectDisappeared()
+   # --- end of deref_safe (...) ---
+
+   __call__ = deref_safe
+   deref    = deref_safe
+
+   def __bool__ ( self ):
+      return False
+   # --- end of __bool__ (...) ---
+
+   def __repr__ ( self ):
+      return "<NoneRef at 0x{:x}>".format ( id ( self ) )
+   # --- end of __repr__ (...) ---
+
+# --- end of NoneRef ---
+
+def get_object_ref ( obj ):
+   if obj is None:
+      return NoneRef()
+   elif hasattr ( obj, 'get_ref' ):
+      return obj.get_ref()
+   else:
+      return SafeWeakRef ( obj )
+# --- end of get_object_ref (...) ---
+
+
 class MethodNotImplementedError ( NotImplementedError ):
    def __init__ ( self, obj, method, msg=None ):
       if isinstance ( obj, str ):
@@ -71,35 +150,72 @@ def not_implemented ( func=None ):
 # --- end of not_implemented (...) ---
 
 
+class Referenceable ( object ):
+
+   CACHE_REF = False
+
+   def __init__ ( self, *args, **kwargs ):
+      super ( Referenceable, self ).__init__()
+      self._cached_selfref = None
+      if self.CACHE_REF:
+         self.cache_ref()
+   # --- end of __init__ (...) ---
+
+   def cache_ref ( self ):
+      self._cached_selfref = self.get_new_ref()
+      self.get_ref = self._get_cached_ref
+   # --- end of cache_ref (...) ---
+
+   def _get_cached_ref ( self ):
+      return self._cached_selfref
+   # --- end of _get_cached_ref (...) ---
+
+   def get_new_ref ( self ):
+      return SafeWeakRef ( self )
+   # --- end of get_new_ref (...) ---
+
+   get_ref = get_new_ref
+
+# --- end of Referenceable ---
+
+
+class ReferenceTree ( Referenceable ):
+
+   def __init__ ( self, parent ):
+      super ( ReferenceTree, self ).__init__()
+      self.parent_ref = None
+      self.set_parent ( parent )
+   # --- end of __init__ (...) ---
+
+   def set_parent ( self, parent ):
+      self.parent_ref = get_object_ref ( parent )
+   # --- end of set_parent (...) ---
+
+   def get_parent ( self ):
+      return self.parent_ref.deref_safe()
+   # --- end of get_parent (...) ---
+
+   get_upper = get_parent
+
+# --- end of ReferenceTree ---
+
+
 class ObjectView ( object ):
 
-   class ObjectDisappeared ( Exception ):
-      pass
-   # --- end of ObjectDisappeared ---
+   ObjectDisappeared = ObjectDisappeared
 
    def __init__ ( self, obj ):
       super ( ObjectView, self ).__init__()
-      self.obj_ref = weakref.ref ( obj ) if obj is not None else None
+      self.obj_ref = get_object_ref ( obj )
+      self.deref_unsafe = self.obj_ref.deref_unsafe
+      self.deref_safe   = self.obj_ref.deref_safe
+      self.deref        = self.obj_ref.deref_safe
    # --- end of __init__ (...) ---
 
    def __bool__ ( self ):
-      return ( self.obj_ref is not None and self.obj_ref() is not None )
+      return bool ( self.obj_ref )
    # --- end of __bool__ (...) ---
 
-   def deref_unsafe ( self ):
-      return None if self.obj_ref is None else self.obj_ref()
-   # --- end of deref_unsafe (...) ---
-
-   def deref_safe ( self ):
-      obj = None if self.obj_ref is None else self.obj_ref()
-      if obj is None:
-         raise self.__class__.ObjectDisappeared()
-      else:
-         return obj
-   # --- end of deref_safe (...) ---
-
-   deref = deref_safe
-
    @abstractmethod
    def update ( self ):
       pass


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-29 13:53 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-29 13:53 UTC (permalink / raw
  To: gentoo-commits

commit:     cbc3333406f8ed796d98f8f5a6fe0ccab60ac7b5
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug 29 13:13:12 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug 29 13:13:12 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=cbc33334

roverlay/util/objects: comments

---
 roverlay/util/objects.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 62 insertions(+), 2 deletions(-)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index ce4eccb..323bc88 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -11,12 +11,24 @@ class ObjectDisappeared ( Exception ):
 # --- end of ObjectDisappeared ---
 
 class SafeWeakRef ( weakref.ref ):
+   """A weak reference that supports 'safe' dereferencing, i.e. raising an
+   exception if the referenced object does no longer exist."""
 
    def deref_unsafe ( self ):
+      """Dereferences without checking whether the object exists.
+
+      Returns: the object / None
+      """
       return super ( SafeWeakRef, self ).__call__()
    # --- end of deref_unsafe (...) ---
 
    def deref_safe ( self ):
+      """Safely dereferences the object.
+
+      Returns: the object
+
+      Raises: ObjectDisappeared if the object does no longer exist.
+      """
       obj = super ( SafeWeakRef, self ).__call__()
       if obj is not None:
          return obj
@@ -28,6 +40,7 @@ class SafeWeakRef ( weakref.ref ):
    deref    = deref_safe
 
    def __bool__ ( self ):
+      """Returns True if the referenced object exists, else False."""
       return self.deref_unsafe() is not None
    # --- end of __bool__ (...) ---
 
@@ -48,6 +61,7 @@ class SafeWeakRef ( weakref.ref ):
 
 
 class NoneRef ( object ):
+   """A 'reference' to None (compat object)."""
 
    def __init__ ( self, obj=None ):
       super ( NoneRef, self ).__init__()
@@ -76,8 +90,17 @@ class NoneRef ( object ):
 # --- end of NoneRef ---
 
 def get_object_ref ( obj ):
+   """Returns a reference to the given object, either by using the object's
+   get_ref() function (if defined) or by creating a SafeWeakRef/NoneRef
+   instance.
+
+   arguments:
+   * obj --
+   """
    if obj is None:
       return NoneRef()
+   elif isinstance ( obj, ( SafeWeakRef, NoneRef, weakref.ref ) ):
+      return obj
    elif hasattr ( obj, 'get_ref' ):
       return obj.get_ref()
    else:
@@ -129,6 +152,15 @@ class AbstractMethodError ( MethodNotImplementedError ):
 # --- end of AbstractMethodError ---
 
 def _get_exception_wrapper ( err_cls, func ):
+   """Returns a method that raises the given exception when called.
+
+   arguments:
+   * err_cls -- class/constructor of the exception that should be raised.
+                Has to accept 2 args:
+                - object to which the method is bound
+                - the actual function
+   * func    -- function to be wrapped
+   """
    def wrapped ( obj, *args, **kwargs ):
       raise err_cls ( obj, func )
    # --- end of wrapped (...) ---
@@ -138,7 +170,6 @@ def _get_exception_wrapper ( err_cls, func ):
       wrapped.__doc__  = func.__doc__
       wrapped.__dict__.update ( func.__dict__ )
    return wrapped
-
 # --- end of _get_exception_wrapper (...) ---
 
 def abstractmethod ( func=None ):
@@ -155,6 +186,7 @@ class Referenceable ( object ):
    CACHE_REF = False
 
    def __init__ ( self, *args, **kwargs ):
+      """Initializes a referenceable object. Ignores all args/kwargs."""
       super ( Referenceable, self ).__init__()
       self._cached_selfref = None
       if self.CACHE_REF:
@@ -162,62 +194,90 @@ class Referenceable ( object ):
    # --- end of __init__ (...) ---
 
    def cache_ref ( self ):
+      """Creates a cached reference and sets get_ref() so that the cached ref
+      is returned (when called)."""
       self._cached_selfref = self.get_new_ref()
       self.get_ref = self._get_cached_ref
    # --- end of cache_ref (...) ---
 
    def _get_cached_ref ( self ):
+      """Returns the cached reference."""
       return self._cached_selfref
    # --- end of _get_cached_ref (...) ---
 
    def get_new_ref ( self ):
+      """Returns a new reference."""
       return SafeWeakRef ( self )
    # --- end of get_new_ref (...) ---
 
+   # initially, get_ref() is get_new_ref()
    get_ref = get_new_ref
 
 # --- end of Referenceable ---
 
 
 class ReferenceTree ( Referenceable ):
+   """A Referenceable that is part of a tree-like data structure with weak
+   backreferences (each object has one ancestor or None)."""
 
    def __init__ ( self, parent ):
+      """Intializes this referencable object.
+
+      arguments:
+      * parent -- the parent object (typically not a reference)
+      """
       super ( ReferenceTree, self ).__init__()
       self.parent_ref = None
       self.set_parent ( parent )
    # --- end of __init__ (...) ---
 
    def set_parent ( self, parent ):
+      """(Re-)sets the parent object.
+
+      arguments:
+      * parent -- the parent object (typically not a reference)
+      """
       self.parent_ref = get_object_ref ( parent )
    # --- end of set_parent (...) ---
 
    def get_parent ( self ):
+      """Returns the parent object (dereferenced parent object reference)."""
       return self.parent_ref.deref_safe()
    # --- end of get_parent (...) ---
 
+   #get_upper() is an alias to get_parent()
    get_upper = get_parent
 
 # --- end of ReferenceTree ---
 
 
 class ObjectView ( object ):
+   """A view object (=expose a (sub-)set of another object's data) that
+   uses weak references."""
 
    ObjectDisappeared = ObjectDisappeared
 
    def __init__ ( self, obj ):
+      """Initializes an object view.
+
+      arguments:
+      * obj -- object to be "viewed"
+      """
       super ( ObjectView, self ).__init__()
-      self.obj_ref = get_object_ref ( obj )
+      self.obj_ref      = get_object_ref ( obj )
       self.deref_unsafe = self.obj_ref.deref_unsafe
       self.deref_safe   = self.obj_ref.deref_safe
       self.deref        = self.obj_ref.deref_safe
    # --- end of __init__ (...) ---
 
    def __bool__ ( self ):
+      """Returns True if the actual object exists, else False."""
       return bool ( self.obj_ref )
    # --- end of __bool__ (...) ---
 
    @abstractmethod
    def update ( self ):
+      """Updates this view (collect data from the actual object etc.)."""
       pass
    # --- end of update (...) ---
 


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-30 14:49 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-30 14:49 UTC (permalink / raw
  To: gentoo-commits

commit:     7830c41f7b9838d1c204837b50448cded7a3087b
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 30 12:37:34 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 30 12:37:34 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=7830c41f

roverlay/util/objects: more meaningful error messages

include parameter list in MethodNotImplementedError/AbstractMethodError (if
given).

---
 roverlay/util/objects.py | 94 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 79 insertions(+), 15 deletions(-)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index 2bcb7e4..95e63f0 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -109,7 +109,48 @@ def get_object_ref ( obj ):
 
 
 class MethodNotImplementedError ( NotImplementedError ):
-   def __init__ ( self, obj, method, msg=None ):
+
+   def __init__ ( self, obj, method, msg=None, params=None ):
+      """Constructor for MethodNotImplementedError.
+
+      arguments:
+      * obj    -- object/class to which the method is bound
+      * method -- method that is not implemented
+      * msg    -- additional information (if set)
+      * params -- an iterable of parameters (args/kwargs) that the method
+                  accepts (used for generating more meaningful messages)
+      """
+      super ( MethodNotImplementedError, self ).__init__ (
+         self._get_error_message ( obj, method, msg, params )
+      )
+   # --- end of __init__ (...) ---
+
+   # or staticmethod, unbound, ...
+   @classmethod
+   def _compare_arg_count ( self, params, method ):
+         if (
+            hasattr ( method, '__code__' ) and
+            hasattr ( method.__code__, 'co_argcount' )
+         ):
+            plen = len ( params )
+            if (
+               plen != method.__code__.co_argcount and (
+                  params[0] in { 'self', 'cls' } or
+                  ( plen + 1 ) != method.__code__.co_argcount
+               )
+            ):
+               raise AssertionError (
+                  "params, arg count mismatch: {:d} != {:d}".format (
+                     len ( params ), method.__code__.co_argcount
+                  )
+               )
+            del plen
+         # -- end if __debug__
+   # --- end of _compare_arg_count (...) ---
+
+   @classmethod
+   def _get_error_message ( cls, obj, method, msg=None, params=None ):
+      # obj_name =
       if isinstance ( obj, str ):
          obj_name = obj
       elif hasattr ( obj, '__class__' ):
@@ -119,6 +160,7 @@ class MethodNotImplementedError ( NotImplementedError ):
       else:
          obj_name = repr ( obj )
 
+      # method_name =
       if isinstance ( method, str ):
          method_name = method
       elif hasattr ( method, '__name__' ):
@@ -126,15 +168,23 @@ class MethodNotImplementedError ( NotImplementedError ):
       else:
          method_name = repr ( method )
 
-      method_str = "{}.{}()".format ( obj_name, method_name )
+      # method str =
+      if params:
+         if __debug__:
+            cls._compare_arg_count ( params, method )
 
-      if msg:
-         super ( MethodNotImplementedError, self ).__init__ (
-            method_str + ': ' + str ( msg )
+         method_str = "{}.{} ( {} )".format (
+            obj_name, method_name, ', '.join ( params )
          )
       else:
-         super ( MethodNotImplementedError, self ).__init__ ( method_str )
-   # --- end of __init__ (...) ---
+         method_str = "{}.{}()".format ( obj_name, method_name )
+
+      # method_str +=
+      if msg:
+         return method_str + ': ' + str ( msg )
+      else:
+         return method_str
+   # --- end of _get_error_message (...) ---
 
 # --- end of MethodNotImplementedError ---
 
@@ -144,14 +194,15 @@ class MethodNotImplemented ( MethodNotImplementedError ):
 # --- end of MethodNotImplemented ---
 
 class AbstractMethodError ( MethodNotImplementedError ):
-   def __init__ ( self, obj, method ):
+   def __init__ ( self, obj, method, params=None ):
       super ( AbstractMethodError, self ).__init__ (
-         obj, method, "has to be implemented by derived classes"
+         obj, method, "has to be implemented by derived classes",
+         params=params,
       )
 
 # --- end of AbstractMethodError ---
 
-def _get_exception_wrapper ( err_cls, func ):
+def _create_exception_wrapper ( err_cls, func, err_args=(), err_kwargs={} ):
    """Returns a method that raises the given exception when called.
 
    arguments:
@@ -162,7 +213,7 @@ def _get_exception_wrapper ( err_cls, func ):
    * func    -- function to be wrapped
    """
    def wrapped ( obj, *args, **kwargs ):
-      raise err_cls ( obj, func )
+      raise err_cls ( obj, func, *err_args, **err_kwargs )
    # --- end of wrapped (...) ---
 
    if func is not None:
@@ -170,14 +221,27 @@ def _get_exception_wrapper ( err_cls, func ):
       wrapped.__doc__  = func.__doc__
       wrapped.__dict__.update ( func.__dict__ )
    return wrapped
+# --- end of _create_exception_wrapper (...) ---
+
+def _get_exception_wrapper ( err_cls, func=None, err_args=(), err_kwargs={} ):
+   if func is None:
+      return lambda real_func: _create_exception_wrapper (
+         err_cls, real_func, err_args, err_kwargs
+      )
+   else:
+      return _create_exception_wrapper ( err_cls, func, err_args, err_kwargs )
 # --- end of _get_exception_wrapper (...) ---
 
-def abstractmethod ( func=None ):
-   return _get_exception_wrapper ( AbstractMethodError, func )
+def abstractmethod ( func=None, **kwargs ):
+   return _get_exception_wrapper (
+      AbstractMethodError, func, err_kwargs=kwargs
+   )
 # --- end of abstractmethod (...) ---
 
-def not_implemented ( func=None ):
-   return _get_exception_wrapper ( MethodNotImplementedError, func )
+def not_implemented ( func=None, **kwargs ):
+   return _get_exception_wrapper (
+      MethodNotImplementedError, func, err_kwargs=kwargs
+   )
 # --- end of not_implemented (...) ---
 
 


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-08-30 14:49 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-08-30 14:49 UTC (permalink / raw
  To: gentoo-commits

commit:     a69da1d2747962af84d2ad1e1ec9bc54746d7056
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 30 13:50:28 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 30 13:50:28 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=a69da1d2

util.fileio: strip newlines if preparse is True

Strip newline chars ('\n', currently) at the end of each line if preparse is set
to True.

---
 roverlay/util/fileio.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index c6e33e5..a8d2e01 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -30,13 +30,20 @@ SUPPORTED_COMPRESSION = {
    COMP_BZIP2 : bz2.BZ2File,
 }
 
+def strip_newline ( s ):
+   return s.rstrip ( '\n' )
+# --- end of strip_newline (...) ---
 
 def read_compressed_file_handle ( CH, preparse=None ):
    if preparse is None:
       for line in CH.readlines():
          yield bytes_try_decode ( line )
+   elif preparse is True:
+      for line in CH.readlines():
+         yield strip_newline ( bytes_try_decode ( line ))
    else:
-      yield preparse ( bytes_try_decode ( line ) )
+      for line in CH.readlines():
+         yield preparse ( bytes_try_decode ( line ) )
 # --- end of read_compressed_file_handle (...) ---
 
 def read_text_file ( filepath, preparse=None, try_harder=True ):
@@ -50,6 +57,7 @@ def read_text_file ( filepath, preparse=None, try_harder=True ):
                    be detected (defaults to True)
    """
 
+
    ftype         = guess_filetype ( filepath )
    compress_open = SUPPORTED_COMPRESSION.get ( ftype[1], None )
 
@@ -82,6 +90,9 @@ def read_text_file ( filepath, preparse=None, try_harder=True ):
             if preparse is None:
                for line in FH.readlines():
                   yield line
+            elif preparse is True:
+               for line in FH.readlines():
+                  yield strip_newline ( line )
             else:
                for line in FH.readlines():
                   yield preparse ( line )
@@ -91,6 +102,9 @@ def read_text_file ( filepath, preparse=None, try_harder=True ):
          if preparse is None:
             for line in FH.readlines():
                yield line
+         elif preparse is True:
+            for line in FH.readlines():
+               yield strip_newline ( line )
          else:
             for line in FH.readlines():
                yield preparse ( line )
@@ -117,18 +131,17 @@ def write_text_file (
             CH.write ( str ( line ).encode() )
             if append_newlines:
                CH.write ( NL )
-         else:
-            if append_newline_eof:
-               CH.write ( NL )
+
+         if append_newline_eof:
+            CH.write ( NL )
    else:
       with open ( filepath, mode ) as FH:
          for line in lines:
             FH.write ( str ( line ) )
             if append_newlines:
                FH.write ( newline )
-         else:
-            if append_newline_eof:
-               FH.write ( newline )
+         if append_newline_eof:
+            FH.write ( newline )
 
    return True
 # --- end of write_text_file (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-02 16:21 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-02 16:21 UTC (permalink / raw
  To: gentoo-commits

commit:     92effc121869dd5d9ef9bc0ad15d2c34c42152d2
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Sep  2 16:16:56 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Sep  2 16:16:56 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=92effc12

roverlay/util/objects: set __all__

---
 roverlay/util/objects.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index 95e63f0..5ba1ccb 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -6,6 +6,9 @@
 
 import weakref
 
+__all__ = [ 'get_object_ref', 'abstractmethod', 'not_implemented', ]
+
+
 class ObjectDisappeared ( Exception ):
    pass
 # --- end of ObjectDisappeared ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-03  8:35 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-03  8:35 UTC (permalink / raw
  To: gentoo-commits

commit:     7739bc6f1809eabb3f034f50978e1e9f7d0c6c08
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep  3 08:30:42 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep  3 08:30:42 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=7739bc6f

roverlay/util/counter

generates numbers in ascending order

---
 roverlay/util/counter.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/roverlay/util/counter.py b/roverlay/util/counter.py
new file mode 100644
index 0000000..53fe631
--- /dev/null
+++ b/roverlay/util/counter.py
@@ -0,0 +1,68 @@
+# R overlay --
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+try:
+   _LONG = long
+except NameError:
+   _LONG = int
+
+
+class CounterException ( Exception ):
+   pass
+# --- end of CounterException ---
+
+class CounterUnderflow ( CounterException ):
+   pass
+# --- end of CounterUnderflow ---
+
+
+class IDGenerator ( object ):
+
+   def __init__ ( self, first_value=0, use_long=False ):
+      super ( IDGenerator, self ).__init__()
+      self._initial_value = ( _LONG if use_long else int ) ( first_value - 1 )
+      self._current_value = self._initial_value
+   # --- end of __init__ (...) ---
+
+   def reset ( self ):
+      self._current_value = self._initial_value
+   # --- end of reset (...) ---
+
+   def inc ( self, step=1 ):
+      self._current_value += step
+      return self._current_value
+   # --- end of inc (...) ---
+
+   __next__ = inc
+
+   def peek ( self ):
+      val = self._current_value
+      if val == self._initial_value:
+         raise CounterException ( "no number generated so far!" )
+      elif val < self._initial_value:
+         raise CounterUnderflow()
+      else:
+         return val
+   # --- end of peek (...) ---
+
+   def __iter__ ( self ):
+      return self
+   # --- end of __iter__ (...) ---
+
+# --- end of IDGenerator ---
+
+class Counter ( IDGenerator ):
+
+   def dec ( self, step=1 ):
+      if self._current_value > self._initial_value:
+         self._current_value -= step
+         return self._current_value
+      else:
+         self._current_value = self._initial_value
+         raise CounterUnderflow()
+   # --- end of dec (...) ---
+
+# --- end of Counter ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-03 12:21 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-03 12:21 UTC (permalink / raw
  To: gentoo-commits

commit:     88529b2797d66d4e04d7338d23dee1b5251d0e50
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep  3 08:55:17 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep  3 08:55:17 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=88529b27

clean up roverlay/util/counter

---
 roverlay/util/counter.py | 74 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 49 insertions(+), 25 deletions(-)

diff --git a/roverlay/util/counter.py b/roverlay/util/counter.py
index 53fe631..6c0e699 100644
--- a/roverlay/util/counter.py
+++ b/roverlay/util/counter.py
@@ -4,6 +4,8 @@
 # Distributed under the terms of the GNU General Public License;
 # either version 2 of the License, or (at your option) any later version.
 
+import roverlay.util.objects
+
 try:
    _LONG = long
 except NameError:
@@ -19,50 +21,72 @@ class CounterUnderflow ( CounterException ):
 # --- end of CounterUnderflow ---
 
 
-class IDGenerator ( object ):
+class AbstractCounter ( object ):
 
    def __init__ ( self, first_value=0, use_long=False ):
-      super ( IDGenerator, self ).__init__()
+      super ( AbstractCounter, self ).__init__()
       self._initial_value = ( _LONG if use_long else int ) ( first_value - 1 )
       self._current_value = self._initial_value
    # --- end of __init__ (...) ---
 
+   @roverlay.util.objects.abstractmethod
+   def set_value ( self, value ):
+      pass
+   # --- end of set_value (...) ---
+
+   @roverlay.util.objects.abstractmethod
    def reset ( self ):
-      self._current_value = self._initial_value
+      pass
    # --- end of reset (...) ---
 
-   def inc ( self, step=1 ):
-      self._current_value += step
+   def change_value ( self, delta ):
+      return self.set_value ( self._current_value + delta )
+   # --- end of change_value (...) ---
+
+   def get_value ( self, value ):
+      return self._current_value
+   # --- end of get_value (...) ---
+
+   def get_value_unsafe ( self, value ):
       return self._current_value
+   # --- end of get_value_unsafe (...) ---
+
+   def inc ( self, step=1 ):
+      return self.change_value ( step )
    # --- end of inc (...) ---
 
-   __next__ = inc
+   def dec ( self, step=1 ):
+      return self.change_value ( (-1) * step )
+   # --- end of dec (...) ---
 
-   def peek ( self ):
-      val = self._current_value
-      if val == self._initial_value:
-         raise CounterException ( "no number generated so far!" )
-      elif val < self._initial_value:
-         raise CounterUnderflow()
-      else:
-         return val
-   # --- end of peek (...) ---
+   def __next__ ( self ):
+      return self.inc()
+   # --- end of __next__ (...) ---
 
    def __iter__ ( self ):
       return self
    # --- end of __iter__ (...) ---
 
-# --- end of IDGenerator ---
+# --- end of AbstractCounter ---
 
-class Counter ( IDGenerator ):
 
-   def dec ( self, step=1 ):
-      if self._current_value > self._initial_value:
-         self._current_value -= step
-         return self._current_value
+class UnsafeCounter ( AbstractCounter ):
+
+   def reset ( self ):
+      self.current_value = self._initial_value
+   # --- end of reset (...) ---
+
+   def set_value ( self, value ):
+      if value <= self._initial_value:
+         raise CounterUnderflow ( value )
       else:
-         self._current_value = self._initial_value
-         raise CounterUnderflow()
-   # --- end of dec (...) ---
+         self._current_value = value
+         return value
+   # --- end of set_value (...) ---
+
+# --- end of UnsafeCounter ---
+
 
-# --- end of Counter ---
+class IDGenerator ( UnsafeCounter ):
+   pass
+# --- end of IDGenerator ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-03 15:50 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-03 15:50 UTC (permalink / raw
  To: gentoo-commits

commit:     9e02fab9a6d7c5ec92bda147df91ccc58aacdf78
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep  3 15:42:57 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep  3 15:42:57 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=9e02fab9

ebuildparser: optionally yield placeholders

... when parsing distfiles.

---
 roverlay/util/ebuildparser.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/roverlay/util/ebuildparser.py b/roverlay/util/ebuildparser.py
index 3f27b65..8c16dd5 100644
--- a/roverlay/util/ebuildparser.py
+++ b/roverlay/util/ebuildparser.py
@@ -217,7 +217,9 @@ class SrcUriParser ( EbuildParser ):
             yield entry
    # --- end of _iterate (...) ---
 
-   def iter_local_files ( self, ignore_unparseable=False ):
+   def iter_local_files (
+      self, ignore_unparseable=False, yield_unparseable=False
+   ):
       def convert_chars_with_vars ( text ):
          mode = 0
          for index, char in enumerate ( text ):
@@ -263,7 +265,22 @@ class SrcUriParser ( EbuildParser ):
                   try:
                      yield varstr ( local_file )
                   except ParserException:
-                     pass
+                     if yield_unparseable in { None, True }:
+                        yield None
+                     elif yield_unparseable:
+                        yield local_file
+
+                  except ( KeyError, IndexError ) as err:
+                     # FIXME debug print
+                     print (
+                        "FIXME: {} {} occured while parsing {!r}".format (
+                           err.__class__.__name__, str(err), local_file
+                        )
+                     )
+                     if yield_unparseable in { None, True }:
+                        yield None
+                     elif yield_unparseable:
+                        yield local_file
                else:
                   yield varstr ( local_file )
 


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-03 15:50 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-03 15:50 UTC (permalink / raw
  To: gentoo-commits

commit:     55bf1d09ba2bcb527cf953276a9c87415ee052a1
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep  3 15:42:42 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep  3 15:42:42 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=55bf1d09

HashPool: extend()

---
 roverlay/util/hashpool.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/roverlay/util/hashpool.py b/roverlay/util/hashpool.py
index 61d8336..29b61f5 100644
--- a/roverlay/util/hashpool.py
+++ b/roverlay/util/hashpool.py
@@ -83,6 +83,16 @@ class HashPool ( object ):
       self._jobs [backref] = HashJob ( filepath, hashdict )
    # --- end of add (...) ---
 
+   def extend ( self, iterable ):
+      for backref, filepath in iterable:
+         self._jobs [backref] = HashJob ( filepath, None )
+   # --- end of extend (...) ---
+
+   def extend_with_hashdict ( self, iterable ):
+      for backref, filepath, hashdict in iterable:
+         self._jobs [backref] = HashJob ( filepath, hashdict )
+   # --- end of extend_with_hashdict (...) ---
+
    def get_executor ( self ):
       return self.executor_cls ( self.max_workers )
    # --- end of get_executor (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-05  9:25 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-05  9:25 UTC (permalink / raw
  To: gentoo-commits

commit:     a828adc6a59516779cfc1178da4669379c01a4c7
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Sep  5 09:04:46 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Sep  5 09:04:46 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=a828adc6

roverlay/util/objects: PersistentContent

an object with a "has changes" ('dirty') flag

---
 roverlay/util/objects.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index 5ba1ccb..a20b707 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -349,3 +349,26 @@ class ObjectView ( object ):
    # --- end of update (...) ---
 
 # --- end of ObjectView ---
+
+
+class PersistentContent ( object ):
+
+   def __init__ ( self, *args, **kwargs ):
+      super ( PersistentContent, self ).__init__()
+      self._dirty = False
+   # --- end of __init__ (...) ---
+
+   @property
+   def dirty ( self ):
+      return self._dirty
+   # --- end of dirty (...) ---
+
+   def set_dirty ( self ):
+      self._dirty = True
+   # --- end of set_dirty (...) ---
+
+   def reset_dirty ( self, value=False ):
+      self._dirty = bool ( value )
+   # --- end of reset_dirty (...) ---
+
+# --- end of PersistentContent ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-05  9:25 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-05  9:25 UTC (permalink / raw
  To: gentoo-commits

commit:     bb0ea5c5eac6d13e68915d3bd445659fe026e982
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Sep  5 09:07:19 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Sep  5 09:07:19 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=bb0ea5c5

roverlay/util/fileio: TextFile class

object representing a text file (with a 'dirty' flag)

---
 roverlay/util/fileio.py | 184 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 184 insertions(+)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index a8d2e01..151e7f1 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -8,8 +8,12 @@ import gzip
 import bz2
 import mimetypes
 import sys
+import os.path
+import shutil
+import errno
 
 import roverlay.util.common
+import roverlay.util.objects
 import roverlay.strutil
 from roverlay.strutil import bytes_try_decode
 
@@ -145,3 +149,183 @@ def write_text_file (
 
    return True
 # --- end of write_text_file (...) ---
+
+
+class TextFile ( roverlay.util.objects.PersistentContent ):
+
+   READ_PREPARSE   = True
+   READ_TRY_HARDER = True
+
+   def __init__ ( self, filepath, compression=None ):
+      super ( TextFile, self ).__init__()
+
+      self._filepath    = None
+      self._compression = None
+
+      self.first_line   = None
+      self.lino         = None
+
+      self.set_filepath ( filepath )
+      self.set_compression ( compression )
+   # --- end of __init__ (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def parse_line ( self, line ):
+      return True
+   # --- end of parse_line (...) ---
+
+   def parse_header_line ( self, line ):
+      return self.parse_line ( line )
+   # --- end of parse_header_line (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def gen_lines ( self ):
+      #yield ...
+      return
+   # --- end of gen_lines (...) ---
+
+   def start_reading ( self ):
+      pass
+   # --- end of start_reading (...) ---
+
+   def done_reading ( self ):
+      pass
+   # --- end of done_reading (...) ---
+
+   def set_filepath ( self, filepath ):
+      self._filepath = filepath
+   # --- end of set_filepath (...) ---
+
+   def set_compression ( self, compression ):
+      if not compression or compression in { 'default', 'none' }:
+         self._compression = None
+      elif compression in SUPPORTED_COMPRESSION:
+         self._compression = compression
+      else:
+         raise ValueError (
+            "unknown file compression {!r}".format ( compression )
+         )
+   # --- end of set_compression (...) ---
+
+   def backup_file ( self, destfile=None, move=False, ignore_missing=False ):
+      """Creates a backup copy of the file.
+
+      arguments:
+      * destfile       -- backup file path
+                          Defaults to <dfile> + '.bak'.
+      * move           -- move dfile (instead of copying)
+      * ignore_missing -- return False if file does not exist instead of
+                          raising an exception. Defaults to False.
+      """
+      dest = destfile or ( self._filepath + '.bak' )
+      try:
+         roverlay.util.dodir ( os.path.dirname ( dest ), mkdir_p=True )
+         if move:
+            shutil.move ( self._filepath, dest )
+            return True
+         else:
+            shutil.copyfile ( self._filepath, dest )
+            return True
+      except IOError as ioerr:
+         if ignore_missing and ioerr.errno == errno.ENOENT:
+            return False
+         else:
+            raise
+   # --- end of backup_file (...) ---
+
+   def backup_and_write ( self,
+      destfile=None, backup_file=None,
+      force=False, move=False, ignore_missing=True
+   ):
+      """Creates a backup copy of the distmap file and writes the modified
+      distmap afterwards.
+
+      arguments:
+      * destfile       -- file path to be written (defaults to self._filepath)
+      * backup_file    -- backup file path (see backup_file())
+      * force          -- enforce writing even if file content not modified
+      * move           -- move distmap (see backup_file())
+      * ignore_missing -- do not fail if the file does not exist when
+                          creating a backup copy.
+                          Defaults to True.
+      """
+      if force or self.dirty:
+         self.backup_file (
+            destfile=backup_file, move=move, ignore_missing=ignore_missing
+         )
+         return self.write ( filepath=destfile, force=True )
+      else:
+         return True
+   # --- end of backup_and_write (...) ---
+
+   def file_exists ( self ):
+      """Returns True if the file exists, else False."""
+      return os.path.isfile ( self._filepath )
+   # --- end of file_exists (...) ---
+
+   def try_read ( self, *args, **kwargs ):
+      """Tries to read the file."""
+      try:
+         self.read ( *args, **kwargs )
+      except IOError as ioerr:
+         if ioerr.errno == errno.ENOENT:
+            pass
+         else:
+            raise
+   # --- end of try_read (...) ---
+
+   def read ( self, filepath=None ):
+      """Reads the file.
+
+      arguments:
+      * filepath -- path to the distmap file (defaults to self.dbfile)
+      """
+      fpath = self._filepath if filepath is None else filepath
+
+      self.start_reading()
+
+      self.first_line = True
+      self.lino       = 0
+      for lino, line in enumerate (
+         read_text_file ( fpath,
+            preparse=self.READ_PREPARSE, try_harder=self.READ_TRY_HARDER
+         )
+      ):
+         self.lino = lino
+         if self.first_line:
+            self.first_line = False
+            # parse_header_line() can reset first_line to True
+            self.parse_header_line ( line )
+         else:
+            self.parse_line ( line )
+
+      if filepath is not None:
+         self.set_dirty()
+
+      self.done_reading()
+   # --- end of read (...) ---
+
+   def write ( self, filepath=None, force=False ):
+      """Writes the file.
+
+      arguments:
+      * filepath -- path to the file to be written (defaults to self._filepath)
+      * force    -- enforce writing even if file content not modified
+      """
+      if force or self.dirty or filepath is not None:
+         fpath = self._filepath if filepath is None else filepath
+         write_text_file (
+            fpath, self.gen_lines(),
+            compression=self._compression, create_dir=True
+         )
+
+         if filepath is None:
+            self.reset_dirty()
+         # else keep
+
+         return True
+      else:
+         return False
+   # --- end of write (...) ---
+
+# --- end of TextFile ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-05 10:24 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-05 10:24 UTC (permalink / raw
  To: gentoo-commits

commit:     8d46adb610ed44be2d32848235671db0f2145668
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Sep  5 10:15:29 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Sep  5 10:15:29 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=8d46adb6

util/fileio.TextFile.try_read(): return true/false

---
 roverlay/util/fileio.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index 151e7f1..372cdd6 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -265,13 +265,18 @@ class TextFile ( roverlay.util.objects.PersistentContent ):
 
    def try_read ( self, *args, **kwargs ):
       """Tries to read the file."""
+      ret = None
       try:
          self.read ( *args, **kwargs )
       except IOError as ioerr:
          if ioerr.errno == errno.ENOENT:
-            pass
+            ret = False
          else:
             raise
+      else:
+         ret = True
+
+      return ret
    # --- end of try_read (...) ---
 
    def read ( self, filepath=None ):


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-10 14:40 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-10 14:40 UTC (permalink / raw
  To: gentoo-commits

commit:     86d4c55af7d46628a5a2204784ec9cb81abfe3bc
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep 10 14:24:03 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep 10 14:24:03 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=86d4c55a

roverlay.util, dodir(): optionally suppress log

---
 roverlay/util/common.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index 24008ad..30dd310 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -270,7 +270,7 @@ def sysnop ( nop_returns_success=True, format_str=None, old_formatting=False ):
    return None
 # --- end of sysnop (...) ---
 
-def dodir ( directory, mkdir_p=False, **makedirs_kw ):
+def dodir ( directory, mkdir_p=False, log_exception=True, **makedirs_kw ):
    """Ensures that a directory exists (by creating it, if necessary).
 
    arguments:
@@ -289,8 +289,9 @@ def dodir ( directory, mkdir_p=False, **makedirs_kw ):
          os.mkdir ( directory )
 
       return True
-   except Exception as e:
-      LOGGER.exception ( e )
+   except OSError as e:
+      if log_exception:
+         LOGGER.exception ( e )
       return os.path.isdir ( directory )
 
 # --- end of dodir (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-12 16:36 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-12 16:36 UTC (permalink / raw
  To: gentoo-commits

commit:     ea52078df34aab6562e49a73844e295d934a440d
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Sep 12 16:29:57 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Sep 12 16:29:57 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=ea52078d

roverlay/util/objects, NoneRef: get_static()

---
 roverlay/util/objects.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index a20b707..5ba2d69 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -66,6 +66,16 @@ class SafeWeakRef ( weakref.ref ):
 class NoneRef ( object ):
    """A 'reference' to None (compat object)."""
 
+   __instance = None
+
+   @classmethod
+   def get_static ( cls, obj=None ):
+      assert obj is None
+      if cls.__instance is None:
+         cls.__instance = cls ( obj=obj )
+      return cls.__instance
+   # --- end of get_static (...) ---
+
    def __init__ ( self, obj=None ):
       super ( NoneRef, self ).__init__()
       assert obj is None
@@ -101,7 +111,7 @@ def get_object_ref ( obj ):
    * obj --
    """
    if obj is None:
-      return NoneRef()
+      return NoneRef.get_static()
    elif isinstance ( obj, ( SafeWeakRef, NoneRef, weakref.ref ) ):
       return obj
    elif hasattr ( obj, 'get_ref' ):


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-12 16:36 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-12 16:36 UTC (permalink / raw
  To: gentoo-commits

commit:     2cc79dc0280b25cfabdd8c5166a35f61ff17935c
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Sep 12 16:30:15 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Sep 12 16:30:15 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=2cc79dc0

roverlay/util/dictwalk: dictmerge()

Convert an iterable of iterables with non-unique keys into a dict with one list
per key.

E.g.
[ ( "a", 1, 2 ), ( "a", 2, 3 ), ( "b", 1, 2 ) ]
-> dict( "a": [(1,2),(2,3)], "b": [(1,2)] )

---
 roverlay/util/dictwalk.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/roverlay/util/dictwalk.py b/roverlay/util/dictwalk.py
index 52a8c61..0813d11 100644
--- a/roverlay/util/dictwalk.py
+++ b/roverlay/util/dictwalk.py
@@ -7,6 +7,27 @@
 import roverlay.util.namespace
 import roverlay.util.objects
 
+def dictmerge_inplace ( d, iterable, get_key=None, get_value=None ):
+   keyfunc = ( lambda x: x[0]  ) if get_key   is None else get_key
+   valfunc = ( lambda x: x[1:] ) if get_value is None else get_value
+
+   for item in iterable:
+      key = keyfunc ( item )
+      val = valfunc ( item )
+      entry = d.get ( key )
+      if entry is None:
+         d[key] = [ val ]
+      else:
+         #assert isinstance ( entry, list )
+         entry.append ( val )
+# --- end of dictmerge_inplace (...) ---
+
+def dictmerge ( iterable, dict_cls=dict, get_key=None, get_value=None ):
+   ret = dict_cls()
+   dictmerge_inplace ( ret, iterable, get_key=get_key, get_value=get_value )
+   return ret
+# --- end of dictmerge (...) ---
+
 
 def dictwalk_create_parent_v ( root, path, dict_create=None, cautious=True ):
    """Creates a dict tree structure using keys the given path. The last path


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-09-20 15:57 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-09-20 15:57 UTC (permalink / raw
  To: gentoo-commits

commit:     3ef843db7ccbdaecf9cab4fb4809ca99dec566e5
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Sep 20 14:46:27 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Sep 20 14:46:27 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=3ef843db

roverlay/util: python 2/3 wrapper for abc.ABCMeta

---
 roverlay/util/_abc2.py   | 13 +++++++++++++
 roverlay/util/_abc3.py   | 13 +++++++++++++
 roverlay/util/objects.py | 10 +++++++++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/roverlay/util/_abc2.py b/roverlay/util/_abc2.py
new file mode 100644
index 0000000..830ab8f
--- /dev/null
+++ b/roverlay/util/_abc2.py
@@ -0,0 +1,13 @@
+# R overlay -- compat module for creating abstract classes (python 2)
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+from abc import ABCMeta, abstractmethod
+
+__all__ = [ 'abstractmethod', 'AbstractObject', ]
+
+class AbstractObject ( object ):
+   __metaclass__ = ABCMeta
+# --- end of AbstractObject ---

diff --git a/roverlay/util/_abc3.py b/roverlay/util/_abc3.py
new file mode 100644
index 0000000..bcf0b0e
--- /dev/null
+++ b/roverlay/util/_abc3.py
@@ -0,0 +1,13 @@
+# R overlay -- compat module for creating abstract classes (python 3)
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+from abc import ABCMeta, abstractmethod
+
+__all__ = [ 'abstractmethod', 'AbstractObject', ]
+
+class AbstractObject ( object, metaclass=ABCMeta ):
+   pass
+# --- end of AbstractObject ---

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index 5ba2d69..d14733e 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -5,8 +5,16 @@
 # either version 2 of the License, or (at your option) any later version.
 
 import weakref
+import sys
 
-__all__ = [ 'get_object_ref', 'abstractmethod', 'not_implemented', ]
+if sys.hexversion >= 0x3000000:
+   from ._abc3 import AbstractObject
+else:
+   from ._abc2 import AbstractObject
+
+__all__ = [
+   'get_object_ref', 'abstractmethod', 'not_implemented', 'AbstractObject',
+]
 
 
 class ObjectDisappeared ( Exception ):


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2013-12-11 18:40 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2013-12-11 18:40 UTC (permalink / raw
  To: gentoo-commits

commit:     04b61e393616a3a731bb794e60d832ca98102f68
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Dec 11 17:46:57 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Dec 11 17:46:57 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=04b61e39

roverlay/util/ebuildparser: add __main__ function

This allows to test the SRC_URI parser with
 PYTHONPATH="${PWD}" python ./roverlay/util/ebuildparser.py /path/to/*.ebuild
from roverlay's toplevel dir.

---
 roverlay/util/ebuildparser.py | 56 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 8 deletions(-)

diff --git a/roverlay/util/ebuildparser.py b/roverlay/util/ebuildparser.py
index 8c16dd5..3da58d9 100644
--- a/roverlay/util/ebuildparser.py
+++ b/roverlay/util/ebuildparser.py
@@ -217,7 +217,7 @@ class SrcUriParser ( EbuildParser ):
             yield entry
    # --- end of _iterate (...) ---
 
-   def iter_local_files (
+   def iter_entries_and_local_files (
       self, ignore_unparseable=False, yield_unparseable=False
    ):
       def convert_chars_with_vars ( text ):
@@ -263,12 +263,12 @@ class SrcUriParser ( EbuildParser ):
             if '$' in local_file:
                if ignore_unparseable:
                   try:
-                     yield varstr ( local_file )
+                     yield ( entry, varstr ( local_file ) )
                   except ParserException:
                      if yield_unparseable in { None, True }:
-                        yield None
+                        yield ( entry, None )
                      elif yield_unparseable:
-                        yield local_file
+                        yield ( entry, local_file )
 
                   except ( KeyError, IndexError ) as err:
                      # FIXME debug print
@@ -278,14 +278,24 @@ class SrcUriParser ( EbuildParser ):
                         )
                      )
                      if yield_unparseable in { None, True }:
-                        yield None
+                        yield ( entry, None )
                      elif yield_unparseable:
-                        yield local_file
+                        yield ( entry, local_file )
                else:
-                  yield varstr ( local_file )
+                  yield ( entry, varstr ( local_file ) )
 
             else:
-               yield local_file
+               yield ( entry, local_file )
+   # --- end of iter_entries_and_local_files (...) ---
+
+   def iter_local_files (
+      self, ignore_unparseable=False, yield_unparseable=False
+   ):
+      for entry, local_file in self.iter_entries_and_local_files (
+         ignore_unparseable=ignore_unparseable,
+         yield_unparseable=yield_unparseable
+      ):
+         yield local_file
    # --- end of iter_local_files (...) ---
 
    def __iter__ ( self ):
@@ -302,3 +312,33 @@ class SrcUriParser ( EbuildParser ):
    # --- end of read (...) ---
 
 # --- end of SrcUriParser ---
+
+
+if __name__ == '__main__':
+   import os
+   import sys
+
+   get_basename = os.path.basename
+
+   files = sys.argv[1:]
+   if files:
+      name_width = min ( 50, max ( len(get_basename(s)) for s in files ) )
+      for f in files:
+         if f == '-':
+            raise Exception ( "input from stdin is not supported." )
+         else:
+            parser = SrcUriParser.from_file ( f )
+            for entry, local_file in parser.iter_entries_and_local_files():
+               print (
+                  "{name:<{l}} : {uri!s} => {locfile!s}".format (
+                     name=get_basename(f), uri=entry, locfile=local_file,
+                     l=name_width
+                  )
+               )
+   else:
+      sys.stderr.write (
+         "Usage: {prog} <ebuild file>...\n".format (
+            prog=os.path.basename ( sys.argv[0] )
+         )
+      )
+# --- end of __main__ (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2014-01-25 18:14 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2014-01-25 18:14 UTC (permalink / raw
  To: gentoo-commits

commit:     e1dd305c2b73b427e3d5c1a8a05d96f852c704a0
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Sat Jan 25 18:00:41 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Sat Jan 25 18:00:41 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=e1dd305c

roverlay/util/ebuildparser: fix typo

foreach_str(), not str_foreach()

Introduced by 326a51e15095d3062f0e6b4b39ea27b247324ea9.

---
 roverlay/util/ebuildparser.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/roverlay/util/ebuildparser.py b/roverlay/util/ebuildparser.py
index 2ce8d9f..e3b926c 100644
--- a/roverlay/util/ebuildparser.py
+++ b/roverlay/util/ebuildparser.py
@@ -147,7 +147,7 @@ class EbuildParser ( object ):
 
       if self.unquote_value:
          return {
-            varname: roverlay.strutil.str_foreach (
+            varname: roverlay.strutil.foreach_str (
                roverlay.strutil.unquote, value
             ) for varname, value in data.items()
          }


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2014-02-16 16:30 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2014-02-16 16:30 UTC (permalink / raw
  To: gentoo-commits

commit:     8a191aee34c82c223612d3c3a158f76258f1147c
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Sun Feb 16 16:24:19 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Sun Feb 16 16:27:44 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=8a191aee

roverlay/util/counter: be compatible with python 2

Fixes d95efe157ea2a9e02eac805ae41fd340ac5e117c

---
 roverlay/util/counter.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/roverlay/util/counter.py b/roverlay/util/counter.py
index 2303863..0fde45e 100644
--- a/roverlay/util/counter.py
+++ b/roverlay/util/counter.py
@@ -65,6 +65,11 @@ class AbstractCounter ( object ):
       return self.inc()
    # --- end of __next__ (...) ---
 
+   def next ( self ):
+      # python 2
+      return self.__next__()
+   # --- end of next (...) ---
+
    def __iter__ ( self ):
       return self
    # --- end of __iter__ (...) ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2014-04-01 16:38 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2014-04-01 16:38 UTC (permalink / raw
  To: gentoo-commits

commit:     ea0f8cbcc126a53bc450b4161c8910fe1d9af778
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Mar 31 18:30:18 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Apr  1 16:36:36 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=ea0f8cbc

fileio: catch EOFError

---
 roverlay/util/fileio.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index dc96119..804aa9f 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -76,7 +76,7 @@ def read_text_file ( filepath, preparse=None, try_harder=True ):
                # safely read first line only
                line    = next ( creader )
 
-            except StopIteration:
+            except ( StopIteration, EOFError ):
                # empty file (?)
                CH.close()
                return


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2014-06-05 22:09 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2014-06-05 22:09 UTC (permalink / raw
  To: gentoo-commits

commit:     728b5d1c32773422f0b3e658d16116f6883ee9d2
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed May  7 01:21:28 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed May  7 01:21:28 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=728b5d1c

roverlay/util/fileio, write_text_file: accept str

---
 roverlay/util/fileio.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index 804aa9f..d4019d7 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -128,6 +128,7 @@ def write_text_file (
    newline='\n'
 ):
    compress_open = get_compress_open ( compression ) if compression else None
+   lines_iter    = ( lines, ) if isinstance ( lines, str ) else lines
 
    if create_dir:
       roverlay.util.common.dodir_for_file ( filepath )
@@ -135,7 +136,7 @@ def write_text_file (
    if compress_open:
       NL = newline.encode()
       with compress_open ( filepath, mode.rstrip ( 'tu' ) ) as CH:
-         for line in lines:
+         for line in lines_iter:
             CH.write ( str ( line ).encode() )
             if append_newlines:
                CH.write ( NL )
@@ -144,7 +145,7 @@ def write_text_file (
             CH.write ( NL )
    else:
       with open ( filepath, mode ) as FH:
-         for line in lines:
+         for line in lines_iter:
             FH.write ( str ( line ) )
             if append_newlines:
                FH.write ( newline )


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2014-06-05 22:09 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2014-06-05 22:09 UTC (permalink / raw
  To: gentoo-commits

commit:     7f1425b229c93c7b13bef1b2d76b34e2a9e2476c
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri May 23 18:48:51 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri May 23 19:59:38 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=7f1425b2

fileio: workaround for small plain text files

Some text files (containing only a few chars) seem to be xz-readable.

---
 roverlay/util/fileio.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index d4019d7..be81ef0 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -79,7 +79,12 @@ def read_text_file ( filepath, preparse=None, try_harder=True ):
             except ( StopIteration, EOFError ):
                # empty file (?)
                CH.close()
-               return
+               CH = None
+               # *** FIXME: workaround ***
+               # retry as normal file,
+               #  EOFError may be caused by small plain text files, too
+               # COULDFIX: ?empty compressed files?
+               #return
 
             except IOError as ioerr:
                # failed to open (gzip, bzip2)


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2014-08-23 19:03 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2014-08-23 19:03 UTC (permalink / raw
  To: gentoo-commits

commit:     cb26f0710d0b0559fb0e596e78d308c015c508da
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Sat Aug 23 17:19:53 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Sat Aug 23 17:19:53 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=cb26f071

minor cleanup

---
 roverlay/util/dictwalk.py | 4 ++--
 roverlay/util/objects.py  | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/roverlay/util/dictwalk.py b/roverlay/util/dictwalk.py
index 0813d11..9408623 100644
--- a/roverlay/util/dictwalk.py
+++ b/roverlay/util/dictwalk.py
@@ -30,8 +30,8 @@ def dictmerge ( iterable, dict_cls=dict, get_key=None, get_value=None ):
 
 
 def dictwalk_create_parent_v ( root, path, dict_create=None, cautious=True ):
-   """Creates a dict tree structure using keys the given path. The last path
-   element will not be created.
+   """Creates a dict tree structure using keys from the given path.
+   The last path element will not be created.
 
    Returns a 3-tuple
       ( <parent of the last path element>,

diff --git a/roverlay/util/objects.py b/roverlay/util/objects.py
index 9c73749..0f2a2da 100644
--- a/roverlay/util/objects.py
+++ b/roverlay/util/objects.py
@@ -59,13 +59,13 @@ class SafeWeakRef ( weakref.ref ):
 
    def __repr__ ( self ):
       obj = self.deref_unsafe()
-      if obj:
-         return "<{} at 0x{:x} to {!r} at 0x{:x}>".format (
+      if obj is not None:
+         return "<{} at {:#x} to {!r} at {:#x}>".format (
             self.__class__.__name__, id ( self ),
             obj.__class__.__name__, id ( obj )
          )
       else:
-         return "<{} at 0x{:x} to None>".format (
+         return "<{} at {:#x} to None>".format (
             self.__class__.__name__, id ( self )
          )
    # --- end of __repr__ (...) ---
@@ -109,7 +109,7 @@ class NoneRef ( object ):
    __nonzero__ = __bool__
 
    def __repr__ ( self ):
-      return "<NoneRef at 0x{:x}>".format ( id ( self ) )
+      return "<NoneRef at {:#x}>".format ( id ( self ) )
    # --- end of __repr__ (...) ---
 
 # --- end of NoneRef ---


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2015-01-26 17:41 André Erdmann
  0 siblings, 0 replies; 41+ messages in thread
From: André Erdmann @ 2015-01-26 17:41 UTC (permalink / raw
  To: gentoo-commits

commit:     686884ffec582aa43264b5f05637bf8d861d30c6
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Dec 15 22:59:37 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Dec 15 22:59:37 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=686884ff

roverlay/util/common: doc typo

---
 roverlay/util/common.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index 92c0183..dffe313 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -200,9 +200,9 @@ def keepenv_v ( to_keep ):
    env_item ::= <env_key> | tuple ( <env_key> [, <env_key>], <fallback> )
 
    example:
-   keepenv (
+   keepenv_v (
       ( 'PATH', '/bin:/usr/bin' ), ( ( 'USER', 'LOGNAME' ), 'user' ),
-      PORTDIR
+      'PORTDIR'
    )
    keeps PATH (with fallback value if unset), USER/LOGNAME (/w fallback) and
    PORTDIR (only if set).


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/
@ 2016-07-07  4:19 Benda XU
  0 siblings, 0 replies; 41+ messages in thread
From: Benda XU @ 2016-07-07  4:19 UTC (permalink / raw
  To: gentoo-commits

commit:     9eade4e4950fbd28c6b4e07440f765248883ee58
Author:     Benda Xu <heroxbd <AT> gentoo <DOT> org>
AuthorDate: Thu Jul  7 04:19:04 2016 +0000
Commit:     Benda XU <heroxbd <AT> gentoo <DOT> org>
CommitDate: Thu Jul  7 04:19:04 2016 +0000
URL:        https://gitweb.gentoo.org/proj/R_overlay.git/commit/?id=9eade4e4

util/fileio.py: do not skip the first line.

 roverlay/util/fileio.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index be81ef0..72d8a9c 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -103,6 +103,7 @@ def read_text_file ( filepath, preparse=None, try_harder=True ):
                raise
 
             else:
+               yield line
                # read remaining lines
                for line in creader:
                   yield line


^ permalink raw reply related	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2016-07-07  4:19 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-16  6:44 [gentoo-commits] proj/R_overlay:master commit in: roverlay/util/ André Erdmann
  -- strict thread matches above, loose matches on Subject: below --
2016-07-07  4:19 Benda XU
2015-01-26 17:41 André Erdmann
2014-08-23 19:03 André Erdmann
2014-06-05 22:09 André Erdmann
2014-06-05 22:09 André Erdmann
2014-04-01 16:38 André Erdmann
2014-02-16 16:30 André Erdmann
2014-01-25 18:14 André Erdmann
2013-12-11 18:40 André Erdmann
2013-09-20 15:57 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-05 10:24 André Erdmann
2013-09-05  9:25 André Erdmann
2013-09-05  9:25 André Erdmann
2013-09-03 15:50 André Erdmann
2013-09-03 15:50 André Erdmann
2013-09-03 12:21 André Erdmann
2013-09-03  8:35 André Erdmann
2013-09-02 16:21 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-29 13:53 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-23 13:51 André Erdmann
2013-08-22  9:01 André Erdmann
2013-08-13  8:56 André Erdmann
2013-08-01 12:44 André Erdmann
2013-07-30 18:40 André Erdmann
2013-07-29 14:56 André Erdmann
2013-07-23 14:57 André Erdmann
2013-07-23 14:57 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 14:57 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-18 19:25 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23  7:51 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-12 13:57 André Erdmann
2013-06-20 23:40 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-22 15:24 ` [gentoo-commits] proj/R_overlay:master " André Erdmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox