From 59e04933c06429b906f496d1495f3ed13e4107e2 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Thu, 14 Apr 2016 17:40:13 -0700 Subject: [PATCH 1/3] Tweak emoji html to display images against darker color. --- generate_emoji_html.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/generate_emoji_html.py b/generate_emoji_html.py index 813401ac3..64c29639f 100755 --- a/generate_emoji_html.py +++ b/generate_emoji_html.py @@ -230,11 +230,12 @@ TEMPLATE = """ """ STYLE = """ - tbody { background-color: rgb(210, 210, 210) } - tbody img { width: 64px; height: 64px } - tbody .desc { font-size: 20pt; font-weight: bold } - tbody .desc img { vertical-align: middle; width: 32px; height: 32px } - tbody .name { background-color: white } + tbody { background-color: rgb(110, 110, 110) } + th { background-color: rgb(210, 210, 210) } + td img { width: 64px; height: 64px } + td.desc { font-size: 20pt; font-weight: bold; background-color: rgb(210, 210, 210) } + td.desc img { vertical-align: middle; width: 32px; height: 32px } + td.name { background-color: white } """ def write_html_page(filename, page_title, dir_infos): @@ -272,7 +273,7 @@ def main(): args = parser.parse_args() file_parts = path.splitext(args.filename) - if file_parts[1] != 'html': + if file_parts[1] != '.html': args.filename = file_parts[0] + '.html' print 'added .html extension to filename:\n%s' % args.filename From 8b2596d76a1a6f4a8ab4391abc8cbdf410d21572 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Fri, 15 Apr 2016 14:06:30 -0700 Subject: [PATCH 2/3] Generate file references relative to destination of output file. Formerly, we wrote the file paths as given on the command line, the assumption being that the output file was in the cwd and the paths to the directories would be correct. However if we want to generate the output file somewhere other than the cwd the generated image paths don't work. This takes the location of the output file into account and either generates relative paths if the files are under the output file directory, or absolute paths otherwise. --- generate_emoji_html.py | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/generate_emoji_html.py b/generate_emoji_html.py index 64c29639f..9140ac3ea 100755 --- a/generate_emoji_html.py +++ b/generate_emoji_html.py @@ -49,23 +49,27 @@ def _merge_keys(dicts): keys.extend(d.keys()) return frozenset(keys) -def _generate_row_cells(key, dir_infos): +def _generate_row_cells(key, dir_infos, basepaths): CELL_PREFIX = '' - def _cell(key, info): + indices = range(len(basepaths)) + def _cell(key, info, basepath): if key in info.filemap: return '' % path.join( - info.directory, info.filemap[key]) + basepath, info.filemap[key]) return '-missing-' - return [CELL_PREFIX + _cell(key, info) for info in dir_infos] + return [CELL_PREFIX + _cell(key, dir_infos[i], basepaths[i]) + for i in indices] -def _get_desc(key_tuple, dir_infos): +def _get_desc(key_tuple, dir_infos, basepaths): CELL_PREFIX = '' def _get_filepath(cp): cp_key = tuple([cp]) - for info in dir_infos: + for i in range(len(dir_infos)): + info = dir_infos[i] if cp_key in info.filemap: - return path.join(info.directory, info.filemap[cp_key]) + basepath = basepaths[i] + return path.join(basepath, info.filemap[cp_key]) return None def _get_part(cp): @@ -98,19 +102,31 @@ def _get_name(key_tuple): return CELL_PREFIX + name -def _generate_content(dir_infos): - """Generate an html table for the infos.""" +def _generate_content(basedir, dir_infos): + """Generate an html table for the infos. basedir is the parent directory + of the content, filenames will be made relative to this if underneath it, + else absolute.""" lines = [''] header_row = [''] header_row.extend([info.title for info in dir_infos]) header_row.extend(['Description', 'Name']) lines.append(''.join(lines) + '\n
'.join(header_row)) + basepaths = [] + abs_basedir = path.abspath(path.expanduser(basedir)) + for filedir, _, _ in dir_infos: + abs_filedir = path.abspath(path.expanduser(filedir)) + if abs_filedir.startswith(abs_basedir): + dirspec = abs_filedir[len(abs_basedir) + 1:] + else: + dirspec = abs_filedir + basepaths.append(dirspec) + all_keys = _merge_keys([info.filemap for info in dir_infos]) for key in sorted(all_keys): row = [] - row.extend(_generate_row_cells(key, dir_infos)) - row.append(_get_desc(key, dir_infos)) + row.extend(_generate_row_cells(key, dir_infos, basepaths)) + row.append(_get_desc(key, dir_infos, basepaths)) row.append(_get_name(key)) lines.append(''.join(row)) return '\n
' @@ -188,7 +204,7 @@ def _get_dir_infos( infos = [] for i in range(count): image_dir = image_dirs[i] - title = titles[i] or path.basename(path.normpath(image_dir)) + title = titles[i] or path.basename(path.abspath(image_dir)) ext = exts[i] or default_ext prefix = prefixes[i] or default_prefix filemap = _get_image_data(image_dir, ext, prefix) @@ -239,7 +255,7 @@ STYLE = """ """ def write_html_page(filename, page_title, dir_infos): - content = _generate_content(dir_infos) + content = _generate_content(path.dirname(filename), dir_infos) text = _instantiate_template( TEMPLATE, {'title': page_title, 'style': STYLE, 'content': content}) with codecs.open(filename, 'w', 'utf-8') as f: From 5fd46ab1366101de5c9ba523ebe8f085f368a4ef Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Fri, 15 Apr 2016 15:07:58 -0700 Subject: [PATCH 3/3] Add limit option to generate_emoji_html. By default the tool uses all sequences that appear in any of the image sets. To make it easier to see just the changes between a smaller set of images and a large one, this lets you limit the sequences to just those in the first set being compared. --- generate_emoji_html.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/generate_emoji_html.py b/generate_emoji_html.py index 9140ac3ea..c4f8ef0f4 100755 --- a/generate_emoji_html.py +++ b/generate_emoji_html.py @@ -102,10 +102,12 @@ def _get_name(key_tuple): return CELL_PREFIX + name -def _generate_content(basedir, dir_infos): +def _generate_content(basedir, dir_infos, limit): """Generate an html table for the infos. basedir is the parent directory of the content, filenames will be made relative to this if underneath it, - else absolute.""" + else absolute. If limit is true and there are multiple dirs, limit the set of + sequences to those in the first dir.""" + lines = [''] header_row = [''] header_row.extend([info.title for info in dir_infos]) @@ -122,7 +124,10 @@ def _generate_content(basedir, dir_infos): dirspec = abs_filedir basepaths.append(dirspec) - all_keys = _merge_keys([info.filemap for info in dir_infos]) + if len(dir_infos) == 1 or limit: + all_keys = frozenset(dir_infos[0].filemap.keys()) + else: + all_keys = _merge_keys([info.filemap for info in dir_infos]) for key in sorted(all_keys): row = [] row.extend(_generate_row_cells(key, dir_infos, basepaths)) @@ -254,8 +259,8 @@ STYLE = """ td.name { background-color: white } """ -def write_html_page(filename, page_title, dir_infos): - content = _generate_content(path.dirname(filename), dir_infos) +def write_html_page(filename, page_title, dir_infos, limit): + content = _generate_content(path.dirname(filename), dir_infos, limit) text = _instantiate_template( TEMPLATE, {'title': page_title, 'style': STYLE, 'content': content}) with codecs.open(filename, 'w', 'utf-8') as f: @@ -280,6 +285,9 @@ def main(): parser.add_argument( '-t', '--titles', help='title, one per image dir', metavar='title', nargs='*'), + parser.add_argument( + '-l', '--limit', help='limit to only sequences supported by first set', + action='store_true') parser.add_argument( '-de', '--default_ext', help='default extension', metavar='ext', default=_default_ext) @@ -294,10 +302,10 @@ def main(): print 'added .html extension to filename:\n%s' % args.filename dir_infos = _get_dir_infos( - args.image_dirs, args.exts, args.prefixes, args.titles, args.default_ext, - args.default_prefix) + args.image_dirs, args.exts, args.prefixes, args.titles, + args.default_ext, args.default_prefix) - write_html_page(args.filename, args.page_title, dir_infos) + write_html_page(args.filename, args.page_title, dir_infos, args.limit) if __name__ == "__main__":