Compare commits

...

45 commits

Author SHA1 Message Date
Paul Liu
ba34ba2e58 Update iA Writer bundle id (#464) 2017-02-12 21:03:42 -08:00
Manuel Ebert
a7b98f28e1 Update CONTRIBUTING.md 2017-01-04 12:02:53 -08:00
Radomír Bosák
4ba577db33 Fix failing behave tests (#447)
The keyring package broke backward compatibility in version 8.0 by
moving some keyring backends to another package, keyrings.alt, as
documented in the changelog [1].

This change broke behave tests which were trying to use
keyring.backends.file.PlaintextKeyring - no longer existing in keyring
package.

This commit adds the keyrings.alt package as dependency so that the
PlaintextKeyring class can be used.

[1] https://pythonhosted.org/keyring/history.html#id22
2017-01-04 10:24:03 -08:00
Andrew Sauber
b2ddd22e50 add fully functional decryption script to docs (#431) 2016-08-20 17:55:09 +00:00
doozr
cf6bc9c051 Do not crash if subdirs found inside Day One dir (#430) 2016-07-14 14:24:48 -07:00
Andrew Sauber
976a6faaa8 Minor Documentation Fixes (#425)
* Update installation.rst

* minor fixes to encryption.rst

instruct user to set `HISTIGNORE` while maintaining their existing `HISTIGNORE`
minor whitespace change
2016-05-17 10:35:56 -07:00
David Silva
54d36297a8 Change README url to point to actual documentation (#423) 2016-05-06 11:02:53 -07:00
Manuel Ebert
5dccceff78 Don't build 2.6 2015-12-28 21:58:08 -08:00
Manuel Ebert
7f8ebcbca6 Merge pull request #370 from vitorgalvao/patch-1
readme.md: homebrew instructions
2015-12-28 21:54:54 -08:00
Vítor Galvão
4a89f92f97 readme.md: homebrew instructions 2015-07-08 20:40:08 +01:00
Manuel Ebert
7c1d552a35 Merge pull request #325 from nikvdp/master
Correct issue #259, also fix issue with specifying DayOne journals in install
2015-01-11 08:50:24 -08:00
Manuel Ebert
f5f301c519 Merge pull request #310 from dedan/patch-2
fix small typo
2014-12-18 10:37:07 +07:00
Nik V
b99c82f9be Don't die if you specify a directory (DayOne journal) to install 2014-12-11 21:28:04 +08:00
Nik V
ef0227cf89 Fix bug with dayone journals on linux 2014-12-11 21:21:18 +08:00
Manuel Ebert
d0b476187f Merge pull request #321 from seinfield/master
corrects issue #316
2014-12-08 13:39:36 +07:00
seinfield
10235b77ce corrected typo 2014-12-07 03:00:41 -05:00
seinfield
3323db3e2a corrects issue #316 2014-12-07 02:55:49 -05:00
Manuel Ebert
270157010c Icon update! 2014-11-29 18:36:42 +07:00
Stephan Gabler
12d34667fd fix small typo 2014-11-19 14:26:13 +01:00
Manuel Ebert
79eb1bb757 Merge pull request #309 from maebert/tmpfile-fix
Fixes #308
2014-11-17 15:46:45 +01:00
Manuel Ebert
44c74d509c Fixes #308 2014-11-17 15:36:43 +01:00
Manuel Ebert
d216dcdbd2 Merge pull request #305 from pcarranza/debug-flag
Added basic logging feature to understand how is configuration loaded
2014-11-09 10:51:03 +01:00
Pablo Carranza
75eaf275b4 Added exception info to the output when it cannot be loaded 2014-11-06 19:15:11 -05:00
Pablo Carranza
a43cf16395 Added basic logging feature to understand how is configuration loaded 2014-11-06 15:36:03 -05:00
Manuel Ebert
73d9882b64 Travis update 2014-11-06 12:38:57 +01:00
Manuel Ebert
e77037b0f1 github_release plug on setup.py 2014-11-06 12:35:31 +01:00
Manuel Ebert
b45e52f743 Merge pull request #304 from maebert/unicode-fixes
Unicode fixes
2014-11-06 11:33:36 +01:00
Manuel Ebert
474bf0a71a version bump 2014-11-06 11:30:15 +01:00
Manuel Ebert
799ff762b2 Fix for writing non-unicode entries on prompt 2014-11-06 11:30:11 +01:00
Manuel Ebert
43f1166ecf Tests for writing non-unicode entries on prompt 2014-11-06 11:30:06 +01:00
Manuel Ebert
acf41a153a Timezone parsing fix 2014-10-21 18:28:03 +02:00
Manuel Ebert
19c57ecf70 Open journal before writing 2014-10-21 18:28:03 +02:00
Manuel Ebert
94b53b9247 Safer temp file creation 2014-10-21 18:28:03 +02:00
Manuel Ebert
9603f7d3ad Merge pull request #289 from willbarrett/bug/journal-not-found
Handle situation where a specified jounal is not found.
2014-10-20 11:47:55 -07:00
Manuel Ebert
cde55ad540 Merge pull request #294 from jfunction/master
Fixed a bug. --edit now shows [1 entry modified] not [1 entries modified]
2014-10-16 15:22:54 -07:00
jfunction
1013d77173 Fixed a bug whereby editing a single entry resulted in the plural form being used. Now editing one entry results in "[1 entry modified]" 2014-10-15 14:23:03 +02:00
Will Barrett
76881f66e9 Handle situation where a specified jounal is not found. 2014-10-06 16:45:25 -04:00
Manuel Ebert
e6cfeabc17 Installation instructions for homebrew 2014-10-02 10:28:39 -07:00
Manuel Ebert
17b439eba4 version bump 2014-09-30 10:17:07 -07:00
Manuel Ebert
c8e5d1ff34 util fixes 2014-09-30 10:16:50 -07:00
Manuel Ebert
bd6edffc81 Merge pull request #283 from pcarranza/ontoday
Fixed "-on today" option inclusive date parsing
2014-09-25 12:35:17 -07:00
Pablo Carranza
e9f691e399 Fixed -on today option parsing 2014-09-25 10:04:17 -04:00
Manuel Ebert
05e63dc76a Merge pull request #278 from pcarranza/master
Added how to ignore history appending for zsh
2014-09-22 12:16:16 -07:00
Pablo Carranza
c81f0e0c1d Added how to ignore history appending for zsh 2014-09-22 07:42:00 -04:00
Manuel Ebert
afcccb78c1 Fix docs typo 2014-09-17 08:35:39 -07:00
22 changed files with 245 additions and 73 deletions

View file

@ -1,12 +1,11 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
install:
- "pip install -e . --use-mirrors"
- "pip install pycrypto>=2.6 --use-mirrors"
- "pip install -e ."
- "pip install pycrypto>=2.6"
- "pip install -q behave"
# command to run tests
script:

View file

@ -4,6 +4,9 @@ Changelog
### 1.9 (July 21, 2014)
* __1.9.8__ Fixes a problem with temporary files on windows
* __1.9.7__ Fixes writing non-ascii entries on the prompt
* __1.9.6__ Fuzzy time parsing improvements (thanks to @pcarranza)
* __1.9.5__ Multi-word tags for DayOne Journals
* __1.9.4__ Fixed: Order of journal entries in file correct after --edit'ing
* __1.9.3__ Fixed: Tags at the beginning of lines

View file

@ -3,6 +3,9 @@ Contributing
If you use jrnl, you can totally make my day by just saying "thanks for the code" or by [tweeting about jrnl](https://twitter.com/intent/tweet?text=Write+your+memoirs+on+the+command+line.+Like+a+boss.+%23jrnl&url=http%3A%2F%2Fmaebert.github.io%2Fjrnl&via=maebert). It's your chance to make a programmer happy today! If you have a minute or two, let me know what you use jrnl for and how, it'll help me to make it even better. If you blog about jrnl, I'll send you a post card!
> # Important:
> ### Please develop new features against the `2.0-rc1` branch. PRs to the `master` branch will not get merged until version 2.0 is released.
Docs & Typos
------------
@ -12,7 +15,7 @@ If you find a typo or a mistake in the docs, just fix it right away and send a p
Bugs
----
They unfortunately happen. Specifically, I don't have a Windows machine to test on, so expect a few rough spots. If you found a bug, please [open a new issue](https://www.github.com/maebert/jrnl/issues/new) and describe it as well as possible. If you're a programmer and have a little time time spare, go ahead, fork the code and fix bugs you spot, it'll be much appreciated!
They unfortunately happen. Specifically, I don't have a Windows machine to test on, so expect a few rough spots. If you found a bug, please [open a new issue](https://www.github.com/maebert/jrnl/issues/new) and describe it as well as possible. If you're a programmer and have a little time to spare, go ahead, fork the code and fix bugs you spot, it'll be much appreciated!
Feature requests and ideas

View file

@ -1,7 +1,7 @@
jrnl [![Build Status](http://img.shields.io/travis/maebert/jrnl.svg?style=flat)](https://travis-ci.org/maebert/jrnl) [![Downloads](http://img.shields.io/pypi/dm/jrnl.svg?style=flat)](https://pypi.python.org/pypi/jrnl/) [![Version](http://img.shields.io/pypi/v/jrnl.svg?style=flat)](https://pypi.python.org/pypi/jrnl/)
====
_For news on updates or to get help, [read the docs](http://maebert.github.io/jrnl), follow [@maebert](https://twitter.com/maebert) or [submit an issue](https://github.com/maebert/jrnl/issues/new) on Github._
_For news on updates or to get help, [read the docs](http://maebert.github.io/jrnl/overview.html), follow [@maebert](https://twitter.com/maebert) or [submit an issue](https://github.com/maebert/jrnl/issues/new) on Github._
*jrnl* is a simple journal application for your command line. Journals are stored as human readable plain text files - you can put them into a Dropbox folder for instant syncing and you can be assured that your journal will still be readable in 2050, when all your fancy iPad journal applications will long be forgotten.
@ -39,3 +39,6 @@ Or, if you want the option to encrypt your journal,
pip install jrnl[encrypted]
Alternatively, on OS X with [Homebrew](http://brew.sh/) installed:
brew install jrnl

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -30,18 +30,39 @@ A note on security
While jrnl follows best practises, true security is an illusion. Specifically, jrnl will leave traces in your memory and your shell history -- it's meant to keep journals secure in transit, for example when storing it on an `untrusted <http://techcrunch.com/2014/04/09/condoleezza-rice-joins-dropboxs-board/>`_ services such as Dropbox. If you're concerned about security, disable history logging for journal in your ``.bashrc`` ::
HISTINGNORE="jrnl *"
HISTIGNORE="$HISTIGNORE:jrnl *"
If you are using zsh instead of bash, you can get the same behaviour adding this to your ``zshrc`` ::
setopt HIST_IGNORE_SPACE
alias jrnl=" jrnl"
Manual decryption
-----------------
Should you ever want to decrypt your journal manually, you can do so with any program that supports the AES algorithm in CBC. The key used for encryption is the SHA-256-hash of your password, the IV (initialisation vector) is stored in the first 16 bytes of the encrypted file. The plain text is encoded in UTF-8 and padded according to PKCS#7 before being encrypted. So, to decrypt a journal file in python, run::
Should you ever want to decrypt your journal manually, you can do so with any program that supports the AES algorithm in CBC. The key used for encryption is the SHA-256-hash of your password, the IV (initialisation vector) is stored in the first 16 bytes of the encrypted file. The plain text is encoded in UTF-8 and padded according to PKCS#7 before being encrypted. Here's a Python script that you can use to decrypt your journal::
#!/usr/bin/env python3
import argparse
from Crypto.Cipher import AES
import getpass
import hashlib
import sys
parser = argparse.ArgumentParser()
parser.add_argument("filepath", help="journal file to decrypt")
args = parser.parse_args()
pwd = getpass.getpass()
key = hashlib.sha256(pwd.encode('utf-8')).digest()
with open(args.filepath, 'rb') as f:
ciphertext = f.read()
crypto = AES.new(key, AES.MODE_CBC, ciphertext[:16])
plain = crypto.decrypt(ciphertext[16:])
plain = plain.strip(plain[-1:])
plain = plain.decode("utf-8")
print(plain)
import hashlib, Crypto.Cipher
key = hashlib.sha256(my_password).digest()
with open("my_journal.txt") as f:
cipher = f.read()
crypto = AES.new(key, AES.MODE_CBC, iv = cipher[:16])
plain = crypto.decrypt(cipher[16:])
plain = plain.strip(plain[-1])
plain = plain.decode("utf-8")

View file

@ -6,7 +6,11 @@ Getting started
Installation
------------
Install *jrnl* using pip ::
On OS X, the easiest way to install *jrnl* is using `Homebrew <http://brew.sh/>`_ ::
brew install jrnl
On other platforms, install *jrnl* using pip ::
pip install jrnl
@ -20,7 +24,7 @@ to install the dependencies for encrypting journals as well.
Installing the encryption library, `pycrypto`, requires a `gcc` compiler. For this reason, jrnl will not install `pycrypto` unless explicitly told so like this. You can `install PyCrypto manually <https://www.dlitz.net/software/pycrypto/>`_ first or install it with ``pip install pycrypto`` if you have a `gcc` compiler.
Also note that when using zsh, you the correct syntax is ``pip install "jrnl[encrypted]"`` (note the quotes).
Also note that when using zsh, the correct syntax is ``pip install "jrnl[encrypted]"`` (note the quotes).
The first time you run ``jrnl`` you will be asked where your journal file should be created and whether you wish to encrypt it.

View file

@ -108,10 +108,17 @@ On OS X, you can use the fabulous `iA Writer <http://www.iawriter.com/mac>`_ to
.. code-block:: javascript
"editor": "open -b jp.informationarchitects.WriterForMacOSX -Wn"
"editor": "open -b pro.writer.mac -Wn"
What does this do? ``open -b ...`` opens a file using the application identified by the bundle identifier (a unique string for every app out there). ``-Wn`` tells the application to wait until it's closed before passing back control, and to use a new instance of the application.
If the ``pro.writer.mac`` bundle identifier is not found on your system, you can find the right string to use by inspecting iA Writer's ``Info.plist`` file in your shell:
.. code-block:: sh
$ grep -A 1 CFBundleIdentifier /Applications/iA\ Writer.app/Contents/Info.plist
<key>CFBundleIdentifier</key>
<string>pro.writer.mac</string>
Notepad++ on Windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -0,0 +1,16 @@
{
"default_hour": 9,
"timeformat": "%Y-%m-%d %H:%M",
"linewrap": 80,
"encrypt": false,
"editor": "",
"default_minute": 0,
"highlight": true,
"password": "",
"journals": {
"simple": "features/journals/simple.journal",
"work": "features/journals/work.journal",
"ideas": "features/journals/nothing.journal"
},
"tagsymbols": "@"
}

View file

@ -34,3 +34,8 @@ Feature: Multiple journals
Then journal "ideas" should not exist
When we run "jrnl ideas 23 july 2012: sell my junk on ebay and make lots of money"
Then journal "ideas" should have 1 entry
Scenario: Gracefully handle a config without a default journal
Given we use the config "multiple_without_default.json"
When we run "jrnl fork this repo and fix something"
Then we should see the message "You have not specified a journal. Either provide a default journal in your config file, or specify one of your journals on the command line."

View file

@ -59,3 +59,10 @@ Feature: Zapped bugs should stay dead.
2014-04-24 09:00 Ran 6.2 miles today in 1:02:03.
| I'm feeling sore because I forgot to stretch.
"""
Scenario: Writing an entry at the prompt with non-ascii characters
# https://github.com/maebert/jrnl/issues/295
Given we use the config "basic.json"
When we run "jrnl" and enter "Crème brûlée & Mötorhead"
Then we should get no error
and the journal should contain "Crème brûlée & Mötorhead"

View file

@ -2,11 +2,11 @@ from behave import *
from jrnl import cli, Journal, util
from dateutil import parser as date_parser
import os
import sys
import codecs
import json
import pytz
import keyring
keyring.set_keyring(keyring.backends.file.PlaintextKeyring())
import keyrings
keyring.set_keyring(keyrings.alt.file.PlaintextKeyring())
try:
from io import StringIO
except ImportError:
@ -30,7 +30,7 @@ def _parse_args(command):
def read_journal(journal_name="default"):
with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file)
with open(config['journals'][journal_name]) as journal_file:
with codecs.open(config['journals'][journal_name], 'r', 'utf-8') as journal_file:
journal = journal_file.read()
return journal
@ -57,7 +57,7 @@ def run_with_input(context, command, inputs=None):
buffer = StringIO(text.strip())
util.STDIN = buffer
try:
cli.run(args or None)
cli.run(args)
context.exit_status = 0
except SystemExit as e:
context.exit_status = e.code
@ -66,7 +66,7 @@ def run_with_input(context, command, inputs=None):
def run(context, command):
args = _parse_args(command)
try:
cli.run(args or None)
cli.run(args)
context.exit_status = 0
except SystemExit as e:
context.exit_status = e.code
@ -124,10 +124,8 @@ def check_output(context, text=None):
def check_output_time_inline(context, text):
out = context.stdout_capture.getvalue()
local_tz = tzlocal.get_localzone()
utc_time = date_parser.parse(text)
date = utc_time + local_tz._utcoffset
local_date = date.strftime("%Y-%m-%d %H:%M")
assert local_date in out, local_date
local_time = date_parser.parse(text).astimezone(local_tz).strftime("%Y-%m-%d %H:%M")
assert local_time in out, local_time
@then('the output should contain "{text}"')
def check_output_inline(context, text):
@ -186,7 +184,7 @@ def config_var(context, key, value, journal=None):
@then('the journal should have {number:d} entry')
@then('journal "{journal_name}" should have {number:d} entries')
@then('journal "{journal_name}" should have {number:d} entry')
def check_journal_content(context, number, journal_name="default"):
def check_num_entries(context, number, journal_name="default"):
journal = open_journal(journal_name)
assert len(journal.entries) == number

View file

@ -30,6 +30,8 @@ class DayOne(Journal.Journal):
filenames = [os.path.join(self.config['journal'], "entries", f) for f in os.listdir(os.path.join(self.config['journal'], "entries"))]
self.entries = []
for filename in filenames:
if os.path.isdir(filename):
continue
with open(filename, 'rb') as plist_entry:
try:
dict_entry = plistlib.readPlist(plist_entry)
@ -58,7 +60,10 @@ class DayOne(Journal.Journal):
if not hasattr(entry, "uuid"):
entry.uuid = uuid.uuid1().hex
utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
filename = os.path.join(self.config['journal'], "entries", entry.uuid + ".doentry")
# make sure to upper() the uuid since uuid.uuid1 returns a lowercase string by default
# while dayone uses uppercase by default. On fully case preserving filesystems (e.g.
# linux) this results in duplicated entries when we save the file
filename = os.path.join(self.config['journal'], "entries", entry.uuid.upper() + ".doentry")
entry_plist = {
'Creation Date': utc_time,
'Starred': entry.starred if hasattr(entry, 'starred') else False,

View file

@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line.
from __future__ import absolute_import
__title__ = 'jrnl'
__version__ = '1.9.5'
__version__ = '1.9.8'
__author__ = 'Manuel Ebert'
__license__ = 'MIT License'
__copyright__ = 'Copyright 2013 - 2014 Manuel Ebert'

View file

@ -17,16 +17,19 @@ import jrnl
import os
import argparse
import sys
import logging
xdg_config = os.environ.get('XDG_CONFIG_HOME')
CONFIG_PATH = os.path.join(xdg_config, "jrnl") if xdg_config else os.path.expanduser('~/.jrnl_config')
PYCRYPTO = install.module_exists("Crypto")
log = logging.getLogger(__name__)
def parse_args(args=None):
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--version', dest='version', action="store_true", help="prints version information and exits")
parser.add_argument('-ls', dest='ls', action="store_true", help="displays accessible journals")
parser.add_argument('-d', '--debug', dest='debug', action='store_true', help='execute in debug mode')
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="*")
@ -90,6 +93,7 @@ def decrypt(journal, filename=None):
def touch_journal(filename):
"""If filename does not exist, touch the file"""
if not os.path.exists(filename):
log.debug('Creating journal file %s', filename)
util.prompt("[Journal created at {0}]".format(filename))
open(filename, 'a').close()
@ -114,8 +118,15 @@ def update_config(config, new_config, scope, force_local=False):
config.update(new_config)
def configure_logger(debug=False):
logging.basicConfig(level=logging.DEBUG if debug else logging.INFO,
format='%(levelname)-8s %(name)-12s %(message)s')
logging.getLogger('parsedatetime').setLevel(logging.INFO) # disable parsedatetime debug logging
def run(manual_args=None):
args = parse_args(manual_args)
configure_logger(args.debug)
args.text = [p.decode('utf-8') if util.PY2 and not isinstance(p, unicode) else p for p in args.text]
if args.version:
version_str = "{0} version {1}".format(jrnl.__title__, jrnl.__version__)
@ -123,8 +134,10 @@ def run(manual_args=None):
sys.exit(0)
if not os.path.exists(CONFIG_PATH):
log.debug('Configuration file not found, installing jrnl...')
config = install.install_jrnl(CONFIG_PATH)
else:
log.debug('Reading configuration from file %s', CONFIG_PATH)
config = util.load_and_fix_json(CONFIG_PATH)
install.upgrade_config(config, config_path=CONFIG_PATH)
@ -132,6 +145,7 @@ def run(manual_args=None):
print(util.py2encode(list_journals(config)))
sys.exit(0)
log.debug('Using configuration "%s"', config)
original_config = config.copy()
# check if the configuration is supported by available modules
if config['encrypt'] and not PYCRYPTO:
@ -151,15 +165,34 @@ def run(manual_args=None):
except:
pass
log.debug('Using journal "%s"', journal_name)
journal_conf = config['journals'].get(journal_name)
if type(journal_conf) is dict: # We can override the default config on a by-journal basis
log.debug('Updating configuration with specific jourlnal overrides %s', journal_conf)
config.update(journal_conf)
else: # But also just give them a string to point to the journal file
config['journal'] = journal_conf
if config['journal'] is None:
util.prompt("You have not specified a journal. Either provide a default journal in your config file, or specify one of your journals on the command line.")
sys.exit(1)
config['journal'] = os.path.expanduser(os.path.expandvars(config['journal']))
touch_journal(config['journal'])
log.debug('Using journal path %(journal)s', config)
mode_compose, mode_export = guess_mode(args, config)
# open journal file or folder
if os.path.isdir(config['journal']):
if config['journal'].strip("/").endswith(".dayone") or \
"entries" in os.listdir(config['journal']):
journal = DayOneJournal.DayOne(**config)
else:
util.prompt("[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
sys.exit(1)
else:
journal = Journal.Journal(journal_name, **config)
# How to quit writing?
if "win32" in sys.platform:
_exit_multiline_code = "on a blank line, press Ctrl+Z and then Enter"
@ -183,22 +216,12 @@ def run(manual_args=None):
else:
mode_compose = False
# open journal file or folder
if os.path.isdir(config['journal']):
if config['journal'].strip("/").endswith(".dayone") or \
"entries" in os.listdir(config['journal']):
journal = DayOneJournal.DayOne(**config)
else:
util.prompt("[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
sys.exit(1)
else:
journal = Journal.Journal(journal_name, **config)
# Writing mode
if mode_compose:
raw = " ".join(args.text).strip()
if util.PY2 and type(raw) is not unicode:
raw = raw.decode(sys.getfilesystemencoding())
log.debug('Appending raw line "%s" to journal "%s"', raw, journal_name)
journal.new_entry(raw)
util.prompt("[Entry added to {0} journal]".format(journal_name))
journal.write()
@ -233,14 +256,14 @@ def run(manual_args=None):
elif args.encrypt is not False:
encrypt(journal, filename=args.encrypt)
# Not encrypting to a separate file: update config!
if not args.encrypt:
if not args.encrypt or args.encrypt == config['journal']:
update_config(original_config, {"encrypt": True}, journal_name, force_local=True)
install.save_config(original_config, config_path=CONFIG_PATH)
elif args.decrypt is not False:
decrypt(journal, filename=args.decrypt)
# Not decrypting to a separate file: update config!
if not args.decrypt:
if not args.decrypt or args.decrypt == config['journal']:
update_config(original_config, {"encrypt": False}, journal_name, force_local=True)
install.save_config(original_config, config_path=CONFIG_PATH)
@ -259,7 +282,7 @@ def run(manual_args=None):
if num_deleted:
prompts.append("{0} {1} deleted".format(num_deleted, "entry" if num_deleted == 1 else "entries"))
if num_edited:
prompts.append("{0} {1} modified".format(num_edited, "entry" if num_deleted == 1 else "entries"))
prompts.append("{0} {1} modified".format(num_edited, "entry" if num_edited == 1 else "entries"))
if prompts:
util.prompt("[{0}]".format(", ".join(prompts).capitalize()))
journal.entries += other_entries

View file

@ -87,7 +87,8 @@ def install_jrnl(config_path='~/.jrnl_config'):
except OSError:
pass
open(default_config['journals']['default'], 'a').close() # Touch to make sure it's there
if not os.path.isdir(path): # if it's a directory and exists (e.g. a DayOne journal, let it be)
open(default_config['journals']['default'], 'a').close() # Touch to make sure it's there
# Write config to ~/.jrnl_conf
with open(config_path, 'w') as f:

View file

@ -48,7 +48,10 @@ def parse(date_str, inclusive=False, default_hour=None, default_minute=None):
return None
if flag is 1: # Date found, but no time. Use the default time.
date = datetime(*date[:3], hour=default_hour or 0, minute=default_minute or 0)
date = datetime(*date[:3],
hour=23 if inclusive else default_hour or 0,
minute=59 if inclusive else default_minute or 0,
second=59 if inclusive else 0)
else:
date = datetime(*date[:6])

View file

@ -13,6 +13,7 @@ import tempfile
import subprocess
import codecs
import unicodedata
import logging
PY3 = sys.version_info[0] == 3
PY2 = sys.version_info[0] == 2
@ -22,6 +23,8 @@ STDOUT = sys.stdout
TEST = False
__cached_tz = None
log = logging.getLogger(__name__)
def getpass(prompt="Password: "):
if not TEST:
@ -71,16 +74,19 @@ def py2encode(s):
def prompt(msg):
"""Prints a message to the std err stream defined in util."""
if not msg:
return
if not msg.endswith("\n"):
msg += "\n"
STDERR.write(u(msg))
def py23_input(msg=""):
STDERR.write(u(msg))
return STDIN.readline().strip()
prompt(msg)
return u(STDIN.readline()).strip()
def py23_read(msg=""):
return STDIN.read()
prompt(msg)
return u(STDIN.read())
def yesno(prompt, default=True):
prompt = prompt.strip() + (" [Y/n]" if default else " [y/N]")
@ -93,27 +99,34 @@ def load_and_fix_json(json_path):
"""
with open(json_path) as f:
json_str = f.read()
config = fixed = None
log.debug('Configuration file %s read correctly', json_path)
config = None
try:
return json.loads(json_str)
except ValueError as e:
log.debug('Could not parse configuration %s: %s', json_str, e,
exc_info=True)
# Attempt to fix extra ,
json_str = re.sub(r",[ \n]*}", "}", json_str)
# Attempt to fix missing ,
json_str = re.sub(r"([^{,]) *\n *(\")", r"\1,\n \2", json_str)
try:
log.debug('Attempting to reload automatically fixed configuration file %s',
json_str)
config = json.loads(json_str)
with open(json_path, 'w') as f:
json.dump(config, f, indent=2)
log.debug('Fixed configuration saved in file %s', json_path)
prompt("[Some errors in your jrnl config have been fixed for you.]")
return config
except ValueError as e:
log.debug('Could not load fixed configuration: %s', e, exc_info=True)
prompt("[There seems to be something wrong with your jrnl config at {0}: {1}]".format(json_path, e.message))
prompt("[Entry was NOT added to your journal]")
sys.exit(1)
def get_text_from_editor(config, template=""):
tmpfile = os.path.join(tempfile.mktemp(prefix="jrnl"))
_, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt")
with codecs.open(tmpfile, 'w', "utf-8") as f:
if template:
f.write(template)

103
setup.py
View file

@ -51,13 +51,8 @@ except ImportError:
readline_available = False
if sys.argv[-1] == 'publish':
os.system("python setup.py sdist upload")
sys.exit()
base_dir = os.path.dirname(os.path.abspath(__file__))
def get_version(filename="jrnl/__init__.py"):
with open(os.path.join(base_dir, filename)) as initfile:
for line in initfile.readlines():
@ -65,6 +60,71 @@ def get_version(filename="jrnl/__init__.py"):
if m:
return m.group(1)
def get_changelog(filename="CHANGELOG.md"):
changelog = {}
current_version = None
with open(os.path.join(base_dir, filename)) as changelog_file:
for line in changelog_file.readlines():
if line.startswith("* __"):
parts = line.strip("* ").split(" ", 1)
if len(parts) == 2:
current_version, changes = parts[0].strip("_\n"), parts[1]
changelog[current_version] = [changes.strip()]
else:
current_version = parts[0].strip("_\n")
changelog[current_version] = []
elif line.strip() and current_version and not line.startswith("#"):
changelog[current_version].append(line.strip(" *\n"))
return changelog
def dist_pypi():
os.system("python setup.py sdist upload")
sys.exit()
def dist_github():
"""Creates a release on the maebert/jrnl repository on github"""
import requests
import keyring
import getpass
version = get_version()
version_tuple = version.split(".")
changes_since_last_version = ["* __{}__: {}".format(key, "\n".join(changes)) for key, changes in get_changelog().items() if key.startswith("{}.{}".format(*version_tuple))]
changes_since_last_version = "\n".join(sorted(changes_since_last_version, reverse=True))
payload = {
"tag_name": version,
"target_commitish": "master",
"name": version,
"body": "Changes in Version {}.{}: \n\n{}".format(version_tuple[0], version_tuple[1], changes_since_last_version)
}
print("Preparing release {}...".format(version))
username = keyring.get_password("github", "__default_user") or raw_input("Github username: ")
password = keyring.get_password("github", username) or getpass.getpass()
otp = raw_input("One Time Token: ")
response = requests.post("https://api.github.com/repos/maebert/jrnl/releases", headers={"X-GitHub-OTP": otp}, json=payload, auth=(username, password))
if response.status_code in (403, 404):
print("Authentication error.")
else:
keyring.set_password("github", "__default_user", username)
keyring.set_password("github", username, password)
if response.status_code > 299:
if "message" in response.json():
print("Error: {}".format(response.json()['message']))
for error_dict in response.json().get('errors', []):
print("*", error_dict)
else:
print("Unkown error")
print(response.text)
else:
print("Release created.")
sys.exit()
if sys.argv[-1] == 'publish':
dist_pypi()
if sys.argv[-1] == 'github_release':
dist_github()
conditional_dependencies = {
"pyreadline>=2.0": not readline_available and "win32" in sys.platform,
"readline>=6.2": not readline_available and "win32" not in sys.platform,
@ -86,30 +146,31 @@ setup(
"six>=1.6.1",
"tzlocal>=1.1",
"keyring>=3.3",
"keyrings.alt>=1.3",
] + [p for p, cond in conditional_dependencies.items() if cond],
extras_require = {
"encrypted": "pycrypto>=2.6"
},
long_description=__doc__,
entry_points={
'console_scripts': [
'jrnl = jrnl:run',
],
"console_scripts": [
"jrnl = jrnl:run",
]
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Office/Business :: News/Diary',
'Topic :: Text Processing'
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Office/Business :: News/Diary",
"Topic :: Text Processing"
],
# metadata for upload to PyPI
author = "Manuel Ebert",