Skip to content

Commit

Permalink
-U only removes related tiger files. Fixes #8.
Browse files Browse the repository at this point in the history
--UNARCHIVE and `Unarchive and Remove Tiger Files` in the GUI now only
remove related tiger files (created by the archived file). The output
directory can still be cleared with `Remove Tiger Files`.

When a file is archived, a list of created files is created and saved
to `<archive_file>.info`. These info files are removed when unarchiving.

This solves issue #8.
  • Loading branch information
cjwelborn committed Apr 25, 2019
1 parent 8ae02aa commit 41e3d75
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 97 deletions.
11 changes: 3 additions & 8 deletions lib/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,16 +701,11 @@ def cmd_menu_remove_tiger_files(self):
)
return True

def cmd_menu_unarchive(self, remove_tiger_files=False):
def cmd_menu_unarchive(self, remove_created=False):
""" Handles btn_unarchive click. """
if not self.validate_dirs(ignore_dirs=('tiger', 'mozaik')):
return False

if remove_tiger_files:
report_cb = self.cmd_menu_remove_tiger_files
else:
report_cb = None

self.enable_interface(False)
self.win_unarchive = WinUnarchive(
self,
Expand All @@ -719,15 +714,15 @@ def cmd_menu_unarchive(self, remove_tiger_files=False):
'geometry_unarchive': self.settings['geometry_unarchive'],
},
destroy_cb=lambda: self.enable_interface(True),
report_cb=report_cb,
arch_dir=self.entry_arch.get(),
dat_dir=self.entry_dat.get(),
remove_created=remove_created,
)
return True

def cmd_menu_unarchive_and_remove(self):
""" Handles menu->Unarchive and Remove Tiger Files """
return self.cmd_menu_unarchive(remove_tiger_files=True)
return self.cmd_menu_unarchive(remove_created=True)

def cmd_menu_viewer(self, filepaths=None, preview_files=None):
""" Handles menu->Tiger Viewer click. """
Expand Down
44 changes: 24 additions & 20 deletions lib/gui/unarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
class WinUnarchive(WinToplevelBase):
def __init__(
self, *args,
settings, destroy_cb, report_cb, arch_dir, dat_dir,
settings, destroy_cb, arch_dir, dat_dir,
remove_created=False,
**kwargs):

self.settings = settings
self.destroy_cb = destroy_cb
self.report_cb = report_cb
self.arch_dir = arch_dir
self.dat_dir = dat_dir
self.remove_created = remove_created
super().__init__(*args, **kwargs)
self.debug_settings()

Expand Down Expand Up @@ -241,18 +242,29 @@ def cmd_btn_unarchive(self):
for archfile in targetinfo:
archive_files.append(archfile.filepath)
try:
archfile.unarchive()
archfile.unarchive(
remove_created=self.remove_created
)
except OSError as ex:
errs.append((archfile.dest_path, str(ex)))
else:
success.append(archfile.filepath)
success.append(
(archfile.filepath, len(archfile.created_files))
)

config_increment(unarchive_files=len(success), default=0)

success_msgs = []
for filepath, created_len in success:
success_msgs.append(trim_file_path(filepath))
success_msgs.append('...Removed {} created {}.'.format(
created_len,
'file' if created_len == 1 else 'files',
))
self.show_report(
archive_files,
errs,
success,
[trim_file_path(s) for s in archive_files],
[(trim_file_path(s), m) for s, m in errs],
success_msgs,
)
return True

Expand Down Expand Up @@ -310,13 +322,7 @@ def show_report(self, parent_files, error_files, success_files):
"""
# self.report_closed() will re-enable the interface.
self.enable_interface(False)
if self.report_cb is None:
destroy_cb = self.destroy
else:
destroy_cb = [
self.destroy,
self.report_cb,
]

reportmsg = 'Success'
if error_files:
reportmsg = 'Errors: {}'.format(len(error_files))
Expand All @@ -327,12 +333,10 @@ def show_report(self, parent_files, error_files, success_files):
settings={
'geometry_report': self.settings['geometry_report'],
},
destroy_cb=destroy_cb,
parent_files=[trim_file_path(s) for s in parent_files],
error_files=[
(trim_file_path(s), m) for s, m in error_files
],
success_files=[trim_file_path(s) for s in success_files],
destroy_cb=self.destroy,
parent_files=parent_files,
error_files=error_files,
success_files=success_files,
parent_name='Archive',
success_name='Restored',
)
Expand Down
Loading

0 comments on commit 41e3d75

Please sign in to comment.