Skip to content

Commit

Permalink
Fix decode issues with subprocess results for python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kostajh committed Jun 24, 2013
1 parent 1a10e30 commit f2b886c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions taskw/warrior.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import subprocess
import json
import pprint
import locale

import taskw.utils

Expand Down Expand Up @@ -366,24 +365,22 @@ def can_use(cls):
['task', '--version'],
stdout=subprocess.PIPE
).communicate()[0]
encoding = locale.getdefaultlocale()[1]
taskwarrior_major_version = int(taskwarrior_version.decode(encoding).split('.')[0])
taskwarrior_major_version = int(taskwarrior_version.decode().split('.')[0])
return taskwarrior_major_version >= 2

def load_tasks(self, **kw):
# Load tasks using `task export`
pending_tasks = list()
completed_tasks = list()
tasks = dict()
encoding = locale.getdefaultlocale()[1]
pending_tasks = json.loads(subprocess.Popen([
'task', 'rc:%s' % self.config_filename,
'rc.json.array=TRUE', 'rc.verbose=nothing', 'status:pending',
'export'], stdout=subprocess.PIPE).communicate()[0].decode(encoding))
'export'], stdout=subprocess.PIPE).communicate()[0].decode())
completed_tasks = json.loads(subprocess.Popen([
'task', 'rc:%s' % self.config_filename,
'rc.json.array=TRUE', 'rc.verbose=nothing', 'status:completed',
'export'], stdout=subprocess.PIPE).communicate()[0].decode(encoding))
'export'], stdout=subprocess.PIPE).communicate()[0].decode())
tasks['pending'] = pending_tasks
tasks['completed'] = completed_tasks
return tasks
Expand Down Expand Up @@ -416,11 +413,10 @@ def _load_task(self, **kw):
search = kw[key][4:]
else:
search = six.text_type(kw[key])
encoding = locale.getdefaultlocale()[1]
task = subprocess.Popen([
'task', 'rc:%s' % self.config_filename,
'rc.verbose=nothing', search,
'export'], stdout=subprocess.PIPE).communicate()[0].decode(encoding)
'export'], stdout=subprocess.PIPE).communicate()[0].decode()
if task:
try:
task_data = json.loads(task)
Expand Down

0 comments on commit f2b886c

Please sign in to comment.