Skip to content

Commit

Permalink
Refactored duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-corneliusson committed Oct 17, 2021
1 parent 2ab7a16 commit c435cd0
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions click_web/resources/cmd_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,7 @@ def save(self):

def after_script_executed(self):
super().after_script_executed()
fd, filename = tempfile.mkstemp(dir=self.temp_dir(), prefix=self.key)
folder_path = self.file_path
self.file_path = filename

logger.info(f'Zipping {self.key} to {filename}')
self.file_path = shutil.make_archive(self.file_path, 'zip', folder_path)
logger.info(f'Zip file created {self.file_path}')
self.file_path = zip_folder(self.file_path, self.temp_dir(), out_prefix=self.key)
self.generate_download_link = True


Expand All @@ -447,10 +441,13 @@ def save(self):

def after_script_executed(self):
super().after_script_executed()
fd, filename = tempfile.mkstemp(dir=self.temp_dir(), prefix=self.key)
folder_path = self.file_path
self.file_path = filename
logger.info(f'Zipping {self.key} to {filename}')
self.file_path = shutil.make_archive(self.file_path, 'zip', folder_path)
logger.info(f'Zip file created {self.file_path}')
self.file_path = zip_folder(self.file_path, self.temp_dir(), out_prefix=self.key)
self.generate_download_link = True


def zip_folder(folder_path, out_folder, out_prefix):
fd, out_base_name = tempfile.mkstemp(dir=out_folder, prefix=out_prefix)
logger.info(f'Zipping {folder_path}')
zip_file_path = shutil.make_archive(out_base_name, 'zip', folder_path)
logger.info(f'Zip file created {zip_file_path}')
return zip_file_path

0 comments on commit c435cd0

Please sign in to comment.