From: W. Trevor King Date: Sat, 8 May 2010 04:07:11 +0000 (-0400) Subject: Moved Argument and other class definitions after Command X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1c41ec100b0754eb5e598ec48b33887ea405af88;p=hooke.git Moved Argument and other class definitions after Command --- diff --git a/hooke/plugin/__init__.py b/hooke/plugin/__init__.py index d34d1fd..c3b25b7 100644 --- a/hooke/plugin/__init__.py +++ b/hooke/plugin/__init__.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python """The plugin module provides optional submodules that add new Hooke commands. @@ -103,92 +102,6 @@ class Success (CommandExit): class Failure (CommandExit): pass - -class Argument (object): - """Structured user input for :class:`Command`\s. - - TODO: ranges for `count`? - """ - def __init__(self, name, type='string', metavar=None, default=None, - optional=True, count=1, completion_callback=None, - callback=None, aliases=None, help=''): - self.name = name - self.type = type - if metavar == None: - metavar = name.upper() - self.metavar = metavar - self.default = default - self.optional = optional - self.count = count - self.completion_callback = completion_callback - self.callback = callback - if aliases == None: - aliases = [] - self.aliases = aliases - self._help = help - - def __str__(self): - return '<%s %s>' % (self.__class__.__name__, self.name) - - def __repr__(self): - return self.__str__() - - def help(self): - parts = ['%s ' % self.name] - if self.metavar != None: - parts.append('%s ' % self.metavar) - parts.extend(['(%s) ' % self.type, self._help]) - return ''.join(parts) - - def validate(self, value): - """If `value` is not appropriate, raise `ValueError`. - """ - pass # TODO: validation - - # TODO: type conversion - -# TODO: type extensions? - -# Useful callbacks - -class StoreValue (object): - def __init__(self, value): - self.value = value - def __call__(self, command, argument, fragment=None): - return self.value - -class NullQueue (queue.Queue): - """The :class:`queue.Queue` equivalent of `/dev/null`. - - This is a bottomless pit. Items go in, but never come out. - """ - def get(self, block=True, timeout=None): - """Raise queue.Empty. - - There's really no need to override the base Queue.get, but I - want to know if someone tries to read from a NullQueue. With - the default implementation they would just block silently - forever :(. - """ - raise queue.Empty - - def put(self, item, block=True, timeout=None): - """Dump an item into the void. - - Block and timeout are meaningless, because there is always a - free slot available in a bottomless pit. - """ - pass - -class PrintQueue (NullQueue): - """Debugging :class:`NullQueue` that prints items before dropping - them. - """ - def put(self, item, block=True, timeout=None): - """Print `item` and then dump it into the void. - """ - print 'ITEM:\n%s' % item - class Command (object): """One-line command description here. @@ -277,3 +190,88 @@ class Command (object): argument_part = '\n'.join(argument_part) help_part = self._help return '\n\n'.join([name_part, argument_part, help_part]) + +class Argument (object): + """Structured user input for :class:`Command`\s. + + TODO: ranges for `count`? + """ + def __init__(self, name, type='string', metavar=None, default=None, + optional=True, count=1, completion_callback=None, + callback=None, aliases=None, help=''): + self.name = name + self.type = type + if metavar == None: + metavar = name.upper() + self.metavar = metavar + self.default = default + self.optional = optional + self.count = count + self.completion_callback = completion_callback + self.callback = callback + if aliases == None: + aliases = [] + self.aliases = aliases + self._help = help + + def __str__(self): + return '<%s %s>' % (self.__class__.__name__, self.name) + + def __repr__(self): + return self.__str__() + + def help(self): + parts = ['%s ' % self.name] + if self.metavar != None: + parts.append('%s ' % self.metavar) + parts.extend(['(%s) ' % self.type, self._help]) + return ''.join(parts) + + def validate(self, value): + """If `value` is not appropriate, raise `ValueError`. + """ + pass # TODO: validation + + # TODO: type conversion + +# TODO: type extensions? + +# Useful callbacks + +class StoreValue (object): + def __init__(self, value): + self.value = value + def __call__(self, command, argument, fragment=None): + return self.value + +class NullQueue (queue.Queue): + """The :class:`queue.Queue` equivalent of `/dev/null`. + + This is a bottomless pit. Items go in, but never come out. + """ + def get(self, block=True, timeout=None): + """Raise queue.Empty. + + There's really no need to override the base Queue.get, but I + want to know if someone tries to read from a NullQueue. With + the default implementation they would just block silently + forever :(. + """ + raise queue.Empty + + def put(self, item, block=True, timeout=None): + """Dump an item into the void. + + Block and timeout are meaningless, because there is always a + free slot available in a bottomless pit. + """ + pass + +class PrintQueue (NullQueue): + """Debugging :class:`NullQueue` that prints items before dropping + them. + """ + def put(self, item, block=True, timeout=None): + """Print `item` and then dump it into the void. + """ + print 'ITEM:\n%s' % item diff --git a/hooke/plugin/cut.py b/hooke/plugin/cut.py index 41cbedb..f2e71cb 100644 --- a/hooke/plugin/cut.py +++ b/hooke/plugin/cut.py @@ -1,4 +1,6 @@ -# -*- coding: utf-8 -*- +"""Defines :class:`CutPlugin` and :class:`CutCommand`. +""" + class cutCommands(object): def _plug_init(self):