1 | #!/usr/bin/env python
|
---|
2 | #
|
---|
3 | # Copyright (c) 2010 Corey Goldberg (corey@goldb.org)
|
---|
4 | # License: GNU LGPLv3
|
---|
5 | #
|
---|
6 | # This file is part of Multi-Mechanize
|
---|
7 |
|
---|
8 |
|
---|
9 | import SimpleXMLRPCServer
|
---|
10 | import socket
|
---|
11 | import thread
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | def launch_rpc_server(port, project_name, run_callback):
|
---|
16 | host = socket.gethostbyaddr(socket.gethostname())[0]
|
---|
17 | server = SimpleXMLRPCServer.SimpleXMLRPCServer((host, 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' % (host, port)
|
---|
21 | print 'waiting for xml-rpc commands...\n'
|
---|
22 | try:
|
---|
23 | server.serve_forever()
|
---|
24 | except KeyboardInterrupt:
|
---|
25 | pass
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | class 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()
|
---|