示例#1
0
 def validate(self, xml_filename, dtd_report_filename, style_report_filename):
     self.logger.register('XMLValidator.validate - inicio')
     self.logger.register('XMLValidator.validate - self.validator.setup()')
     self.validator.logger = self.logger
     self.validator.setup(xml_filename)
     self.logger.register('XMLValidator.validate - xml_utils.load_xml')
     xml, e = xml_utils.load_xml(self.validator.xml.content)
     self.logger.register('XMLValidator.validate - self.validator.dtd_validation')
     is_valid_dtd = self.validator.dtd_validation(dtd_report_filename)
     content = ''
     if e is None:
         self.logger.register('XMLValidator.validate - self.validator.style_validation')
         self.validator.style_validation(style_report_filename)
         self.logger.register('XMLValidator.validate - fs_utils.read_file')
         content = fs_utils.read_file(style_report_filename)
     else:
         self.logger.register('XMLValidator.validate - e is not None')
         content = validation_status.STATUS_FATAL_ERROR + ': ' + _('Unable to load {xml}. ').format(xml=xml_filename) + '\n' + e
         fs_utils.write_file(style_report_filename, content)
     self.logger.register('XMLValidator.validate - style_checker_statistics')
     f, e, w = style_checker_statistics(content)
     self.logger.register('XMLValidator.validate - self.validator.finish()')
     self.validator.finish()
     self.logger.register('XMLValidator.validate - fim')
     return (xml, is_valid_dtd, (f, e, w))
示例#2
0
def load_articles(filenames):
    files = {}
    for name, f in filenames.items():
        content = fs_utils.read_file(f)
        xmlcontent = xml_utils.XMLContent(content)
        xmlcontent.normalize()
        xml, error = xml_utils.load_xml(xmlcontent.content)
        if xml is not None:
            files[name] = xml_utils.tostring(xml.getroot())
        else:
            print(' ERROR 1: Invalid XML {}'.format(name))
    return files
示例#3
0
def validate_article_xml(xml_filename, dtd_files, dtd_report_filename, style_report_filename):
    register_log('validate_article_xml: inicio')
    is_valid_style = False

    register_log('validate_article_xml: inicio')
    xml, e = xml_utils.load_xml(xml_filename)
    is_valid_dtd = dtd_validation(xml_filename, dtd_report_filename, dtd_files.doctype_with_local_path, dtd_files.database_name)
    if e is None:
        is_valid_style = style_validation(xml_filename, dtd_files.doctype_with_local_path, style_report_filename, dtd_files.xsl_prep_report, dtd_files.xsl_report, dtd_files.database_name)
    else:
        text = validation_status.STATUS_FATAL_ERROR + ': ' + _('Unable to load') + ' ' + xml_filename + '\n' + e
        fs_utils.write_file(style_report_filename, text)
    f, e, w = style_checker_statistics(style_report_filename)
    register_log('validate_article_xml: fim')
    #open(os.path.dirname(style_report_filename) + '/validate_article_xml.log', 'a+').write('\n'.join(log_items))
    return (xml, is_valid_dtd, (f, e, w))
示例#4
0
    def __init__(self, parent, screen):
        # controls how held keys are repeated. The first number is the delay in milliseconds, the second is the interval
        # at which the keys are repeated
        pygame.key.set_repeat(1, 1)

        # Set the parent driver
        self.parent = parent

        # sets screen
        self.screen = screen
        # creates an empty array called events
        self.events = []
        # sets map width
        self.map_width = SCREEN_SIZE[0] * MAP_WIDTH // TILE_SIZE
        # sets map height
        self.map_height = SCREEN_SIZE[1] * MAP_HEIGHT // TILE_SIZE
        # sets screen width
        self.screen_width = SCREEN_SIZE[0] // TILE_SIZE
        # sets screen height
        self.screen_height = SCREEN_SIZE[1] // TILE_SIZE
        # sets background sprite path
        background = pygame.image.load("resources/graphics/forest.png")
        # scales background using the path defined above as the background
        self.background = pygame.transform.scale(background, SCREEN_SIZE)
        # where camera is on the screen, x position
        self.x_offset = (MAP_WIDTH - 1) * self.screen_width // 2
        # where camera is on the screen, y position
        self.y_offset = (MAP_HEIGHT - 1) * self.screen_height // 2
        # creates an empty array called objects
        self.objects = []
        # variable that determines player location and xml
        self.player = Player(self.map_width // 2, self.map_height // 2,
                             load_xml("resources/xml/player.xml"), self)
        # appends the player to objects
        self.objects.append(self.player)
        # load the rock xml
        rock_xml = load_xml("resources/xml/rock.xml")
        # rock sprite directory is set up
        rock = pygame.image.load("resources/graphics/rock.png")
        # width of the rock
        w = int(rock_xml.get('width'))
        # height of the rock
        h = int(rock_xml.get('height'))
        # path to zombie image
        self.zombie_img = pygame.image.load(
            "resources/graphics/enemies/zombie.png")
        # makes rocks appear at a certain boundary on the top and bottom (x axis)
        for x in range(self.screen_width, self.screen_width * (MAP_WIDTH - 1),
                       w):
            self.objects.append(
                GameObject(x,
                           self.screen_height,
                           w,
                           h,
                           self,
                           image=rock,
                           active=True))
            self.objects.append(
                GameObject(x,
                           self.screen_height * (MAP_HEIGHT - 1),
                           w,
                           h,
                           self,
                           image=rock,
                           active=True))
        # makes rocks appear at a certain boundary on the left and right (y axis)
        for y in range(self.screen_height,
                       self.screen_height * (MAP_HEIGHT - 1), h):
            self.objects.append(
                GameObject(self.screen_width,
                           y,
                           w,
                           h,
                           self,
                           image=rock,
                           active=True))
            self.objects.append(
                GameObject(self.screen_width * (MAP_WIDTH - 1),
                           y,
                           w,
                           h,
                           self,
                           image=rock,
                           active=True))

        # Preload the xml so we can reuse it
        self.zombie_xml = load_xml("resources/xml/zombie.xml")

        # Set a score value, initially 0
        self.score = 0
        self.scoreText = font_small.render(str(self.score), True,
                                           RED_TEXT_COLOUR, self.screen)
示例#5
0
    def _load(self, xml_filename, show_message=False):
        self.ns = ''
        self.report.write('_load ' + xml_filename)
        self.root = xml_utils.load_xml(xml_filename)

        return (self.root is not None)