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.6 by slacapra, Fri Mar 28 17:18:47 2008 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 <
1 > #!/usr/bin/env python
2 >        
3   ##
4   ## MAIN PROGRAM
5   ##
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:]
6  
7 <    # Read values from file(s) and cmdline
8 <    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)
7 > import getopt,sys
8 > from DashboardAPI import report
9  
10 <    # Exit
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 >    report(args)
31 > #    print "***"
32 > #    print opts
33 > #    print "###"
34 > #    print args
35      sys.exit(0)
36 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines