diff options
| author | Loïc Guégan <loic@debianus> | 2024-04-19 07:48:27 +0200 |
|---|---|---|
| committer | Loïc Guégan <loic@debianus> | 2024-04-19 07:48:27 +0200 |
| commit | e7d21b74a6dba14daa004295441ad66b5b27c704 (patch) | |
| tree | fbeb983cabfbe283d618a3f4b88c61b0338c81aa /pnote/tools/search.py | |
| parent | b36e130286061edf577e85a5d6e9649abd63c93e (diff) | |
Create export command
Diffstat (limited to 'pnote/tools/search.py')
| -rw-r--r-- | pnote/tools/search.py | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/pnote/tools/search.py b/pnote/tools/search.py index ad8dee9..25266c6 100644 --- a/pnote/tools/search.py +++ b/pnote/tools/search.py @@ -3,9 +3,6 @@ import argparse, os class ToolSearch(Tool): - def __init__(self): - self.format_file=None - def add_parser(self,subparsers): p = subparsers.add_parser("search", description="Perform search operation on your notes") p.add_argument("-g", "--grep", help="Grep an expression") @@ -16,28 +13,11 @@ class ToolSearch(Tool): p.add_argument("-s", "--subpath-only", help="Show file subpath only", action='store_true') p.add_argument("--last-created", help="Get last n created note files") p.add_argument("--last-added", help="Get last n added note files") - p.add_argument("--format-file", help="Format output according to a format file") def catsubpath(self,project,subpath): - if self.format_file is not None: - with open(project.getpath(subpath),"r") as noteFile: - with open(self.format_file,"r") as tplFile: - variables={ - "content":noteFile.read(), - "created":project.getfileinfo(subpath,"created"), - "added":project.getfileinfo(subpath,"added"), - "id":project.getfileinfo(subpath,"id"), - "hostname":project.getfileinfo(subpath,"hostname"), - "platform":project.getfileinfo(subpath,"platform"), - "tags":project.listtags(subpath), - "subpath":subpath} - for line in tplFile: - print(line.format(**variables),end="") - else: - with open(project.getpath(subpath),"r") as fp: - for line in fp: - print(line,end="") - + with open(project.getpath(subpath),"r") as fp: + for line in fp: + print(line,end="") def catsubpaths(self, project, subpaths, content_only=False, subpath_only=False): first=True @@ -46,10 +26,9 @@ class ToolSearch(Tool): print(subpath) continue if not content_only: - if self.format_file is not None: - if not first: - print() - self.printsubpath(subpath) + if not first: + print() + self.printsubpath(subpath) self.catsubpath(project,subpath) first=False @@ -61,11 +40,6 @@ class ToolSearch(Tool): if content_only and subpath_only: print("content and file-path options cannot be used at the same time") exit(1) - if args.format_file: - if not os.path.exists(args.format_file): - print("Template file not found: {}".format(args.format_file)) - exit(1) - self.format_file=args.format_file if args.grep: first=True for entry in project.grep(args.grep, ignore_case): |
