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

6
7
8
9
10
def start(instance_path,port=5000, debug=True, ip="0.0.0.0", git_bin="/usr/bin/git"):
        
    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
29
        raise Exception("Instance path of Flask app didn't match the requested value")
        
30
31
32
33
    # load up the actual interface code
    import pykat.testing.web.web_interface
    
    # need local copy of src
34
    if not os.path.exists(os.path.join(app.instance_path,"finesse_src")):
35
        print "finesse src folder didn't exist, cloning now..."
36
        utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/src.git","finesse_src"])
37
    else:
38
        os.chdir(os.path.join(app.instance_path,"finesse_src"))
39
        # get the latest version for logs etc.
40
        utils.git("pull")
41
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..."
45
        utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/test.git","finesse_test"])
46
47
    
    app.secret_key = os.urandom(24)
48
    app.run(debug=debug, port=int(port), host=ip,use_reloader=False)
49
50
51

if __name__ == "__main__":
    
52
    parser = OptionParser()
53
    
54
55
56
    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="")
57
    
58
59
60
61
62
    options, args = parser.parse_args()
    
    if options.instance_path is None:
        print "Must specify a path for the web server"
        exit()
63
    
64
    start(options.instance_path, port=options.port, git_bin=options.git_bin )