/ruffus/test/play_with_colours.py

https://code.google.com/p/ruffus/ · Python · 278 lines · 125 code · 77 blank · 76 comment · 5 complexity · 7d41bb6fac7a1ded92cbb8cc290e458d MD5 · raw file

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