From f426b616fd8de276f163bb11a7a81e221c6f1253 Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Sat, 21 Jul 2018 15:55:07 +0200 Subject: [PATCH] Clean lint problems --- action.py | 7 +------ args.py | 4 ++-- note.py | 7 +------ phelp.py | 16 ++++++++++------ pits.py | 11 ++++------- project.py | 16 ++++++---------- task.py | 14 +++++--------- utils.py | 2 +- 8 files changed, 30 insertions(+), 47 deletions(-) diff --git a/action.py b/action.py index b37450d..21513d8 100644 --- a/action.py +++ b/action.py @@ -1,13 +1,8 @@ -import sqlite3 -import os -import argparse -import json import getpass import datetime import logging from datetime import datetime from enum import Enum -import sys class TypeAction(Enum): @@ -31,7 +26,7 @@ class Action: return str(self.__dict__) -def handle_action(args, last_action, conn): +def handle_action(_1, _2, conn): logging.info(">> handle action") query = "SELECT * FROM action;" cursor = conn.cursor() diff --git a/args.py b/args.py index 107f602..c0f2223 100644 --- a/args.py +++ b/args.py @@ -30,9 +30,9 @@ def arg_string(arg, required=""): return arg.strip() -def arg_number(arg, required=""): +def arg_number(arg): # , required=""): if not arg.isdigit(): - print("Invalid value") # TODO + print("Invalid value") sys.exit(1) return int(arg) diff --git a/note.py b/note.py index c2f61f1..a6ca4b6 100644 --- a/note.py +++ b/note.py @@ -1,15 +1,10 @@ # import sqlite3 -import os -import argparse -import json import getpass -import datetime import logging import sys from action import record_action from action import TypeAction -import project from args import get_string_arg from args import arg_number @@ -22,7 +17,7 @@ class Note: def handle_note(args, last_action, conn): logging.info("> handle note") - logging.debug("args: " + str(args)) + logging.debug("args: %s", args) if not args: list_note( diff --git a/phelp.py b/phelp.py index da6b2fa..739d0a2 100644 --- a/phelp.py +++ b/phelp.py @@ -28,12 +28,8 @@ def handle_help(args, *_): sys.exit(1) if candidate < 0: - print( - "Invalid command ({}), run '{} help' for help".format( - args[0], os.path.basename(__file__) - ) - ) - sys.exit(1) + print("No help, <{}> is unknown command".format(args[0])) + help_help() cmd_handler[candidate][1]() @@ -88,6 +84,7 @@ Examples: * 1: (username) [current] Task and Bugs (0 tasks) """ ) + sys.exit(0) def help_task(): @@ -154,6 +151,7 @@ Examples: 1: (username) [done] [normal] Oct 10, 2010 4:30 Hack this (0 notes) """ ) + sys.exit(0) def help_note(): @@ -177,6 +175,7 @@ Listing notes: $ pits note """ ) + sys.exit(0) def help_action(): @@ -186,6 +185,7 @@ def help_action(): pits log """ ) + sys.exit(0) def help_info(): @@ -195,6 +195,7 @@ def help_info(): pits info """ ) + sys.exit(0) 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. """ ) + sys.exit(0) def help_version(): print("todo") + sys.exit(0) def help_init(): @@ -238,3 +241,4 @@ Example: Created database /home/user/.pit """ ) + sys.exit(0) diff --git a/pits.py b/pits.py index 25859e3..7c48fcd 100644 --- a/pits.py +++ b/pits.py @@ -1,9 +1,6 @@ import sqlite3 import os -import argparse -import json import getpass -import datetime import logging import sys @@ -18,7 +15,7 @@ import utils # 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.ERROR, + level=logging.DEBUG, format="%(asctime)s :: {%(filename)10s:%(lineno)3d} :: %(funcName)s :: %(levelname)s :: %(message)s", ) @@ -32,7 +29,7 @@ SCHEMA_VERSION = 1 def pits_init(): 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): valid = {"yes": True, "y": True, "ye": True} @@ -49,7 +46,7 @@ def pits_init(): with sqlite3.connect(db_path) as conn: logging.info("Creating schema") 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: schema = f.read() @@ -128,7 +125,7 @@ def main(): conn = utils.create_connection(DB_FILENAME) 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[2:]) cmd_handler[candidate][1](argv[2:], last_action, conn) diff --git a/project.py b/project.py index e530b57..aaa2629 100644 --- a/project.py +++ b/project.py @@ -1,7 +1,4 @@ # import sqlite3 -import os -import argparse -import json import getpass import datetime import logging @@ -28,7 +25,7 @@ class Project: def handle_project(args, last_action, conn): logging.info("> handle project") - logging.debug("args: " + str(args)) + logging.debug("args: %s", args) if not args: list_project(last_action.project_id, conn) @@ -58,10 +55,9 @@ def handle_project(args, last_action, conn): else: project_id = last_action.project_id 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) - # TODO To set as active project, us a -a option? elif args[0] == "-d": if len(args) > 1: @@ -133,11 +129,11 @@ def edit_project(project, project_id, conn): ) 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 = 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() logging.debug("Do a project update") @@ -179,7 +175,7 @@ def list_project(active_project_id, conn): cursor = conn.cursor() cursor.execute(query) 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 # TODO Formatting track: https://stackoverflow.com/questions/9989334/create-nice-column-output-in-python print( @@ -219,7 +215,7 @@ def view_project_set_active(project_id, last_action, conn): """ cursor.execute(query, (project_id,)) 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 message = date + time + name print( diff --git a/task.py b/task.py index db8650b..0f5670a 100644 --- a/task.py +++ b/task.py @@ -1,7 +1,4 @@ # import sqlite3 -import os -import argparse -import json import getpass import datetime import logging @@ -59,10 +56,9 @@ def handle_task(args, last_action, conn): last_action.task_id ) # FIXME If no active tast - use incremental args_i 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) - # TODO To set as active project, us a -a option? elif args[0] == "-d": # FIXME Duplicate code if len(args) > 1: @@ -190,11 +186,11 @@ def edit_task(task, task_id, project_id, conn): ) 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 = 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() 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)) # TODO Remove project id ? - logging.debug("UPDATE TASK - ACTION MESSAGE : " + log_args) + logging.debug("UPDATE TASK - ACTION MESSAGE : %s", log_args) record_action( 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,)) for row in cursor.fetchall(): - logging.debug("Note row: {}".format(row)) + logging.debug("Note row: %s", row) note_id, username, message = row print( " {} {:d}: ({}) {}".format( diff --git a/utils.py b/utils.py index 4d81f8c..ba38d5e 100644 --- a/utils.py +++ b/utils.py @@ -38,7 +38,7 @@ def strstr(haystack, needle): def create_connection(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: conn = sqlite3.connect(db_path) return conn