#! /usr/bin/python __author__="bjschuma" __date__ ="$Mar 13, 2010 4:19:39 PM$" import variables import event global vars global events vars = variables.Vars() events = event.Event() from ct import path from ct import opts path.mkdir(vars.OCARINA) opts.parse() # Set verbose value if opts.has("v") == True: vars.VERBOSE += opts.opts["v"] if opts.has("verbose") == True: vars.VERBOSE += opts.opts["verbose"] import gstreamer def postConfig(): from ct import tcp global vars lock = vars.LOCKFILE from ct.opts import args # Load a song if we were passed one on load space = ' ' song = space.join(args) # Check if another instance already has the lock if path.exists(lock) == True: # Print a warning message, and tell where the lock file is so the user # can remove it if this message is in error print "Warning: an instance of Ocarina may already be running!" print "If this is not the case, remove the lock file located at:" print lock # Find the port of the other application fin = open(lock) port = int(fin.read()) fin.close() try: # Try to send the song to the other application tcp.send(port,song) return -1 except: print "Warning: I could not connect to port",port print "We will continue as if this is the only Ocarina" # Become a tcp server port = tcp.server() # Write the port to a file out = open(lock,'w') out.write( str(port)+"\n" ) out.close() # Load a song if we were passed one on startup if path.exists(song) == True: from ct import call call.load(song) return 0 '''Attempt to read in a configuration file''' def config(): global vars from ct.call import pyfile config = "config.py" pyfile(path.join(vars.OCARINA,config)) pyfile(config) if postConfig() != 0: import sys sys.exit()