add support for listprojects

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-11-27 13:05:18 +01:00
parent 92c51d9dc0
commit 9b943ebd3d
3 changed files with 54 additions and 2 deletions

View File

@ -48,6 +48,10 @@ def parse_argv(argv, version):
parser['sub'] = parser['main'].add_subparsers(title="Commands")
parser['listprojects'] = parser['sub'].add_parser('listprojects',
parents=[parser['loglevel']])
parser['listprojects'].set_defaults(func=ListProjects.commandline)
parser['track'] = parser['sub'].add_parser('track',
parents=[parser['loglevel']])
parser['track'].set_defaults(func=Tracker.commandline)
@ -98,6 +102,8 @@ if __name__ == "__main__":
import ctt
from ctt.tracker import Tracker
from ctt.report import Report
from ctt.listprojects import ListProjects
parse_argv(sys.argv[1:], ctt.VERSION)
sys.exit(0)

View File

@ -23,7 +23,7 @@
import os
import os.path
VERSION = "0.5"
VERSION = "0.6"
FILE_DELTA = "delta"
FILE_COMMENT = "comment"
DATEFORMAT = "%Y-%m-%d"
@ -56,9 +56,17 @@ def user_timedelta(seconds):
return (hours, minutes, seconds)
def project_dir(project):
def ctt_dir():
home = os.environ['HOME']
ctt_dir = os.path.join(home, ".ctt")
return ctt_dir
def project_dir(project):
ctt_dir = ctt_dir()
project_dir = os.path.join(ctt_dir, project)
return project_dir
def list_projects(ctt_dir):
return os.listdir(ctt_dir)

38
lib/ctt/listprojects.py Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 2012 Nico Schottelius (nico-ctt at schottelius.org)
#
# This file is part of ctt.
#
# ctt 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.
#
# ctt 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 ctt. If not, see <http://www.gnu.org/licenses/>.
#
#
import ctt
import logging
log = logging.getLogger(__name__)
class ListProjects(object):
"""Return existing projects"""
@classmethod
def commandline(cls, args):
cls.print_projects()
def print_projects():
for project in ctt.list_projects(ctt.ctt_dir()):
print(project)