01-07-2018, 10:08 AM | #1 |
Member
Posts: 12
Karma: 10
Join Date: Jan 2015
Device: none
|
Access "Categories with hierarchical items"
Under calibre-debug, what is the right way to access the group of fields that I have defined in the GUI under "Look & Feel" --> "Tag Browser -->" "Categories with hierarchical items"? I have tried gprefs and similar fields in various modules, but I don't appear to be hitting it. Thanks!
|
01-07-2018, 10:19 AM | #2 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
This one is stored per library, along with a lot of others. You can see which by looking at the "preferences" table in metadata.db. The preference you are asking about is
Code:
self.db.prefs.get('categories_using_hierarchy', []) |
01-07-2018, 11:34 AM | #3 |
Member
Posts: 12
Karma: 10
Join Date: Jan 2015
Device: none
|
Thanks for the prompt reply. I am self-taught re Python/sqlite/etc., which means I am great in some areas and woefully deficient in others - which explains why I ask the below:
I read your response to mean accessing attributes of an object "db", but how should I go about accessing/creating this object? I know from the api documentation how to establish a cache object (i.e. from calibre.library import db; db=db('Path to calibre library folder').new_api), but am gathering that this is not what you mean since this db object has no attribute "prefs". Thanks for your patience here. |
01-07-2018, 12:03 PM | #4 |
Member
Posts: 12
Karma: 10
Join Date: Jan 2015
Device: none
|
I've now found a method that produces the result I am looking for:
from calibre.library import database2 db = database2.LibraryDatabase2('Path to calibre library folder') print(db.prefs.get('categories_using_hierarchy')) My revised question: is this the best/most efficient way to get this info? I don't have a good feel for how this object is different than the cache object "from calibre.library import db; db=db('Path to calibre library folder').new_api", so would be interested in your thoughts here as well. Thanks for you time once again. |
01-07-2018, 12:58 PM | #5 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Any new calibre code should use the "new_api", so you should use the first method you described to get a db object.
Code:
from calibre.library import db; db=db('Path to calibre library folder').new_api A "new_api" object is an instance of calibre.db.cache.Cache. Look there for "public" methods, properties, and attributes. For example db.prefs is a method (line 609): Code:
@read_api def pref(self, name, default=None): ' Return the value for the specified preference or the value specified as ``default`` if the preference is not set. ' return self.backend.prefs.get(name, default) Code:
db.prefs.get('categories_using_hierarchy') Code:
db.prefs.get('categories_using_hierarchy', []) |
01-07-2018, 01:42 PM | #6 |
creator of calibre
Posts: 43,856
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The db Cache objects API is documented in the manual, at https://manual.calibre-ebook.com/db_api.html
|
01-07-2018, 03:38 PM | #7 |
Member
Posts: 12
Karma: 10
Join Date: Jan 2015
Device: none
|
Very helpful! Understand your point on always using "new_api". I saw the pref method here before, but until today didn't know the specific preference name I should enter to get what I wanted (i.e. 'categories_using_hierarchy'). Appreciate the hint as well - makes sense.
At the risk of overstaying my welcome in this thread, one final clarification: what's the right way to get a list of all possible preference names that I could pass to "db.pref()" such that, in the future, I could determine the calibre name for the specific preference I want? The initial answer above mentions looking at a preferences table - is this something that I would/should do using my new_api db object somehow? |
01-07-2018, 04:01 PM | #8 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
That said, this snippet will give you the names of all the library-specific preferences. Personally I think it is easier to look at the db using some db explorer (I use SQLiteSpy) because that lets you explore the values of the preferences in addition to the names. And yes, this snippet uses the old API. Code:
from calibre.db.legacy import LibraryDatabase db = LibraryDatabase(sys.argv[1]) all_prefs = db.prefs.iterkeys() for t in all_prefs: print t |
|
01-07-2018, 04:22 PM | #9 |
Member
Posts: 12
Karma: 10
Join Date: Jan 2015
Device: none
|
Got it! I didn't get that when you initially mentioned looking at the preferences table, you meant using a tool outside of the Calibre api. Understand your point - I agree with looking at source code as the first step. Also appreciate you providing the old API code snippet.
I looked at metadata.db with Sqliteman and found the preferences table just as you mentioned, so I see how I could preference names next time if/as needed. Thanks very much for your helpful replies! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
All my documents from "My Items" list on Kindle Touch disappeared | kinkle | Kindle Developer's Corner | 33 | 03-02-2016 02:42 PM |
Kindle Paperwhite displaying "My Items (0)"; Ideas? | CuriousJay | Amazon Kindle | 15 | 01-15-2014 03:58 AM |
Recipe for Safari "Reading List" unread items | anoved | Recipes | 6 | 03-19-2013 01:21 PM |
Select multiple items in "Check library results" window | Pepin33 | Library Management | 2 | 08-01-2012 11:10 AM |
Kindle for PC "Failed to sync and check for new items" | curtw | Amazon Kindle | 4 | 02-16-2011 10:20 PM |