diff options
author | MichaĆ Zimniewicz <michzimny@users.noreply.github.com> | 2017-10-12 19:18:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-12 19:18:48 +0200 |
commit | d3a7e4e66ff224859441051f0c1f7fdc56caed86 (patch) | |
tree | 1a68fca517f668eb5ecf68d2577b88181763956c | |
parent | a592554b2fc0cd9ec9decbc81645eb149ba6cabe (diff) | |
parent | cbb6849dcc7a12db6929341c6171ddee9446167c (diff) |
Merge pull request #15 from michzimny/input-defaults1.0
Input defaults
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | quick_lineup.py | 24 |
2 files changed, 28 insertions, 6 deletions
@@ -15,16 +15,16 @@ pip install -r requirements-PLATFORM.txt Where `PLATFORM` is either `windows` or `linux`. -# Configuration +You can also download the pre-built EXE release. -Set MySQL settings in ql/settings.py. +# Configuration -For Linux, you can leave the default `engine` property, for Windows, you have to change it to `mysql.connector.django` to use Oracle connector. +Set MySQL settings in config.json. # Usage ``` -python quick_lineup.py <round> <segment> [<start from table>] +python quick_lineup.py [<round> <segment> [<start from table>]] ``` For instance, to process round 3, segment 2, starting from table 1 run: @@ -33,6 +33,8 @@ For instance, to process round 3, segment 2, starting from table 1 run: python quick_lineup.py 3 2 1 ``` +If round and segment are missing, the script will ask for these values interactively. + The script will iterate pair by pair in each match. It presents the currently assigned players and let you confirm them - pressing ENTER without any input - or change - providing player names (press TAB to autocomplete). # Build process diff --git a/quick_lineup.py b/quick_lineup.py index 7da857f..3f4d000 100644 --- a/quick_lineup.py +++ b/quick_lineup.py @@ -3,13 +3,33 @@ import sys from ql.console import Console +class DefaultArgumentInput(argparse.Action): + def __init__(self, *args, **kwargs): + super(DefaultArgumentInput, self).__init__(*args, **kwargs) + + def __call__(self, parser, namespace, values, option_string=None): + if values is None: + values = input('Please enter value for %s: ' % self.metavar) + try: + values = self.type(values) + except ValueError: + parser.error( + "argument %s: invalid %s value: '%s'" % ( + self.metavar, self.type.__name__, values)) + setattr(namespace, self.dest, values) + + def main(): parser = argparse.ArgumentParser( description='Interface for line-up management in JFR Teamy') - parser.add_argument('round', metavar='ROUND', type=int, + parser.add_argument('round', metavar='ROUND', + action=DefaultArgumentInput, + type=int, nargs='?', help='round number') - parser.add_argument('segment', metavar='SEGMENT', type=int, + parser.add_argument('segment', metavar='SEGMENT', + action=DefaultArgumentInput, + type=int, nargs='?', help='segment number') parser.add_argument('table', metavar='TABLE', type=int, nargs='?', default=None, |