Exemple #1
0
    def read_template_file(self, filename, debug=False):
        """Attemp to read in template file

        If we can't find the template file immediately then search for it in
        the default template directory, if it's not there raise an Error

        Args:
            filename (string): Path to the template file

        Return:
            Nothing

        Raises:
            ProjectGeneratorError:
                Unable to find the template.json file
                Error while loading the template.json file
        """
        if not filename.endswith(".json"):
            filename = "%s.json" % filename
        if not os.path.exists(filename):
            test_path = os.path.join(utils.get_nysa_base(), "ibuilder",
                                     "templates", filename)
            if os.path.exists(test_path):
                filename = test_path
            else:
                if self.s:
                    self.s.Fatal("Can't find template file at: %s" %
                                 (filename))
                raise PGE("Can't find template file at: %s" % (filename))
        try:
            if self.s: self.s.Verbose("Loading template file: %s" % filename)
            self.template_tags = json.load(open(filename, "r"))
        except IOError as err:
            if self.s:
                self.s.Fatal("Error while loading the template tags: %s" %
                             str(err))
            raise PGE("Error while loading the template tags: %s" % str(err))
        except TypeError as err:
            if self.s:
                self.s.Fatal(
                    "Error reading the tags in the template file: %s" %
                    str(err))
            raise PGE("Error reading the tags in the template file: %s" %
                      str(err))
        except ValueError as err:
            if self.s:
                self.s.Fatal("Error parsing JSON in template file: %s" %
                             str(err))
            raise PGE("Error parsing JSON in template file: %s" % str(err))

        #Fix all paths to be compatible with the OS and
        #Replace all "${NYSA}" with a
        #print "Replace NYSA name with real paths"
        utils.recursive_dict_name_fix(self.template_tags)
 def gen_script(self, tags={}, buf="", user_paths=[], debug=False):
     template = Template(buf)
     #Find out if cocotb is installed on the system
     #TODO: Incorporate command line options to allow the user to specify
     #the location of cocotb
     cocotb_base = cocotb_utils.find_cocotb_base()
     #Find out where the Xilinx toolchain is located
     xilinx_base = xilinx_utils.find_xilinx_path()
     #Find out what simulation files are to be included
     #Get a reference to the base Nysa Class
     base = utils.get_nysa_base()
     buf = template.safe_substitute(COCOTB=cocotb_base,
                                    XILINX=xilinx_base,
                                    NYSA=base)
     return buf
 def gen_script (self, tags = {}, buf = "", user_paths = [], debug = False):
     template = Template(buf)
     #Find out if cocotb is installed on the system
     #TODO: Incorporate command line options to allow the user to specify
         #the location of cocotb
     cocotb_base = cocotb_utils.find_cocotb_base()
     #Find out where the Xilinx toolchain is located
     xilinx_base = xilinx_utils.find_xilinx_path()
     #Find out what simulation files are to be included
     #Get a reference to the base Nysa Class
     base = utils.get_nysa_base()
     buf = template.safe_substitute (COCOTB=cocotb_base,
                                     XILINX=xilinx_base,
                                     NYSA=base)
     return buf
Exemple #4
0
    def read_template_file(self, filename, debug=False):
        """Attemp to read in template file

        If we can't find the template file immediately then search for it in
        the default template directory, if it's not there raise an Error

        Args:
            filename (string): Path to the template file

        Return:
            Nothing

        Raises:
            ProjectGeneratorError:
                Unable to find the template.json file
                Error while loading the template.json file
        """
        if not filename.endswith(".json"):
            filename = "%s.json" % filename
        if not os.path.exists(filename):
            test_path = os.path.join(utils.get_nysa_base(),
                                    "ibuilder",
                                    "templates",
                                    filename)
            if os.path.exists(test_path):
                filename = test_path
            else:
                if self.s: self.s.Fatal("Can't find template file at: %s" % (filename))
                raise PGE("Can't find template file at: %s" % (filename))
        try:
            if self.s: self.s.Verbose("Loading template file: %s" % filename)
            self.template_tags = json.load(open(filename, "r"))
        except IOError as err:
            if self.s: self.s.Fatal("Error while loading the template tags: %s" % str(err))
            raise PGE("Error while loading the template tags: %s" % str(err))
        except TypeError as err:
            if self.s: self.s.Fatal("Error reading the tags in the template file: %s" % str(err))
            raise PGE("Error reading the tags in the template file: %s" % str(err))
        except ValueError as err:
            if self.s: self.s.Fatal("Error parsing JSON in template file: %s" % str(err))
            raise PGE("Error parsing JSON in template file: %s" % str(err))

        #Fix all paths to be compatible with the OS and
        #Replace all "${NYSA}" with a
        #print "Replace NYSA name with real paths"
        utils.recursive_dict_name_fix(self.template_tags)