Pits help
Basic report of original Pit help. Need review
This commit is contained in:
239
phelp.py
Normal file
239
phelp.py
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def strstr(haystack, needle):
|
||||||
|
"""
|
||||||
|
Return a sub-string of haystack, going from first occurence of needle until the end.
|
||||||
|
Return None if not found.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
haystack {string} -- the entry string
|
||||||
|
needle {string} -- the part of string searched
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string -- sub-string of haystack, starting from needle. None if not exist.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
email = 'name@example.com'
|
||||||
|
domain = strstr(email, '@');
|
||||||
|
print(domain) // Display : @example.com
|
||||||
|
"""
|
||||||
|
pos = haystack.find(needle)
|
||||||
|
if pos < 0: # not found
|
||||||
|
return None
|
||||||
|
|
||||||
|
return haystack[pos:]
|
||||||
|
|
||||||
|
# TODO Review help message / output / usage
|
||||||
|
|
||||||
|
def handle_help(args, *_):
|
||||||
|
if not args:
|
||||||
|
help_help()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
cmd_handler = [
|
||||||
|
('init', help_init),
|
||||||
|
('project', help_project),
|
||||||
|
('task', help_task),
|
||||||
|
('note', help_note),
|
||||||
|
('log', help_action),
|
||||||
|
('info', help_info),
|
||||||
|
('help', help_help),
|
||||||
|
('version', help_version)
|
||||||
|
]
|
||||||
|
candidate = -1
|
||||||
|
|
||||||
|
for i in range(len(cmd_handler)):
|
||||||
|
if strstr(cmd_handler[i][0], args[0]) == cmd_handler[i][0]:
|
||||||
|
if candidate < 0:
|
||||||
|
candidate = i
|
||||||
|
else:
|
||||||
|
print('Ambiguous command ({})'.format(args[0]))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if candidate < 0:
|
||||||
|
print("Invalid command ({}), run '{} help' for help".format(args[0], os.path.basename(__file__)))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
cmd_handler[candidate][1]()
|
||||||
|
|
||||||
|
def help_project():
|
||||||
|
print('''Pits project is basic entity used to group related tasks together. A project has name and status.
|
||||||
|
|
||||||
|
Creating a project:
|
||||||
|
|
||||||
|
$ pits project -c name [-s status]
|
||||||
|
|
||||||
|
Editing a project:
|
||||||
|
|
||||||
|
$ pits project -e [number] [-n name] [-s status]
|
||||||
|
|
||||||
|
Deleting a project:
|
||||||
|
|
||||||
|
$ pits project -d [number]
|
||||||
|
|
||||||
|
Viewing a project:
|
||||||
|
|
||||||
|
$ pits project [[-q] number]
|
||||||
|
|
||||||
|
Searching projects:
|
||||||
|
|
||||||
|
$ pits project -q [number | [-n name] [-s status]]
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
$ pits project -c 'My Tasks'
|
||||||
|
created project 1: My Tasks (status: active)
|
||||||
|
|
||||||
|
$ pits project -c 'Feature Requests' -s backlog
|
||||||
|
created project 2: Feature Requests (status: backlog)
|
||||||
|
|
||||||
|
$ pits pro
|
||||||
|
1: (username) [active ] My Tasks (0 tasks)
|
||||||
|
* 2: (username) [backlog] Feature Requests (0 tasks)
|
||||||
|
|
||||||
|
$ pits p 1 -e -n 'Task and Bugs' -s current
|
||||||
|
1: Task and Bugs (current, 0 tasks)
|
||||||
|
|
||||||
|
$ pits p
|
||||||
|
1: (username) [current] Task and Bugs (0 tasks)
|
||||||
|
* 2: (username) [backlog] Feature Requests (0 tasks)
|
||||||
|
|
||||||
|
$ pits p -d
|
||||||
|
deleted project 2: Feature Requests
|
||||||
|
|
||||||
|
$ pits p
|
||||||
|
* 1: (username) [current] Task and Bugs (0 tasks)
|
||||||
|
''')
|
||||||
|
|
||||||
|
def help_task():
|
||||||
|
print('''In Pits a task belongs to a project and projects can have many tasks. Task attributes include name, status,
|
||||||
|
priority, date, and time. All attributes except the name are optional.
|
||||||
|
|
||||||
|
Creating a task:
|
||||||
|
|
||||||
|
pits task -c name [-s status] [-p priority] [-d date] [-t time]
|
||||||
|
|
||||||
|
Editing a task:
|
||||||
|
|
||||||
|
pits task -e [number] [-n name] [-s status] [-p priority] [-d date] [-t time]
|
||||||
|
|
||||||
|
Moving a task:
|
||||||
|
|
||||||
|
pits task -m [number] -p number
|
||||||
|
|
||||||
|
Deleting a task:
|
||||||
|
|
||||||
|
pits task -d [number]
|
||||||
|
|
||||||
|
Viewing a task:
|
||||||
|
|
||||||
|
pits task [[-q] number]
|
||||||
|
|
||||||
|
Searching tasks:
|
||||||
|
|
||||||
|
pits task -q [number | [-n name] [-s status] [-p priority] [-d date-from] [-D date-to] [-t time-min] [-T time-max]]
|
||||||
|
|
||||||
|
Supported date formats:
|
||||||
|
|
||||||
|
none, 4/26, 4/26/2012, 4/26/12, '4/26 3pm', '4/26 19:30', '4/26/2012 3:15am', '4/26/12 17:00'
|
||||||
|
'Apr 26', 'Apr 26, 2012', 'Apr 26 3pm', 'Apr 26 19:30', 'Apr 26, 12 3:15am', 'Apr 26, 2012 17:00'
|
||||||
|
|
||||||
|
Supported time formats:
|
||||||
|
|
||||||
|
none, 17, 17:00, 17:30, 5pm, 1:15am
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
$ pits task -c 'Hack this'
|
||||||
|
created task 1/1: Hack this (status: open, priority: normal)
|
||||||
|
|
||||||
|
$ pits task -c 'And hack that' -s new -p urgent -d 'Dec 31'
|
||||||
|
created task 2/1: And hack that (status: new, priority: urgent, date: Dec 31, 2010)
|
||||||
|
|
||||||
|
$ pits t
|
||||||
|
1: (username) [open] [normal] Hack this (0 notes)
|
||||||
|
* 2: (username) [new ] [urgent] Dec 31, 2010 And hack that (0 notes)
|
||||||
|
|
||||||
|
$ pits t -e 1 -s done -d 10/10 -t 4:30
|
||||||
|
updated task 1: Hack that (status: done, date: Oct 10, 2010, time: 4:30)
|
||||||
|
|
||||||
|
$ pits t
|
||||||
|
1: (username) [done] [normal] Oct 10, 2010 4:30 Hack this (0 notes)
|
||||||
|
* 2: (username) [new] [urgent] Dec 31, 2010 And hack that (0 notes)
|
||||||
|
|
||||||
|
$ pits t -d
|
||||||
|
deleted task 2: And hack that
|
||||||
|
|
||||||
|
$ pits t
|
||||||
|
1: (username) [done] [normal] Oct 10, 2010 4:30 Hack this (0 notes)
|
||||||
|
''')
|
||||||
|
|
||||||
|
def help_note():
|
||||||
|
print('''Pits notes are attached to a task. The only attribute is the note's message body.
|
||||||
|
|
||||||
|
Creating a note:
|
||||||
|
|
||||||
|
$ pits note -c message
|
||||||
|
|
||||||
|
Editing a note:
|
||||||
|
|
||||||
|
$ pits note -e [number] message
|
||||||
|
|
||||||
|
Deleting a note:
|
||||||
|
|
||||||
|
$ pits note -d [number]
|
||||||
|
|
||||||
|
Listing notes:
|
||||||
|
|
||||||
|
$ pits note
|
||||||
|
''')
|
||||||
|
|
||||||
|
def help_action():
|
||||||
|
print('''Show summary information about your Pits database. This command is as simple as:
|
||||||
|
|
||||||
|
pits log
|
||||||
|
''')
|
||||||
|
|
||||||
|
def help_info():
|
||||||
|
print('''Show summary information about your Pits database. This command is as simple as:
|
||||||
|
|
||||||
|
pits info
|
||||||
|
''')
|
||||||
|
|
||||||
|
def help_help():
|
||||||
|
print('''Pits is highly experimental software. Use it at your own risk. See LICENSE file for details.
|
||||||
|
usage: pits command [args]
|
||||||
|
|
||||||
|
The commands are:
|
||||||
|
init Create empty Pits database or reinitialize an existing one
|
||||||
|
project Create, search, and manage Pits projects
|
||||||
|
task Create, search, and manage Pits tasks
|
||||||
|
note Create, search, and manage Pits notes
|
||||||
|
log Show chronological Pits activity log
|
||||||
|
info Show summary information about your Pits database
|
||||||
|
help Show help information about Pit
|
||||||
|
version Show Pits version number
|
||||||
|
|
||||||
|
All commands might be shortened as long as they remain unambiguous. See 'pits help <command>' for more
|
||||||
|
information on a specific command.
|
||||||
|
''')
|
||||||
|
|
||||||
|
def help_version():
|
||||||
|
print('todo')
|
||||||
|
|
||||||
|
def help_init():
|
||||||
|
print('''Create empty Pits database or reinitialize an existing one. Default file name for the Pits database
|
||||||
|
is ~/.pits.db -- you can override the default by setting PITFILE environment variable.
|
||||||
|
|
||||||
|
$ pits init [-f]
|
||||||
|
|
||||||
|
-f force initialization without prompt
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
$ pits init
|
||||||
|
/home/user/.pits.db already exists, do you want to override it [y/N]: y
|
||||||
|
Created database /home/user/.pit
|
||||||
|
''')
|
||||||
9
pits.py
9
pits.py
@@ -11,6 +11,7 @@ import project
|
|||||||
import action
|
import action
|
||||||
import task
|
import task
|
||||||
import note
|
import note
|
||||||
|
import phelp
|
||||||
|
|
||||||
# logging.basicConfig(level=logging.ERROR, format='%(levelname)7s :: %(message)s')
|
# logging.basicConfig(level=logging.ERROR, format='%(levelname)7s :: %(message)s')
|
||||||
# logging.basicConfig(level=logging.DEBUG, format='%(asctime)s :: %(levelname)s :: %(message)s')
|
# logging.basicConfig(level=logging.DEBUG, format='%(asctime)s :: %(levelname)s :: %(message)s')
|
||||||
@@ -90,6 +91,8 @@ def init():
|
|||||||
action_msg = 'Initialized pits database - DB Schema version: {}'.format(SCHEMA_VERSION)
|
action_msg = 'Initialized pits database - DB Schema version: {}'.format(SCHEMA_VERSION)
|
||||||
conn.execute(action_query, (getpass.getuser(), 'init', action_msg,))
|
conn.execute(action_query, (getpass.getuser(), 'init', action_msg,))
|
||||||
|
|
||||||
|
print('Created database ' + db_path)
|
||||||
|
|
||||||
# logging.info('Inserting initial data')
|
# logging.info('Inserting initial data')
|
||||||
# conn.executescript("""
|
# conn.executescript("""
|
||||||
# insert into project values(1, 'me', 'test', 'in progress', 'now', 'now')""")
|
# insert into project values(1, 'me', 'test', 'in progress', 'now', 'now')""")
|
||||||
@@ -114,10 +117,6 @@ def count_object(conn, table_name):
|
|||||||
def version(*_):
|
def version(*_):
|
||||||
print('pit version 0.1.0')
|
print('pit version 0.1.0')
|
||||||
|
|
||||||
def pit_help(args, *_):
|
|
||||||
print('TODO help')
|
|
||||||
# TODO help
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
cmd_handler = [
|
cmd_handler = [
|
||||||
('project', project.handle_project),
|
('project', project.handle_project),
|
||||||
@@ -125,7 +124,7 @@ def main():
|
|||||||
('note', note.handle_note),
|
('note', note.handle_note),
|
||||||
('log', action.handle_action),
|
('log', action.handle_action),
|
||||||
('info', info),
|
('info', info),
|
||||||
('help', pit_help),
|
('help', phelp.handle_help),
|
||||||
('version', version),
|
('version', version),
|
||||||
('init', init)
|
('init', init)
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user