Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit fae5b59

Browse files
Merge pull request #31 from ChanceNCounter/feature/bak-diff
Implements 'bak diff', closes #12
2 parents 3c25ae4 + c042b23 commit fae5b59

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Don't worry, they're easy to remember after a minute:
2424

2525
## Additional commands and flags
2626
`bak down --keep my_file` - Restores from .bakfile, does not delete .bakfile
27+
`bak diff my_file` Compare a .bakfile using `diff` (will become configurable)
2728
`bak show my_file` View a .bakfile in $PAGER
2829
`bak show --using exec my_file` View a .bakfile using `exec` (alias `--in`)
2930

@@ -44,7 +45,6 @@ example:
4445

4546
`bak list` - List all .bakfiles, with a bit of metadata to help with disambiguation
4647
`bak list my_file` - List all .bakfiles *of the specified file*, with metadata
47-
`bak diff my_file <bakfile>` - Self-explanatory. Without .bakfile argument, diffs `my_file` against its most recent .bakfile. By default, uses [ydiff](https://github.com/ymattw/ydiff). Can be configured to use the difftool of your choice.
4848

4949
## Current state (updated Oct. 31, 2020)
5050
This is a very pre-alpha version, as in, this is a spaghetti proof-of-concept. Perhaps ~~5-6~~ 12-15 hours have been spent on development so far. As such, it's only "working" in the strictest sense.

bak/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from click_default_group import DefaultGroup
66

77
from . import commands
8-
# from . import data
9-
# # import data
108

119

1210
def __print_help():
@@ -84,5 +82,11 @@ def bak_get(to_where_you_once_belonged):
8482
commands.bak_getfile_cmd(to_where_you_once_belonged)
8583

8684

85+
@bak.command("diff")
86+
@click.argument("filename", required=True, type=click.Path(exists=True))
87+
def bak_diff(filename):
88+
commands.bak_diff_cmd(filename)
89+
90+
8791
if __name__ == "__main__":
8892
bak()

bak/commands/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _assemble_bakfile(filename):
4848
# TODO #26 get bakfile directory from config
4949
bakfile_path = os.path.join(bak_dir, bakfile_name)
5050

51-
new_bak_entry = bakfile.BakFile(filename,
51+
new_bak_entry = bakfile.BakFile(os.path.basename(filename),
5252
os.path.abspath(filename),
5353
bakfile_path,
5454
time_now,
@@ -60,7 +60,7 @@ def _assemble_bakfile(filename):
6060

6161

6262
def _get_bakfile_entry(filename, select_prompt=default_select_prompt, err=False):
63-
entries = db_handler.get_bakfile_entries(filename)
63+
entries = db_handler.get_bakfile_entries(expandpath(filename))
6464
if not entries or len(entries) == 0:
6565
return None
6666
return entries[0] if len(entries) == 1 else _do_select_bakfile(entries, select_prompt, err)
@@ -128,7 +128,7 @@ def create_bakfile(filename: str):
128128
# TODO descriptive failure
129129
return False
130130
new_bakfile = _assemble_bakfile(filename)
131-
copy2(new_bakfile.original_file, new_bakfile.bakfile_loc)
131+
copy2(new_bakfile.orig_abspath, new_bakfile.bakfile_loc)
132132
db_handler.create_bakfile_entry(new_bakfile)
133133

134134

@@ -245,3 +245,9 @@ def bak_getfile_cmd(bak_to_get: (str, bakfile.BakFile)):
245245
if not bak_to_get:
246246
return # _get_bakfile_entry() handles failures, so just exit
247247
click.echo(bak_to_get.bakfile_loc)
248+
249+
250+
def bak_diff_cmd(filename):
251+
# TODO configurable diff executable
252+
bak_to_diff = _get_bakfile_entry(expandpath(filename))
253+
call(['diff', bak_to_diff.bakfile_loc, bak_to_diff.orig_abspath])

bak/data/bak_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def del_bakfile_entry(self, bak_entry: BakFile):
3434
with sqlite3.connect(self.db_loc) as db_conn:
3535
db_conn.execute(
3636
"""
37-
DELETE FROM bakfiles WHERE original_file=:orig
38-
""", (bak_entry.original_file,))
37+
DELETE FROM bakfiles WHERE original_abspath=:orig
38+
""", (bak_entry.orig_abspath,))
3939
db_conn.commit()
4040

4141
def update_bakfile_entry(self,

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
click==7.1.2
22
click-default-group==1.2.2
3-
rich==9.1.0
4-
ydiff==1.2
3+
rich==9.1.0

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
require = ['click==7.1.2',
44
'click-default-group==1.2.2',
5-
'rich==9.1.0',
6-
'ydiff==1.2']
5+
'rich==9.1.0']
76

87
setup(name='bak',
98
version='0.0.1a',

0 commit comments

Comments
 (0)