summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2019-02-13 11:46:32 +0900
committerKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2019-04-09 14:59:34 +0900
commitf71c04567d20617cf10b3818903159a0744092d8 (patch)
tree6ce12a27c9e682c6f52d5eae4b815efae46a01be /scripts
parent5b3ba7911d0d2c64da59c5020f9307c1222edc58 (diff)
view: add -r option to show relationships
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/view.py68
1 files changed, 60 insertions, 8 deletions
diff --git a/scripts/view.py b/scripts/view.py
index 04928e1..308d1db 100755
--- a/scripts/view.py
+++ b/scripts/view.py
@@ -23,12 +23,15 @@ class viewer(base.base):
# parse
#
# -f : with file
+ # -r : with relationships
# --oneline: one line
#--------------------
def parse(self, arg):
for arg in arg:
if (arg == "-f"):
self.with_file = 1
+ elif (arg == "-r"):
+ self.with_rel = 1
elif (arg == "--oneline"):
self.one_line = 1
elif (os.path.exists(arg) and
@@ -44,11 +47,32 @@ class viewer(base.base):
self.text = ""
self.files = []
self.with_file = 0
+ self.with_rel = 0
self.one_line = 0
self.parse(arg)
#--------------------
+ # get_item
+ #--------------------
+ def get_item(self, data):
+ # Ughhhh
+ # All Yaml data is "dictionary", and not simple to getting data !!
+ # ( `⌒´)d I hate you !!
+ return list(data)[0]
+
+ #--------------------
+ # get_related_file
+ #--------------------
+ def get_related_file(self, data):
+ file = self.run("egrep -l \"key:\s+{}\" -r {}/projects".\
+ format(data, self.top()))
+ if (file):
+ return file
+ else:
+ return data
+
+ #--------------------
# get_data
#--------------------
def get_data(self, file):
@@ -61,29 +85,50 @@ class viewer(base.base):
# make_one
# for --oneline
#--------------------
- def make_one(self, file):
-
- data = self.get_data(file)
+ def make_one(self, tag, file):
if (len(self.text) > 0):
self.text += "\n"
+ if (tag):
+ self.text += "{:<22}".format(self.color("tag", tag))
+
+ if (not os.path.exists(file)):
+ self.text += self.color("error", "No such task ({})".format(file))
+ return
+
+ data = self.get_data(file)
+
# show "key"
self.text += "{}: {}".format(
self.color("key", data["key"]),
data["title"])
+ # show relationships
+ relationships = data["relationships"]
+ if ((not tag) and self.with_rel and relationships):
+ for d in relationships:
+ self.make_one(self.get_item(d.keys()),
+ self.get_related_file(self.get_item(d.values())))
+
#--------------------
# make_full
# for normal
#--------------------
- def make_full(self, file):
-
- data = self.get_data(file)
+ def make_full(self, tag, file):
if (len(self.text) > 0):
self.text += "\n"
+ if (tag):
+ self.text += "{:<22}".format(self.color("tag", tag))
+
+ if (not os.path.exists(file)):
+ self.text += self.color("error", "No such task ({})".format(file))
+ return
+
+ data = self.get_data(file)
+
# show "key"
self.text += "{}, {}, {}\n".format(
self.color("key", data["key"]),
@@ -106,15 +151,22 @@ class viewer(base.base):
for comment in comments:
self.text += "\n{}".format(comment)
+ # show relationships
+ relationships = data["relationships"]
+ if ((not tag) and self.with_rel and relationships):
+ for d in relationships:
+ self.make_full(self.get_item(d.keys()),
+ self.get_related_file(self.get_item(d.values())))
+
#--------------------
# show
#--------------------
def show(self):
for f in self.files:
if (self.one_line):
- self.make_one(f)
+ self.make_one(None, f)
else:
- self.make_full(f)
+ self.make_full(None, f)
# escape " -> \"
# otherwise " will be disappeared