Mercurial > sqlpython
changeset 390:3905ef976608
cleaning up extra print statements
author | catherine@DellZilla |
---|---|
date | Tue, 06 Oct 2009 16:20:16 -0400 |
parents | 53ee70e9417e |
children | 5fd44394d789 |
files | sqlpython/schemagroup.py sqlpython/sqlpyPlus.py sqlpython/sqlpython.py |
diffstat | 3 files changed, 35 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/schemagroup.py Tue Oct 06 15:16:47 2009 -0400 +++ b/sqlpython/schemagroup.py Tue Oct 06 16:20:16 2009 -0400 @@ -1,4 +1,4 @@ -import gerald, re, datetime, threading +import gerald, re, datetime, threading, time def gerald_connection_string(sqlalchemy_connection_string): return sqlalchemy_connection_string.split('/?mode=')[0].replace('//','/') @@ -17,30 +17,36 @@ self.schemagroup.schemas[self.owner] = self.schema class RefreshGroupThread(threading.Thread): - def __init__(self, schemas): + def __init__(self, schemas, minutes_between_refreshes): threading.Thread.__init__(self) + self.parent = threading.current_thread() self.schemas = schemas + self.minutes_between_refreshes = minutes_between_refreshes self.daemon = True def run(self): - self.schemas.refresh() + while self.parent.isAlive(): + self.schemas.refresh() + time.sleep(60 * self.minutes_between_refreshes) class SchemaDict(dict): schema_types = {'oracle': gerald.OracleSchema} - def __init__(self, dct, rdbms, user, connection, connection_string): + def __init__(self, dct, rdbms, user, connection, connection_string, minutes_between_refreshes): dict.__init__(self, dct) self.child_type = self.schema_types[rdbms] self.user = user self.connection = connection self.gerald_connection_string = gerald_connection_string(connection_string) - self.refresh_thread = RefreshGroupThread(self) + self.refresh_thread = RefreshGroupThread(self, minutes_between_refreshes) self.complete = False - # do we need a second thread for a second run? def refresh_asynch(self): self.refresh_thread.start() - def refresh(self): + def get_current_database_time(self): curs = self.connection.cursor() curs.execute('SELECT sysdate FROM dual') - current_database_time = curs.fetchone()[0] + return curs.fetchone()[0] + def refresh(self): + current_database_time = self.get_current_database_time() + curs = self.connection.cursor() curs.execute('''SELECT owner, MAX(last_ddl_time) FROM all_objects GROUP BY owner @@ -49,8 +55,12 @@ {'username': self.user.upper()}) for (owner, last_ddl_time) in curs.fetchall(): if (owner not in self) or (self[owner].refreshed < last_ddl_time): - self[owner] = self.child_type(owner, self.gerald_connection_string) - self[owner].refreshed = current_database_time + self.refresh_one(owner, current_database_time) # what if a user's last object is deleted? self.complete = True + def refresh_one(self, owner, current_database_time=None): + if not current_database_time: + current_database_time = self.get_current_database_time() + self[owner] = self.child_type(owner, self.gerald_connection_string) + self[owner].refreshed = current_database_time \ No newline at end of file
--- a/sqlpython/sqlpyPlus.py Tue Oct 06 15:16:47 2009 -0400 +++ b/sqlpython/sqlpyPlus.py Tue Oct 06 16:20:16 2009 -0400 @@ -347,7 +347,9 @@ def __init__(self): sqlpython.sqlpython.__init__(self) self.binds = CaselessDict() - self.settable += 'autobind bloblimit colors commit_on_exit maxfetch maxtselctrows rows_remembered scan serveroutput sql_echo timeout heading wildsql version'.split() + self.settable += '''autobind bloblimit colors commit_on_exit maxfetch maxtselctrows + minutes_between_refreshes rows_remembered scan serveroutput + sql_echo timeout heading wildsql version'''.split() self.settable.remove('case_insensitive') self.settable.sort() self.stdoutBeforeSpool = sys.stdout @@ -363,6 +365,7 @@ self.result_history = [] self.rows_remembered = 10000 self.bloblimit = 5 + self.minutes_between_refreshes = 1 self.version = 'SQLPython %s' % sqlpython.__version__ self.pystate = {'r': [], 'binds': self.binds, 'substs': self.substvars} @@ -1430,9 +1433,10 @@ 'WINDOW GROUP', 'XML SCHEMA') - @options([make_option('-l', '--long', action='store_true', help='long descriptions'), + @options([#make_option('-l', '--long', action='store_true', help='long descriptions'), make_option('-a', '--all', action='store_true', help="all schemas' objects"), - make_option('-t', '--timesort', action='store_true', help="Sort by last_ddl_time"), + 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")]) def do_ls(self, arg, opts): ''' @@ -1442,8 +1446,13 @@ seek = '^%s$' % (arg.replace('*', '.*').replace('?','.'). \ replace('%', '.*')) schemas = self.connections[self.connection_number]['schemas'] + username = self.connections[self.connection_number]['user'].upper() + if opts.immediate: + if opts.all: + self.perror('Cannot combine --all with --immediate - operation takes too long') + else: + schemas.refresh_one(username) result = [] - username = self.connections[self.connection_number]['user'].upper() for (schema_name, schema) in schemas.items(): if opts.all or schema_name == username: for (name, obj) in schema.schema.items():
--- a/sqlpython/sqlpython.py Tue Oct 06 15:16:47 2009 -0400 +++ b/sqlpython/sqlpython.py Tue Oct 06 16:20:16 2009 -0400 @@ -103,7 +103,8 @@ conn = {'conn': self.conn, 'prompt': self.prompt, 'dbname': eng.url.database, 'rdbms': rdbms, 'user': user, 'eng': eng, 'schemas': schemagroup.SchemaDict({}, - rdbms=rdbms, user=user, connection=self.conn, connection_string=arg)} + rdbms=rdbms, user=user, connection=self.conn, connection_string=arg, + minutes_between_refreshes = self.minutes_between_refreshes)} s = conn['schemas'] s.refresh_asynch() return conn