web_server.py 2.42 KB
Newer Older
1
2
3
import os
import sys  
from flask import Flask
4
from optparse import OptionParser
5

6
def start(instance_path,port=5000, debug=True, ip="0.0.0.0", git_bin="/usr/bin/git"):
7
8
9
10
        
    os.environ["GIT_BIN"] = git_bin
    # we import this now so that we can set the GIT_BIN env var
    from pykat.testing import utils
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    
    print "starting web server..."
    
    if instance_path is None:
        raise Exception("instance_path must be defined")
    elif type(instance_path) is not str:
        raise Exception("instance_path must be a string")
        
    if not os.path.exists(instance_path):
        os.mkdir(instance_path)
        
    os.chdir(instance_path)
    
    from pykat.testing.web import app    
    
26
    if(app.instance_path!=instance_path):
27
	print app.instance_path, instance_path
28
        raise Exception("Instance path of Flask app didn't match the requested value")
Daniel Brown's avatar
Daniel Brown committed
29
    
Daniel Brown's avatar
Daniel Brown committed
30
31
    os.chdir(instance_path)    
    
32
    # need local copy of src
33
    if not os.path.exists(os.path.join(app.instance_path,"finesse_src")):
34
        print "finesse src folder didn't exist, cloning now..."
35
        utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/finesse.git","finesse_src"])
36
37
    else:
        # get the latest version for logs etc.
Daniel Brown's avatar
Daniel Brown committed
38
        utils.git("pull", cwd=os.path.join(app.instance_path,"finesse_src"))
Daniel Brown's avatar
Daniel Brown committed
39
40
41
     
    os.chdir(instance_path)
    
42
    # need local copy of test
43
    if not os.path.exists(os.path.join(app.instance_path,"finesse_test")):
44
        print "finesse test folder didn't exist, cloning now..."
Daniel Brown's avatar
Daniel Brown committed
45
        utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/test.git","finesse_test"])
46
    
47
48
49
    # load up the actual interface code
    import pykat.testing.web.web_interface
    
50
    app.secret_key = os.urandom(24)
51
    app.run(debug=debug, port=int(port), host=ip,use_reloader=False)
52
53
54

if __name__ == "__main__":
    
55
    parser = OptionParser()
56
    
57
58
59
    parser.add_option("-P","--path",type="string",dest="instance_path",help="")
    parser.add_option("-p","--port",type="int",default=5000,dest="port",help="")
    parser.add_option("-g","--git-bin",type="string",default="/usr/bin/git",dest="git_bin",help="")
60
    
61
62
63
64
65
    options, args = parser.parse_args()
    
    if options.instance_path is None:
        print "Must specify a path for the web server"
        exit()
66
    
67
    start(options.instance_path, port=options.port, git_bin=options.git_bin )