Пример #1
0
from menus import Shift_Tracking_Menu
from objects import Shift
from os import path, chdir
from resources.system_names import data_directory, shifts_directory
from utility.utility import now

# make directories to store user data
shifts_path = path.join(data_directory, shifts_directory)
if not path.exists(data_directory):
    from os import mkdir
    mkdir(data_directory)
if not path.exists(shifts_path):
    from os import mkdir
    mkdir(shifts_path)

shift = Shift(now().date())
# check for completed shift
if path.exists(shift.file_list()['info']):
    from menus import Completed_Shift
    menu = Completed_Shift(shift)
    shift = menu.shift
# check if shift has not started
elif not path.exists(shift.file_list()['directory']):
    shift.start()
# load shift
else:
    shift.load_current()

# daily shift tracking menu
Shift_Tracking_Menu(shift)
Пример #2
0
class Completed_Shift:
    def __init__(self, shift, test=False):
        from objects import Shift
        if not isinstance(shift, Shift):
            raise TypeError

        self.shift = shift

        if test is False:
            from utility.user_input import enter_to_continue
            self.user_choice()
            if self.user_choice.lower() == 'r':
                from resources.strings import Shift__resume__confirmation
                self.resume_shift(self.shift)
                enter_to_continue(Shift__resume__confirmation)
            elif self.user_choice.lower() == 'o':
                from resources.strings import Shift__overwritten__confirmation
                self.overwrite_shift(self.shift)
                enter_to_continue(Shift__overwritten__confirmation)
            elif self.user_choice.lower() == 'q':
                pass

    def overwrite_shift(self):
        from objects import Shift
        from os import mkdir
        from shutil import rmtree
        from utility.file import write
        from utility.utility import now

        self.shift = Shift(now().date())

        # delete directory that contains all files
        rmtree(self.shift.file_list()['directory'])
        # recreate the directory to store new files
        mkdir(self.shift.file_list()['directory'])
        # set and save start time
        self.shift.set_start_time()
        write(self.shift.start_time, self.shift.file_list()['start_time'])
        # remove id from completed ids file
        self.shift.remove_id_from_file()

        return self

    def resume_shift(self):
        from objects import Shift
        from os import remove
        from utility.file import write
        from utility.utility import now

        self.shift = Shift(now().date())

        # load completed shift data
        self.shift.load_completed()
        # get shift start time
        start_time = self.shift.start_time
        # delete shift info file
        remove(self.shift.file_list()['info'])
        # save start time
        write(start_time, self.shift.file_list()['start_time'])
        # remove id from completed ids file
        self.shift.remove_id_from_file()
        # load current shift data
        self.shift.load_current()

        return self

    def user_choice(self):
        from resources.strings import Shift__completed__menu as prompt
        from utility.user_input import check_match, user_input

        self.user_choice = user_input(self.prompt)
        while not check_match('^[roq]$', self.user_choice):
            self.user_choice = user_input(self.prompt)
        return self