diff options
Diffstat (limited to 'pnote/tools/export.py')
| -rw-r--r-- | pnote/tools/export.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/pnote/tools/export.py b/pnote/tools/export.py new file mode 100644 index 0000000..711dec8 --- /dev/null +++ b/pnote/tools/export.py @@ -0,0 +1,54 @@ +from pnote.tools.tool import Tool +import argparse, os, sys + +class ToolExport(Tool): + + def __init__(self): + self.format_file=None + + def add_parser(self,subparsers): + p = subparsers.add_parser("export", description="Export notes from subpaths in stdin") + p.add_argument("--format-file", help="Export notes 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="") + + def run(self, project, args): + if args.format_file: + if not os.path.exists(args.format_file): + print("Format file not found: {}".format(args.format_file)) + exit(1) + self.format_file=args.format_file + for line in sys.stdin: + subpath=line.rstrip() + 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="") +
\ No newline at end of file |
