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

Daniel Brown's avatar
Daniel Brown committed
6
7
repo_url = "https://git.ligo.org/finesse"

8
def start(instance_path,port=5000, debug=True, ip="0.0.0.0", git_bin="/usr/bin/git"):
9
10
11
12
        
    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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    
    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    
    
28
    if(app.instance_path!=instance_path):
29
	print app.instance_path, instance_path
30
        raise Exception("Instance path of Flask app (%s) didn't match the requested value (%s)" %(app.instance_path, instance_path))
Daniel Brown's avatar
Daniel Brown committed
31
    
Daniel Brown's avatar
Daniel Brown committed
32
33
    os.chdir(instance_path)    
    
34
    # need local copy of src
35
    if not os.path.exists(os.path.join(app.instance_path,"finesse_src")):
36
        print "finesse src folder didn't exist, cloning now..."
Daniel Brown's avatar
Daniel Brown committed
37
        utils.git(["clone","%s/finesse.git"%repo_url,"finesse_src"])
38
39
    else:
        # get the latest version for logs etc.
Daniel Brown's avatar
Daniel Brown committed
40
        utils.git("pull", cwd=os.path.join(app.instance_path,"finesse_src"))
Daniel Brown's avatar
Daniel Brown committed
41
42
43
     
    os.chdir(instance_path)
    
44
    # need local copy of test
45
    if not os.path.exists(os.path.join(app.instance_path,"finesse_test")):
46
        print "finesse test folder didn't exist, cloning now..."
Daniel Brown's avatar
Daniel Brown committed
47
        utils.git(["clone","%s/test.git"%repo_url,"finesse_test"])
48
        utils.git(["config","core.sharedRepository","true"], cwd="./finesse_test/")
49
    
50
51
52
    # load up the actual interface code
    import pykat.testing.web.web_interface
    
53
    app.secret_key = os.urandom(24)
54
    app.run(debug=debug, port=int(port), host=ip,use_reloader=False)
55
56
57

if __name__ == "__main__":
    
58
    parser = OptionParser()
59
    
60
61
62
    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="")
63
    
64
65
66
67
68
    options, args = parser.parse_args()
    
    if options.instance_path is None:
        print "Must specify a path for the web server"
        exit()
69
    
70
    start(options.instance_path, port=options.port, git_bin=options.git_bin )