source: main/waeup.sirp/branches/multimechanize/trunk/multimechanize/rpcserver.py @ 7541

Last change on this file since 7541 was 7541, checked in by uli, 13 years ago

Add sources copied from current multi-mechanize GIT repos.

File size: 1.8 KB
Line 
1#!/usr/bin/env python
2#
3#  Copyright (c) 2010-2012 Corey Goldberg (corey@goldb.org)
4#  License: GNU LGPLv3
5#
6#  This file is part of Multi-Mechanize | Performance Test Framework
7#
8
9
10import SimpleXMLRPCServer
11import socket
12import thread
13
14
15
16def launch_rpc_server(bind_addr, port, project_name, run_callback):
17    server = SimpleXMLRPCServer.SimpleXMLRPCServer((bind_addr, port), logRequests=False)
18    server.register_instance(RemoteControl(project_name, run_callback))
19    server.register_introspection_functions()
20    print '\nMulti-Mechanize: %s listening on port %i' % (bind_addr, port)
21    print 'waiting for xml-rpc commands...\n'
22    try:
23        server.serve_forever()
24    except KeyboardInterrupt:
25        pass
26
27
28
29class RemoteControl(object):
30    def __init__(self, project_name, run_callback):
31        self.project_name = project_name
32        self.run_callback = run_callback
33        self.test_running = False
34        self.output_dir = None
35
36    def run_test(self):
37        if self.test_running:
38            return 'Test Already Running'
39        else:
40            thread.start_new_thread(self.run_callback, (self,))
41            return 'Test Started'
42
43    def check_test_running(self):
44        return self.test_running
45
46    def update_config(self, config):
47        with open('projects/%s/config.cfg' % self.project_name, 'w') as f:
48            f.write(config)
49            return True
50
51    def get_config(self):
52        with open('projects/%s/config.cfg' % self.project_name, 'r') as f:
53            return f.read()
54
55    def get_project_name(self):
56        return self.project_name
57
58    def get_results(self):
59        if self.output_dir is None:
60            return 'Results Not Available'
61        else:
62            with open(self.output_dir + 'results.csv', 'r') as f:
63                return f.read()
Note: See TracBrowser for help on using the repository browser.