use wrapper in bin/ so script/ctt can run in sane PYTHONPATH
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
parent
5a9983f7dd
commit
d49e95baac
3 changed files with 132 additions and 97 deletions
104
bin/ctt
104
bin/ctt
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2012-2013 Nico Schottelius (nico-ctt at schottelius.org)
|
||||
# 2013 Nico Schottelius (nico-ctt at schottelius.org)
|
||||
#
|
||||
# This file is part of ctt.
|
||||
#
|
||||
|
@ -20,101 +20,19 @@
|
|||
#
|
||||
#
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os.path
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Setup locale for calendar printing
|
||||
# Setup locale to get Timezone information?
|
||||
#print(locale.getlocale())
|
||||
|
||||
# Record tags
|
||||
|
||||
def parse_argv(argv, version):
|
||||
parser = {}
|
||||
parser['loglevel'] = argparse.ArgumentParser(add_help=False)
|
||||
parser['loglevel'].add_argument('-d', '--debug',
|
||||
help='set log level to debug', action='store_true',
|
||||
default=False)
|
||||
parser['loglevel'].add_argument('-v', '--verbose',
|
||||
help='set log level to info, be more verbose',
|
||||
action='store_true', default=False)
|
||||
|
||||
parser['main'] = argparse.ArgumentParser(description='ctt ' + version,
|
||||
parents=[parser['loglevel']])
|
||||
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)
|
||||
parser['track'].add_argument("--sd", "--start", help="start date (default: first of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, dest="start")
|
||||
parser['track'].add_argument("--ed", "--end", help="end date (default: last of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, default=None, dest="end")
|
||||
parser['track'].add_argument("-n", "--no-comment", help="disable comment prompting after tracking",
|
||||
action='store_false', dest="comment")
|
||||
parser['track'].add_argument("project", help="project to track time for", nargs=1)
|
||||
|
||||
parser['report'] = parser['sub'].add_parser('report',
|
||||
parents=[parser['loglevel']])
|
||||
parser['report'].set_defaults(func=Report.commandline)
|
||||
parser['report'].add_argument("project", help="project to report time for", nargs='*')
|
||||
parser['report'].add_argument("--sd", "--start", help="start date (default: first of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, dest="start")
|
||||
parser['report'].add_argument("--ed", "--end", help="end date (default: last of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, default=None, dest="end")
|
||||
|
||||
parser['report'].add_argument("-a", "--all", help="List entries for all projects", action='store_true')
|
||||
parser['report'].add_argument("-e", "--regexp", help="regular expression to match",
|
||||
default=None)
|
||||
parser['report'].add_argument("-i", "--ignore-case", help="ignore case distinctions", action="store_true")
|
||||
parser['report'].add_argument("-f", "--format", help="output format (default: %s)" % ctt.REPORTFORMAT,
|
||||
default=ctt.REPORTFORMAT, dest="output_format")
|
||||
|
||||
#parser['track'].add_argument("-t", "--tag", help="Add tags",
|
||||
# action="store_true")
|
||||
|
||||
args = parser['main'].parse_args()
|
||||
|
||||
if args.verbose:
|
||||
logging.root.setLevel(logging.INFO)
|
||||
if args.debug:
|
||||
logging.root.setLevel(logging.DEBUG)
|
||||
|
||||
log.debug(args)
|
||||
|
||||
try:
|
||||
args.func(args)
|
||||
|
||||
except ctt.Error as e:
|
||||
log.error(e)
|
||||
sys.exit(1)
|
||||
except AttributeError as e:
|
||||
print(e)
|
||||
parser['main'].print_help()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Ensure our /lib/ is included into PYTHON_PATH
|
||||
sys.path.insert(0, os.path.abspath(
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), '../lib')))
|
||||
here = os.path.dirname(os.path.realpath(__file__))
|
||||
lib = os.path.abspath(os.path.join(here, '../lib'))
|
||||
ctt_argv = [os.path.abspath(os.path.join(here, '../scripts/ctt'))]
|
||||
|
||||
#logging.basicConfig(format='%(levelname)s: %(message)s')
|
||||
logging.basicConfig(format='%(message)s')
|
||||
orig_pythonpath = os.getenv('PYTHONPATH', "")
|
||||
pythonpath = "%s:%s" % (lib, orig_pythonpath)
|
||||
os.environ['PYTHONPATH'] = pythonpath
|
||||
|
||||
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)
|
||||
ctt_argv.extend(sys.argv[1:])
|
||||
subprocess.call(ctt_argv)
|
||||
|
|
120
scripts/ctt
Executable file
120
scripts/ctt
Executable file
|
@ -0,0 +1,120 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2012-2013 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 argparse
|
||||
import logging
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Setup locale for calendar printing
|
||||
# Setup locale to get Timezone information?
|
||||
#print(locale.getlocale())
|
||||
|
||||
# Record tags
|
||||
|
||||
def parse_argv(argv, version):
|
||||
parser = {}
|
||||
parser['loglevel'] = argparse.ArgumentParser(add_help=False)
|
||||
parser['loglevel'].add_argument('-d', '--debug',
|
||||
help='set log level to debug', action='store_true',
|
||||
default=False)
|
||||
parser['loglevel'].add_argument('-v', '--verbose',
|
||||
help='set log level to info, be more verbose',
|
||||
action='store_true', default=False)
|
||||
|
||||
parser['main'] = argparse.ArgumentParser(description='ctt ' + version,
|
||||
parents=[parser['loglevel']])
|
||||
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)
|
||||
parser['track'].add_argument("--sd", "--start", help="start date (default: first of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, dest="start")
|
||||
parser['track'].add_argument("--ed", "--end", help="end date (default: last of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, default=None, dest="end")
|
||||
parser['track'].add_argument("-n", "--no-comment", help="disable comment prompting after tracking",
|
||||
action='store_false', dest="comment")
|
||||
parser['track'].add_argument("project", help="project to track time for", nargs=1)
|
||||
|
||||
parser['report'] = parser['sub'].add_parser('report',
|
||||
parents=[parser['loglevel']])
|
||||
parser['report'].set_defaults(func=Report.commandline)
|
||||
parser['report'].add_argument("project", help="project to report time for", nargs='*')
|
||||
parser['report'].add_argument("--sd", "--start", help="start date (default: first of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, dest="start")
|
||||
parser['report'].add_argument("--ed", "--end", help="end date (default: last of this month, format: %s)" % ctt.DATEFORMAT_PLAIN,
|
||||
nargs=1, default=None, dest="end")
|
||||
|
||||
parser['report'].add_argument("-a", "--all", help="List entries for all projects", action='store_true')
|
||||
parser['report'].add_argument("-e", "--regexp", help="regular expression to match",
|
||||
default=None)
|
||||
parser['report'].add_argument("-i", "--ignore-case", help="ignore case distinctions", action="store_true")
|
||||
parser['report'].add_argument("-f", "--format", help="output format (default: %s)" % ctt.REPORTFORMAT,
|
||||
default=ctt.REPORTFORMAT, dest="output_format")
|
||||
|
||||
#parser['track'].add_argument("-t", "--tag", help="Add tags",
|
||||
# action="store_true")
|
||||
|
||||
args = parser['main'].parse_args()
|
||||
|
||||
if args.verbose:
|
||||
logging.root.setLevel(logging.INFO)
|
||||
if args.debug:
|
||||
logging.root.setLevel(logging.DEBUG)
|
||||
|
||||
log.debug(args)
|
||||
|
||||
try:
|
||||
args.func(args)
|
||||
|
||||
except ctt.Error as e:
|
||||
log.error(e)
|
||||
sys.exit(1)
|
||||
except AttributeError as e:
|
||||
print(e)
|
||||
parser['main'].print_help()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Ensure our /lib/ is included into PYTHON_PATH
|
||||
sys.path.insert(0, os.path.abspath(
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), '../lib')))
|
||||
|
||||
#logging.basicConfig(format='%(levelname)s: %(message)s')
|
||||
logging.basicConfig(format='%(message)s')
|
||||
|
||||
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)
|
5
setup.py
5
setup.py
|
@ -9,17 +9,14 @@ import ctt
|
|||
|
||||
setup(name='ctt',
|
||||
version=ctt.VERSION,
|
||||
# description=pwman.description,
|
||||
author=ctt.AUTHOR,
|
||||
author_email=ctt.WWW,
|
||||
url=ctt.WWW,
|
||||
license="GNU GPL",
|
||||
packages=['lib/ctt',
|
||||
],
|
||||
scripts=['bin/ctt'],
|
||||
scripts=['scripts/ctt'],
|
||||
zip_safe=True,
|
||||
# install_requires=['pycrypto>=2.6',
|
||||
# 'colorama>=0.2.4'],
|
||||
classifiers=[
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: End Users/Desktop',
|
||||
|
|
Loading…
Reference in a new issue