Remove 'yaml-md' as an export option.

This commit is contained in:
William Minchin 2014-08-06 15:43:09 -06:00
parent 400d286254
commit 18f3e5df44
2 changed files with 8 additions and 9 deletions

View file

@ -42,7 +42,7 @@ def parse_args(args=None):
exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal') exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal')
exporting.add_argument('--short', dest='short', action="store_true", help='Show only titles or line containing the search tags') exporting.add_argument('--short', dest='short', action="store_true", help='Show only titles or line containing the search tags')
exporting.add_argument('--tags', dest='tags', action="store_true", help='Returns a list of all tags and number of occurences') exporting.add_argument('--tags', dest='tags', action="store_true", help='Returns a list of all tags and number of occurences')
exporting.add_argument('--export', metavar='TYPE', dest='export', choices=['text', 'txt', 'markdown', 'md', 'json', 'yaml', 'yaml-md'], help='Export your journal. TYPE can be json, markdown, text, or yaml.', default=False, const=None) exporting.add_argument('--export', metavar='TYPE', dest='export', choices=['text', 'txt', 'markdown', 'md', 'json', 'yaml'], help='Export your journal. TYPE can be json, markdown, text, or yaml.', default=False, const=None)
exporting.add_argument('-o', metavar='OUTPUT', dest='output', help='Optionally specifies output file when using --export. If OUTPUT is a directory, exports each entry into an individual file instead (required for pelican exports).', default=False, const=None) exporting.add_argument('-o', metavar='OUTPUT', dest='output', help='Optionally specifies output file when using --export. If OUTPUT is a directory, exports each entry into an individual file instead (required for pelican exports).', default=False, const=None)
exporting.add_argument('--encrypt', metavar='FILENAME', dest='encrypt', help='Encrypts your existing journal with a new password', nargs='?', default=False, const=None) exporting.add_argument('--encrypt', metavar='FILENAME', dest='encrypt', help='Encrypts your existing journal with a new password', nargs='?', default=False, const=None)
exporting.add_argument('--decrypt', metavar='FILENAME', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=None) exporting.add_argument('--decrypt', metavar='FILENAME', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=None)

View file

@ -11,7 +11,7 @@ import codecs
def get_tags_count(journal): def get_tags_count(journal):
"""Returns a set of tuples (count, tag) for all tags present in the journal.""" """Returns a set of tuples (count, tag) for all tags present in the journal."""
# Astute reader: should the following line leave you as puzzled as me the first time # Astute reader: should the following line leave you as puzzled as me the first time
# I came across this construction, worry not and embrace the ensuing moment of enlightment. # I came across this construction, worry not and embrace the ensuing moment of enlightenment.
tags = [tag tags = [tag
for entry in journal.entries for entry in journal.entries
for tag in set(entry.tags)] for tag in set(entry.tags)]
@ -80,7 +80,7 @@ def to_yaml(entry):
def export(journal, format, output=None): def export(journal, format, output=None):
"""Exports the journal to various formats. """Exports the journal to various formats.
format should be one of json, txt, text, md, markdown, yaml, yaml-md. format should be one of json, txt, text, md, markdown, yaml.
If output is None, returns a unicode representation of the output. If output is None, returns a unicode representation of the output.
If output is a directory, exports entries into individual files. If output is a directory, exports entries into individual files.
Otherwise, exports to the given output file. Otherwise, exports to the given output file.
@ -91,15 +91,14 @@ def export(journal, format, output=None):
"text": to_txt, "text": to_txt,
"md": to_md, "md": to_md,
"markdown": to_md, "markdown": to_md,
"yaml": to_yaml, "yaml": to_yaml
"yaml-md": to_yaml
} }
if format not in maps: if format not in maps:
return u"[ERROR: can't export to '{0}'. Valid options are 'md', 'txt', 'json', and 'yaml']".format(format) return u"[ERROR: can't export to '{0}'. Valid options are 'md', 'txt', 'json', and 'yaml']".format(format)
if output and os.path.isdir(output): # multiple files if output and os.path.isdir(output): # multiple files
return write_files(journal, output, format) return write_files(journal, output, format)
else: else:
if format is ("yaml" or "yaml-md"): if format is "yaml":
return u"YAML exports must be to a directory." return u"YAML exports must be to a directory."
else: else:
content = maps[format](journal) content = maps[format](journal)
@ -117,7 +116,8 @@ def export(journal, format, output=None):
def write_files(journal, path, format): def write_files(journal, path, format):
"""Turns your journal into separate files for each entry. """Turns your journal into separate files for each entry.
Format should be either json, md, txt or yaml.""" Format should be either json, md, txt or yaml."""
make_filename = lambda entry: e.date.strftime("%Y-%m-%d_{0}.{1}".format(slugify(u(e.title)), format)) extention = 'md' if format == 'yaml' else format
make_filename = lambda entry: e.date.strftime("%Y-%m-%d_{0}.{1}".format(slugify(u(e.title)), extention))
for e in journal.entries: for e in journal.entries:
if format == 'json': if format == 'json':
content = json.dumps(e.to_dict(), indent=2) + "\n" content = json.dumps(e.to_dict(), indent=2) + "\n"
@ -125,8 +125,7 @@ def write_files(journal, path, format):
content = e.to_md() content = e.to_md()
elif format in ('txt', 'text'): elif format in ('txt', 'text'):
content = e.__unicode__() content = e.__unicode__()
elif format in ('yaml', 'yaml-md'): elif format == 'yaml':
make_filename = lambda entry: e.date.strftime("%Y-%m-%d_{0}.{1}".format(slugify(u(e.title)), 'md'))
content = to_yaml(e) content = to_yaml(e)
full_path = os.path.join(path, make_filename(e)) full_path = os.path.join(path, make_filename(e))
with codecs.open(full_path, "w", "utf-8") as f: with codecs.open(full_path, "w", "utf-8") as f: