From 5ff185b2dfe8e44b93c53f132a583ebf39de3645 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Tue, 28 Jan 2014 14:37:15 -0700 Subject: [PATCH 1/8] documentation typo fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c68473..11f760b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Changelog * __1.7.8__ Upgrade to parsedatetime 1.2 * __1.7.7__ Cleaned up imports, better unicode support * __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.2__ Dateutil added to requirements. * __1.7.1__ Fixes issues with parsing time information in entries. From f1e5c88b2387c03d84b212f2d67440463c229b68 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Tue, 28 Jan 2014 15:02:49 -0700 Subject: [PATCH 2/8] allow newer versions of tzlocal --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1981d62c..a2a94491 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,6 @@ parsedatetime >= 1.2 pytz >= 2013b pycrypto >= 2.6 argparse==1.2.1 -tzlocal == 1.0 +tzlocal >= 1.0 keyring==3.0.5 python-dateutil==2.2 From 6f302ad66459ef23539f12169c758918421c1e22 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Tue, 28 Jan 2014 15:20:13 -0700 Subject: [PATCH 3/8] Just use setup.py (don't keep a second copy in `requirements.txt`) --- .gitignore | 4 ++++ requirements.txt | 7 ------- setup.py | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) delete mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index b23a2adc..031d0a65 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,7 @@ obj *.pyproj *.sln *.suo + +# virtaulenv +env/ +env*/ diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a2a94491..00000000 --- a/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -parsedatetime >= 1.2 -pytz >= 2013b -pycrypto >= 2.6 -argparse==1.2.1 -tzlocal >= 1.0 -keyring==3.0.5 -python-dateutil==2.2 diff --git a/setup.py b/setup.py index 27209fdb..6c20310f 100644 --- a/setup.py +++ b/setup.py @@ -72,7 +72,7 @@ setup( install_requires = [ "parsedatetime>=1.2", "pytz>=2013b", - "tzlocal==1.0", + "tzlocal>=1.0", "keyring>=3.3", "python-dateutil>=2.2" ] + [p for p, cond in conditional_dependencies.items() if cond], From 3a4607f6714c2207297a00ad7b28c485b6127151 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Tue, 28 Jan 2014 16:08:22 -0700 Subject: [PATCH 4/8] Use Travis-CI without requirements.txt --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 15cf9c92..5b5972f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ python: - "2.7" - "3.3" install: - - "pip install -q -r requirements.txt --use-mirrors" + - "pip install -e . --use-mirrors" - "pip install -q behave" # command to run tests script: From a26fd3d1d7f96cfe02d951bb1fa1b51c765444e6 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Tue, 28 Jan 2014 16:17:13 -0700 Subject: [PATCH 5/8] [Travis-CI] manually install PyCrypto --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5b5972f0..12928624 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ python: - "3.3" install: - "pip install -e . --use-mirrors" + - "pip install pycrypto>=2.6 --use-mirrors" - "pip install -q behave" # command to run tests script: From a20381ce6803f1104320ac1cacbae5c862add049 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Wed, 29 Jan 2014 09:15:46 -0700 Subject: [PATCH 6/8] require tzlocal version 1.1 or better jrnl needs the OSX fixes in version 1.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6c20310f..d3d11c3c 100644 --- a/setup.py +++ b/setup.py @@ -72,7 +72,7 @@ setup( install_requires = [ "parsedatetime>=1.2", "pytz>=2013b", - "tzlocal>=1.0", + "tzlocal>=1.1", "keyring>=3.3", "python-dateutil>=2.2" ] + [p for p, cond in conditional_dependencies.items() if cond], From 9e5664ba46698903ea96c126469d0d1dc3dd27f1 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Wed, 29 Jan 2014 09:43:29 -0700 Subject: [PATCH 7/8] Fix typos in test files --- features/dayone.feature | 2 +- features/exporting.feature | 2 +- features/fix_json.feature | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/dayone.feature b/features/dayone.feature index c8e987e1..890af8ac 100644 --- a/features/dayone.feature +++ b/features/dayone.feature @@ -13,7 +13,7 @@ Feature: DayOne Ingetration 2013-07-17 11:38 This entry is starred! """ - Scenario: Entries without timezone information will be intepreted in the current timezone + Scenario: Entries without timezone information will be interpreted as in the current timezone Given we use the config "dayone.json" When we run "jrnl -until 'feb 2013'" Then we should get no error diff --git a/features/exporting.feature b/features/exporting.feature index 5b3e940f..405b5496 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -1,4 +1,4 @@ -Feature: Expoting a Journal +Feature: Exporting a Journal Scenario: Exporting to json Given we use the config "tags.json" diff --git a/features/fix_json.feature b/features/fix_json.feature index 84f91955..a653e25c 100644 --- a/features/fix_json.feature +++ b/features/fix_json.feature @@ -1,6 +1,6 @@ Feature: Fixing broken config files - Scenario: Loading a file with journal + Scenario: Loading a file with journal Given we use the config "broken.json" When we run "jrnl -n 2" Then we should see the message "Some errors in your jrnl config have been fixed for you." From ca7a804b09a538fcf845936080a627337bbb2dd5 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Wed, 29 Jan 2014 09:57:15 -0700 Subject: [PATCH 8/8] Convert from local `util.get_local_timezone()` to `tzlocal.get_localzone()` one side effect is that a `pytz` object is returned rather than a string, and so conversion to a string must be done explicitly at run time where needed. --- features/steps/core.py | 3 ++- jrnl/Journal.py | 5 +++-- jrnl/util.py | 18 ------------------ 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/features/steps/core.py b/features/steps/core.py index 6f2baa5b..cdde7613 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -11,6 +11,7 @@ try: from io import StringIO except ImportError: from cStringIO import StringIO +import tzlocal def _parse_args(command): nargs=[] @@ -120,7 +121,7 @@ def check_output(context): @then('the output should contain "{text}" in the local time') def check_output_time_inline(context, text): out = context.stdout_capture.getvalue() - local_tz = pytz.timezone(util.get_local_timezone()) + 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") diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 32fb8b20..b5d7a664 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -23,6 +23,7 @@ import hashlib import plistlib import pytz import uuid +import tzlocal class Journal(object): def __init__(self, name='default', **kwargs): @@ -333,7 +334,7 @@ class DayOne(Journal): try: timezone = pytz.timezone(dict_entry['Time Zone']) except (KeyError, pytz.exceptions.UnknownTimeZoneError): - timezone = pytz.timezone(util.get_local_timezone()) + timezone = tzlocal.get_localzone() date = dict_entry['Creation Date'] date = date + timezone.utcoffset(date) raw = dict_entry['Entry Text'] @@ -357,7 +358,7 @@ class DayOne(Journal): 'Creation Date': utc_time, 'Starred': entry.starred if hasattr(entry, 'starred') else False, 'Entry Text': entry.title+"\n"+entry.body, - 'Time Zone': util.get_local_timezone(), + 'Time Zone': str(tzlocal.get_localzone()), 'UUID': entry.uuid, 'Tags': [tag.strip(self.config['tagsymbols']) for tag in entry.tags] } diff --git a/jrnl/util.py b/jrnl/util.py index 708150f0..4b252cbd 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -88,24 +88,6 @@ def yesno(prompt, default=True): raw = py23_input(prompt) return {'y': True, 'n': False}.get(raw.lower(), default) -def get_local_timezone(): - """Returns the Olson identifier of the local timezone. - In a happy world, tzlocal.get_localzone would do this, but there's a bug on OS X - that prevents that right now: https://github.com/regebro/tzlocal/issues/6""" - global __cached_tz - if not __cached_tz and "darwin" in sys.platform: - __cached_tz = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip() - if not __cached_tz or __cached_tz not in pytz.all_timezones_set: - link = os.readlink("/etc/localtime") - # This is something like /usr/share/zoneinfo/America/Los_Angeles. - # Find second / from right and take the substring - __cached_tz = link[link.rfind('/', 0, link.rfind('/'))+1:] - elif not __cached_tz: - __cached_tz = str(get_localzone()) - if not __cached_tz or __cached_tz not in pytz.all_timezones_set: - __cached_tz = "UTC" - return __cached_tz - def load_and_fix_json(json_path): """Tries to load a json object from a file. If that fails, tries to fix common errors (no or extra , at end of the line).