Project

General

Profile

hellocherry.py

Dennis Box, 10/22/2013 04:45 PM

 
1
import cherrypy
2
import mako
3
import socket
4
import commands
5

    
6
class Users(object):
7
    def default(self):
8
        return "Stub for /jobsub/users"
9
    default.exposed = True
10

    
11
class Submit(object):
12
    def default(self):
13
        return "stub for /jobsub/submit"
14
    default.exposed = True
15

    
16
class Experiments(object):
17

    
18
   def index(self):
19
        rsp="<br>The following experiments are supported:"
20
        for exp in experiment_list:
21
                rsp = rsp + "<br><a href='menu/%s'>%s</a>"%( exp, exp)
22
        return rsp
23
        
24
   index.exposed = True
25

    
26

    
27

    
28

    
29
   def default(self,exp,jobs='jobs',userid=None,jobid=None):
30
        queryTmp = "condor_q -dag -pool %s -name %s -constraint 'Agroup==\"group_%s\"' %s "
31

    
32
        if jobid:
33
                query = queryTmp % ( collector, schedd, exp, jobid)
34
        elif userid:
35
                query = queryTmp % ( collector, schedd, exp, userid)
36
        else:
37
                query = queryTmp % ( collector, schedd, exp, '' )
38

    
39
        (code,rslt)=commands.getstatusoutput(query)
40
        lines=rslt.split('\n')
41
        rslt2=''
42
        for line in lines:
43
                rslt2=rslt2+'<br>'+line
44
        return rslt2
45

    
46
        #return "execute this here: %s"%query
47
   default.exposed = True
48

    
49
class ExperimentMenu(object):
50
    def index(self):
51
        return "experiment menu"
52
    index.exposed = True
53

    
54
    def default(self, exp):
55
        cmd = "condor_userprio -allusers -all -pool gpsn01.fnal.gov:9640 -l | grep %s"%exp
56
        (code,rslt)=commands.getstatusoutput(cmd)
57
        lines=rslt.split('\n')
58
        for index,item in enumerate(lines):
59
                item=item.split('=')[1]
60
                lines[index]=item
61
        rslt2=''
62
        for line in lines:
63
                rslt2=rslt2+'<br>'+line
64
        return rslt2
65
    default.exposed = True
66

    
67

    
68

    
69
class Jobsub(object):
70
    def index(self):
71
        return "<br><a href='experiments'>experiments</a><br><a href='users'>users</a><br><a href='submit'>submit</a> a job"
72
    index.exposed = True
73

    
74
class Root(object):
75
    jobsub = Jobsub()
76
    jobsub.experiments = Experiments()
77
    jobsub.experiments.menu = ExperimentMenu()
78
    #jobsub.experiments.jobs = Jobs()
79
    jobsub.users = Users()
80
    jobsub.submit = Submit()
81
    def index(self):
82
        return "This server hosts the <a href='jobsub'>jobsub</a> application"
83
    index.exposed = True
84

    
85

    
86
experiment_list = ['gm2','seaquest','argoneut','minerva','lbne','marsmu2e','marslbne','mu2e','uboone','nova','coupp','minos',]
87
collector = 'gpsn01.fnal.gov:9640'
88
schedd = 'gpsn01.fnal.gov'
89

    
90

    
91
appconf = {'/': {'tools.proxy.on':True,}
92

    
93

    
94
cherrypy.config.update({'server.socket_port': 8090,
95
                        'server.socket_host': '127.0.0.1',
96
                        'experiment_list':experiment_list,
97
                        'collector':collector,
98
                        'schedd':schedd,
99
                       })
100

    
101

    
102
cherrypy.quickstart(Root(), '/', appconf)