[Zope] [ANN] zshell: The Zope Shell

Jose Soares jose@sferacarta.com
Fri, 04 May 2001 12:02:04 +0200


Where on can find Zope Shell version 0.001 ?
at http://www.zope.org/Members/sf/zopeshell
there's only...

Release               Version                          Date
----------------------------------------------------------------------
Zopeshell 0.4     0.4 (Stable)                    2000/12/19
zopeshell-0.3.0   0.3.0 (Development)      2000/08/05
zopeshell-0.2.0   0.2.0 (Development)      2000/06/06
zopeshell 0.1.1    0.1.1 (Development)     2000/05/07
zopeshell vers 0.1   0.1 (Development)     2000/05/06







Jerome Alet wrote:

> Hi there,
>
> I'm pleased to announce you the Zope Shell version 0.001.
>
> The Zope shell is a GPLed Python Script which makes some of the most
> commonly used unix shell commands available from within Zope, to manage
> the ZODB contents. You'll find this 155 lines script attached to this
> message.
>
> As for the 0.001 version which is attached to this message, the following
> commands are recognized: cd, cp, mv, rm, ls
>
> there are some restrictions however, and it doesn't seem to work with
> absolute paths, read the source for details and the future commands.
>
> zshell accepts an unlimited number of commands to launch in a single Zope
> transaction, so feel free to combine these five commands to do some very
> complicated stuff. Despite its current limitations it works fine here on
> Zope 2.3.2+Hotfix0501.
>
> Please feel free to send me any comment about this software.
>
> Such similar functionnality included in Zope's core would make me VERY
> happy.
>
> hoping this helps.
>
> Jerome Alet - alet@unice.fr
>
>   ------------------------------------------------------------------------
> ## Script (Python) "zshell"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=
> ##title=The Zope Shell
> ##
> # zshell - (c) 2001 Jerome Alet
> #
> # You're welcome to redistribute this software under the
> # terms of the GNU General Public Licence version 2.0
> # or, at your option, any higher version.
> #
> # You can read the complete GNU GPL in the file COPYING
> # which should come along with this software, or visit
> # the Free Software Foundation's WEB site http://www.fsf.org
> #
> # author: Jerome Alet - <alet@unice.fr>
> #
> #
> # This is the Zope shell, an attempt at making the most common
> # Unix shell commands available from within Zope.
> #
> # As of May 3rd 2001, version 0.001, the following commands
> # are recognized:
> #
> #       cd, rm, mv, cp, ls
> #
> # * cd accepts a single path as an argument
> # * rm accepts many path arguments
> # * mv and cp last argument is the destination folder, every previous
> #   argument is an object id in the current folder
> # * ls accepts many meta types as its arguments
> #
> # The future:
> #
> # in the future I'd be interested in adding more functionnalities
> # as well as making it a complete Zope product, splitting it
> # in one method per command, and making the accepted syntax much more
> # match Unix shell's one.
> # adding support for a find command is also high on my priority list
> #
> # Feel free to send me any feedback about this software at: alet@unice.fr
> #
>
> import string
>
> def toObject(curdir, path) :
>         import string
>         path = string.strip(path)
>         if path[0] == '/' :
>                 path = path[1:]
>                 while hasattr(curdir, 'aq_parent') and (curdir.aq_parent is not None):
>                         curdir = curdir.aq_parent
>
>         components = filter(None, string.split(path, '/'))
>         for component in components :
>                 if component == '.' :
>                         continue
>                 elif component == '..' :
>                         if hasattr(curdir, 'aq_parent') and (curdir.aq_parent is not None):
>                                 curdir = curdir.aq_parent
>                 elif hasattr(curdir, component) :
>                         curdir = curdir[component]
>                 else :
>                         return None     # Error
>         return curdir
>
> print context.standard_html_header.document_src()
>
> if context.REQUEST.has_key("commands") :
>         commands = filter(None, context.REQUEST["commands"])
> else :
>         commands = []
>
> print '<p><form action="zshell" method="POST">'
> print 'Enter your commands below:<br>'
> print '<textarea rows="10" cols="50" wrap="physical" name="commands:lines">%s</textarea>' % string.join(commands, '\n')
> print '<br><input type="submit" name="run" value="Run !" />'
> print '</form></p>'
>
> if commands :
>         print '<hr noshade="noshade" width="33%" /><p>Results:'
>         current = context
>         for command in commands :
>                 cmd = command[:2]
>                 print '<br><b>%s:</b> ' % cmd
>                 if cmd == 'cd' :
>                         path = command[3:]
>                         newdir = toObject(current, path)
>                         if (newdir is not None) and hasattr(newdir, 'meta_type') and (newdir.meta_type == 'Folder') :
>                                 current = newdir
>                                 print 'New folder is <em><b>/%s</b></em>' % newdir.absolute_url(relative=1)
>                         else :
>                                 print 'Incorrect path <em><b>%s</b></em>' % path
>                                 print '[%s]' % repr(newdir)
>                 elif (cmd == 'mv') or (cmd == 'cp') :
>                         args = string.split(command[3:])
>                         if len(args) < 2 :
>                                 print 'Incorrect number of arguments'
>                         else :
>                                 dst = args[-1]
>                                 srcs = args[:-1]
>                                 objids = []
>                                 for src in srcs :
>                                         if '/' in src :
>                                                 print 'Paths in source objects are not allowed at this time: <em><b>%s</b></em>' % src
>                                         else :
>                                                 objids.append(src)
>                                 dsto = toObject(current, dst)
>                                 if dsto is None :
>                                         print 'Incorrect destination argument <em><b>%s</b></em>' % dst
>                                         continue
>                                 if dsto.meta_type != 'Folder' :
>                                         print 'Destination <em><b>%s</b></em> is not a folderish object' % dst
>                                         continue
>                                 if cmd == 'cp' :
>                                         clipboard = current.manage_copyObjects(ids = objids)
>                                         action = 'copied'
>                                 else :
>                                         clipboard = current.manage_cutObjects(ids = objids)
>                                         action = 'moved'
>                                 dsto.manage_pasteObjects(cb_copy_data = clipboard)
>                                 for oid in objids :
>                                         print '<br>%s %s' % (oid, action)
>                 elif cmd == 'rm' :
>                         objpaths = filter(None, string.split(string.strip(command[3:])))
>                         for objpath in objpaths :
>                                 object = toObject(current, objpath)
>                                 if object is None :
>                                         print 'Incorrect path <em><b>%s</b></em>' % objpath
>                                 else :
>                                         if hasattr(object, 'aq_parent') :
>                                                 object.aq_parent.manage_delObjects(ids = [object.getId()])
>                                                 print "<br>/%s removed" % object.absolute_url(relative=1)
>                 elif cmd == 'ls' :
>                         metatypes = filter(None, string.split(string.strip(command[3:])))
>                         if metatypes :
>                                 objects = current.objectValues(metatypes)
>                         else :
>                                 objects = current.objectValues()
>                         if objects :
>                                 print '<table border="1"><tr><th>Id</th><th>Title</th><th>MetaType</th></tr>'
>                                 for object in objects :
>                                         title = object.title or '&nbsp;'
>                                         print '<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (object.getId(), title, object.meta_type)
>                                 print '</table>'
>                 else :
>                         print 'Unknown command <em><b>%s</b></em>' % command
>         print '</p>'
>
> print context.standard_html_footer.document_src()
> return printed