commit 6bfd32b99223e1e2e6b8de2088cf446b772cedcb
Author: Jan Pokorný <jpokorny(a)redhat.com>
Date: Fri Mar 16 03:51:54 2012 +0100
setup: extra font handling
additionally, the situation is following (c.f. 81c85c9)
- sunzi/public/fonts/LiberationSans-Bold-webfont.eot
+ sunzi/public/liberation/LiberationSans-Bold.eot
not
+ sunzi/public/css/liberation/LiberationSans-Bold.eot
This is better when writing scss styles referring to the fonts as
both scss and generated css files will use "../liberation/some.ttf".
Signed-off-by: Jan Pokorný <jpokorny(a)redhat.com>
prepare-devel.py | 78 ++++++++++++++++++++++++++++++++++++++---------------
setup_prepare.py | 36 +++++++++++++++++++-----
2 files changed, 84 insertions(+), 30 deletions(-)
---
diff --git a/prepare-devel.py b/prepare-devel.py
index 9187b67..e71b325 100644
--- a/prepare-devel.py
+++ b/prepare-devel.py
@@ -7,7 +7,8 @@ if __name__ == '__main__': # __builtin__ expected (?)
raise RuntimeError, "Not used in an expected way"
from os import walk, makedirs
-from os.path import join, exists, isfile, basename, splitext, normpath, sep
+from os.path import join, exists, isfile, isdir, basename, splitext, \
+ normpath, sep
from shutil import copy2
from fnmatch import fnmatch
@@ -82,17 +83,18 @@ class ParamItems(object):
for filename in nonmatching:
to_copy.append((join(root, filename), this_destdir))
for src,dst in to_copy:
+ print "jere", src
copy2(src, dst)
class StylesheetItems(ParamItems):
- def init(self, ignore=(), **kwargs):
+ """Stylesheet items, either direct *.js files or
directories"""
+ def init(self, ignore=()):
self._items = []
self._ignore = ignore
def add(self, *inputitems):
assert len([item for item in inputitems if item in self._items]) == 0
self._items.extend(inputitems)
def make_param(self, *stylesheet_dir):
- outer_self = self
destdir = join(*stylesheet_dir)
class StylesheetGetter(ContentGetter):
# NOTE: beware of using inner_self
@@ -116,39 +118,66 @@ class StylesheetItems(ParamItems):
# NOTE: no explicit collision checks
self.proceed(inputitem, destdir, '*css', lambda fn:
files.setdefault(fn, open(fn).read()),
- self._ignore)
+ ignore=self._ignore)
return Scss(scss_opts=opts, scss_files=files).compile()
return StylesheetGetter
class JavaScriptItems(ParamItems):
- def init(self, ignore=(), **kwargs):
+ """JavaScript items, either direct *.js files or
directories"""
+ def init(self, ignore=()):
self._items = {}
self._ignore = ignore
- def _inputitem2dict(self, fn):
- # jquery-ui-1.8.17.js -> jquery_ui_1_8_17, etc.
- base = splitext(basename(fn))[0].replace('-',
'_').replace('.', '_')
- assert not self._items.has_key(base)
- self._items[base] = fn
- def add(self, *inputitems):
+ def _file2dict(self, destpath):
+ def file2dict(fn):
+ base = splitext(basename(fn))[0]
+ assert not base in self._items
+ self._items[base] = (fn, destpath)
+ return file2dict
+ def add(self, destpath=(), *inputitems):
for inputitem in inputitems:
- self.proceed(inputitem, None, '*.js', self._inputitem2dict,
- self._ignore)
+ self.proceed(inputitem, None, '*.js', self._file2dict(destpath),
+ ignore=self._ignore)
def make_params(self, *javascript_dir):
destdir = join(*javascript_dir)
- for key, item in self._items.iteritems():
- base = basename(item)
- gen_file(key+'_path',
+ for base, (item, destpath) in self._items.iteritems(): # safe?
+ gen_file('javascript-' + base,
item,
- join(destdir, base),
+ join(destdir, *destpath)
)
- base = splitext(base)[0]
- nonoptions(**{key: base}) # easy access to script within JS dir
+ # for require.js
+ self._items[base] = (lambda *a: '/'.join(a))(destdir, *destpath)
+ nonoptions(**self._items)
+
+class FontItems(ParamItems):
+ """Font items, expected to be directories"""
+ def init(self, ignore=()):
+ self._items = []
+ self._ignore = ignore
+ def add(self, *inputitems):
+ for inputitem in inputitems:
+ assert not inputitem in self._items
+ if not isdir(inputitem):
+ raise RuntimeError("not a directory: %s" % inputitem)
+ self._items.append(inputitem)
+ def make_param(self, *root_dir):
+ destdir = join(*root_dir)
+ class FontGetter(ContentGetter):
+ # NOTE: beware of using inner_self
+ def get(inner_self):
+ for item in self._items:
+ # NOTE: no explicit collision checks (?)
+ base = basename(item)
+ print "YAY", item, destdir
+ self.proceed(item, destdir, '[_]*', ignore=self._ignore)
+ return None
+ return FontGetter
# initiate input items with anything appropriate from devel dirs
stylesheet_items = StylesheetItems(join(PACKAGE,PUBLIC,DEVEL_STYLESHEET_ROOT),
ignore=IGNORE)
javascript_items = JavaScriptItems(join(PACKAGE,PUBLIC,DEVEL_JAVASCRIPT_ROOT),
ignore=IGNORE)
+font_items = FontItems(ignore=IGNORE)
# RequireJS + requisities (hardcoded as this is referrenced via metadata.py)
gen_file('requirejs',
@@ -171,12 +200,13 @@ javascript_items.add(
join('third-party','target-jquery-ui','ui','i18n','jquery-ui-i18n.js'),
)
stylesheet_items.add(
-
join('third-party','target-jquery-ui','themes','base') #
jquery-ui.css + images
+ # jquery-ui.css + images
+
join('third-party','target-jquery-ui','themes','base')
)
# Liberation fonts
-stylesheet_items.add(
- join('third-party','target-liberation-fonts') #
"liberation" dir
+font_items.add(
+ join('third-party','target-liberation-fonts')
)
# put all stylesheet files (CSS/SCSS) altogether
@@ -184,5 +214,9 @@ gen_file('stylesheet',
stylesheet_items.make_param(PACKAGE,PUBLIC,STYLESHEET_ROOT),
join(PACKAGE,PUBLIC,STYLESHEET_ROOT,*STYLESHEET_MAIN),
)
+# similarly, handle all fonts at once
+gen_file('fonts',
+ font_items.make_param(PACKAGE,PUBLIC),
+)
# similarly for JavaScript files (but 1:1 mapping kept)
javascript_items.make_params(PACKAGE,PUBLIC,JAVASCRIPT_ROOT)
diff --git a/setup_prepare.py b/setup_prepare.py
index 9a79790..35fe182 100644
--- a/setup_prepare.py
+++ b/setup_prepare.py
@@ -348,9 +348,15 @@ class Params(object):
self.data_files.append(
PrepareDataFile(src_key, dst_key, **kwargs)
)
- def set_gen_file(self, basekey, src, dst, **kwargs):
+ def set_gen_file(self, basekey, src, dst=None, **kwargs):
src_key, dst_key = '__'+basekey, basekey
- self.set_nonoptions(**{src_key: src, dst_key:dst})
+ if dst:
+ self.set_nonoptions(**{src_key: src, dst_key:dst})
+ else:
+ # special case of callable taking whole care (src only,
+ # but really meant as dst as src cannot be skipped)
+ src_key = None
+ self.set_nonoptions(**{dst_key: src})
self.gen_files.append(
PrepareFile(src_key, dst_key, **kwargs)
)
@@ -393,15 +399,22 @@ class Params(object):
class PrepareFile(object):
"""Planned file ``preparation'' using symbolic
source/destination path"""
def __init__(self, src, dst, subst=False, incl=True, **kwargs):
- self.src = subst and Params.substitute(src) or src
- self.dst = dst
-
- self.src_getter = lambda src,getter: getter(src, 'r')
- self.dst_getter = lambda dst,getter: getter(dst, 'w')
+ if src:
+ self.dst = dst
+ self.src = subst and Params.substitute(src) or src
+ self.src_getter = lambda src,getter: getter(src, 'r')
+ self.dst_getter = lambda dst,getter: getter(dst, 'w')
+ else:
+ # special case of callable taking whole care (dst only)
+ self.src = src
+ self.dst = subst and Params.substitute(dst) or dst
+ self.dst_getter = lambda dst,getter: getter(dst, 'r')
self.incl = incl
self.private = kwargs # mainly to keep data between prepare and attach
self._prepared = False
+ def __repr__(self):
+ return "<PrepareFile src:%s,dst:%s>" % (repr(self.src),
repr(self.dst))
def prepare(self, getter, distribution=None):
src, dst = self.do_prepare(getter, distribution)
self._prepared = True
@@ -411,7 +424,10 @@ class PrepareFile(object):
raise RuntimeError('Cannot attach before preparing self')
self.do_attach(distribution)
def do_prepare(self, getter, distribution):
- src = self.src_getter(self.src, getter)
+ src = self.src
+ if src:
+ # otherwise, special case of callable taking whole care
+ src = self.src_getter(src, getter)
dst = self.dst_getter(self.dst, getter)
return src, dst
def do_attach(self, distribution):
@@ -549,6 +565,10 @@ class PrepareBaseCommand(Command, object):
dst.close()
copymode(src.name, dst.name)
return
+ elif not src:
+ # special case of callable taking whole care (dst only)
+ dst.get()
+ return
log.debug("Getting content into %s", dst.name)
if self.dry_run:
return