diff --git a/bin/ctt b/bin/ctt index d39f446..976ca3c 100755 --- a/bin/ctt +++ b/bin/ctt @@ -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) diff --git a/lib/ctt/__init__.py b/lib/ctt/__init__.py index cb2fab4..9a4c103 100644 --- a/lib/ctt/__init__.py +++ b/lib/ctt/__init__.py @@ -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) diff --git a/lib/ctt/listprojects.py b/lib/ctt/listprojects.py new file mode 100755 index 0000000..731b4b0 --- /dev/null +++ b/lib/ctt/listprojects.py @@ -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 . +# +# + +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)