From: kaliko <kaliko@azylum.org>
Date: Fri, 23 Apr 2021 09:23:03 +0000 (+0200)
Subject: Add new command purge-history
X-Git-Tag: 0.17.0~2
X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=abb05a55c1b6c27a11bbd90efbc594ad6331bbc6;p=mpd-sima.git

Add new command purge-history
---

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 <kaliko@azylum.org>
 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
-.\"      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/
       <arg choice="plain">generate-config</arg>
       <arg choice="opt"><option>…</option></arg>
     </cmdsynopsis>
+    <cmdsynopsis>
+      <command>&dhpackage;</command>
+      <arg choice="plain">purge-history</arg>
+      <arg choice="opt"><option>--var-dir=</option><replaceable class="option">var_directory</replaceable></arg>
+    </cmdsynopsis>
   </refsynopsisdiv>
   <refsect1 id="description">
     <title>DESCRIPTION</title>
@@ -235,6 +240,12 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
                 <para>Generate a sample configuration file according to the current CLI options and env. var.. The configuration is written on stdout.</para>
             </listitem>
         </varlistentry>
+        <varlistentry> <!-- purge-history -->
+            <term><option>purge-history</option></term>
+            <listitem>
+                <para>Purge play history in the database and exit. Uses folder specified with <option>--var-dir</option> or default directory.<sbr />Default is to use <envar>$XDG_DATA_HOME/mpd_sima/</envar> (see <xref linkend="files"/> for more).</para>
+            </listitem>
+        </varlistentry>
     </variablelist>
   </refsect1>
   <xi:include href="files.xml" />
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 <kaliko@azylum.org>  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.