Python 3 compatibility

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

View file

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

View file

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

View file

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

View file

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

View file

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

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)