12 """Extension of DesktopService for SPD."""
15 super(SPDDesktopService, self).__init__(
"")
19 def __create_json(self, pddl_input_program):
20 """Returns a json object representing InputProgram."""
24 for ip
in pddl_input_program:
25 if not isinstance(ip, PDDLInputProgram):
28 pType = pip.get_programs_type()
30 if pType
is PDDLProgramType.DOMAIN:
31 domain += str(pip.get_programs()) + str(pip.get_separator())
34 elif pType
is PDDLProgramType.PROBLEM:
35 problem += str(pip.get_programs()) + str(pip.get_separator())
39 raise (
"Program type : " +
40 pip.get_programs_type() +
" not valid.")
43 raise "Problem file not specified"
45 raise "Domain file not specified"
47 data = {
"problem": problem,
"domain": domain}
49 json_data = json.dumps(data)
53 def __get_from_file(self, files_paths, separator):
54 """Reads files from given paths and returns their content separated
55 by given string separator ."""
60 to_return += separator
65 def __post_json_to_url(self, js):
66 """Posts a json string given to SPD solver server and returns result."""
68 if sys.version_info < (3, 0):
70 connection = httplib.HTTPConnection(
74 connection = http.client.HTTPConnection(
77 headers = {
'Content-type':
'application/json'}
81 response = connection.getresponse()
83 if response.status == 200:
84 result = response.read().decode()
86 raise PDDLException(
"HTTP connection error, response code : " + str(
87 response.status) +
" response message : " + str(response.reason))
96 """Reads file from given path and returns its content."""
98 with open(s,
'r')
as f:
100 everything = f.read()
105 def _get_output(self, output, error):
106 """Returns SPDPlan object from given output and error strings."""
109 def start_sync(self, programs, options):
110 """Return SPDPlan object representing output generated from SPD solver
113 return self.
_get_output(
"",
"PDDLInputProgram not defined")
117 except Exception
as e: