tools

various tools I have been using throughout the years
Log | Files | Refs | README | LICENSE

commit 424407660e3c3ebcbf0e43c8d9efc2b5aaaba835
parent 19119d2fedbe539eb780c3d76bbcd9a8f66703f0
Author: mtmn <miro@haravara.org>
Date:   Tue, 11 Aug 2026 12:30:30 +0200

mpd: use current month on reports when unset

Diffstat:
Mmpd/README.md | 12++++++------
Mmpd/mpd_report_daily | 6+++---
Mmpd/mpd_report_monthly | 6+++---
Mmpd/tests/test_mpd_report_daily.py | 13+++++++++++++
Mmpd/tests/test_mpd_report_monthly.py | 25+++++++++++++++++++++++++
5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/mpd/README.md b/mpd/README.md @@ -18,8 +18,8 @@ starting with `#` are ignored. Use `-` for stdin. | `mpd_update_queue` | `[--force] [FILE\|-]` | Replace the queue while preserving playback where possible. | | `mpd_update_library` | `[--no-wait] [--rescan] [FILE\|-]` | Update unique top-level directories, or the whole database with terminal stdin. | | `mpd_report` | `[OPTIONS]` | Find database entries by `Last-Modified` time window. | -| `mpd_report_monthly` | `MONTH [YEAR] [MPD_REPORT_OPTION ...]` | Write the first four weekly reports for a month. | -| `mpd_report_daily` | `MONTH [YEAR] [MPD_REPORT_OPTION ...]` | Write daily reports for each day of a month. | +| `mpd_report_monthly` | `[MONTH [YEAR]] [MPD_REPORT_OPTION ...]` | Write the first four weekly reports for a month. | +| `mpd_report_daily` | `[MONTH [YEAR]] [MPD_REPORT_OPTION ...]` | Write daily reports for each day of a month. | Queue editing detects concurrent changes and attempts to restore the previous queue after a replacement failure. Playlist edits stage non-empty replacements @@ -34,15 +34,15 @@ path and `--output -` explicitly writes them to stdout. `--tracks-output FILE` atomically writes all song URIs during the same scan. `mpd_report_monthly` is a Ruby helper for the four weekly reports created by -`diggah -m MM -w`. Run `mpd_report_monthly 07 2026` to write +`diggah -m MM -w`. Run `mpd_report_monthly` (or `mpd_report_monthly 07 2026`) to write `1_07_2026.txt` through `4_07_2026.txt`; append `--files`, `--path URI`, or -other `mpd_report` options after `--`. It uses the current year when omitted, +other `mpd_report` options after `--`. It uses the current month and year when omitted. accepts `-o DIRECTORY`, and replaces reports atomically after a successful MPD query. -`mpd_report_daily` is a Ruby helper for daily reports. Run `mpd_report_daily 07 2026` to +`mpd_report_daily` is a Ruby helper for daily reports. Run `mpd_report_daily` (or `mpd_report_daily 07 2026`) to write `01_07_2026.txt` through `31_07_2026.txt`; append `--files`, `--path URI`, or -other `mpd_report` options after `--`. It uses the current year when omitted, +other `mpd_report` options after `--`. It uses the current month and year when omitted. accepts `-o DIRECTORY`, and replaces reports atomically after a successful MPD query. diff --git a/mpd/mpd_report_daily b/mpd/mpd_report_daily @@ -11,7 +11,7 @@ MANAGED_MPD_OPTIONS = %w[-i --indexed -o --output -w --window].freeze def main(arguments) options = {output_directory: "."} parser = OptionParser.new do |opts| - opts.banner = "Usage: #{opts.program_name} [-o DIRECTORY] MONTH [YEAR] [-- MPD_OPTION ...]" + opts.banner = "Usage: #{opts.program_name} [-o DIRECTORY] [MONTH [YEAR]] [-- MPD_OPTION ...]" opts.on("-o", "--output-dir DIRECTORY", "write reports beneath DIRECTORY") do |directory| options[:output_directory] = directory end @@ -26,8 +26,8 @@ def main(arguments) arguments.pop if arguments.last == "--" parser.parse!(arguments) - month = Integer(arguments.shift || raise(OptionParser::MissingArgument, "MONTH"), 10) - year = Integer(arguments.shift || Date.today.year, 10) + month = (v = arguments.shift) ? Integer(v, 10) : Date.today.month + year = (v = arguments.shift) ? Integer(v, 10) : Date.today.year raise OptionParser::InvalidArgument, arguments.first unless arguments.empty? first = Date.new(year, month, 1) diff --git a/mpd/mpd_report_monthly b/mpd/mpd_report_monthly @@ -12,7 +12,7 @@ MANAGED_MPD_OPTIONS = %w[-i --indexed -o --output -w --window].freeze def main(arguments) options = {output_directory: "."} parser = OptionParser.new do |opts| - opts.banner = "Usage: #{opts.program_name} [-o DIRECTORY] MONTH [YEAR] [-- MPD_OPTION ...]" + opts.banner = "Usage: #{opts.program_name} [-o DIRECTORY] [MONTH [YEAR]] [-- MPD_OPTION ...]" opts.on("-o", "--output-dir DIRECTORY", "write reports beneath DIRECTORY") do |directory| options[:output_directory] = directory end @@ -27,8 +27,8 @@ def main(arguments) arguments.pop if arguments.last == "--" parser.parse!(arguments) - month = Integer(arguments.shift || raise(OptionParser::MissingArgument, "MONTH"), 10) - year = Integer(arguments.shift || Date.today.year, 10) + month = (v = arguments.shift) ? Integer(v, 10) : Date.today.month + year = (v = arguments.shift) ? Integer(v, 10) : Date.today.year raise OptionParser::InvalidArgument, arguments.first unless arguments.empty? first = Date.new(year, month, 1) diff --git a/mpd/tests/test_mpd_report_daily.py b/mpd/tests/test_mpd_report_daily.py @@ -141,6 +141,19 @@ class MpdReportDailyTest(unittest.TestCase): self.assertTrue(expected.exists()) self.assertEqual(expected.read_text(), "Today\n") + def test_uses_current_month_when_month_omitted(self): + from datetime import date + current_year = date.today().year + current_month = date.today().month + with tempfile.TemporaryDirectory() as name: + directory = Path(name) + fake = self.make_fake(directory, "printf '0\tToday\n'\n") + result = self.run_helper(directory, fake) + self.assertEqual(result.returncode, 0, result.stderr) + expected = directory / f"01_{current_month:02d}_{current_year}.txt" + self.assertTrue(expected.exists()) + self.assertEqual(expected.read_text(), "Today\n") + if __name__ == "__main__": unittest.main() diff --git a/mpd/tests/test_mpd_report_monthly.py b/mpd/tests/test_mpd_report_monthly.py @@ -104,5 +104,30 @@ class MpdReportMonthlyTest(unittest.TestCase): self.assertIn("managed by this helper", result.stderr) + def test_uses_current_year_when_year_omitted(self): + from datetime import date + current_year = date.today().year + with tempfile.TemporaryDirectory() as name: + directory = Path(name) + fake = self.make_fake(directory, "printf '0\tWeek1\n'\n") + result = self.run_helper(directory, fake, "01") + self.assertEqual(result.returncode, 0, result.stderr) + expected = directory / f"1_01_{current_year}.txt" + self.assertTrue(expected.exists()) + self.assertEqual(expected.read_text(), "Week1\n") + + def test_uses_current_month_when_month_omitted(self): + from datetime import date + current_year = date.today().year + current_month = date.today().month + with tempfile.TemporaryDirectory() as name: + directory = Path(name) + fake = self.make_fake(directory, "printf '0\tWeek1\n'\n") + result = self.run_helper(directory, fake) + self.assertEqual(result.returncode, 0, result.stderr) + expected = directory / f"1_{current_month:02d}_{current_year}.txt" + self.assertTrue(expected.exists()) + self.assertEqual(expected.read_text(), "Week1\n") + if __name__ == "__main__": unittest.main()