diff --git a/HISTORY.rst b/HISTORY.rst index c6b9afb..850f7af 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,10 +2,15 @@ History ======= +2.2 (unreleased) +---------------- + +- Update code to make it Python 3 compatible [gforcada, 2024-04-02] + 2.1 (2014-02-19) ---------------- -- refactored logging, because it was always in my way when changing other parts +- refactored logging, because it was always in my way when changing other parts of the code. [jensens, 2014-02-19] diff --git a/setup.py b/setup.py index 43935c1..e8fdd04 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import from setuptools import setup, find_packages import os @@ -19,6 +20,7 @@ 'Programming Language :: Python', 'Topic :: Software Development', 'License :: OSI Approved :: BSD License', + 'Programming Language :: Python :: 3', ], keywords='postgresql zodb pack zope', author='BlueDynamics Alliance', diff --git a/src/relstorage_packer/__init__.py b/src/relstorage_packer/__init__.py index 407a256..bcb7883 100644 --- a/src/relstorage_packer/__init__.py +++ b/src/relstorage_packer/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging logging.basicConfig( level=logging.INFO, diff --git a/src/relstorage_packer/refcount.py b/src/relstorage_packer/refcount.py index ec82535..7c5dd95 100644 --- a/src/relstorage_packer/refcount.py +++ b/src/relstorage_packer/refcount.py @@ -1,4 +1,5 @@ """relstorage_packer - reference numinrefs process""" +from __future__ import absolute_import from .utils import dbcommit from .utils import get_conn_and_cursor from .utils import get_references @@ -135,7 +136,7 @@ def next_tid(cursor, lasttid): def changed_tids_len(cursor, tid): stmt = "SELECT COUNT(distinct tid) FROM object_state WHERE tid >=%d;" % tid cursor.execute(stmt) - (count,) = cursor.next() + (count,) = next(cursor) return count or 0 @@ -163,9 +164,9 @@ def _check_removed_refs(cursor, source_zoid, target_zoids): stmt = """ SELECT zoid FROM object_inrefs - WHERE inref = %(source_zoid)s - AND zoid <> %(source_zoid)s; - """ % {'source_zoid': source_zoid} + WHERE inref = {source_zoid} + AND zoid <> {source_zoid}; + """.format(source_zoid=source_zoid) cursor.execute(stmt) stmt = "" for zoid in cursor: @@ -178,15 +179,15 @@ def _check_removed_refs(cursor, source_zoid, target_zoids): ) stmt += """ DELETE FROM object_inrefs - WHERE zoid = %(zoid)s - AND inref = %(source_zoid)s; + WHERE zoid = {zoid} + AND inref = {source_zoid}; UPDATE object_inrefs SET numinrefs = numinrefs - 1 - WHERE zoid = %(zoid)s - AND inref = %(zoid)s; - """ % {'source_zoid': source_zoid, - 'zoid': zoid} + WHERE zoid = {zoid} + AND inref = {zoid}; + """.format(source_zoid=source_zoid, + zoid=zoid) if stmt: cursor.execute(stmt) @@ -250,7 +251,7 @@ def _remove_blob(storage, zoid): return fshelper = storage.blobhelper.fshelper blobpath = fshelper.getPathForOID(p64(zoid)) - log.debug('-> Blobs for zoid=%s are at %s' % (zoid, blobpath)) + log.debug('-> Blobs for zoid={} are at {}'.format(zoid, blobpath)) if not os.path.exists(blobpath): log.debug('-> No Blobs to remove') return @@ -281,24 +282,24 @@ def _remove_zoid(cursor, zoid): for target_zoid in target_zoids: stmt += """ DELETE FROM object_inrefs - WHERE zoid = %(target_zoid)s - AND inref = %(source_zoid)s; + WHERE zoid = {target_zoid} + AND inref = {source_zoid}; UPDATE object_inrefs SET numinrefs = numinrefs - 1 - WHERE zoid = %(target_zoid)s - AND inref = %(target_zoid)s; - """ % {'source_zoid': source_zoid, - 'target_zoid': target_zoid} + WHERE zoid = {target_zoid} + AND inref = {target_zoid}; + """.format(source_zoid=source_zoid, + target_zoid=target_zoid) # finally delete data stmt += """ DELETE FROM object_inrefs - WHERE zoid = %(zoid)s; + WHERE zoid = {zoid}; DELETE FROM object_state - WHERE zoid = %(zoid)s; - """ % {'zoid': zoid} + WHERE zoid = {zoid}; + """.format(zoid=zoid) cursor.execute(stmt) @@ -327,7 +328,7 @@ def remove_orphans(connection, cursor, storage): if (count % CYCLES_TO_RECONNECT) == 0: # get a fresh connection, else postgres server may consume too # much RAM .oO( sigh ) - log.info('Refresh connection after {0} zoid cycles'.format(count)) + log.info(f'Refresh connection after {count} zoid cycles') connection.close() connection, cursor = get_conn_and_cursor(storage) else: @@ -443,7 +444,7 @@ def run(argv=sys.argv): log.info('Fetching number of all transactions from DB ...') else: log.info( - "Fetching number of new transactions since tid {0} " + "Fetching number of new transactions since tid {} " "from DB ...".format(init_tid) ) stats['overall_tids'] = changed_tids_len(cursor, init_tid) @@ -502,8 +503,8 @@ def run(argv=sys.argv): 'Finished cleanup phase after %s (%.2fs)' % (str(datetime.timedelta(seconds=processing_time)), processing_time) ) - except Exception, e: - log.error(e.message) + except Exception as error: + log.error(str(error)) raise exit(1) finally: diff --git a/src/relstorage_packer/utils.py b/src/relstorage_packer/utils.py index 276a1b0..d5a4ce4 100644 --- a/src/relstorage_packer/utils.py +++ b/src/relstorage_packer/utils.py @@ -1,5 +1,6 @@ +from __future__ import absolute_import import logging -from StringIO import StringIO +from io import StringIO import ZConfig from ZODB.serialize import referencesf from ZODB.utils import u64 @@ -40,7 +41,7 @@ def get_storage(config_file): connection = config.storages[0] if connection.config.keep_history: raise RuntimeError('Packing does not support history keeping storages') - name = '%s (%s)' % ((connection.name or 'storage'), + name = '{} ({})'.format((connection.name or 'storage'), connection.__class__.__name__) log.info("Opening %s...", name) storage = connection.open() @@ -60,6 +61,6 @@ def get_references(state): """Return the set of OIDs the given state refers to.""" refs = set() if state: - for oid in referencesf(str(state)): + for oid in referencesf(state): refs.add(u64(oid)) return refs