Beispiel #1
0
def main(options, arguments):
    print options.show_venues
    def key(race):
        try:
            return (race.date, race.meet.name)
        except AttributeError:
            return (race.date,)
    races = sorted(Races.select(), key=key)
    rows = irows(races, options.show_venues)
    for row in Table(rows, column_seperator=" | "):
        print row
def parse_arguments(arguments):
    """Parse command line arguments.  Returns the tuple (options, race_id)."""
    option_parser = OptionParser()
    option_parser.set_usage("%prog [options] RACE_ID")
    option_parser.add_option("-y", "--year", default=date.today().year,
                             help="Year in which the race occurred.",
                             type="int")
    options, arguments = option_parser.parse_args(arguments[1:])
    try:
        connect(options.server)
        race = Races.get(int(arguments[0]))
    except ConnectionError, error:
        option_parser.error(error)
def parse_arguments(arguments):
    """Parse command line arguments.  Returns the tuple (options, race_id)."""
    option_parser = OptionParser()
    option_parser.set_usage("%prog [options] RACE_ID")
    option_parser.add_option("-y", "--year", default=date.today().year,
                             help="Year in which the race occurred.",
                             type="int")
    options, arguments = option_parser.parse_args(arguments[1:])
    try:
        connect(options.server)
        race = Races.get(int(arguments[0]))
    except ConnectionError, error:
        option_parser.error(error)
    except ValueError:
        race = Races.get(arguments[0], options.year)
    except IndexError:
        option_parser.error("Required positional argument missing.")
    return options, race

@main_function(parse_arguments)
def main(options, race):
    """Read YAML race results from stdin and save them to the specified
    race."""
    try:
        results = load(stdin.read())
    except KeyboardInterrupt:
        return 1
    except ScannerError, error:
        print >> stderr, error
        return 1
Beispiel #4
0
    if options.womens_distance is None:
        options.womens_distance = Distances.get(1).womens_distance
    return options, (race_name, date, venue)

@main_function(parse_arguments)
def main(options, (name, date, venue)):
    """Reads race results from a YAML file taken from stdin and saves them to
    the database based on the command-line arguments."""
    try:
        results = load(stdin.read())
    except KeyboardInterrupt:
        return 1
    except ScannerError, error:
        print >> stderr, error
        return 1
    Races.create(name, date, venue, options.mens_distance,
                 options.womens_distance, options.comments, results)

class Date(datetime.date):
    """Clone of datetime.date that can be instantiated by parsing a string of
    the form /YYYY-MM-DD/."""

    @classmethod
    def from_string(cls, string):
        """Construct a new datetime.date object from a string matching the
        pattern \d{4}[-/]\d{1,2}[-/]\d{1,2}."""
        try:
            if "-" in string:
                year, month, day = string.split("-")
            elif "/" in string:
                year, month, day = string.split("/")
            else: