[Zope] - FYI: Q&A updated

Paul Everitt Paul@digicool.com
Sat, 12 Dec 1998 13:16:28 -0500


I finally updated my Q&A at:

  www.zope.org/Information/QA

It is authored completely in Structured Text with some DTML scripting to
assemble the pieces.

For those that care, I've attached an External Method which will upload
the contents of a directory into a Folder.  It fails if the documents
already exist (I couldn't figure out how to test for the existance of an
object in a folder, has_key failed :^(  )

--Paul

Paul Everitt       Digital Creations
paul@digicool.com  540.371.6909

--------------------------------------
loadfiles.py
--------------------------------------

import os

def importfiles(self):
  """Load files from disk into a Folder

  If you use an editor to manage a bunch of files on disk and you want
  to keep them current in a Zope Folder, loading them one by one is a
  pain.  It would be nice to have a facility to easily load files on
  the same machine as the Zope site into Zope.

  Since External Methods have access to the filesystem, they are a
  natural fit.  Just make sure you pass in 'self' as an argument,
  allowing the function to invoke Folder methods to add documents.
  """

  directory = 'c:/temp/OSS/QandA'
  response = '<P>Starting External Method...</P>'

  for filename in os.listdir(directory):
    # Skip things ending in '~' from Emacs
    if filename[-1] == '~': continue
    contents = open(os.path.join(directory,filename)).read()
    try:
      # See if the document exists, if so, grab it and update it.
      document = self[filename]
      document.manage_edit(contents,filename)
      response = response + '\n<P>Added %s.</P>' % filename
    except KeyError:
      # Document doesn't exist so add it
      self.manage_addDocument(filename,'',contents)
      response = response + '\n<P>Updated %s.</P>' % filename

  return response

if __name__ == '__main__': importfiles()