diff options
author | emkael <emkael@tlen.pl> | 2017-03-16 14:06:10 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-03-16 14:07:34 +0100 |
commit | 293605302c3e01ad0abc87631688291995cb754b (patch) | |
tree | 07c45abef60af55018338806bbcc8bc318a1cb95 | |
parent | a5eb585bc5192268743776db8e4ee24e4fd903ba (diff) |
Prompting for settings filename if not provided via command line
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | playoff.py | 19 |
2 files changed, 19 insertions, 2 deletions
@@ -38,6 +38,8 @@ python playoff.py PLIK_USTAWIEŃ_JSON `PLIK_USTAWIEŃ_JSON` jest plikiem konfiguracyjnym, dostarczającym wszelkich danych niezbędnych do pracy programu. +Jeśli w wywołaniu nie podano ścieżki do pliku ustawień, program spyta o nią sam. + Jego strukturę opisuje dokument [CONFIG](CONFIG.md). Znane ograniczenia @@ -1,11 +1,26 @@ -import json, os, shutil, socket, sys +import glob, json, os, readline, shutil, socket, sys import mysql.connector from datetime import datetime from urlparse import urljoin from playoff import sql as p_sql from playoff import template as p_temp -settings = json.load(open(sys.argv[1])) +def complete_filename(text, state): + return (glob.glob(text+'*')+[None])[state] + +if len(sys.argv) > 1: + settings_file = sys.argv[1] +else: + readline.set_completer_delims(' \t\n;') + readline.parse_and_bind("tab: complete") + readline.set_completer(complete_filename) + settings_file = raw_input('JSON settings file: ') + +if not os.path.exists(settings_file): + print 'Settings file "%s" not found' % settings_file + sys.exit(1) + +settings = json.load(open(settings_file)) teams = settings['teams'] leaderboard = [None] * len(teams) |