From 8200ebb6fe09b972670be948b73bf79028718e83 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Fri, 19 Apr 2013 14:46:05 +0200 Subject: [PATCH] Python 3 compatibility --- CHANGELOG.md | 1 + jrnl/Journal.py | 6 +++--- jrnl/__init__.py | 4 ++-- jrnl/install.py | 3 ++- jrnl/jrnl.py | 3 ++- jrnl/util.py | 10 ++++++++++ 6 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 jrnl/util.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 84ba1c93..9338542d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog ### 1.0.4 * [Improved] Python 2.6 compatibility +* [New] Python 3 compatibility ### 1.0.3 (April 17, 2013) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 7c8b8f6d..60be81ff 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # encoding: utf-8 -from Entry import Entry +import Entry import os import parsedatetime.parsedatetime as pdt import re @@ -135,7 +135,7 @@ class Journal(object): # parsing successfull => save old entry and create new one if new_date and current_entry: entries.append(current_entry) - current_entry = Entry(self, date=new_date, title=line[date_length+1:]) + current_entry = Entry.Entry(self, date=new_date, title=line[date_length+1:]) except ValueError: # Happens when we can't parse the start of the line as an date. # In this case, just append line to our body. @@ -271,7 +271,7 @@ class Journal(object): if not date: # Still nothing? Meh, just live in the moment. date = self.parse_date("now") - entry = Entry(self, date, title, body) + entry = Entry.Entry(self, date, title, body) self.entries.append(entry) if sort: self.sort() diff --git a/jrnl/__init__.py b/jrnl/__init__.py index 6716b4ea..b1116eed 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -12,5 +12,5 @@ __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 Manuel Ebert' -from Journal import Journal -from jrnl import cli +from jrnl.Journal import Journal +from jrnl.jrnl import cli diff --git a/jrnl/install.py b/jrnl/install.py index e0b1d068..ca83b8de 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -6,6 +6,7 @@ import getpass try: import simplejson as json except ImportError: import json import os +import util def module_exists(module_name): """Checks if a module exists and can be imported""" @@ -62,7 +63,7 @@ def install_jrnl(config_path='~/.jrnl_config'): # Where to create the journal? path_query = 'Path to your journal file (leave blank for ~/journal.txt): ' - journal_path = raw_input(path_query).strip() or os.path.expanduser('~/journal.txt') + journal_path = util.py23_input(path_query).strip() or os.path.expanduser('~/journal.txt') default_config['journals']['default'] = os.path.expanduser(journal_path) # Encrypt it? diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index cbe4c3aa..3b88b43e 100755 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -8,6 +8,7 @@ """ import Journal +import util import exporters import install import os @@ -174,7 +175,7 @@ def cli(): if config['editor']: raw = get_text_from_editor(config) else: - raw = raw_input("[Compose Entry] ") + raw = util.py23_input("[Compose Entry] ") if raw: args.text = [raw] else: diff --git a/jrnl/util.py b/jrnl/util.py new file mode 100644 index 00000000..391cbc17 --- /dev/null +++ b/jrnl/util.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# encoding: utf-8 +import sys + +def py23_input(msg): + if sys.version_info[0] == 3: + try: return input(msg) + except SyntaxError: return "" + else: + return raw_input(msg)