From abb05a55c1b6c27a11bbd90efbc594ad6331bbc6 Mon Sep 17 00:00:00 2001 From: kaliko Date: Fri, 23 Apr 2021 11:23:03 +0200 Subject: [PATCH] Add new command purge-history --- data/bash/completion.sh | 3 ++- data/man/mpd-sima.1 | 19 +++++++++++++++++-- data/man/mpd_sima.1.xml | 11 +++++++++++ doc/Changelog | 4 ++-- sima/launch.py | 8 ++++++++ sima/utils/startopt.py | 1 + 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/data/bash/completion.sh b/data/bash/completion.sh index 11f1713..3defa72 100644 --- a/data/bash/completion.sh +++ b/data/bash/completion.sh @@ -36,7 +36,8 @@ _sima() { --var-dir \ -d --daemon \ config-test \ - generate-config" + generate-config \ + purge-history" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) diff --git a/data/man/mpd-sima.1 b/data/man/mpd-sima.1 index b676ecd..7d039e1 100644 --- a/data/man/mpd-sima.1 +++ b/data/man/mpd-sima.1 @@ -2,12 +2,12 @@ .\" Title: mpd-sima .\" Author: kaliko .\" Generator: DocBook XSL Stylesheets v1.79.2 -.\" Date: 04/22/2021 +.\" Date: 04/23/2021 .\" Manual: mpd-sima 0.17.0 User Manual .\" Source: mpd-sima .\" Language: English .\" -.TH "MPD\-SIMA" "1" "04/22/2021" "mpd-sima" "mpd-sima 0.17.0 User Manual" +.TH "MPD\-SIMA" "1" "04/23/2021" "mpd-sima" "mpd-sima 0.17.0 User Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -40,6 +40,8 @@ mpd-sima \- mpd\-sima will try to maintain some titles ahead in the queue follow \fBmpd\-sima\fR create\-db [\fB\-\-var\-dir=\fR\fIvar_directory\fR] .HP \w'\fBmpd\-sima\fR\ 'u \fBmpd\-sima\fR generate\-config [\fB\&...\fR] +.HP \w'\fBmpd\-sima\fR\ 'u +\fBmpd\-sima\fR purge\-history [\fB\-\-var\-dir=\fR\fIvar_directory\fR] .SH "DESCRIPTION" .PP This manual page documents briefly the @@ -220,6 +222,19 @@ for more)\&. .RS 4 Generate a sample configuration file according to the current CLI options and env\&. var\&.\&. The configuration is written on stdout\&. .RE +.PP +\fBpurge\-history\fR +.RS 4 +Purge play history in the database and exit\&. Uses folder specified with +\fB\-\-var\-dir\fR +or default directory\&. +.br +Default is to use +\fB$XDG_DATA_HOME/mpd_sima/\fR +(see +the section called \(lqFILES\(rq +for more)\&. +.RE .SH "FILES" .PP ${XDG_CONFIG_HOME}/mpd_sima/mpd_sima\&.cfg diff --git a/data/man/mpd_sima.1.xml b/data/man/mpd_sima.1.xml index 7d4269a..a67b4e5 100644 --- a/data/man/mpd_sima.1.xml +++ b/data/man/mpd_sima.1.xml @@ -100,6 +100,11 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ generate-config + + &dhpackage; + purge-history + var_directory + DESCRIPTION @@ -235,6 +240,12 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ Generate a sample configuration file according to the current CLI options and env. var.. The configuration is written on stdout. + + + + Purge play history in the database and exit. Uses folder specified with or default directory.Default is to use $XDG_DATA_HOME/mpd_sima/ (see for more). + + diff --git a/doc/Changelog b/doc/Changelog index e56ec8b..9be8db4 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -8,8 +8,8 @@ MPD_sima v0.17.0.dev0 * Use duration instead of time in Track objects (closes #37) * Move "test-tags-config" as positional argument "config-test" * Move "--create-db" as positional argument "create-db" - * Add commands as positional arguments: - config-test, create-db, generate-config + * Add mpd-sima commands as positional arguments: + config-test, create-db, generate-config, purge-history -- kaliko UNRELEASED diff --git a/sima/launch.py b/sima/launch.py index a8e285e..9cd3623 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -110,6 +110,14 @@ def start(sopt, restart=False): else: logger.info('Database already there, not overwriting %s', db_file) sys.exit(0) + if cmd == "purge-history": + db_file = config.get('sima', 'db_file') + if not isfile(db_file): + logger.warning('No db found: %s', db_file) + sys.exit(1) + SimaDB(db_path=db_file).purge_history(duration=0) + sys.exit(0) + # TODO: To remove eventually in next major realese v0.18 # Create Database diff --git a/sima/utils/startopt.py b/sima/utils/startopt.py index cdcfcec..6208d68 100644 --- a/sima/utils/startopt.py +++ b/sima/utils/startopt.py @@ -44,6 +44,7 @@ def clean_dict(to_clean): CMDS = {'config-test': 'Test configuration (MPD connection and Tags plugin only)', 'create-db': 'Create the database', 'generate-config': 'Generate a configuration file to stdout', + 'purge-history': 'Remove play history' } # OPTIONS LIST # pop out 'sw' value before creating Parser object. -- 2.39.2