Skip to content

Commit

Permalink
Added backup command (close #248)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Dec 17, 2020
1 parent c256e8a commit 300e7db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,15 @@ def backup_check(self):
return False

def backup_wtf(self, console):
zipf = zipfile.ZipFile(Path('WTF-Backup', f'{datetime.datetime.now().strftime("%d%m%y")}.zip'), 'w',
zipfile.ZIP_DEFLATED)
archive = Path('WTF-Backup', f'{datetime.datetime.now().strftime("%d%m%y")}.zip')
if os.path.isfile(archive):
suffix = 1
while True:
archive = Path('WTF-Backup', f'{datetime.datetime.now().strftime("%d%m%y")}-{suffix}.zip')
if not os.path.isfile(archive):
break
suffix += 1
zipf = zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED)
filecount = 0
for _, _, files in os.walk('WTF/', topdown=True, followlinks=True):
files = [f for f in files if not f[0] == '.']
Expand Down
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
from rich.terminal_theme import TerminalTheme

__version__ = '3.15.5'
__version__ = '3.16.0'
__license__ = 'GPLv3'
__copyright__ = '2019-2020, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
5 changes: 5 additions & 0 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def setup_completer(self):
'orphans': None,
'search': None,
'recommendations': None,
'backup': None,
'import': {'install': None},
'export': None,
'toggle': {'authors': None,
Expand Down Expand Up @@ -810,6 +811,9 @@ def c_recommendations(self, _):
if not found:
self.console.print('Not found any recommendations for you. Good job!')

def c_backup(self, _):
self.core.backup_wtf(None if self.headless else self.console)

def c_import(self, args):
hit, partial_hit, miss = self.core.detect_addons()
if args == 'install' and len(hit) > 0:
Expand Down Expand Up @@ -857,6 +861,7 @@ def c_help(self, _):
'[green]search [Keyword][/green]\n\tExecutes addon search on CurseForge.\n'
'[green]recommendations[/green]\n\tCheck the list of currently installed addons against a co'
'mmunity-driven database of tips.\n'
'[green]backup[/green]\n\tCommand creates a backup of WTF directory.\n'
'[green]import[/green]\n\tCommand attempts to import already installed addons.\n'
'[green]export[/green]\n\tCommand prints list of all installed addons in a form suitable f'
'or sharing.\n'
Expand Down

0 comments on commit 300e7db

Please sign in to comment.