Clean lint problems

This commit is contained in:
2018-07-21 15:55:07 +02:00
parent b18c4dcd18
commit f426b616fd
8 changed files with 30 additions and 47 deletions

View File

@@ -1,13 +1,8 @@
import sqlite3
import os
import argparse
import json
import getpass import getpass
import datetime import datetime
import logging import logging
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum
import sys
class TypeAction(Enum): class TypeAction(Enum):
@@ -31,7 +26,7 @@ class Action:
return str(self.__dict__) return str(self.__dict__)
def handle_action(args, last_action, conn): def handle_action(_1, _2, conn):
logging.info(">> handle action") logging.info(">> handle action")
query = "SELECT * FROM action;" query = "SELECT * FROM action;"
cursor = conn.cursor() cursor = conn.cursor()

View File

@@ -30,9 +30,9 @@ def arg_string(arg, required=""):
return arg.strip() return arg.strip()
def arg_number(arg, required=""): def arg_number(arg): # , required=""):
if not arg.isdigit(): if not arg.isdigit():
print("Invalid value") # TODO print("Invalid value")
sys.exit(1) sys.exit(1)
return int(arg) return int(arg)

View File

@@ -1,15 +1,10 @@
# import sqlite3 # import sqlite3
import os
import argparse
import json
import getpass import getpass
import datetime
import logging import logging
import sys import sys
from action import record_action from action import record_action
from action import TypeAction from action import TypeAction
import project
from args import get_string_arg from args import get_string_arg
from args import arg_number from args import arg_number
@@ -22,7 +17,7 @@ class Note:
def handle_note(args, last_action, conn): def handle_note(args, last_action, conn):
logging.info("> handle note") logging.info("> handle note")
logging.debug("args: " + str(args)) logging.debug("args: %s", args)
if not args: if not args:
list_note( list_note(

View File

@@ -28,12 +28,8 @@ def handle_help(args, *_):
sys.exit(1) sys.exit(1)
if candidate < 0: if candidate < 0:
print( print("No help, <{}> is unknown command".format(args[0]))
"Invalid command ({}), run '{} help' for help".format( help_help()
args[0], os.path.basename(__file__)
)
)
sys.exit(1)
cmd_handler[candidate][1]() cmd_handler[candidate][1]()
@@ -88,6 +84,7 @@ Examples:
* 1: (username) [current] Task and Bugs (0 tasks) * 1: (username) [current] Task and Bugs (0 tasks)
""" """
) )
sys.exit(0)
def help_task(): def help_task():
@@ -154,6 +151,7 @@ Examples:
1: (username) [done] [normal] Oct 10, 2010 4:30 Hack this (0 notes) 1: (username) [done] [normal] Oct 10, 2010 4:30 Hack this (0 notes)
""" """
) )
sys.exit(0)
def help_note(): def help_note():
@@ -177,6 +175,7 @@ Listing notes:
$ pits note $ pits note
""" """
) )
sys.exit(0)
def help_action(): def help_action():
@@ -186,6 +185,7 @@ def help_action():
pits log pits log
""" """
) )
sys.exit(0)
def help_info(): def help_info():
@@ -195,6 +195,7 @@ def help_info():
pits info pits info
""" """
) )
sys.exit(0)
def help_help(): def help_help():
@@ -216,10 +217,12 @@ All commands might be shortened as long as they remain unambiguous. See 'pits he
information on a specific command. information on a specific command.
""" """
) )
sys.exit(0)
def help_version(): def help_version():
print("todo") print("todo")
sys.exit(0)
def help_init(): def help_init():
@@ -238,3 +241,4 @@ Example:
Created database /home/user/.pit Created database /home/user/.pit
""" """
) )
sys.exit(0)

11
pits.py
View File

@@ -1,9 +1,6 @@
import sqlite3 import sqlite3
import os import os
import argparse
import json
import getpass import getpass
import datetime
import logging import logging
import sys import sys
@@ -18,7 +15,7 @@ import utils
# 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')
logging.basicConfig( logging.basicConfig(
level=logging.ERROR, level=logging.DEBUG,
format="%(asctime)s :: {%(filename)10s:%(lineno)3d} :: %(funcName)s :: %(levelname)s :: %(message)s", format="%(asctime)s :: {%(filename)10s:%(lineno)3d} :: %(funcName)s :: %(levelname)s :: %(message)s",
) )
@@ -32,7 +29,7 @@ SCHEMA_VERSION = 1
def pits_init(): def pits_init():
db_path = utils.get_file_path(DB_FILENAME) db_path = utils.get_file_path(DB_FILENAME)
logging.debug("Search database in {}".format(db_path)) logging.debug("Search database in %s", db_path)
if os.path.exists(db_path): if os.path.exists(db_path):
valid = {"yes": True, "y": True, "ye": True} valid = {"yes": True, "y": True, "ye": True}
@@ -49,7 +46,7 @@ def pits_init():
with sqlite3.connect(db_path) as conn: with sqlite3.connect(db_path) as conn:
logging.info("Creating schema") logging.info("Creating schema")
schema_path = utils.get_file_path(SCHEMA_FILENAME) schema_path = utils.get_file_path(SCHEMA_FILENAME)
logging.debug("Schema file path: {}".format(schema_path)) logging.debug("Schema file path: %s", schema_path)
with open(schema_path, "rt") as f: with open(schema_path, "rt") as f:
schema = f.read() schema = f.read()
@@ -128,7 +125,7 @@ def main():
conn = utils.create_connection(DB_FILENAME) conn = utils.create_connection(DB_FILENAME)
last_action = action.read_current(conn) last_action = action.read_current(conn)
logging.debug("Last action: {}".format(last_action)) logging.debug("Last action: %s", last_action)
logging.debug(argv) logging.debug(argv)
logging.debug(argv[2:]) logging.debug(argv[2:])
cmd_handler[candidate][1](argv[2:], last_action, conn) cmd_handler[candidate][1](argv[2:], last_action, conn)

View File

@@ -1,7 +1,4 @@
# import sqlite3 # import sqlite3
import os
import argparse
import json
import getpass import getpass
import datetime import datetime
import logging import logging
@@ -28,7 +25,7 @@ class Project:
def handle_project(args, last_action, conn): def handle_project(args, last_action, conn):
logging.info("> handle project") logging.info("> handle project")
logging.debug("args: " + str(args)) logging.debug("args: %s", args)
if not args: if not args:
list_project(last_action.project_id, conn) list_project(last_action.project_id, conn)
@@ -58,10 +55,9 @@ def handle_project(args, last_action, conn):
else: else:
project_id = last_action.project_id project_id = last_action.project_id
parse_project_args(project, args[1:]) parse_project_args(project, args[1:])
logging.debug("Project: ({}) {}".format(project_id, project)) logging.debug("Project: (%s) %s", project_id, project)
edit_project(project, project_id, conn) edit_project(project, project_id, conn)
# TODO To set as active project, us a -a option?
elif args[0] == "-d": elif args[0] == "-d":
if len(args) > 1: if len(args) > 1:
@@ -133,11 +129,11 @@ def edit_project(project, project_id, conn):
) )
sys.exit(1) sys.exit(1)
logging.debug("Project update args: {}".format(update_args)) logging.debug("Project update args: %s", update_args)
query = "UPDATE project SET {} WHERE id = ?" query = "UPDATE project SET {} WHERE id = ?"
query = query.format(", ".join("%s = '%s'" % (k, v) for k, v in update_args)) query = query.format(", ".join("%s = '%s'" % (k, v) for k, v in update_args))
logging.debug("update project query: " + query) logging.debug("update project query: %s", query)
cursor = conn.cursor() cursor = conn.cursor()
logging.debug("Do a project update") logging.debug("Do a project update")
@@ -179,7 +175,7 @@ def list_project(active_project_id, conn):
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(query) cursor.execute(query)
for row in cursor.fetchall(): for row in cursor.fetchall():
logging.debug("Project row: {}".format(row)) logging.debug("Project row: %s", row)
project_id, username, name, status, nb_task = row project_id, username, name, status, nb_task = row
# TODO Formatting track: https://stackoverflow.com/questions/9989334/create-nice-column-output-in-python # TODO Formatting track: https://stackoverflow.com/questions/9989334/create-nice-column-output-in-python
print( print(
@@ -219,7 +215,7 @@ def view_project_set_active(project_id, last_action, conn):
""" """
cursor.execute(query, (project_id,)) cursor.execute(query, (project_id,))
for row in cursor.fetchall(): for row in cursor.fetchall():
logging.debug("Task row: {}".format(row)) logging.debug("Task row: %s", row)
task_id, username, name, status, priority, date, time, nb_note = row task_id, username, name, status, priority, date, time, nb_note = row
message = date + time + name message = date + time + name
print( print(

14
task.py
View File

@@ -1,7 +1,4 @@
# import sqlite3 # import sqlite3
import os
import argparse
import json
import getpass import getpass
import datetime import datetime
import logging import logging
@@ -59,10 +56,9 @@ def handle_task(args, last_action, conn):
last_action.task_id last_action.task_id
) # FIXME If no active tast - use incremental args_i ) # FIXME If no active tast - use incremental args_i
parse_task_args(task, args[1:]) parse_task_args(task, args[1:])
logging.debug("Task: ({}) {}".format(task_id, task)) logging.debug("Task: (%s) %s", task_id, task)
edit_task(task, task_id, last_action.project_id, conn) edit_task(task, task_id, last_action.project_id, conn)
# TODO To set as active project, us a -a option?
elif args[0] == "-d": elif args[0] == "-d":
# FIXME Duplicate code # FIXME Duplicate code
if len(args) > 1: if len(args) > 1:
@@ -190,11 +186,11 @@ def edit_task(task, task_id, project_id, conn):
) )
sys.exit(1) sys.exit(1)
logging.debug("Task update args: {}".format(update_args)) logging.debug("Task update args: %s", update_args)
query = "UPDATE task SET {} WHERE id = ?" query = "UPDATE task SET {} WHERE id = ?"
query = query.format(", ".join("%s = '%s'" % (k, v) for k, v in update_args)) query = query.format(", ".join("%s = '%s'" % (k, v) for k, v in update_args))
logging.debug("update task query: " + query) logging.debug("update task query: %s")
cursor = conn.cursor() cursor = conn.cursor()
logging.debug("Do a task update") logging.debug("Do a task update")
@@ -204,7 +200,7 @@ def edit_task(task, task_id, project_id, conn):
print("updated task {}: ({})".format(task_id, log_args)) print("updated task {}: ({})".format(task_id, log_args))
# TODO Remove project id ? # TODO Remove project id ?
logging.debug("UPDATE TASK - ACTION MESSAGE : " + log_args) logging.debug("UPDATE TASK - ACTION MESSAGE : %s", log_args)
record_action( record_action(
cursor, TypeAction.UPDATE, "({})".format(log_args), project_id, task_id cursor, TypeAction.UPDATE, "({})".format(log_args), project_id, task_id
) )
@@ -303,7 +299,7 @@ def view_task_set_active(task_id, last_action, conn):
""" """
cursor.execute(query, (task_id,)) cursor.execute(query, (task_id,))
for row in cursor.fetchall(): for row in cursor.fetchall():
logging.debug("Note row: {}".format(row)) logging.debug("Note row: %s", row)
note_id, username, message = row note_id, username, message = row
print( print(
" {} {:d}: ({}) {}".format( " {} {:d}: ({}) {}".format(

View File

@@ -38,7 +38,7 @@ def strstr(haystack, needle):
def create_connection(db_filename): def create_connection(db_filename):
db_path = get_file_path(db_filename) db_path = get_file_path(db_filename)
logging.debug("Try to connect to {}".format(db_path)) logging.debug("Try to connect to %s", db_path)
try: try:
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
return conn return conn