ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/report.py
(Generate patch)

Comparing COMP/CRAB/python/report.py (file contents):
Revision 1.1 by corvo, Wed Dec 14 17:08:44 2005 UTC vs.
Revision 1.7 by spiga, Tue May 19 12:06:03 2009 UTC

# Line 1 | Line 1
1 < #!/usr/bin/python
2 <
3 < """
4 < This is a simple test program for the 'apmon' Python module.
5 <
6 < """
7 <
8 < import apmon
9 < import time, sys, os
10 <
11 < apmonInstance = None
12 < def getApmonInstance() :
13 <    global apmonInstance
14 <    if apmonInstance is None :
15 <        #apmonUrl = 'http://monalisa.cern.ch/ARDA/apmon.cms'
16 <        apmonUrl = ('192.91.245.5:58884',)
17 <        logger("ApmReport: Creating ApMon with " + `apmonUrl`)
18 <        apmonInstance = apmon.ApMon(apmonUrl)
19 <    return apmonInstance
20 <
21 < def getParamValues(lines, retDict=None) :
22 <    readAll = False
23 <    if retDict is None :
24 <        retDict = {}
25 <        readAll = True
26 <    elif retDict == {} :
27 <        readAll = True
28 <    for line in lines :
29 <        line = line.strip()
30 <        if line.find('=') != -1 :
31 <            split = line.split('=')
32 <            if len(split) > 2 :
33 <                split = [split[0], '='.join(split[1:])]
34 <            split = [x.strip() for x in split]
35 <            if readAll or split[0] in retDict.keys() :
36 <                retDict[split[0]] = split[1]
37 <    return retDict
38 <
39 < def readFileContent(fileName) :
40 <    lines = None
41 <    if os.path.exists(fileName) :
42 <        fh = open(fileName, 'r')
43 <        lines = fh.readlines()
44 <        fh.close()
45 <    return lines
46 <
47 < def readParamValues(fileNameArr, retDict=None) :
48 <    for fileName in fileNameArr :
49 <        lines = readFileContent(fileName)
50 <        if lines is not None :
51 <            return getParamValues(lines, retDict)
52 <    return retDict
53 <
54 < def readTaskIdFile(filename='TASK_ID') :
55 <    taskId = None
56 <    taskIdFile = readFileContent(filename)
57 <    if taskIdFile is not None and len(taskIdFile) > 0 :
58 <        taskId = taskIdFile[0].strip()
59 <    return taskId
60 <
61 < def logger(msg) :
62 <    msg = `msg`
63 <    if not msg.endswith('\n') :
64 <        msg = msg + '\n'
65 <    fh = open('report.log','a')
66 <    fh.write(msg)
67 <    fh.close
68 <    #print msg
69 <
70 < def getJobID(id, jobId='UNKNOWN') :
71 <    if id.find('.') != -1 :
72 <        split = id.split('.')
73 <        if split[0].find('_') :
74 <            jobId = split[0].split('_')[-1]
75 <        elif len(split[0]) >= 6 :
76 <            jobId = split[0][-6:]
77 <        else :
78 <            jobId = split[0]
79 <    return jobId
80 <
81 < def mlSend(task, job, paramDict) :
82 <    apm = getApmonInstance()
83 <    #logger("ApmReport: Destinations:", apm.destinations)
84 <    logger("ApmReport: Sending:"+`task`+":"+`job`+":"+`paramDict`)
85 <    apm.sendParameters(task, job, paramDict)
86 <
87 < ##
88 < ## MAIN PROGRAM
89 < ##
90 < if __name__ == '__main__' :
91 <    # Default file names and initial values
92 <    mlConfigFileArr = ['MonalisaParameters', '.orcarc']
93 < #    mlDefaultDict = { 'SyncGridName' : os.popen("grid-proxy-info -identity") ,
94 < #                      'SyncGridJobId' : os.environ['EDG_WL_JOBID'] }
95 <    mlDefaultDict = { 'SyncGridName' : 'gigio',
96 <                      'SyncGridJobId' : 'pippo' }
97 <
98 <    args = sys.argv[1:]
99 <
100 <    # Read values from file(s) and cmdline
101 <    mlDict = readParamValues(mlConfigFileArr, mlDefaultDict)
102 <    paramDict = getParamValues(args)
103 <    if len(paramDict) == 0 :
104 <        sys.exit(0)
105 <    # Report
106 <    mlSend(mlDict['SyncGridName'], mlDict['SyncGridJobId'], paramDict)
107 <
108 <    # Exit
109 <    sys.exit(0)
1 > #!/usr/bin/env python
2 >        
3 > ##
4 > ## MAIN PROGRAM
5 > ##
6 >
7 > import getopt,sys
8 > from DashboardAPI import report
9 >
10 > if __name__ == '__main__' :
11 >    try:
12 >        opts, args = getopt.getopt(sys.argv[1:], "f:")
13 >    except getopt.GetoptError:
14 >        # print help information and exit:
15 >        print "Unknown option"
16 >        sys.exit(1)
17 >    if len( opts)==1 :
18 >        copt=opts[0]
19 >        filename=copt[1]
20 >        try:
21 >            rfile=open(filename)
22 >        except IOError, ex:
23 >            print "Can not open input file"
24 >            sys.exit(1)
25 >        lines=rfile.readlines()
26 >        for line in lines :
27 >           args.append(line.strip())
28 > #        print args
29 > #        print "********************"
30 >    if len(args)>0 :
31 >         argstring=' '.join(args)
32 >         mytmp=argstring.split('=')
33 >         mystring=''
34 >         newkey=''
35 >         if len(mytmp)>0 :
36 >          for i in range(0, len(mytmp)-1):
37 >              mytmp[i]=mytmp[i].strip()
38 >              mytmp[i+1]=mytmp[i+1].strip()
39 >              if  newkey=='':
40 >                  ckey=mytmp[i]
41 >              else :
42 >                  ckey=newkey
43 >              if i< len(mytmp)-2 :  
44 >                  cvalue=' '.join(mytmp[i+1].split(' ')[:-1])+","
45 >              else:
46 >                  cvalue= mytmp[-1]    
47 >              newkey=mytmp[i+1].split(' ')[-1]
48 >              mystring=mystring+ckey.replace(" ",'')+"="+cvalue
49 >          args=mystring.split(',')  
50 >    report(args)
51 > #    print "***"
52 > #    print opts
53 > #    print "###"
54 > #    print args
55 >    sys.exit(0)
56 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines