Skip to content

Commit

Permalink
Merge pull request #194 from StephaneMangin/python2_removal_continued
Browse files Browse the repository at this point in the history
Python 2 removal continued
  • Loading branch information
mgedmin committed Oct 9, 2020
2 parents 8c6d2aa + 32d9f29 commit 19ca732
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 33 deletions.
1 change: 0 additions & 1 deletion benchmark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python3
from __future__ import print_function

import gc
import os
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import ast
import io
import os
import re
import sys
Expand All @@ -12,7 +11,7 @@


def read(filename):
with io.open(os.path.join(here, filename), 'r', encoding='utf-8') as f:
with open(os.path.join(here, filename), encoding='utf-8') as f:
return f.read()


Expand Down
3 changes: 1 addition & 2 deletions src/gtimelog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def mark_time(what=None):
import email.mime.text
import functools
import gettext
import io
import locale
import logging
import os
Expand Down Expand Up @@ -344,7 +343,7 @@ def on_shortcuts(self, action, parameter):

def get_contributors(self):
contributors = []
with io.open(CONTRIBUTORS_FILE, encoding='UTF-8') as f:
with open(CONTRIBUTORS_FILE, encoding='utf-8') as f:
for line in f:
if line.startswith('- '):
contributors.append(line[2:].strip())
Expand Down
2 changes: 0 additions & 2 deletions src/gtimelog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Settings for GTimeLog
"""

from __future__ import absolute_import

import datetime
import locale
import os
Expand Down
7 changes: 3 additions & 4 deletions src/gtimelog/tests/test_timelog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tests for gtimelog.timelog"""

import codecs
import datetime
import doctest
import os
Expand Down Expand Up @@ -1004,7 +1003,7 @@ def tempfile(self, filename='timelog.txt'):

def write_file(self, filename, content):
filename = os.path.join(self.mkdtemp(), filename)
with codecs.open(filename, 'w', encoding='UTF-8') as f:
with open(filename, 'w', encoding='utf-8') as f:
f.write(content)
return filename

Expand Down Expand Up @@ -1049,10 +1048,10 @@ def test_parsing(self):
])

def test_unicode(self):
taskfile = self.write_file('tasks.txt', u'\N{SNOWMAN}')
taskfile = self.write_file('tasks.txt', '\N{SNOWMAN}')
tasklist = TaskList(taskfile)
self.assertEqual(tasklist.groups, [
('Other', [u'\N{SNOWMAN}']),
('Other', ['\N{SNOWMAN}']),
])

def test_reloading(self):
Expand Down
40 changes: 18 additions & 22 deletions src/gtimelog/timelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Non-GUI bits of gtimelog.
"""

from __future__ import unicode_literals

import codecs
import collections
import csv
import datetime
Expand Down Expand Up @@ -550,11 +547,11 @@ def _categorizing_report(self, output, email, who, subject, period_name):
continue # skip empty "arrival" entries

entry = entry[:1].upper() + entry[1:]
output.write(u" %-61s %+5s\n" %
output.write(" %-61s %+5s\n" %
(entry, format_duration_short(duration)))

output.write('-' * 70 + '\n')
output.write(u"%+70s\n" % format_duration_short(totals[cat]))
output.write("%+70s\n" % format_duration_short(totals[cat]))
output.write('\n')
output.write("Total work done this %s: %s\n" %
(period_name, format_duration_short(total_work)))
Expand Down Expand Up @@ -629,7 +626,7 @@ def _report_categories(self, output, categories):
if no_cat is not None:
items.append(('(none)', no_cat))
for cat, duration in items:
output.write(u"%-62s %s\n" % (
output.write("%-62s %s\n" % (
cat, format_duration_long(duration)))
output.write('\n')

Expand Down Expand Up @@ -666,7 +663,7 @@ def _plain_report(self, output, email, who, subject, period_name):
cat, datetime.timedelta(0)) + duration

entry = entry[:1].upper() + entry[1:]
output.write(u"%-62s %s\n" %
output.write("%-62s %s\n" %
(entry, format_duration_long(duration)))
output.write('\n')
output.write("Total work done this %s: %s\n" %
Expand All @@ -681,7 +678,7 @@ def _plain_report(self, output, email, who, subject, period_name):

def weekly_report_subject(self, who):
week = self.window.min_timestamp.isocalendar()[1]
return u'Weekly report for %s (week %02d)' % (who, week)
return 'Weekly report for %s (week %02d)' % (who, week)

def weekly_report(self, output, email, who):
if self.style == 'categorized':
Expand All @@ -703,7 +700,7 @@ def weekly_report_categorized(self, output, email, who):

def monthly_report_subject(self, who):
month = self.window.min_timestamp.strftime('%Y/%m')
return u'Monthly report for %s (%s)' % (who, month)
return 'Monthly report for %s (%s)' % (who, month)

def monthly_report(self, output, email, who):
if self.style == 'categorized':
Expand All @@ -727,7 +724,7 @@ def custom_range_report_subject(self, who):
min = self.window.min_timestamp.strftime('%Y-%m-%d')
max = self.window.max_timestamp - datetime.timedelta(1)
max = max.strftime('%Y-%m-%d')
return u'Custom date range report for %s (%s - %s)' % (who, min, max)
return 'Custom date range report for %s (%s - %s)' % (who, min, max)

def custom_range_report_categorized(self, output, email, who):
"""Format a custom range report with entries displayed under categories."""
Expand All @@ -741,8 +738,8 @@ def daily_report_subject(self, who):
weekday_names = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
weekday = weekday_names[self.window.min_timestamp.weekday()]
week = self.window.min_timestamp.isocalendar()[1]
return (u"{0:%Y-%m-%d} report for {who}"
u" ({weekday}, week {week:0>2})".format(
return ("{0:%Y-%m-%d} report for {who}"
" ({weekday}, week {week:0>2})".format(
self.window.min_timestamp, who=who,
weekday=weekday, week=week))

Expand All @@ -753,8 +750,8 @@ def daily_report(self, output, email, who):
"""
window = self.window
if self.email_headers:
output.write(u"To: %s\n" % email)
output.write(u"Subject: %s\n" % self.daily_report_subject(who))
output.write("To: %s\n" % email)
output.write("Subject: %s\n" % self.daily_report_subject(who))
output.write('\n')
items = list(window.all_entries())
if not items:
Expand All @@ -770,7 +767,7 @@ def daily_report(self, output, email, who):
if work:
for start, entry, duration in work:
entry = entry[:1].upper() + entry[1:]
output.write(u"%-62s %s\n" % (entry,
output.write("%-62s %s\n" % (entry,
format_duration_long(duration)))
cat, task = TimeCollection.split_category(entry)
categories[cat] = categories.get(
Expand All @@ -787,7 +784,7 @@ def daily_report(self, output, email, who):
if slack:
for start, entry, duration in slack:
entry = entry[:1].upper() + entry[1:]
output.write(u"%-62s %s\n" % (entry,
output.write("%-62s %s\n" % (entry,
format_duration_long(duration)))
output.write('\n')
output.write("Time spent slacking: %s\n" %
Expand Down Expand Up @@ -992,11 +989,10 @@ def window_for_date_range(self, min, max):

def raw_append(self, line, need_space):
"""Append a line to the time log file."""
f = codecs.open(self.filename, "a", encoding='UTF-8')
if need_space:
f.write('\n')
f.write(line + '\n')
f.close()
with open(self.filename, "a", encoding='utf-8') as f:
if need_space:
f.write('\n')
f.write(line + '\n')
self.last_mtime = get_mtime(self.filename)

def append(self, entry, now=None):
Expand Down Expand Up @@ -1106,7 +1102,7 @@ def load(self):
groups = {}
self.last_mtime = get_mtime(self.filename)
try:
with codecs.open(self.filename, encoding='UTF-8') as f:
with open(self.filename, encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'):
Expand Down

0 comments on commit 19ca732

Please sign in to comment.