mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Merge pull request #126 from maebert/absolute-imports
Cleaned up imports to work with Python2.6 and Python 3.3
This commit is contained in:
commit
b387e56822
8 changed files with 33 additions and 32 deletions
|
@ -4,6 +4,7 @@ Changelog
|
||||||
|
|
||||||
### 1.7 (December 22, 2013)
|
### 1.7 (December 22, 2013)
|
||||||
|
|
||||||
|
* __1.7.7__ Cleaned up imports, better unicode support
|
||||||
* __1.7.6__ Python 3 port for slugify
|
* __1.7.6__ Python 3 port for slugify
|
||||||
* __1.7.5__ Colorama is only needed on windows. Smaller fixes
|
* __1.7.5__ Colorama is only needed on windows. Smaller fixes
|
||||||
* __1.7.3__ Touches temporary files before opening them to allow more external editors.
|
* __1.7.3__ Touches temporary files before opening them to allow more external editors.
|
||||||
|
|
|
@ -129,11 +129,15 @@ def check_output_time_inline(context, text):
|
||||||
@then('the output should contain "{text}"')
|
@then('the output should contain "{text}"')
|
||||||
def check_output_inline(context, text):
|
def check_output_inline(context, text):
|
||||||
out = context.stdout_capture.getvalue()
|
out = context.stdout_capture.getvalue()
|
||||||
|
if isinstance(out, bytes):
|
||||||
|
out = out.decode('utf-8')
|
||||||
assert text in out
|
assert text in out
|
||||||
|
|
||||||
@then('the output should not contain "{text}"')
|
@then('the output should not contain "{text}"')
|
||||||
def check_output_not_inline(context, text):
|
def check_output_not_inline(context, text):
|
||||||
out = context.stdout_capture.getvalue()
|
out = context.stdout_capture.getvalue()
|
||||||
|
if isinstance(out, bytes):
|
||||||
|
out = out.decode('utf-8')
|
||||||
assert text not in out
|
assert text not in out
|
||||||
|
|
||||||
@then('we should see the message "{text}"')
|
@then('we should see the message "{text}"')
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
try: from . import Entry
|
from __future__ import absolute_import
|
||||||
except (SystemError, ValueError): import Entry
|
from . import Entry
|
||||||
try: from . import util
|
from . import util
|
||||||
except (SystemError, ValueError): import util
|
|
||||||
import codecs
|
import codecs
|
||||||
import os
|
import os
|
||||||
try: import parsedatetime.parsedatetime_consts as pdt
|
try: import parsedatetime.parsedatetime_consts as pdt
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
"""
|
"""
|
||||||
jrnl is a simple journal application for your command line.
|
jrnl is a simple journal application for your command line.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
__title__ = 'jrnl'
|
__title__ = 'jrnl'
|
||||||
__version__ = '1.7.6'
|
__version__ = '1.7.7'
|
||||||
__author__ = 'Manuel Ebert'
|
__author__ = 'Manuel Ebert'
|
||||||
__license__ = 'MIT License'
|
__license__ = 'MIT License'
|
||||||
__copyright__ = 'Copyright 2013 - 2014 Manuel Ebert'
|
__copyright__ = 'Copyright 2013 - 2014 Manuel Ebert'
|
||||||
|
|
28
jrnl/cli.py
28
jrnl/cli.py
|
@ -7,17 +7,12 @@
|
||||||
license: MIT, see LICENSE for more details.
|
license: MIT, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
from __future__ import absolute_import
|
||||||
from . import Journal
|
from . import Journal
|
||||||
from . import util
|
from . import util
|
||||||
from . import exporters
|
from . import exporters
|
||||||
from . import install
|
from . import install
|
||||||
from . import __version__
|
from . import __version__
|
||||||
except (SystemError, ValueError):
|
|
||||||
import Journal
|
|
||||||
import util
|
|
||||||
import exporters
|
|
||||||
import install
|
|
||||||
import jrnl
|
import jrnl
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -120,7 +115,8 @@ def run(manual_args=None):
|
||||||
args = parse_args(manual_args)
|
args = parse_args(manual_args)
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
print("{0} version {1}".format(jrnl.__title__, jrnl.__version__))
|
version_str = "{0} version {1}".format(jrnl.__title__, jrnl.__version__)
|
||||||
|
print(util.py2encode(version_str))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# If the first textual argument points to a journal file,
|
# If the first textual argument points to a journal file,
|
||||||
|
@ -186,17 +182,17 @@ def run(manual_args=None):
|
||||||
|
|
||||||
# Reading mode
|
# Reading mode
|
||||||
if not mode_compose and not mode_export:
|
if not mode_compose and not mode_export:
|
||||||
print(journal.pprint())
|
print(util.py2encode(journal.pprint()))
|
||||||
|
|
||||||
# Various export modes
|
# Various export modes
|
||||||
elif args.short:
|
elif args.short:
|
||||||
print(journal.pprint(short=True))
|
print(util.py2encode(journal.pprint(short=True)))
|
||||||
|
|
||||||
elif args.tags:
|
elif args.tags:
|
||||||
print(exporters.to_tag_list(journal))
|
print(util.py2encode(exporters.to_tag_list(journal)))
|
||||||
|
|
||||||
elif args.export is not False:
|
elif args.export is not False:
|
||||||
print(exporters.export(journal, args.export, args.output))
|
print(util.py2encode(exporters.export(journal, args.export, args.output)))
|
||||||
|
|
||||||
elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTO:
|
elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTO:
|
||||||
util.prompt("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.")
|
util.prompt("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.")
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
import os
|
import os
|
||||||
import string
|
import json
|
||||||
try: import simplejson as json
|
from .util import u, slugify
|
||||||
except ImportError: import json
|
|
||||||
try: from .util import u, slugify
|
|
||||||
except (SystemError, ValueError): from util import u, slugify
|
|
||||||
|
|
||||||
|
|
||||||
def get_tags_count(journal):
|
def get_tags_count(journal):
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
import readline
|
import readline
|
||||||
import glob
|
import glob
|
||||||
import getpass
|
import getpass
|
||||||
try: import simplejson as json
|
import json
|
||||||
except ImportError: import json
|
|
||||||
import os
|
import os
|
||||||
try: from . import util
|
from . import util
|
||||||
except (SystemError, ValueError): import util
|
|
||||||
|
|
||||||
|
|
||||||
def module_exists(module_name):
|
def module_exists(module_name):
|
||||||
|
|
|
@ -6,8 +6,7 @@ from tzlocal import get_localzone
|
||||||
import getpass as gp
|
import getpass as gp
|
||||||
import keyring
|
import keyring
|
||||||
import pytz
|
import pytz
|
||||||
try: import simplejson as json
|
import json
|
||||||
except ImportError: import json
|
|
||||||
if "win32" in sys.platform:
|
if "win32" in sys.platform:
|
||||||
import colorama
|
import colorama
|
||||||
colorama.init()
|
colorama.init()
|
||||||
|
@ -66,6 +65,10 @@ def u(s):
|
||||||
"""Mock unicode function for python 2 and 3 compatibility."""
|
"""Mock unicode function for python 2 and 3 compatibility."""
|
||||||
return s if PY3 or type(s) is unicode else unicode(s.encode('string-escape'), "unicode_escape")
|
return s if PY3 or type(s) is unicode else unicode(s.encode('string-escape'), "unicode_escape")
|
||||||
|
|
||||||
|
def py2encode(s):
|
||||||
|
"""Encode in Python 2, but not in python 3."""
|
||||||
|
return s.encode("utf-8") if PY2 and type(s) is unicode else s
|
||||||
|
|
||||||
def prompt(msg):
|
def prompt(msg):
|
||||||
"""Prints a message to the std err stream defined in util."""
|
"""Prints a message to the std err stream defined in util."""
|
||||||
if not msg.endswith("\n"):
|
if not msg.endswith("\n"):
|
||||||
|
|
Loading…
Add table
Reference in a new issue