943,852 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 7578
  • Python RSS
Jul 5th, 2007
0

Help with Python code and accessing ZODB

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gratefulluke is offline Offline
2 posts
since Jul 2007
Jul 6th, 2007
0

Re: Help with Python code and accessing ZODB

Given:
#!/usr/bin/python2.3
...
>>> 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
It 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?
Reputation Points: 94
Solved Threads: 48
Posting Whiz
BearofNH is offline Offline
321 posts
since May 2007
Jul 10th, 2007
0

Re: Help with Python code and accessing ZODB

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?
Last edited by gratefulluke; Jul 10th, 2007 at 7:20 pm. Reason: Pasted wrong execution output
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gratefulluke is offline Offline
2 posts
since Jul 2007
Sep 3rd, 2007
0

Re: Help with Python code and accessing ZODB

i think you are working with zope/plone environment, so my suggession is to use external method.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: I need help with grabbing a complete web site.
Next Thread in Python Forum Timeline: decompile python bytecodes online service depython.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC