def player_query_file(name, baseurl, authstr, network): ''' Query Content Manager for an existing Player object by name. Arguments: name Player name, must be enabled in CM. baseurl Base URL to Content Manager authstr "user:pwd" Player (not webservice) credential string. network CM network. Returns: Player Object on success. None on failure. ''' import xml.etree.ElementTree as et url = join(baseurl, 'data/webdav', network, 'redirect.xml') url = url.replace('\\', '/') user, pwd = authstr.split(':', 1) filename = 'player_list.xml' try: st.grab_url(url, filename=filename, username=user, password=pwd) filename = st.find_file(filename) except Exception, e: _log.critical('Unable to retrieve player details from CM. ' + str(e)) sys.exit(_ERR_MISC)
def import_mod(name): ''' Search for a module, import, and return if found. Argument: name - The name of a module to search for, using scalatools.find_file(). Returns: A python module object. Raises ImportError if not found. Example: from scalalib import import_mod mymod = import_mod('mymod') # .py not necessary ''' if not name: raise ValueError, 'name must not be blank.' try: return sys.modules[name] except KeyError: import imp import scalatools as st name = os.path.splitext(name)[0] # remove any extension # search for the file try: modpath = st.find_file('%s.pyc' % name) except IOError: try: modpath = st.find_file('%s.py' % name) except IOError: errstr = '"%s" not found.' % name _log_report(errstr) raise ImportError, errstr _log.info('"%s" as "%s"' % (modpath, name)) if modpath.lower().endswith('.pyc'): try: # module could be from an old version of python return imp.load_compiled(name, modpath) except ImportError: # try again with .py return imp.load_source(name, modpath[:-1]) elif modpath.lower().endswith('.py'): return imp.load_source(name, modpath)
def import_mod(name): ''' Search for a module, import, and return if found. Argument: name - The name of a module to search for, using scalatools.find_file(). Returns: A python module object. Raises ImportError if not found. Example: from scalalib import import_mod mymod = import_mod('mymod') # .py not necessary ''' if not name: raise ValueError, 'name must not be blank.' try: return sys.modules[name] except KeyError: import imp import scalatools as st name = os.path.splitext(name)[0] # remove any extension # search for the file try: modpath = st.find_file('%s.pyc' % name) except IOError: try: modpath = st.find_file('%s.py' % name) except IOError: errstr = '"%s" not found.' % name _log_report(errstr) raise ImportError, errstr _log.info('"%s" as "%s"' % (modpath, name) ) if modpath.lower().endswith('.pyc'): try: # module could be from an old version of python return imp.load_compiled(name, modpath) except ImportError: # try again with .py return imp.load_source(name, modpath[:-1]) elif modpath.lower().endswith('.py'): return imp.load_source(name, modpath)
def checkFile(file, type=None): if type == "dados": try: st.find_file(file) tmpCkFile = st.file_is_current(file, minutes=svars.validade) if not tmpCkFile: sl.log_external('Arquivo "' + file + '" fora da data de validade.') svars.ckFile = 'invalido' quit() else: svars.ckFile = 'valido' except: sl.log_external('Arquivo "' + file + '" invalido ou nao encontrado.') svars.ckFile = 'invalido' quit() elif type == "foto": try: st.find_file(file) svars.ckFoto = "valida" except: sl.log_external("Nao foi possivel encontrar a imagem: " + file) svars.ckFoto = "invalida"