Example #1
0
    def test_log_file_should_not_create_if_file_exists(self):
        file_utility = FileUtilities()
        file_utility.get_root_path = MagicMock(
            return_value='beginning of file path' + '\\Infrastructure')
        file_utility.file_exists = MagicMock(return_value=True)
        file_utility.create_file = MagicMock(return_value=True)

        date_time_utility = DateTimeUtility()
        EventLoggingManager(file_utility, date_time_utility)

        file_utility.create_file.assert_not_called()
Example #2
0
    def test_log_file_should_be_created_if_doesnt_exist(self):
        file_utility = FileUtilities()
        beginning_of_file_path = 'beginning of file path'
        file_utility.get_root_path = MagicMock(
            return_value=beginning_of_file_path + "\\Infrastructure")
        file_utility.file_exists = MagicMock(return_value=False)
        file_utility.create_file = MagicMock(return_value=True)
        date_time_utility = DateTimeUtility()
        EventLoggingManager(file_utility, date_time_utility)

        file_utility.create_file.assert_called_with(beginning_of_file_path +
                                                    '\\MobTimerEvents.log')
Example #3
0
class SessionManager(object):
    def __init__(self, uuid_generator):
        self.uuid_generator = uuid_generator
        self.file_utilities = FileUtilities()

    def create_session(self):
        session_id = self.uuid_generator.uuid1()

        directory = self.get_sessions_path()

        file = open(directory + session_id.__str__(), 'w+')

    def get_sessions_path(self):
        directory = (self.file_utilities.get_root_path() + "/Sessions/")
        if not os.path.exists(directory):
            os.makedirs(directory)
        return directory

    def get_active_sessions(self):
        return os.listdir(self.get_sessions_path())

    def clear_sessions(self):
        folder = self.get_sessions_path()
        for the_file in os.listdir(folder):
            file_path = os.path.join(folder, the_file)
            try:
                if os.path.isfile(file_path):
                    os.unlink(file_path)
            except Exception:
                pass
Example #4
0
    def test_log_file_should_append_to_log(self):
        file_utility = FileUtilities()
        beginning_of_file_path = 'beginning of file path'
        file_utility.get_root_path = MagicMock(
            return_value=beginning_of_file_path + '\\Infrastructure')
        file_utility.file_exists = MagicMock(return_value=True)
        file_utility.create_file = MagicMock(return_value=True)
        file_utility.append = MagicMock()
        date_time_utility = DateTimeUtility()

        timestamps = [1594823426.159446, 1594123426.159447, 1594654426.159448]
        date_time_utility.get_timestamp = Mock()
        date_time_utility.get_timestamp.side_effect = timestamps
        logger = EventLoggingManager(file_utility, date_time_utility)

        test_data = ["Hello world 1", "Hello world 2"]

        for entry in test_data:
            logger.log(entry)
        calls = []
        index = 0
        for entry in test_data:
            calls.append(
                call(f'{beginning_of_file_path}\\MobTimerEvents.log',
                     f'\n{timestamps[index]} {entry}'))
            index += 1

        file_utility.append.assert_has_calls(calls)
Example #5
0
class TipsManager(object):
    def __init__(self, seed=None, root_directory=sys.argv[0]):
        self.file_utility = FileUtilities()
        self.root_directory = self.file_utility.go_up_dirs(root_directory, 1)
        if seed is not None:
            random.seed(seed)

    def get_random_tip(self):
        tips_folder = self.root_directory + "/Tips"
        random_file = random.choice(os.listdir("%s" % tips_folder))
        random_file_path = tips_folder + "\\" + random_file
        return "{}: {}".format(random_file,
                               TipsManager.random_line(random_file_path))

    @staticmethod
    def random_line(file_name):
        with open(file_name) as a_file:
            line = next(a_file)
            for num, aline in enumerate(a_file):
                if random.randrange(num + 2): continue
                line = aline
            return line
Example #6
0
 def __init__(self, uuid_generator):
     self.uuid_generator = uuid_generator
     self.file_utilities = FileUtilities()
Example #7
0
 def get_sessions_path(self):
     directory = (FileUtilities.get_root_path() + "/Sessions/")
     if not os.path.exists(directory):
         os.makedirs(directory)
     return directory
 def get_sessions_path(self):
     directory = FileUtilities.get_root_path() + "/Sessions/"
     if not os.path.exists(directory):
         os.makedirs(directory)
     return directory
Example #9
0
 def setUpClass(cls):
     cls.fileUtilities = FileUtilities()
Example #10
0
    def __init__(self, *args, **kwargs):
        Tk.__init__(self, *args, **kwargs)
        self.toggle_transparent_frame_position_function = self.toggle_transparent_frame_position_enabled
        self.transparent_frame_monitor_index = 0
        self.transparent_frame_position_index = 0
        self.settings_manager = SettingsManager()
        self.tips_manager = TipsManager()
        self.time_options_manager = TimeSettingsManager()
        self.date_time_utility = DateTimeUtility()
        self.file_utilities = FileUtilities()
        self.event_logging_manager = EventLoggingManager(self.file_utilities, self.date_time_utility)
        self.mobber_manager = MobberManager(self.settings_manager.get_randomize_randomize_next_driver())
        self.countdown_manager = CountdownManager(self)
        self.session_manager = SessionManager(uuid)
        self.timer_extension_count = self.settings_manager.get_timer_extension_count()
        self.extensions_used = 0
        atexit.register(self.session_manager.clear_sessions)
        if self.session_manager.get_active_sessions().__len__() > 0:
            self.quit_and_destroy_session()

        self.session_manager.create_session()
        if sys.platform != 'darwin':
            self.iconbitmap(default='time-bomb.ico')

        self.countdown_manager.subscribe_to_time_changes(self.show_screen_blocker_when_session_interupted)

        self.theme_manager = ThemeManager()
        theme = self.settings_manager.get_general_theme()
        if not theme == 'none':
            self.theme_manager.set_theme(theme)
        monitors = ScreenUtility.get_monitors_or_default()
        num_monitors = monitors.__len__()
        self.parent_containers = [self]
        self.containers = []
        for monitor_index in range(1, num_monitors):
            monitor_screen_blocker = Toplevel(self)
            self.parent_containers.append(monitor_screen_blocker)
        self.frame_types = (ScreenBlockerFrame, TransparentCountdownFrame, MinimalScreenBlockerFrame)
        self.frames = {}
        for frame_type in self.frame_types:
            self.frames[frame_type] = []
        for parent_container, monitor in zip(self.parent_containers, monitors):
            parent_container.grid_rowconfigure(0, weight=1)
            parent_container.grid_columnconfigure(0, weight=1)

            container = OuterFrame(parent=parent_container, monitor=monitor)
            self.containers.append(container)
            container.grid(row=0, column=0, sticky=(N, S, E, W))
            container.grid_rowconfigure(0, weight=1)
            container.grid_columnconfigure(0, weight=1)
            for frame_type in self.frame_types:
                frame_instance = frame_type(container, self, self.time_options_manager, self.mobber_manager,
                                            self.countdown_manager, self.settings_manager, self.tips_manager,
                                            self.theme_manager)
                self.frames[frame_type].append(frame_instance)
                frame_instance.grid(row=0, column=0, sticky=(N, S, E, W))
                frame_instance.grid_rowconfigure(0, weight=1)
                frame_instance.grid_columnconfigure(0, weight=1)
        self.last_frame = None
        self.show_screen_blocker_frame()
        for frame_instance in self.frames[TransparentCountdownFrame]:
            frame_instance.bind("<Enter>", self.toggle_transparent_frame_position)
        self.transparent_frame_position = 0
        self.title("Mob Timer")
        self.bind_all("<Control-Return>", self.launch_transparent_countdown_if_blocking)
        self.time_options_manager.set_countdown_time(self.settings_manager.get_timer_minutes(),
                                                     self.settings_manager.get_timer_seconds())

        self.dojo_manager = DojoManager(self)

        if self.settings_manager.get_event_logging_enabled():
            self.mobber_manager.subscribe_to_mobber_add(self.add_mobber_callback)
            self.mobber_manager.subscribe_to_mobber_remove(self.remove_mobber_callback)
Example #11
0
 def __init__(self, seed=None, root_directory=sys.argv[0]):
     self.file_utility = FileUtilities()
     self.root_directory = self.file_utility.go_up_dirs(root_directory, 1)
     if seed is not None:
         random.seed(seed)