From ff01015b613c8b58663c082aab71070eca2636c0 Mon Sep 17 00:00:00 2001 From: Guilherme Danno Date: Mon, 18 Jan 2016 22:41:08 -0200 Subject: [PATCH 1/2] Fields: Print flexible attributes --- beets/ui/commands.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 0022fac74..28893cd1f 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -79,6 +79,14 @@ def _do_query(lib, query, album, also_items=True): return items, albums +def _print_sqlite(query): + """Gets the result of the query, transforms the sqlite3.Row in dictionary + entries and print the values of it, with identation of 2 spaces. + """ + for row in query: + print_(' ' * 2 + dict(zip(row.keys(), row))['key']) + + # fields: Shows a list of available fields for queries and format strings. def fields_func(lib, opts, args): @@ -92,6 +100,15 @@ def fields_func(lib, opts, args): print_("Album fields:") _print_rows(library.Album.all_keys()) + with lib.transaction() as tx: + # The SQL uses the DISTINCT to get unique values from the query + unique_fields = 'SELECT DISTINCT key FROM (%s)' + + print_("Item flexible attributes:") + _print_sqlite(tx.query(unique_fields % library.Item._flex_table)) + + print_("Album flexible attributes:") + _print_sqlite(tx.query(unique_fields % library.Album._flex_table)) fields_cmd = ui.Subcommand( 'fields', From 4605016c65edfd72083790ad86efc4692c046c35 Mon Sep 17 00:00:00 2001 From: Guilherme Danno Date: Thu, 28 Jan 2016 18:18:08 -0200 Subject: [PATCH 2/2] Changelog for #1818 --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 51fab3100..ecb70f8de 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -20,6 +20,8 @@ New: session. :bug:`1779` * :doc:`/plugins/info`: A new option will print only fields' names and not their values. Thanks to :user:`GuilhermeHideki`. :bug:`1812` +* The :ref:`fields-cmd` command now displays flexible attributes. + Thanks to :user:`GuilhermeHideki`. :bug:`1818` .. _AcousticBrainz: http://acousticbrainz.org/