Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
dcb5891d
Commit
dcb5891d
authored
Oct 19, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sort subcommand to sort a todo.txt file.
parent
b3817f3e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
0 deletions
+113
-0
README.md
README.md
+3
-0
cli/Main.py
cli/Main.py
+2
-0
lib/SortCommand.py
lib/SortCommand.py
+64
-0
test/SortCommandTest.py
test/SortCommandTest.py
+44
-0
No files found.
README.md
View file @
dcb5891d
...
...
@@ -33,10 +33,13 @@ Subcommands implemented:
*
lscon
*
lsprj
*
pri
*
sort [xx]
Subcommands marked as [x] don't exist in the todo.txt CLI, but were added by
todo.txt-tools.
Subcommands marked as [xx] are new in Topydo.
Motivation
----------
...
...
cli/Main.py
View file @
dcb5891d
...
...
@@ -34,6 +34,7 @@ from ListContextCommand import ListContextCommand
from
ListProjectCommand
import
ListProjectCommand
from
PrettyPrinter
import
*
from
PriorityCommand
import
PriorityCommand
from
SortCommand
import
SortCommand
import
TodoFile
import
TodoList
from
Utils
import
escape_ansi
...
...
@@ -119,6 +120,7 @@ class CLIApplication(object):
'listprojects'
:
ListProjectCommand
,
'pri'
:
PriorityCommand
,
'rm'
:
DeleteCommand
,
'sort'
:
SortCommand
,
}
args
=
arguments
()
...
...
lib/SortCommand.py
0 → 100644
View file @
dcb5891d
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
Command
import
*
import
Config
import
Filter
import
Sorter
class
SortCommand
(
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
SortCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
def
execute
(
self
):
if
not
super
(
SortCommand
,
self
).
execute
():
return
False
try
:
expression
=
self
.
argument
(
0
)
except
InvalidCommandArgument
:
expression
=
Config
.
SORT_STRING
sorter
=
Sorter
.
Sorter
(
expression
)
# TODO: validate
sorted_todos
=
sorter
.
sort
(
self
.
todolist
.
todos
())
self
.
todolist
.
erase
()
for
todo
in
sorted_todos
:
self
.
todolist
.
add_todo
(
todo
)
def
usage
(
self
):
return
"""Synopsis: sort [expression]"""
def
help
(
self
):
return
"""Sorts the file according to the expression. If no expression is given,
the expression in the configuration is used.
The following sort properties are supported:
* creation - Sort by creation date
* completed - Sort by completion state
* importance - Sort by importance
* importance-avg - Sort by average importance (based on parent items)
* text - Sort by text
* <tag> - Sort by values of the given tag
Any property can be prefixed with 'asc:' and 'desc:' to specify the sort order.
The default is ascending sort.
"""
test/SortCommandTest.py
0 → 100644
View file @
dcb5891d
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
CommandTest
import
Config
import
SortCommand
import
TestFacilities
class
SortCommandTest
(
CommandTest
.
CommandTest
):
def
setUp
(
self
):
self
.
todolist
=
TestFacilities
.
load_file_to_todolist
(
"data/SorterTest1.txt"
)
def
test_sort1
(
self
):
""" Alphabetically sorted """
command
=
SortCommand
.
SortCommand
([
"text"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertEquals
(
str
(
self
.
todolist
),
"First
\
n
(A) Foo
\
n
2014-06-14 Last"
)
def
test_sort2
(
self
):
command
=
SortCommand
.
SortCommand
([],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertEquals
(
str
(
self
.
todolist
),
"(A) Foo
\
n
2014-06-14 Last
\
n
First"
)
def
test_help
(
self
):
command
=
SortCommand
.
SortCommand
([
"help"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertEquals
(
self
.
output
,
""
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
\
n
"
+
command
.
help
()
+
"
\
n
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment