def __init__(self, x, y, r): Animal.__init__(self, x, y, r) is_swimming = True self.tail = Tail(self) self.destination_x = x self.destination_y = y return
def get_tail_of_log(self): date_str = datetime.now().strftime("%Y-%m-%d") log_file = self.app_name + "-" + date_str + ".log" log_file_path = "%s/%s/%s" % (log_dir, self.app_name, log_file) if os.path.exists(log_file_path): return Tail(log_file_path) log_file_path = "%s/%s/%s" % (log_dir, self.app_name, "log_info.log") if os.path.exists(log_file_path): return Tail(log_file_path) raise TailError("没有找到日志文件")
def tail_thread(_tail: tail.Tail): logger.info("wait for tail file ... %s", _tail.tailed_file) while True: if os.path.exists(_tail.tailed_file): logger.info("Start tail file..... %s", _tail.tailed_file) break _tail.register_callback(unity_log_tail) _tail.follow(s=0.5)
def __init__(self, pos, size = 20, gravity = 0.001): self.pos = pos self.speed = [0, 0] self.acc = [0, gravity] self.size = size self.color = self.BLUE self.gravity = gravity self.jumping = False self.tail = Tail(pos, [0, 0])
def main(): parser = argparse.ArgumentParser(description='Read and display file from the end.') parser.add_argument('file', metavar='FILE', type=str, help='file name to be tailed.') parser.add_argument('-n', dest='lines', type=int, default=10, help='display last [n] lines') parser.add_argument('-f', dest='follow', action='store_true', default=False, help='continuosly tailing file.') parser.add_argument('-s', dest='sleep', type=float, default=1.0, help='with -f, sleep for N seconds, (deafult 1.0)') args = parser.parse_args() tail = Tail(open(args.file, 'rb')) try: if args.follow: tail.seek_end() for line in tail.follow(delay=args.sleep): print line else: if args.lines > 0: lines = tail.tail(args.lines) for line in lines: print line except KeyboardInterrupt: pass finally: tail.close()
def __init__(self, config): self.replica_count = config.replica_count self.head = Head(config.init_object) self.tail = Tail(config.init_object) # create inner_replicas with chains inner_replicas = [Replica(config.init_object) * self.replica_count] self.replicas = [head] + inner_replicas + [tail] pass
def tail(file, lines=10): """ Test returning the end [x] lines of the file. >>> import StringIO >>> f = StringIO.StringIO() >>> for i in range(10): ... f.write('Line %d\\n' % (i + 1)) >>> tail(f, 4) ['Line 7', 'Line 8', 'Line 9', 'Line 10'] """ return Tail(file).tail(lines)
def path_tailers(fdict): "generate tailer threads with all the initialization done." fields = fdict.get('fields', {"type": "default"}) if "type" not in fields: fields["type"] = "default" for _path in fdict.get('paths', []): annotation = {'name': path.basename(_path)} annotation.update(fields) tailer = Tail(_path, q=config.LOG_QUEUE, stop_event=config.STOP_EVENT, fields=annotation, interval=config.POLL_INTERVAL) yield tailer
def check_events(snake, food, screen, my_tail, tails, settings, button, gf, end_game_screen, score, gametime): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() check_keydown_events(event, snake, button, settings, gametime) if pygame.sprite.collide_rect(snake, food.sprite): x, y = generate_randoms() food.add(Food(snake, screen, x, y)) settings.snake_length += 1 score.increase_score() tail_sprite = Tail(snake, screen, settings.snake_length - 1, my_tail) my_tail.append(tail_sprite) for body in my_tail: tails.add(body) if lose_condition_met(snake, settings, tails, gametime): settings.game_active = False end_game_screen.draw_me()
def game(): pygame.init() setting = Setting() screen = pygame.display.set_mode( (setting.screen_width, setting.screen_height)) snake_head = Snake_head(screen, setting) apple = Apple(screen, setting) tail = Tail(screen, setting) apple.get_rect(snake_head, tail) start_time = pygame.time.get_ticks() while gf.resume_game(setting, snake_head, tail): gf.check_event(snake_head, start_time) gf.update(screen, setting, snake_head, apple, tail) pygame.time.delay(100) print(tail.ate_apples_count)
def follow(file, delay=1.0): """ Test following a file. >>> import os >>> f = file('test_follow.txt', 'w') >>> f_r = file('test_follow.txt', 'r') >>> generator = follow(f_r) >>> f.write('Line 1\\n') >>> f.flush() >>> generator.next() 'Line 1' >>> f.write('Line 2\\n') >>> f.flush() >>> generator.next() 'Line 2' >>> f.close() >>> f_r.close() >>> os.remove('test_follow.txt') """ return Tail(file).follow(delay=delay)
def addTailPiece(self): self.tails.append(Tail(self.snake.x(),self.snake.y()))
def addTail(self, direction): self.body.append( Tail((self.position[0] - direction[0], self.position[1] - direction[1]), self.pps)) return
class Ball: BLUE = (0, 0, 255) RED = (255, 0, 0) ATRICT = 0.7 def __init__(self, pos, size = 20, gravity = 0.001): self.pos = pos self.speed = [0, 0] self.acc = [0, gravity] self.size = size self.color = self.BLUE self.gravity = gravity self.jumping = False self.tail = Tail(pos, [0, 0]) def reset(self): self.acc = [0, self.gravity] def jump(self): self.speed[1] = -0.5 self.jumping = True def move(self, acc): self.acc[0] += acc[0] self.acc[1] += acc[1] def applySpeed(self): self.pos[0] += self.speed[0] self.pos[1] += self.speed[1] self.tail.updatePos(self.pos) def applyAcc(self): self.speed[0] += self.acc[0] self.speed[1] += self.acc[1] def borderColision(self, screen): w, h = screen.get_size() # Borda de baixo if self.pos[1] + self.size > h: self.speed[1] = - abs(self.speed[1]) * self.ATRICT self.jumping = False # Borda de cima if self.pos[1] + self.size < 0: self.speed[1] = abs(self.speed[1]) * self.ATRICT # Borda da esquerda if self.pos[0] - self.size < 0: self.speed[0] = abs(self.speed[0]) * self.ATRICT # Borda da direita if self.pos[0] + self.size > w: self.speed[0] = - abs(self.speed[0]) * self.ATRICT def draw(self, screen): #checando se bateu nas bordas self.borderColision(screen) self.applyAcc() self.applySpeed() pygame.draw.circle(screen, self.color, radius=self.size, center=self.pos) self.tail.draw(screen)
class Fish(Animal): __sin = 0.0 # direction of swimmin sight_range = 80 color = (200, 0, 0) energy = 300 def __init__(self, x, y, r): Animal.__init__(self, x, y, r) is_swimming = True self.tail = Tail(self) self.destination_x = x self.destination_y = y return def display(self, output): drawX = int(self.get_x()) drawY = int(self.get_y()) pygame.draw.circle(output, (255, 0, 0), (drawX, drawY), self.sight_range, 2) pygame.draw.circle(output, self.color, (drawX, drawY), 10) # self.tail.display(output) return def set_parent(self, parent): self.parent_world = parent def swim(self): Animal.rotate(self) self.move(self.speed_x, self.speed_y) # self.tail.activity() return def floating(self): # self.speed_x = random.randint(-1,1) # self.speed_y = random.randint(-1,1) # self.move(self.speed_x, self.speed_y) return def move(self, x, y): Animal.move(self, x, y) self.tail.move(x, y) return def eat_food(self, food): self.energy += 100 return def search_food(self): min_dist = self.sight_range # to make sure distance will be smaller food_found = False # self.is_swimming = True fx = 0 fy = 0 for f in self.parent_world.food: distance = math.sqrt((f.get_x() - self.get_x())**2 + (f.get_y() - self.get_y())**2) if distance < min_dist: # food in sight range and closer than previous food min_dist = distance food_found = True fx = f.get_x() fy = f.get_y() if distance < 3: self.eat_food(f) self.parent_world.food.remove(f) if food_found: # self.is_swimming = False self.destination_x = fx self.destination_y = fy return def go_to_destination(self): x = self.destination_x y = self.destination_y self.speed_x = 0 self.speed_y = 0 if x > self.get_x(): self.speed_x = 1 if x < self.get_x(): self.speed_x = -1 if y > self.get_y(): self.speed_y = 1 if y < self.get_y(): self.speed_y = -1 return def reproduce(self): return def activity(self): if self.is_swimming: self.swim() # else: # self.floating() self.search_food() self.go_to_destination() self.energy -= 1 print("Energy: %d" % self.energy) if self.energy <= 0: self.parent_world.fish.remove(self) if self.energy >= 1000: self.reproduce() return
def stop_tail(_tail: tail.Tail, t: Thread): _tail.terminate() t.join() logger.info("Stop tail file..... %s", _tail.tailed_file)
def display_BRIDGE(): # pass if BRIDGE.empty(): print 'empty' else: print 'not empty\n' # a=BRIDGE.get() # print '\na',a['send_speed'] # print '\na',a['recv_speed'] # for m in BRIDGE: # print m['recv_speed'],'---',m['send_speed'] ####################################################################################### trace_log = Tail(log_file_path) trace_log.register_callback(deal_line) #trace_log.follow(s=0.01) def thread_fun(): print 'thread fun start' # for i in range(100): # BRIDGE.put(i) trace_log.follow(s=0.01) print 'thread fun ended' trace_thread = Thread(target=thread_fun) trace_thread.start()
from threading import Thread from flask import Flask, render_template from flask_socketio import SocketIO from tail import Tail app = Flask(__name__) app.config['SECRET_KEY'] = 'my_secret' socket_io = SocketIO(app) tf = Tail("data.log", socket_io) # Path of log file to tail @app.route("/log") def render(): return render_template('index.html') @socket_io.on('connected') def handle_log(json): print('received msg: ' + str(json)) tf.tail() thread = Thread(target=tf.follow) thread.start() if __name__ == '__main__': socket_io.run(app, port=5000)
def initialise_snake(snake, screen, my_tail, tails, settings): for number in range(1, settings.snake_length): tail_sprite = Tail(snake, screen, number, my_tail) my_tail.append(tail_sprite) for body in my_tail: tails.add(body)