Application -- Venue interaction

Eric Olson eolson at mcs.anl.gov
Fri Sep 12 16:56:33 CDT 2003


Here is a quick sample on how to use the venueUrl option that Ivan 
recently added.  All this example does is register the app and then let 
your app be launched from the venueclient with the venueUrl provided as an 
argument.  The SampleApp just prints the url and exits.  I sent this to 
Terry, but others may want to comment on it or try it -- if so, just 
follow the instructions below.
Eric

---------- Forwarded message ----------
Date: Fri, 12 Sep 2003 14:42:45 -0500 (CDT)
From: Eric Olson <eolson at mcs.anl.gov>
To: Terrence Disz <disz at mcs.anl.gov>
Subject: sample app

Hi Terry,

This only works in cvs right now and of course the methods for doing these 
things may change with future releases.  The two files attached should be 
in the same directory.

1) Run RegisterSampleApp.py to register SampleApp.py.

In windows (in linux use python2):
  python RegisterSampleApp.py

2) Restart the venueclient (in debug mode --debug so you can see the print 
statement later) and join a venue.  You should see "Start Sample App" in 
venue applications.  It will put a "Sample App" entry under Applications 
in the current venue, and will also run it.

3) Open or double-click the new "Sample App".  The SampleApp.py will run 
and print out the current venue url (in windows, you will probably only 
see it if you run the venueclient in debug mode).

You no longer need the two files because SampleApp.py has been copied to 
your .AccessGrid/SharedApplications directory and it runs from there.

Let me know if you have any problems.

Eric

-------------- next part --------------
#!/usr/bin/python2
# Normal import stuff
import os
import sys
import getopt
import logging
from threading import Thread
import Queue
import shutil

from wxPython.wx import *

# Imports we need from the Access Grid Module
from AccessGrid.hosting.pyGlobus import Client
from AccessGrid.EventClient import EventClient
from AccessGrid.Events import ConnectEvent, Event
from AccessGrid import Platform
from AccessGrid import DataStore


# This function registers the application with the users environment
# There is no longer support for shared application installations
# that might be reintroduced later.

def registerApp(fileName):
    import AccessGrid.Toolkit as Toolkit
    app = Toolkit.CmdlineApplication()
    appdb = app.GetAppDatabase()

    # Get just the filename
    fn = os.path.split(fileName)[1]

    # Find the app dir
    uad = Platform.GetUserAppPath()

    # Get the absolute path for copying the file
    src = os.path.abspath(fn)

    # Get the destination filename
    dest = os.path.join(uad, fn)

    if sys.platform == Platform.WIN:
        exeCmd = sys.executable + " \"" + dest + "\" %(venueUrl)s"
    else:
        exeCmd = sys.executable + " " + dest + " %(venueUrl)s"

    print "SRC: %s DST: %s CMD: %s" % (src, dest, exeCmd)
    
    # Copy the file
    try:
        shutil.copyfile(src, dest)
    except IOError:
        print "Couldn't copy app into place, bailing."
        sys.exit(1)

    # If the application requires additional files, you can
    # put them in a list here.
    if sys.platform == Platform.WIN:
        additional_files = []
    else:
        additional_files = []

    # Copy supporting files 
    for file in additional_files:
        # Get the absolute path for copying the file
        src = os.path.abspath(file)

        # Get the destination filename
        dest = os.path.join(uad, file)

        # copy the file
        try:
            shutil.copyfile(src, dest)
        except IOError:
            print "Couldn't copy", src, "into", dest, ", bailing."

        # make the file executable
        os.chmod(dest, 0755)

    # Call the registration method on the applications database
    appdb.RegisterApplication("Sample App",
                              "application/x-ag-sampleapp",
                              "sampleapp",
                              {"Open" : exeCmd })

    # That command copies the executable to the shared app database
    # We also need to copy the vncviewer file
    app_dir = os.path.join(appdb.defaultPath, appdb.defaultName)
    

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Utility functions
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#
# This gets logging started given the log name passed in
# For more information about the logging module, check out:
# http://www.red-dove.com/python_logging.html
#
def InitLogging(appName, debug=0):
    """
    This method sets up logging so you can see what's happening.
    If you want to see more logging information use the appName 'AG',
    then you'll see logging information from the Access Grid Module.
    """
    logFormat = "%(name)-17s %(asctime)s %(levelname)-5s %(message)s"


    # Set up a venue client log, too, since it's used by the event client
    log = logging.getLogger("AG.VenueClient")
    log.setLevel(logging.DEBUG)
    hdlr = logging.StreamHandler()
    hdlr.setFormatter(logging.Formatter(logFormat))
    log.addHandler(hdlr)

    log = logging.getLogger(appName)
    log.setLevel(logging.DEBUG)


    # Log to file
    logFile = appName + ".log"
    fileHandler = logging.FileHandler(logFile)
    fileHandler.setFormatter(logging.Formatter(logFormat))
    log.addHandler(fileHandler)

    # If debugging, log to command window too
    if debug:
        hdlr = logging.StreamHandler()
        hdlr.setFormatter(logging.Formatter(logFormat))
        log.addHandler(hdlr)
    return log


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# MAIN block
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if __name__ == "__main__":

    InitLogging("RegisterSampleApp")
    registerApp("SampleApp.py")

-------------- next part --------------
import sys

print sys.argv

if len(sys.argv) > 1:
    print "venue:", sys.argv[1]



More information about the ag-dev mailing list