summaryrefslogtreecommitdiff
path: root/scripts/view.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/view.py')
-rwxr-xr-xscripts/view.py122
1 files changed, 122 insertions, 0 deletions
diff --git a/scripts/view.py b/scripts/view.py
new file mode 100755
index 0000000..b73095c
--- /dev/null
+++ b/scripts/view.py
@@ -0,0 +1,122 @@
+#! /usr/bin/env python3
+#===============================
+#
+# viewer
+#
+# 2019/02/07 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
+#===============================
+import yaml
+import sys
+import os
+import re
+
+import base
+
+#====================================
+#
+# viewer
+#
+#====================================
+class viewer(base.base):
+
+ #--------------------
+ # parse
+ #
+ # -f : with file
+ # --oneline: one line
+ #--------------------
+ def parse(self, arg):
+ for arg in arg:
+ if (arg == "-f"):
+ self.with_file = 1
+ elif (arg == "--oneline"):
+ self.one_line = 1
+ elif (os.path.exists(arg) and
+ re.match("{}/projects".format(self.top()),
+ os.path.abspath(arg))):
+ self.files += [arg]
+
+ #--------------------
+ # __init__
+ #--------------------
+ def __init__(self, arg):
+
+ self.text = ""
+ self.files = []
+ self.with_file = 0
+ self.one_line = 0
+
+ self.parse(arg)
+
+ #--------------------
+ # make_one
+ # for --oneline
+ #--------------------
+ def make_one(self, file, data):
+
+ if (len(self.text) > 0):
+ self.text += "\n"
+
+ # show "key"
+ self.text += "{}: {}".format(
+ self.color("key", data["key"]),
+ data["title"])
+
+ #--------------------
+ # make_full
+ # for normal
+ #--------------------
+ def make_full(self, file, data):
+
+ if (len(self.text) > 0):
+ self.text += "\n"
+
+ # show "key"
+ self.text += "{}, {}, {}\n".format(
+ self.color("key", data["key"]),
+ self.color("status", data["status"]),
+ self.color("team", data["team"]));
+
+ # show title
+ self.text += "Title: {}\n".format(data["title"])
+
+ # show assignee
+ self.text += "Assignee: {}\n".format(data["assignee"])
+
+ if (self.with_file):
+ self.text += "File: {}\n".format(
+ os.path.abspath(file).replace("{}/".format(self.top()), ""))
+
+ # show comments
+ comments = data["comments"]
+ if (comments):
+ for comment in comments:
+ self.text += "\n{}".format(comment)
+
+ #--------------------
+ # show
+ #--------------------
+ def show(self):
+ for f in self.files:
+ F = open(f, "r+")
+ data = yaml.load(F)
+ F.close()
+
+ if (self.one_line):
+ self.make_one(f, data)
+ else:
+ self.make_full(f, data)
+
+ # escape " -> \"
+ # otherwise " will be disappeared
+ self.text = self.text.replace("\"", "\\\"");
+ self.do("echo \"{}\" | {}".format(
+ self.text, self.config("viewer")))
+
+#====================================
+#
+# As command
+#
+#====================================
+if __name__=='__main__':
+ viewer(sys.argv).show()