Exemple #1
0
def load_database():
    """ Loads database from disk if it exists | None -> pd.DataFrame or None """
    try:
        db = pd.read_pickle(config.get_full_db_path())
        print('Loading saved key dataframe')
        print(db)
    except FileNotFoundError:
        print('No saved key dataframe')
        db = pd.DataFrame()  #Initialize empty db
        db.to_pickle(config.get_full_db_path())
    return db
Exemple #2
0
def initialize_db(key_list, phrase):
    """ Create new database on first startup | list(str), str -> pd.DataFrame """
    print('Initializing database')
    global db
    row_data = []
    for i in range(len(key_list)):
        row_data.append(True)
    db = pd.DataFrame.from_dict({phrase: row_data},
                                orient='index',
                                columns=key_list)
    db.to_pickle(config.get_full_db_path())
Exemple #3
0
def daily_backup():
    """ Performs daily backup | None -> None """
    print('daily backup in progress')
    db_filepath = config.get_full_db_path()
    backup_path = config.get_backup_path()
    db_name = config.get_db_name()
    backup_filepath = backup_path / (db_name + '_daily.pickle')
    print(f'saving {backup_filepath}')
    shutil.copy(db_filepath, backup_filepath)
    backup_date_dict['day'] = date.today()
    save_backup_dates()
Exemple #4
0
def redo():
    """ Reverts previous undo call | None -> None """
    if not redo_db_list:  # If no undo in memory
        return
    #Part 1: Save current state to temp backup
    prepare_undo()
    #Part 2: Revert previous undo command
    db_filepath = config.get_full_db_path()
    revert_filepath = redo_db_list[-1]
    shutil.copy(revert_filepath, db_filepath)
    redo_db_list.pop().unlink()
    reload_database()
Exemple #5
0
def undo():
    """ Reverts previous database save command | None -> None """
    if not undo_db_list:  #If no previous saved state
        return
    #Part 1: Save current state to temp backup
    prepare_redo()
    #Part 2: Revert previous save command
    db_filepath = config.get_full_db_path()
    revert_filepath = undo_db_list[-1]
    shutil.copy(revert_filepath, db_filepath)
    undo_db_list.pop().unlink()
    reload_database()
Exemple #6
0
def save():
    """ Save contents of database to disk | db.DataFrame -> None """
    global db
    db.to_pickle(config.get_full_db_path())
Exemple #7
0
def prepare_redo():
    """ Saves current db state to redo file and saves path | None -> None """
    db_filepath = config.get_full_db_path()
    filepath = generate_redo_filepath()
    shutil.copy(db_filepath, filepath)
    redo_db_list.append(filepath)