Example #1
0
    def run(self):
        input = self.inputs[0]
        with codecs.open(input, 'r', 'utf-8') as d_f:
            with codecs.open(self.outputs[0], "w", "utf-8") as o_f:
                with codecs.open(self.outputs[1], "w", "utf-8") as r_f:
                    cnt = 0
                    line = d_f.readline()
                    while line:
                        cnt += 1
                        if cnt % 100000 == 0:
                            print "processed %d lines" % cnt
                        line = line.strip("\r\n")
                        orig_line = line

                        if not line:
                            if self.replace_empty_line:
                                o_f.write("%s\n" % self.replace_empty_line)
                            r_f.write("%d\t%s\n" % (cnt, orig_line))
                            line = d_f.readline()
                            continue

                        for rule in self.rules:
                            line = rule.run(line)
                        if not line:
                            if self.replace_empty_line:
                                o_f.write("%s\n" % self.replace_empty_line)
                            r_f.write("%d\t%s\n" % (cnt, orig_line))
                            line = d_f.readline()
                            continue

                        o_f.write("%s\n" % line)

                        line = d_f.readline()
        return self.outputs
Example #2
0
 def process(self, line=None):
     if not line: return None
     for rule in self.rules:
         # print rule.printme()
         line = rule.run(line)
         # print line
     return line
Example #3
0
 def run(self):
     """ Iterates through all associated rules, executes them and collects the results. """
     errors = []
     for rule in self.rules:
         if not rule.run(self.value):
             errors.append(rule.error)
             if self.stop_on_first_error:
                 break
     return False if errors else True, errors
Example #4
0
    def run(self):

        inputs = self.inputs
        outputs = []
        for rule in self.rules:
            print rule
            outputs = rule.run(inputs)
            inputs = outputs
            self.temp_outputs.extend(outputs)
        if len(outputs) != len(self.outputs):
            print outputs
            print self.outputs
            print 'inconsistant outputs length in step %s, check schema' % self.name
            raise Exception

        for i, o in enumerate(outputs):
            shutil.move(o, self.outputs[i])
        return outputs
Example #5
0
import rule
import graphic
import pygame
map_handler = rule.map()
run_handler = rule.run(map_handler)
game_handler = rule.run(map_handler)
graphic_handler=graphic.graphic()
###  Initialize handler 
while map_handler.life:
    graphic_handler.clock.tick(60)
    graphic_handler.screen.fill((0,0,0))
    map_handler.map_draw()
    graphic_handler.draw(map_handler.map)
    pygame.display.flip()
    ### draw map
    key=graphic_handler.key_lock()
    if key == 1:
        run_handler.left_move()
    elif key ==2:
        run_handler.right_move()
    elif key ==3:
        run_handler.up_move()
    elif key ==4:
        run_handler.down_move()
    # if key is press => key_lock unlock and return 1 2 3 4 

    graphic_handler.screen.fill((0,0,0))
    graphic_handler.draw(map_handler.map)
    # draw

    pygame.display.flip()
Example #6
0
 def execute(self, context):
     for rule in self.rules:
         rule.run(context)