updated comments and docs to 120 characters per line

This commit is contained in:
Andreas Preikschat 2013-03-22 21:29:52 +01:00
parent 35bbead73b
commit e6e57b6c03
1 changed files with 34 additions and 58 deletions

View File

@ -134,8 +134,7 @@ def delete_database(plugin_name, db_file_name=None):
The name of the plugin to remove the database for The name of the plugin to remove the database for
``db_file_name`` ``db_file_name``
The database file name. Defaults to None resulting in the The database file name. Defaults to None resulting in the plugin_name being used.
plugin_name being used.
""" """
db_file_path = None db_file_path = None
if db_file_name: if db_file_name:
@ -164,11 +163,10 @@ class Manager(object):
""" """
Provide generic object persistence management Provide generic object persistence management
""" """
def __init__(self, plugin_name, init_schema, db_file_name=None, def __init__(self, plugin_name, init_schema, db_file_name=None, upgrade_mod=None):
upgrade_mod=None):
""" """
Runs the initialisation process that includes creating the connection Runs the initialisation process that includes creating the connection to the database and the tables if they do
to the database and the tables if they don't exist. not exist.
``plugin_name`` ``plugin_name``
The name to setup paths and settings section names The name to setup paths and settings section names
@ -180,8 +178,7 @@ class Manager(object):
The upgrade_schema function for this database The upgrade_schema function for this database
``db_file_name`` ``db_file_name``
The file name to use for this database. Defaults to None resulting The file name to use for this database. Defaults to None resulting in the plugin_name being used.
in the plugin_name being used.
""" """
settings = Settings() settings = Settings()
settings.beginGroup(plugin_name) settings.beginGroup(plugin_name)
@ -241,11 +238,9 @@ class Manager(object):
self.is_dirty = True self.is_dirty = True
return True return True
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue - "MySQL has gone away"') log.exception(u'Probably a MySQL issue - "MySQL has gone away"')
self.session.rollback() self.session.rollback()
if try_count >= 2: if try_count >= 2:
@ -276,11 +271,9 @@ class Manager(object):
self.is_dirty = True self.is_dirty = True
return True return True
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue, "MySQL has gone away"') log.exception(u'Probably a MySQL issue, "MySQL has gone away"')
self.session.rollback() self.session.rollback()
if try_count >= 2: if try_count >= 2:
@ -310,11 +303,9 @@ class Manager(object):
try: try:
return self.session.query(object_class).get(key) return self.session.query(object_class).get(key)
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue, "MySQL has gone away"') log.exception(u'Probably a MySQL issue, "MySQL has gone away"')
if try_count >= 2: if try_count >= 2:
raise raise
@ -333,11 +324,9 @@ class Manager(object):
try: try:
return self.session.query(object_class).filter(filter_clause).first() return self.session.query(object_class).filter(filter_clause).first()
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue, "MySQL has gone away"') log.exception(u'Probably a MySQL issue, "MySQL has gone away"')
if try_count >= 2: if try_count >= 2:
raise raise
@ -350,8 +339,7 @@ class Manager(object):
The type of objects to return The type of objects to return
``filter_clause`` ``filter_clause``
The filter governing selection of objects to return. Defaults to The filter governing selection of objects to return. Defaults to None.
None.
``order_by_ref`` ``order_by_ref``
Any parameters to order the returned objects by. Defaults to None. Any parameters to order the returned objects by. Defaults to None.
@ -367,11 +355,9 @@ class Manager(object):
try: try:
return query.all() return query.all()
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue, "MySQL has gone away"') log.exception(u'Probably a MySQL issue, "MySQL has gone away"')
if try_count >= 2: if try_count >= 2:
raise raise
@ -384,8 +370,7 @@ class Manager(object):
The type of objects to return. The type of objects to return.
``filter_clause`` ``filter_clause``
The filter governing selection of objects to return. Defaults to The filter governing selection of objects to return. Defaults to None.
None.
""" """
query = self.session.query(object_class) query = self.session.query(object_class)
if filter_clause is not None: if filter_clause is not None:
@ -394,11 +379,9 @@ class Manager(object):
try: try:
return query.count() return query.count()
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue, "MySQL has gone away"') log.exception(u'Probably a MySQL issue, "MySQL has gone away"')
if try_count >= 2: if try_count >= 2:
raise raise
@ -422,11 +405,9 @@ class Manager(object):
self.is_dirty = True self.is_dirty = True
return True return True
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue, "MySQL has gone away"') log.exception(u'Probably a MySQL issue, "MySQL has gone away"')
self.session.rollback() self.session.rollback()
if try_count >= 2: if try_count >= 2:
@ -443,17 +424,14 @@ class Manager(object):
def delete_all_objects(self, object_class, filter_clause=None): def delete_all_objects(self, object_class, filter_clause=None):
""" """
Delete all object records. Delete all object records. This method should only be used for simple tables and **not** ones with
This method should only be used for simple tables and not ones with relationships. The relationships are not deleted from the database and this will lead to database corruptions.
relationships. The relationships are not deleted from the database and
this will lead to database corruptions.
``object_class`` ``object_class``
The type of object to delete The type of object to delete
``filter_clause`` ``filter_clause``
The filter governing selection of objects to return. Defaults to The filter governing selection of objects to return. Defaults to None.
None.
""" """
for try_count in range(3): for try_count in range(3):
try: try:
@ -465,11 +443,9 @@ class Manager(object):
self.is_dirty = True self.is_dirty = True
return True return True
except OperationalError: except OperationalError:
# This exception clause is for users running MySQL which likes # This exception clause is for users running MySQL which likes to terminate connections on its own
# to terminate connections on its own without telling anyone. # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a
# See bug #927473 # non-recoverable way. So we only retry 3 times.
# However, other dbms can raise it, usually in a non-recoverable
# way. So we only retry 3 times.
log.exception(u'Probably a MySQL issue, "MySQL has gone away"') log.exception(u'Probably a MySQL issue, "MySQL has gone away"')
self.session.rollback() self.session.rollback()
if try_count >= 2: if try_count >= 2: