Пример #1
0
 def _read(self):
     if not self.path:
         return
     try:
         fp = open(self.path, "r")
     except IOError as err:
         if err.errno != errno.ENOENT:
             raise
         return
     for i, line in enumerate(util.iterfile(fp)):
         line = line.splitlines()[0].rstrip()
         if not line:
             # Ignore blank lines
             continue
         try:
             key, value = line.rsplit(" ", 1)
         except ValueError:
             raise error.Abort(
                 _("syntax error in %s(%d): key/value pair expected")
                 % (self.path, i + 1)
             )
         if key not in self:
             self.order.append(key)
         super(mapfile, self).__setitem__(key, value)
     fp.close()
Пример #2
0
    def parsesplicemap(self, path):
        """ check and validate the splicemap format and
            return a child/parents dictionary.
            Format checking has two parts.
            1. generic format which is same across all source types
            2. specific format checking which may be different for
               different source type.  This logic is implemented in
               checkrevformat function in source files like
               hg.py, subversion.py etc.
        """

        if not path:
            return {}
        m = {}
        try:
            fp = open(path, "r")
            for i, line in enumerate(util.iterfile(fp)):
                line = line.splitlines()[0].rstrip()
                if not line:
                    # Ignore blank lines
                    continue
                # split line
                lex = shlex.shlex(line, posix=True)
                lex.whitespace_split = True
                lex.whitespace += ","
                line = list(lex)
                # check number of parents
                if not (2 <= len(line) <= 3):
                    raise error.Abort(
                        _("syntax error in %s(%d): child parent1"
                          "[,parent2] expected") % (path, i + 1))
                for part in line:
                    self.source.checkrevformat(part)
                child, p1, p2 = line[0], line[1:2], line[2:]
                if p1 == p2:
                    m[child] = p1
                else:
                    m[child] = p1 + p2
        # if file does not exist or error reading, exit
        except IOError:
            raise error.Abort(
                _("splicemap file not found or error reading %s:") % path)
        return m