-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtaskdeps
110 lines (90 loc) · 3.49 KB
/
taskdeps
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
#!/usr/bin/env python3
# coding: utf-8
# pylint: disable=F0401,C0111,W0232,E1101,E1103,C0301,W0614
# Copyright 2015 by Leipzig University Library, http://ub.uni-leipzig.de
# The Finc Authors, http://finc.info
# Martin Czygan, <[email protected]>
#
# This file is part of some open source application.
#
# Some open source application is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either
# version 3 of the License, or (at your option) any later version.
#
# Some open source application is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
#
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
"""
Usage: taskdeps TASKNAME
Example output:
$ taskdeps JstorIntermediateSchema
└─ JstorIntermediateSchema(date=2018-05-03)
└─ AMSLService(date=2018-05-03, name=outboundservices:discovery)
└─ JstorCollectionMapping(date=2018-05-03)
└─ JstorIntermediateSchemaGenericCollection(date=2018-05-03)
└─ Executable(name=span-import, message=http://git.io/vI8NV)
└─ JstorXML(date=2018-05-03)
└─ JstorLatestMembers(date=2018-05-03, version=2)
└─ JstorMembers(date=2018-05-03)
└─ JstorPaths(date=2018-05-03)
└─ FTPMirror(host=example.com, ...)
└─ Executable(name=lftp, message=http://lftp.yar.ru/)
"""
from __future__ import print_function
import collections
import re
import sys
from io import StringIO
from luigi.cmdline_parser import CmdlineParser
from luigi.parameter import MissingParameterException
from luigi.task import Register
from luigi.task_register import TaskClassNotFoundException
from siskin.sources import *
from siskin.workflows import *
g = collections.defaultdict(set) # node -> [deps] dictionary
def sanitize(s):
"""
Slightly sanitize string.
"""
s = re.sub(r"host=[^ ,]+", "host=example.com", s, 0)
s = re.sub(r"username=[^ ,]+", "username=xxxx", s, 0)
s = re.sub(r"password=[^ ,]+", "password=xxxx", s, 0)
return s
def dump(root=None, indent=0, output=None):
"""
Taken from https://git.io/vp2zB.
"""
if indent == 0:
output.write(u'%s ── %s\n' % (' ' * indent, root))
else:
output.write(u'%s └─ %s\n' % (' ' * indent, root))
for dep in g[root]:
dump(root=dep, indent=indent + 1, output=output)
if __name__ == '__main__':
try:
parser = CmdlineParser(sys.argv[1:])
root_task = parser.get_task_obj()
queue = [root_task]
while len(queue) > 0:
task = queue.pop()
for dep in task.deps():
g[task].add(dep)
queue.append(dep)
output = StringIO()
dump(root=root_task, output=output)
print(sanitize(output.getvalue()))
except MissingParameterException as err:
print('missing parameter: %s' % err, file=sys.stderr)
sys.exit(1)
except TaskClassNotFoundException as err:
print(err, file=sys.stderr)
sys.exit(1)
except BrokenPipeError:
pass