source: geniuswebcore/geniusweb/simplerunner/NegoRunner.py@ 100

Last change on this file since 100 was 100, checked in by ruud, 19 months ago

python installs also wheel to avoid error messages

File size: 2.7 KB
Line 
1import json
2import logging
3from pathlib import Path
4import sys
5import time
6import traceback
7from typing import List, Optional
8
9from pyson.ObjectMapper import ObjectMapper
10from tudelft.utilities.listener.Listener import Listener
11from tudelft_utilities_logging.Reporter import Reporter
12
13from geniusweb.events.ProtocolEvent import ProtocolEvent
14from geniusweb.protocol.CurrentNegoState import CurrentNegoState
15from geniusweb.protocol.NegoProtocol import NegoProtocol
16from geniusweb.protocol.NegoSettings import NegoSettings
17from geniusweb.protocol.NegoState import NegoState
18from geniusweb.simplerunner.ClassPathConnectionFactory import ClassPathConnectionFactory
19from geniusweb.simplerunner.Runner import Runner
20from geniusweb.simplerunner.gui.GUI import GUI
21
22
23class StdOutReporter (Reporter):
24
25 def log(self, level:int , msg:str, exc:Optional[BaseException]=None):
26 if level >= logging.WARNING:
27 print(logging.getLevelName(level) + ":" + msg, file=sys.stderr)
28 else:
29 print(logging.getLevelName(level) + ":" + msg)
30
31
32class NegoRunner:
33 '''
34 A simple tool to run a negotiation stand-alone, without starting the servers.
35 All referred files and classes need to be stored locally (or be in the
36 dependency list if you use maven).
37 <p>
38 <em>IMPORTANT</em> SimpleRunner has a number of restrictions, compared to a
39 run using a runserver and partyserver
40 <ul>
41 <li>With stand-alone runner, your parties are run together in a single
42 classloader. The main implication is that there may arise version conflicts
43 between parties.
44 <li>Stand-alone runner does NOT enforce the time deadline. Parties may
45 continue running indefinitely and thus bog down the JVM and stalling
46 tournaments.
47 </ul>
48 '''
49
50 @staticmethod
51 def main(args:List[str]):
52 '''
53 The main runner
54
55 @param args should have 0 or 1 argument. If 0 arguments, the {@link GUI}
56 is started. If one argoment, it should be a filename
57 containing a settings.json file. That session is then run.
58 @throws IOException if problem occurs
59 '''
60 if len(args) == 0:
61 GUI.main([])
62 return
63
64 if len(args) != 1:
65 NegoRunner.showusage()
66 return;
67
68 serialized = Path(args[0]).read_text("utf-8")
69 settings:NegoSettings = ObjectMapper().parse(json.loads(serialized),
70 NegoSettings) # type:ignore
71
72 runner = Runner(settings,
73 ClassPathConnectionFactory(), StdOutReporter(), 0)
74 runner.run()
75
76 @staticmethod
77 def showusage():
78 print("GeniusWeb stand-alone runner.")
79 print("first argument should be <settings.json>.")
80 print("The settings.json file should contain the NegoSettings.")
81 print("See the settings.json example file and the GeniusWeb wiki pages. ")
82
83
84if __name__ == '__main__':
85 NegoRunner.main(sys.argv[1:])
86
Note: See TracBrowser for help on using the repository browser.