Skip to content

Commit

Permalink
Locale aware console output.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Mar 4, 2009
1 parent d51fef2 commit 499e672
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
34 changes: 20 additions & 14 deletions gtd
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

import sys
import os
import locale
import gtdzen
from pdb import set_trace

_language, _encoding = locale.getdefaultlocale()

def output(text):
print text.encode(_encoding)

def _comma_split(string):
return [s for s in (s.strip() for s in string.split(',')) if s]

Expand Down Expand Up @@ -67,39 +73,39 @@ class CommandUI:
priority=int(priority),
tags = _parse_tags(tags),
)
print u'Task %s was added with id %d' % (task, task.id)
output(u'Task %s was added with id %d' % (task, task.id))

def cmd_tags(self):
"Show all tags with number of open/closed tasks."

tags = self.gtd.getTags()
if len(tags) > 0:
for tag in tags:
print u'%d\t%s (%d/%d)' % (
output(u'%d\t%s (%d/%d)' % (
tag.id, tag,
len(tag.open_tasks),
len(tag.closed_tasks))
len(tag.closed_tasks)))
else:
print u'No tags'
output(u'No tags')

def cmd_active_tags(self):
"Show only tags with open tasks."

tags = [t for t in self.gtd.getTags() if len(t.open_tasks) > 0]
if len(tags) > 0:
for tag in tags:
print u'%d\t%s (%d)' % (
output(u'%d\t%s (%d)' % (
tag.id, tag,
len(tag.open_tasks))
len(tag.open_tasks)))
else:
print u'No tags'
output(u'No tags')

def cmd_del_tag(self, tag_ids):
"Delete tag by id (comma-separated list can be passed to remove many tags)."

for tag_id in _parse_ids(tag_ids):
self.gtd.deleteTag(tag_id)
print u'These tags were deleted'
output(u'These tags were deleted')

def cmd_show(self, tags = u'', mode = 'open'):
"Show tasks, filtered by tags."
Expand All @@ -111,9 +117,9 @@ class CommandUI:
show = mode)
if len(tasks) > 0:
for task in tasks:
print u'%d %s' % (task.id, task)
output(u'%d %s' % (task.id, task))
else:
print u'No tasks'
output(u'No tasks')

def cmd_show_closed(self, *args, **kwargs):
"Show closed tasks with given tags."
Expand Down Expand Up @@ -144,28 +150,28 @@ class CommandUI:
task.setTags(new_tags)

self.gtd.save(task)
print u'Task %s was updated' % task
output(u'Task %s was updated' % task)

def cmd_close(self, task_ids):
"Close task or tasks."

for task_id in _parse_ids(task_ids):
self.gtd.closeTask(task_id)
print u'Task %s was closed' % task_id
output(u'Task %s was closed' % task_id)

def cmd_del_task(self, task_ids):
"Close task or tasks."

for task_id in _parse_ids(task_ids):
task = self.gtd.getTaskById(task_id)
if task is None:
print 'Task %d not found.' % task_id
output('Task %d not found.' % task_id)
continue

yes_no = raw_input((u'Do you really want to delete task "%s"?\nAnswer "yes" or "no": ' % task.title).encode('utf-8'))
if yes_no == 'yes':
self.gtd.deleteTask(task_id)
print u'Task %s was deleted' % task_id
output(u'Task %s was deleted' % task_id)

def cmd_test(self):
"Doctests the program. Outputs nothing if all tests pass"
Expand Down
4 changes: 2 additions & 2 deletions gtdzen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Task(Entity):

using_options(tablename='tasks', order_by='-priority')

def __str__(self):
def __unicode__(self):
return u'"%s" / %s (%s)' % (self.title, self.priority, ', '.join(map(unicode, self.tags)))

def __repr__(self):
Expand All @@ -30,7 +30,7 @@ class Tag(Entity):

using_options(tablename='tags', order_by='title')

def __str__(self):
def __unicode__(self):
return self.title

def __repr__(self):
Expand Down

0 comments on commit 499e672

Please sign in to comment.