black formatting

This commit is contained in:
2018-07-21 15:41:48 +02:00
parent 5f9ea6f0b7
commit b18c4dcd18
8 changed files with 475 additions and 266 deletions

95
pits.py
View File

@@ -17,22 +17,29 @@ 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, format='%(asctime)s :: {%(filename)10s:%(lineno)3d} :: %(funcName)s :: %(levelname)s :: %(message)s')
logging.basicConfig(
level=logging.ERROR,
format="%(asctime)s :: {%(filename)10s:%(lineno)3d} :: %(funcName)s :: %(levelname)s :: %(message)s",
)
DB_FILENAME = 'pits.db'
SCHEMA_FILENAME = 'pits_schema.sql'
DB_FILENAME = "pits.db"
SCHEMA_FILENAME = "pits_schema.sql"
PIT_VERSION = '0.0.1'
PIT_VERSION = "0.0.1"
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 {}".format(db_path))
if os.path.exists(db_path):
valid = {"yes": True, "y": True, "ye": True}
print('{} already exists, do you want to override it? [y/N]:'.format(db_path), end='')
print(
"{} already exists, do you want to override it? [y/N]:".format(db_path),
end="",
)
choice = input().lower()
if choice in valid:
os.remove(db_path)
@@ -40,58 +47,63 @@ def pits_init():
sys.exit(0)
with sqlite3.connect(db_path) as conn:
logging.info('Creating schema')
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: {}".format(schema_path))
with open(schema_path, 'rt') as f:
with open(schema_path, "rt") as f:
schema = f.read()
conn.executescript(schema)
action_query = '''
action_query = """
INSERT INTO action (username, action, message)
VALUES (?, ?, ?);
'''
action_msg = 'Initialized pits database - DB Schema version: {}'.format(SCHEMA_VERSION)
conn.execute(action_query, (getpass.getuser(), 'init', action_msg,))
"""
action_msg = "Initialized pits database - DB Schema version: {}".format(
SCHEMA_VERSION
)
conn.execute(action_query, (getpass.getuser(), "init", action_msg))
print('Created database ' + db_path)
print("Created database " + db_path)
# logging.info('Inserting initial data')
# conn.executescript("""
# insert into project values(1, 'me', 'test', 'in progress', 'now', 'now')""")
def pits_info(_1, _2, conn):
print('Pit version: {}'.format(PIT_VERSION))
print('Pit file name: {}'.format(utils.get_file_path(DB_FILENAME)))
print('Created by: {} on {}'.format(*action.get_first_action(conn)))
print('Last updated by: {} on {}'.format(*action.get_last_action(conn)))
print('Schema version: {}'.format(SCHEMA_VERSION))
print('Projects: {}'.format(utils.count_object(conn, 'project')))
print('Tasks: {}'.format(utils.count_object(conn, 'task')))
print('Notes: {}'.format(utils.count_object(conn, 'note')))
print('Log entries: {}'.format(utils.count_object(conn, 'action')))
print("Pit version: {}".format(PIT_VERSION))
print("Pit file name: {}".format(utils.get_file_path(DB_FILENAME)))
print("Created by: {} on {}".format(*action.get_first_action(conn)))
print("Last updated by: {} on {}".format(*action.get_last_action(conn)))
print("Schema version: {}".format(SCHEMA_VERSION))
print("Projects: {}".format(utils.count_object(conn, "project")))
print("Tasks: {}".format(utils.count_object(conn, "task")))
print("Notes: {}".format(utils.count_object(conn, "note")))
print("Log entries: {}".format(utils.count_object(conn, "action")))
def pits_version(*_):
print('Pits version 0.1.0')
print("Pits version 0.1.0")
def main():
cmd_handler = [
('project', project.handle_project),
('task', task.handle_task),
('note', note.handle_note),
('log', action.handle_action),
('info', pits_info),
('help', phelp.handle_help),
('version', pits_version),
('init', pits_init)
("project", project.handle_project),
("task", task.handle_task),
("note", note.handle_note),
("log", action.handle_action),
("info", pits_info),
("help", phelp.handle_help),
("version", pits_version),
("init", pits_init),
]
candidate = -1
argv = sys.argv
if len(argv) == 1:
argv.append('help')
argv.append("help")
argv.append(None)
for i in range(len(cmd_handler)):
@@ -99,20 +111,24 @@ def main():
if candidate < 0:
candidate = i
else:
print('Ambiguous command ({})'.format(argv[1]))
print("Ambiguous command ({})".format(argv[1]))
sys.exit(1)
if candidate < 0:
print("Invalid command ({}), run '{} help' for help".format(argv[1], utils.get_pits_path()))
print(
"Invalid command ({}), run '{} help' for help".format(
argv[1], utils.get_pits_path()
)
)
sys.exit(1)
if candidate == (len(cmd_handler) -1):
if candidate == (len(cmd_handler) - 1):
pits_init()
sys.exit(0)
conn = utils.create_connection(DB_FILENAME)
last_action = action.read_current(conn)
logging.debug('Last action: {}'.format(last_action))
logging.debug("Last action: {}".format(last_action))
logging.debug(argv)
logging.debug(argv[2:])
cmd_handler[candidate][1](argv[2:], last_action, conn)
@@ -120,5 +136,6 @@ def main():
conn.commit()
conn.close()
if __name__ == '__main__':
main()
if __name__ == "__main__":
main()