def __init__(self): Application.__init__(self) # Register .agpkg mime type if not IsWindows(): agpmFile = os.path.join(AGTkConfig.instance().GetBinDir(), "agpm3.py") agpmCmd = agpmFile + " --gui --package %f" MimeConfig.instance().RegisterMimeType( "application/x-ag3-pkg", ".agpkg3", "agpkg file", "Access Grid Package", [ ("agpm3.py", agpmCmd, "open") ] ) # Register .vv3d if not IsWindows(): vcFile = os.path.join(AGTkConfig.instance().GetBinDir(), "GoToVenue3.py") vcCmd = vcFile + " --file %f" MimeConfig.instance().RegisterMimeType( "application/x-ag-venueclient", ".vv3d", "AG Virtual Venues File", "Access Grid Virtual Venue Description", [ ("GoToVenue.py", vcCmd, "Open") ] )
def testAGTkConfigDir(self): #print "BASEDIR:", AGTkConfig.instance().installBase, self.userdir, self.sysdir configDir = AGTkConfig.instance().GetConfigDir() assert configDir != "" and configDir is not None, 'empty config dir' expectedDir = os.path.join(self.sysdir, "Config") assert configDir == expectedDir, 'AGTkConfig config dir %s != AGTkConfig...GetConfigDir() %s' % ( configDir, expectedDir)
def testGetConfigDir(self): configDir = AGTkConfig.instance().GetConfigDir() assert configDir != "" and configDir is not None, 'invalid user config dir' expectedDir = os.path.join(self.sysdir, "Config") assert configDir == expectedDir, 'AGTkConfig config dir %s != AGTkConfig...GetConfigDir() %s' % ( configDir, expectedDir) assert os.path.isdir(configDir)
def ReadLicenseFile(self): ''' Read COPYING.txt file from shared document directory. ''' config = AGTkConfig.instance() path = os.path.join(config.GetDocDir(), 'COPYING.txt') licenseFile = file(os.path.normpath(path)) self.licenseText = licenseFile.read() licenseFile.close()
def test_200_TestStaticStreams(self): global venue, venueUrl global bridgeConfig global bridgerName, bridgerLoc RemoveStreams(venue) # Add static stream to venue streamDesc = StreamDescription3( 'static test stream', MulticastNetworkLocation('224.2.2.2', 20000, 127), Capability3('producer', 'test'), 0, None, 1) venue.AddStream(streamDesc) # Start the bridgeserver against the venue # - find the bridgeserver exe bin = AGTkConfig.instance().GetBinDir() bridgeserverexe = os.path.join(bin, 'BridgeServer.py') # - build a config file for the bridge server configFile = os.tmpnam() f = open(configFile, 'w') f.write(bridgeConfig % ( bridgerName, bridgerLoc, venueUrl, )) f.close() # - start the bridge server exe = sys.executable opts = [ bridgeserverexe, '-c', configFile, ] processManager.StartProcess(exe, opts) # Enter the venue print "sleeping" time.sleep(10) # Confirm presence of bridged network locations numBridgedStreams = 0 streamList = venue.GetStreams() for stream in streamList: for netloc in stream.networkLocations: print "stream : ", stream.id, stream.name, netloc.host, netloc.port, netloc.profile.name, netloc.profile.location if (netloc.profile.name == bridgerName and netloc.profile.location == bridgerLoc): numBridgedStreams += 1 print "numstreams, numbridgedstreams = ", len( streamList), numBridgedStreams assert len(streamList) == numBridgedStreams
def UnregisterServicePackage(servicePackageFile): tkConf = AGTkConfig.instance() servicePackagePath = os.path.join(tkConf.GetNodeServicesDir(),servicePackageFile) try: os.remove(servicePackagePath) ShowResult( "Unregistration of service package %s complete." % (servicePackageFile,) ) except Exception, e: log.exception("UnregisterServicePackage") ShowResult( e )
def setUp(self): # only way to clear the config seems to be to # set the instance to None. Config.AGTkConfig.theAGTkConfigInstance = None self.userdir = tempfile.mkdtemp() self.sysdir = tempfile.mkdtemp() self.foodir = os.path.join(self.sysdir, "foo") os.mkdir(self.foodir) try: self.origSysDir = os.environ[Platform.AGTK_LOCATION] except: self.origSysDir = None try: self.origUserDir = os.environ[Platform.AGTK_USER] except: self.origUserDir = None os.environ[Platform.AGTK_LOCATION] = self.sysdir os.environ[Platform.AGTK_USER] = self.userdir # initialize AGTk config. AGTkConfig.instance(initIfNeeded=1)
def UnregisterServicePackage(servicePackageFile): tkConf = AGTkConfig.instance() servicePackagePath = os.path.join(tkConf.GetNodeServicesDir(), servicePackageFile) try: os.remove(servicePackagePath) ShowResult("Unregistration of service package %s complete." % (servicePackageFile, )) except Exception, e: log.exception("UnregisterServicePackage") ShowResult(e)
def test_200_TestStaticStreams(self): global venue, venueUrl global bridgeConfig global bridgerName,bridgerLoc RemoveStreams(venue) # Add static stream to venue streamDesc = StreamDescription3('static test stream', MulticastNetworkLocation('224.2.2.2',20000,127), Capability3('producer','test'), 0,None, 1) venue.AddStream(streamDesc) # Start the bridgeserver against the venue # - find the bridgeserver exe bin = AGTkConfig.instance().GetBinDir() bridgeserverexe = os.path.join(bin,'BridgeServer.py') # - build a config file for the bridge server configFile = os.tmpnam() f = open(configFile,'w') f.write( bridgeConfig % (bridgerName,bridgerLoc,venueUrl,)) f.close() # - start the bridge server exe = sys.executable opts = [ bridgeserverexe, '-c', configFile, ] processManager.StartProcess(exe,opts) # Enter the venue print "sleeping" time.sleep(10) # Confirm presence of bridged network locations numBridgedStreams = 0 streamList = venue.GetStreams() for stream in streamList: for netloc in stream.networkLocations: print "stream : ", stream.id, stream.name, netloc.host, netloc.port, netloc.profile.name, netloc.profile.location if (netloc.profile.name == bridgerName and netloc.profile.location == bridgerLoc ): numBridgedStreams += 1 print "numstreams, numbridgedstreams = ", len(streamList), numBridgedStreams assert len(streamList) == numBridgedStreams
def test_130_GetAvailableServices(self): global serviceManager, server, smurl svcList = serviceManager.GetAvailableServices() nsDir = AGTkConfig.instance().GetNodeServicesDir() svcFileList = os.listdir(nsDir) print "Testing available services" print "- Number of service files:", len(svcFileList) print "- Number of reported services:", len(svcList) assert len(svcList) == len(svcFileList)
def RegisterServicePackage(servicePackage): tkConf = AGTkConfig.instance() servicePackageFile = os.path.split(servicePackage)[1] servicePackagePath = os.path.join(tkConf.GetNodeServicesDir(),servicePackageFile) try: shutil.copy(servicePackage,servicePackagePath) # Set the permissions correctly os.chmod(servicePackagePath,0644) except Exception, e: log.exception("RegisterServicePackage") ShowResult(str(e)) return
def __init__(self): Application.__init__(self) # Register .agpkg mime type if not IsWindows(): agpmFile = os.path.join(AGTkConfig.instance().GetBinDir(), "agpm3.py") agpmCmd = agpmFile + " --gui --package %f" MimeConfig.instance().RegisterMimeType( "application/x-ag3-pkg", ".agpkg3", "agpkg file", "Access Grid Package", [("agpm3.py", agpmCmd, "open")]) # Register .vv3d if not IsWindows(): vcFile = os.path.join(AGTkConfig.instance().GetBinDir(), "GoToVenue3.py") vcCmd = vcFile + " --file %f" MimeConfig.instance().RegisterMimeType( "application/x-ag-venueclient", ".vv3d", "AG Virtual Venues File", "Access Grid Virtual Venue Description", [("GoToVenue.py", vcCmd, "Open")])
def RegisterServicePackage(servicePackage): tkConf = AGTkConfig.instance() servicePackageFile = os.path.split(servicePackage)[1] servicePackagePath = os.path.join(tkConf.GetNodeServicesDir(), servicePackageFile) try: shutil.copy(servicePackage, servicePackagePath) # Set the permissions correctly os.chmod(servicePackagePath, 0644) except Exception, e: log.exception("RegisterServicePackage") ShowResult(str(e)) return
def Run(self): self.running = 1 avahiDiscoverExe = os.path.join(AGTkConfig.instance().GetBinDir(), 'ag-avahi-discover3.py') self.subproc = subprocess.Popen([avahiDiscoverExe, self.serviceType], bufsize=1, stdout=subprocess.PIPE, close_fds=True) # Loop while self.subproc.poll() == None and self.IsRunning(): line = self.subproc.stdout.readline().strip() if not line : break if line[0] == '+' : txtparts = line.split('=') if txtparts and len(txtparts) > 1: self.__NewService(txtparts[0][1:], txtparts[1]) elif line[0] == '-' : self.__RemoveService(line[1:])
def test_100_Setup(self): global venueServer, processManager, venue, venueUrl # initialize toolkit and environment app = Toolkit.Service().instance() app.Initialize("Node_test", sys.argv[:1]) log = app.GetLog() # Start process manager processManager = ProcessManager() # Find venue server exe bin = AGTkConfig.instance().GetBinDir() venueserverexe = os.path.join(bin, 'VenueServer.py') # Start the venue server exe = sys.executable opts = [ venueserverexe, '-p', str(venueserverport), ] processManager.StartProcess(exe, opts) # Create proxy to the venue server venueServer = VenueServerIW('https://localhost:%d/VenueServer' % (venueserverport, )) # Wait for server to become reachable print "Wait for venue server..." up = 0 while not up: try: up = venueServer.IsValid() print "up = ", up continue except: print "waiting for venue server..." pass time.sleep(1) venueUrl = venueServer.GetDefaultVenue() venue = VenueIW(venueUrl)
def test_100_Setup(self): global venueServer, processManager, venue, venueUrl # initialize toolkit and environment app = Toolkit.Service().instance() app.Initialize("Node_test", sys.argv[:1]) log = app.GetLog() # Start process manager processManager = ProcessManager() # Find venue server exe bin = AGTkConfig.instance().GetBinDir() venueserverexe = os.path.join(bin,'VenueServer.py') # Start the venue server exe = sys.executable opts = [ venueserverexe, '-p', str(venueserverport), ] processManager.StartProcess(exe,opts) # Create proxy to the venue server venueServer = VenueServerIW('https://localhost:%d/VenueServer' % (venueserverport,)) # Wait for server to become reachable print "Wait for venue server..." up = 0 while not up: try: up = venueServer.IsValid() print "up = ", up continue except: print "waiting for venue server..." pass time.sleep(1) venueUrl = venueServer.GetDefaultVenue() venue = VenueIW(venueUrl)
def Run(self): self.running = 1 avahiDiscoverExe = os.path.join(AGTkConfig.instance().GetBinDir(), 'ag-avahi-discover3.py') self.subproc = subprocess.Popen( [avahiDiscoverExe, self.serviceType], bufsize=1, stdout=subprocess.PIPE, close_fds=True) # Loop while self.subproc.poll() == None and self.IsRunning(): line = self.subproc.stdout.readline().strip() if not line: break if line[0] == '+': txtparts = line.split('=') if txtparts and len(txtparts) > 1: self.__NewService(txtparts[0][1:], txtparts[1]) elif line[0] == '-': self.__RemoveService(line[1:])
def testGetBinDir(self): binDir = AGTkConfig.instance().GetBinDir() assert binDir != "" and binDir is not None, 'invalid bin dir'
def testGetServicesDir(self): servicesDir = AGTkConfig.instance().GetServicesDir() assert servicesDir != "" and servicesDir is not None, 'invalid services dir' assert os.path.isdir(servicesDir)
def testGetNodeServicesDir(self): nsDir = AGTkConfig.instance().GetNodeServicesDir() assert nsDir != "" and nsDir is not None, 'invalid node services dir' assert os.path.isdir(nsDir)
def InitAppAndProcessArgs(app): doc = """ By default this program registers/installs a shared application or node service with the users environment. Using the -u argument applications can be unregistered/uninstalled. To unregister node services, use the '--unregister-service' argument. """ tkConf = AGTkConfig.instance() app.AddCmdLineOption( Option("-u", "--unregister", action="store_true", dest="unregister", default=0, help="Unregister the application, instead of registering it. \ Specify application with '-n'")) app.AddCmdLineOption( Option("--unregister-service", action="store_true", dest="unregisterservice", default=0, help="Unregister the service, instead of registering it. \ Specify service with '-n'. (Requires administrative access)")) app.AddCmdLineOption( Option("--unregister-plugin", action="store_true", dest="unregisterplugin", default=0, help="Unregister the plugin, instead of registering it. \ Specify plugin with '-n'.")) app.AddCmdLineOption( Option( "-n", "--name", dest="appname", help="specify a name other than the default on from the .app file." )) app.AddCmdLineOption( Option("-v", "--verbose", action="store_true", dest="verbose", default=0, help="Be verbose during app processing.")) app.AddCmdLineOption( Option("-f", "--file", dest="appfile", help="The name of a .app file to install.")) # Remove conflicting options and readd without the shorter option. app.parser.remove_option("-d") # remove debug option app.parser.remove_option("-l") # remove logfile option # Unnecessary options app.parser.remove_option("--cert") app.parser.remove_option("--key") app.parser.remove_option("--cadir") app.parser.remove_option("--secure") # Readd debug option without the shorter -d. app.parser.add_option("--debug", action="store_true", dest="debug", default=0, help="Set the debug level of this program.") # Readd logfile option without the shorter -l. app.parser.add_option("--logfile", dest="logfilename", metavar="LOGFILE", default=None, help="Specify a log file to output logging to.") app.AddCmdLineOption( Option("-d", "--dir", dest="appdir", help="The name of a directory containing a .app file.")) app.AddCmdLineOption( Option("-z", "--zip", dest="appzip", help="The name of a .zip file containing a .app or .svc file.\ (Requires administrative access to install services)" )) app.AddCmdLineOption( Option("-p", "--package", dest="apppkg", help="The name of an agpkg file containing a .app or .svc \ file. (Requires administrative access to install services)" )) app.AddCmdLineOption( Option("-l", "--list-apps", action="store_true", dest="listapps", help="List installed shared apps.")) app.AddCmdLineOption( Option("--list-services", action="store_true", dest="listservices", help="List installed node services.")) app.AddCmdLineOption( Option("--list-plugins", action="store_true", dest="listplugins", help="List installed plugins.")) app.AddCmdLineOption( Option("-s", "--system", action="store_true", dest="sys_install", default=0, help="Install the package for all users. \ (This requires administrative access)")) app.AddCmdLineOption( Option("--post-install", action="store_true", dest="post_install", default=0, help="Do a post-installation run, which will install \ all apps distributed with the toolkit in the system \ if possible. (This requires administrative access)")) app.AddCmdLineOption( Option("--wait-for-input", action="store_true", dest="wait_for_input", default=0, help="After completing wait for the user to confirm by\ pressing a key.")) app.AddCmdLineOption( Option( "--gui", action="store_true", dest="useGui", help="Show if the installation was successful with a GUI dialog.")) args = app.Initialize("agpm") if True == app.GetOption("useGui"): global gUseGui gUseGui = True # Validate arguments if not ( # these args imply an action app.options.appzip or app.options.apppkg or app.options.appfile or app.options.appdir # these are explicit actions or app.options.post_install or app.options.listservices or app.options.listapps or app.options.listplugins or app.options.unregister or app.options.unregisterservice or app.options.unregisterplugin): app.parser.print_help() ShowResult("Error: no action specified") sys.exit(1) if app.options.sys_install or app.options.post_install: appdb = AppDb(path=tkConf.GetConfigDir()) plugindb = PluginDb(path=tkConf.GetConfigDir()) appdest = tkConf.GetSharedAppDir() plugindest = tkConf.GetPluginDir() else: appdb = AppDb() plugindb = PluginDb() appdest = UserConfig.instance().GetSharedAppDir() plugindest = UserConfig.instance().GetPluginDir() return app.options, appdb, plugindb, appdest, plugindest
def testGetSharedAppDir(self): appDir = AGTkConfig.instance().GetSharedAppDir() assert appDir != "" and appDir is not None, 'invalid app dir' assert os.path.isdir(appDir)
def testGetInstallDir(self): instDir = AGTkConfig.instance().GetInstallDir() assert instDir != "" and instDir is not None, 'invalid install dir' assert os.path.isdir(instDir)
def testGetBaseDir(self): baseDir = AGTkConfig.instance().GetBaseDir() assert baseDir == self.sysdir , 'incorrect install dir' assert os.path.isdir(baseDir)
def Initialize(self, name=None, args=None): """ This method sets up everything for reasonable execution. At the first sign of any problems it raises exceptions and exits. """ self.name = name # 1. Process Command Line Arguments argvResult = self.ProcessArgs(args=args) # 2. Load the Toolkit wide configuration. try: self.agtkConfig = AGTkConfig.instance(0) except Exception: self.log.exception("Toolkit Initialization failed.") sys.exit(-1) # 3. Load the user configuration, creating one if necessary. try: self.userConfig = UserConfig.instance(initIfNeeded=1) except Exception: self.log.exception("User Initialization failed.") sys.exit(-1) # Load client preferences self.preferences = Preferences() self.ProcessArgsThatUsePreferences() # 4. Redirect logging to files in the user's directory, # purging memory to file fh = Log.defLogHandler if self.options.logfilename is not None: if not self.options.logfilename.endswith(".log"): self.name = self.options.logfilename + ".log" else: self.name = self.options.logfilename elif self.name is not None: if not self.name.endswith(".log"): self.name = self.name + ".log" self.log.info("Logfile Name: %s", self.name) if self.name: if not self.name.startswith(os.sep) \ and not self.name.startswith("."): filename = os.path.join(self.userConfig.GetLogDir(), self.name) else: filename = self.name fh = Log.RotatingFileHandler(filename,"a", self.options.logfilesize, self.options.numlogfiles) fh.setFormatter(Log.GetFormatter()) self.fhLoggerLevels = Log.HandleLoggers(fh, Log.GetDefaultLoggers()) self.fhLoggerLevels.SetLevel(Log.DEBUG) self.fhLoggerLevels.SetLevel(Log.CRITICAL, Log.RTPSensor) self.loggerLevels = self.fhLoggerLevels # Send the log in memory to stream (debug) or file handler. if self.options.debug or int(self.preferences.GetPreference(Preferences.LOG_TO_CMD)): Log.mlh.setTarget(Log.defStreamHandler) else: Log.mlh.setTarget(fh) Log.mlh.close() Log.RemoveLoggerLevels(Log.memLevels,Log.GetLoggers()) self.__SetLogPreference() self.CheckDependencies() # Check if machine clock is synchronized. # - Disabled for 3.0: clock-sync is important when using proxy certs, which we're not #self.__CheckForInvalidClock() self.__context = None return argvResult
def InitAppAndProcessArgs(app): doc = """ By default this program registers/installs a shared application or node service with the users environment. Using the -u argument applications can be unregistered/uninstalled. To unregister node services, use the '--unregister-service' argument. """ tkConf = AGTkConfig.instance() app.AddCmdLineOption(Option("-u", "--unregister", action="store_true", dest="unregister", default=0, help="Unregister the application, instead of registering it. \ Specify application with '-n'")) app.AddCmdLineOption(Option("--unregister-service", action="store_true", dest="unregisterservice", default=0, help="Unregister the service, instead of registering it. \ Specify service with '-n'. (Requires administrative access)")) app.AddCmdLineOption(Option("--unregister-plugin", action="store_true", dest="unregisterplugin", default=0, help="Unregister the plugin, instead of registering it. \ Specify plugin with '-n'.")) app.AddCmdLineOption(Option("-n", "--name", dest="appname", help="specify a name other than the default on from the .app file.")) app.AddCmdLineOption(Option("-v", "--verbose", action="store_true", dest="verbose", default=0, help="Be verbose during app processing.")) app.AddCmdLineOption(Option("-f", "--file", dest="appfile", help="The name of a .app file to install.")) # Remove conflicting options and readd without the shorter option. app.parser.remove_option("-d") # remove debug option app.parser.remove_option("-l") # remove logfile option # Unnecessary options app.parser.remove_option("--cert") app.parser.remove_option("--key") app.parser.remove_option("--cadir") app.parser.remove_option("--secure") # Readd debug option without the shorter -d. app.parser.add_option("--debug", action="store_true", dest="debug", default=0, help="Set the debug level of this program.") # Readd logfile option without the shorter -l. app.parser.add_option("--logfile", dest="logfilename", metavar="LOGFILE", default=None, help="Specify a log file to output logging to.") app.AddCmdLineOption(Option("-d", "--dir", dest="appdir", help="The name of a directory containing a .app file.")) app.AddCmdLineOption(Option("-z", "--zip", dest="appzip", help="The name of a .zip file containing a .app or .svc file.\ (Requires administrative access to install services)")) app.AddCmdLineOption(Option("-p", "--package", dest="apppkg", help="The name of an agpkg file containing a .app or .svc \ file. (Requires administrative access to install services)")) app.AddCmdLineOption(Option("-l", "--list-apps", action="store_true", dest="listapps", help="List installed shared apps.")) app.AddCmdLineOption(Option("--list-services", action="store_true", dest="listservices", help="List installed node services.")) app.AddCmdLineOption(Option("--list-plugins", action="store_true", dest="listplugins", help="List installed plugins.")) app.AddCmdLineOption(Option("-s", "--system", action="store_true", dest="sys_install", default=0, help="Install the package for all users. \ (This requires administrative access)")) app.AddCmdLineOption(Option("--post-install", action="store_true", dest="post_install", default=0, help="Do a post-installation run, which will install \ all apps distributed with the toolkit in the system \ if possible. (This requires administrative access)")) app.AddCmdLineOption(Option("--wait-for-input", action="store_true", dest="wait_for_input", default=0, help="After completing wait for the user to confirm by\ pressing a key.")) app.AddCmdLineOption(Option("--gui", action="store_true", dest="useGui", help="Show if the installation was successful with a GUI dialog.")) args = app.Initialize("agpm") if True == app.GetOption("useGui"): global gUseGui gUseGui = True # Validate arguments if not ( # these args imply an action app.options.appzip or app.options.apppkg or app.options.appfile or app.options.appdir # these are explicit actions or app.options.post_install or app.options.listservices or app.options.listapps or app.options.listplugins or app.options.unregister or app.options.unregisterservice or app.options.unregisterplugin ): app.parser.print_help() ShowResult("Error: no action specified") sys.exit(1) if app.options.sys_install or app.options.post_install: appdb = AppDb(path=tkConf.GetConfigDir()) plugindb = PluginDb(path=tkConf.GetConfigDir()) appdest = tkConf.GetSharedAppDir() plugindest = tkConf.GetPluginDir() else: appdb = AppDb() plugindb = PluginDb() appdest = UserConfig.instance().GetSharedAppDir() plugindest = UserConfig.instance().GetPluginDir() return app.options, appdb, plugindb, appdest, plugindest
def main(): import signal bridgeServer = None defaultListenPort = 20000 defaultUMTPPort = 50000 executable = None if IsWindows() : executable = "umtp.exe" elif IsLinux(): executable = "umtp" os.chmod(executable, 0755) # make umtp_linux file executable elif IsOSX(): executable = "umtp" os.chmod(executable, 0755) # make umtp_linux file executable defaultexec = os.path.join(AGTkConfig.instance().GetBinDir(), executable) print 'defaultexec = ', defaultexec defaultRegistryUrlList=['http://www.accessgrid.org/registry/peers.txt'] # maxConnections? , maxBridges?, recycleTimeout? parser = OptionParser() parser.add_option("-p", "--listenPort", dest="listenPort", default=defaultListenPort, help="Port to listen on.", type="int") parser.add_option("-u", "--registryUrl", action="append", dest="registryUrlList", default=defaultRegistryUrlList, help="Url to the registry. UMTP Server will register with it.") parser.add_option("-r", "--port", dest="port", default=defaultUMTPPort, help="Minimum and maximum port, space-separated.", type="int") parser.add_option("-x", "--exec", dest="umtpexec", default=defaultexec, help="Location of UMTP executable.") parser.add_option("-n", "--name", dest="name", default=None, help="Name.") parser.add_option("-l", "--location", dest="location", default=None, help="Location.") (options, ret_args) = parser.parse_args(args=sys.argv) # Init toolkit with standard environment. app = Toolkit.Service.instance() try: app.Initialize("UMTPBridge", args=ret_args) except: print "Failed to initialize toolkit, exiting." sys.exit(-1) global log log = app.GetLog() if options.name == None: print 'Error: No name specified' parser.print_help() sys.exit(-1) if options.location == None: print 'Error: No location specified' parser.print_help() sys.exit(-1) if options.registryUrlList == None: print 'Error: No registry url specified' parser.print_help() sys.exit(-1) # Signal handler to catch signals and shutdown def SignalHandler(signum, frame): " SignalHandler catches signals and shuts down the UMTP Server " print "Shutting down..." umtpServer.Shutdown() print "SignalHandler exiting." # Register a signal handler so we can shut down cleanly signal.signal(signal.SIGINT, SignalHandler) if sys.platform != 'win32': signal.signal(signal.SIGHUP, SignalHandler) umtpServer = UMTPServer(name=options.name, location=options.location, listenPort=options.listenPort, umtpexec=options.umtpexec, dataPort=options.port, registryUrlList=options.registryUrlList) umtpServer.Run()
def testAGTkConfigDir(self): #print "BASEDIR:", AGTkConfig.instance().installBase, self.userdir, self.sysdir configDir = AGTkConfig.instance().GetConfigDir() assert configDir != "" and configDir is not None, 'empty config dir' expectedDir = os.path.join(self.sysdir, "Config") assert configDir == expectedDir, 'AGTkConfig config dir %s != AGTkConfig...GetConfigDir() %s' % (configDir, expectedDir)
def testVersion(self): version = AGTkConfig.instance().GetVersion()
def testGetConfigDir(self): configDir = AGTkConfig.instance().GetConfigDir() assert configDir != "" and configDir is not None, 'invalid user config dir' expectedDir = os.path.join(self.sysdir, "Config") assert configDir == expectedDir, 'AGTkConfig config dir %s != AGTkConfig...GetConfigDir() %s' % (configDir, expectedDir) assert os.path.isdir(configDir)
# cp packaging/config/defaultWindows AGTkConfig.instance().GetConfigDir() # cp packaging/config/defaultLinux AGTkConfig.instance().GetConfigDir() # cp packaging/config/CACertificates AGTkConfig.instance().GetConfigDir()/CACertificates # print "" # Set AGTK_LOCATION so we can use the toolkit's initialization functions. os.environ["AGTK_LOCATION"] = ABS_AG_BASE_DIR # Add to PYTHONPATH sys.path.insert(0, os.path.abspath(options.agsrcdir)) # New config using AGTkConfig from AccessGrid.Platform.Config import AGTkConfig # Create directory structure agtkConfig = AGTkConfig.instance(initIfNeeded=1) # Make shared app packages # # python2 makeAppPackages.py inputdir sharedappconfigdir cmd = "%s %s %s %s" % (sys.executable, os.path.join( options.agsrcdir, "packaging", "makeAppPackages.py" ), os.path.join(ABS_AG_BASE_DIR,'sharedapps'), AGTkConfig.instance().GetSharedAppDir()) if options.verbose: print " ",cmd os.system(cmd) # Make service packages # python packaging/makeServicePackages.py /path/to/AccessGrid /path/to/source (ag-media should be found under here)
def ImportCACertificates(self): sysConfDir = AGTkConfig.instance().GetConfigDir() caDir = os.path.join(sysConfDir,'CAcertificates') log.debug("Initializing from %s", caDir) # # Now handle the CA certs. # if caDir is not None: try: files = os.listdir(caDir) except: from AccessGrid import Toolkit certMgrUI = Toolkit.GetDefaultApplication().GetCertificateManagerUI() certMgrUI.ReportError("Error reading CA certificate directory\n" + caDir + "\n" + "You will have to import trusted CA certificates later.") files = [] # # Extract the files from the caDir that match OpenSSL's # 8-character dot index format. # regexp = re.compile(r"^[\da-fA-F]{8}\.\d$") possibleCertFiles = filter(lambda f, r = regexp: r.search(f), files) for f in possibleCertFiles: path = os.path.join(caDir, f); log.info("%s might be a cert" % (path)) # Check for existence of signing policy certbasename = f.split('.')[0] signingPolicyFile = '%s.signing_policy' % (certbasename,) signingPath = os.path.join(caDir,signingPolicyFile) if not os.path.isfile(signingPath): log.info("Not importing CA cert %s; couldn't find signing policy file %s", f,signingPath) continue try: # Import the certificate desc = self.ImportCACertificatePEM(self.certRepo, path) except: log.exception('import of ca cert failed') try: # # Copy the signing policy file # shutil.copyfile(signingPath, desc.GetFilePath("signing_policy")) log.info("Imported cert as %s.0", desc.GetSubject().get_hash()) except: # print "Failure to import ", path log.exception("failure importing %s", path)
def main(): """ This is the main, this function processes command line arguments, then digs the files out of the directory, or archive and installs them. It registers the application with the users AG environment. """ workingDir = os.getcwd() commands = dict() files = list() cleanup = 0 tkConf = AGTkConfig.instance() # We're going to assume there's a .app file in the current directory, # but only after we check for a command line argument that specifies one. # We also have the ability to pass in a zip file that contains a .app # file and the other parts of the shared application. app = Toolkit.CmdlineApplication.instance() options, appdb, plugindb, appdest, plugindest = InitAppAndProcessArgs(app) # # Handle list-only options # if options.listapps: apps = appdb.ListApplications() import pprint pprint.pprint(apps) sys.exit(0) if options.listservices: files = os.listdir(tkConf.GetNodeServicesDir()) for f in files: print f sys.exit(0) if options.listplugins: plugins = plugindb.ListPlugins() import pprint pprint.pprint(plugins) sys.exit(0) # # Handle command-line errors # if options.appfile and not os.path.exists(options.appfile): ShowResult("Error: app file does not exist: %s" % options.appfile ) sys.exit(1) if options.appdir and not os.path.exists(options.appdir): ShowResult("Error: dir does not exist: %s" % options.appdir ) sys.exit(1) if options.apppkg and not os.path.exists(options.apppkg): ShowResult("Error: package file does not exist: %s" % options.apppkg ) sys.exit(1) if options.appzip and not os.path.exists(options.appzip): ShowResult("Error: zip file does not exist: %s" % options.appzip) sys.exit(1) # # Determine whether it's a service or app package # isServicePackage = 0 isPluginPackage = 0 if options.appzip or options.apppkg: try: filename=options.appzip or options.apppkg zipArchive = zipfile.ZipFile(filename) for filename in zipArchive.namelist(): if filename.endswith('.svc'): isServicePackage = 1 break elif filename.endswith('.plugin'): isPluginPackage = 1 break except zipfile.BadZipfile,e: log.exception("Error in zipfile %s", filename) ShowResult( "Error in zipfile %s: %s" % (filename,e.args[0])) sys.exit(1)
def main(): """ This is the main, this function processes command line arguments, then digs the files out of the directory, or archive and installs them. It registers the application with the users AG environment. """ workingDir = os.getcwd() commands = dict() files = list() cleanup = 0 tkConf = AGTkConfig.instance() # We're going to assume there's a .app file in the current directory, # but only after we check for a command line argument that specifies one. # We also have the ability to pass in a zip file that contains a .app # file and the other parts of the shared application. app = Toolkit.CmdlineApplication.instance() options, appdb, plugindb, appdest, plugindest = InitAppAndProcessArgs(app) # # Handle list-only options # if options.listapps: apps = appdb.ListApplications() import pprint pprint.pprint(apps) sys.exit(0) if options.listservices: files = os.listdir(tkConf.GetNodeServicesDir()) for f in files: print f sys.exit(0) if options.listplugins: plugins = plugindb.ListPlugins() import pprint pprint.pprint(plugins) sys.exit(0) # # Handle command-line errors # if options.appfile and not os.path.exists(options.appfile): ShowResult("Error: app file does not exist: %s" % options.appfile) sys.exit(1) if options.appdir and not os.path.exists(options.appdir): ShowResult("Error: dir does not exist: %s" % options.appdir) sys.exit(1) if options.apppkg and not os.path.exists(options.apppkg): ShowResult("Error: package file does not exist: %s" % options.apppkg) sys.exit(1) if options.appzip and not os.path.exists(options.appzip): ShowResult("Error: zip file does not exist: %s" % options.appzip) sys.exit(1) # # Determine whether it's a service or app package # isServicePackage = 0 isPluginPackage = 0 if options.appzip or options.apppkg: try: filename = options.appzip or options.apppkg zipArchive = zipfile.ZipFile(filename) for filename in zipArchive.namelist(): if filename.endswith('.svc'): isServicePackage = 1 break elif filename.endswith('.plugin'): isPluginPackage = 1 break except zipfile.BadZipfile, e: log.exception("Error in zipfile %s", filename) ShowResult("Error in zipfile %s: %s" % (filename, e.args[0])) sys.exit(1)
def Initialize(self, name=None, args=None): """ This method sets up everything for reasonable execution. At the first sign of any problems it raises exceptions and exits. """ self.name = name # 1. Process Command Line Arguments argvResult = self.ProcessArgs(args=args) # 2. Load the Toolkit wide configuration. try: self.agtkConfig = AGTkConfig.instance(0) except Exception: self.log.exception("Toolkit Initialization failed.") sys.exit(-1) # 3. Load the user configuration, creating one if necessary. try: self.userConfig = UserConfig.instance(initIfNeeded=1) except Exception: self.log.exception("User Initialization failed.") sys.exit(-1) # Load client preferences self.preferences = Preferences() self.ProcessArgsThatUsePreferences() # 4. Redirect logging to files in the user's directory, # purging memory to file fh = Log.defLogHandler if self.options.logfilename is not None: if not self.options.logfilename.endswith(".log"): self.name = self.options.logfilename + ".log" else: self.name = self.options.logfilename elif self.name is not None: if not self.name.endswith(".log"): self.name = self.name + ".log" self.log.info("Logfile Name: %s", self.name) if self.name: if not self.name.startswith(os.sep) \ and not self.name.startswith("."): filename = os.path.join(self.userConfig.GetLogDir(), self.name) else: filename = self.name fh = Log.RotatingFileHandler(filename, "a", self.options.logfilesize, self.options.numlogfiles) fh.setFormatter(Log.GetFormatter()) self.fhLoggerLevels = Log.HandleLoggers(fh, Log.GetDefaultLoggers()) self.fhLoggerLevels.SetLevel(Log.DEBUG) self.fhLoggerLevels.SetLevel(Log.CRITICAL, Log.RTPSensor) self.loggerLevels = self.fhLoggerLevels # Send the log in memory to stream (debug) or file handler. if self.options.debug or int( self.preferences.GetPreference(Preferences.LOG_TO_CMD)): Log.mlh.setTarget(Log.defStreamHandler) else: Log.mlh.setTarget(fh) Log.mlh.close() Log.RemoveLoggerLevels(Log.memLevels, Log.GetLoggers()) self.__SetLogPreference() self.CheckDependencies() # Check if machine clock is synchronized. # - Disabled for 3.0: clock-sync is important when using proxy certs, which we're not #self.__CheckForInvalidClock() self.__context = None return argvResult
print "Cannot find AG source dir.", file_to_find, " not found." sys.exit() # Get absolute paths for when we need to pass them to python.exe later. ABS_AG_BASE_DIR = os.path.abspath(options.agsrcdir) ABS_SRC_DIR = os.path.abspath(options.srcdir) # Set AGTK_LOCATION so we can use the toolkit's initialization functions. os.environ["AGTK_LOCATION"] = ABS_AG_BASE_DIR # Add to PYTHONPATH sys.path.insert(0, os.path.abspath(options.agsrcdir)) # New config using AGTkConfig from AccessGrid.Platform.Config import AGTkConfig # Create directory structure agtkConfig = AGTkConfig.instance(initIfNeeded=1) agtk_location = os.path.join(os.path.abspath(options.agsrcdir)) python_path = os.path.abspath(options.agsrcdir) #-------------------------------------------------------------------------------- # Make shared app packages #-------------------------------------------------------------------------------- print "Building shared application packages" # python2 makeAppPackages.py inputdir sharedappconfigdir cmd = "%s %s %s %s" % (sys.executable, os.path.join( options.agsrcdir, "packaging", "makeAppPackages.py" ), os.path.join(ABS_AG_BASE_DIR,'sharedapps'), AGTkConfig.instance().GetSharedAppDir()) if options.verbose:
def testGetBaseDir(self): baseDir = AGTkConfig.instance().GetBaseDir() assert baseDir == self.sysdir, 'incorrect install dir' assert os.path.isdir(baseDir)