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