Skip to content

Commit

Permalink
Merge pull request #33 from liminspace/develop
Browse files Browse the repository at this point in the history
Release 0.0.15
  • Loading branch information
liminspace authored Jan 15, 2019
2 parents 097ba61 + d870fe4 commit fa83c88
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.0.15 (2019-01-16)
===================
* Added metadata with import date

0.0.14 (2018-08-07)
=============
===================
* Added supporting Django 2.1
8 changes: 3 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
pip==18.0
setuptools==40.0.0
wheel==0.31.1
twine==1.11.0
wheel==0.32.3
twine==1.12.1

django<2.2
django-rosetta>=0.7.14
requests>=2.15.1
polib>=1.1.0
coverage==4.5.1
coverage==4.5.2
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
zip_safe=False, # because include static
install_requires=[
'django>=1.8,<2.2',
'django-rosetta>=0.7.14',
'requests>=2.15.1',
'polib>=1.1.0',
],
Expand Down
2 changes: 1 addition & 1 deletion transtool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.0.14'
__version__ = '0.0.15'

default_app_config = 'transtool.apps.TrantoolConfig'
17 changes: 14 additions & 3 deletions transtool/management/commands/transtool_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import zipfile
import requests
from io import BytesIO
from polib import pofile
from django.core.management import CommandError, BaseCommand
from ...tools import get_lc_files_list, get_diff_po
from ...tools import get_lc_files_list, get_diff_po, timestamp_with_timezone
from ...settings import TRANSTOOL_DL_URL, TRANSTOOL_DL_KEY, TRANSTOOL_PROJECT_BASE_DIR


Expand Down Expand Up @@ -91,16 +92,24 @@ def print_diff_info(self, diff_info):
else:
self.stdout.write(' :empty:')

@classmethod
def update_import_datetime(cls, fn):
po = pofile(fn)
po.metadata['X-Transtool-Imported'] = timestamp_with_timezone()
po.save()

def copy_files(self, diff_info, imp_zip_file):
z = zipfile.ZipFile(imp_zip_file)
try:
if diff_info['new']:
self.stdout.write('Copy new files:')
for fn in sorted(diff_info['new']):
content = z.read(fn)
po_path = os.path.join(TRANSTOOL_PROJECT_BASE_DIR, fn)
try:
with open(os.path.join(TRANSTOOL_PROJECT_BASE_DIR, fn), 'wb') as f:
with open(po_path, 'wb') as f:
f.write(content)
self.update_import_datetime(po_path)
except IOError as e:
self.stdout.write(e.message)
self.stdout.write(' SKIP: {}'.format(fn))
Expand All @@ -116,9 +125,11 @@ def copy_files(self, diff_info, imp_zip_file):
else:
fn_info = fn
content = z.read(fn)
po_path = os.path.join(TRANSTOOL_PROJECT_BASE_DIR, fn)
try:
with open(os.path.join(TRANSTOOL_PROJECT_BASE_DIR, fn), 'wb') as f:
with open(po_path, 'wb') as f:
f.write(content)
self.update_import_datetime(po_path)
except IOError as e:
self.stdout.write(e.message)
self.stdout.write(' SKIP: {}'.format(fn_info))
Expand Down
18 changes: 18 additions & 0 deletions transtool/tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from datetime import datetime
import difflib
import os
import re
import polib
from django.utils import timezone


lc_dir_re = re.compile(r'^.*?locale/[\w\-]{2,5}/LC_MESSAGES$')
Expand Down Expand Up @@ -62,3 +64,19 @@ def get_commonpath(paths):
break
prefix = os.sep if isabs else ''
return prefix + os.sep.join(common)


def timestamp_with_timezone(dt=None):
"""
Return a timestamp with a timezone for the configured locale. If all else
fails, consider localtime to be UTC.
"""
dt = dt or datetime.now()
if timezone is None:
return dt.strftime('%Y-%m-%d %H:%M%z')
if not dt.tzinfo:
tz = timezone.get_current_timezone()
if not tz:
tz = timezone.utc
dt = dt.replace(tzinfo=tz)
return dt.strftime("%Y-%m-%d %H:%M%z")

0 comments on commit fa83c88

Please sign in to comment.