mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Sync to pluginize
This commit is contained in:
commit
fe9a33adf7
@ -11,6 +11,7 @@ LIBUSB_DIR = 'C:\\libusb'
|
|||||||
LIBUNRAR = 'C:\\Program Files\\UnrarDLL\\unrar.dll'
|
LIBUNRAR = 'C:\\Program Files\\UnrarDLL\\unrar.dll'
|
||||||
PDFTOHTML = 'C:\\cygwin\\home\\kovid\\poppler-0.10.6\\rel\\pdftohtml.exe'
|
PDFTOHTML = 'C:\\cygwin\\home\\kovid\\poppler-0.10.6\\rel\\pdftohtml.exe'
|
||||||
IMAGEMAGICK_DIR = 'C:\\ImageMagick'
|
IMAGEMAGICK_DIR = 'C:\\ImageMagick'
|
||||||
|
PDFTK = 'C:\\pdftk.exe'
|
||||||
FONTCONFIG_DIR = 'C:\\fontconfig'
|
FONTCONFIG_DIR = 'C:\\fontconfig'
|
||||||
VC90 = r'C:\VC90.CRT'
|
VC90 = r'C:\VC90.CRT'
|
||||||
|
|
||||||
@ -100,6 +101,9 @@ class BuildEXE(py2exe.build_exe.py2exe):
|
|||||||
shutil.copyfile(PDFTOHTML, os.path.join(PY2EXE_DIR, os.path.basename(PDFTOHTML)))
|
shutil.copyfile(PDFTOHTML, os.path.join(PY2EXE_DIR, os.path.basename(PDFTOHTML)))
|
||||||
shutil.copyfile(PDFTOHTML+'.manifest', os.path.join(PY2EXE_DIR,
|
shutil.copyfile(PDFTOHTML+'.manifest', os.path.join(PY2EXE_DIR,
|
||||||
os.path.basename(PDFTOHTML)+'.manifest'))
|
os.path.basename(PDFTOHTML)+'.manifest'))
|
||||||
|
print '\tAdding pdftk'
|
||||||
|
shutil.copyfile(PDFTK, os.path.join(PY2EXE_DIR, os.path.basename(PDFTK)))
|
||||||
|
|
||||||
print '\tAdding ImageMagick'
|
print '\tAdding ImageMagick'
|
||||||
for f in os.listdir(IMAGEMAGICK_DIR):
|
for f in os.listdir(IMAGEMAGICK_DIR):
|
||||||
shutil.copyfile(os.path.join(IMAGEMAGICK_DIR, f), os.path.join(PY2EXE_DIR, f))
|
shutil.copyfile(os.path.join(IMAGEMAGICK_DIR, f), os.path.join(PY2EXE_DIR, f))
|
||||||
|
@ -2,7 +2,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
__appname__ = 'calibre'
|
__appname__ = 'calibre'
|
||||||
__version__ = '0.5.10'
|
__version__ = '0.5.11'
|
||||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||||
'''
|
'''
|
||||||
Various run time constants.
|
Various run time constants.
|
||||||
|
@ -17,6 +17,7 @@ try:
|
|||||||
_imagemagick_loaded = True
|
_imagemagick_loaded = True
|
||||||
except:
|
except:
|
||||||
_imagemagick_loaded = False
|
_imagemagick_loaded = False
|
||||||
|
from calibre.utils.pdftk import set_metadata as pdftk_set_metadata
|
||||||
|
|
||||||
def get_metadata(stream, extract_cover=True):
|
def get_metadata(stream, extract_cover=True):
|
||||||
""" Return metadata as a L{MetaInfo} object """
|
""" Return metadata as a L{MetaInfo} object """
|
||||||
@ -67,6 +68,13 @@ class MetadataWriter(Thread):
|
|||||||
|
|
||||||
def set_metadata(stream, mi):
|
def set_metadata(stream, mi):
|
||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
|
try:
|
||||||
|
pdftk_set_metadata(stream, mi)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
# Use a StringIO object for the pdf because we will want to over
|
# Use a StringIO object for the pdf because we will want to over
|
||||||
# write it later and if we are working on the stream directly it
|
# write it later and if we are working on the stream directly it
|
||||||
# could cause some issues.
|
# could cause some issues.
|
||||||
|
BIN
src/calibre/gui2/images/news/straitstimes.png
Normal file
BIN
src/calibre/gui2/images/news/straitstimes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 953 B |
@ -142,8 +142,10 @@ class WorkerMother(object):
|
|||||||
self.gui_executable = os.path.join(contents, 'MacOS',
|
self.gui_executable = os.path.join(contents, 'MacOS',
|
||||||
os.path.basename(sys.executable))
|
os.path.basename(sys.executable))
|
||||||
contents = os.path.join(contents, 'console.app', 'Contents')
|
contents = os.path.join(contents, 'console.app', 'Contents')
|
||||||
self.executable = os.path.join(contents, 'MacOS',
|
exe = os.path.basename(sys.executable)
|
||||||
os.path.basename(sys.executable))
|
if 'python' not in exe:
|
||||||
|
exe = 'python'
|
||||||
|
self.executable = os.path.join(contents, 'MacOS', exe)
|
||||||
|
|
||||||
resources = os.path.join(contents, 'Resources')
|
resources = os.path.join(contents, 'Resources')
|
||||||
fd = os.path.join(contents, 'Frameworks')
|
fd = os.path.join(contents, 'Frameworks')
|
||||||
@ -479,9 +481,9 @@ class Overseer(object):
|
|||||||
self.job.update_status(percent, msg)
|
self.job.update_status(percent, msg)
|
||||||
elif word == 'ERROR':
|
elif word == 'ERROR':
|
||||||
self.write('OK')
|
self.write('OK')
|
||||||
exception, traceback = cPickle.loads(msg)
|
exception, tb = cPickle.loads(msg)
|
||||||
self.job.output(u'%s\n%s'%(exception, traceback))
|
self.job.output(u'%s\n%s'%(exception, tb))
|
||||||
self.job.exception, self.job.traceback = exception, traceback
|
self.job.exception, self.job.traceback = exception, tb
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
self.terminate()
|
self.terminate()
|
||||||
|
@ -29,7 +29,7 @@ class PersistentTemporaryFile(object):
|
|||||||
prefix = ""
|
prefix = ""
|
||||||
fd, name = tempfile.mkstemp(suffix, __appname__+"_"+ __version__+"_" + prefix,
|
fd, name = tempfile.mkstemp(suffix, __appname__+"_"+ __version__+"_" + prefix,
|
||||||
dir=dir)
|
dir=dir)
|
||||||
self._file = os.fdopen(fd, 'w+b')
|
self._file = os.fdopen(fd, mode)
|
||||||
self._name = name
|
self._name = name
|
||||||
atexit.register(cleanup, name)
|
atexit.register(cleanup, name)
|
||||||
|
|
||||||
@ -75,3 +75,28 @@ class TemporaryDirectory(object):
|
|||||||
if not self.keep and os.path.exists(self.tdir):
|
if not self.keep and os.path.exists(self.tdir):
|
||||||
shutil.rmtree(self.tdir, ignore_errors=True)
|
shutil.rmtree(self.tdir, ignore_errors=True)
|
||||||
|
|
||||||
|
class TemporaryFile(object):
|
||||||
|
|
||||||
|
def __init__(self, suffix="", prefix="", dir=None, mode='w+b'):
|
||||||
|
if prefix == None:
|
||||||
|
prefix = ''
|
||||||
|
if suffix is None:
|
||||||
|
suffix = ''
|
||||||
|
self.prefix, self.suffix, self.dir, self.mode = prefix, suffix, dir, mode
|
||||||
|
self._file = None
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
fd, name = tempfile.mkstemp(self.suffix,
|
||||||
|
__appname__+"_"+ __version__+"_" + self.prefix,
|
||||||
|
dir=self.dir)
|
||||||
|
self._file = os.fdopen(fd, self.mode)
|
||||||
|
self._name = name
|
||||||
|
self._file.close()
|
||||||
|
return name
|
||||||
|
|
||||||
|
def __exit__(self, *args):
|
||||||
|
cleanup(self._name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ DEPENDENCIES = [
|
|||||||
('BeautifulSoup', '3.0.5', 'beautifulsoup', 'python-beautifulsoup', 'python-BeautifulSoup'),
|
('BeautifulSoup', '3.0.5', 'beautifulsoup', 'python-beautifulsoup', 'python-BeautifulSoup'),
|
||||||
('dnspython', '1.6.0', 'dnspython', 'dnspython', 'dnspython', 'dnspython'),
|
('dnspython', '1.6.0', 'dnspython', 'dnspython', 'dnspython', 'dnspython'),
|
||||||
('poppler', '0.10.5', 'poppler', 'poppler', 'poppler', 'poppler'),
|
('poppler', '0.10.5', 'poppler', 'poppler', 'poppler', 'poppler'),
|
||||||
|
('pdftk', '1.12', 'pdftk', 'pdftk', 'pdftk', 'pdftk'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
80
src/calibre/utils/pdftk.py
Normal file
80
src/calibre/utils/pdftk.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#!/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 sys, subprocess, os, errno
|
||||||
|
from functools import partial
|
||||||
|
from contextlib import nested
|
||||||
|
|
||||||
|
from calibre.ptempfile import TemporaryFile
|
||||||
|
from calibre.constants import iswindows
|
||||||
|
|
||||||
|
PDFTK = 'pdftk'
|
||||||
|
popen = subprocess.Popen
|
||||||
|
#if isosx and hasattr(sys, 'frameworks_dir'):
|
||||||
|
# PDFTK = os.path.join(getattr(sys, 'frameworks_dir'), 'pdftk')
|
||||||
|
if iswindows and hasattr(sys, 'frozen'):
|
||||||
|
PDFTK = os.path.join(os.path.dirname(sys.executable), 'pdftk.exe')
|
||||||
|
popen = partial(subprocess.Popen, creationflags=0x08) # CREATE_NO_WINDOW=0x08 so that no ugly console is popped up
|
||||||
|
|
||||||
|
class PdftkError(Exception): pass
|
||||||
|
|
||||||
|
def mi_to_info(mi):
|
||||||
|
ans = []
|
||||||
|
if mi.title:
|
||||||
|
ans.extend(('InfoKey: Title', 'InfoValue: '+mi.title))
|
||||||
|
if mi.authors:
|
||||||
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
|
ans.extend(('InfoKey: Author', 'InfoValue: ' +
|
||||||
|
authors_to_string(mi.authors)))
|
||||||
|
return u'\n'.join(ans)
|
||||||
|
|
||||||
|
def set_metadata(stream, mi):
|
||||||
|
raw = mi_to_info(mi)
|
||||||
|
if not raw: return
|
||||||
|
raw = raw.encode('utf-8')
|
||||||
|
with nested(TemporaryFile('.pdf'), TemporaryFile('.pdf'),
|
||||||
|
TemporaryFile('.info')) as (input, output, meta):
|
||||||
|
oi = getattr(stream, 'name', None)
|
||||||
|
if not oi or not os.access(oi, os.R_OK):
|
||||||
|
stream.seek(0)
|
||||||
|
with open(input, 'wb') as f: f.write(stream.read())
|
||||||
|
else:
|
||||||
|
input = oi
|
||||||
|
with open(meta, 'wb') as f: f.write(raw)
|
||||||
|
if os.path.exists(output):
|
||||||
|
os.remove(output)
|
||||||
|
cmd = (PDFTK, input, 'update_info', meta, 'output', output)
|
||||||
|
p = popen(cmd)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
ret = p.wait()
|
||||||
|
break
|
||||||
|
except OSError, e:
|
||||||
|
if e.errno == errno.EINTR:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
if os.stat(output).st_size < 2048:
|
||||||
|
raise PdftkError('Output file too small')
|
||||||
|
|
||||||
|
with open(output, 'rb') as f: raw = f.read()
|
||||||
|
if raw:
|
||||||
|
stream.seek(0)
|
||||||
|
stream.truncate()
|
||||||
|
stream.write(raw)
|
||||||
|
stream.flush()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = sys.argv
|
||||||
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
mi = MetaInformation(args[2], [args[3]])
|
||||||
|
x = open(args[1], 'r+b')
|
||||||
|
set_metadata(x, mi)
|
@ -42,6 +42,7 @@ recipe_modules = ['recipe_' + r for r in (
|
|||||||
'moneynews', 'der_standard', 'diepresse', 'nzz_ger', 'hna',
|
'moneynews', 'der_standard', 'diepresse', 'nzz_ger', 'hna',
|
||||||
'seattle_times', 'scott_hanselman', 'coding_horror', 'twitchfilms',
|
'seattle_times', 'scott_hanselman', 'coding_horror', 'twitchfilms',
|
||||||
'stackoverflow', 'telepolis_artikel', 'zaobao', 'usnews',
|
'stackoverflow', 'telepolis_artikel', 'zaobao', 'usnews',
|
||||||
|
'straitstimes',
|
||||||
)]
|
)]
|
||||||
|
|
||||||
import re, imp, inspect, time, os
|
import re, imp, inspect, time, os
|
||||||
|
56
src/calibre/web/feeds/recipes/recipe_straitstimes.py
Normal file
56
src/calibre/web/feeds/recipes/recipe_straitstimes.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
|
||||||
|
'''
|
||||||
|
www.straitstimes.com
|
||||||
|
'''
|
||||||
|
|
||||||
|
from calibre.web.feeds.recipes import BasicNewsRecipe
|
||||||
|
|
||||||
|
class StraitsTimes(BasicNewsRecipe):
|
||||||
|
title = 'The Straits Times'
|
||||||
|
__author__ = 'Darko Miletic'
|
||||||
|
description = 'Singapore newspaper'
|
||||||
|
oldest_article = 2
|
||||||
|
max_articles_per_feed = 100
|
||||||
|
no_stylesheets = True
|
||||||
|
use_embedded_content = False
|
||||||
|
encoding = 'cp1252'
|
||||||
|
publisher = 'Singapore Press Holdings Ltd.'
|
||||||
|
category = 'news, politics, singapore, asia'
|
||||||
|
language = _('English')
|
||||||
|
|
||||||
|
html2lrf_options = [
|
||||||
|
'--comment', description
|
||||||
|
, '--category', category
|
||||||
|
, '--publisher', publisher
|
||||||
|
, '--ignore-tables'
|
||||||
|
]
|
||||||
|
|
||||||
|
html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"\nlinearize_tables=True'
|
||||||
|
|
||||||
|
remove_tags = [
|
||||||
|
dict(name=['object','link'])
|
||||||
|
,dict(name='table', attrs={'width':'980'})
|
||||||
|
,dict(name='td' , attrs={'class':'padlrt10'})
|
||||||
|
]
|
||||||
|
|
||||||
|
feeds = [
|
||||||
|
(u'Singapore' , u'http://www.straitstimes.com/STI/STIFILES/rss/break_singapore.xml' )
|
||||||
|
,(u'SE Asia' , u'http://www.straitstimes.com/STI/STIFILES/rss/break_sea.xml' )
|
||||||
|
,(u'Money' , u'http://www.straitstimes.com/STI/STIFILES/rss/break_money.xml' )
|
||||||
|
,(u'Sport' , u'http://www.straitstimes.com/STI/STIFILES/rss/break_sport.xml' )
|
||||||
|
,(u'World' , u'http://www.straitstimes.com/STI/STIFILES/rss/break_world.xml' )
|
||||||
|
,(u'Tech & Science' , u'http://www.straitstimes.com/STI/STIFILES/rss/break_tech.xml' )
|
||||||
|
,(u'Lifestyle' , u'http://www.straitstimes.com/STI/STIFILES/rss/break_lifestyle.xml' )
|
||||||
|
]
|
||||||
|
|
||||||
|
def preprocess_html(self, soup):
|
||||||
|
for item in soup.findAll(style=True):
|
||||||
|
del item['style']
|
||||||
|
return soup
|
||||||
|
|
||||||
|
def print_version(self, url):
|
||||||
|
return url.replace('http://www.straitstimes.com','http://www.straitstimes.com/print')
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user