move args
This commit is contained in:
35
args.py
Normal file
35
args.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
|
def get_string_arg(args, required):
|
||||||
|
"""
|
||||||
|
Take an array of element, take first element and return it stripped.
|
||||||
|
If array is empty or None, print an error message with required and exit
|
||||||
|
in error.
|
||||||
|
|
||||||
|
:param args: an array of arguments. Can be empty or None
|
||||||
|
:param required: the message to print in no args (or None)
|
||||||
|
:return: The arg stripped
|
||||||
|
"""
|
||||||
|
if not args:
|
||||||
|
print(f'Missing {required}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
logging.debug(args)
|
||||||
|
return args[0].strip()
|
||||||
|
|
||||||
|
# TODO Move this function
|
||||||
|
def arg_string(arg, required = ''):
|
||||||
|
# TODO To meld with get_string_args
|
||||||
|
if required and arg.startswith('-'):
|
||||||
|
print('required ', required)
|
||||||
|
sys.exit('1')
|
||||||
|
else:
|
||||||
|
return arg.strip()
|
||||||
|
|
||||||
|
def arg_number(arg, required = ''):
|
||||||
|
if not arg.isdigit():
|
||||||
|
print('Invalid value') # TODO
|
||||||
|
sys.exit('1')
|
||||||
|
|
||||||
|
return int(arg)
|
||||||
44
project.py
44
project.py
@@ -9,6 +9,9 @@ import sys
|
|||||||
|
|
||||||
import action
|
import action
|
||||||
|
|
||||||
|
from args import get_string_arg
|
||||||
|
from args import arg_number
|
||||||
|
|
||||||
class Project:
|
class Project:
|
||||||
def __init__(self, status = None):
|
def __init__(self, status = None):
|
||||||
self.name = None
|
self.name = None
|
||||||
@@ -60,7 +63,7 @@ def handle_project(args, last_action, conn):
|
|||||||
else:
|
else:
|
||||||
delete_project(last_action.project_id, conn)
|
delete_project(last_action.project_id, conn)
|
||||||
else:
|
else:
|
||||||
print('Nothing to do... And this is not normalous')
|
print(f'Invalid project option: {args[0]}')
|
||||||
|
|
||||||
def parse_project_args(project, args):
|
def parse_project_args(project, args):
|
||||||
if not args:
|
if not args:
|
||||||
@@ -81,39 +84,6 @@ def parse_project_args(project, args):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def get_string_arg(args, required):
|
|
||||||
"""
|
|
||||||
Take an array of element, take first element and return it stripped.
|
|
||||||
If array is empty or None, print an error message with required and exit
|
|
||||||
in error.
|
|
||||||
|
|
||||||
:param args: an array of arguments. Can be empty or None
|
|
||||||
:param required: the message to print in no args (or None)
|
|
||||||
:return: The arg stripped
|
|
||||||
"""
|
|
||||||
if not args:
|
|
||||||
print(f'Missing {required}')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
logging.debug(args)
|
|
||||||
return args[0].strip()
|
|
||||||
|
|
||||||
# TODO Move this function
|
|
||||||
def arg_string(arg, required = ''):
|
|
||||||
# TODO To meld with get_string_args
|
|
||||||
if required and arg.startswith('-'):
|
|
||||||
print('required ', required)
|
|
||||||
sys.exit('1')
|
|
||||||
else:
|
|
||||||
return arg.strip()
|
|
||||||
|
|
||||||
def arg_number(arg, required = ''):
|
|
||||||
if not arg.isdigit():
|
|
||||||
print('Invalid value') # TODO
|
|
||||||
sys.exit('1')
|
|
||||||
|
|
||||||
return int(arg)
|
|
||||||
|
|
||||||
def create_project(project, conn):
|
def create_project(project, conn):
|
||||||
# TODO Project is same name is forbidden
|
# TODO Project is same name is forbidden
|
||||||
logging.info('>> Create project')
|
logging.info('>> Create project')
|
||||||
@@ -139,7 +109,7 @@ def edit_project(project, project_id, conn):
|
|||||||
|
|
||||||
if not update_args:
|
if not update_args:
|
||||||
print("nothing to update")
|
print("nothing to update")
|
||||||
print("Tips: if you want to set an active, just do '{} project <project_id>'"
|
print("Tips: if you want to set an active project, just do '{} project <project_id>'"
|
||||||
.format(os.path.basename(sys.argv[0])))
|
.format(os.path.basename(sys.argv[0])))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@@ -153,8 +123,9 @@ def edit_project(project, project_id, conn):
|
|||||||
logging.debug('Do a project update')
|
logging.debug('Do a project update')
|
||||||
cursor.execute(query, (project_id,))
|
cursor.execute(query, (project_id,))
|
||||||
|
|
||||||
log_args = ', '.join("%s: '%s'" % (k, v) for k, v in update_args)
|
log_args = ', '.join("%s: %s" % (k, v) for k, v in update_args)
|
||||||
print('updated project {}: ({})'.format(project_id, log_args))
|
print('updated project {}: ({})'.format(project_id, log_args))
|
||||||
|
# TODO Bad output
|
||||||
|
|
||||||
action.create_action(cursor, project_id, message = 'update ' + str(update_args))
|
action.create_action(cursor, project_id, message = 'update ' + str(update_args))
|
||||||
|
|
||||||
@@ -217,5 +188,6 @@ def view_project_set_active(project_id, act_task_id, conn):
|
|||||||
print(' {} {:d}: ({}) [{}] [{}] {} ({} tasks)'.format('*' if act_task_id == row[0] else ' ',
|
print(' {} {:d}: ({}) [{}] [{}] {} ({} tasks)'.format('*' if act_task_id == row[0] else ' ',
|
||||||
task_id, username, status, priority, message, nb_note))
|
task_id, username, status, priority, message, nb_note))
|
||||||
action.create_action(cursor, project_id=project_id)
|
action.create_action(cursor, project_id=project_id)
|
||||||
|
# TODO Unset active task
|
||||||
|
|
||||||
# TODO Add a -v option to see notes?
|
# TODO Add a -v option to see notes?
|
||||||
Reference in New Issue
Block a user