File: play_with_colours.py

package info (click to toggle)
python-ruffus 2.6.3%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,828 kB
  • ctags: 2,843
  • sloc: python: 15,745; makefile: 180; sh: 14
file content (268 lines) | stat: -rw-r--r-- 9,977 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/env python
"""

    play_with_colours.py
    [--log_file PATH]
    [--verbose]

"""

################################################################################
#
#   test
#
#
#   Copyright (c) 7/13/2010 Leo Goodstadt
#
#   Permission is hereby granted, free of charge, to any person obtaining a copy
#   of this software and associated documentation files (the "Software"), to deal
#   in the Software without restriction, including without limitation the rights
#   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#   copies of the Software, and to permit persons to whom the Software is
#   furnished to do so, subject to the following conditions:
#
#   The above copyright notice and this permission notice shall be included in
#   all copies or substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#   THE SOFTWARE.
#################################################################################

import sys, os


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#   options


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888


from optparse import OptionParser
import StringIO

parser = OptionParser(version="%play_with_colours 1.0",
                      usage = "\n\n    play_with_colours "
                                "--flowchart FILE [options] "
                                "[--colour_scheme_index INT ] "
                                "[--key_legend_in_graph]")

#
#   pipeline
#
parser.add_option("--flowchart", dest="flowchart",
                    metavar="FILE",
                    type="string",
                    help="Don't actually run any commands; just print the pipeline "
                         "as a flowchart.")
parser.add_option("--colour_scheme_index", dest="colour_scheme_index",
                    metavar="INTEGER",
                    type="int",
                    help="Index of colour scheme for flow chart.")
parser.add_option("--key_legend_in_graph", dest="key_legend_in_graph",
                    action="store_true", default=False,
                    help="Print out legend and key for dependency graph.")

(options, remaining_args) = parser.parse_args()
if not options.flowchart:
    raise Exception("Missing mandatory parameter: --flowchart.\n")




#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#   imports


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

from ruffus import *
from ruffus.ruffus_exceptions import JobSignalledBreak


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#   Pipeline


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888


#
# up to date tasks
#
@check_if_uptodate (lambda : (False, ""))
def Up_to_date_task1(infile, outfile):
    pass

@check_if_uptodate (lambda : (False, ""))
@follows(Up_to_date_task1)
def Up_to_date_task2(infile, outfile):
    pass

@check_if_uptodate (lambda : (False, ""))
@follows(Up_to_date_task2)
def Up_to_date_task3(infile, outfile):
    pass


@check_if_uptodate (lambda : (False, ""))
@follows(Up_to_date_task3)
def Up_to_date_final_target(infile, outfile):
    pass


#
# Explicitly specified
#
@check_if_uptodate (lambda : (False, ""))
@follows(Up_to_date_task1)
def Explicitly_specified_task(infile, outfile):
    pass



#
# Tasks to run
#
@follows(Explicitly_specified_task)
def Task_to_run1(infile, outfile):
    pass


@follows(Task_to_run1)
def Task_to_run2(infile, outfile):
    pass

@follows(Task_to_run2)
def Task_to_run3(infile, outfile):
    pass

@check_if_uptodate (lambda : (False, ""))
@follows(Task_to_run2)
def Up_to_date_task_forced_to_rerun(infile, outfile):
    pass


#
# Final target
#
@follows(Up_to_date_task_forced_to_rerun, Task_to_run3)
def Final_target(infile, outfile):
    pass

#
# Ignored downstream
#
@follows(Final_target)
def Downstream_task1_ignored(infile, outfile):
    pass

@follows(Final_target)
def Downstream_task2_ignored(infile, outfile):
    pass











#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#   Main logic


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
from collections import defaultdict
custom_flow_chart_colour_scheme = defaultdict(dict)

#
#   Base chart on this overall colour scheme index
#
custom_flow_chart_colour_scheme["colour_scheme_index"] = options.colour_scheme_index

#
#   Overriding colours
#
if options.colour_scheme_index is None:
    custom_flow_chart_colour_scheme["Vicious cycle"]["linecolor"]                        = '"#FF3232"'
    custom_flow_chart_colour_scheme["Pipeline"]["fontcolor"]                             = '"#FF3232"'
    custom_flow_chart_colour_scheme["Key"]["fontcolor"]                                  = "black"
    custom_flow_chart_colour_scheme["Key"]["fillcolor"]                                  = '"#F6F4F4"'
    custom_flow_chart_colour_scheme["Task to run"]["linecolor"]                          = '"#0044A0"'
    custom_flow_chart_colour_scheme["Up-to-date"]["linecolor"]                           = "gray"
    custom_flow_chart_colour_scheme["Final target"]["fillcolor"]                         = '"#EFA03B"'
    custom_flow_chart_colour_scheme["Final target"]["fontcolor"]                         = "black"
    custom_flow_chart_colour_scheme["Final target"]["color"]                             = "black"
    custom_flow_chart_colour_scheme["Final target"]["dashed"]                            = 0
    custom_flow_chart_colour_scheme["Vicious cycle"]["fillcolor"]                        = '"#FF3232"'
    custom_flow_chart_colour_scheme["Vicious cycle"]["fontcolor"]                        = 'white'
    custom_flow_chart_colour_scheme["Vicious cycle"]["color"]                            = "white"
    custom_flow_chart_colour_scheme["Vicious cycle"]["dashed"]                           = 0
    custom_flow_chart_colour_scheme["Up-to-date task"]["fillcolor"]                      = '"#B8CC6E"'
    custom_flow_chart_colour_scheme["Up-to-date task"]["fontcolor"]                      = '"#006000"'
    custom_flow_chart_colour_scheme["Up-to-date task"]["color"]                          = '"#006000"'
    custom_flow_chart_colour_scheme["Up-to-date task"]["dashed"]                         = 0
    custom_flow_chart_colour_scheme["Down stream"]["fillcolor"]                          = "white"
    custom_flow_chart_colour_scheme["Down stream"]["fontcolor"]                          = "gray"
    custom_flow_chart_colour_scheme["Down stream"]["color"]                              = "gray"
    custom_flow_chart_colour_scheme["Down stream"]["dashed"]                             = 0
    custom_flow_chart_colour_scheme["Explicitly specified task"]["fillcolor"]            = "transparent"
    custom_flow_chart_colour_scheme["Explicitly specified task"]["fontcolor"]            = "black"
    custom_flow_chart_colour_scheme["Explicitly specified task"]["color"]                = "black"
    custom_flow_chart_colour_scheme["Explicitly specified task"]["dashed"]               = 0
    custom_flow_chart_colour_scheme["Task to run"]["fillcolor"]                          = '"#EBF3FF"'
    custom_flow_chart_colour_scheme["Task to run"]["fontcolor"]                          = '"#0044A0"'
    custom_flow_chart_colour_scheme["Task to run"]["color"]                              = '"#0044A0"'
    custom_flow_chart_colour_scheme["Task to run"]["dashed"]                             = 0
    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["fillcolor"]      = 'transparent'
    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["fontcolor"]      = '"#0044A0"'
    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["color"]          = '"#0044A0"'
    custom_flow_chart_colour_scheme["Up-to-date task forced to rerun"]["dashed"]         = 1
    custom_flow_chart_colour_scheme["Up-to-date Final target"]["fillcolor"]              = '"#EFA03B"'
    custom_flow_chart_colour_scheme["Up-to-date Final target"]["fontcolor"]              = '"#006000"'
    custom_flow_chart_colour_scheme["Up-to-date Final target"]["color"]                  = '"#006000"'
    custom_flow_chart_colour_scheme["Up-to-date Final target"]["dashed"]                 = 0

if __name__ == '__main__':
    pipeline_printout_graph (

                                    open(options.flowchart, "w"),
                                    # use flowchart file name extension to decide flowchart format
                                    #   e.g. svg, jpg etc.
                                    os.path.splitext(options.flowchart)[1][1:],

                                    # final targets
                                    [Final_target, Up_to_date_final_target],

                                    # Explicitly specified tasks
                                    [Explicitly_specified_task],

                                    # Do we want key legend
                                    no_key_legend   = not options.key_legend_in_graph,

                                    # Print all the task types whether used or not
                                    minimal_key_legend             = False,

                                    user_colour_scheme = custom_flow_chart_colour_scheme,
                                    pipeline_name = "Colour schemes")