From 8e80cec14a4834ae2012959d61e473a2b430c6c4 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 25 Nov 2016 16:33:01 +0100 Subject: bootstrap file and environment for pyinstaller --- ql/__main__.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 ql/__main__.py (limited to 'ql') diff --git a/ql/__main__.py b/ql/__main__.py deleted file mode 100644 index e79056d..0000000 --- a/ql/__main__.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys -from .console import Console - - -if len(sys.argv) < 3 or len(sys.argv) > 4: - print('Give correct parameters: round, segment and (optionally) table') - sys.exit(1) - -round = int(sys.argv[1]) -segment = int(sys.argv[2]) -if len(sys.argv) == 4: - table = int(sys.argv[3]) -else: - table = None - -Console(round, segment, table).run() -- cgit v1.2.3 From 62dca92a29e746d7dabf04ad7bea6931fa0e7ad7 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 25 Nov 2016 18:00:29 +0100 Subject: Replacing cached_property module from Django to a standalone one --- ql/lineup.py | 2 +- requirements-linux.txt | 1 + requirements-windows.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) (limited to 'ql') diff --git a/ql/lineup.py b/ql/lineup.py index b0d5847..5a2ce82 100644 --- a/ql/lineup.py +++ b/ql/lineup.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from django.utils.functional import cached_property +from cached_property import cached_property from .orm.models import Segment, Team, Player diff --git a/requirements-linux.txt b/requirements-linux.txt index 02377be..967d473 100644 --- a/requirements-linux.txt +++ b/requirements-linux.txt @@ -1,3 +1,4 @@ django mysqlclient readline +cached_property diff --git a/requirements-windows.txt b/requirements-windows.txt index 48b847f..3e5e893 100644 --- a/requirements-windows.txt +++ b/requirements-windows.txt @@ -1,2 +1,3 @@ django pyreadline +cached_property -- cgit v1.2.3 From ee4f35076b048162c87059d08425b6280776ec09 Mon Sep 17 00:00:00 2001 From: Michal Zimniewicz Date: Sun, 9 Oct 2016 12:27:23 +0200 Subject: adjust super() calls to python2 --- ql/lineup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ql') diff --git a/ql/lineup.py b/ql/lineup.py index 5a2ce82..cca69e5 100644 --- a/ql/lineup.py +++ b/ql/lineup.py @@ -38,7 +38,7 @@ class TeamInSegment(object): class HomeTeamInSegment(TeamInSegment): def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + super(HomeTeamInSegment, self).__init__(*args, **kwargs) def get_paired_players_fields(self): return [ @@ -56,7 +56,7 @@ class HomeTeamInSegment(TeamInSegment): class AwayTeamInSegment(TeamInSegment): def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + super(AwayTeamInSegment, self).__init__(*args, **kwargs) def get_paired_players_fields(self): return [ -- cgit v1.2.3 From ae7738768ead06aea4b93826c8e164da53eeba51 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 10 Oct 2016 13:19:25 +0200 Subject: alias raw_input() as input() for python2 --- ql/console.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ql') diff --git a/ql/console.py b/ql/console.py index 0c741ca..dede956 100755 --- a/ql/console.py +++ b/ql/console.py @@ -22,6 +22,12 @@ class Console(object): lineup = self.get_lineup(table) print(lineup.info) print() + # Python 2.x workaround + global input + try: + input = raw_input + except NameError: + pass # if raw_input is not defined (Python 3.x), ignore it for team in lineup.teams: Completer.install_new_completer(team.player_names) for pair in team.pairs: -- cgit v1.2.3 From 07401a984b58d6d1328264efca45df39e1951ea2 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 10 Oct 2016 16:12:23 +0200 Subject: encoding readline completer options in case Python2 unicode strings are involved --- ql/completer.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ql') diff --git a/ql/completer.py b/ql/completer.py index a9b7d8d..89920d4 100644 --- a/ql/completer.py +++ b/ql/completer.py @@ -1,4 +1,5 @@ import readline +import sys class Completer(object): @@ -10,8 +11,15 @@ class Completer(object): readline.set_completer_delims('') # allow options with whitespace readline.parse_and_bind('tab: complete') + def __encode_completion_string(self, s): + try: + return s.encode(sys.stdin.encoding) if isinstance(s, unicode) else s + except NameError: # Python 3.x does not have a 'unicode' type + pass + return s + def __init__(self, options): - self.options = options + self.options = [self.__encode_completion_string(s) for s in options] def complete(self, text, state): text = text.lower() -- cgit v1.2.3 From 918046228044145d77e96d8b739430c65da6f23f Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 10 Oct 2016 16:15:33 +0200 Subject: fun fact: `print()` in Python2 prints out "()" --- ql/console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ql') diff --git a/ql/console.py b/ql/console.py index dede956..6751b83 100755 --- a/ql/console.py +++ b/ql/console.py @@ -21,7 +21,7 @@ class Console(object): def process_table(self, table): lineup = self.get_lineup(table) print(lineup.info) - print() + print('') # Python 2.x workaround global input try: -- cgit v1.2.3 From cadaee4d114be675bdc6a235cb918dd1bae35ed3 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 10 Oct 2016 16:17:39 +0200 Subject: clearing up Pair info for printing purposes --- ql/lineup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ql') diff --git a/ql/lineup.py b/ql/lineup.py index cca69e5..872fc7f 100644 --- a/ql/lineup.py +++ b/ql/lineup.py @@ -95,7 +95,7 @@ class Pair(object): return 'Team: %s - %s - %s' % ( self.team.name, self.label, - [ p.info if p is not None else '' for p in self.players ] + ', '.join([ p.info if p is not None else '' for p in self.players ]) ) def set_player(self, name): -- cgit v1.2.3 From 2ee4dc85051ebb01a88ffd49ed513b65ccc651c8 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 25 Nov 2016 21:35:10 +0100 Subject: Handling Ctrl+C/Ctrl+D a bit more gracefully --- ql/console.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ql') diff --git a/ql/console.py b/ql/console.py index 6751b83..f797da7 100755 --- a/ql/console.py +++ b/ql/console.py @@ -16,7 +16,10 @@ class Console(object): def run(self): for table in self.tables: - self.process_table(table) + try: + self.process_table(table) + except (EOFError, KeyboardInterrupt): + break def process_table(self, table): lineup = self.get_lineup(table) -- cgit v1.2.3 From 542e7cfbf6c543a234309feb42d087779a7cdc12 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 25 Nov 2016 22:09:22 +0100 Subject: Configuration from external JSON file. Fixes #2 --- .gitignore | 1 + ql/settings.py | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'ql') diff --git a/.gitignore b/.gitignore index 0903698..38e438d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ /venv* build dist +config.json diff --git a/ql/settings.py b/ql/settings.py index a975f14..df68ae3 100755 --- a/ql/settings.py +++ b/ql/settings.py @@ -1,12 +1,33 @@ +import json, sys + +def _fetch_settings(config_path, constant_config, default_config): + try: + config = constant_config.copy() + config.update(json.load(open(config_path))) + return config + except FileNotFoundError: + with open(config_path, 'w') as new_config: + json.dump(default_config, new_config) + print('Config file created, fill it up!') + sys.exit() + except ValueError: + print('Config file invalid, fix it!') + sys.exit(1) + DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'HOST': '127.0.0.1', - 'PORT': '3306', - 'USER': 'your-username', - 'PASSWORD': 'your-password', - 'NAME': 'your-database-name', - } + 'default': _fetch_settings( + 'config.json', + { + 'ENGINE': 'mysql.connector.django' + }, + { + 'HOST': 'localhost', + 'PORT': '3306', + 'USER': 'root', + 'PASSWORD': '', + 'NAME': 'belongs_to_us' + } + ) } INSTALLED_APPS = ( -- cgit v1.2.3 From 6d5ae86eac297cbc62d56c0479582e50207b05bd Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 25 Nov 2016 22:26:19 +0100 Subject: More verbose config-related messages --- ql/settings.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ql') diff --git a/ql/settings.py b/ql/settings.py index df68ae3..7d8af00 100755 --- a/ql/settings.py +++ b/ql/settings.py @@ -1,4 +1,4 @@ -import json, sys +import json, os, sys def _fetch_settings(config_path, constant_config, default_config): try: @@ -8,10 +8,16 @@ def _fetch_settings(config_path, constant_config, default_config): except FileNotFoundError: with open(config_path, 'w') as new_config: json.dump(default_config, new_config) - print('Config file created, fill it up!') + print( + 'Config file %s created, fill it up!' % + os.path.realpath(config_path) + ) sys.exit() except ValueError: - print('Config file invalid, fix it!') + print( + 'Config file %s invalid, fix it!' % + os.path.realpath(config_path) + ) sys.exit(1) DATABASES = { -- cgit v1.2.3 From fca5169ad79dbee8db6d31a7ab51a74525fda561 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 26 Feb 2017 16:36:46 +0100 Subject: https://github.com/michzimny/teamy-quick-lineup/pull/9#pullrequestreview-23883015 --- ql/lineup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ql') diff --git a/ql/lineup.py b/ql/lineup.py index 872fc7f..688825b 100644 --- a/ql/lineup.py +++ b/ql/lineup.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from cached_property import cached_property +from django.utils.functional import cached_property from .orm.models import Segment, Team, Player -- cgit v1.2.3