예제 #1
0
def init():
    try:
        DataStore.init(os.getcwd())
        print('Habit Store initialized successfully!')
    except FileExistsError as e:
        print(e)
        exit(1)
예제 #2
0
def load_goals():
    store = DataStore(os.getcwd())
    names = store.list_goal_names()
    if not names:
        return []
    pool = multiprocessing.dummy.Pool(len(names))
    return pool.map(lambda name: store.load_goal(name), names)
예제 #3
0
def list(name):
    store = DataStore(os.getcwd())
    goal = load_goal(store, name)
    table = [[d.uuid[:8], d.value,
              d.stamp.isoformat(), d.comment] for d in goal.datapoints]
    print(
        tabulate.tabulate(table, headers=['Hash', 'Value', 'Time', 'Comment']))
예제 #4
0
def remove(name, uuid):
    store = DataStore(os.getcwd())
    goal = load_goal(store, name)
    try:
        goal.remove_point(uuid)
        print('Point with uuid {} removed successfully!'.format(uuid))
    except KeyError as e:
        print(e)
        exit(1)
예제 #5
0
def edit(name, uuid, value, time, comment):
    store = DataStore(os.getcwd())
    goal = load_goal(store, name)
    try:
        if time is not None:
            time = dparse(time)
        if value is not None:
            value = float(value)
        goal.edit_point(uuid, value=value, comment=comment, stamp=time)
        print('Point with uuid {} edited successfully!'.format(uuid))
    except KeyError as e:
        print(e)
        exit(1)
예제 #6
0
def new(name, slope, pledge, initial_pause):
    store = DataStore(os.getcwd())
    goal = create_goal(name=name,
                       daily_slope=slope,
                       pledge=pledge,
                       initial_pause_days=initial_pause)
    try:
        goal.set_store(store)
        print(
            'Goal named {} with daily slope of {} and a pledge of {}€ created successfully!'
            .format(name, slope, pledge))
    except ValueError as e:
        print(e)
        exit(1)
예제 #7
0
def add(name, value, comment=''):
    store = DataStore(os.getcwd())
    goal = load_goal(store, name)
    point = create_point(value=float(value), comment=comment)
    goal.add_point(point)
    print('Point added successfully!')
예제 #8
0
def test_init_in_git_repo_fails(empty_datastore):
    with pytest.raises(FileExistsError):
        DataStore.init(empty_datastore.path)
예제 #9
0
def empty_datastore(empty_folder):
    return DataStore.init(empty_folder)
예제 #10
0
def test_datastore_can_be_initialized_and_creates_a_git_repository(
        empty_folder):
    _ = DataStore.init(empty_folder)
    assert os.path.exists(os.path.join(empty_folder, '.git'))
예제 #11
0
def test_datastore_raises_error_if_not_a_git_repository(empty_folder):
    with pytest.raises(InvalidGitRepositoryError):
        _ = DataStore(empty_folder)
예제 #12
0
def test_datastore_raises_error_if_path_is_not_a_directory():
    _, path = tempfile.mkstemp()
    with pytest.raises(NotADirectoryError):
        _ = DataStore(path)
    os.remove(path)
예제 #13
0
def test_datastore_raises_error_if_directory_does_not_exists(empty_folder):
    os.rmdir(empty_folder)
    with pytest.raises(FileNotFoundError):
        _ = DataStore(empty_folder)