Пример #1
0
    def create_source(self, objects=[]):
        """Create report from objects (list of DNs)."""
        tmpfile = self.__create_tempfile()
        admin.set_format(self._type)
        parser = Parser(filename=self._template)
        parser.tokenize()
        tokens = parser._tokens
        fd = codecs.open(tmpfile, 'wb+', encoding='utf8')
        if parser._header:
            fd.write(parser._header.data)
        elif self._header:
            self.__append_file(fd, self._header)

        for dn in objects:
            if isinstance(dn, basestring):
                obj = admin.get_object(None, dn)
            else:
                obj = admin.cache_object(dn)
            if obj is None:
                print >> sys.stderr, "warning: dn '%s' not found, skipped." % dn
                continue
            tks = copy.deepcopy(tokens)
            interpret = Interpreter(obj, tks)
            interpret.run()
            output = Output(tks, fd=fd)
            output.write()
        if parser._footer:
            fd.write(parser._footer.data)
        elif self._footer:
            self.__append_file(fd, self._footer)
        fd.close()

        return tmpfile
Пример #2
0
 def __append_file(self, fd, filename, obj=None):
     parser = Parser(filename=filename)
     parser.tokenize()
     tks = copy.deepcopy(parser._tokens)
     interpret = Interpreter(obj, tks)
     interpret.run()
     output = Output(tks, fd=fd)
     output.write()