web_server.py 2.3 KB
Newer Older
1
2
3
4
5
import os
import sys  
from flask import Flask
from pykat.testing import utils

6
def start(instance_path,port=5000, debug=True, ip="0.0.0.0"):
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    global app
    
    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    
    
23
    if(app.instance_path!=instance_path):
24
	print app.instance_path, instance_path
25
26
        raise Exception("Instance path of Flask app didn't match the requested value")
        
27
28
29
30
    # load up the actual interface code
    import pykat.testing.web.web_interface
    
    # need local copy of src
31
    if not os.path.exists(os.path.join(app.instance_path,"finesse_src")):
32
        print "finesse src folder didn't exist, cloning now..."
33
        utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/src.git","finesse_src"])
34
    else:
35
        os.chdir(os.path.join(app.instance_path,"finesse_src"))
36
        # get the latest version for logs etc.
37
        utils.git("pull")
38
39
        
    # need local copy of test
40
    if not os.path.exists(os.path.join(app.instance_path,"finesse_test")):
41
        print "finesse test folder didn't exist, cloning now..."
42
        utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/test.git","finesse_test"])
43
44
    
    app.secret_key = os.urandom(24)
45
    app.run(debug=debug, port=int(port), host=ip)
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

if __name__ == "__main__":
    n = len(sys.argv)
    
    if n != 2 and n != 3:
        print """
Command starts a Flask based website on which allows
users to manage the FINESSE test builds.
        
start_test_server usage:

    python -m pykat.testing.web_server <server_path> <port>

    Arguments:
        server_path: Directory where website should be run from
        port:        TCP port which the server should run under
                     default is port 5000.
"""
        exit()
        
    instance_path = sys.argv[1]
    
    if n == 3:
        port = sys.argv[2]
    else:
        port = 5000
    
    start(instance_path, port=port)
74
75
76
77