mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Sync to trunk.
This commit is contained in:
commit
aa48bc9763
@ -1,6 +1,5 @@
|
||||
#!/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>'
|
||||
@ -39,13 +38,19 @@ def _run():
|
||||
import os, sys, site
|
||||
sys.frozen = 'macosx_app'
|
||||
base = os.environ['RESOURCEPATH']
|
||||
sys.frameworks_dir = os.path.join(os.path.dirname(base, 'Frameworks'))
|
||||
sys.frameworks_dir = os.path.join(os.path.dirname(base), 'Frameworks')
|
||||
sys.new_app_bundle = True
|
||||
site.addsitedir(base)
|
||||
site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
|
||||
exe = os.environ.get('CALIBRE_LAUNCH_MODULE', 'calibre.gui2.main')
|
||||
exe = os.path.join(base, 'Python', 'site-packages', *exe.split('.'))
|
||||
exe += '.py'
|
||||
sys.argv[0] = __file__ = exe
|
||||
argv = os.environ.get('CALIBRE_LAUNCH_ARGV', None)
|
||||
if argv is not None:
|
||||
import cPickle
|
||||
argv = cPickle.loads(argv)
|
||||
sys.argv[1:] = argv
|
||||
execfile(exe, globals(), globals())
|
||||
|
||||
_run()
|
||||
|
@ -5,7 +5,7 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
import os, sys
|
||||
import os, sys, cPickle
|
||||
|
||||
ENV = {}##ENV##
|
||||
MODULE = ''##MODULE##
|
||||
@ -18,13 +18,16 @@ resources_dir = os.path.join(base_dir, 'Resources')
|
||||
frameworks_dir = os.path.join(base_dir, 'Frameworks')
|
||||
exe_dir = os.path.join(base_dir, 'MacOS')
|
||||
base_name = os.path.splitext(name)[0]
|
||||
python = os.path.join(base_dir, 'MacOS', 'calibre')
|
||||
python = os.path.join(base_dir, 'MacOS', 'Python')
|
||||
|
||||
for key, val in ENV.items():
|
||||
if val.startswith('@exec'):
|
||||
ENV[key] = os.path.normpath(val.replace('@executable_path', exe_dir))
|
||||
ENV['CALIBRE_LAUNCH_MODULE'] = MODULE
|
||||
ENV['CALIBRE_LAUNCH_ARGV'] = cPickle.dumps(sys.argv[1:], -1)
|
||||
ENV['RESOURCEPATH'] = resources_dir
|
||||
os.environ.update(ENV)
|
||||
args = [path] + sys.argv[1:]
|
||||
launcher = os.path.join(resources_dir, 'launcher.py')
|
||||
args = ['-OO', launcher]
|
||||
os.execv(python, args)
|
||||
|
||||
|
@ -864,9 +864,10 @@ static int py2app_main(int argc, char * const *argv, char * const *envp) {
|
||||
if (!getApplicationName()) return report_error(ERR_NONAME);
|
||||
pyLocations = (CFArrayRef)getKey("PyRuntimeLocations");
|
||||
if (!pyLocations) return report_error(ERR_PYRUNTIMELOCATIONS);
|
||||
printf("1111111\n;");
|
||||
pyLocation = findPyLocation(pyLocations);
|
||||
if (!pyLocation) return report_error(ERR_NOPYTHONRUNTIME);
|
||||
|
||||
printf("2222222\n");
|
||||
setExecutablePath();
|
||||
setResourcePath();
|
||||
/* check for ':' in path, not compatible with Python due to Py_GetPath */
|
||||
@ -895,7 +896,7 @@ static int py2app_main(int argc, char * const *argv, char * const *envp) {
|
||||
xCFStringGetCString(pyLocation, buf, sizeof(buf), kCFStringEncodingUTF8);
|
||||
py_dylib = dlopen(buf, PYMACAPP_DYLD_FLAGS);
|
||||
if (py_dylib == NULL) return report_linkEdit_error();
|
||||
|
||||
printf("3333333\n");
|
||||
#define LOOKUP_SYMBOL(NAME) \
|
||||
tmpSymbol = dlsym(py_dylib, # NAME)
|
||||
#define LOOKUP_DEFINEADDRESS(NAME, ADDRESS) \
|
||||
|
@ -26,6 +26,7 @@ ENV = dict(
|
||||
PYTHONIOENCODING='utf-8:replace',
|
||||
PYTHONPATH='@executable_path/../Resources/Python/site-packages',
|
||||
PYTHONHOME='@executable_path/../Resources/Python',
|
||||
PYTHONOPTIMIZE='2',
|
||||
QT_PLUGIN_PATH='@executable_path'
|
||||
)
|
||||
|
||||
@ -66,6 +67,16 @@ def strip_files(files, argv_max=(256 * 1024)):
|
||||
for args in flips:
|
||||
flipwritable(*args)
|
||||
|
||||
def flush(func):
|
||||
def ff(*args, **kwargs):
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
ret = func(*args, **kwargs)
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
return ret
|
||||
return ff
|
||||
|
||||
class Py2App(object):
|
||||
|
||||
FID = '@executable_path/../Frameworks'
|
||||
@ -75,7 +86,16 @@ class Py2App(object):
|
||||
self.contents_dir = join(self.build_dir, 'Contents')
|
||||
self.resources_dir = join(self.contents_dir, 'Resources')
|
||||
self.frameworks_dir = join(self.contents_dir, 'Frameworks')
|
||||
self.version_info = '.'.join(map(str, sys.version_info[:2]))
|
||||
self.to_strip = []
|
||||
self.warnings = []
|
||||
|
||||
def warn(self, *args):
|
||||
self.warnings.append(args)
|
||||
prefix = '' if args and args[0].startswith('WARNING:') else 'WARNING: '
|
||||
sys.stdout.write(prefix+' '.join(args)+'\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def run(self):
|
||||
self.create_skeleton()
|
||||
@ -103,26 +123,43 @@ class Py2App(object):
|
||||
self.strip_files()
|
||||
self.create_launchers()
|
||||
|
||||
return self.makedmg(self.build_dir, APPNAME+'-'+VERSION+'-x86_64')
|
||||
ret = self.makedmg(self.build_dir, APPNAME+'-'+VERSION+'-x86_64')
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
|
||||
print '\nThere were', len(self.warnings), 'warnings'
|
||||
for w in list(self.warnings):
|
||||
print
|
||||
self.warn(*w)
|
||||
return ret
|
||||
|
||||
@flush
|
||||
def create_launchers(self):
|
||||
launcher = join(os.path.dirname(__file__), 'launcher.py')
|
||||
print '\nCreating launchers'
|
||||
all_names = basenames['console'] + basenames['gui']
|
||||
all_modules = main_modules['console'] + main_modules['gui']
|
||||
launcher = join(os.path.dirname(__file__), 'loader.py')
|
||||
launcher = open(launcher, 'rb').read()
|
||||
launcher = launcher.replace('{}##ENV##', repr(ENV))
|
||||
os.mkdir(join(self.resources_dir, 'loaders'))
|
||||
for module, basename in zip(main_modules, basenames):
|
||||
for basename, module in zip(all_names, all_modules):
|
||||
py_file = join('src', *module.split('.'))+'.py'
|
||||
shutil.copy2(py_file, join(self.resources_dir, 'Python',
|
||||
'site-packages', *module.split('.'))+'.py')
|
||||
raw = launcher.replace("''##MODULE##", repr(module))
|
||||
path = join(self.resources_dir, 'loaders', basename)
|
||||
open(path, 'wb').write(raw)
|
||||
os.chmod(path, stat.S_IXUSR|stat.S_IXGRP|stat.S_IXOTH|stat.S_IREAD\
|
||||
|stat.S_IWUSR|stat.S_IROTH|stat.S_IRGRP)
|
||||
|
||||
|
||||
@flush
|
||||
def strip_files(self):
|
||||
print '\nStripping files...'
|
||||
strip_files(self.to_strip)
|
||||
|
||||
@flush
|
||||
def create_exe(self):
|
||||
print '\nCreating executable'
|
||||
gcc = os.environ.get('CC', 'gcc')
|
||||
base = os.path.dirname(__file__)
|
||||
out = join(self.contents_dir, 'MacOS', 'calibre')
|
||||
@ -130,25 +167,25 @@ class Py2App(object):
|
||||
'main.c'), '-o', out])
|
||||
self.to_strip.append(out)
|
||||
|
||||
@flush
|
||||
def set_id(self, path_to_lib, new_id):
|
||||
old_mode = flipwritable(path_to_lib)
|
||||
subprocess.check_call(['install_name_tool', '-id', new_id, path_to_lib])
|
||||
if old_mode is not None:
|
||||
flipwritable(path_to_lib, old_mode)
|
||||
|
||||
@flush
|
||||
def get_dependencies(self, path_to_lib):
|
||||
raw = subprocess.Popen(['otool', '-L', path_to_lib],
|
||||
stdout=subprocess.PIPE).stdout.read()
|
||||
for line in raw.splitlines():
|
||||
if 'compatibility' not in line:
|
||||
if 'compatibility' not in line or line.strip().endswith(':'):
|
||||
continue
|
||||
idx = line.find('(')
|
||||
path = line[:idx].strip()
|
||||
bname = os.path.basename(path).partition('.')[0]
|
||||
if bname in path_to_lib:
|
||||
continue
|
||||
yield path
|
||||
|
||||
@flush
|
||||
def get_local_dependencies(self, path_to_lib):
|
||||
for x in self.get_dependencies(path_to_lib):
|
||||
for y in (SW+'/lib/', '/usr/local/lib/', SW+'/qt/lib/',
|
||||
@ -157,11 +194,13 @@ class Py2App(object):
|
||||
yield x, x[len(y):]
|
||||
break
|
||||
|
||||
@flush
|
||||
def change_dep(self, old_dep, new_dep, path_to_lib):
|
||||
print '\tResolving dependency %s to'%old_dep, new_dep
|
||||
subprocess.check_call(['install_name_tool', '-change', old_dep, new_dep,
|
||||
path_to_lib])
|
||||
|
||||
@flush
|
||||
def fix_dependencies_in_lib(self, path_to_lib):
|
||||
print '\nFixing dependencies in', path_to_lib
|
||||
self.to_strip.append(path_to_lib)
|
||||
@ -174,7 +213,9 @@ class Py2App(object):
|
||||
if old_mode is not None:
|
||||
flipwritable(path_to_lib, old_mode)
|
||||
|
||||
@flush
|
||||
def add_python_framework(self):
|
||||
print '\nAdding Python framework'
|
||||
src = join(SW, 'python', 'Python.framework')
|
||||
x = join(self.frameworks_dir, 'Python.framework')
|
||||
curr = os.path.realpath(join(src, 'Versions', 'Current'))
|
||||
@ -185,7 +226,12 @@ class Py2App(object):
|
||||
shutil.copy2(join(curr, 'Python'), currd)
|
||||
self.set_id(join(currd, 'Python'),
|
||||
self.FID+'/Python.framework/Versions/%s/Python'%basename(curr))
|
||||
python = '%s/python/Python.framework/Versions/%s/Resources/Python.app/Contents/MacOS/Python'\
|
||||
% (SW, self.version_info)
|
||||
shutil.copy2(python, join(self.contents_dir, 'MacOS'))
|
||||
self.fix_dependencies_in_lib(join(self.contents_dir, 'MacOS', 'Python'))
|
||||
|
||||
@flush
|
||||
def add_qt_frameworks(self):
|
||||
for f in ('QtCore', 'QtGui', 'QtXml', 'QtNetwork', 'QtSvg', 'QtWebkit',
|
||||
'phonon'):
|
||||
@ -197,6 +243,7 @@ class Py2App(object):
|
||||
x = os.path.relpath(l, join(self.contents_dir, 'MacOS'))
|
||||
self.set_id(l, '@executable_path/'+x)
|
||||
|
||||
@flush
|
||||
def add_qt_framework(self, f):
|
||||
libname = f
|
||||
f = f+'.framework'
|
||||
@ -210,6 +257,7 @@ class Py2App(object):
|
||||
self.set_id(lib, self.FID+'/'+rpath)
|
||||
self.fix_dependencies_in_lib(lib)
|
||||
|
||||
@flush
|
||||
def create_skeleton(self):
|
||||
c = join(self.build_dir, 'Contents')
|
||||
for x in ('Frameworks', 'MacOS', 'Resources'):
|
||||
@ -217,6 +265,7 @@ class Py2App(object):
|
||||
x = 'library.icns'
|
||||
shutil.copyfile(join('icons', x), join(self.resources_dir, x))
|
||||
|
||||
@flush
|
||||
def add_calibre_plugins(self):
|
||||
dest = join(self.frameworks_dir, 'plugins')
|
||||
os.mkdir(dest)
|
||||
@ -225,6 +274,7 @@ class Py2App(object):
|
||||
self.fix_dependencies_in_lib(join(dest, basename(f)))
|
||||
|
||||
|
||||
@flush
|
||||
def create_plist(self):
|
||||
pl = dict(
|
||||
CFBundleDevelopmentRegion='English',
|
||||
@ -236,7 +286,7 @@ class Py2App(object):
|
||||
CFBundleSignature='????',
|
||||
CFBundleExecutable='calibre',
|
||||
LSMinimumSystemVersion='10.5.2',
|
||||
PyRuntimeLocations=[self.FID+'/Python.framework/Versions/Current/Python'],
|
||||
PyRuntimeLocations=[self.FID+'/Python.framework/Versions/%s/Python'%self.version_info],
|
||||
LSRequiresNativeExecution=True,
|
||||
NSAppleScriptEnabled=False,
|
||||
NSHumanReadableCopyright='Copyright 2008, Kovid Goyal',
|
||||
@ -248,6 +298,7 @@ class Py2App(object):
|
||||
)
|
||||
plistlib.writePlist(pl, join(self.contents_dir, 'Info.plist'))
|
||||
|
||||
@flush
|
||||
def install_dylib(self, path, set_id=True):
|
||||
shutil.copy2(path, self.frameworks_dir)
|
||||
if set_id:
|
||||
@ -255,25 +306,30 @@ class Py2App(object):
|
||||
self.FID+'/'+basename(path))
|
||||
self.fix_dependencies_in_lib(join(self.frameworks_dir, basename(path)))
|
||||
|
||||
@flush
|
||||
def add_podofo(self):
|
||||
print '\nAdding PoDoFo'
|
||||
pdf = join(SW, 'lib', 'libpodofo.0.6.99.dylib')
|
||||
self.install_dylib(pdf)
|
||||
|
||||
@flush
|
||||
def add_poppler(self):
|
||||
print '\nAdding poppler'
|
||||
for x in ('libpoppler.4.dylib', 'libpoppler-qt4.3.dylib'):
|
||||
self.install_dylib(os.path.join(SW, 'lib', x))
|
||||
self.install_dylib(os.path.join(SW, 'bin', 'pdftohtml'), False)
|
||||
|
||||
@flush
|
||||
def add_libjpeg(self):
|
||||
print '\nAdding libjpeg'
|
||||
self.install_dylib(os.path.join(SW, 'lib', 'libjpeg.7.dylib'))
|
||||
|
||||
@flush
|
||||
def add_libpng(self):
|
||||
print '\nAdding libpng'
|
||||
self.install_dylib(os.path.join(SW, 'lib', 'libpng12.0.dylib'))
|
||||
|
||||
@flush
|
||||
def add_fontconfig(self):
|
||||
print '\nAdding fontconfig'
|
||||
for x in ('fontconfig.1', 'freetype.6', 'expat.1'):
|
||||
@ -297,6 +353,7 @@ class Py2App(object):
|
||||
''')
|
||||
open(fc, 'wb').write(raw)
|
||||
|
||||
@flush
|
||||
def add_imagemagick(self):
|
||||
print '\nAdding ImageMagick'
|
||||
for x in ('Wand', 'Core'):
|
||||
@ -315,11 +372,15 @@ class Py2App(object):
|
||||
f = join(x[0], f)
|
||||
self.fix_dependencies_in_lib(f)
|
||||
|
||||
@flush
|
||||
def add_misc_libraries(self):
|
||||
for x in ('usb', 'unrar'):
|
||||
print '\nAdding', x
|
||||
shutil.copy2(join(SW, 'lib', 'lib%s.dylib'%x), self.frameworks_dir)
|
||||
x = 'lib%s.dylib'%x
|
||||
shutil.copy2(join(SW, 'lib', x), self.frameworks_dir)
|
||||
self.set_id(join(self.frameworks_dir, x), self.FID+'/'+x)
|
||||
|
||||
@flush
|
||||
def add_site_packages(self):
|
||||
print '\nAdding site-packages'
|
||||
self.site_packages = join(self.resources_dir, 'Python', 'site-packages')
|
||||
@ -327,18 +388,19 @@ class Py2App(object):
|
||||
paths = reversed(map(abspath, [x for x in sys.path if x.startswith('/')]))
|
||||
upaths = []
|
||||
for x in paths:
|
||||
if x not in upaths:
|
||||
upaths.append(x)
|
||||
for x in upaths:
|
||||
if x.endswith('/PIL') or 'site-packages' not in x:
|
||||
continue
|
||||
if x not in upaths:
|
||||
upaths.append(x)
|
||||
upaths.append(os.path.expanduser('~/build/calibre/src'))
|
||||
for x in upaths:
|
||||
tdir = None
|
||||
try:
|
||||
if not os.path.isdir(x):
|
||||
try:
|
||||
zf = zipfile.ZipFile(x)
|
||||
except:
|
||||
print "WARNING:", x, 'is neither a directory nor a zipfile'
|
||||
self.warn(x, 'is neither a directory nor a zipfile')
|
||||
continue
|
||||
tdir = tempfile.mkdtemp()
|
||||
zf.extractall(tdir)
|
||||
@ -350,6 +412,7 @@ class Py2App(object):
|
||||
shutil.rmtree(tdir)
|
||||
self.remove_bytecode(join(self.resources_dir, 'Python', 'site-packages'))
|
||||
|
||||
@flush
|
||||
def add_modules_from_dir(self, src):
|
||||
for x in glob.glob(join(src, '*.py'))+glob.glob(join(src, '*.so')):
|
||||
dest = join(self.site_packages, basename(x))
|
||||
@ -357,6 +420,7 @@ class Py2App(object):
|
||||
if x.endswith('.so'):
|
||||
self.fix_dependencies_in_lib(x)
|
||||
|
||||
@flush
|
||||
def add_packages_from_dir(self, src):
|
||||
for x in os.listdir(src):
|
||||
x = join(src, x)
|
||||
@ -365,46 +429,60 @@ class Py2App(object):
|
||||
continue
|
||||
self.add_package_dir(x)
|
||||
|
||||
@flush
|
||||
def add_package_dir(self, x, dest=None):
|
||||
def ignore(root, files):
|
||||
ans = []
|
||||
for y in files:
|
||||
if os.path.splitext(y) in ('.py', '.so'):
|
||||
continue
|
||||
ext = os.path.splitext(y)[1]
|
||||
if ext not in ('', '.py', '.so') or \
|
||||
(not ext and not os.path.isdir(join(root, y))):
|
||||
ans.append(y)
|
||||
|
||||
return ans
|
||||
if dest is None:
|
||||
dest = self.site_packages
|
||||
dest = join(dest, basename(x))
|
||||
shutil.copytree(x, dest, symlinks=True, ignore=ignore)
|
||||
self.postprocess_package(x, dest)
|
||||
for x in os.walk(dest):
|
||||
for f in x[-1]:
|
||||
if f.endswith('.so'):
|
||||
f = join(x[0], f)
|
||||
self.fix_dependencies_in_lib(f)
|
||||
|
||||
@flush
|
||||
def filter_package(self, name):
|
||||
return name in ('Cython', 'modulegraph', 'macholib', 'py2app',
|
||||
'bdist_mpkg', 'altgraph')
|
||||
|
||||
@flush
|
||||
def postprocess_package(self, src_path, dest_path):
|
||||
pass
|
||||
|
||||
@flush
|
||||
def add_stdlib(self):
|
||||
print '\nAdding python stdlib'
|
||||
src = join(SW, 'python/Python.framework/Versions/Current/lib/python')
|
||||
src += '.'.join(map(str, sys.version_info[:2]))
|
||||
src += self.version_info
|
||||
dest = join(self.resources_dir, 'Python', 'lib', 'python')
|
||||
dest += '.'.join(map(str, sys.version_info[:2]))
|
||||
dest += self.version_info
|
||||
os.makedirs(dest)
|
||||
for x in os.listdir(src):
|
||||
if x in ('site-packages', 'config', 'test', 'lib2to3', 'lib-tk',
|
||||
'lib-old', 'idlelib', 'plat-mac', 'plat-darwin', 'site.py'):
|
||||
continue
|
||||
x = join(src, x)
|
||||
if os.path.isdir(x):
|
||||
self.add_package_dir(join(src, x), dest)
|
||||
elif os.path.splitext(x) in ('.so', '.py'):
|
||||
shutil.copy2(join(src, x), dest)
|
||||
dest = join(dest, basename(x))
|
||||
if dest.endswith('.so'):
|
||||
self.fix_dependencies_in_lib(dest)
|
||||
self.add_package_dir(x, dest)
|
||||
elif os.path.splitext(x)[1] in ('.so', '.py'):
|
||||
shutil.copy2(x, dest)
|
||||
dest2 = join(dest, basename(x))
|
||||
if dest2.endswith('.so'):
|
||||
self.fix_dependencies_in_lib(dest2)
|
||||
self.remove_bytecode(join(self.resources_dir, 'Python', 'lib'))
|
||||
|
||||
@flush
|
||||
def remove_bytecode(self, dest):
|
||||
for x in os.walk(dest):
|
||||
root = x[0]
|
||||
@ -412,6 +490,7 @@ class Py2App(object):
|
||||
if os.path.splitext(f) in ('.pyc', '.pyo'):
|
||||
os.remove(join(root, f))
|
||||
|
||||
@flush
|
||||
def compile_py_modules(self):
|
||||
print '\nCompiling Python modules'
|
||||
base = join(self.resources_dir, 'Python')
|
||||
@ -425,8 +504,9 @@ class Py2App(object):
|
||||
py_compile.compile(y, dfile=rel, doraise=True)
|
||||
os.remove(y)
|
||||
except:
|
||||
print 'WARNING: Failed to byte-compile', y
|
||||
self.warn('WARNING: Failed to byte-compile', y)
|
||||
|
||||
@flush
|
||||
def create_console_app(self):
|
||||
print '\nCreating console.app'
|
||||
cc_dir = os.path.join(self.contents_dir, 'console.app', 'Contents')
|
||||
@ -442,16 +522,22 @@ class Py2App(object):
|
||||
os.symlink(join('../..', x),
|
||||
join(cc_dir, x))
|
||||
|
||||
@flush
|
||||
def copy_launcher_and_site(self):
|
||||
base = os.path.dirname(__file__)
|
||||
for x in ('launcher', 'site'):
|
||||
shutil.copy2(join(base, x+'.py'), self.resources_dir)
|
||||
shutil.copy2(join(base, 'launcher.py'), self.resources_dir)
|
||||
shutil.copy2(join(base, 'site.py'), join(self.resources_dir, 'Python',
|
||||
'lib', 'python'+self.version_info))
|
||||
|
||||
|
||||
@flush
|
||||
def makedmg(self, d, volname,
|
||||
destdir='dist',
|
||||
internet_enable=True,
|
||||
format='UDBZ'):
|
||||
''' Copy a directory d into a dmg named volname '''
|
||||
print '\nCreating dmg'
|
||||
sys.stdout.flush()
|
||||
if not os.path.exists(destdir):
|
||||
os.makedirs(destdir)
|
||||
dmg = os.path.join(destdir, volname+'.dmg')
|
||||
@ -461,6 +547,8 @@ class Py2App(object):
|
||||
'-volname', volname, '-format', format, dmg])
|
||||
if internet_enable:
|
||||
subprocess.check_call(['/usr/bin/hdiutil', 'internet-enable', '-yes', dmg])
|
||||
size = os.stat(dmg).st_size/(1024*1024.)
|
||||
print '\nInstaller size: %.2fMB\n'%size
|
||||
return dmg
|
||||
|
||||
|
||||
|
@ -305,6 +305,7 @@ Device._fields_ = [ \
|
||||
]
|
||||
|
||||
if _libusb is not None:
|
||||
try:
|
||||
_libusb.usb_get_busses.restype = POINTER(Bus)
|
||||
_libusb.usb_open.restype = POINTER(DeviceHandle)
|
||||
_libusb.usb_open.argtypes = [POINTER(Device)]
|
||||
@ -321,6 +322,8 @@ if _libusb is not None:
|
||||
_libusb.usb_set_configuration.argtypes = [POINTER(DeviceHandle), c_int]
|
||||
_libusb.usb_set_configuration.restype = c_int
|
||||
_libusb.usb_init()
|
||||
except:
|
||||
_libusb = None
|
||||
|
||||
|
||||
|
||||
|
@ -339,7 +339,7 @@ def main():
|
||||
dev.touch(args[0])
|
||||
else:
|
||||
parser.print_help()
|
||||
if dev.handle: dev.close()
|
||||
if getattr(dev, 'handle', False): dev.close()
|
||||
return 1
|
||||
except DeviceLocked:
|
||||
print >> sys.stderr, "The device is locked. Use the --unlock option"
|
||||
|
@ -141,8 +141,9 @@ class MOBIOutput(OutputFormatPlugin):
|
||||
toc.nodes[0].href = toc.nodes[0].nodes[0].href
|
||||
|
||||
# GR diagnostics
|
||||
#self.dump_toc(toc)
|
||||
#self.dump_manifest()
|
||||
if self.opts.verbose > 3:
|
||||
self.dump_toc(toc)
|
||||
self.dump_manifest()
|
||||
|
||||
|
||||
def convert(self, oeb, output_path, input_plugin, opts, log):
|
||||
|
@ -52,7 +52,7 @@ class TXTMLizer(object):
|
||||
stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
|
||||
content = unicode(etree.tostring(item.data.find(XHTML('body')), encoding=unicode))
|
||||
content = self.remove_newlines(content)
|
||||
output.append(self.get_text(etree.fromstring(content), stylizer))
|
||||
output += self.dump_text(etree.fromstring(content), stylizer))
|
||||
output = self.cleanup_text(u''.join(output))
|
||||
|
||||
return output
|
||||
@ -107,17 +107,6 @@ class TXTMLizer(object):
|
||||
|
||||
return text
|
||||
|
||||
def get_text(self, elem, stylizer):
|
||||
'''
|
||||
@elem: The element in the etree that we are working on.
|
||||
@stylizer: The style information attached to the element.
|
||||
@end: The last two characters of the text from the previous element.
|
||||
This is used to determine if a blank line is needed when starting
|
||||
a new block element.
|
||||
'''
|
||||
|
||||
return u''.join(self.dump_text(elem, stylizer))
|
||||
|
||||
def dump_text(self, elem, stylizer, end=''):
|
||||
'''
|
||||
@elem: The element in the etree that we are working on.
|
||||
@ -147,7 +136,7 @@ class TXTMLizer(object):
|
||||
if not end.endswith(u'\n\n') and hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '':
|
||||
text.append(u'\n\n')
|
||||
|
||||
# Proccess tags that contain text.
|
||||
# Process tags that contain text.
|
||||
if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '':
|
||||
text.append(elem.text)
|
||||
|
||||
|
@ -17,7 +17,8 @@ class PluginWidget(Widget, Ui_Form):
|
||||
HELP = _('Options specific to')+' TXT '+_('output')
|
||||
|
||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||
Widget.__init__(self, parent, 'txt_output', ['newline', 'inline_toc'])
|
||||
Widget.__init__(self, parent, 'txt_output', ['newline', 'inline_toc',
|
||||
'flush_paras', 'indent_paras'])
|
||||
self.db, self.book_id = db, book_id
|
||||
self.initialize_options(get_option, get_help, db, book_id)
|
||||
|
||||
|
@ -922,6 +922,8 @@ class BasicNewsRecipe(Recipe):
|
||||
desc = a.text_summary
|
||||
if not desc:
|
||||
desc = None
|
||||
else:
|
||||
desc = self.description_limiter(desc)
|
||||
entries.append('%sindex.html'%adir)
|
||||
po = self.play_order_map.get(entries[-1], None)
|
||||
if po is None:
|
||||
|
@ -12,16 +12,30 @@ from calibre.web.feeds.news import BasicNewsRecipe
|
||||
class BusinessWeek(BasicNewsRecipe):
|
||||
title = 'Business Week'
|
||||
description = 'Business News, Stock Market and Financial Advice'
|
||||
__author__ = 'ChuckEggDotCom'
|
||||
__author__ = 'ChuckEggDotCom and Sujata Raman'
|
||||
language = _('English')
|
||||
oldest_article = 7
|
||||
max_articles_per_feed = 10
|
||||
no_stylesheets = True
|
||||
|
||||
remove_tags_before = dict(name='h1')
|
||||
remove_tags_after = dict(id='footer')
|
||||
remove_tags = [dict(attrs={'class':['articleTools', 'post-tools', 'side_tool']}),
|
||||
dict(id=['footer', 'navigation', 'archive', 'side_search', 'blog_sidebar', 'side_tool', 'side_index']),
|
||||
dict(name='h2', attrs={'class':'listspace'}),
|
||||
|
||||
extra_css = '''
|
||||
h1{font-family :Arial,Helvetica,sans-serif; font-size:large;}
|
||||
h2{font-family :Arial,Helvetica,sans-serif; font-size:small;color:#666666;}
|
||||
p{font-family :Arial,Helvetica,sans-serif; }
|
||||
#lede600{font-size:x-small;}
|
||||
#storybody{font-size:x-small;}
|
||||
.strap{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#064599;}
|
||||
.byline{font-family :Arial,Helvetica,sans-serif; font-size:x-small;}
|
||||
.postedBy{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#666666;}
|
||||
.trackback{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#666666;}
|
||||
.date{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#666666;}
|
||||
.wrapper{font-family :Arial,Helvetica,sans-serif; font-size:x-small;}
|
||||
.photoCredit{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#666666;}
|
||||
.tagline{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#666666;}
|
||||
'''
|
||||
|
||||
remove_tags = [ dict(name='div', attrs={'id':["bw2-header","column2","wrapper-bw2-footer","wrapper-mgh-footer","inset","commentForm","commentDisplay","bwExtras","bw2-umbrella","readerComments","pageNav","leg"]}),
|
||||
]
|
||||
|
||||
feeds = [
|
||||
@ -29,29 +43,37 @@ class BusinessWeek(BasicNewsRecipe):
|
||||
(u'Top News', u'http://www.businessweek.com/rss/bwdaily.rss'),
|
||||
(u'Asia', u'http://www.businessweek.com/rss/asia.rss'),
|
||||
(u'Autos', u'http://www.businessweek.com/rss/autos/index.rss'),
|
||||
(u'Classic Cars', u'http://www.businessweek.com/rss/autos/classic_cars/index.rss'),
|
||||
(u'Hybrids', u'http://www.businessweek.com/rss/hybrids/index.rss'),
|
||||
(u'Classic Cars', u'http://rss.businessweek.com/bw_rss/classiccars'),
|
||||
(u'Hybrids', u'http://rss.businessweek.com/bw_rss/hybrids'),
|
||||
(u'Europe', u'http://www.businessweek.com/rss/europe.rss'),
|
||||
(u'Auto Reviews', u'http://www.businessweek.com/rss/autos/reviews/index.rss'),
|
||||
(u'Auto Reviews', u'http://rss.businessweek.com/bw_rss/autoreviews'),
|
||||
(u'Innovation & Design', u'http://www.businessweek.com/rss/innovate.rss'),
|
||||
(u'Architecture', u'http://www.businessweek.com/rss/architecture.rss'),
|
||||
(u'Brand Equity', u'http://www.businessweek.com/rss/brandequity.rss'),
|
||||
(u'Auto Design', u'http://www.businessweek.com/rss/carbuff.rss'),
|
||||
(u'Game Room', u'http://www.businessweek.com/rss/gameroom.rss'),
|
||||
(u'Game Room', u'http://rss.businessweek.com/bw_rss/gameroom'),
|
||||
(u'Technology', u'http://www.businessweek.com/rss/technology.rss'),
|
||||
(u'Investing', u'http://www.businessweek.m/rss/investor.rss'),
|
||||
(u'Investing', u'http://rss.businessweek.com/bw_rss/investor'),
|
||||
(u'Small Business', u'http://www.businessweek.com/rss/smallbiz.rss'),
|
||||
(u'Careers', u'http://www.businessweek.com/rss/careers.rss'),
|
||||
(u'Careers', u'http://rss.businessweek.com/bw_rss/careers'),
|
||||
(u'B-Schools', u'http://www.businessweek.com/rss/bschools.rss'),
|
||||
(u'Magazine Selections', u'http://www.businessweek.com/rss/magazine.rss'),
|
||||
(u'CEO Guide to Tech', u'http://www.businessweek.com/rss/ceo_guide_tech.rss'),
|
||||
]
|
||||
|
||||
def get_article_url(self, article):
|
||||
|
||||
url = article.get('guid', None)
|
||||
if 'podcasts' in url:
|
||||
|
||||
if 'podcasts' in url or 'surveys' in url:
|
||||
url = None
|
||||
|
||||
return url
|
||||
|
||||
def print_version(self, url):
|
||||
return url.replace('http://www.businessweek.com/', 'http://www.businessweek.com/print/')
|
||||
def postrocess_html(self, soup, first):
|
||||
|
||||
for tag in soup.findAll(name=['ul','li']):
|
||||
tag.name = 'div'
|
||||
|
||||
return soup
|
||||
|
||||
|
@ -523,8 +523,9 @@ class VMInstaller(OptionlessCommand):
|
||||
--exclude "*.pyc" --exclude "*.pyo" --exclude "*.swp" --exclude "*.swo" \
|
||||
rsync://%(host)s/work/%(project)s . && \
|
||||
cd %(project)s && \
|
||||
rm -rf src/calibre/plugins/* && \
|
||||
%%s && \
|
||||
rm -rf build/* dist/* src/calibre/plugins/* && \
|
||||
rm -rf build/* dist/* && \
|
||||
%%s %%s
|
||||
'''%dict(host=HOST, project=__appname__))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user