From 553b5e01dd60ded1404bd500457eabdf5a875ad2 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 1 Sep 2015 12:02:55 +0200 Subject: * path parsing and file existence checks --- bidding_data.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'bidding_data.py') diff --git a/bidding_data.py b/bidding_data.py index a56847b..e24ffba 100644 --- a/bidding_data.py +++ b/bidding_data.py @@ -156,7 +156,7 @@ class JFRBidding: self.__round_lineups = self.__parse_lineup_data(self.__lineup_data) self.__bids = self.__parse_bidding_data(bid_data) self.__tournament_prefix = path.splitext( - path.realpath(file_prefix + '.html'))[0] + path.realpath(file_prefix))[0] self.__tournament_files_match = re.compile( re.escape(self.__tournament_prefix) + '([0-9]{3})\.html') self.__map_board_numbers() @@ -276,10 +276,20 @@ if __name__ == '__main__': argument_parser = argparse.ArgumentParser( description='Display bidding data from BWS files on JFR Pary pages') + + def file_path(filepath): + filepath = unicode(filepath, sys.getfilesystemencoding()) + if path.isfile(filepath): + return filepath + else: + argument_parser.error('File %s does not exist' % filepath) + argument_parser.add_argument('bws_file', metavar='BWS_FILE', - help='path to BWS file') + help='path to BWS file', + type=file_path) argument_parser.add_argument('path', metavar='PATH', - help='tournament path with JFR prefix') + help='tournament path (to PREFIX.html)', + type=file_path) arguments = argument_parser.parse_args() -- cgit v1.2.3