| | |
Help with Python code and accessing ZODB
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2007
Posts: 2
Reputation:
Solved Threads: 0
I am at a real loss for what to do. My boss wants me to devise a way to extract user data from a Plone installation and I don't know how to do it. The best option I've found so far is the following piece of Python code. Below it is the executed code from the console. Can anyone tell me what I'm doing wrong? I am no coder and have no experience with Python at all. Is there some easier way to do what I'm trying to do that anyone knows of? Any suggestions would help, thanks.
***********************************Here is the unexecuted code:
#!/usr/bin/python2.3
#
# Authors - Stephan February, Michael Clark
#
# License - LGPL - http://www.gnu.org/licenses/lgpl.txt
#
import sys
#set your zope directory as appropriate
sys.path.append('/usr/lib/zope/lib/python/')
from ZODB import FileStorage, DB
# set this to point to your ZODB
# NOTE: Zope/Plone needs to be stopped first
#
storage = FileStorage.FileStorage('/var/lib/zope/data/Data.fs')
db = DB(storage)
connection = db.open()
root = connection.root()
#obtain a list of all acl_users for the plone site
userList = root.items()[0][1]['myplonesite']['acl_users']['Users']
['acl_users'].getUsers()
portalData = root.items()[0][1]['myplonesite']['portal_memberdata']
#obtain a portal_membership tool
mtool = root.items()[0][1]['myplonesite']['portal_membership']
#the following loop will print user information as:
# username, password, emailaddress, fullname,<list of user's roles>
for user in userList:
user_wrapper = mtool.getMemberById( user.getUserName() )
email = user_wrapper.getProperty('email')
fullname = user_wrapper.getProperty('fullname')
print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
email, fullname, user.getRoles())
db.close()
***************************************Now the executed code:
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:0Cool [MSC v.1310 32 bit (Intel)] o
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> #!/usr/bin/python2.3
...
>>>
>>> #
... # Authors - Stephan February, Michael Clark
... #
... # License - LGPL - http://www.gnu.org/licenses/lgpl.txt
... #
...
>>>
>>> import sys
>>>
>>> #set your zope directory as appropriate
... sys.path.append('/usr/lib/zope/lib/python/')
>>>
>>> from ZODB import FileStorage, DB
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ZODB
>>>
>>> # set this to point to your ZODB
... # NOTE: Zope/Plone needs to be stopped first
... #
... storage = FileStorage.FileStorage('/var/lib/zope/data/Data.fs')
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
NameError: name 'FileStorage' is not defined
>>> db = DB(storage)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'DB' is not defined
>>> connection = db.open()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'db' is not defined
>>> root = connection.root()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'connection' is not defined
>>>
>>> #obtain a list of all acl_users for the LUGS plone site
... userList = root.items()[0][1]['myplonesite']['acl_users']['Users']
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'root' is not defined
>>> ['acl_users'].getUsers()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'getUsers'
>>>
>>> portalData = root.items()[0][1]['myplonesite']['portal_memberdata']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'root' is not defined
>>>
>>> #obtain a portal_membership tool
... mtool = root.items()[0][1]['myplonesite']['portal_membership']
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'root' is not defined
>>>
>>> #the following loop will print user information as:
... # username, password, emailaddress, fullname,<list of user's roles>
... for user in userList:
... user_wrapper = mtool.getMemberById( user.getUserName() )
... email = user_wrapper.getProperty('email')
... fullname = user_wrapper.getProperty('fullname')
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
NameError: name 'userList' is not defined
>>> print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
File "<stdin>", line 1
print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
^
IndentationError: unexpected indent
>>> email, fullname, user.getRoles())
File "<stdin>", line 1
email, fullname, user.getRoles())
^
SyntaxError: invalid syntax
>>>
>>> db.close()
***************************************
My configuration is as follows:
Python 2.5.1
Zope 2.9.5
Plone 2.5.2
***********************************Here is the unexecuted code:
#!/usr/bin/python2.3
#
# Authors - Stephan February, Michael Clark
#
# License - LGPL - http://www.gnu.org/licenses/lgpl.txt
#
import sys
#set your zope directory as appropriate
sys.path.append('/usr/lib/zope/lib/python/')
from ZODB import FileStorage, DB
# set this to point to your ZODB
# NOTE: Zope/Plone needs to be stopped first
#
storage = FileStorage.FileStorage('/var/lib/zope/data/Data.fs')
db = DB(storage)
connection = db.open()
root = connection.root()
#obtain a list of all acl_users for the plone site
userList = root.items()[0][1]['myplonesite']['acl_users']['Users']
['acl_users'].getUsers()
portalData = root.items()[0][1]['myplonesite']['portal_memberdata']
#obtain a portal_membership tool
mtool = root.items()[0][1]['myplonesite']['portal_membership']
#the following loop will print user information as:
# username, password, emailaddress, fullname,<list of user's roles>
for user in userList:
user_wrapper = mtool.getMemberById( user.getUserName() )
email = user_wrapper.getProperty('email')
fullname = user_wrapper.getProperty('fullname')
print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
email, fullname, user.getRoles())
db.close()
***************************************Now the executed code:
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:0Cool [MSC v.1310 32 bit (Intel)] o
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> #!/usr/bin/python2.3
...
>>>
>>> #
... # Authors - Stephan February, Michael Clark
... #
... # License - LGPL - http://www.gnu.org/licenses/lgpl.txt
... #
...
>>>
>>> import sys
>>>
>>> #set your zope directory as appropriate
... sys.path.append('/usr/lib/zope/lib/python/')
>>>
>>> from ZODB import FileStorage, DB
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ZODB
>>>
>>> # set this to point to your ZODB
... # NOTE: Zope/Plone needs to be stopped first
... #
... storage = FileStorage.FileStorage('/var/lib/zope/data/Data.fs')
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
NameError: name 'FileStorage' is not defined
>>> db = DB(storage)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'DB' is not defined
>>> connection = db.open()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'db' is not defined
>>> root = connection.root()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'connection' is not defined
>>>
>>> #obtain a list of all acl_users for the LUGS plone site
... userList = root.items()[0][1]['myplonesite']['acl_users']['Users']
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'root' is not defined
>>> ['acl_users'].getUsers()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'getUsers'
>>>
>>> portalData = root.items()[0][1]['myplonesite']['portal_memberdata']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'root' is not defined
>>>
>>> #obtain a portal_membership tool
... mtool = root.items()[0][1]['myplonesite']['portal_membership']
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'root' is not defined
>>>
>>> #the following loop will print user information as:
... # username, password, emailaddress, fullname,<list of user's roles>
... for user in userList:
... user_wrapper = mtool.getMemberById( user.getUserName() )
... email = user_wrapper.getProperty('email')
... fullname = user_wrapper.getProperty('fullname')
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
NameError: name 'userList' is not defined
>>> print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
File "<stdin>", line 1
print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
^
IndentationError: unexpected indent
>>> email, fullname, user.getRoles())
File "<stdin>", line 1
email, fullname, user.getRoles())
^
SyntaxError: invalid syntax
>>>
>>> db.close()
***************************************
My configuration is as follows:
Python 2.5.1
Zope 2.9.5
Plone 2.5.2
Given:
#!/usr/bin/python2.3It looks like you problem stems from not having the right version of ZODB installed in the right place, or not running the right version of Python. Shouldn't the top line read #!/usr/bin/python2.5?
...
>>> from ZODB import FileStorage, DB
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ZODB
>>>
...
My configuration is as follows:
Python 2.5.1
•
•
Join Date: Jul 2007
Posts: 2
Reputation:
Solved Threads: 0
Okay, I made some changes now, and this is what happens.....
>>> import sys
>>>
>>> #set your zope directory as appropriate
... sys.path.append('C:\Program Files\Plone 2\Data\var')
>>> sys.path.append('C:\Program Files\Plone 2\Zope\lib\python\ZODB')
>>>
>>> from ZODB import FileStorage, DB
>>>
>>> # set this to point to your ZODB
... # NOTE: Zope/Plone needs to be stopped first
... #
...
>>> storage = FileStorage.FileStorage ('C:\Program Files\Plone 2\Data\var\data.f
s')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Program Files\Plone 2\Zope\lib\python\ZODB\FileStorage\FileStorage.py
", line 112, in __init__
self._lock_file = LockFile(file_name + '.lock')
File "C:\Program Files\Plone 2\Zope\lib\python\ZODB\lock_file.py", line 60, in
__init__
self._fp = open(path, 'w+')
IOError: [Errno 2] No such file or directory: 'C:\\Program Files\\Plone 2\\Data\
x0bar\\data.fs.lock'
>>> db = DB(storage)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'storage' is not defined
>>> connection = db.open()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'db' is not defined
>>> root = connection.root()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'connection' is not defined
>>>
Any suggestions?
>>> import sys
>>>
>>> #set your zope directory as appropriate
... sys.path.append('C:\Program Files\Plone 2\Data\var')
>>> sys.path.append('C:\Program Files\Plone 2\Zope\lib\python\ZODB')
>>>
>>> from ZODB import FileStorage, DB
>>>
>>> # set this to point to your ZODB
... # NOTE: Zope/Plone needs to be stopped first
... #
...
>>> storage = FileStorage.FileStorage ('C:\Program Files\Plone 2\Data\var\data.f
s')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Program Files\Plone 2\Zope\lib\python\ZODB\FileStorage\FileStorage.py
", line 112, in __init__
self._lock_file = LockFile(file_name + '.lock')
File "C:\Program Files\Plone 2\Zope\lib\python\ZODB\lock_file.py", line 60, in
__init__
self._fp = open(path, 'w+')
IOError: [Errno 2] No such file or directory: 'C:\\Program Files\\Plone 2\\Data\
x0bar\\data.fs.lock'
>>> db = DB(storage)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'storage' is not defined
>>> connection = db.open()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'db' is not defined
>>> root = connection.root()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'connection' is not defined
>>>
Any suggestions?
Last edited by gratefulluke; Jul 10th, 2007 at 7:20 pm. Reason: Pasted wrong execution output
![]() |
Similar Threads
- Starting Python (Python)
- How to do Input in Python? (Python)
- Display Python code on Blogspot (Python)
- Python! Thoughts? (Python)
- Convert python code to C++ (C++)
Other Threads in the Python Forum
- Previous Thread: I need help with grabbing a complete web site.
- Next Thread: decompile python bytecodes online service depython.net
Views: 4323 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced assignment beginner bluetooth chmod cmd code convert count csv data decimals dictionary dynamic dynamically enter examples excel external file float format frange ftp function gnu gui heads homework import input jaunty java leftmouse line linux list lists loan loop module mouse multiple newb number numbers output parsing path pointer port prime program programming projects push py2exe pygame pygtk pyopengl pyqt python random raw_input recursion recursive scrolledtext slicenotation software ssh stderr string strings table tennis terminal text thread threading time tkinter tlapse tooltip tricks tuple tutorial ubuntu unicode unix urllib urllib2 variable variables ventrilo web webservice windows wx.wizard wxpython xlib





