Browse Source

Options are @classmethod now (like networks)

master
Julio Biason 15 years ago
parent
commit
d41ba0352d
  1. 13
      mitterlib/ui/cmd.py
  2. 13
      mitterlib/ui/mh.py
  3. 71
      mitterlib/ui/tty.py

13
mitterlib/ui/cmd.py

@ -28,18 +28,14 @@ from mitterlib.network import NetworksNoNetworkSetupError, NetworksError
from mitterlib.network.networkbase import NetworkError, \
NetworkPermissionDeniedError
namespace = 'cmd' # TODO: rename this var to NAMESPACE (check other files too)
_log = logging.getLogger('ui.cmd')
def options(options):
# no options for this interface
return
class Interface(cmd.Cmd):
"""The command line interface for Mitter."""
NAMESPACE = 'cmd'
# -----------------------------------------------------------------------
# Methods required by cmd.Cmd (our commands)
# -----------------------------------------------------------------------
@ -324,3 +320,8 @@ class Interface(cmd.Cmd):
warnings.simplefilter('error') # Warnings are exceptions
self.cmdloop()
return
@classmethod
def options(self, options):
# no options for this interface
return

13
mitterlib/ui/mh.py

@ -28,18 +28,14 @@ from mitterlib.network import NetworksNoNetworkSetupError, NetworksError
from mitterlib.network.networkbase import NetworkError, \
NetworkPermissionDeniedError
namespace = 'cmd' # TODO: rename this var to NAMESPACE (check other files too)
_log = logging.getLogger('ui.cmd')
def options(options):
# no options for this interface
return
class Interface(cmd.Cmd):
"""A MH-like interface to Mitter."""
NAMESPACE = 'mh'
# -----------------------------------------------------------------------
# Commands
# -----------------------------------------------------------------------
@ -161,3 +157,8 @@ class Interface(cmd.Cmd):
warnings.simplefilter('error') # Warnings are exceptions
self.cmdloop()
return
@classmethod
def options(self, options):
# no options for this interface
return

71
mitterlib/ui/tty.py

@ -17,8 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
NAMESPACE = 'tty'
import mitterlib.ui.console_utils as console_utils
import logging
from mitterlib.network.networkbase import NetworkError
@ -27,41 +25,11 @@ from mitterlib.network import NetworksNoNetworkSetupError, NetworksError
_log = logging.getLogger('ui.tty')
def options(options):
"""Add command line options for this interface."""
options.add_group(NAMESPACE, 'TTY interface') # This surely needs a
# better description
options.add_option('--messages',
group=NAMESPACE,
option='messages',
help='Display the latest messages.',
default=False,
action='store_true',
is_config_option=False,
conflict_group='interface')
options.add_option('--update',
group=NAMESPACE,
option='update',
default=None,
help='Update your status',
metavar='STATUS',
type='str',
is_config_option=False,
conflict_group='interface')
options.add_option('--replies',
group=NAMESPACE,
option='replies',
help='Get a list of replies instead of the friends timeline',
default=False,
action='store_true',
is_config_option=False,
conflict_group='interface')
return
class Interface(object):
"""The console/tty interface for Mitter."""
NAMESPACE = 'tty'
# -----------------------------------------------------------------------
# Private functions
# -----------------------------------------------------------------------
@ -117,14 +85,45 @@ class Interface(object):
def __call__(self):
"""The callable function, used by mitter to start the interface."""
status_message = self._options[NAMESPACE]['update']
status_message = self._options[self.NAMESPACE]['update']
if status_message:
self._update(status_message)
return
if self._options[NAMESPACE]['replies']:
if self._options[self.NAMESPACE]['replies']:
self._replies()
return
self._messages()
return
@classmethod
def options(self, options):
"""Add command line options for this interface."""
options.add_group(self.NAMESPACE, 'TTY interface')
options.add_option('--messages',
group=self.NAMESPACE,
option='messages',
help='Display the latest messages.',
default=False,
action='store_true',
is_config_option=False,
conflict_group='interface')
options.add_option('--update',
group=self.NAMESPACE,
option='update',
default=None,
help='Update your status',
metavar='STATUS',
type='str',
is_config_option=False,
conflict_group='interface')
options.add_option('--replies',
group=self.NAMESPACE,
option='replies',
help='Get a list of replies instead of the friends timeline',
default=False,
action='store_true',
is_config_option=False,
conflict_group='interface')
return

Loading…
Cancel
Save