annotate omit_error_objects.patch @ 485:885c275ee790

pared down connections.py
author catherine.devlin@gmail.com
date Sun, 05 Sep 2010 07:30:46 -0400
parents ad07a08cb792
children
rev   line source
478
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
1 diff -r db8d877dbf4e gerald/oracle_schema.py
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
2 --- a/gerald/oracle_schema.py Wed Mar 10 15:41:22 2010 -0500
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
3 +++ b/gerald/oracle_schema.py Wed Mar 10 15:46:07 2010 -0500
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
4 @@ -84,21 +84,21 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
5 cursor.execute(stmt)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
6 for table in cursor.fetchall():
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
7 LOG.debug('Getting details for table %s' % table[0])
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
8 - schema[table[0]] = Table(table[0], cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
9 + self._set_unless_fail(schema, table[0], table[0], Table, cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
10 # Views
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
11 stmt = """SELECT view_name
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
12 FROM user_views"""
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
13 cursor.execute(stmt)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
14 for view in cursor.fetchall():
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
15 LOG.debug("Getting details for view %s" % view[0])
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
16 - schema[view[0]] = View(view[0], cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
17 + self._set_unless_fail(schema, view[0], view[0], View, cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
18 # Sequences
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
19 stmt = """SELECT sequence_name
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
20 FROM user_sequences"""
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
21 cursor.execute(stmt)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
22 for sequence in cursor.fetchall():
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
23 LOG.debug("Getting details for sequence %s" % sequence[0])
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
24 - schema[sequence[0]] = Sequence(sequence[0], cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
25 + self._set_unless_fail(schema, sequence[0], sequence[0], Sequence, cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
26 # Code objects (packages, procedures and functions)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
27 # Note that we exclude package bodies, even though they are separate
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
28 # objects they are stored under the package header in gerald
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
29 @@ -112,11 +112,9 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
30 object_name, object_type = code_object
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
31 LOG.debug("Getting details for code object %s" % object_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
32 if object_type == 'PACKAGE':
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
33 - schema[object_name] = Package(object_name, object_type, cursor,
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
34 - schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
35 + self._set_unless_fail(schema, object_name, object_name, Package, object_type, cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
36 else:
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
37 - schema[object_name] = CodeObject(object_name, object_type,
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
38 - cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
39 + self._set_unless_fail(schema, object_name, object_name, CodeObject, object_type, cursor, schema_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
40 # Database links
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
41 stmt = """SELECT db_link
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
42 FROM user_db_links
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
43 @@ -126,12 +124,11 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
44 for db_link in cursor.fetchall():
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
45 link_name = db_link[0]
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
46 LOG.debug("Getting details for db link %s" % link_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
47 - schema[link_name] = DatabaseLink(link_name, cursor)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
48 + self._set_unless_fail(schema, link_name, link_name, DatabaseLink, cursor)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
49 # All done, return the fruit of our labours
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
50 LOG.info('Got details for schema %s' % self.name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
51 return schema
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
52
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
53 -
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
54 class User(schema.Schema):
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
55 """
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
56 A representation of an Oracle database user
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
57 @@ -168,7 +165,7 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
58 owner, table_name = table
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
59 LOG.debug('Getting details for table %s' % table_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
60 table_key = '%s.%s' % (owner, table_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
61 - schema[table_key] = Table(table_name, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
62 + self._set_unless_fail(schema, table_key, table_name, Table, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
63 # Views
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
64 stmt = """SELECT view_name, owner
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
65 FROM all_views"""
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
66 @@ -177,7 +174,7 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
67 view_name, owner = view
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
68 LOG.debug("Getting details for view %s" % view_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
69 view_key = '%s.%s' % (owner, view_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
70 - schema[view_key] = View(view_name, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
71 + self._set_unless_fail(schema, view_key, view_name, View, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
72 # Sequences
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
73 stmt = """SELECT sequence_name, sequence_owner
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
74 FROM all_sequences"""
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
75 @@ -186,7 +183,7 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
76 sequence, owner = seq
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
77 LOG.debug("Getting details for sequence %s" % sequence)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
78 sequence_key = '%s.%s' % (owner, sequence)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
79 - schema[sequence_key] = Sequence(sequence, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
80 + self._set_unless_fail(schema, sequence_key, sequence, Sequence, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
81 # Code objects (packages, procedures and functions)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
82 # Note that we exclude package bodies, even though they are separate
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
83 # objects they are stored under the package header in gerald
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
84 @@ -201,9 +198,9 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
85 object_key = '%s.%s' % (owner, object_name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
86 LOG.debug("Getting details for code object %s" % object_key)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
87 if object_type == 'PACKAGE':
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
88 - schema[object_key] = Package(object_name, object_type, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
89 + self._set_unless_fail(schema, object_key, object_name, Package, object_type, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
90 else:
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
91 - schema[object_key] = CodeObject(object_name, object_type, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
92 + self._set_unless_fail(schema, object_key, object_name, CodeObject, object_type, cursor, owner)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
93 # All done, return the fruit of our labours
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
94 LOG.info('Got details for user %s' % self.name)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
95 return schema
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
96 @@ -1033,5 +1030,8 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
97
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
98
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
99 if __name__ == "__main__":
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
100 - print "This module should not be invoked from the command line"
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
101 + import gerald
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
102 + sch = gerald.oracle_schema.User('eqdbw', 'oracle://eqdbw/mtndew@afmcce1.wpafb.af.mil/eqprod.wpafb.af.mil',omit_error_objects=True)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
103 + print sch
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
104 + #print "This module should not be invoked from the command line"
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
105 sys.exit(1)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
106 diff -r db8d877dbf4e gerald/schema.py
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
107 --- a/gerald/schema.py Wed Mar 10 15:41:22 2010 -0500
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
108 +++ b/gerald/schema.py Wed Mar 10 15:46:07 2010 -0500
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
109 @@ -75,7 +75,7 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
110 - _db. A database connection. Optional, need not be provided by sub-classes.
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
111 - _cursor. A cursor generated from _db
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
112 """
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
113 - def __init__(self, schema_name, connection_string=None):
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
114 + def __init__(self, schema_name, connection_string=None, omit_error_objects=False):
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
115 """
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
116 Initialise the schema.
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
117
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
118 @@ -87,6 +87,7 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
119 @return: Success or failure
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
120 @rtype: Boolean
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
121 """
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
122 + self.omit_error_objects = omit_error_objects
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
123 self.name = schema_name
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
124 self.api_version = Decimal('1.1')
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
125 self.schema = {}
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
126 @@ -226,6 +227,15 @@
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
127 results.append('%s is different ' % schema_object)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
128 results.append('in the two schemas')
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
129 return ''.join(results)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
130 + def _set_unless_fail(self, schema, key, object_name, object_type, *args):
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
131 + try:
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
132 + schema[key] = object_type(object_name, *args)
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
133 + except (AttributeError) as e:
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
134 + if self.omit_error_objects:
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
135 + LOG.warning("Couldn't get details for %s: %s" % (key, str(e)))
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
136 + else:
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
137 + raise
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
138 +
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
139
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
140
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
141 class Table(object):
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
142
ad07a08cb792 temporarily package gerald patch for convenience
catherine@dellzilla
parents:
diff changeset
143