diff options
-rw-r--r-- | .config.sample | 2 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rwxr-xr-x | scripts/view.py | 68 |
3 files changed, 63 insertions, 8 deletions
diff --git a/.config.sample b/.config.sample index 1350199..a12a486 100644 --- a/.config.sample +++ b/.config.sample @@ -4,3 +4,5 @@ viewer:less -RXE key:33 status:01;46 team:32 +tag:01;47 +error:01;41 @@ -43,4 +43,5 @@ You need to have **.config** file. You can copy sample .config, and edit it - ject -t IO,MM ... - ject -nt Core ... * -f : show with file name + * -r : show with relationships * --oneline : show one line 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 |