~mars/tarmac/throwaway-merge-source

« back to all changes in this revision

Viewing changes to webui.py

  • Committer: Paul Hummer
  • Date: 2009-07-11 04:18:18 UTC
  • mfrom: (131 tarmac)
  • mto: This revision was merged to the branch mainline in revision 132.
  • Revision ID: paul@eventuallyanyway.com-20090711041818-jirjz6ert780jcx9
Merge from trunk, resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# This file is part of Tarmac.
 
3
#
 
4
# Tarmac is free software: you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License version 3 as
 
6
# published by
 
7
# the Free Software Foundation.
 
8
#
 
9
# Tarmac is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with Tarmac.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
# Copyright 2009 Elliot Murphy
 
18
"""Simple WSGI web application for showing the current Tarmac status."""
 
19
 
 
20
import sys
 
21
import subprocess
 
22
from tarmac.config import TarmacConfig
 
23
import web
 
24
 
 
25
urls = (
 
26
    '/', 'index'
 
27
)
 
28
 
 
29
render = web.template.render('templates/')
 
30
 
 
31
class index(object):
 
32
    """The main page of the status site."""
 
33
 
 
34
    def GET(self):
 
35
        # XXX I cannot figure out how to make the config object from main
 
36
        # available here.
 
37
        # statusfile = config.log_file
 
38
        from tarmac.config import TarmacConfig
 
39
        statusfile = TarmacConfig(sys.argv[2]).log_file
 
40
        print statusfile
 
41
        tail = subprocess.Popen(('tail', '-n40', statusfile),
 
42
            stdout = subprocess.PIPE,
 
43
            stderr = subprocess.PIPE)
 
44
        output, errput = tail.communicate()
 
45
        return render.index(output, errput)
 
46
 
 
47
 
 
48
def main():
 
49
    if len(sys.argv) != 3:
 
50
        print "Please specify a port number and a project name: ./webui.py 8080 default"
 
51
        return 1
 
52
    projectname = sys.argv[2]
 
53
    config = TarmacConfig(projectname)
 
54
    app = web.application(urls, globals())
 
55
    return app.run()
 
56
 
 
57
 
 
58
if __name__ == "__main__":
 
59
    sys.exit(main())