Skip to content

Instantly share code, notes, and snippets.

@seanupton
Created January 12, 2015 20:08
Show Gist options
  • Save seanupton/7697e21bb906478488d0 to your computer and use it in GitHub Desktop.
Save seanupton/7697e21bb906478488d0 to your computer and use it in GitHub Desktop.
Making zodbupdate play nice with RelStorage
# somewhere in zodbupdate, likely at the end of update.py,
# add a monkey-patch for RelStorage to have a record_iternext() method:
# relstorage monkey patch for zodbupdate compatibility
# BIG caveat: FileStoreage record_iternext() is only current records; this
# will only ever work on a history-free or zero-day-packed
# RelStorage, and as such it is a hack.
import itertools
from relstorage.storage import RelStorage
def record_iternext(self, next=None):
record_iterator = next
if not isinstance(record_iterator, itertools.chain):
record_iterator = itertools.chain(*self.iterator())
record = record_iterator.next()
return (
record.oid,
record.tid,
record.data,
record_iterator # next usally oid, we cheat here, pass caller iterator
)
RelStorage.record_iternext = record_iternext # patch
# /relstorage patch
next, for main.py, you need to load the means of making RelStorage ZConfig work:
101 elif options.config:
102 # begin relstorage nonsense
103 from relstorage.zodbpack import schema_xml
104 import ZConfig
105 from StringIO import StringIO
106 schema = ZConfig.loadSchemaFile(StringIO(schema_xml))
107 config, handler = ZConfig.loadConfig(schema, options.config)
108 storage = config.storages[0].open()
109 #import pdb; pdb.set_trace()
110 #storage = ZODB.config.storageFromConfig(config.storage)
111 # end relstorage stuff
112 #storage = ZODB.config.storageFromURL(options.config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment