summaryrefslogtreecommitdiff
path: root/scripts/find.py
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2019-02-12 14:23:17 +0900
committerKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2019-04-09 14:59:34 +0900
commitd8acb2a5980b7e60087baba75344a7df37253122 (patch)
tree41b362e3b338a2d4a018fcb31fd1a130da1e84a8 /scripts/find.py
parent3df58144b27e92acde74b3925c37d0daa36ba54a (diff)
add PeriJect viewer
Very simple 1st verstion Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Diffstat (limited to 'scripts/find.py')
-rwxr-xr-xscripts/find.py124
1 files changed, 124 insertions, 0 deletions
diff --git a/scripts/find.py b/scripts/find.py
new file mode 100755
index 0000000..3150475
--- /dev/null
+++ b/scripts/find.py
@@ -0,0 +1,124 @@
+#! /usr/bin/env python3
+#===============================
+#
+# find
+#
+# 2019/02/07 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
+#===============================
+import sys
+import os
+import re
+
+import base
+
+#====================================
+#
+# find
+#
+#====================================
+class find(base.base):
+
+ #--------------------
+ # default_arg
+ #--------------------
+ def default_arg(self, arg):
+ # add "-ns Done" automatically
+ # if user doesn't specify "-s" or "-ns"
+ match = 0
+ for cmd in arg:
+ if ((cmd == "-s") or (cmd == "-ns")):
+ match = 1
+
+ if (not match):
+ return ["-ns", "Done"]
+
+ return []
+
+ #--------------------
+ # parse_option
+ #--------------------
+ def parse_option(self, arg, option, char, hit):
+
+ op = "-l" # hit
+ if (not hit):
+ op = "-L" # not hit
+
+ match = 0
+ for cmd in arg:
+ if (cmd == option):
+ match = 1
+ elif (match):
+ # Wolfram,Shimoda
+ # ->
+ # (Wolfram|Shimoda)
+ tgt = "({})".format(cmd.replace(",", "|"))
+
+ self.files = self.run("echo \"{}\" | xargs egrep {} \"{}:\s+{}\"".\
+ format(self.files, op, char, tgt))
+ return
+
+ #--------------------
+ # parse_files
+ #--------------------
+ def parse_files(self, arg):
+
+ # find specified key files if exist
+ for key in arg:
+ if (not self.is_key(key)):
+ continue
+
+ if (len(self.files) > 0):
+ self.files += "\n"
+
+ self.files += self.run("egrep -l \"key:\s+{}\" -r {}/projects".\
+ format(key, self.top()))
+
+ # all project files if no files
+ if (len(self.files) == 0):
+ self.files = self.run("find {}/projects -type f | grep -v schema".\
+ format(self.top()))
+
+ #--------------------
+ # __init__
+ #--------------------
+ def __init__(self, arg):
+ super().__init__()
+
+ self.files = ""
+
+ self.parse_files(arg)
+
+ arg += self.default_arg(arg)
+
+ # -s : matched status
+ # -ns : not matched status
+ # -a : matched assignee
+ # -na : not matched assignee
+ # -t : matched team
+ # -nt : not matched team
+ self.parse_option(arg, "-s", "status", 1)
+ self.parse_option(arg, "-ns", "status", 0)
+ self.parse_option(arg, "-a", "assignee", 1)
+ self.parse_option(arg, "-na", "assignee", 0)
+ self.parse_option(arg, "-t", "team", 1)
+ self.parse_option(arg, "-nt", "team", 0)
+
+ #--------------------
+ # get
+ #--------------------
+ def get(self):
+ return self.tolist(self.files)
+
+ #--------------------
+ # show
+ #--------------------
+ def show(self):
+ print(self.files)
+
+#====================================
+#
+# As command
+#
+#====================================
+if __name__=='__main__':
+ find(sys.argv).show()