Help with Python code and accessing ZODB

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2007
Posts: 2
Reputation: gratefulluke is an unknown quantity at this point 
Solved Threads: 0
gratefulluke gratefulluke is offline Offline
Newbie Poster

Help with Python code and accessing ZODB

 
0
  #1
Jul 5th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 311
Reputation: BearofNH is on a distinguished road 
Solved Threads: 40
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz

Re: Help with Python code and accessing ZODB

 
0
  #2
Jul 6th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 2
Reputation: gratefulluke is an unknown quantity at this point 
Solved Threads: 0
gratefulluke gratefulluke is offline Offline
Newbie Poster

Re: Help with Python code and accessing ZODB

 
0
  #3
Jul 10th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 18
Reputation: sharma_vivek82 is an unknown quantity at this point 
Solved Threads: 0
sharma_vivek82 sharma_vivek82 is offline Offline
Newbie Poster

Re: Help with Python code and accessing ZODB

 
0
  #4
Sep 3rd, 2007
i think you are working with zope/plone environment, so my suggession is to use external method.
Best wishes,
Vivek Sharma
Zope/Python Developer
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4325 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC