| 1 |
# (C) Copyright 2007-2025 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
|
| 11 |
""" The 'Message of the Day' implementation! """ |
| 12 |
|
| 13 |
|
| 14 |
# Standard library imports. |
| 15 |
from random import choice |
| 16 |
|
| 17 |
# Local imports. |
| 18 |
from acme.motd.i_message import IMessage |
| 19 |
from acme.motd.i_motd import IMOTD |
| 20 |
from acme.motd.message import Message |
| 21 |
|
| 22 |
# Enthought library imports. |
| 23 |
from traits.api import HasTraits, List, provides |
| 24 |
|
| 25 |
|
| 26 |
@provides(IMOTD) |
| 27 |
class MOTD(HasTraits): |
| 28 |
"""The 'Message of the Day' implementation!""" |
| 29 |
|
| 30 |
# The default message is used when there are no other messages! |
| 31 |
DEFAULT_MESSAGE = Message( |
| 32 |
author="Anon", text="Work hard and be good to your Mother" |
| 33 |
) |
| 34 |
|
| 35 |
# The list of possible messages. |
| 36 |
messages = List(IMessage) |
| 37 |
|
| 38 |
########################################################################### |
| 39 |
# 'IMOTD' interface. |
| 40 |
########################################################################### |
| 41 |
|
| 42 |
def motd(self): |
| 43 |
"""Prints a random message.""" |
| 44 |
|
| 45 |
if len(self.messages) > 0: |
| 46 |
message = choice(self.messages) |
| 47 |
|
| 48 |
else: |
| 49 |
message = self.DEFAULT_MESSAGE |
| 50 |
|
| 51 |
return message |