public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/parser/context/, roverlay/depres/, roverlay/tools/, ...
@ 2013-12-11 18:40 André Erdmann
  0 siblings, 0 replies; only message in thread
From: André Erdmann @ 2013-12-11 18:40 UTC (permalink / raw
  To: gentoo-commits

commit:     af769bd915d90b6bf3c7523b5cf0ce164a24233e
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Dec 11 18:30:38 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Dec 11 18:31:55 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=af769bd9

minor fixes

This commit fixes some issues, most of them are theoretical only, e.g. variables
that might be accessed before assignment in with/try..except blocks.

---
 roverlay/argutil.py                           |  2 +-
 roverlay/config/loader.py                     |  4 ++--
 roverlay/defaultscript.py                     |  7 +++++--
 roverlay/depres/listeners.py                  |  4 +++-
 roverlay/digest.py                            |  2 ++
 roverlay/overlay/creator.py                   |  2 +-
 roverlay/overlay/pkgdir/packagedir_base.py    |  3 ++-
 roverlay/packagerules/parser/context/match.py |  6 ++++--
 roverlay/remote/rsync.py                      | 19 ++++++++++---------
 roverlay/tools/shenv.py                       |  7 ++++---
 roverlay/util/mapreader.py                    |  1 +
 11 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/roverlay/argutil.py b/roverlay/argutil.py
index b8f8363..093d7c9 100644
--- a/roverlay/argutil.py
+++ b/roverlay/argutil.py
@@ -106,8 +106,8 @@ def is_fs_file_or_void ( value ):
       return ''
 
 def is_config_opt ( value ):
+   k = value.partition ( '=' ) [0]
    try:
-      k = value.partition ( '=' ) [0]
       map_entry = deref_entry_safe ( k )
    except KeyError:
       raise argparse.ArgumentTypeError (

diff --git a/roverlay/config/loader.py b/roverlay/config/loader.py
index 6d94214..f5d28d8 100644
--- a/roverlay/config/loader.py
+++ b/roverlay/config/loader.py
@@ -366,13 +366,13 @@ class ConfigLoader ( object ):
          * val --
          """
          if not val is None:
-            to_check = str ( val ) . lower ()
+            to_check = str ( val ).lower()
             if to_check in [ 'y', 'yes', '1', 'true', 'enabled', 'on' ]:
                return 1
             elif to_check in [ 'n', 'no', '0', 'false', 'disabled', 'off' ]:
                return 0
 
-         self.logger.warning ( to_check + " is not a valid yesno value." )
+         self.logger.warning ( str(val) + " is not a valid yesno value." )
          return -1
       # --- end of yesno (...) ---
 

diff --git a/roverlay/defaultscript.py b/roverlay/defaultscript.py
index 7e36394..6c8ae99 100644
--- a/roverlay/defaultscript.py
+++ b/roverlay/defaultscript.py
@@ -200,6 +200,9 @@ def run_overlay_create ( env ):
       return
    run_sync ( env )
 
+   repo_list       = None
+   overlay_creator = None
+
    try:
       repo_list       = env.get_repo_list()
       overlay_creator = env.get_overlay_creator()
@@ -263,7 +266,7 @@ def run_overlay_create ( env ):
       else:
          raise
    finally:
-      if 'overlay_creator' in locals() and not overlay_creator.closed:
+      if overlay_creator is not None and not overlay_creator.closed:
          # This is important 'cause it unblocks remaining ebuild creation
          # jobs/threads, specifically waiting EbuildJobChannels in depres.
          # It also writes the deps_unresolved file
@@ -386,9 +389,9 @@ def run_apply_package_rules ( env ):
       tristate_counter ( receive_package )
    )
 
+   FH_SHARED = True
    try:
       if dump_file == "-":
-         FH_SHARED = True
          FH = sys.stdout
       else:
          FH_SHARED = False

diff --git a/roverlay/depres/listeners.py b/roverlay/depres/listeners.py
index dd7003c..7234b53 100644
--- a/roverlay/depres/listeners.py
+++ b/roverlay/depres/listeners.py
@@ -88,6 +88,7 @@ class SetFileListener ( DependencyResolverListener ):
    # --- end of _event (...) ---
 
    def write ( self, sort_entries=True ):
+      fh = None
       try:
          fdir = os.path.dirname ( self._file )
          if not os.path.isdir ( fdir ):
@@ -105,7 +106,8 @@ class SetFileListener ( DependencyResolverListener ):
 
          fh.close()
       finally:
-         if 'fh' in locals(): fh.close()
+         if fh:
+            fh.close()
    # --- end of write (...) ---
 
    def close ( self ):

diff --git a/roverlay/digest.py b/roverlay/digest.py
index 49625ee..99e094b 100644
--- a/roverlay/digest.py
+++ b/roverlay/digest.py
@@ -87,6 +87,7 @@ def _generic_obj_hash (
 def _generic_file_obj_hash (
    hashobj, filepath, binary_digest=False, blocksize=DEFAULT_BLOCKSIZE
 ):
+   ret = None
    with open ( filepath, 'rb' ) as fh:
       ret = _generic_obj_hash ( hashobj, fh, binary_digest, blocksize )
    return ret
@@ -130,6 +131,7 @@ def multihash_file ( filepath, digest_types, **kwargs ):
    * **kwargs     -- passed to multihash()
    """
    if digest_types:
+      hashdict = None
       with open ( filepath, mode='rb' ) as fh:
          hashdict = multihash ( fh, digest_types, **kwargs )
       return hashdict

diff --git a/roverlay/overlay/creator.py b/roverlay/overlay/creator.py
index 4a52e86..ea623e6 100644
--- a/roverlay/overlay/creator.py
+++ b/roverlay/overlay/creator.py
@@ -277,8 +277,8 @@ class OverlayCreator ( object ):
       """Starts ebuild creation and waits until done."""
       self._runlock.acquire()
       self.stats.creation_time.begin ( "setup" )
+      allow_reraise = True
       try:
-         allow_reraise = True
          self._work_done.wait()
          self.depresolver.reload_pools()
 

diff --git a/roverlay/overlay/pkgdir/packagedir_base.py b/roverlay/overlay/pkgdir/packagedir_base.py
index 27f395c..12ab292 100644
--- a/roverlay/overlay/pkgdir/packagedir_base.py
+++ b/roverlay/overlay/pkgdir/packagedir_base.py
@@ -899,6 +899,7 @@ class PackageDirBase ( roverlay.overlay.base.OverlayObject ):
          * (shared_fh from write_ebuilds())
          """
          _success = False
+         fh       = None
          try:
             fh = open ( efile, 'w' ) if shared_fh is None else shared_fh
             if ebuild_header is not None:
@@ -911,7 +912,7 @@ class PackageDirBase ( roverlay.overlay.base.OverlayObject ):
          except IOError as e:
             self.logger.exception ( e )
          finally:
-            if shared_fh is None and 'fh' in locals() and fh:
+            if shared_fh is None and fh:
                fh.close()
 
          return _success

diff --git a/roverlay/packagerules/parser/context/match.py b/roverlay/packagerules/parser/context/match.py
index 6ff55ad..55328fb 100644
--- a/roverlay/packagerules/parser/context/match.py
+++ b/roverlay/packagerules/parser/context/match.py
@@ -195,8 +195,10 @@ class RuleMatchContext (
                # child RuleMatchContexts as inactive
                self.get_nested()._active = False
 
-            argv = s.split ( None )
-            argc = len ( argv )
+            argv  = s.split ( None )
+            argc  = len ( argv )
+            op    = None
+            value = None
 
 
             match_type = self.KEYWORDS_MATCH.get ( argv [0], None )

diff --git a/roverlay/remote/rsync.py b/roverlay/remote/rsync.py
index 4ba9ab7..85cbde7 100644
--- a/roverlay/remote/rsync.py
+++ b/roverlay/remote/rsync.py
@@ -132,20 +132,18 @@ class RsyncRepo ( BasicRepo ):
       # --- end of waitfor (...) ---
 
       retcode = None
+      proc    = None
 
       try:
-
          rsync_cmd = self._rsync_argv()
-
          util.dodir ( self.distdir, mkdir_p=True )
-
          self.logger.debug ( 'running rsync cmd: ' + ' '.join ( rsync_cmd ) )
 
          retry_count = 0
 
-         proc = subprocess.Popen ( rsync_cmd, env=RSYNC_ENV )
-         retcode = waitfor ( proc )
-         del proc
+         proc        = subprocess.Popen ( rsync_cmd, env=RSYNC_ENV )
+         retcode     = waitfor ( proc )
+         proc        = None
 
          while retcode in RETRY_ON_RETCODE and retry_count < MAX_RSYNC_RETRY:
             # this handles retcodes like
@@ -159,9 +157,9 @@ class RsyncRepo ( BasicRepo ):
                )
             )
 
-            proc = subprocess.Popen ( rsync_cmd, env=RSYNC_ENV )
+            proc    = subprocess.Popen ( rsync_cmd, env=RSYNC_ENV )
             retcode = waitfor ( proc )
-            del proc
+            proc    = None
 
          if retcode == 0:
             self._set_ready ( is_synced=True )
@@ -169,10 +167,13 @@ class RsyncRepo ( BasicRepo ):
 
 
       except KeyboardInterrupt:
+         # maybe add terminate/kill code here,
+         # similar to roverlay.tools.shenv->run_script()
+         #
          sys.stderr.write (
             "\nKeyboard interrupt - waiting for rsync to exit...\n"
          )
-         if 'proc' in locals() and proc is not None:
+         if proc is not None:
             proc.communicate()
             retcode = proc.returncode
          else:

diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index a669907..a136bc4 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -415,8 +415,9 @@ def run_script (
 #   if _SHELL_INTPR is None:
 #      _SHELL_INTPR = roverlay.config.get ( 'SHELL_ENV.shell', '/bin/sh' )
 
-   my_logger = logger or LOGGER
-   my_env    = get_env ( phase )
+   my_logger   = logger or LOGGER
+   my_env      = get_env ( phase )
+   script_call = None
 
    try:
       script_call = subprocess.Popen (
@@ -431,7 +432,7 @@ def run_script (
 
       output = script_call.communicate()
    except:
-      if 'script_call' in locals():
+      if script_call is not None:
          try:
             script_call.terminate()
             time.sleep ( 1 )

diff --git a/roverlay/util/mapreader.py b/roverlay/util/mapreader.py
index 1c398a7..36f4ba7 100644
--- a/roverlay/util/mapreader.py
+++ b/roverlay/util/mapreader.py
@@ -151,6 +151,7 @@ class MapFileParser ( object ):
    # --- end of read_lines (...) ---
 
    def read_file ( self, filepath, handle_compressed=True ):
+      ret = None
       try:
          if handle_compressed:
             ret = self.read_lines (


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-12-11 18:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-11 18:40 [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/parser/context/, roverlay/depres/, roverlay/tools/, André Erdmann

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