[csw-devel] SF.net SVN: gar:[18039] csw/mgar/gar/v2/lib/python/makeStdLibDb.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu May 17 18:24:54 CEST 2012


Revision: 18039
          http://gar.svn.sourceforge.net/gar/?rev=18039&view=rev
Author:   wahwah
Date:     2012-05-17 16:24:53 +0000 (Thu, 17 May 2012)
Log Message:
-----------
makeStdLibDb: Refactoring

Instead of copy/pasting the code, using a loop over a list of paths.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/makeStdLibDb.py

Modified: csw/mgar/gar/v2/lib/python/makeStdLibDb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/makeStdLibDb.py	2012-05-17 16:19:31 UTC (rev 18038)
+++ csw/mgar/gar/v2/lib/python/makeStdLibDb.py	2012-05-17 16:24:53 UTC (rev 18039)
@@ -5,7 +5,7 @@
 
 """
 
-from os import listdir, chdir, getcwd
+import os
 import re
 import cjson
 
@@ -13,32 +13,20 @@
 
 def buildStdlibList():
   liblst = ['libjawt.so']
-  cwd = getcwd()
-  chdir('/usr/lib')
-  for lib in listdir('.'):
-  if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
-    liblst.append(lib)
-  chdir('/usr/dt/lib')
-  for lib in listdir('.'):
-  if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
-      if not lib in liblst:
-          liblst.append(lib)
-  chdir('/usr/openwin/lib')
-  for lib in listdir('.'):
-  if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
-      if not lib in liblst:
-          liblst.append(lib)
-  chdir('/usr/X11/lib')
-  for lib in listdir('.'):
-  if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
-      if not lib in liblst:
-          liblst.append(lib)
-  chdir('/usr/ucblib')
-  for lib in listdir('.'):
-  if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
-      if not lib in liblst:
-          liblst.append(lib)
-  chdir(cwd)
-  with open(fnLiblst,'w') as fd:
-  fd.write(cjson.encode(liblst))
-  fd.close()
+  cwd_save = os.getcwd()
+  std_locations = (
+      '/usr/lib',
+      '/usr/dt/lib',
+      '/usr/openwin/lib',
+      '/usr/X11/lib',
+      '/usr/ucblib',
+  )
+  for libdir in std_locations:
+    os.chdir(libdir)
+    for lib in os.listdir('.'):
+      if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
+        liblst.append(lib)
+  os.chdir(cwd_save)
+  with open(fnLiblst, 'w') as fd:
+    fd.write(cjson.encode(liblst))
+    fd.close()

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list