mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Complete migration to new resources framework
This commit is contained in:
parent
f2cc9ebf0b
commit
66a6887fc1
@ -9,6 +9,8 @@ dist
|
||||
docs
|
||||
resources/localization
|
||||
resources/images.qrc
|
||||
resources/recipes.pickle
|
||||
resources/scripts.pickle
|
||||
installer/windows/calibre/build.log
|
||||
src/calibre/translations/.errors
|
||||
src/cssutils/.svn/
|
||||
|
@ -11,6 +11,7 @@ __all__ = [
|
||||
'build',
|
||||
'gui',
|
||||
'develop',
|
||||
'resources',
|
||||
'check',
|
||||
]
|
||||
|
||||
@ -33,6 +34,9 @@ gui = GUI()
|
||||
from setup.check import Check
|
||||
check = Check()
|
||||
|
||||
from setup.resources import Resources
|
||||
resources = Resources()
|
||||
|
||||
commands = {}
|
||||
for x in __all__:
|
||||
commands[x] = locals()[x]
|
||||
|
57
setup/resources.py
Normal file
57
setup/resources.py
Normal file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import with_statement
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, cPickle
|
||||
|
||||
from setup import Command, basenames
|
||||
|
||||
class Resources(Command):
|
||||
|
||||
def get_recipes(self):
|
||||
sdir = os.path.join('src', 'calibre', 'web', 'feeds', 'recipes')
|
||||
resources= {}
|
||||
files = []
|
||||
for f in os.listdir(sdir):
|
||||
if f.endswith('.py') and f != '__init__.py':
|
||||
files.append(os.path.join(sdir, f))
|
||||
resources[f.replace('.py', '')] = open(files[-1], 'rb').read()
|
||||
return resources, files
|
||||
|
||||
|
||||
def run(self, opts):
|
||||
scripts = {}
|
||||
for x in ('console', 'gui'):
|
||||
for name in basenames[x]:
|
||||
if name in ('calibre-complete', 'calibre_postinstall'):
|
||||
continue
|
||||
scripts[name] = x
|
||||
|
||||
dest = self.j(self.RESOURCES, 'scripts.pickle')
|
||||
if self.newer(dest, self.j(self.SRC, 'calibre', 'linux.py')):
|
||||
self.info('\tCreating scripts.pickle')
|
||||
f = open(dest, 'wb')
|
||||
cPickle.dump(scripts, f, -1)
|
||||
|
||||
recipes, files = self.get_recipes()
|
||||
|
||||
dest = self.j(self.RESOURCES, 'recipes.pickle')
|
||||
if self.newer(dest, files):
|
||||
self.info('\tCreating recipes.pickle')
|
||||
f = open(dest, 'wb')
|
||||
cPickle.dump(recipes, f, -1)
|
||||
|
||||
|
||||
def clean(self):
|
||||
for x in ('scripts', 'recipes'):
|
||||
x = self.j(self.RESOURCES, x+'.pickle')
|
||||
if os.path.exists(x):
|
||||
os.remove(x)
|
||||
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@ def get_metadata(stream):
|
||||
_('Unknown'))))[0]
|
||||
for x in XPath('//fb2:book-title')(root):
|
||||
title = tostring(x)
|
||||
break
|
||||
comments = ''
|
||||
for x in XPath('//fb2:annotation')(root):
|
||||
comments += tostring(x)
|
||||
|
@ -1,6 +1,6 @@
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
import time, os
|
||||
import time, os, cPickle
|
||||
|
||||
from PyQt4.QtCore import SIGNAL, QUrl
|
||||
from PyQt4.QtGui import QDesktopServices
|
||||
@ -185,9 +185,10 @@ class %(classname)s(%(base_class)s):
|
||||
|
||||
def add_builtin_recipe(self):
|
||||
from calibre.web.feeds.recipes import recipes, recipe_modules, english_sort
|
||||
from calibre.resources import recipes as rdat
|
||||
from PyQt4.Qt import QInputDialog
|
||||
|
||||
rdat = cPickle.load(open(P('recipes.pickle'), 'rb'))
|
||||
|
||||
class Recipe(object):
|
||||
def __init__(self, title, id, recipes):
|
||||
self.title = unicode(title)
|
||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys, os
|
||||
import sys, os, cPickle
|
||||
|
||||
AUTHTOOL="""#!/usr/bin/python
|
||||
import os
|
||||
@ -29,8 +29,11 @@ DEST_PATH = '/usr/bin'
|
||||
def create_symlinks():
|
||||
return create_symlinks_new() if getattr(sys, 'new_app_bundle', False) else create_symlinks_old()
|
||||
|
||||
def get_scripts():
|
||||
return cPickle.load(open(P('scripts.pickle'), 'rb'))
|
||||
|
||||
def create_symlinks_new():
|
||||
from calibre.resources import scripts
|
||||
scripts = get_scripts()
|
||||
|
||||
links = [os.path.join(DEST_PATH, i) for i in scripts]
|
||||
scripts = [os.path.join(
|
||||
@ -40,7 +43,7 @@ def create_symlinks_new():
|
||||
|
||||
|
||||
def create_symlinks_old():
|
||||
from calibre.resources import scripts
|
||||
scripts = get_scripts()
|
||||
|
||||
resources_path = os.environ['RESOURCEPATH']
|
||||
links = [os.path.join(DEST_PATH, i) for i in scripts]
|
||||
|
@ -17,9 +17,8 @@ class cdnet(BasicNewsRecipe):
|
||||
timefmt = ' [%d %b %Y]'
|
||||
max_articles_per_feed = 50
|
||||
no_stylesheets = True
|
||||
language = 'de'
|
||||
|
||||
encoding = 'utf-8'
|
||||
language = 'de'
|
||||
|
||||
|
||||
remove_tags = [dict(id='outside-advert'),
|
||||
@ -39,8 +38,14 @@ class cdnet(BasicNewsRecipe):
|
||||
dict(id='bookmarkTools'),
|
||||
dict(id='printTools'),
|
||||
dict(id='header-nextNews'),
|
||||
dict(id='commentsBox'),
|
||||
dict(id='showComments'),
|
||||
dict(id='footer'),
|
||||
dict(id=''),
|
||||
dict(name='div', attrs={'class':'pyjama'}),
|
||||
dict(name='div', attrs={'class':'basicCentral'}),
|
||||
dict(name='li', attrs={'class':'simplePagination-previous'}),
|
||||
dict(name='form', attrs={'id':'commentForm'}),
|
||||
dict(name='href', attrs={'class':'comment'}),
|
||||
dict(name='div', attrs={'class':'greyBoxR clearfix'}),
|
||||
dict(name='div', attrs={'class':'greyBoxL clearfix'}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user