mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Infrastructure for writing Coffeescript
This commit is contained in:
parent
644e5fe449
commit
bb8b02c26c
@ -2,6 +2,7 @@
|
|||||||
.check-cache.pickle
|
.check-cache.pickle
|
||||||
src/calibre/plugins
|
src/calibre/plugins
|
||||||
resources/images.qrc
|
resources/images.qrc
|
||||||
|
resources/display/*.js
|
||||||
src/calibre/manual/.build/
|
src/calibre/manual/.build/
|
||||||
src/calibre/manual/cli/
|
src/calibre/manual/cli/
|
||||||
src/calibre/manual/template_ref.rst
|
src/calibre/manual/template_ref.rst
|
||||||
|
@ -11,7 +11,7 @@ __all__ = [
|
|||||||
'build', 'build_pdf2xml', 'server',
|
'build', 'build_pdf2xml', 'server',
|
||||||
'gui',
|
'gui',
|
||||||
'develop', 'install',
|
'develop', 'install',
|
||||||
'kakasi', 'resources',
|
'kakasi', 'coffee', 'resources',
|
||||||
'check',
|
'check',
|
||||||
'sdist',
|
'sdist',
|
||||||
'manual', 'tag_release',
|
'manual', 'tag_release',
|
||||||
@ -49,9 +49,10 @@ gui = GUI()
|
|||||||
from setup.check import Check
|
from setup.check import Check
|
||||||
check = Check()
|
check = Check()
|
||||||
|
|
||||||
from setup.resources import Resources, Kakasi
|
from setup.resources import Resources, Kakasi, Coffee
|
||||||
resources = Resources()
|
resources = Resources()
|
||||||
kakasi = Kakasi()
|
kakasi = Kakasi()
|
||||||
|
coffee = Coffee()
|
||||||
|
|
||||||
from setup.publish import Manual, TagRelease, Stage1, Stage2, \
|
from setup.publish import Manual, TagRelease, Stage1, Stage2, \
|
||||||
Stage3, Stage4, Stage5, Publish
|
Stage3, Stage4, Stage5, Publish
|
||||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, cPickle, re, shutil, marshal, zipfile, glob
|
import os, cPickle, re, shutil, marshal, zipfile, glob, subprocess, time
|
||||||
from zlib import compress
|
from zlib import compress
|
||||||
|
|
||||||
from setup import Command, basenames, __appname__
|
from setup import Command, basenames, __appname__
|
||||||
@ -23,7 +23,46 @@ def get_opts_from_parser(parser):
|
|||||||
for o in g.option_list:
|
for o in g.option_list:
|
||||||
for x in do_opt(o): yield x
|
for x in do_opt(o): yield x
|
||||||
|
|
||||||
class Kakasi(Command):
|
class Coffee(Command): # {{{
|
||||||
|
|
||||||
|
description = 'Compile coffeescript files into javascript'
|
||||||
|
COFFEE_DIRS = {'ebooks/oeb/display': 'display'}
|
||||||
|
|
||||||
|
def add_options(self, parser):
|
||||||
|
parser.add_option('--watch', '-w', action='store_true', default=False,
|
||||||
|
help='Autocompile when .coffee files are changed')
|
||||||
|
|
||||||
|
def run(self, opts):
|
||||||
|
self.do_coffee_compile()
|
||||||
|
if opts.watch:
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
self.do_coffee_compile(timestamp=True)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def do_coffee_compile(self, timestamp=False):
|
||||||
|
for toplevel, dest in self.COFFEE_DIRS.iteritems():
|
||||||
|
dest = self.j(self.RESOURCES, dest)
|
||||||
|
for x in glob.glob(self.j(self.SRC, __appname__, toplevel, '*.coffee')):
|
||||||
|
js = self.j(dest, os.path.basename(x.rpartition('.')[0]+'.js'))
|
||||||
|
if self.newer(js, x):
|
||||||
|
print ('\t%sCompiling %s'%(time.strftime('[%H:%M:%S] ') if
|
||||||
|
timestamp else '', os.path.basename(x)))
|
||||||
|
subprocess.check_call(['coffee', '-c', '-o', dest, x])
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
for toplevel, dest in self.COFFEE_DIRS.iteritems():
|
||||||
|
dest = self.j(self.RESOURCES, dest)
|
||||||
|
for x in glob.glob(self.j(self.SRC, __appname__, toplevel, '*.coffee')):
|
||||||
|
x = x.rpartition('.')[0] + '.js'
|
||||||
|
x = self.j(dest, os.path.basename(x))
|
||||||
|
if os.path.exists(x):
|
||||||
|
os.remove(x)
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class Kakasi(Command): # {{{
|
||||||
|
|
||||||
description = 'Compile resources for unihandecode'
|
description = 'Compile resources for unihandecode'
|
||||||
|
|
||||||
@ -62,9 +101,6 @@ class Kakasi(Command):
|
|||||||
self.info('\tGenerating kanadict')
|
self.info('\tGenerating kanadict')
|
||||||
self.mkkanadict(src, dest)
|
self.mkkanadict(src, dest)
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def mkitaiji(self, src, dst):
|
def mkitaiji(self, src, dst):
|
||||||
dic = {}
|
dic = {}
|
||||||
for line in open(src, "r"):
|
for line in open(src, "r"):
|
||||||
@ -125,11 +161,12 @@ class Kakasi(Command):
|
|||||||
kakasi = self.j(self.RESOURCES, 'localization', 'pykakasi')
|
kakasi = self.j(self.RESOURCES, 'localization', 'pykakasi')
|
||||||
if os.path.exists(kakasi):
|
if os.path.exists(kakasi):
|
||||||
shutil.rmtree(kakasi)
|
shutil.rmtree(kakasi)
|
||||||
|
# }}}
|
||||||
|
|
||||||
class Resources(Command):
|
class Resources(Command): # {{{
|
||||||
|
|
||||||
description = 'Compile various needed calibre resources'
|
description = 'Compile various needed calibre resources'
|
||||||
sub_commands = ['kakasi']
|
sub_commands = ['kakasi', 'coffee']
|
||||||
|
|
||||||
def run(self, opts):
|
def run(self, opts):
|
||||||
scripts = {}
|
scripts = {}
|
||||||
@ -223,13 +260,13 @@ class Resources(Command):
|
|||||||
x = self.j(self.RESOURCES, x+'.pickle')
|
x = self.j(self.RESOURCES, x+'.pickle')
|
||||||
if os.path.exists(x):
|
if os.path.exists(x):
|
||||||
os.remove(x)
|
os.remove(x)
|
||||||
from setup.commands import kakasi
|
from setup.commands import kakasi, coffee
|
||||||
kakasi.clean()
|
kakasi.clean()
|
||||||
|
coffee.clean()
|
||||||
for x in ('builtin_recipes.xml', 'builtin_recipes.zip',
|
for x in ('builtin_recipes.xml', 'builtin_recipes.zip',
|
||||||
'template-functions.json'):
|
'template-functions.json'):
|
||||||
x = self.j(self.RESOURCES, x)
|
x = self.j(self.RESOURCES, x)
|
||||||
if os.path.exists(x):
|
if os.path.exists(x):
|
||||||
os.remove(x)
|
os.remove(x)
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user