Created
June 20, 2011 21:15
-
-
Save williamsjj/1036604 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 | |
from optparse import OptionParser | |
import sys, os | |
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-property", dest="object", | |
help="Fully-qualified object property to edit (e.g. Folder.file.property)") | |
parser.add_option("-v", "--value", dest="value", | |
help="Value to set on property.") | |
args = parser.parse_args()[0] | |
if not (args.instance_home and args.data_file and args.object): | |
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() | |
app = root['Application'] | |
obj = eval("app." + args.object) | |
if not args.value: | |
print "Object Type: " + str(type(obj)) | |
print "Object Contents\n------\n" | |
print dir(obj) | |
print "Object Value: " + str(obj) | |
else: | |
print transaction.get().status | |
transaction.savepoint() | |
obj = args.value | |
print obj | |
transaction.savepoint() | |
print transaction.get().status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment