Python 2.6 compatibility

This commit is contained in:
Manuel Ebert 2013-08-28 13:48:18 -07:00
parent 974f5a0f9c
commit 4e36d7baf0
4 changed files with 9 additions and 9 deletions

View file

@ -58,7 +58,7 @@ class Entry:
) )
def __repr__(self): def __repr__(self):
return "<Entry '{}' on {}>".format(self.title.strip(), self.date.strftime("%Y-%m-%d %H:%M")) return "<Entry '{0}' on {1}>".format(self.title.strip(), self.date.strftime("%Y-%m-%d %H:%M"))
def to_dict(self): def to_dict(self):
return { return {

View file

@ -181,7 +181,7 @@ class Journal(object):
return self.__unicode__() return self.__unicode__()
def __repr__(self): def __repr__(self):
return "<Journal with {} entries>".format(len(self.entries)) return "<Journal with {0} entries>".format(len(self.entries))
def write(self, filename=None): def write(self, filename=None):
"""Dumps the journal into the config file, overwriting it""" """Dumps the journal into the config file, overwriting it"""
@ -234,7 +234,7 @@ class Journal(object):
for m in matches: for m in matches:
date = e.date.strftime(self.config['timeformat']) date = e.date.strftime(self.config['timeformat'])
excerpt = e.body[m.start():min(len(e.body), m.end()+60)] excerpt = e.body[m.start():min(len(e.body), m.end()+60)]
res.append('{} {} ..'.format(date, excerpt)) res.append('{0} {1} ..'.format(date, excerpt))
e.body = "\n".join(res) e.body = "\n".join(res)
else: else:
for e in self.entries: for e in self.entries:

View file

@ -87,16 +87,16 @@ def export(journal, format, output=None):
try: try:
with open(output, 'w') as f: with open(output, 'w') as f:
f.write(content) f.write(content)
return "[Journal exported to {}]".format(output) return "[Journal exported to {0}]".format(output)
except IOError as e: except IOError as e:
return "[ERROR: {} {}]".format(e.filename, e.strerror) return "[ERROR: {0} {1}]".format(e.filename, e.strerror)
else: else:
return content return content
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 or txt.""" Format should be either json, md or txt."""
make_filename = lambda entry: e.date.strftime("%C-%m-%d_{}.{}".format(slugify(u(e.title)), format)) make_filename = lambda entry: e.date.strftime("%C-%m-%d_{0}.{1}".format(slugify(u(e.title)), format))
for e in journal.entries: for e in journal.entries:
full_path = os.path.join(path, make_filename(e)) full_path = os.path.join(path, make_filename(e))
if format == 'json': if format == 'json':
@ -107,4 +107,4 @@ def write_files(journal, path, format):
content = u(e) content = u(e)
with open(full_path, 'w') as f: with open(full_path, 'w') as f:
f.write(content) f.write(content)
return "[Journal exported individual files in {}]".format(path) return "[Journal exported individual files in {0}]".format(path)

View file

@ -123,7 +123,7 @@ def cli(manual_args=None):
try: try:
config = json.load(f) config = json.load(f)
except ValueError as e: except ValueError as e:
util.prompt("[There seems to be something wrong with your jrnl config at {}: {}]".format(CONFIG_PATH, e.message)) util.prompt("[There seems to be something wrong with your jrnl config at {0}: {1}]".format(CONFIG_PATH, e.message))
util.prompt("[Entry was NOT added to your journal]") util.prompt("[Entry was NOT added to your journal]")
sys.exit(1) sys.exit(1)
install.update_config(config, config_path=CONFIG_PATH) install.update_config(config, config_path=CONFIG_PATH)
@ -155,7 +155,7 @@ def cli(manual_args=None):
"entries" in os.listdir(config['journal']): "entries" in os.listdir(config['journal']):
journal = Journal.DayOne(**config) journal = Journal.DayOne(**config)
else: else:
util.prompt("[Error: {} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal'])) util.prompt("[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
sys.exit(1) sys.exit(1)
else: else:
journal = Journal.Journal(**config) journal = Journal.Journal(**config)