changeset 435:5443c5d5ed8c

fixes to ls
author catherine@dellzilla
date Wed, 27 Jan 2010 16:30:05 -0500
parents 8e822859e3a4
children f441f2eb52e0
files sqlpython/connections.py sqlpython/sqlpyPlus.py
diffstat 2 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/connections.py	Wed Jan 27 10:40:40 2010 -0500
+++ b/sqlpython/connections.py	Wed Jan 27 16:30:05 2010 -0500
@@ -12,14 +12,19 @@
         self.dbobj = dbobj
         self.type = str(type(self.dbobj)).split('.')[-1].lower().strip("'>")
         self.path = '%s/%s' % (self.type, self.fullname)
-        #self.type_path = '%s/' % self.dbobj.type
         (self.owner, self.unqualified_name) = self.fullname.split('.')
+        self.unqualified_path = '%s/%s' % (self.type, self.unqualified_name)
         self.owner = self.owner.lower()
     def match_pattern(self, pattern, specific_owner=None):
-        return ( pattern.match(self.fullname) or 
-                  pattern.match(self.type) or 
-                  ((not specific_owner) and pattern.match(self.unqualified_name)) or
-                  (specific_owner and (self.owner == specific_owner.lower()) and pattern.match(self.unqualified_name)) )
+        right_owner = (not specific_owner) or (self.owner == specific_owner.lower())
+        if not pattern:
+            return right_owner        
+        compiled = re.compile(pattern, re.IGNORECASE)            
+        if r'\.' in pattern:
+            return compiled.match(self.fullname) or compiled.match(self.path)
+        return right_owner and (compiled.match(self.type) or 
+                                 compiled.match(self.unqualified_name) or
+                                 compiled.match(self.unqualified_path))
         
 class GeraldPlaceholder(object):
     current = False
--- a/sqlpython/sqlpyPlus.py	Wed Jan 27 10:40:40 2010 -0500
+++ b/sqlpython/sqlpyPlus.py	Wed Jan 27 16:30:05 2010 -0500
@@ -982,7 +982,8 @@
     def do_find(self, arg, opts):
         """Finds argument in source code or (with -c) in column definitions."""
               
-        seek = self._regex_form_of_search_pattern(arg, exact=opts.col)
+        seek = re.compile(self._regex_form_of_search_pattern(arg, exact=opts.col),
+                          re.IGNORECASE)
         qualified = opts.get('all')
         for descrip in self._matching_database_objects('*', opts):
             if opts.col:
@@ -1213,8 +1214,6 @@
     standard_options = [
               all_users_option,
               make_option('-l', '--long', action='store_true', help='long descriptions'),
-              make_option('-i', '--immediate', action='store_true', help="force immediate refresh of metadata"),
-              #make_option('-t', '--timesort', action='store_true', help="Sort by last_ddl_time"),              
               make_option('-r', '--reverse', action='store_true', help="Reverse order while sorting")]
     
     @options(standard_options)
@@ -1515,12 +1514,16 @@
         
     def _regex_form_of_search_pattern(self, s, exact=False):
         if not s:
-            return re.compile('.*')
-        seekpatt = r'[/\\]?%s[/\\]?' % (
-            s.replace('*', '.*').replace('?','.').replace('%', '.*'))        
+            return '^[^\.]*$'
+        if '.' in s:
+            seekpatt = r'[/\\]?%s[/\\]?' % (
+                s.replace('*', '.*').replace('?','.').replace('%', '.*'))        
+        else:
+            seekpatt = r'[/\\]?%s[/\\]?' % (
+                s.replace('*', '[^\.]*').replace('?','[^\.]').replace('%', '[^\.]*'))                    
         if exact:
             seekpatt = '^%s$' % seekpatt
-        return re.compile(seekpatt, re.IGNORECASE)
+        return seekpatt
 
     def do_refresh(self, arg):
         '''Refreshes metadata for the specified schema; only required
@@ -1544,7 +1547,7 @@
         if not gerald_schema.complete:
             raise StopIteration
         
-        seek = self._regex_form_of_search_pattern(arg, opts.get('exact'))
+        seek = str(arg) and self._regex_form_of_search_pattern(arg, opts.get('exact'))
         for (name, descrip) in gerald_schema.descriptions.items():
             if descrip.match_pattern(seek, specific_owner = ((not opts.all) and username)):
                 yield descrip