def create_ec2_connection(hostname=None, path=None, port=None): if hostname == None: # We're using EC2. # Check for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, # and use EC2Connection. boto will fill in all the values if not (environ.has_key("AWS_ACCESS_KEY_ID") and environ.has_key("AWS_SECRET_ACCESS_KEY")): return None else: return EC2Connection() else: # We're using an EC2-ish cloud. # Check for EC2_ACCESS_KEY and EC2_SECRET_KEY (these are used by Eucalyptus; # we will probably have to tweak this further to support other systems) if not (environ.has_key("EC2_ACCESS_KEY") and environ.has_key("EC2_SECRET_KEY")): return None else: print "Setting region" region = RegionInfo(name="eucalyptus", endpoint=hostname) return connect_ec2( aws_access_key_id=environ["EC2_ACCESS_KEY"], aws_secret_access_key=environ["EC2_SECRET_KEY"], is_secure=False, region=region, port=port, path=path, )
def get_plugin_dirs(): PLUGINS = [] PLUGINS_DIRS = [] PLUGINS_DIRS += [os.path.join(d, "gwibber", "plugins") for d in DATA_BASE_DIRS] if exists(os.path.join("gwibber", "microblog", "plugins")): PLUGINS_DIRS.insert(0, os.path.realpath(os.path.join("gwibber", "microblog", "plugins"))) if exists(os.path.join("gwibber", "plugins")): PLUGINS_DIRS.insert(0, os.path.realpath(os.path.join("gwibber", "plugins"))) if environ.has_key("GWIBBER_PLUGIN_DIR"): GWIBBER_PLUGIN_DIR = environ["GWIBBER_PLUGIN_DIR"] if exists(os.path.realpath(GWIBBER_PLUGIN_DIR)): PLUGINS_DIRS.insert(0, os.path.realpath(GWIBBER_PLUGIN_DIR)) PLUGINS_DIRS.reverse() if environ.has_key("GWIBBER_PLUGIN_TEST_DIR"): PLUGINS_DIRS = [] PLUGINS_DIRS.insert (0, os.path.realpath(environ["GWIBBER_PLUGIN_TEST_DIR"])) for p in PLUGINS_DIRS: if exists(p): sys.path.insert(0, p) for d in os.listdir(p): if os.path.isdir(os.path.join(p, d)): if d not in PLUGINS: PLUGINS.append(d) return [PLUGINS,PLUGINS_DIRS]
def end(summary,perfdata,longserviceoutput,nagios_state): global show_longserviceoutput global show_perfdata global nagios_server global do_phone_home global nagios_port global nagios_myhostname global hostname global mode global escape_newlines global check_system message = "%s - %s" % ( state[nagios_state], summary) if show_perfdata: message = "%s | %s" % ( message, perfdata) if show_longserviceoutput: message = "%s\n%s" % ( message, longserviceoutput.strip()) if escape_newlines == True: lines = message.split('\n') message = '\\n'.join(lines) debug( "do_phone_home = %s" %(do_phone_home) ) if do_phone_home == True: try: if nagios_myhostname is None: if environ.has_key( 'HOSTNAME' ): nagios_myhostname = environ['HOSTNAME'] elif environ.has_key( 'COMPUTERNAME' ): nagios_myhostname = environ['COMPUTERNAME'] else: nagios_myhostname = hostname phone_home(nagios_server,nagios_port, status=nagios_state, message=message, hostname=nagios_myhostname, servicename=mode,system=check_system) except: raise print message exit(nagios_state)
def run(): profilelevel = None if environ.has_key('PROFILELEVEL'): profilelevel = int(environ['PROFILELEVEL']) if profilelevel is None: TestProgramPyMVPA() else: profilelines = environ.has_key('PROFILELINES') import hotshot, hotshot.stats pname = "%s.prof" % sys.argv[0] prof = hotshot.Profile(pname, lineevents=profilelines) try: # actually return values are never setup # since unittest.main sys.exit's benchtime, stones = prof.runcall( unittest.main ) except SystemExit: pass print "Saving profile data into %s" % pname prof.close() if profilelevel > 0: # we wanted to see the summary right here # instead of just storing it into a file print "Loading profile data from %s" % pname stats = hotshot.stats.load(pname) stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(profilelevel)
def testStdoutSetting(self): """EnvVariable Central value is correct when ACS_LOG_CENTRAL environment variable is set""" self.assertEquals(False, environ.has_key('ACS_LOG_STDOUT')) self.assertEquals(True, environ.has_key('ACS_LOG_CENTRAL')) self.assertEquals('2', environ['ACS_LOG_CENTRAL']) self.assertEquals(2, Log.ACS_LOG_CENTRAL) self.assertEquals(3, Log.ACS_LOG_STDOUT)
def get_username(): """ Returns the username of the current user. """ if (environ.has_key("USER")): return environ["USER"] elif (environ.has_key("USERNAME")): return environ["USERNAME"] else: return "Unknown"
def _getRootEnvSys(self,version,usepython=False): """Returns an environment suitable for running Root and sometimes Python.""" from os.path import join from os import environ from Ganga.Lib.Root.shared import setEnvironment,findPythonVersion rootsys = getrootsys(version) rootenv = {} #propagate from localhost if environ.has_key('PATH'): setEnvironment('PATH',environ['PATH'],update=True,environment=rootenv) if environ.has_key('LD_LIBRARY_PATH'): setEnvironment('LD_LIBRARY_PATH',environ['LD_LIBRARY_PATH'],update=True,environment=rootenv) setEnvironment('LD_LIBRARY_PATH',join(rootsys,'lib'),update=True,environment=rootenv) setEnvironment('PATH',join(rootsys,'bin'),update=True,environment=rootenv) setEnvironment('ROOTSYS',rootsys,update=False,environment=rootenv) logger.debug('Have set Root variables. rootenv is now %s', str(rootenv)) if usepython: # first get from config python_version = '' try: python_version = getConfig('ROOT')['pythonversion'] except ConfigError, e: logger.debug('There was a problem trying to get [ROOT]pythonversion: %s.', e) #now try grepping files if not python_version: python_version = findPythonVersion(rootsys) if (python_version is None): logger.warn('Unable to find the Python version needed for Root version %s. See the [ROOT] section of your .gangarc file.', version) else: logger.debug('Python version found was %s', python_version) python_home = getpythonhome(pythonversion=python_version) logger.debug('PYTHONHOME is being set to %s',python_home) python_bin = join(python_home,'bin') setEnvironment('PATH',python_bin,update=True,environment=rootenv) setEnvironment('PYTHONPATH',join(rootsys,'lib'),update=True,environment=rootenv) logger.debug('Added PYTHONPATH. rootenv is now %s', str(rootenv)) if join(python_bin,'python') != sys.executable: #only try to do all this if the python currently running isn't going to be used logger.debug('Using a different Python - %s.', python_home) python_lib = join(python_home,'lib') import os.path if not os.path.exists(python_bin) or not os.path.exists(python_lib): logger.error('The PYTHONHOME specified does not have the expected structure. See the [ROOT] section of your .gangarc file.') setEnvironment('LD_LIBRARY_PATH',python_lib,update=True,environment=rootenv) setEnvironment('PYTHONHOME',python_home,update=False,environment=rootenv) setEnvironment('PYTHONPATH',python_lib,update=True,environment=rootenv)
def main(): # initialize variables from environment modulePath = Env.get('PythonSleighModulePath', '') logDir = Env.get('PythonSleighLogDir') if not logDir or not os.path.isdir(logDir): logDir = _TMPDIR outfile = Env.get('PythonSleighWorkerOut') if outfile: outfile = os.path.join(logDir, os.path.split(outfile)[1]) else: outfile = _NULFILE Env['PythonSleighLogFile'] = outfile verbose = Env.has_key('PythonSleighWorkerOut') and 1 or 0 nwsName = Env['PythonSleighNwsName'] nwsHost = Env.get('PythonSleighNwsHost', 'localhost') nwsPort = int(Env.get('PythonSleighNwsPort', '8765')) if Env.has_key('PythonSleighName'): name = Env['PythonSleighName'] if Env.has_key('PythonSleighID'): name = '%s@%s' % (name, Env['PythonSleighID']) logger.setName(name) logger.logDebug(nwsName, nwsHost, nwsPort) nws = NetWorkSpace(nwsName, nwsHost, nwsPort, useUse=True, create=False) newProtocol = nws.findTry('version') is not None if newProtocol: worker_id = nws.fetch('worker_ids') Env['PythonSleighRank'] = worker_id # create the script file for the worker to execute script = '''\ import sys, os try: os.setpgid(0, 0) except: pass try: sys.stdout = sys.stderr = open(%s, 'w', 0) except: pass sys.path[1:1] = %s.split(os.pathsep) from nws.sleigh import cmdLaunch print "entering worker loop" cmdLaunch(%d) ''' % (repr(outfile), repr(modulePath), verbose) fd, tmpname = tempfile.mkstemp(suffix='.py', prefix='__nws', text=True) tmpfile = os.fdopen(fd, 'w') tmpfile.write(script) tmpfile.close() logger.logDebug("executing Python worker") argv = [sys.executable, tmpname] out = open(outfile, 'w') try: p = subprocess.Popen(argv, stdin=open(tmpname), stdout=out, stderr=subprocess.STDOUT) except OSError, e: logger.logError("error executing command:", argv) raise e
def main(): try: global keep_running, password, port, libraryFileLocation keep_running = True nextIsPass = False nextIsPort = False if environ.has_key('TC_PORT'): port = int(environ['TC_PORT']) del environ['TC_PORT'] if environ.has_key('TC_PASSWORD'): password = environ['TC_PASSWORD'][:] del environ['TC_PASSWORD'] for arg in sys.argv: if arg == "--password": nextIsPass = True elif arg == "--port": nextIsPort = True elif nextIsPass: password = arg nextIsPass = False elif nextIsPort: port = int(arg) nextIsPort = False server = HTTPServer(('', port), TCHandler) print 'started httpserver...' bonjourService = pybonjour.DNSServiceRegister( name = socket.gethostname().replace('.local', ''), regtype = '_tunage._tcp', port = port) loadLibraryFile(libraryFileLocation) while keep_running: server.handle_request() print 'termination command received, shutting down server' server.socket.close() bonjourService.close() return except KeyboardInterrupt, SystemExit: print 'termination command received, shutting down server' server.socket.close() bonjourService.close() return
def find_executable(executable_name): """Helper function to find executables""" from os import path, name, environ, pathsep from sys import argv executable_name = path.basename(executable_name) logger.debug("Looking for executable {}".format(executable_name)) if name == "nt": executable_name += ".exe" possible_locations = environ["PATH"].split(pathsep) if environ.has_key("PATH") else [] possible_locations.insert(0, path.dirname(argv[0])) if name == "nt": possible_locations.append(path.join(r"C:", "Windows", "System32")) else: possible_locations += [ path.join(path.sep, "sbin"), path.join(path.sep, "usr", "bin"), path.join(path.sep, "bin"), ] possible_executables = [path.join(location, executable_name) for location in possible_locations] existing_executables = [item for item in possible_executables if path.exists(item)] if not existing_executables: logger.debug("No executables found") return executable_name logger.debug("Found the following executables: {}".format(existing_executables)) return existing_executables[0]
def getCPPCookies(self): if environ.has_key('HTTP_COOKIE'): #s('reading cookies from server...\n') #for eachCookie in map(strip, split(environ['HTTP_COOKIE'], ';')): cookies = [x.strip() for x in environ['HTTP_COOKIE'].split(';')] for eachCookie in cookies: if len(eachCookie) > 6 and eachCookie[:3] == 'CPP': tag = eachCookie[3:7] try: self.cookies[tag] = eval(unquote(eachCookie[8:])) except (NameError, SyntaxError): self.cookies[tag] = unquote(eachCookie[8:]) if not self.cookies.has_key('info'): self.cookies['info'] = '' if not self.cookies.has_key('user'): self.cookies['user'] = '' else: #s('no cookies on server...\n') self.cookies['info'] = self.cookies['user'] = '' #s('cookies: %s\n' % str(self.cookies)) if self.cookies['info'] != '': self.who, langStr, self.fn = self.cookies['info'].split(':') self.langs = langStr.split(',') else: self.who = self.fn = '' self.langs = ['Python']
def validate_references(references=None, path_to_bowtie='bowtie', logger=None, environ_key='SOT_DEFAULT_REFERENCES', target_dir=curdir, **kwargs): makedirs(target_dir, mode=0755) debug('Validating references') new_references = [] if references is None: if environ.has_key(environ_key): references = environ[environ_key].split() else: critical('no reference genomes specified') return [] for r in references: bowtie_index = find_bowtie_index(r, path_to_bowtie=path_to_bowtie) if bowtie_index is None: if exists(r): debug('Attempting to build bowtie index from %s' % r) new_index = fastq_to_bowtie(r, target_dir=target_dir, path_to_bowtie=path_to_bowtie) if new_index is not None: new_references.append(new_index) continue else: critical('Failed to build bowtie index.') critical('bowtie could not find the index for %s', r) critical('we will not align to %s', r) else: new_references.append(bowtie_index) return new_references
def __init__(self, name='sid', dir=path_join(WORK_DIR, 'sessions'), path=None, domain=None, max_age=None): self._name = name now = datetime.utcnow(); # blank cookie self._cookie = SimpleCookie() if environ.has_key('HTTP_COOKIE'): # cookie already exists, see what's in it self._cookie.load(environ['HTTP_COOKIE']) try: # what's our session ID? self.sid = self._cookie[name].value; except KeyError: # there isn't any, make a new session ID remote = environ.get('REMOTE_ADDR') self.sid = sha224('%s-%s' % (remote, now)).hexdigest() self._cookie.clear(); self._cookie[name] = self.sid # set/reset path if path: self._cookie[name]['path'] = path else: self._cookie[name]['path'] = '' # set/reset domain if domain: self._cookie[name]['domain'] = domain else: self._cookie[name]['domain'] = '' # set/reset expiration date if max_age: if isinstance(max_age, int): max_age = timedelta(seconds=max_age) expires = now + max_age self._cookie[name]['expires'] = expires.strftime('%a, %d %b %Y %H:%M:%S') else: self._cookie[name]['expires'] = '' # to protect against cookie-stealing JS, make our cookie # available only to the browser, and not to any scripts try: # This will not work for Python 2.5 and older self._cookie[name]['httponly'] = True except CookieError: pass # if the sessions dir doesn't exist, create it if not exists(dir): mkdir(dir) # persist the session data self._shelf_file = path_join(dir, self.sid) # -1 signifies the highest available protocol version self._shelf = shelve_open(self._shelf_file, protocol=-1, writeback=True)
def check_version() : if environ.has_key('SMDS_URL') : from smds.version import version from urllib import urlopen, urlretrieve import tarfile try: repository_version = urlopen(environ['SMDS_URL']+'.version').readline() except: return if version != repository_version.strip() : stop() if platform == 'win32' : from win32api import SearchPath from win32process import CreateProcess, STARTUPINFO (path, d) = SearchPath(None, 'python', '.exe') CreateProcess(path, 'python %s\\smds\\downloader.py' % environ['SMDS_LOC'], None, None, 0, 0, None, None, STARTUPINFO()) exit() else: try : fn = urlretrieve(environ['SMDS_URL'])[0] f = tarfile.open(fn, 'r:gz') for m in f.getmembers() : f.extract(m, environ['SMDS_LOC']) except : return
def foamMPI(): """@return: the used MPI-Implementation""" if not environ.has_key("WM_MPLIB"): return () else: vStr=environ["WM_MPLIB"] return vStr
def foamVersionString(useConfigurationIfNoInstallation=False): """@return: string for the Foam-version as found in $WM_PROJECT_VERSION""" if not environ.has_key("WM_PROJECT_VERSION") and not useConfigurationIfNoInstallation: return "" else: if environ.has_key("WM_PROJECT_VERSION"): vStr=environ["WM_PROJECT_VERSION"] else: vStr="" if vStr=="" and useConfigurationIfNoInstallation: vStr=config().get("OpenFOAM","Version") return vStr
def getcookie(key): if environ.has_key('HTTP_COOKIE'): for cookie in environ['HTTP_COOKIE'].split(';'): k , v = cookie.split('=') if key == k: return v return ""
def newPlayer(self): self._player = gst.element_factory_make("playbin", "player") if environ.has_key("GST_AUDIO_SINK"): sink = environ["GST_AUDIO_SINK"] self._sink = gst.element_factory_make(sink, "custom-audio-sink " + sink) self._sink.set_property("sync", True) self._player.set_property("audio-sink", self._sink)
def get_level(): from os import environ if environ.has_key('SS_LOG_LEVEL'): return getattr(logging, environ.get('SS_LOG_LEVEL')) else: return logging.DEBUG
def setup_class(cls): if ( environ.has_key('C2G_HEADLESS_TESTS') and environ['C2G_HEADLESS_TESTS'] ): cls.display = Display(visible=0, size=(800, 600)) cls.display.start() cls.browser = webdriver.Chrome() super(SeleniumTestBase, cls).setUpClass()
def __init__(self, co, user, server, txn): self.co = co self.user = user self.server = server self.txn = txn self.secret_key = "secret-%s-%s" % (user, server) self.hash_key = 'hash-%s-%s' % (user, server) self.pwid_key = "pwid-%s-%s" % (user, server) self.password = None self.secret = None self.pwid = co.linforepo.get(self.pwid_key, txn=txn) self.agent_sock = None try: if environ.has_key('CDV_AUTH_SOCK'): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(environ['CDV_AUTH_SOCK']) self.agent_sock = sock elif co.nopass == 2: raise ValueError, 'No agent found' except socket.error: if co.nopass == 2: raise return
def getEnviron(self,name): """@param name: name of an environment variable @return: value of the variable, empty string if non-existing""" result="" if environ.has_key(name): result=environ[name] return result
def format_buffer(ebuf, col=60): """Format the text buffer 'ebuf'. Parameter 'ebuf' is as a list of strings. The text displayed will use a column width no more than the value stored in the environment variable COLUMNS if available. Otherwise a conservative width of no more than 60 characters will be used. """ if environ.has_key('COLUMNS'): txtwid = int(environ['COLUMNS']) - 2 else: txtwid = col - 2 if len(ebuf) == 0: return "" final = [] while len(ebuf) > 0: (line, rem) = string_truncate(ebuf[0], txtwid) ebuf = ebuf[1:] final.append("{0:s}".format(line)) while len(rem) > txtwid: (line, rem) = string_truncate(rem, txtwid) final.append("{0:s}".format(line)) final.append("{0:s}".format(rem)) text = final[0] if not text.endswith('\n'): text += '\n' for line in final[1:]: if not line.endswith('\n'): line += '\n' text += '> ' + line return text
def main(): """<comment-ja> Web Application 起動処理 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ # logging load karesansui.lib.log.logger.reload_conf(karesansui.config['application.log.config']) if karesansui.lib.log.logger.is_ready() is False: raise karesansui.lib.log.logger.KaresansuiLogError("""Warning!! Logging set initial startup failed. example : Does the log configuration file exist? The present file path : %s """ % karesansui.config['application.log.config']) logger = logging.getLogger('karesansui.app') logger_trace = logging.getLogger('karesansui_trace.app') if not os.popen("ps -eo cmd | grep -e ^libvirtd -e ^/usr/sbin/libvirtd").read(): logger.error('libvirtd not running."/etc/init.d/libvirtd start" Please start.') print >>sys.stderr, '[Error] libvirtd not running."/etc/init.d/libvirtd start" Please start.' sys.exit(1) if web.wsgi._is_dev_mode() is True and env.has_key('FCGI') is False: logger.info('Start Mode [development]') app = web.application(urls, globals(), autoreload=True) app.internalerror = web.debugerror sys.argv = [] # argv clear else: logger.info('Start Mode [fastcgi]') web.config.debug = False app = web.application(urls, globals(), autoreload=False) #sys.argv = [] # argv clear # load processor! # - karesansui database! app.add_processor(load_sqlalchemy_karesansui) logger.info('The load was added. - load_sqlalchemy_karesansui') # - pysilhouette database! app.add_processor(load_sqlalchemy_pysilhouette) logger.info('The load was added. - load_sqlalchemy_pysilhouette') # http://domain/(../..)/hoge if karesansui.config['application.url.prefix']: mapping = (karesansui.config['application.url.prefix'], app) app = web.subdir_application(mapping) try: if (not opts is None) and opts.shell is True: # shell mode!! shell() else: app.run() # Web Application Start! except Exception, e: logger_trace.critical(traceback.format_exc()) print >>sys.stderr, "[ERROR] %s" % str(e.args) print >>sys.stderr, traceback.format_exc() return 1
def init_colors(): from colorama import init from os import environ # see http://code.google.com/p/colorama/issues/detail?id=16 # colors don't work on Cygwin if we call init # TODO delete this function when colorama is fixed if not environ.has_key('TERM'): # this is how we recognize real Windows (init should only be called there) init()
def get_tempdir(): # Default directory on POSIX machines if ((environ.has_key("TMPDIR")) and (os.path.isdir(environ["TMPDIR"]))): return environ["TMPDIR"] # TEMP / TMP are for win32 systems elif ((environ.has_key("TEMP")) and (os.path.isdir(environ["TEMP"]))): return environ["TEMP"] elif ((environ.has_key("TMP")) and (os.path.isdir(environ["TMP"]))): return environ["TMP"] else: # Try to find another existing temporary directory if (os.path.exists("/tmp")): return "/tmp" elif (os.path.exists("/var/tmp")): return "/var/tmp" else: return "/usr/tmp"
def getHostDomain(): site = '' if environ.has_key('INTBUILD_SITELOCAL'): site = 'localhost.localdomain.com' else: import socket site = socket.getfqdn() fqdn = site.split('.') return fqdn[0], fqdn[-2]+'.'+fqdn[-1]
def get_path_to_analog_hardware_backend(): symap2ic_path = get_symap2ic_path() if environ.has_key('PYNN_HW_PATH'): hardware_path = get_pynn_hw_path() else: hardware_path = get_hardware_path(symap2ic_path) return hardware_path
def __init__(self): if env.has_key('TM_PROJECT_DIRECTORY'): self.project_dir = env['TM_PROJECT_DIRECTORY'] else: self.project_dir = "." self.index = Index.create() self.type_kinds = set([CursorKind.STRUCT_DECL, CursorKind.CLASS_DECL, CursorKind.CLASS_TEMPLATE,CursorKind.TYPEDEF_DECL])
def _setOpt(name, value, conv=None): '''set a module level value from environ/default''' from os import environ ename = 'RL_'+name if environ.has_key(ename): value = environ[ename] if conv: value = conv(value) globals()[name] = value
def index(): addr, host = "", "" if environ.has_key('REMOTE_ADDR'): addr = environ['REMOTE_ADDR'] if environ.has_key('REMOTE_HOST'): host = environ['REMOTE_HOST'] else: host = socket.gethostbyaddr(addr)[0] html = """ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>PythonSpy</title> <style type="text/css"> body,td{font: 12px Arial,Tahoma;line-height: 16px;} .input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;} .area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;} .bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;} a {color: #00f;text-decoration:underline;} a:hover{color: #f00;text-decoration:none;} .alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;} .alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;} .focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;} .head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;} .head td span{font-weight:normal;} form{margin:0;padding:0;} h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;} ul.info li{margin:0;color:#444;line-height:24px;height:24px;} u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;} </style> <script type="text/javascript"> function CheckAll(form) { for(var i=0;i<form.elements.length;i++) { var e = form.elements[i]; if (e.name != 'chkall') e.checked = form.chkall.checked; } } function $(id) { return document.getElementById(id); } function goaction(act){ $('goaction').action.value=act; $('goaction').submit(); } </script> </head> <body style="margin:0;table-layout:fixed; word-break:break-all"> <table width="100%%" border="0" cellpadding="0" cellspacing="0"> <tr class="head"> <td><span style="float:right;"><a href="http://blog.csdn.net/yueguanghaidao" target="_blank"> Author: SkyCrab</a></span>%s(%s) </td> </tr> <tr class="alt1"> <td> <a href="javascript:goaction('file');">File Manager</a> | <a href="javascript:goaction('shell');">Execute Command</a> | <a href="javascript:goaction('env');">System Variable</a> | <a href="javascript:goaction('eval');">Eval Python Code</a> </td> </tr> </table> <form name="goaction" id="goaction" action="" method="post" > <input id="action" type="hidden" name="action" value="" /> </form> """ % (addr, host) print html handler()
STATIC_URL = '/static/' TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')] TEMPLATE_CONTEXT_PROCESSORS = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.core.context_processors.tz", "django.contrib.messages.context_processors.messages") from os import environ from urlparse import urlparse if environ.has_key('DATABASE_URL'): url = urlparse(environ['DATABASE_URL']) DATABASES['default'] = { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': url.path[1:], 'USER': url.username, 'PASSWORD': url.password, 'HOST': url.hostname, 'PORT': url.port, } GRAPH_MODELS = { 'all_applications': True, 'group_models': True, }
John Jacobsen, [email protected] Started November, 2006 """ from DAQRunIface import DAQRunIface from DAQConst import DAQPort from os.path import join, exists from os import environ from datetime import * from re import search import optparse import time import sys # Find install location via $PDAQ_HOME, otherwise use locate_pdaq.py if environ.has_key("PDAQ_HOME"): metaDir = environ["PDAQ_HOME"] else: from locate_pdaq import find_pdaq_trunk metaDir = find_pdaq_trunk() # add meta-project python dir to Python library search path sys.path.append(join(metaDir, 'src', 'main', 'python')) from SVNVersionInfo import get_version_info SVN_ID = "$Id: ExpControlSkel.py 4024 2009-04-03 21:03:29Z dglo $" class DOMArgumentException(Exception): pass
type=str, default=None) parser.add_option( "-f", "--force", dest="force", help= "Force running of workflows without checking the server for previous run", action="store_true", default=False) opts, args = parser.parse_args() if len(args) > 0: parser.error("Too many/few arguments") if not opts.workflow: parser.error("Missing -l|--list <workflows> argument.") if (not environ.has_key("CMSSW_VERSION")) or ( not environ.has_key("CMSSW_BASE")) or ( not environ.has_key("SCRAM_ARCH")): print "ERROR: Unable to file the release environment, please make sure you have set the cmssw environment before calling this script" exit(1) thrds = cmsRunProcessCount cmssw_ver = environ["CMSSW_VERSION"] arch = environ["SCRAM_ARCH"] cmssw_base = environ["CMSSW_BASE"] logger = LogUpdater(dirIn=cmssw_base) if re.match("^CMSSW_(9_([3-9]|[1-9][0-9]+)|[1-9][0-9]+)_.*$", cmssw_ver): p = Popen("%s/jobs/create-relval-jobs.py %s" % (SCRIPT_DIR, opts.workflow), shell=True)
def test_tzset(self): from os import environ # Epoch time of midnight Dec 25th 2002. Never DST in northern # hemisphere. xmas2002 = 1040774400.0 # These formats are correct for 2002, and possibly future years # This format is the 'standard' as documented at: # http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap08.html # They are also documented in the tzset(3) man page on most Unix # systems. eastern = 'EST+05EDT,M4.1.0,M10.5.0' victoria = 'AEST-10AEDT-11,M10.5.0,M3.5.0' utc='UTC+0' org_TZ = environ.get('TZ',None) try: # Make sure we can switch to UTC time and results are correct # Note that unknown timezones default to UTC. # Note that altzone is undefined in UTC, as there is no DST environ['TZ'] = eastern time.tzset() environ['TZ'] = utc time.tzset() self.assertEqual( time.gmtime(xmas2002), time.localtime(xmas2002) ) self.assertEqual(time.daylight, 0) self.assertEqual(time.timezone, 0) self.assertEqual(time.localtime(xmas2002).tm_isdst, 0) # Make sure we can switch to US/Eastern environ['TZ'] = eastern time.tzset() self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) self.assertEqual(time.tzname, ('EST', 'EDT')) self.assertEqual(len(time.tzname), 2) self.assertEqual(time.daylight, 1) self.assertEqual(time.timezone, 18000) self.assertEqual(time.altzone, 14400) self.assertEqual(time.localtime(xmas2002).tm_isdst, 0) self.assertEqual(len(time.tzname), 2) # Now go to the southern hemisphere. environ['TZ'] = victoria time.tzset() self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) # Issue #11886: Australian Eastern Standard Time (UTC+10) is called # "EST" (as Eastern Standard Time, UTC-5) instead of "AEST" on some # operating systems (e.g. FreeBSD), which is wrong. See for example # this bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=93810 self.assertIn(time.tzname[0], ('AEST' 'EST'), time.tzname[0]) self.assertTrue(time.tzname[1] == 'AEDT', str(time.tzname[1])) self.assertEqual(len(time.tzname), 2) self.assertEqual(time.daylight, 1) self.assertEqual(time.timezone, -36000) self.assertEqual(time.altzone, -39600) self.assertEqual(time.localtime(xmas2002).tm_isdst, 1) finally: # Repair TZ environment variable in case any other tests # rely on it. if org_TZ is not None: environ['TZ'] = org_TZ elif environ.has_key('TZ'): del environ['TZ'] time.tzset()
def setUp(self): if environ.has_key('SOCCERMETRICS_APP_KEY'): del environ['SOCCERMETRICS_APP_KEY'] if environ.has_key('SOCCERMETRICS_APP_ID'): del environ['SOCCERMETRICS_APP_ID']
import win32api # define default players, common locations ie = "c:/Program Files/Internet Explorer/iexplore.exe" safari = "/Applications/Safari.app" ff = { "win": "c:/Program Files/Mozilla Firefox/firefox.exe", "lnx": "/usr/bin/firefox", "mac": "/Applications/Firefox.app" }[ostype] sa = "c:/builds/latest/FlashPlayer.exe" # set environment variable: playertype=ie,ff,sa,safari # if default does not work set: playerpath=path to player or browser try: if environ.has_key('player') == False: playertype = ff else: playertype = environ['player'] if environ.has_key('playerpath'): player = environ['playerpath'] else: player = { 'ie': ie, 'ff': ff, 'sa': sa, 'internetexplorer': ie, 'firefox': ff, 'saplayer': sa, 'safari': safari
# __author__ = "Sebastien E. Bourban; Noemie Durand" __date__ = "$19-Jul-2010 08:51:29$" if __name__ == "__main__": debug = False BYPASS = True # /!\ Temporary bypass for subroutine within programs # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< # ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ print '\n\nLoading Options and Configurations\n\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' USETELCFG = '' if environ.has_key('USETELCFG'): USETELCFG = environ['USETELCFG'] PWD = path.dirname(path.dirname(sys.argv[0])) SYSTELCFG = path.join(PWD, 'config') if environ.has_key('SYSTELCFG'): SYSTELCFG = environ['SYSTELCFG'] if path.isdir(SYSTELCFG): SYSTELCFG = path.join(SYSTELCFG, 'systel.cfg') parser = OptionParser("usage: %prog [options] \nuse -h for more help.") parser.add_option( "-c", "--configname", type="string", dest="configName", default=USETELCFG, help= "specify configuration name, default is randomly found in the configuration file" ) parser.add_option("-f",
fixPathSettings.add_on_change('fixpath-reload', fixPath) # Save the original environ (particularly the original PATH) to restore later global originalEnv for key in environ: originalEnv[key] = environ[key] fixPath() def plugin_unloaded(): # When we unload, reset PATH to original value. Otherwise, reloads of this plugin will cause # the PATH to be duplicated. environ['PATH'] = originalEnv['PATH'] global fixPathSettings fixPathSettings.clear_on_change('fixpath-reload') # Sublime Text 2 doesn't have loaded/unloaded handlers, so trigger startup code manually, first # taking care to clean up any messes from last time. if int(sublime.version()) < 3000: # Stash the original PATH in the env variable _ST_ORIG_PATH. if environ.has_key('_ST_ORIG_PATH'): # If _ST_ORIG_PATH exists, restore it as the true path. environ['PATH'] = environ['_ST_ORIG_PATH'] else: # If it doesn't exist, create it environ['_ST_ORIG_PATH'] = environ['PATH'] plugin_loaded()
def CGI_ENV_Get(self, varname): value = "" if (environ.has_key(varname)): value = environ[varname] return value
#!/usr/bin/python # Import modules for CGI handling from os import environ import cgi, cgitb if environ.has_key('HTTP_COOKIE'): for cookie in map(strip, split(environ['HTTP_COOKIE'], ';')): (key, value) = split(cookie, '=') if key == "UserID": user_id = value if key == "Password": password = value print "User ID = %s" % user_id print "Password = %s" % password
def setUp(self): environ['SOCCERMETRICS_APP_KEY'] = 'AUTH_TOKEN' if environ.has_key('SOCCERMETRICS_APP_ID'): del environ['SOCCERMETRICS_APP_ID']
def getCookieVal(name): if environ.has_key('HTTP_COOKIE'): for cookie in environ['HTTP_COOKIE'].split(';'): (k, v) = cookie.split('=', 1) if k == name: return v
# -*- coding: utf-8 -*- from os import environ from .common import * read_env = lambda e, d=None: environ[e] if environ.has_key(e) else d DEBUG = os.environ.get('ROTV_STAGING_DJANGO_DEBUG') TEMPLATE_DEBUG = DEBUG DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': read_env('ROTV_STAGING_DB_NAME' ), # Or path to database file if using sqlite3. 'USER': read_env('ROTV_STAGING_DB_USER'), # Not used with sqlite3. 'PASSWORD': read_env('ROTV_STAGING_DB_PASS'), # Not used with sqlite3. 'HOST': read_env( 'ROTV_STAGING_DB_HOST' ), # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } ALLOWED_HOSTS += [ 'staging.raportobiezyswiata.tv', ] SECRET_KEY = read_env('ROTV_STAGING_SECRET')
def getDbCreds(VAULT_ROLE="web-role"): VAULT_ADDR = "" VAULT_NONCE = "" creds = {} creds['db_host'] = "" creds['db_port'] = "" creds['db_name'] = "" creds['db_username'] = "" creds['db_password'] = "" creds['lease_id'] = "" creds['lease_duration'] = 0 # Get the PKCS7 signature from this EC2 instance's metadata try: PKCS7 = get( "http://169.254.169.254/latest/dynamic/instance-identity/pkcs7" ).text except: return creds # Get the VAULT_NONCE ENV variable (should be set in apache SetEnv for us # during server build in userdata.sh) if environ.has_key('VAULT_NONCE'): VAULT_NONCE = environ['VAULT_NONCE'] if environ.has_key('VAULT_ADDR'): VAULT_ADDR = environ['VAULT_ADDR'] print "VAULT_NONCE: %s" % VAULT_NONCE print "VAULT_ADDR: %s" % VAULT_ADDR # If the vault server wasnt set in the EnvVars, go try to get it from the Ec2 # tag VAULT_IP if VAULT_ADDR == "": META_ADDR = "http://169.254.169.254/latest/meta-data" instance_id = get(META_ADDR + "/instance-id").text region = get(META_ADDR + "/placement/availability-zone").text[:-1] from boto3 import resource ec2 = resource('ec2', region_name=region) ec2instance = ec2.Instance(instance_id) for tag in ec2instance.tags: if tag["Key"] == "VaultIP": VAULT_IP = tag["Value"] VAULT_ADDR = 'http://%s:8200' % VAULT_IP # Initiate a vault client import hvac vaultClient = hvac.Client(url=VAULT_ADDR) # Authenticate the client to vault auth_params = { 'role': VAULT_ROLE, 'pkcs7': PKCS7, 'nonce': VAULT_NONCE, } try: result = vaultClient.auth('/v1/auth/aws-ec2/login', json=auth_params) except: return creds # Get database information from vault request = (vaultClient.read('secret/mysql')) creds['db_host'] = request['data']['host'] creds['db_port'] = request['data']['port'] creds['db_name'] = request['data']['database'] request = (vaultClient.read('mysql/creds/readwrite')) creds['db_username'] = request['data']['username'] creds['db_password'] = request['data']['password'] creds['lease_id'] = request['lease_id'] creds['lease_duration'] = request['lease_duration'] return creds
"revision": self.file_revision(commit, full_path), "branch": self.extract_branch(), "addedlines": "0", "removedlines": "0", "description": commit["message"], "commitid": commit["id"], "hash": commit["id"], "author": self.extract_email(commit["author"]), "committer": self.extract_email(self.extract_committer(commit)) } rows.append(row) db = PostsaiDB(self.config) db.import_data(rows) print("Content-Type: text/plain; charset='utf-8'\r") print("\r") print("Completed") if __name__ == '__main__': if environ.has_key( 'REQUEST_METHOD') and environ['REQUEST_METHOD'] == "POST": PostsaiImporter(vars(config), json.loads(sys.stdin.read())).import_from_webhook() else: form = cgi.FieldStorage() if form.getfirst("method", "") == "commit": PostsaiCommitViewer(vars(config)).process() else: Postsai(vars(config)).process()
"""Production settings and globals.""" from common import * from os import environ from urlparse import urlparse ########## DATABASE CONFIGURATION if environ.has_key('DATABASE_URL'): # provided by heroku url = urlparse(environ['DATABASE_URL']) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': url.path[1:], 'USER': url.username, 'PASSWORD': url.password, 'HOST': url.hostname, 'PORT': url.port, } } ########## END DATABASE CONFIGURATION ########## INSTALLED APPS CONFIGURATION INSTALLED_APPS += ( 'gunicorn', 'storages', ) ########## END INSTALLED APPS CONFIGURATION ########## SSL CONFIGURATION
DEFAULT_MAXIMUM_QUEUE = 1000 DEFAULT_IMMEDIATE_DISPATCH = logging.CRITICAL + 1 #------------------------------------------------------------------------------ LEVELS = { 'CRITICAL': ACSLog.ACS_LOG_CRITICAL, 'ERROR': ACSLog.ACS_LOG_ERROR, 'WARN': ACSLog.ACS_LOG_WARNING, 'WARNING': ACSLog.ACS_LOG_WARNING, 'INFO': ACSLog.ACS_LOG_INFO, 'DEBUG': ACSLog.ACS_LOG_DEBUG, 'NOTSET': ACSLog.ACS_LOG_TRACE } #create a file handler if environ.has_key('ACS_LOG_FILE'): LOG_FILE_NAME = environ['ACS_LOG_FILE'] else: if environ.has_key('ACS_TMP'): LOG_FILE_NAME = path.join(environ['ACS_TMP'], 'acs_local_log') else: LOG_FILE_NAME = path.join(environ['ACSDATA'], 'tmp/' + gethostname() + '/acs_local_log') LOG_FILE_NAME = LOG_FILE_NAME + "_" + path.basename(sys.argv[0]) + "_" + str( getpid()) #------------------------------------------------------------------------------ class ACSLogRecord(logging.LogRecord): '''
def test_tzset(self): if not hasattr(time, "tzset"): return # Can't test this; don't want the test suite to fail from os import environ # Epoch time of midnight Dec 25th 2002. Never DST in northern # hemisphere. xmas2002 = 1040774400.0 # These formats are correct for 2002, and possibly future years # This format is the 'standard' as documented at: # http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap08.html # They are also documented in the tzset(3) man page on most Unix # systems. eastern = 'EST+05EDT,M4.1.0,M10.5.0' victoria = 'AEST-10AEDT-11,M10.5.0,M3.5.0' utc = 'UTC+0' org_TZ = environ.get('TZ', None) try: # Make sure we can switch to UTC time and results are correct # Note that unknown timezones default to UTC. # Note that altzone is undefined in UTC, as there is no DST environ['TZ'] = eastern time.tzset() environ['TZ'] = utc time.tzset() self.assertEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) self.assertEqual(time.daylight, 0) self.assertEqual(time.timezone, 0) self.assertEqual(time.localtime(xmas2002).tm_isdst, 0) # Make sure we can switch to US/Eastern environ['TZ'] = eastern time.tzset() self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) self.assertEqual(time.tzname, ('EST', 'EDT')) self.assertEqual(len(time.tzname), 2) self.assertEqual(time.daylight, 1) self.assertEqual(time.timezone, 18000) self.assertEqual(time.altzone, 14400) self.assertEqual(time.localtime(xmas2002).tm_isdst, 0) self.assertEqual(len(time.tzname), 2) # Now go to the southern hemisphere. environ['TZ'] = victoria time.tzset() self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) self.assertTrue(time.tzname[0] == 'AEST', str(time.tzname[0])) self.assertTrue(time.tzname[1] == 'AEDT', str(time.tzname[1])) self.assertEqual(len(time.tzname), 2) self.assertEqual(time.daylight, 1) self.assertEqual(time.timezone, -36000) self.assertEqual(time.altzone, -39600) self.assertEqual(time.localtime(xmas2002).tm_isdst, 1) finally: # Repair TZ environment variable in case any other tests # rely on it. if org_TZ is not None: environ['TZ'] = org_TZ elif environ.has_key('TZ'): del environ['TZ'] time.tzset()
'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } #import dj_database_url #DATABASES = {'default': dj_database_url.config(default='postgres://localhost')} ON_HEROKU = False if 'HEROKU_PRODUCTION_FLAG' in os.environ: env = lambda e, d: environ[e] if environ.has_key(e) else d ON_HEROKU = True EMAIL_HOST = env('EMAIL_HOST', 'smtp.gmail.com') EMAIL_HOST_USER = env('EMAIL_HOST_USER', '') EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD', '') TEST_EMAIL_LIST = [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ] # FULL_EMAIL_LIST = [ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**',
# Django settings for gruvdrift project. from os import environ from ConfigParser import ConfigParser local_cfg = ConfigParser() if environ.has_key('GDHOME'): local_cfg.read("%s/settings-local.conf" % environ['GDHOME']) else: local_cfg.read("settings-local.conf") DEBUG = local_cfg.getboolean('devel', 'debug') LDEVPATH = local_cfg.getboolean('devel', 'ldevpath') #DEBUG = False TEMPLATE_DEBUG = DEBUG FORCE_SCRIPT_NAME = "" ADMINS = ( # ('Your Name', '*****@*****.**'), ) MANAGERS = ADMINS LOGIN_URL = "/auth/" DATABASES = { 'default': { # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'ENGINE': 'django.db.backends.%s' % local_cfg.get('db', 'type'), 'NAME': local_cfg.get('db', 'name'), # Or path to database file if using sqlite3.
def handle_argset(argset,xmlDOC,xmlCPG,machineFileInfo): global totalProcs, nextRange, argvCopy, configLines, configIdx, appnum global validGlobalArgs, globalArgs, validLocalArgs, localArgSets host = globalArgs['-ghost'] wdir = globalArgs['-gwdir'] wpath = globalArgs['-gpath'] nProcs = globalArgs['-gn'] usize = globalArgs['-usize'] gexec = globalArgs['-gexec'] softness = globalArgs['-gsoft'] if globalArgs['-genvnone']: envall = 0 else: envall = 1 if globalArgs['-genvlist']: globalArgs['-genvlist'] = globalArgs['-genvlist'].split(',') localEnvlist = [] localEnv = {} argidx = 0 while argidx < len(argset): if argset[argidx] not in validLocalArgs: if argset[argidx][0] == '-': if validGlobalArgs.has_key(argset[argidx]): print 'global arg %s must not appear among local args' % \ (argset[argidx]) else: print 'unknown option: %s' % argset[argidx] usage() break # since now at executable if argset[argidx] == '-n' or argset[argidx] == '-np': if len(argset) < (argidx+2): print '** missing arg to -n' usage() nProcs = argset[argidx+1] if not nProcs.isdigit(): print '** non-numeric arg to -n: %s' % nProcs usage() nProcs = int(nProcs) argidx += 2 elif argset[argidx] == '-host': if len(argset) < (argidx+2): print '** missing arg to -host' usage() host = argset[argidx+1] argidx += 2 elif argset[argidx] == '-path': if len(argset) < (argidx+2): print '** missing arg to -path' usage() wpath = argset[argidx+1] argidx += 2 elif argset[argidx] == '-wdir': if len(argset) < (argidx+2): print '** missing arg to -wdir' usage() wdir = argset[argidx+1] argidx += 2 elif argset[argidx] == '-soft': if len(argset) < (argidx+2): print '** missing arg to -soft' usage() softness = argset[argidx+1] argidx += 2 elif argset[argidx] == '-arch': if len(argset) < (argidx+2): print '** missing arg to -arch' usage() print '** -arch is accepted but not used' argidx += 2 elif argset[argidx] == '-envall': envall = 1 argidx += 1 elif argset[argidx] == '-envnone': envall = 0 argidx += 1 elif argset[argidx] == '-envlist': localEnvlist = argset[argidx+1].split(',') argidx += 2 elif argset[argidx] == '-env': if len(argset) < (argidx+3): print '** missing arg to -env' usage() var = argset[argidx+1] val = argset[argidx+2] localEnv[var] = val argidx += 3 else: print 'unknown option: %s' % argset[argidx] usage() if softness: nProcs = adjust_nprocs(nProcs,softness) cmdAndArgs = [] if argidx < len(argset): while argidx < len(argset): cmdAndArgs.append(argset[argidx]) argidx += 1 else: if gexec: cmdAndArgs = [gexec] if not cmdAndArgs: print 'no cmd specified' usage() argsetLoRange = nextRange argsetHiRange = nextRange + nProcs - 1 loRange = argsetLoRange hiRange = argsetHiRange defaultHostForArgset = host while loRange <= argsetHiRange: host = defaultHostForArgset ifhn = '' if machineFileInfo: if len(machineFileInfo) <= hiRange: print 'too few entries in machinefile' exit(-1) host = machineFileInfo[loRange]['host'] ifhn = machineFileInfo[loRange]['ifhn'] for i in range(loRange+1,hiRange+1): if machineFileInfo[i]['host'] != host or machineFileInfo[i]['ifhn'] != ifhn: hiRange = i - 1 break xmlPROCSPEC = xmlDOC.createElement('process-spec') xmlCPG.appendChild(xmlPROCSPEC) xmlPROCSPEC.setAttribute('user',getpwuid(getuid())[0]) xmlPROCSPEC.setAttribute('exec',cmdAndArgs[0]) xmlPROCSPEC.setAttribute('path',wpath) xmlPROCSPEC.setAttribute('cwd',wdir) xmlPROCSPEC.setAttribute('host',host) xmlPROCSPEC.setAttribute('range','%d-%d' % (loRange,hiRange)) for i in xrange(1,len(cmdAndArgs[1:])+1): arg = cmdAndArgs[i] xmlARG = xmlDOC.createElement('arg') xmlPROCSPEC.appendChild(xmlARG) xmlARG.setAttribute('idx', '%d' % (i) ) xmlARG.setAttribute('value', '%s' % (quote(arg))) envToSend = {} if envall: for envvar in environ.keys(): envToSend[envvar] = environ[envvar] for envvar in globalArgs['-genvlist']: if not environ.has_key(envvar): print '%s in envlist does not exist in your env' % (envvar) exit(-1) envToSend[envvar] = environ[envvar] for envvar in localEnvlist: if not environ.has_key(envvar): print '%s in envlist does not exist in your env' % (envvar) exit(-1) envToSend[envvar] = environ[envvar] for envvar in globalArgs['-genv'].keys(): envToSend[envvar] = globalArgs['-genv'][envvar] for envvar in localEnv.keys(): envToSend[envvar] = localEnv[envvar] for envvar in envToSend.keys(): xmlENVVAR = xmlDOC.createElement('env') xmlPROCSPEC.appendChild(xmlENVVAR) xmlENVVAR.setAttribute('name', '%s' % (envvar)) xmlENVVAR.setAttribute('value', '%s' % (envToSend[envvar])) if usize: xmlENVVAR = xmlDOC.createElement('env') xmlPROCSPEC.appendChild(xmlENVVAR) xmlENVVAR.setAttribute('name', 'MPI_UNIVERSE_SIZE') xmlENVVAR.setAttribute('value', '%s' % (usize)) xmlENVVAR = xmlDOC.createElement('env') xmlPROCSPEC.appendChild(xmlENVVAR) xmlENVVAR.setAttribute('name', 'MPI_APPNUM') xmlENVVAR.setAttribute('value', '%s' % str(appnum)) if ifhn: xmlENVVAR.setAttribute('name', 'MPICH_INTERFACE_HOSTNAME') xmlENVVAR.setAttribute('value', '%s' % (ifhn)) loRange = hiRange + 1 hiRange = argsetHiRange # again appnum += 1 nextRange += nProcs totalProcs += nProcs
def mpdboot(): global myHost, fullDirName, rshCmd, user, mpdCmd, debug, verbose myHost = gethostname() mpd_set_my_id('mpdboot_%s' % (myHost) ) fullDirName = path.abspath(path.split(argv[0])[0]) rshCmd = 'ssh' user = mpd_get_my_username() mpdCmd = path.join(fullDirName,'mpd.py') hostsFilename = 'mpd.hosts' totalnumToStart = 1 # may get chgd below debug = 0 verbose = 0 localConArg = '' remoteConArg = '' oneMPDPerHost = 1 myNcpus = 1 myIfhn = '' chkupIndicator = 0 # 1 -> chk and start ; 2 -> just chk maxUnderOneRoot = 4 try: shell = path.split(environ['SHELL'])[-1] except: shell = 'csh' argidx = 1 # skip arg 0 while argidx < len(argv): if argv[argidx] == '-h' or argv[argidx] == '--help': usage() elif argv[argidx] == '-r': # or --rsh= rshCmd = argv[argidx+1] argidx += 2 elif argv[argidx].startswith('--rsh'): splitArg = argv[argidx].split('=') try: rshCmd = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-u': # or --user= user = argv[argidx+1] argidx += 2 elif argv[argidx].startswith('--user'): splitArg = argv[argidx].split('=') try: user = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-m': # or --mpd= mpdCmd = argv[argidx+1] argidx += 2 elif argv[argidx].startswith('--mpd'): splitArg = argv[argidx].split('=') try: mpdCmd = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-f': # or --file= hostsFilename = argv[argidx+1] argidx += 2 elif argv[argidx].startswith('--file'): splitArg = argv[argidx].split('=') try: hostsFilename = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx].startswith('--ncpus'): splitArg = argv[argidx].split('=') try: myNcpus = int(splitArg[1]) except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx].startswith('--ifhn'): splitArg = argv[argidx].split('=') myIfhn = splitArg[1] myHost = splitArg[1] argidx += 1 elif argv[argidx] == '-n': # or --totalnum= totalnumToStart = int(argv[argidx+1]) argidx += 2 elif argv[argidx].startswith('--totalnum'): splitArg = argv[argidx].split('=') try: totalnumToStart = int(splitArg[1]) except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx].startswith('--maxbranch'): splitArg = argv[argidx].split('=') try: maxUnderOneRoot = int(splitArg[1]) except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-d' or argv[argidx] == '--debug': debug = 1 argidx += 1 elif argv[argidx] == '-s' or argv[argidx] == '--shell': shell = 'bourne' argidx += 1 elif argv[argidx] == '-v' or argv[argidx] == '--verbose': verbose = 1 argidx += 1 elif argv[argidx] == '-c' or argv[argidx] == '--chkup': chkupIndicator = 1 argidx += 1 elif argv[argidx] == '--chkuponly': chkupIndicator = 2 argidx += 1 elif argv[argidx] == '-1': oneMPDPerHost = 0 argidx += 1 elif argv[argidx] == '--loccons': localConArg = '-n' argidx += 1 elif argv[argidx] == '--remcons': remoteConArg = '-n' argidx += 1 else: print 'mpdboot: unrecognized argument:', argv[argidx] usage() if debug: print 'debug: starting' lines = [] if totalnumToStart > 1: try: f = open(hostsFilename,'r') for line in f: lines.append(line) except: print 'unable to open (or read) hostsfile %s' % (hostsFilename) exit(-1) hostsAndInfo = [ {'host' : myHost, 'ncpus' : myNcpus, 'ifhn' : myIfhn} ] for line in lines: line = line.strip() if not line or line[0] == '#': continue splitLine = re.split(r'\s+',line) host = splitLine[0] ncpus = 1 # default if ':' in host: (host,ncpus) = host.split(':',1) ncpus = int(ncpus) ifhn = '' # default for kv in splitLine[1:]: (k,v) = kv.split('=',1) if k == 'ifhn': ifhn = v hostsAndInfo.append( {'host' : host, 'ncpus' : ncpus, 'ifhn' : ifhn} ) cachedIPs = {} if oneMPDPerHost and totalnumToStart > 1: oldHostsAndInfo = hostsAndInfo[:] hostsAndInfo = [] for hostAndInfo in oldHostsAndInfo: oldhost = hostAndInfo['host'] try: ips = gethostbyname_ex(oldhost)[2] # may fail if invalid host except: print 'unable to obtain IP for host:', oldhost continue uips = {} # unique ips for ip in ips: uips[ip] = 1 keep = 1 for ip in uips.keys(): if cachedIPs.has_key(ip): keep = 0 break if keep: hostsAndInfo.append(hostAndInfo) cachedIPs.update(uips) if len(hostsAndInfo) < totalnumToStart: # one is local print 'totalnum=%d numhosts=%d' % (totalnumToStart,len(hostsAndInfo)) print 'there are not enough hosts on which to start all processes' exit(-1) if chkupIndicator: hostsToCheck = [ hai['host'] for hai in hostsAndInfo[1:totalnumToStart] ] (upList,dnList) = chkupdn(hostsToCheck) if dnList: print "these hosts are down; exiting" print dnList exit(-1) print "there are %d hosts up (counting local)" % (len(upList)+1) if chkupIndicator == 2: # do the chkup and quit exit(0) try: # stop current (if any) mpds; ignore the output getoutput('%s/mpdallexit.py' % (fullDirName)) if verbose or debug: print 'running mpdallexit on %s' % (myHost) except: pass if environ.has_key('MPD_TMPDIR'): tmpdir = environ['MPD_TMPDIR'] else: tmpdir = '' if myIfhn: ifhn = '--ifhn=%s' % (myIfhn) else: ifhn = '' hostsAndInfo[0]['entry_host'] = '' hostsAndInfo[0]['entry_port'] = '' mpdArgs = '%s %s --ncpus=%d' % (localConArg,ifhn,myNcpus) if tmpdir: mpdArgs += ' --tmpdir=%s' % (tmpdir) (mpdPID,mpdFD) = launch_one_mpd(0,0,mpdArgs,hostsAndInfo) fd2idx = {mpdFD : 0} handle_mpd_output(mpdFD,fd2idx,hostsAndInfo) try: from os import sysconf maxfds = sysconf('SC_OPEN_MAX') except: maxfds = 1024 maxAtOnce = min(128,maxfds-8) # -8 for stdeout, etc. + a few more for padding hostsSeen = { myHost : 1 } fdsToSelect = [] numStarted = 1 # local already going numStarting = 0 numUnderCurrRoot = 0 possRoots = [] currRoot = 0 idxToStart = 1 # local mpd already going while numStarted < totalnumToStart: if numStarting < maxAtOnce and idxToStart < totalnumToStart: if numUnderCurrRoot < maxUnderOneRoot: entryHost = hostsAndInfo[currRoot]['host'] entryPort = hostsAndInfo[currRoot]['list_port'] hostsAndInfo[idxToStart]['entry_host'] = entryHost hostsAndInfo[idxToStart]['entry_port'] = entryPort if hostsSeen.has_key(hostsAndInfo[idxToStart]['host']): remoteConArg = '-n' myNcpus = hostsAndInfo[idxToStart]['ncpus'] ifhn = hostsAndInfo[idxToStart]['ifhn'] if ifhn: ifhn = '--ifhn=%s' % (ifhn) mpdArgs = '%s -h %s -p %s %s --ncpus=%d' % (remoteConArg,entryHost,entryPort,ifhn,myNcpus) if tmpdir: mpdArgs += ' --tmpdir=%s' % (tmpdir) (mpdPID,mpdFD) = launch_one_mpd(idxToStart,currRoot,mpdArgs,hostsAndInfo) numStarting += 1 numUnderCurrRoot += 1 hostsAndInfo[idxToStart]['pid'] = mpdPID hostsSeen[hostsAndInfo[idxToStart]['host']] = 1 fd2idx[mpdFD] = idxToStart fdsToSelect.append(mpdFD) idxToStart += 1 else: if possRoots: currRoot = possRoots.pop() numUnderCurrRoot = 0 selectTime = 0.01 else: selectTime = 0.1 try: (readyFDs,unused1,unused2) = select(fdsToSelect,[],[],selectTime) except error, errmsg: mpd_print(1,'mpdboot: select failed: errmsg=:%s:' % (errmsg) ) exit(-1) for fd in readyFDs: handle_mpd_output(fd,fd2idx,hostsAndInfo) numStarted += 1 numStarting -= 1 possRoots.append(fd2idx[fd]) fdsToSelect.remove(fd) fd.close()
from ctypes import c_float,\ cdll,\ c_double,\ c_int,\ pythonapi,\ py_object,\ c_void_p from os import environ import sys libcname = "/lib/libc.so.6" # default path, but is different in e.g. Ubuntu 11.10 if environ.has_key("LIBCPATH"): libcname = environ["LIBCPATH"] if environ.has_key("GROMPY_DOUBLE"): isdouble = True c_real = c_double print "Loading GromPy with double precision library..." libmdname = "libmd_d.so" libgmxname = "libgmx_d.so" libmdrunname = "mdrun_d.so" else: isdouble = False c_real = c_float print "Loading GromPy with single precision library..." libmdname = "libmd.so" libgmxname = "libgmx.so" libmdrunname = "mdrun.so"
f = open("/nfs/Temp/migrate", "w+") print >> f, env f.close() theDir = env["SGE_CKPT_DIR"] if theDir == "NONE": theDir = env["SGE_O_WORKDIR"] jobName = env["JOB_NAME"] jobId = env["JOB_ID"] timeout = 36000 waiting = 10 fName = path.join(theDir, "%s.%s" % (jobName, jobId)) if env.has_key("TASK_IS"): fName += ".%s" % env["TASK_ID"] fName += ".pyFoam.clusterjob" if trigger == "clean": system("rm -f " + fName + "*") sys.exit(0) if not path.exists(fName): print "Job does not seem to exist" sys.exit(-1) trigger = fName + "." + trigger # trigger=fName+".checkpoint" f = open(trigger, "w")
def mpdboot(): global myHost, fullDirName, rshCmd, user, mpdCmd, debug, verbose myHost = gethostname() mpd_set_my_id('mpdboot_%s' % (myHost)) fullDirName = path.abspath(path.split(argv[0])[0]) rshCmd = 'ssh' user = mpd_get_my_username() mpdCmd = path.join(fullDirName, 'mpd.py') hostsFilename = 'mpd.hosts' totalnumToStart = 0 debug = 0 verbose = 0 chkupIndicator = 0 # 1 -> chk and start ; 2 -> just chk maxUnderOneRoot = 4 try: shell = path.split(environ['SHELL'])[-1] except: shell = 'csh' if environ.has_key('MPD_TMPDIR'): tmpdir = environ['MPD_TMPDIR'] else: tmpdir = '' argidx = 1 # skip arg 0 while argidx < len(argv): if argv[argidx] == '-h' or argv[argidx] == '--help': usage() elif argv[argidx] == '-r': # or --rsh= rshCmd = argv[argidx + 1] argidx += 2 elif argv[argidx].startswith('--rsh'): splitArg = argv[argidx].split('=') try: rshCmd = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-u': # or --user= user = argv[argidx + 1] argidx += 2 elif argv[argidx].startswith('--user'): splitArg = argv[argidx].split('=') try: user = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-m': # or --mpd= mpdCmd = argv[argidx + 1] argidx += 2 elif argv[argidx].startswith('--mpd'): splitArg = argv[argidx].split('=') try: mpdCmd = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-f': # or --file= hostsFilename = argv[argidx + 1] argidx += 2 elif argv[argidx].startswith('--file'): splitArg = argv[argidx].split('=') try: hostsFilename = splitArg[1] except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-n': # or --totalnum= totalnumToStart = int(argv[argidx + 1]) argidx += 2 elif argv[argidx].startswith('--totalnum'): splitArg = argv[argidx].split('=') try: totalnumToStart = int(splitArg[1]) except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx].startswith('--maxbranch'): splitArg = argv[argidx].split('=') try: maxUnderOneRoot = int(splitArg[1]) except: print 'mpdboot: invalid argument:', argv[argidx] usage() argidx += 1 elif argv[argidx] == '-d' or argv[argidx] == '--debug': debug = 1 argidx += 1 elif argv[argidx] == '-s' or argv[argidx] == '--shell': shell = 'bourne' argidx += 1 elif argv[argidx] == '-v' or argv[argidx] == '--verbose': verbose = 1 argidx += 1 elif argv[argidx] == '-c' or argv[argidx] == '--chkup': chkupIndicator = 1 argidx += 1 elif argv[argidx] == '--chkuponly': chkupIndicator = 2 argidx += 1 else: print 'mpdboot: unrecognized argument:', argv[argidx] usage() if debug: print 'debug: starting' lines = [] try: f = open(hostsFilename, 'r') for line in f: if not line or line[0] == '#': continue lines.append(line) except: print 'unable to open (or read) hostsfile %s' % (hostsFilename) exit(-1) if totalnumToStart == 0: totalnumToStart = len(lines) numRead = 0 hostsAndInfo = [] for line in lines: line = line.strip() splitLine = re.split(r'\s+', line) host = splitLine[0] ncpus = 1 # default ifhn = '' # default cons = '' # default for kv in splitLine[1:]: (k, v) = kv.split('=', 1) if k == 'ifhn': ifhn = v elif k == 'ncpus': ncpus = int(v) elif k == 'cons': cons = v else: print "unrecognized key:", k exit(-1) hostsAndInfo.append({ 'host': host, 'ifhn': ifhn, 'ncpus': ncpus, 'cons': cons }) numRead += 1 if numRead >= totalnumToStart: break if len(hostsAndInfo) < totalnumToStart: # one is local print 'totalnum=%d numhosts=%d' % (totalnumToStart, len(hostsAndInfo)) print 'there are not enough hosts on which to start all processes' exit(-1) if chkupIndicator: hostsToCheck = [hai['host'] for hai in hostsAndInfo] (upList, dnList) = chkupdn(hostsToCheck) if dnList: print "these hosts are down; exiting" print dnList exit(-1) print "there are %d hosts up" % (len(upList)) if chkupIndicator == 2: # do the chkup and quit exit(0) try: from os import sysconf maxfds = sysconf('SC_OPEN_MAX') except: maxfds = 1024 maxAtOnce = min(128, maxfds - 8) # -8 for stdout, etc. + a few more for padding fd2idx = {} hostsSeen = {} fdsToSelect = [] numStarted = 0 numStarting = 0 numUnderCurrRoot = 0 possRoots = [] currRoot = 0 idxToStart = 0 while numStarted < totalnumToStart: if numStarting < maxAtOnce and idxToStart < totalnumToStart: if numUnderCurrRoot < maxUnderOneRoot: if idxToStart == 0: entryHost = '' entryPort = '' else: entryHost = hostsAndInfo[currRoot]['host'] entryPort = hostsAndInfo[currRoot]['list_port'] hostsAndInfo[idxToStart]['entry_host'] = entryHost hostsAndInfo[idxToStart]['entry_port'] = entryPort if entryHost: entryHost = '-h ' + entryHost entryPort = '-p ' + str(entryPort) ifhn = hostsAndInfo[idxToStart]['ifhn'] ncpus = hostsAndInfo[idxToStart]['ncpus'] cons = hostsAndInfo[idxToStart]['cons'] if ifhn: ifhn = '--ifhn=%s' % (ifhn) if ncpus: ncpus = '--ncpus=%s' % (ncpus) if cons == 'n': cons = '-n' mpdArgs = '%s %s %s %s %s ' % (cons, entryHost, entryPort, ifhn, ncpus) if tmpdir: mpdArgs += ' --tmpdir=%s' % (tmpdir) (mpdPID, mpdFD) = launch_one_mpd(idxToStart, currRoot, mpdArgs, hostsAndInfo) hostsAndInfo[idxToStart]['pid'] = mpdPID hostsSeen[hostsAndInfo[idxToStart]['host']] = 1 fd2idx[mpdFD] = idxToStart if idxToStart == 0: handle_mpd_output(mpdFD, fd2idx, hostsAndInfo) numStarted += 1 else: numUnderCurrRoot += 1 fdsToSelect.append(mpdFD) numStarting += 1 idxToStart += 1 else: if possRoots: currRoot = possRoots.pop() numUnderCurrRoot = 0 selectTime = 0.01 else: selectTime = 0.1 try: (readyFDs, unused1, unused2) = select(fdsToSelect, [], [], selectTime) except error, errmsg: mpd_print(1, 'mpdboot: select failed: errmsg=:%s:' % (errmsg)) exit(-1) for fd in readyFDs: handle_mpd_output(fd, fd2idx, hostsAndInfo) numStarted += 1 numStarting -= 1 possRoots.append(fd2idx[fd]) fdsToSelect.remove(fd) fd.close()
def parseParams(): ''' parse arguments from cmdline(optparse) or web(form). :return: opmode(String), configuration(dict), entry(dict) ''' parser = optparse.OptionParser(description="PassWebTool - a stupid idea") parser.add_option('-m', '--mode', action="store", dest="mode", help="opmode: [list|get|edit|save]") parser.add_option('-c', action="store", dest="cfgfile", help="PassWebTool keepass config [default:%default]", default="../etc/pwt.ini") # parser.add_option('-p', action="store", dest="kppass", help="KeePass: Password [default:********]", default="PassWebTool") parser.add_option('-v', action="store_true", dest="verbose", help="enable logging") parser.add_option('-I', '--pwid', action="store", dest="pwid", help="Criteria: pwid (PassWordIDentification)") parser.add_option('-H', '--host', action="store", dest="host", help="Criteria: host-name") parser.add_option('-S', '--service', action="store", dest="service", help="Criteria: service-name") parser.add_option('-U', '--user', action="store", dest="username", help="Criteria: username") parser.add_option('-P', '--pass', action="store", dest="password", help="Criteria: password") parser.add_option('-N', '--notes', action="store", dest="notes", help="Criteria: notes") parser.add_option('-D', '--delete', action="store_true", dest="delete", help="remove entry (req. --pwid only)") form = cgi.FieldStorage() options, args = parser.parse_args() configfile = options.cfgfile if environ.has_key('cfgfile'): configfile = environ['cfgfile'] try: cfgfile = ConfigParser() cfgfile.read(configfile) logfile = cfgfile.get("PassWebTool", "logfile") logverb = logging.INFO - 10 * cfgfile.getboolean( "PassWebTool", "verbose") c = { 'kpfile': cfgfile.get("KeePass", "file"), 'kppass': cfgfile.get("KeePass", "pass"), 'kpgroup': cfgfile.get("KeePass", "new_folder"), 'delay_answer': int(cfgfile.get("PassWebTool", "delay_answer")) / 1000, 'pwid_length': int(cfgfile.get("PassWebTool", "pwid_length")) } except Exception, e: raise PassWebToolException("Error while parsing cfgfile: " + str(e))
# This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from os import environ if (not environ.has_key("DISPLAY")): raise ImportError, "DISPLAY environment variable not set" import sys, string, commands import pygtk pygtk.require('2.0') import gtk, gobject PACKAGE = "pyxmlsec-demo" ntb = tview_exec = tview_src = None class Gadget:
import xdg.BaseDirectory from os.path import join, isdir, realpath from os import mkdir from os.path import join, isdir, realpath from os import mkdir import xdg.BaseDirectory CACHE_DIR = realpath(join(xdg.BaseDirectory.xdg_cache_home, "gwibber")) if not isdir(CACHE_DIR): mkdir(CACHE_DIR) from os import environ if environ.has_key("FB_APP_KEY"): FB_APP_KEY = environ["FB_APP_KEY"] else: FB_APP_KEY = "71b85c6d8cb5bbb9f1a3f8bbdcdd4b05" TWITTER_OAUTH_KEY = "VDOuA5qCJ1XhjaSa4pl76g" TWITTER_OAUTH_SECRET = "BqHlB8sMz5FhZmmFimwgiIdB0RiBr72Y0bio49IVJM" # Gwibber MAX_MESSAGE_LENGTH = 140 MAX_MESSAGE_COUNT = 20000 cache_dir = realpath(join(xdg.BaseDirectory.xdg_cache_home, "gwibber")) config_dir = realpath(join(xdg.BaseDirectory.xdg_config_home, "gwibber")) SQLITE_DB_FILENAME = "%s/gwibber.sqlite" % config_dir if not isdir(cache_dir): mkdir(cache_dir) if not isdir(config_dir): mkdir(config_dir)
def mpdlistjobs(): mpd_set_my_id('mpdlistjobs_') username = mpd_get_my_username() uname = '' jobid = '' sjobid = '' jobalias = '' sssPrintFormat = 0 if len(argv) > 1: aidx = 1 while aidx < len(argv): if argv[aidx] == '-h' or argv[aidx] == '--help': usage() if argv[aidx] == '-u': # or --user= uname = argv[aidx + 1] aidx += 2 elif argv[aidx].startswith('--user'): splitArg = argv[aidx].split('=') try: uname = splitArg[1] except: print 'mpdlistjobs: invalid argument:', argv[aidx] usage() aidx += 1 elif argv[aidx] == '-j': # or --jobid= jobid = argv[aidx + 1] aidx += 2 sjobid = jobid.split('@') # jobnum and originating host elif argv[aidx].startswith('--jobid'): splitArg = argv[aidx].split('=') try: jobid = splitArg[1] sjobid = jobid.split('@') # jobnum and originating host except: print 'mpdlistjobs: invalid argument:', argv[aidx] usage() aidx += 1 elif argv[aidx] == '-a': # or --alias= jobalias = argv[aidx + 1] aidx += 2 elif argv[aidx].startswith('--alias'): splitArg = argv[aidx].split('=') try: jobalias = splitArg[1] except: print 'mpdlistjobs: invalid argument:', argv[aidx] usage() aidx += 1 elif argv[aidx] == '--sss': sssPrintFormat = 1 aidx += 1 else: print 'unrecognized arg: %s' % argv[aidx] exit(-1) if environ.has_key('UNIX_SOCKET'): conFD = int(environ['UNIX_SOCKET']) conSocket = fromfd(conFD, AF_UNIX, SOCK_STREAM) close(conFD) else: if environ.has_key('MPD_CON_EXT'): conExt = '_' + environ['MPD_CON_EXT'] else: conExt = '' consoleName = '/tmp/mpd2.console_' + username + conExt conSocket = socket(AF_UNIX, SOCK_STREAM) # note: UNIX socket try: conSocket.connect(consoleName) except Exception, errmsg: print 'mpdlistjobs: cannot connect to local mpd (%s); possible causes:' % consoleName print ' 1. no mpd running on this host' print ' 2. mpd is running but was started without a "console" (-n option)' print 'you can start an mpd with the "mpd" command; to get help, run:' print ' mpd -h' exit(-1) msgToSend = 'realusername=%s\n' % username mpd_send_one_line(conSocket, msgToSend)