Exemplo n.º 1
0
def read_list():
    f = open('watchlist', 'r')
    watchlist = []
    read_email = False
    email = ''

    for line in f:
        if not read_email:
            email = line.rstrip()
            read_email = True
            continue

        values = line.split(',')
        try:
            watchlist.append(watch.Watch(values[0], float(values[1].rstrip())))
        except Exception as e:
            print(
                f"{datetime.datetime.now()} - Failed to parse watchlist line: {line}",
                file=sys.stderr)
            print(format(e), file=sys.stderr)
            exit(1)

    f.close()

    return watchList.WatchList(watchlist, email)
Exemplo n.º 2
0
def load_pop(gui):
    openFile= filedialog.askopenfile(
        parent= gui.window,
        mode= 'rb',
        title= OPEN_POPULATION_WINDOW_NAME,
        filetypes= (POP_FILE_NAME,ALL_FILE_NAME)
    )

    pop= watch.open_pop(openFile)
    openFile.close()
    gui.bWatch= watch.Watch()
    gui.algo.reset(pop)
Exemplo n.º 3
0
    def __init__(self, opts=None):
        if opts is None:
            opts = {}

        if opts.get('logger'):
            self.logger = opts['logger']
        else:
            self.logger = logging.getLogger('filewatch.Tail')

        self.files = {}
        self.lastwarn = {}
        self.buffers = {}
        self.watch = watch.Watch()
        self.watch.logger = self.logger
        self.sincedb = {}
        self.sincedb_last_write = 0
        self.statcache = {}
        self.opts = {
            'sincedb_write_interval': 10,
            'stat_interval': 1,
            'discover_interval': 5,
            'exclude': [],
            'start_at_new_files': 'end'
        }
        self.opts.update(opts)

        if not self.opts.get('sincedb_path'):
            if os.environ.get('HOME'):
                self.opts['sincedb_path'] = os.path.join(
                    os.environ['HOME'], '.sincedb')
            if os.environ.get('SINCEDB_PATH'):
                self.opts['sincedb_path'] = os.environ['SINCEDB_PATH']

        if not self.opts.get('sincedb_path'):
            raise NoSinceDBPathGiven(
                "No HOME or SINCEDB_PATH set in environment. I need one of "
                "these set so I can keep track of the files I am following.")

        self.watch.exclude(self.opts['exclude'])
        self._sincedb_open()
Exemplo n.º 4
0
    def main(self):
        self.alive = True
        self.bWatch = watch.Watch()

        self.window = tk.Tk()
        self.window.configure(background=BACKGROUND_COLOR_1)

        self.window.withdraw()

        #Launch the splash window in order to let the programm load itself
        splash = Splash(self.window)

        self.window.title(MAIN_WINDOW_NAME)
        img = tk.PhotoImage(file=ICON_PATH)
        self.window.tk.call('wm', 'iconphoto', self.window._w, img)
        self.window.protocol('WM_DELETE_WINDOW', partial(exit_app, self))

        screenWidth, screenHeight = self.window.winfo_screenwidth(
        ), self.window.winfo_screenheight()
        windowWidth, windowHeight = map(
            int, (screenWidth * 0.8, screenHeight * 0.8))

        #window.rowconfigure(0, minsize= int(windowHeight*0.0), weight=1)
        self.window.rowconfigure(1, minsize=int(windowHeight * 0.5), weight=1)
        self.window.rowconfigure(2, minsize=int(windowHeight * 0.5), weight=1)
        #window.rowconfigure(3, minsize= int(windowHeight*0.02), weight=1)

        self.window.columnconfigure(0,
                                    minsize=int(windowWidth * 0.3),
                                    weight=1)
        self.window.columnconfigure(1,
                                    minsize=int(windowWidth * 0.6),
                                    weight=1)
        self.window.columnconfigure(2,
                                    minsize=int(windowWidth * 0.1),
                                    weight=1)

        top = tk.Frame(self.window,
                       relief=tk.FLAT,
                       background=BACKGROUND_COLOR_1)
        toolbar = tk.Frame(top,
                           bd=1,
                           relief=tk.FLAT,
                           background=BACKGROUND_COLOR_1)

        #Initialize the availability of each button at the start of the programm
        self.startButton = tk.Button(toolbar)
        self.nextButton = tk.Button(toolbar)
        self.stopButton = tk.Button(toolbar, state='disabled')
        self.resetButton = tk.Button(toolbar, state='disabled')
        self.wsaveButton = tk.Button(toolbar, state='disabled')
        self.popsaveButton = tk.Button(toolbar, state='disabled')
        self.poploadButton = tk.Button(toolbar)
        self.wloadButton = tk.Button(toolbar)
        self.helpButton = tk.Button(toolbar)

        #Connect each button with his icon and what it does
        A = ((self.startButton, START_ICON_PATH,
              start_algo), (self.nextButton, NEXT_ICON_PATH, next_algo),
             (self.stopButton, STOP_ICON_PATH,
              stop_algo), (self.resetButton, RESET_ICON_PATH, reset_algo),
             (self.wsaveButton, WSAVE_ICON_PATH,
              save_watch), (self.popsaveButton, POPSAVE_ICON_PATH, save_pop),
             (self.poploadButton, POPLOAD_ICON_PATH,
              load_pop), (self.wloadButton, WLOAD_ICON_PATH, load_watch),
             (self.helpButton, HELP_ICON_PATH, help_menu))
        for a, b, c in A:
            img = tk.PhotoImage(file=b)
            a.config(image=img,
                     command=partial(c, self),
                     relief=tk.FLAT,
                     bg=BACKGROUND_COLOR_1,
                     bd=2,
                     highlightthickness=0,
                     activebackground=BACKGROUND_COLOR_2)
            a.image = img
            a.pack(side=tk.LEFT)

        #Load each part of the interface
        self.costFrame = CostFrame(self.window)
        self.watchCanvas = WatchCanvas(self.window)
        self.infosFrame = InfosFrame(self.window)
        self.graphFrame = GraphFrame(self.window)

        top.grid(row=0, column=0, columnspan=1, sticky='nesw')
        toolbar.pack()

        self.costFrame.grid(row=1, column=2, rowspan=2, sticky='nesw')
        self.watchCanvas.grid(row=1, column=1, rowspan=2, sticky='nesw')
        self.infosFrame.grid(row=1, column=0, sticky='nesw')
        self.graphFrame.grid(row=2, column=0, sticky='nesw')

        self.algo = watch.EvAlgo()
        self.algo.start()

        self.watchCanvas.set_watch(watch.Watch())
        self.infosFrame.update(0, self.bWatch)
        self.graphFrame.update(0, self.bWatch)
        self.costFrame.update()
        self.window.update_idletasks()
        self.window.update()

        #Kill the splash screen and then show the main part of the programm
        splash.destroy()
        self.window.deiconify()
        self.main_loop()
        self.window.destroy()
Exemplo n.º 5
0
        try:
            pop.append(pickle.load(openFile))
        except EOFError:
            break

    return pop


if __name__ == "__main__":

    #population= [randwatch.random_watch() for _ in range(10)]
    #save_pop(population)

    import watch
    import randwatch
    w = watch.Watch()

    i = randwatch.random_component("gear")
    j = randwatch.random_component("gear")
    a = randwatch.random_component("axis")
    w.add_edge(randwatch.random_component("engine"), a)
    w.add_edge(i, a)
    w.add_edge(i, j)
    w.add_edge(i, randwatch.random_component("gear"))
    w.add_edge(j, randwatch.random_component("gear"))
    w.add_edge(j, randwatch.random_component("gear"))
    a = randwatch.random_component("axis")
    w.add_edge(j, a)
    w.add_edge(a, randwatch.random_component("hand"))
    w.add_edge(j, randwatch.random_component("balance"))
Exemplo n.º 6
0
    def main(self, stdscr):
        self.alive = True

        self.cmdLog = list()
        self.logIndex = 0
        self.inputBuffer = str()
        self.inputMinX = 0

        self.algo = watch.EvAlgo()
        self.algo.start()
        self.bWatch = watch.Watch()

        self.inputScr = stdscr  # screen for input, also standart screen
        curses.noecho(
        )  # be able to read keys and only display them under certain circumstances
        curses.cbreak(
        )  # react to keys instantly, without requiring the Enter key to be pressed
        self.inputScr.keypad(True)  # enable keypad mode
        self.inputScr.timeout(16)
        self.inputScr.clear()
        self.inputScr.refresh()

        self.scrSize = self.inputScr.getmaxyx()
        if self.scrSize[0] < HIGHT_MIN or self.scrSize[
                1] < WIDTH_MIN:  #check if the window is big enough for the application
            raise Exception(CONSOLE_TOO_SMALL_ERROR_MSG)

        self.progSize = 3, 100
        self.progPos = 0, 0

        self.inputSize = 1, self.scrSize[1]
        self.inputPos = self.scrSize[0] - 1, 0
        self.cmdSize = 3, self.scrSize[1]
        self.cmdPos = self.inputPos[0] - self.cmdSize[0], 0

        self.genSize = self.cmdPos[0] - self.progSize[0], 25
        self.genPos = self.progSize[0], 0
        self.watchSize = self.genSize[0], 75
        self.watchPos = self.genPos[0], self.genPos[1] + self.genSize[1]

        self.progScr = curses.newwin(
            *(self.progSize +
              self.progPos))  # screen for genetic algorithme infos
        self.progScr.move(1, 1)
        self.progScr.addstr(
            ("{:^{width}}").format(PROG_NAME, width=str(self.progSize[1] - 2)))
        self.progScr.border()
        self.progScr.refresh()

        self.genScr = curses.newwin(
            *(self.genSize +
              self.genPos))  # screen for genetic algorithme infos
        self.genScr.move(1, 1)
        self.genScr.border()
        self.genScr.refresh()

        self.watchScr = curses.newwin(
            *(self.watchSize +
              self.watchPos))  # screen for genetic algorithme infos
        self.watchScr.move(1, 1)
        self.watchScr.border()
        self.watchScr.refresh()

        self.cmdScr = curses.newwin(*(self.cmdSize +
                                      self.cmdPos))  # sreen for command infos
        self.cmdScr.move(self.cmdSize[0] - 1, 1)

        self.inputScr.move(self.scrSize[0] - 1, 0)
        self.clear_input()

        self.main_loop()
        curses.endwin()
Exemplo n.º 7
0
def reset_algo(gui):
    print(RESET_MSG)
    gui.bWatch= watch.Watch()
    gui.graphFrame.log= (list(), list())
    gui.algo.reset()
Exemplo n.º 8
0
                         config.DATE_FORMAT_PRINT)
    merbs.order()
    t_end = timer()
    logger_sirken.info("Loading Merbs. Done in %s seconds" %
                       (round(t_end - t_start, 5)))

    # Load Helper
    t_start = timer()
    helper = helper.Helper(config.HELP_DIR)
    t_end = timer()
    logger_sirken.info("Loading Help. Done in %s seconds" %
                       (round(t_end - t_start, 5)))

    # Load Watcher
    t_start = timer()
    watch = watch.Watch(config.FILE_WATCH)
    t_end = timer()
    logger_sirken.info("Loading Watcher. Done in %s seconds" %
                       (round(t_end - t_start, 5)))

    # Load Trackers
    t_start = timer()
    trackers = trackers.Trackers(config.FILE_TRACKERS, merbs)
    t_end = timer()
    logger_sirken.info("Loading Trackers. Done in %s seconds" %
                       (round(t_end - t_start, 5)))

    # Initialize Sirken Commands
    sirken_cmds = SirkenCommands(client, config.authenticator, merbs, helper,
                                 watch, trackers)
    t_end = timer()
Exemplo n.º 9
0
def watch(key, time):
    watch_package.Watch(key, time).watch()