~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to madgraph/various/misc.py

  • Committer: olivier Mattelaer
  • Date: 2015-03-05 00:14:16 UTC
  • mfrom: (258.1.9 2.3)
  • mto: (258.8.1 2.3)
  • mto: This revision was merged to the branch mainline in revision 259.
  • Revision ID: olivier.mattelaer@uclouvain.be-20150305001416-y9mzeykfzwnl9t0j
partial merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
239
239
                    wait_once = True
240
240
                    time.sleep(sleep * (i+1))
241
241
 
 
242
            if __debug__:
 
243
                raise
242
244
            raise error.__class__, '[Fail %i times] \n %s ' % (i+1, error)
243
245
        return deco_f_retry
244
246
    return deco_retry
919
921
 
920
922
def sprint(*args, **opt):
921
923
    """Returns the current line number in our program."""
 
924
    
 
925
    if not __debug__:
 
926
        return
 
927
    
922
928
    import inspect
923
929
    if opt.has_key('log'):
924
930
        log = opt['log']
928
934
        level = opt['level']
929
935
    else:
930
936
        level = logging.getLogger('madgraph').level
931
 
        if level == 20:
932
 
            level = 10 #avoid info level
 
937
        #print  "madgraph level",level
 
938
        #if level == 20:
 
939
        #    level = 10 #avoid info level
 
940
        #print "use", level
933
941
    lineno  =  inspect.currentframe().f_back.f_lineno
934
942
    fargs =  inspect.getframeinfo(inspect.currentframe().f_back)
935
943
    filename, lineno = fargs[:2]
936
944
    #file = inspect.currentframe().f_back.co_filename
937
945
    #print type(file)
938
 
 
939
 
 
940
 
    log.log(level, ' '.join([str(a) for a in args]) + \
941
 
               '\nraised at %s at line %s ' % (filename, lineno))
 
946
    try:
 
947
        source = inspect.getsourcelines(inspect.currentframe().f_back)
 
948
        line = source[0][lineno-source[1]]
 
949
        line = re.findall(r"misc\.sprint\(\s*(.*)\)\s*($|#)", line)[0][0]
 
950
        if line.startswith("'") and line.endswith("'") and line.count(",") ==0:
 
951
            line= ''
 
952
        elif line.startswith("\"") and line.endswith("\"") and line.count(",") ==0:
 
953
            line= ''
 
954
        elif line.startswith(("\"","'")) and len(args)==1 and "%" in line:
 
955
            line= ''        
 
956
    except Exception:
 
957
        line=''
 
958
 
 
959
    if line:
 
960
        intro = ' %s = \033[0m' % line
 
961
    else:
 
962
        intro = ''
942
963
    
 
964
 
 
965
    log.log(level, ' '.join([intro]+[str(a) for a in args]) + \
 
966
                   ' \033[1;30m[%s at line %s]\033[0m' % (os.path.basename(filename), lineno))
943
967
    return 
944
968
 
945
969
################################################################################