PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/ruffus/test/play_with_colours.py

https://code.google.com/p/ruffus/
Python | 278 lines | 179 code | 44 blank | 55 comment | 5 complexity | 7d41bb6fac7a1ded92cbb8cc290e458d MD5 | raw file
  1#!/usr/bin/env python
  2"""
  3
  4    play_with_colours.py
  5    [--log_file PATH]
  6    [--verbose]
  7
  8"""
  9
 10################################################################################
 11#
 12#   test
 13#
 14#
 15#   Copyright (c) 7/13/2010 Leo Goodstadt
 16#
 17#   Permission is hereby granted, free of charge, to any person obtaining a copy
 18#   of this software and associated documentation files (the "Software"), to deal
 19#   in the Software without restriction, including without limitation the rights
 20#   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 21#   copies of the Software, and to permit persons to whom the Software is
 22#   furnished to do so, subject to the following conditions:
 23#
 24#   The above copyright notice and this permission notice shall be included in
 25#   all copies or substantial portions of the Software.
 26#
 27#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 28#   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 29#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 30#   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 31#   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 32#   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 33#   THE SOFTWARE.
 34#################################################################################
 35
 36import sys, os
 37
 38# add self to search path for testing
 39exe_path = os.path.split(os.path.abspath(sys.argv[0]))[0]
 40sys.path.insert(0,os.path.abspath(os.path.join(exe_path,"..", "..")))
 41if __name__ == '__main__':
 42    module_name = os.path.split(sys.argv[0])[1]
 43    module_name = os.path.splitext(module_name)[0];
 44else:
 45    module_name = __name__
 46
 47
 48
 49#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
 50
 51#   options
 52
 53
 54#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
 55
 56
 57from optparse import OptionParser
 58import StringIO
 59
 60parser = OptionParser(version="%play_with_colours 1.0",
 61                      usage = "\n\n    play_with_colours "
 62                                "--flowchart FILE [options] "
 63                                "[--colour_scheme_index INT ] "
 64                                "[--key_legend_in_graph]")
 65
 66#
 67#   pipeline
 68#
 69parser.add_option("--flowchart", dest="flowchart",
 70                    metavar="FILE",
 71                    type="string",
 72                    help="Don't actually run any commands; just print the pipeline "
 73                         "as a flowchart.")
 74parser.add_option("--colour_scheme_index", dest="colour_scheme_index",
 75                    metavar="INTEGER",
 76                    type="int",
 77                    help="Index of colour scheme for flow chart.")
 78parser.add_option("--key_legend_in_graph", dest="key_legend_in_graph",
 79                    action="store_true", default=False,
 80                    help="Print out legend and key for dependency graph.")
 81
 82(options, remaining_args) = parser.parse_args()
 83if not options.flowchart:
 84    raise Exception("Missing mandatory parameter: --flowchart.\n")
 85
 86
 87
 88
 89#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
 90
 91#   imports
 92
 93
 94#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
 95
 96from ruffus import *
 97from ruffus.ruffus_exceptions import JobSignalledBreak
 98
 99
100#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
101
102#   Pipeline
103
104
105#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
106
107
108#
109# up to date tasks
110#
111@check_if_uptodate (lambda : (False, ""))
112def Up_to_date_task1(infile, outfile):
113    pass
114
115@check_if_uptodate (lambda : (False, ""))
116@follows(Up_to_date_task1)
117def Up_to_date_task2(infile, outfile):
118    pass
119
120@check_if_uptodate (lambda : (False, ""))
121@follows(Up_to_date_task2)
122def Up_to_date_task3(infile, outfile):
123    pass
124
125
126@check_if_uptodate (lambda : (False, ""))
127@follows(Up_to_date_task3)
128def Up_to_date_final_target(infile, outfile):
129    pass
130
131
132#
133# Explicitly specified
134#
135@check_if_uptodate (lambda : (False, ""))
136@follows(Up_to_date_task1)
137def Explicitly_specified_task(infile, outfile):
138    pass
139
140
141
142#
143# Tasks to run
144#
145@follows(Explicitly_specified_task)
146def Task_to_run1(infile, outfile):
147    pass
148
149
150@follows(Task_to_run1)
151def Task_to_run2(infile, outfile):
152    pass
153
154@follows(Task_to_run2)
155def Task_to_run3(infile, outfile):
156    pass
157
158@check_if_uptodate (lambda : (False, ""))
159@follows(Task_to_run2)
160def Up_to_date_task_forced_to_rerun(infile, outfile):
161    pass
162
163
164#
165# Final target
166#
167@follows(Up_to_date_task_forced_to_rerun, Task_to_run3)
168def Final_target(infile, outfile):
169    pass
170
171#
172# Ignored downstream
173#
174@follows(Final_target)
175def Downstream_task1_ignored(infile, outfile):
176    pass
177
178@follows(Final_target)
179def Downstream_task2_ignored(infile, outfile):
180    pass
181
182
183
184
185
186
187
188
189
190
191
192#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
193
194#   Main logic
195
196
197#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
198from collections import defaultdict
199custom_flow_chart_colour_scheme = defaultdict(dict)
200
201#
202#   Base chart on this overall colour scheme index
203#
204custom_flow_chart_colour_scheme["colour_scheme_index"] = options.colour_scheme_index
205
206#
207#   Overriding colours
208#
209if options.colour_scheme_index == None:
210    custom_flow_chart_colour_scheme["Vicious cycle"]["linecolor"]                        = '"#FF3232"'
211    custom_flow_chart_colour_scheme["Pipeline"]["fontcolor"]                             = '"#FF3232"'
212    custom_flow_chart_colour_scheme["Key"]["fontcolor"]                                  = "black"
213    custom_flow_chart_colour_scheme["Key"]["fillcolor"]                                  = '"#F6F4F4"'
214    custom_flow_chart_colour_scheme["Task to run"]["linecolor"]                          = '"#0044A0"'
215    custom_flow_chart_colour_scheme["Up-to-date"]["linecolor"]                           = "gray"
216    custom_flow_chart_colour_scheme["Final target"]["fillcolor"]                         = '"#EFA03B"'
217    custom_flow_chart_colour_scheme["Final target"]["fontcolor"]                         = "black"
218    custom_flow_chart_colour_scheme["Final target"]["color"]                             = "black"
219    custom_flow_chart_colour_scheme["Final target"]["dashed"]                            = 0
220    custom_flow_chart_colour_scheme["Vicious cycle"]["fillcolor"]                        = '"#FF3232"'
221    custom_flow_chart_colour_scheme["Vicious cycle"]["fontcolor"]                        = 'white'
222    custom_flow_chart_colour_scheme["Vicious cycle"]["color"]                            = "white"
223    custom_flow_chart_colour_scheme["Vicious cycle"]["dashed"]                           = 0
224    custom_flow_chart_colour_scheme["Up-to-date task"]["fillcolor"]                      = '"#B8CC6E"'
225    custom_flow_chart_colour_scheme["Up-to-date task"]["fontcolor"]                      = '"#006000"'
226    custom_flow_chart_colour_scheme["Up-to-date task"]["color"]                          = '"#006000"'
227    custom_flow_chart_colour_scheme["Up-to-date task"]["dashed"]                         = 0
228    custom_flow_chart_colour_scheme["Down stream"]["fillcolor"]                          = "white"
229    custom_flow_chart_colour_scheme["Down stream"]["fontcolor"]                          = "gray"
230    custom_flow_chart_colour_scheme["Down stream"]["color"]                              = "gray"
231    custom_flow_chart_colour_scheme["Down stream"]["dashed"]                             = 0
232    custom_flow_chart_colour_scheme["Explicitly specified task"]["fillcolor"]            = "transparent"
233    custom_flow_chart_colour_scheme["Explicitly specified task"]["fontcolor"]            = "black"
234    custom_flow_chart_colour_scheme["Explicitly specified task"]["color"]                = "black"
235    custom_flow_chart_colour_scheme["Explicitly specified task"]["dashed"]               = 0
236    custom_flow_chart_colour_scheme["Task to run"]["fillcolor"]                          = '"#EBF3FF"'
237    custom_flow_chart_colour_scheme["Task to run"]["fontcolor"]                          = '"#0044A0"'
238    custom_flow_chart_colour_scheme["Task to run"]["color"]                              = '"#0044A0"'
239    custom_flow_chart_colour_scheme["Task to run"]["dashed"]                             = 0
240    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["fillcolor"]      = 'transparent'
241    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["fontcolor"]      = '"#0044A0"'
242    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["color"]          = '"#0044A0"'
243    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["dashed"]         = 1
244    custom_flow_chart_colour_scheme["Up-to-date Final target"]["fillcolor"]              = '"#EFA03B"'
245    custom_flow_chart_colour_scheme["Up-to-date Final target"]["fontcolor"]              = '"#006000"'
246    custom_flow_chart_colour_scheme["Up-to-date Final target"]["color"]                  = '"#006000"'
247    custom_flow_chart_colour_scheme["Up-to-date Final target"]["dashed"]                 = 0
248
249if __name__ == '__main__':
250    pipeline_printout_graph (
251
252                                    open(options.flowchart, "w"),
253                                    # use flowchart file name extension to decide flowchart format
254                                    #   e.g. svg, jpg etc.
255                                    os.path.splitext(options.flowchart)[1][1:],
256
257                                    # final targets
258                                    [Final_target, Up_to_date_final_target],
259
260                                    # Explicitly specified tasks
261                                    [Explicitly_specified_task],
262
263                                    # Do we want key legend
264                                    no_key_legend   = not options.key_legend_in_graph,
265
266                                    # Print all the task types whether used or not
267                                    minimal_key_legend             = False,
268
269                                    user_colour_scheme = custom_flow_chart_colour_scheme,
270                                    pipeline_name = "Colour schemes")
271
272
273
274
275
276
277
278