-
-
Save williamsjj/78dbf3a992ab7c255f95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# (c)2011 Jason J. W. Williams - jasonjwwilliams@gmail.com | |
# Distributed under the BSD license. | |
from optparse import OptionParser | |
import sys, os, copy | |
parser = OptionParser() | |
parser.add_option("-i", "--instance-home", dest="instance_home", | |
help="Path to Zope-instance.") | |
parser.add_option("-s", "--software-home", dest="software_home", | |
help="Path to Zope-installed python. (/usr/lib/zope-2.9.3/lib/python)", | |
default="/usr/lib/zope-2.9.3/lib/python") | |
parser.add_option("-d", "--data-file", dest="data_file", | |
help="Path to ZODB data file.") | |
parser.add_option("-o", "--object", dest="object", | |
help="Fully-qualified object to edit (e.g. Folder.file)") | |
parser.add_option("-p", "--property", dest="property", | |
help="Object property to edit ") | |
parser.add_option("-v", "--value", dest="value", | |
help="Value to set on property. (must be valid Python)") | |
args = parser.parse_args()[0] | |
if not (args.instance_home and args.data_file and args.object and args.property): | |
print 'Incorrect usage, please run "zodb_modobj.py --help" to see correct usage' | |
sys.exit(-1) | |
sys.path.append(args.software_home) | |
os.environ["SOFTWARE_HOME"] = args.software_home | |
os.environ["INSTANCE_HOME"] = args.instance_home | |
from ZODB.FileStorage import FileStorage | |
from ZODB.DB import DB | |
import transaction | |
storage = FileStorage(args.data_file) | |
db = DB(storage) | |
connection = db.open() | |
root = connection.root() | |
parent = root['Application'] | |
obj = None | |
for leaf in args.object.split("."): | |
obj = getattr(parent, leaf) | |
parent = obj | |
if not args.value: | |
prop = getattr(obj, args.property) | |
print "Property Type: " + str(type(prop)) | |
print "Property Contents\n------\n" | |
print dir(prop) | |
print "Property Value: " + str(prop) | |
else: | |
trans = transaction.get() | |
print trans.status | |
setattr(obj, args.property, eval(args.value)) | |
trans.commit() | |
print id(root['Application']) | |
print trans.status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment