Merge pull request #112 from maebert/version-info

Version info
This commit is contained in:
Manuel Ebert 2013-11-29 11:23:22 -08:00
commit 490ba01a2e
7 changed files with 31 additions and 16 deletions

View file

@ -3,6 +3,7 @@ Changelog
### 1.6 (November 5, 2013)
* __1.6.6__ -v prints the current version, also better strings for windows users. Furthermore, jrnl/jrnl.py moved to jrnl/cli.py
* __1.6.5__ Allows composing multi-line entries on the command line or importing files
* __1.6.4__ Fixed a bug that caused creating encrypted journals to fail
* __1.6.3__ New, pretty, _useful_ documentation!

View file

@ -34,3 +34,9 @@ Feature: Basic reading and writing to a journal
Then we should get no error
and the journal should contain "2013-07-25 09:00 I saw Elvis."
and the journal should contain "He's alive."
Scenario: Displaying the version number
Given we use the config "basic.json"
When we run "jrnl -v"
Then we should get no error
Then the output should contain "version"

View file

@ -1,7 +1,7 @@
from behave import *
import shutil
import os
from jrnl import jrnl
import jrnl
try:
from io import StringIO
except ImportError:

View file

@ -1,5 +1,5 @@
from behave import *
from jrnl import jrnl, Journal, util
from jrnl import cli, Journal, util
from dateutil import parser as date_parser
import os
import sys
@ -27,14 +27,14 @@ def _parse_args(command):
return nargs
def read_journal(journal_name="default"):
with open(jrnl.CONFIG_PATH) as config_file:
with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file)
with open(config['journals'][journal_name]) as journal_file:
journal = journal_file.read()
return journal
def open_journal(journal_name="default"):
with open(jrnl.CONFIG_PATH) as config_file:
with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file)
journal_conf = config['journals'][journal_name]
if type(journal_conf) is dict: # We can override the default config on a by-journal basis
@ -46,7 +46,7 @@ def open_journal(journal_name="default"):
@given('we use the config "{config_file}"')
def set_config(context, config_file):
full_path = os.path.join("features/configs", config_file)
jrnl.CONFIG_PATH = os.path.abspath(full_path)
cli.CONFIG_PATH = os.path.abspath(full_path)
@when('we run "{command}" and enter')
@when('we run "{command}" and enter "{inputs}"')
@ -54,9 +54,9 @@ def run_with_input(context, command, inputs=None):
text = inputs or context.text
args = _parse_args(command)
buffer = StringIO(text.strip())
jrnl.util.STDIN = buffer
util.STDIN = buffer
try:
jrnl.cli(args or None)
cli.run(args or None)
context.exit_status = 0
except SystemExit as e:
context.exit_status = e.code
@ -65,7 +65,7 @@ def run_with_input(context, command, inputs=None):
def run(context, command):
args = _parse_args(command)
try:
jrnl.cli(args or None)
cli.run(args or None)
context.exit_status = 0
except SystemExit as e:
context.exit_status = e.code
@ -154,7 +154,7 @@ def check_journal_content(context, text, journal_name="default"):
@then('journal "{journal_name}" should not exist')
def journal_doesnt_exist(context, journal_name="default"):
with open(jrnl.CONFIG_PATH) as config_file:
with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file)
journal_path = config['journals'][journal_name]
assert not os.path.exists(journal_path)
@ -168,7 +168,7 @@ def config_var(context, key, value, journal=None):
"int": int,
"str": str
}[t](value)
with open(jrnl.CONFIG_PATH) as config_file:
with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file)
if journal:
config = config["journals"][journal]

View file

@ -7,11 +7,11 @@ jrnl is a simple journal application for your command line.
"""
__title__ = 'jrnl'
__version__ = '1.6.5'
__version__ = '1.6.6'
__author__ = 'Manuel Ebert'
__license__ = 'MIT License'
__copyright__ = 'Copyright 2013 Manuel Ebert'
from . import Journal
from . import jrnl
from .jrnl import cli
from . import cli
from .cli import run

12
jrnl/jrnl.py → jrnl/cli.py Executable file → Normal file
View file

@ -12,11 +12,13 @@ try:
from . import util
from . import exporters
from . import install
from . import __version__
except (SystemError, ValueError):
import Journal
import util
import exporters
import install
import jrnl
import os
import tempfile
import subprocess
@ -30,6 +32,8 @@ PYCRYPTO = install.module_exists("Crypto")
def parse_args(args=None):
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--version', dest='version', action="store_true", help="prints version information and exits")
composing = parser.add_argument_group('Composing', 'To write an entry simply write it on the command line, e.g. "jrnl yesterday at 1pm: Went to the gym."')
composing.add_argument('text', metavar='', nargs="*")
@ -116,7 +120,7 @@ def update_config(config, new_config, scope, force_local=False):
else:
config.update(new_config)
def cli(manual_args=None):
def run(manual_args=None):
if not os.path.exists(CONFIG_PATH):
config = install.install_jrnl(CONFIG_PATH)
else:
@ -131,6 +135,10 @@ def cli(manual_args=None):
args = parse_args(manual_args)
if args.version:
print("{0} version {1}".format(jrnl.__title__, jrnl.__version__))
sys.exit(0)
# If the first textual argument points to a journal file,
# use this!
journal_name = args.text[0] if (args.text and args.text[0] in config['journals']) else 'default'
@ -230,4 +238,4 @@ def cli(manual_args=None):
journal.write()
if __name__ == "__main__":
cli()
run()

View file

@ -82,7 +82,7 @@ setup(
long_description=__doc__,
entry_points={
'console_scripts': [
'jrnl = jrnl:cli',
'jrnl = jrnl:run',
],
},
classifiers=[