Can someone please help me with accessing web2py objects outside web2py for a utility script.

333 views
Skip to first unread message

JoeCodeswell

unread,
Jan 4, 2014, 1:25:20 PM1/4/14
to web...@googlegroups.com
Dear web2py Forum,

I thought it would be a great idea if i wrote a utility script which would take as input a web2py app name and

create
        - HTML Pages and
        - Associated Default Controller Actions
        for each:
            Menu Item of the Input Application Name

I am sure many of you are chuckling because of the difficulties i have been having accessing the web2py environment without running web2py. :)

My code so far is at the bottom.

It results in this error stack.

Traceback (most recent call last):
 
File "C:\web2py\pages4menu.py", line 127, in <module>
    test
() #test
 
File "C:\web2py\pages4menu.py", line 116, in test
    pages4menu
('menu2pagest')
 
File "C:\web2py\pages4menu.py", line 58, in pages4menu
   
from JoeTempPkg import menu as jmenu
 
File "C:\web2py\JoeTempPkg\menu.py", line 39, in <module>
   
(T('Home'), False, URL('default', 'index'), []),
 
File "C:\web2py\gluon\html.py", line 300, in URL
   
raise SyntaxError('not enough information to build the url (%s %s %s)' % (application, controller, function))
SyntaxError: not enough information to build the url (None default index)


If anyone has any suggestions, please let me know.

Thanks in advance.

Love and peace,

Joe

Here is the code. Thanks again.

'''
pages4menu.py creates
        - HTML Pages and
        - Associated Default Controller Actions
        for each:
            Menu Item of the Input Application Name
 
Usage:   pages4menu.py inAppName
Example: pages4menu.py myapp

Created on Dec 28, 2013
@author: Joe Dorocak aka Joe Codeswell
License: Use this as you please. :)
         Use with caution - I have done minimal testing.
         RIGHT NOW IT DOESN'
T WORK AT ALL! :)
         
No warranty is implied. :)
'''  
       

'''
RESEARCH        
google
: web2py use gluon in a python program
    http
://www.web2pyslices.com/slice/show/1478/using-modules-in-web2py
google
: use gluon in python
   
Add gluon to global python path
        https
://www.mail-archive.com/web...@googlegroups.com/msg62545.html
web2py
group: custom_import.
book
'Accessing the API from Python modules'
    http
://www.web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules
        find
: Web2py defines some global objects (request, response, session, cache, T) that can only exist when an HTTP request is present (or is faked).
        find also
: The core API entities in the web2py execution environment are request, response, session, cache, URL, HTTP, redirect and T and are discussed below.
       
MAYBE i need to
do this as an app?
   
First: post this stuff on the google group.
'''
import sys, os, tempfile, shutil, importlib
from gluon.html import *


def pages4menu(appName):
   
    assert os.path.basename(os.path.abspath(os.curdir)) == '
web2py', 'This program must be run from the web2py directory.'

    actionTemplate = '''
def %s(): return dict()
   
'''
    pageTemplate = '''
{{response.title = "%s"}}
   
{{extend 'layout.html'}}
   
<h1>Welcome to Epiphany Listens</h1>
    <p>This is the default/
public/index.html template</p>
    {{#=BEAUTIFY(response._vars)}}
    '''

    # create temporary dir/
pkg for file manipulation/import
    joeTmpPkgPath
= createJoeTempPkg()

    appPath
= os.path.join('.','applications',appName)
    appMenuPath
= os.path.join(appPath,'models','menu.py')
    prepTempMenu
(appMenuPath, joeTmpPkgPath)  
   
   
from JoeTempPkg import menu as jmenu
       
   
print [item for item in dir(jmenu) if not item.startswith("__")]
   

   
# destroy temporary dir/pkg RECURSIVELY
    destroyTempPkg
(joeTmpPkgPath)
   
def prepTempMenu(appMenuPath, joeTmpPkgPath):    
   
# copy the appMenuFile into the tempPkg for import
    shutil
.copy(appMenuPath, joeTmpPkgPath)

    insertStr
= 'from gluon.html import *\n'
    insertStr
+= 'from gluon.storage import *\n'        
    insertStr
+= 'response = Storage()\n'        
    insertStr
+= 'request = Storage()\n'  
    insertStr
+= 'def T(aString): return aString\n'
    insertStr
+= 'request.application = "helloApp"\n'
    insertStr
+= 'response.meta = Storage()\n'
    insertStr
+= 'response.meta.author = "helloAuthor"\n'
    insertStr
+= 'request.application = "app_name"\n'
    insertStr
+= 'request.controller = "default"\n'
    insertStr
+= 'request.function = "myfunc"\n'

    f
= open(os.path.join(joeTmpPkgPath,'menu.py'), 'r'); s1 = f.read(); f.close()
    l
= s1.splitlines(); l.insert(1, insertStr); s2 = '\n'.join(l)
    f
= open(os.path.join(joeTmpPkgPath,'menu.py'), 'w'); f.write(s2); f.close()
   
   
   
def destroyTempPkg(path):
    shutil
.rmtree(path)

def createJoeTempPkg():
   
   
#tempDirAbsPath = tempfile.mkdtemp()
    joeTmpPkgPath
= os.path.join('.','JoeTempPkg')
   
if not os.path.exists(joeTmpPkgPath):
        os
.mkdir(joeTmpPkgPath)
   
else:
       
# delete everything in the joeTmpPkgPath folder   - http://stackoverflow.com/questions/185936/delete-folder-contents-in-python
        folder
= joeTmpPkgPath
       
for the_file in os.listdir(folder):
            file_path
= os.path.join(folder, the_file)
           
try:
                os
.unlink(file_path)
           
except Exception, e:
               
print e
           
   
# make the tempdir a package to expedite importing files from here
    f
= open(os.path.join(joeTmpPkgPath,'__init__.py'), 'w'); f.write('\n'); f.close()

   
return joeTmpPkgPath

 

def test():
   
#os.chdir(r"..") # test assertion program must be run from the web2py directory.
    pages4menu
('menu2pagest')

NUM_ARGS
= 1
def main():
    args
= sys.argv[1:]
   
if len(args) != NUM_ARGS or "-h" in args or "--help" in args:
       
print __doc__
        sys
.exit(2)
    pages4menu
(args[0])

if __name__ == '__main__':
    test
() #test
   
#main() #production


"""possible change of approach
    # new approach
##        don't import instead
##        get stuff and ddo your own menu

    # import menu.py
    #    see   variable-packages  http://stackoverflow.com/questions/6677424   find Dan Copeland
    #          http://docs.python.org/2/library/functions.html#__import__
    #          http://docs.python.org/2/library/importlib.html
    #          http://effbot.org/zone/import-confusion.htm
    # my_module = importlib.import_module("
package.path.%s" % module_name)
    # menuMod = importlib.import_module('menu.py', package=tempPkgAbsPath)
    # from gluon import *            # see http://stackoverflow.com/questions/13649411
     
   # problem menu is not importing anything
        # because of the web2py approach
        # import response.menu
        # to temp/menu.py prepend
            # from gluon.html import *
"""

"""saved experiments

PythonWin 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> pwd
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
NameError: name 'pwd' is not defined
>>> os.path.abspath(os.curdir)
'C:\\web2py'
>>> os.path.abspath(os.curdir).dirname
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
AttributeError: 'str' object has no attribute 'dirname'
>>> os.path.abspath.dirname
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
AttributeError: 'function' object has no attribute 'dirname'
>>> os.path.abspath.dirname()
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
AttributeError: 'function' object has no attribute 'dirname'
>>> os.path.dirname()
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
TypeError: dirname() takes exactly 1 argument (0 given)
>>> print os.path.basename(os.curdir)
>>> print os.path.abspath.basename(os.curdir)
.
>>> print os.path.abspath.basename(os.curdir)
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
AttributeError: 'function' object has no attribute 'basename'
>>> print os.path.abspath(os.curdir).basename
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
AttributeError: 'function' object has no attribute 'basename'
>>> print os.path.abspath(os.curdir).basename
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
AttributeError: 'str' object has no attribute 'basename'
>>> print os.path.basename(os.path.abspath(os.curdir))
web2py
>>>
pages4menu.py creates
        - HTML Pages and
        - Associated Default Controller Actions
        for each
            Menu Item of the Input Application Name
 
Usage:   pages4menu.py inAppName
Example: pages4menu.py myapp

Created on Dec 28, 2013
@author: Joe Dorocak aka Joe Codeswell
License: Use this as you please. :)
         Use with caution - I have done minimal testing.
         No warranty is implied. :)


Traceback (most recent call last):
  File "
C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript
    debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File "
C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "
C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 655, in run
    exec cmd in globals, locals
  File "
C:\web2py\pages4menu.py", line 17, in <module>
    '''
  File "
C:\web2py\pages4menu.py", line 35, in test
    pages4menu('menu2pagest')
  File "
C:\web2py\pages4menu.py", line 22, in pages4menu
    assert os.path.basename(os.path.abspath(os.curdir)) == 'web2py', 'This program must be run from the web2py directory.'
AssertionError: This program must be run from the web2py directory.
Traceback (most recent call last):
  File "
C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript
    debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File "
C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "
C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 655, in run
    exec cmd in globals, locals
  File "
C:\web2py\pages4menu.py", line 17, in <module>
    '''
  File "
C:\web2py\pages4menu.py", line 35, in test
    pages4menu('menu2pagest')
  File "
C:\web2py\pages4menu.py", line 22, in pages4menu
    assert os.path.basename(os.path.abspath(os.curdir)) == 'web2py', 'This program must be run from the web2py directory.'
AssertionError: This program must be run from the web2py directory.
>>> os.chdir(r"
web2py")
>>> import shutil
>>> os.path.join('./applications/',appName,)
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
NameError: name 'appName' is not defined
>>> appName = 'menu2pagest'
>>> os.path.join('./applications/',appName,)
'./applications/menu2pagest'
>>> os.path.join(list('./applications/',appName,'/models/menu.py'))
'/models/menu.py'
>>> os.path.join(['./applications/',appName,'/models/menu.py'])
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
TypeError: list() takes at most 1 argument (3 given)
>>> os.path.join('./applications/',appName,'/models/menu.py')
['./applications/', 'menu2pagest', '/models/menu.py']
>>> os.path.abspath(os.path.join('./applications/',appName,'/models/menu.py'))
'C:\\models\\menu.py'
>>> os.path.abspath('.')
'C:\\web2py'
>>> appName
'menu2pagest'
>>> os.path.abspath(os.path.join('./applications/',appName))
'C:\\web2py\\applications\\menu2pagest'
>>> os.path.abspath(os.path.join('./applications/',appName,'/models/))
Traceback (  File "
<interactive input>", line 1
    os.path.abspath(os.path.join('./applications/',appName,'/models/))
                                                                     ^
SyntaxError: EOL while scanning string literal
>>> os.path.abspath(os.path.join('./applications/',appName,'/models/'))
'C:\\models'
>>> os.path.join('.',appName,'models','menu.py')
'.\\menu2pagest\\models\\menu.py'
>>> os.path.abspath(os.path.join('.',appName,'models','menu.py'))
'C:\\web2py\\menu2pagest\\models\\menu.py'
>>> os.path.isfile()
False
>>> p = os.path.abspath(os.path.join('.','applications',appName,'models','menu.py'))
>>> os.path.isfile(p)
False
>>> p
'C:\\web2py\\menu2pagest\\models\\menu.py'
>>> p = os.path.abspath(os.path.join('.','applications',appName,'models','menu.py'))
>>> os.path.isfile(p)
True
>>> appPath = os.path.join('.','applications',appName)
>>> appPath
'.\\applications\\menu2pagest'
>>> menuMod = importlib.import_module('menu.py', package=p)
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
NameError: name 'importlib' is not defined
>>> import importlib
>>> menuMod = importlib.import_module('menu.py', package=p)
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
  File "
C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named menu.py
>>> menuMod = importlib.import_module('C:\\web2py\\menu2pagest\\models\\menu.py')
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
  File "
C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
ImportError: Import by filename is not supported.
>>> os.chdir('C:\\web2py\\menu2pagest\\models\\menu.py')
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
WindowsError: [Error 3] The system cannot find the path specified: 'C:\\web2py\\menu2pagest\\models\\menu.py'
>>> os.chdir('C:\\web2py\\applications\\menu2pagest\\models\\menu.py')
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
WindowsError: [Error 267] The directory name is invalid: 'C:\\web2py\\applications\\menu2pagest\\models\\menu.py'
>>> os.chdir('C:\\web2py\\applications\\menu2pagest\\models')
>>> import menu.py
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
ImportError: No module named menu.py
>>> os.chdir('C:\\web2py\\')
>>> os.mkdir(os.path.join('.','joeTempPkg')
... )
>>> f = open(os.path.join(tmpPkgPath,'__init__.py'), 'w'); f.write('\n'); f.close()
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
NameError: name 'tmpPkgPath' is not defined
>>> tmpPkgPath = os.path.join('.','joeTempPkg')
>>> f = open(os.path.join(tmpPkgPath,'__init__.py'), 'w'); f.write('\n'); f.close()
>>> from joeTempPkg import menu
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
ImportError: cannot import name menu
>>> appPath = os.path.join('.','applications',appName)
>>> appMenuPath = os.path.join(appPath,'models','menu.py')
>>> shutil.copy(appMenuPath, joeTempPkg)
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
NameError: name 'joeTempPkg' is not defined
>>> joeTempPkg = tmpPkgPath
>>> shutil.copy(appMenuPath, joeTempPkg)
>>> from joeTempPkg import menu
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
  File "
C:\web2py\joeTempPkg\menu.py", line 8, in <module>
    response.logo = A(B('web',SPAN(2),'py'),XML('&trade;&nbsp;'),
NameError: name 'A' is not defined
>>> from joeTempPkg.menu import *Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
  File "
C:\web2py\joeTempPkg\menu.py", line 8, in <module>
    response.logo = A(B('web',SPAN(2),'py'),XML('&trade;&nbsp;'),
NameError: name 'A' is not defined
>>> from joeTempPkg.menu import *
Traceback (most recent call last):
  File "
<interactive input>", line 1, in <module>
  File "
C:\web2py\joeTempPkg\menu.py", line 8, in <module>
    response.logo = A(B('web',SPAN(2),'py'),XML('&trade;&nbsp;'),
NameError: name 'A' is not defined
>>>
"""

Thanks again - Joe.



Anthony

unread,
Jan 4, 2014, 1:52:05 PM1/4/14
to web...@googlegroups.com
Don't have time to look at all the code, but the error from the URL function can be fixed by providing the app name as the first argument (otherwise, it attempts to get the app name from request.application, which won't work outside of a request).

Anthony

JoeCodeswell

unread,
Jan 4, 2014, 2:34:29 PM1/4/14
to web...@googlegroups.com
Dear Anthony,

Thanks for the reply. I fixed the URL by adding one more insert into the temporary menu.py file.

It defined URL as follows.

    insertStr += 'def URL(*args): return ",".join([str(arg) for arg in args])\n'

Now in my pages4menu.py, having done a good import of the temp menu.py module, I get a result i think i can live with. I'll need to press on.

Here's the code snippet followed by the resulting output.

    from JoeTempPkg import menu as
jmenu
       
   
#print [item for item in dir(jmenu) if not item.startswith("__")]
   
from pprint import pprint as pp
    pp
(jmenu.response.menu)
'''
yields:
[('
Home', False, 'default,index', []),
 ('
Ministries',
  False,
  '
default,index',
  [('
Children',
    False,
    '
default,index',
    [('
Nursery', False, 'default,index', []),
     ('
Church School', False, 'default,index', []),
     ('
Seekers', False, 'default,index', [])]),
   ('
Worship', False, 'default,index', []),
   ('
Music', False, 'default,index', []),
   ('
Fellowship', False, 'default,index', []),
   ('
Spiritual Formation', False, 'default,index', [])]),
 ('
Facility Rental',
  False,
  '
http://www.example.org/facilities/facilities.php',
 
[]),
 
('Contact', False, 'default,index', [])]
'''


Thanks again, Anthony.

Love and peace,

Joe

JoeCodeswell

unread,
Jan 28, 2014, 1:33:10 PM1/28/14
to web...@googlegroups.com
OK so here's the FINAL RESULT of the utility i came up with.

It seems to work for me. It helps me with the drudgery of creating and recreating menus, and associated views and

I took a different approach than originally. I now require that it be run from the web2py command line for the application to which it refers. That way i get the response.menu object without hassle.

I put it up on GitHub here.

Here's the current, seems to test OK, code.

Thanks for a great framework and community.

Love and peace,

Joe

#! /usr/bin/env python
# -*- coding: UTF-8 -*-
'''makePagesNactions4MenuTitles.py creates
    - Associated Controller Actions and
    - HTML View Pages  
    for each:
        Menu Item Title of the Input <Application Name>  
       
Output:
    In <path to makePagesNactions4MenuTitles.py>
        1. A directory named '
outdir' is created
        2. In '
outdir'
            2.1 A file named controller.py is created.
                This contains Menu Associated Controller Actions to be copied into your Application'
s Controller File of choice.
                N
.B. Home menu item WILL NOT MATCH index action
           
2.2 A directory named 'viewfiles' inside of which are
                a
set of Menu Associated HTML View Page files are created. These
                files are to be copied
into your Application's 'views' Subdirectory of choice.
       
Usage: This program must be run from the web2py Interactive Command Shell Interpreter:
    Open a command window for your system [Windows, Mac or NIX]
    $ cd <web2py install dir>
    $ python web2py.py -S <Application Name> -M
    >>> import os
    >>> os.chdir(r"<path to makePagesNactions4MenuTitles.py>")        
    >>> execfile('
makePagesNactions4MenuTitles.py')

License:
from http://wiki.civiccommons.org/Choosing_a_License
and http://opensource.org/licenses/MIT

The MIT License (MIT)

Copyright (c) 2014 Joseph P. Dorocak aka Joe Codeswell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


'''

import sys

def makePagesNactions4MenuTitles():
    makeOutputDirsIfRequired
()
    menuTitleList
= getTitlesFromMenu(response.menu)
   
print '\n'.join(menuTitleList)
    menuTitleList
= getTitlesFromMenu(response.menu)
    makeActions4menuTitles
(menuTitleList)
    makePages4menuTitles
(menuTitleList)

def makeOutputDirsIfRequired():
   
'''make the Output Dirs If Non Existent'''
   
if not os.path.isdir('outdir'): os.mkdir('outdir')
   
if not os.path.isdir(os.path.join('outdir','viewfiles')): os.mkdir(os.path.join('outdir','viewfiles'))  
   
def getTitlesFromMenu(menu):
    menuTitleList
= []
    tt
= TreeTrav(menu, menuTitleList)
    menuTitleList
= tt.recursiveTreeProperties(menu)
   
return menuTitleList
   
def makeActions4menuTitles(menuTitleList):
    resStr
= ''
   
for item in menuTitleList:
        resStr
= ''.join([resStr, 'def %s(): response.flash = T("OurSite - %s"); return dict()\n'%(item.lower().replace(' ', '_'),item)])
        f
= open(os.path.join('outdir','controller.py'), 'w'); f.write(resStr); f.close()    
       
   
pageTemplate
= '''{{response.title = "%s"}}
{{extend '
joe_layout.html'}}
<h2>Welcome to OurSite %s</h2>
<b>Information about %s.</b>
<p>%s ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. </p>
{{#=BEAUTIFY(response._vars)}}
'''

# N.B. Home menu item WILL NOT MATCH index action
   
def makePages4menuTitles(menuTitleList):
   
for item in menuTitleList:
        pageContent
=  pageTemplate%(item,item,item,item)
        outFileName
= item.lower().replace(' ', '_')+'.html'
        f
= open(os.path.join('outdir','viewfiles',outFileName), 'w'); f.write(pageContent); f.close()    
         
#<testTreeTravJoe.py>    
class TreeTrav:
   
def __init__(self, treeContainerNode, resultList):
       
self.treeContainerNode = treeContainerNode
       
self.resultList = resultList
 
   
def isLeafNode(self, node):      # the test for web2[y menus
        isLeaf
= node[3] == []
       
return isLeaf

   
def processNode(self, node):
       
#print 'processNode          (node[0]:%s, node[1]:%s, node[2]:%s, isLeafNode(node):%s'%(node[0],node[1],node[2],isLeafNode(node))  
       
pass

   
def processLeaf(self, node):
       
#print 'processLeaf          (node[0]:%s, node[1]:%s, node[2]:%s, isLeafNode(node):%s'%(node[0],node[1],node[2],isLeafNode(node))  
       
self.resultList.append(node[0])
       
   
def processContainerNode(self, node):
       
#print 'processContainerNode (node[0]:%s, node[1]:%s, node[2]:%s, isLeafNode(node):%s'%(node[0],node[1],node[2],isLeafNode(node))  
       
self.resultList.append(node[0])
       
   
def recursiveTreeProperties(self, treeContainerNode):
       
for node in treeContainerNode:                    # node is a containerNode or leafNode
           
self.processNode(node)
           
if self.isLeafNode(node):
               
self.processLeaf(node)                    # node is a leafNode
           
else:                            
               
self.processContainerNode(node)           # node is a containerNode    
               
self.recursiveTreeProperties(node[3])     # recursive call: node is a tree ie it has submembers
               
       
return self.resultList
       
#</testTreeTravJoe.py>  
   
def main():
    makePagesNactions4MenuTitles
()

if __name__ == '__main__':
    main
()
   
Reply all
Reply to author
Forward
0 new messages