From: Satya G. <sg...@be...> - 2003-08-06 15:43:41
|
Jeff Emanuel wrote: > >You would need to extend the language grammar. > Is there any document that describes how to achieve this? Is it a recommended approach? Thanks for any pointers, -satya > How about >if your users issue this existing command? > > > >>>>print connect.__doc__ >>>> >>>> > > > >-----Original Message----- >From: Satya Ghattu [mailto:sg...@be...] >Sent: Friday, July 18, 2003 8:46 AM >To: Updike, Clark >Cc: 'jyt...@li...' >Subject: Re: [Jython-Users] Defining commands in the shell .... > > >Yes, I defined a sitecustomize.py file under the Lib directory to run and >set my environment, something like this: >sitecustomize.py >import sys >def help(name): > if (name == "connect"): > print 'This command lets you connect to the server" >The sitecustomize.py will be executed when you bring up an interactive >session. I can do something like, > > >>>>help("connect") >>>> >>>> >And this will do what i want. >But my question is can I do something like, > > >>>>help connect >>>> >>>> >with out the enclosing brackets? Calling help("connect") somehow doesn't >seem natural. My users are complaining about that they do not want to call >as if they are calling functions, they just want to be able to issue >commands as if they are interacting with a command shell. >Can this be achieved? > >Thanks for any help, >-satya > >Updike, Clark wrote: > > >You can run a script in the environment that sets up the help function > >before the interactive session takes over. I use this to set up > >lots of other stuff (database connections, app functions, variables) > >for users. > > > >I don't think the environment variable PYTHONSTARTUP (which runs the > >specified script in Python) does anything in Jython. However, > >this is how I achieve the same end. > > > >FILE PyEnv.py ---------------------------------------- > ># Sets up the custom command line environment. > ># Can also run user scripts before going interactive. > ># > ># FYI: calling batch file must use -i switch to go to an > ># interactive session after running the user's script. > > > >import sys > > > ># set up help function > ># users can run help on the function object: help(envFunc) > ># or on the string name of the function: help('envFunc') > >def help(subject='help'): > > """help([,subject]) -> None > > > > Put your high level help documentation goes here: > > List of environments variables, functions, etc. > > """ > > > > if hasattr(subject,'__doc__'): > > > > print subject.__doc__ # passed in function ref > > > > else: > > > > try: > > exec("print " + subject + ".__doc__") > > except NameError, e: > > print "Nothing found by the name '" + subject + "'" > > > ># set up anything else you want (variables, other fuctions, etc.) > > > ># run user's script if present (argv[1]) > >if len(sys.argv) > 1: > > > > execfile(sys.argv[1]) > > print 'Script %s has run' % sys.argv[1] > > > > > >FILE PyLaunch.bat ------------------------------------ > > > >C:\APPS\jython-2.1\jython.bat -i PyEnv.py %1 %2 %3 %4 %5 %6 %7 > > > > > >Then, to start up the interactive session with the help function > >present, just run the bat file: > > > >C:\temp>PyLaunch.bat > > > >C:\temp>C:\APPS\jython-2.1\jython.bat -i PyEnv.py > > > >help(help) > > > >help([,subject]) -> None > > > > Put your high level help documentation goes here: > > List of environments variables, functions, etc. > > > > > > >If you set up resources like database connections, be sure to use > >a try/finally construct in PyEnv.py to clean up after exceptions. > > > >Good luck, > >Clark > > > >-----Original Message----- > >From: Satya Ghattu [ mailto:sg...@be... <mailto:sg...@be...> ] > >Sent: Thursday, July 17, 2003 6:04 PM > >To: ' jyt...@li... ><mailto:jyt...@li...> ' > >Subject: [Jython-Users] Defining commands in the shell .... > > > > > >Hello there... > >I am not sure if this is achievable in Jython interactive shell but > >would like to know for sure ... > >Can I define 'commands' in jython that I can execute when a user types > >it on the interactive shell? > >For example, I would like to define a 'help' command that shows the user > >some basic help about my application. So, the user can just type, > > >>> help > >on the command prompt. And also can these commands take additional > >arguments, like ... > > >>> help connection > >which should display help about connecting to my application. > > > >Thanks for any help, > >-satya > > > > > > > > > >------------------------------------------------------- > >This SF.net email is sponsored by: VM Ware > >With VMware you can run multiple operating systems on a single machine. > >WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > >same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 ><http://www.vmware.com/wl/offer/345/0> > >_______________________________________________ > >Jython-users mailing list > >Jyt...@li... ><mailto:Jyt...@li...> > >https://lists.sourceforge.net/lists/listinfo/jython-users ><https://lists.sourceforge.net/lists/listinfo/jython-users> > > > > > > > > > > > > |