Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 valid syntax #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from setuptools import setup, find_packages
import os

Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/relstorage_packer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import logging
logging.basicConfig(
level=logging.INFO,
Expand Down
49 changes: 25 additions & 24 deletions src/relstorage_packer/refcount.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/relstorage_packer/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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