how to export data from ZODB to text files

Discussion in 'Python' started by ls, Jun 7, 2005.

  1. ls

    ls Guest

    Hi All,

    I looking for help with ZODB data export to text file. I have file
    Data.fs (file becomes from Plone CMS) and I have to display content
    structure, data like intro, body of article, etc and save it in to
    simple file. However I can't use Plone XML export because is broken,
    Zope Corp. set low priority for this bug, so I have to find other way
    how to digg in to data.

    Could you point me in to some Python code examples, code contributions
    and so on.

    Thank you for any suggestions,

    Lukasz
     
    ls, Jun 7, 2005
    #1
    1. Advertising

  2. ls

    Peter Hansen Guest

    ls wrote:
    > I looking for help with ZODB data export to text file. I have file
    > Data.fs
    > [snip]
    > Could you point me in to some Python code examples, code contributions
    > and so on.


    You can download the "standalone" ZODB code and run it under regular
    Python without Zope installed or involved, and use that to access your
    Data.fs file directly. See http://www.zope.org/Products/StandaloneZODB

    This page lists much documentation (near the bottom):
    http://www.zope.org/Wikis/ZODB/FrontPage

    -Peter
     
    Peter Hansen, Jun 7, 2005
    #2
    1. Advertising

  3. ls

    ls Guest

    Hi Peter,

    Thank you for your reply. I already can access file using code


    >>> from ZODB import FileStorage, DB
    >>> storage =

    FileStorage.FileStorage('mydatabase.fs')
    >>> db = DB(storage)
    >>> connection = db.open()
    >>> root = connection.root()



    But this is the point where my konwledge ends since I`m not a Python
    programmer.

    I don`t know what is the structure of ZODB, I`m just looking for code,
    or some tool, which I can use to export data from Data.ts file to
    plain text file.

    I`m looking for easiest way to export data from ZODB and put it to
    MySQL later.

    Do you know what way I should choose? I have to know Python language
    to finish this task?

    --
    Lukasz
     
    ls, Jun 7, 2005
    #3
  4. On Tue, 7 Jun 2005 14:48:34 +0000 (UTC),
    -spam.invalid (ls) declaimed the following in
    comp.lang.python:

    >
    > I don`t know what is the structure of ZODB, I`m just looking for code,
    > or some tool, which I can use to export data from Data.ts file to
    > plain text file.
    >
    > I`m looking for easiest way to export data from ZODB and put it to
    > MySQL later.
    >

    I've not looked into ZODB directly, but as I understand it...

    ZODB is an object store, so it doesn't really have a "structure"
    in terms of RDBM tables. As I understand it, loading "data" from ZODB
    creates instances of various classes; you probably (if you don't already
    /know/ the nature of the classes) will have to look into each instance
    to find the attributes, etc.



    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Jun 7, 2005
    #4
  5. ls

    John J. Lee Guest

    -spam.invalid (ls) writes:

    > Hi Peter,
    >
    > Thank you for your reply. I already can access file using code
    >
    >
    > >>> from ZODB import FileStorage, DB
    > >>> storage =

    > FileStorage.FileStorage('mydatabase.fs')
    > >>> db = DB(storage)
    > >>> connection = db.open()
    > >>> root = connection.root()

    >
    >
    > But this is the point where my konwledge ends since I`m not a Python
    > programmer.
    >
    > I don`t know what is the structure of ZODB, I`m just looking for code,
    > or some tool, which I can use to export data from Data.ts file to
    > plain text file.
    >
    > I`m looking for easiest way to export data from ZODB and put it to
    > MySQL later.
    >
    > Do you know what way I should choose? I have to know Python language
    > to finish this task?


    Yes, you do (or hire somebody else who does). I'm afraid you may
    really have your work cut out here! It really all depends on the
    complexity of your application, and how well it was written. But if
    you're shiny-new to Python, Zope, OO databases and all the ideas that
    go with these kinds of systems, you may be at the bottom of a longish
    ladder -- what's your background? ZODB is relatively simple and
    probably has relatively few quirks as OO persistance systems go, but
    still, learning ZODB and a new language at the same time might be
    confusing (not to mention finding your way around the application
    you're working with). And Zope is... complicated.

    Why are you doing this in the first place? Trying to escape from
    Zope-land? Exporting data on a regular basis, for use in another app?


    John
     
    John J. Lee, Jun 8, 2005
    #5
  6. ls

    ls Guest

    > Why are you doing this in the first place? Trying to escape from
    > Zope-land? Exporting data on a regular basis, for use in another

    app?

    Hi Jonh,

    Thank you for your reply.

    Yes, I'm traing to escape from Zope-land, to be more clarify I want to
    migrate from Plone to PHP Application, which uses MySQL database
    engine, so I have to move all data from ZODB to MySQL. I suppose that
    python script shouldn`t be so complex. I need just iterate ZODB and
    write attributes like "Intro", "Body" of article to file for example.
    I need export Plone content hierarchy like


    Home
    |
    | - - - Folder 1 (Title, Intro, Body)
    | | - - - Article (Title, Intro, Body)
    |
    | - - - Folder 2 (Title, Intro, Body)


    Now after your answer, I see that I will be not able to finish this
    taks by myself ...

    I'm experienced mostly in C, PHP, also with some backgrounds of CPP
    and Java, but I'm totaly new in Python ...

    What do you suggest in this case?

    --
    Lukasz
     
    ls, Jun 8, 2005
    #6
  7. ls

    Max M Guest

    ls wrote:

    > I'm experienced mostly in C, PHP, also with some backgrounds of CPP
    > and Java, but I'm totaly new in Python ...
    >
    > What do you suggest in this case?


    The simplest approach is to run Zope with the Data.fs file. If you have
    access to the zope instance you want to export from, you only need to
    write an external method in Zope to export the data you want. Its pretty
    easy that way.


    --

    hilsen/regards Max M, Denmark

    http://www.mxm.dk/
    IT's Mad Science
     
    Max M, Jun 8, 2005
    #7
  8. ls

    Josef Meile Guest

    Hi Lukasz,

    > Yes, I'm traing to escape from Zope-land, to be more clarify I want to
    > migrate from Plone to PHP Application, which uses MySQL database
    > engine, so I have to move all data from ZODB to MySQL. I suppose that
    > python script shouldn`t be so complex. I need just iterate ZODB and
    > write attributes like "Intro", "Body" of article to file for example.
    > I need export Plone content hierarchy like
    >
    >
    > Home
    > |
    > | - - - Folder 1 (Title, Intro, Body)
    > | | - - - Article (Title, Intro, Body)
    > |
    > | - - - Folder 2 (Title, Intro, Body)

    I haven't done that with Plone, but with CMF, which is the base of
    Plone. So, I guess it would be almost the same. You even don't need
    the product Peter suggested; you could do a python script inside your
    plone site, which searches all the objects you want and print it in
    form of a pipe '|' delimited list. Then, once you define your tables
    in mysql, you can import the data by copying the output of your
    script and saving it into a text file. This is how my script looks like:

    catalog=context.portal_catalog
    jobs=catalog(
    {
    'meta_type' : 'Internship'
    }
    )
    OID = 1
    for metaJob in jobs:
    jobData=catalog.getobject(metaJob.data_record_id_)
    print "%i|%s|%s|%s|%s|%s|%s|%s|" % \
    (OID,
    jobData.companyName,
    jobData.companyVision,
    jobData.description,
    jobData.positionOffered,
    jobData.jobProfile,
    jobData.contact,
    jobData.country)
    OID += 1

    return printed

    Off course, this only work assuming that your fields aren't files like
    images or PDFs.

    Regards,
    Josef
     
    Josef Meile, Jun 8, 2005
    #8
  9. ls

    ls Guest

    Hi Josef,

    Thank you so much. I will ask our Plone administrator to test your
    script and I will write about result here.

    I thought also about Python script like


    //connect to database
    >>> from ZODB import FileStorage, DB
    >>> storage = FileStorage.FileStorage('Data.fs')
    >>> db = DB(storage)
    >>> conn = db.open()
    >>> dbroot = conn.root()


    //here should be interation for DB which saves attributes output in
    to file


    I'm not able to write the second part, but I think that this shouldn`t
    be a problem for experienced Python developer.

    How complex will be script like above?

    @Max

    > If you have access to the zope instance you want to export from, you

    only need to write an external method in Zope to export the data you
    want. Its pretty easy that way.

    Could you contribute code which do export data?

    --
    Lukasz
     
    ls, Jun 9, 2005
    #9
  10. ls

    Josef Meile Guest

    Hi Lucasz,

    > Thank you so much. I will ask our Plone administrator to test your
    > script and I will write about result here.

    You are wellcome. I think it is one of the easiest way of doing it.

    > I thought also about Python script like
    >
    >
    > //connect to database
    > >>> from ZODB import FileStorage, DB
    > >>> storage = FileStorage.FileStorage('Data.fs')
    > >>> db = DB(storage)
    > >>> conn = db.open()
    > >>> dbroot = conn.root()

    >
    > //here should be interation for DB which saves attributes output in
    > to file
    >
    >
    > I'm not able to write the second part, but I think that this shouldn`t
    > be a problem for experienced Python developer.
    >
    > How complex will be script like above?

    I have to say it would be interesting to do something like that with
    ZODB. Specially if you only have the Data.fs and don't have access to
    the original Plone site. But I don't know how to do it. You may ask in
    the ZODB list:

    http://lists.zope.org/mailman/listinfo/zodb-dev

    Regards,
    Josef
     
    Josef Meile, Jun 10, 2005
    #10
  11. ls

    Josef Meile Guest

    Hi again,

    > I thought also about Python script like
    >
    >
    > //connect to database
    > >>> from ZODB import FileStorage, DB
    > >>> storage = FileStorage.FileStorage('Data.fs')
    > >>> db = DB(storage)
    > >>> conn = db.open()
    > >>> dbroot = conn.root()

    I just found an information that may be useful for you:

    * ZODB for Python Programmers By Michael Pelletier:
    http://www.informit.com/articles/article.asp?p=23413&rl=1

    * A Simple ZODB viewer in wxPython:
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409012

    The first link contains some useful examples and explanations. The
    second one could help you to see how your zodb is organized. In the
    links that Peter post, there is also an useful powerpoint presentation.

    According to the first link, the ZODB is a persistent dictionary that
    you can access like:

    >>> db = DB(storage)
    >>> connection = db.open()
    >>> root = connection.root()


    If I'm not wrong, you could see what objects are in root of your zodb by
    doing:

    >>> print root.keys()


    After that you could get your plone site by doing:

    >>> ploneSite = root['ploneFolder']


    Where if I'm not wrong, "ploneFolder" may be a key in the root
    dictionary. Then if plone is like CMF, it must have a "portal_catalog"
    instance in it, so, you can get it by:

    >>> catalog = getattr(ploneSite,'portal_catalog',None)


    If at this point catalog = None, then you have to print the objects in
    the plone site by doing:

    >>> print ploneSite.objectIds()


    Once you find the catalog object, you could try the script I post before
    from the command line.

    I haven't tested this, but I hope it helps.

    Regards,
    Josef Meile
     
    Josef Meile, Jun 10, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2aWQgVmFsbGU=?=

    Invalid export DLL or export format

    =?Utf-8?B?RGF2aWQgVmFsbGU=?=, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,629
    =?Utf-8?B?RGF2aWQgVmFsbGU=?=
    Oct 29, 2003
  2. Achim Domma

    loading objects from ZODB

    Achim Domma, Jul 4, 2003, in forum: Python
    Replies:
    2
    Views:
    324
    John J. Lee
    Jul 5, 2003
  3. drs

    More ZEO/ZODB issues

    drs, Jul 12, 2003, in forum: Python
    Replies:
    0
    Views:
    330
  4. Diez B. Roggisch

    zodb troubles - seeking advice for app design

    Diez B. Roggisch, May 6, 2004, in forum: Python
    Replies:
    3
    Views:
    352
    Dieter Maurer
    May 7, 2004
  5. Maarten Porters
    Replies:
    1
    Views:
    433
    Florian Gilcher
    Jul 28, 2008
Loading...

Share This Page