Skip to content

Commit

Permalink
Added --init argument
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalec committed Aug 29, 2023
1 parent cf444fa commit aa9aaea
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deemon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
from deemon.utils import startup

__version__ = '2.19.3'
__version__ = '2.20'
__dbversion__ = '3.7'

appdata = startup.get_appdata_dir()
Expand Down
8 changes: 7 additions & 1 deletion deemon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
@click.group(context_settings=CONTEXT_SETTINGS, invoke_without_command=True,
no_args_is_help=True)
@click.option('--whats-new', is_flag=True, help="Show release notes from this version")
@click.option('--init', is_flag=True, help="""Initialize deemon application data
directory. Warning: if directory exists, this will delete existing config and database.""")
@click.option('-P', '--profile', help="Specify profile to run deemon as")
@click.version_option(__version__, '-V', '--version', message='deemon %(version)s')
@click.option('-v', '--verbose', is_flag=True, help="Show debug output")
def run(whats_new, verbose, profile):
def run(whats_new, init, verbose, profile):
"""Monitoring and alerting tool for new music releases using the Deezer API.
deemon is a free and open source tool. To report issues or to contribute,
Expand All @@ -54,6 +56,10 @@ def run(whats_new, verbose, profile):
if whats_new:
return startup.get_changelog(__version__)

if init:
app_data_path = startup.get_appdata_dir()
startup.reinit_appdata_dir(app_data_path)

config = Config()
db = Database()

Expand Down
15 changes: 15 additions & 0 deletions deemon/utils/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ def init_appdata_dir(appdata):
Path(appdata / 'backups').mkdir(exist_ok=True)


def delete_appdata(appdata):
import shutil
try:
shutil.rmtree(appdata)
except OSError as e:
logger.info(f"Error while deleting path: {e}")

def reinit_appdata_dir(appdata):
if appdata.exists():
logger.info("Deleting existing application data directory (config, database, etc.)")
delete_appdata(appdata)
logger.info("Initializing new application data directory...")
init_appdata_dir(appdata)


def get_config():
return get_appdata_dir() / 'config.json'

Expand Down
20 changes: 19 additions & 1 deletion docs/docs/commands/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,22 @@ title: Commands
nav_order: 4
has_children: true
permalink: /docs/commands
---
---

# arguments
{: .no_toc }

## Table of contents
{: .no_toc .text-delta }

1. TOC
{:toc}

---
The following arguments may be run directly after `deemon`:

`--whats-new` - prints current version release notes from GitHub
`--init` - Initializes deemon's application data directory. (*If directory exists, it will be deleted!*)
`-P ID`, `--profile ID` - Uses specified profile ID
`-V` - Prints current version and exits
`-v`, `--verbose` - Show all verbose log messages

0 comments on commit aa9aaea

Please sign in to comment.