Skip to content

Commit 936bcda

Browse files
committed
Clean up debug_prints
1 parent f21f927 commit 936bcda

3 files changed

Lines changed: 40 additions & 46 deletions

File tree

__init__.py

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
from __future__ import (unicode_literals, division, absolute_import, print_function)
1+
#!/usr/bin/env python3
22

3-
from calibre import browser
3+
from functools import partial
4+
5+
from calibre.constants import numeric_version
46
from calibre.customize import StoreBase
5-
from calibre.devices.usbms.driver import debug_print
7+
from calibre.devices.usbms.driver import debug_print as root_debug_print
68
from calibre.gui2 import open_url
79
from calibre.gui2.store import StorePlugin
810
from calibre.gui2.store.search_result import SearchResult
911
from calibre.gui2.store.web_store_dialog import WebStoreDialog
1012
from PyQt5.Qt import QUrl
1113

12-
from .libgen_client import LibgenFictionClient
14+
from calibre_plugins.libgen_fiction.libgen_client import LibgenFictionClient
1315

14-
store_version = 5 # Needed for dynamic plugin loading
16+
if numeric_version >= (5, 5, 0):
17+
module_debug_print = partial(root_debug_print, ' the_eye:__init__:', sep='')
18+
else:
19+
module_debug_print = partial(root_debug_print, 'the_eye:__init__:')
1520

16-
__license__ = 'MIT'
17-
__copyright__ = 'fallaciousreasoning'
18-
__docformat__ = 'restructuredtext en'
21+
__license__ = 'MIT'
22+
__copyright__ = 'fallaciousreasoning'
23+
__docformat__ = 'restructuredtext en'
1924

20-
PLUGIN_NAME = 'Libgen Fiction'
21-
PLUGIN_DESCRIPTION = 'Adds a Libgen Fiction search provider to Calibre'
22-
PLUGIN_AUTHORS = "fallaciousreasoning (https://github.com/fallaciousreasoning/CalibreLibgenStore)"
23-
PLUGIN_VERSION = (0, 2, 0)
25+
PLUGIN_NAME = 'Libgen Fiction'
26+
PLUGIN_DESCRIPTION = 'Adds a Libgen Fiction search provider to calibre'
27+
PLUGIN_AUTHORS = 'fallaciousreasoning (https://github.com/fallaciousreasoning/CalibreLibgenStore)'
28+
PLUGIN_VERSION = (0, 4, 0)
2429

2530
class LibgenStore(StorePlugin):
2631
def genesis(self):
27-
'''
28-
Initialize the Libgen Client
29-
'''
30-
debug_print('Libgen Fiction::__init__.py:LibgenStore:genesis')
32+
"""Initialize the Libgen Client
33+
"""
34+
debug_print = partial(module_debug_print, 'LibgenStore:genesis:')
35+
debug_print('start')
3136

3237
self.libgen = LibgenFictionClient()
3338

3439
def search(self, query, max_results=10, timeout=60):
35-
'''
36-
Searches LibGen for Books. Since the mirror links are not direct
40+
"""Searches LibGen for Books. Since the mirror links are not direct
3741
downloads, it should not provide these as `s.downloads`.
38-
'''
39-
40-
debug_print('Libgen Fiction::__init__.py:LibgenStore:search:query =',
41-
query)
42+
"""
43+
debug_print = partial(module_debug_print, 'LibgenStore:search:')
44+
debug_print('search:query = ', query)
4245

4346
libgen_results = self.libgen.search(query)
4447

4548
for result in libgen_results.results[:min(max_results, len(libgen_results.results))]:
46-
debug_print('Libgen Fiction::__init__.py:LibgenStore:search:'
47-
'result.title =',
48-
result.title)
49+
debug_print('result.title = ', result.title)
4950

5051
for mirror in result.mirrors[0:1]: # Calibre only shows 1 anyway
51-
debug_print('Libgen Fiction::__init__.py:LibgenStore:search:'
52-
'result.mirror.url =', mirror.url)
52+
debug_print('result.mirror.url = ', mirror.url)
5353

5454
s = SearchResult()
5555

@@ -64,27 +64,23 @@ def search(self, query, max_results=10, timeout=60):
6464
s.formats = mirror.format
6565
s.plugin_author = PLUGIN_AUTHORS
6666

67-
debug_print('Libgen Fiction::__init__.py:LibgenStore:search:s =',
68-
s)
67+
debug_print('s = ', s)
6968

7069
yield s
7170

7271
def open(self, parent=None, detail_item=None, external=False):
73-
'''
74-
Open the specified item in the external, or Calibre's browser
75-
'''
76-
77-
debug_print('Libgen Fiction::__init__.py:LibgenStore:open:locals() =',
78-
locals())
72+
"""Open the specified item in the external, or Calibre's browser
73+
"""
74+
debug_print = partial(module_debug_print, 'LibgenStore:open:')
75+
debug_print('locals() = ', locals())
7976

8077
detail_url = (
8178
self.libgen.get_detail_url(detail_item)
8279
if detail_item
8380
else self.libgen.base_url
8481
)
8582

86-
debug_print('Libgen Fiction::__init__.py:LibgenStore:open:detail_url =',
87-
detail_url)
83+
debug_print('detail_url = ', detail_url)
8884

8985
if external or self.config.get('open_external', False):
9086
open_url(QUrl(detail_url))
@@ -97,23 +93,20 @@ def open(self, parent=None, detail_item=None, external=False):
9793

9894
def get_details(self, search_result, details):
9995
url = self.libgen.get_detail_url(search_result.detail_item)
100-
10196
download = self.libgen.get_download_url(search_result.detail_item)
10297
search_result.downloads[search_result.formats] = download
103-
98+
10499
class LibgenStoreWrapper(StoreBase):
105100
name = PLUGIN_NAME
106101
description = PLUGIN_DESCRIPTION
107-
supported_platforms = ['windows', 'osx', 'linux']
108102
author = PLUGIN_AUTHORS
109103
version = PLUGIN_VERSION
110-
minimum_calibre_version = (1, 0, 0)
104+
minimum_calibre_version = (5, 0, 1) # Because Python 3
111105
affiliate = False
112106
drm_free_only = True
113107

114108
def load_actual_plugin(self, gui):
115-
'''
116-
This method must return the actual interface action plugin object.
117-
'''
109+
"""This method must return the actual interface action plugin object.
110+
"""
118111
self.actual_plugin_object = LibgenStore(gui, self.name)
119112
return self.actual_plugin_object

about.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p>Libgen Fiction</p>
22
<ul>
3-
<li>A Libgen Fiction store plugin for Calibre.</li>
3+
<li>Adds a Libgen Fiction search provider to calibre.</li>
44
<li>Please report any errors or requests on <a href="https://github.com/fallaciousreasoning/CalibreLibgenStore/issues">this plugin’s GitHub repository page</a>.</li>
55
</ul>

libgen_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#!/usr/bin/env python3
2+
13
from lxml import etree
24
import random
35
import urllib
46

57

6-
78
def xpath(node, path):
89
tree = node.getroottree()
910
base_xpath = tree.getpath(node)

0 commit comments

Comments
 (0)