[2] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | import sys |
---|
| 4 | from Cheetah.Template import Template |
---|
| 5 | import string |
---|
| 6 | from subprocess import Popen, PIPE |
---|
| 7 | import os.path |
---|
| 8 | |
---|
| 9 | assert sys.version_info[:2] >= ( 2, 4 ) |
---|
| 10 | |
---|
| 11 | def run( cmd ): |
---|
| 12 | return Popen( cmd, stdout=PIPE).communicate()[0] |
---|
| 13 | |
---|
| 14 | templates = [ ( "base.css.tmpl", "base.css" ), |
---|
| 15 | ( "masthead.css.tmpl", "masthead.css"), |
---|
| 16 | ( "history.css.tmpl", "history.css" ), |
---|
| 17 | ( "tool_menu.css.tmpl", "tool_menu.css" ) ] |
---|
| 18 | |
---|
| 19 | images = [ ( "./gradient.py 9 1000 $menu_bg_top $menu_bg_hatch FFFFFF 0 0 FFFFFF 1 1", "menu_bg.png" ), |
---|
| 20 | ( "./gradient.py 9 1000 $base_bg_top - FFFFFF 0 0 FFFFFF 1 1", "base_bg.png" ), |
---|
| 21 | ( "./gradient.py 9 50 $masthead_bg $masthead_bg_hatch 000000 0 0.5 000000 1 1", "masthead_bg.png" ), |
---|
| 22 | ( "./gradient.py 9 30 $footer_title_bg $footer_title_hatch 000000 0 0.5 000000 1 1", "footer_title_bg.png" ), |
---|
| 23 | ( "./gradient.py 9 50 $form_title_bg $form_title_bg_hatch FFFFFF 0 0 FFFFFF 0.5 1", "form_title_bg.png" ), |
---|
| 24 | ( "./gradient.py 9 200 $history_ok_bg - FFFFFF 0 0.5 FFFFFF 0.5 1", "ok_bg.png" ), |
---|
| 25 | ( "./gradient.py 9 200 $history_error_bg - FFFFFF 0 0.5 FFFFFF 0.5 1", "error_bg.png" ), |
---|
| 26 | ( "./gradient.py 9 200 $history_running_bg - FFFFFF 0 0.5 FFFFFF 0.5 1", "warn_bg.png" ), |
---|
| 27 | ( "./gradient.py 9 200 $history_queued_bg - FFFFFF 0 0.5 FFFFFF 0.5 1", "gray_bg.png" ) ] |
---|
| 28 | |
---|
| 29 | shared_images = [ |
---|
| 30 | # Dialog boxes |
---|
| 31 | ( "ok_large.png", "done_message_bg", "done_message_icon.png" ), |
---|
| 32 | ( "info_large.png", "info_message_bg", "info_message_icon.png" ), |
---|
| 33 | ( "warn_large.png", "warn_message_bg", "warn_message_icon.png" ), |
---|
| 34 | ( "error_large.png", "error_message_bg", "error_message_icon.png" ), |
---|
| 35 | # History icons |
---|
| 36 | ( "ok_small.png", "history_ok_bg", "data_ok.png" ), |
---|
| 37 | ( "error_small.png", "history_error_bg", "data_error.png" ), |
---|
| 38 | ( "wait_small.png", "history_queued_bg", "data_queued.png" ) ] |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | vars, out_dir = sys.argv[1:] |
---|
| 42 | |
---|
| 43 | context = dict() |
---|
| 44 | for line in open( vars ): |
---|
| 45 | if line.startswith( '#' ): |
---|
| 46 | continue |
---|
| 47 | key, value = line.rstrip("\r\n").split( '=' ) |
---|
| 48 | if value.startswith( '"' ) and value.endswith( '"' ): |
---|
| 49 | value = value[1:-1] |
---|
| 50 | context[key] = value |
---|
| 51 | |
---|
| 52 | for input, output in templates: |
---|
| 53 | print input ,"->", output |
---|
| 54 | open( os.path.join( out_dir, output ), "w" ).write( str( Template( file=input, searchList=[context] ) ) ) |
---|
| 55 | |
---|
| 56 | for rule, output in images: |
---|
| 57 | t = string.Template( rule ).substitute( context ) |
---|
| 58 | print t, "->", output |
---|
| 59 | open( os.path.join( out_dir, output ), "w" ).write( run( t.split() ) ) |
---|
| 60 | |
---|
| 61 | for src, bg, out in shared_images: |
---|
| 62 | t = "./png_over_color.py shared_images/%s %s %s" % ( src, context[bg], os.path.join( out_dir, out ) ) |
---|
| 63 | print t |
---|
| 64 | run( t.split() ) |
---|