Python 3 compatibility

This commit is contained in:
Manuel Ebert 2013-04-19 14:46:05 +02:00
parent cf720732b2
commit 3052e0cce7
6 changed files with 20 additions and 7 deletions

View file

@ -4,6 +4,7 @@ Changelog
### 1.0.4 ### 1.0.4
* [Improved] Python 2.6 compatibility * [Improved] Python 2.6 compatibility
* [New] Python 3 compatibility
### 1.0.3 (April 17, 2013) ### 1.0.3 (April 17, 2013)

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
from Entry import Entry import Entry
import os import os
import parsedatetime.parsedatetime as pdt import parsedatetime.parsedatetime as pdt
import re import re
@ -135,7 +135,7 @@ class Journal(object):
# parsing successfull => save old entry and create new one # parsing successfull => save old entry and create new one
if new_date and current_entry: if new_date and current_entry:
entries.append(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: except ValueError:
# Happens when we can't parse the start of the line as an date. # Happens when we can't parse the start of the line as an date.
# In this case, just append line to our body. # 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. if not date: # Still nothing? Meh, just live in the moment.
date = self.parse_date("now") date = self.parse_date("now")
entry = Entry(self, date, title, body) entry = Entry.Entry(self, date, title, body)
self.entries.append(entry) self.entries.append(entry)
if sort: if sort:
self.sort() self.sort()

View file

@ -12,5 +12,5 @@ __author__ = 'Manuel Ebert'
__license__ = 'MIT License' __license__ = 'MIT License'
__copyright__ = 'Copyright 2013 Manuel Ebert' __copyright__ = 'Copyright 2013 Manuel Ebert'
from Journal import Journal from jrnl.Journal import Journal
from jrnl import cli from jrnl.jrnl import cli

View file

@ -6,6 +6,7 @@ import getpass
try: import simplejson as json try: import simplejson as json
except ImportError: import json except ImportError: import json
import os import os
import util
def module_exists(module_name): def module_exists(module_name):
"""Checks if a module exists and can be imported""" """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? # Where to create the journal?
path_query = 'Path to your journal file (leave blank for ~/journal.txt): ' 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) default_config['journals']['default'] = os.path.expanduser(journal_path)
# Encrypt it? # Encrypt it?

View file

@ -8,6 +8,7 @@
""" """
import Journal import Journal
import util
import exporters import exporters
import install import install
import os import os
@ -174,7 +175,7 @@ def cli():
if config['editor']: if config['editor']:
raw = get_text_from_editor(config) raw = get_text_from_editor(config)
else: else:
raw = raw_input("[Compose Entry] ") raw = util.py23_input("[Compose Entry] ")
if raw: if raw:
args.text = [raw] args.text = [raw]
else: else:

10
jrnl/util.py Normal file
View file

@ -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)