pddl_file.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 import sys
00005 import os.path
00006 import re
00007 
00008 import parser
00009 
00010 import tasks
00011 
00012 def parse_pddl_file(type, filename):
00013   try:
00014     return parser.parse_nested_list(file(filename))
00015   except IOError, e:
00016     raise SystemExit("Error: Could not read file: %s\nReason: %s." %
00017                      (e.filename, e))
00018   except parser.ParseError, e:
00019     raise SystemExit("Error: Could not parse %s file: %s\n" % (type, filename))
00020 
00021 def open(task_filename=None, domain_filename=None):
00022   if task_filename is None:
00023     if len(sys.argv) not in (2, 3):
00024       raise SystemExit("Error: Need exactly one or two command line arguments.\n"
00025                        "Usage: %s [<domain.pddl>] <task.pddl>" % sys.argv[0])
00026 
00027     task_filename = sys.argv[-1]
00028     if len(sys.argv) == 3:
00029       domain_filename = sys.argv[1]
00030 
00031   if not domain_filename:
00032     dirname, basename = os.path.split(task_filename)
00033     domain_filename = os.path.join(dirname, "domain.pddl")
00034     if not os.path.exists(domain_filename) and re.match(r"p[0-9][0-9]\b", basename):
00035       domain_filename = os.path.join(dirname, basename[:4] + "domain.pddl")
00036     if not os.path.exists(domain_filename) and re.match(r"p[0-9][0-9]\b", basename):
00037       domain_filename = os.path.join(dirname, basename[:3] + "-domain.pddl")
00038     if not os.path.exists(domain_filename):
00039       raise SystemExit("Error: Could not find domain file using "
00040                        "automatic naming rules.")
00041 
00042   domain_pddl = parse_pddl_file("domain", domain_filename)
00043   task_pddl = parse_pddl_file("task", task_filename)
00044   return tasks.Task.parse(domain_pddl, task_pddl)
00045 
00046 if __name__ == "__main__":
00047   open().dump()


tfd_modules
Author(s): Maintained by Christian Dornhege (see AUTHORS file).
autogenerated on Mon Oct 6 2014 07:52:06