def __init__(self, name, opt, desc, value=None, default=None, metavar=None, replace=False): """ Constructor. @param name The name of the configuration query to which the option overrides the answer. @param opt A string or a sequence of strings defining the command-line options. The options can be short (a dash followed by one letter) or long (two dashes followed by a word). Case sensitive. @param desc A one-line description of the option that will appear in the help text. @param value For a boolean option, the value that this option sets when specified. Up to two @option decorators can be put on the same function with different value arguments. The default behavior for a boolean option when value is not specified is that the option sets a true value, and the opposite option name is generated automatically. Short options are not inverted. The inversion is not performed when value is specified. @param default The default value to display in the help text. This is only for documentation purposes and does not affect the actual default used when the option is not specified. The default behavior when default is not specified is to use the actual value obtained from reading the configuration files up to the point of parsing the command line. @param metavar The meta-variable that will be used to refer to the option's value in the help text, such as FILE. The default is N for integer options, STRING for strings and lists, and KEY=VALUE for dictionaries. @param replace Only for list or dictionary options. If true, the first use of the option on the command line clears the list or dictionary; subsequent uses add items to it. If false, every use of the option adds an item. """ self.name = name self.opt = util.ensureList(opt) self.desc = desc self.value = value self.default = default self.metavar = metavar self.replace = replace
def step(self): """ Run a slice of the flow until it yields or returns. The state must be PENDING, and becomes RUNNING for the duration of the slice, then changes to PENDING, BLOCKED, COMPLETED or FAILED. @return If the resulting state is BLOCKED, a sequence of nodes or commands on which the node is blocked. Otherwise a false value. """ assert self._state == Node.PENDING and self._blocked == 0 and self._generator try: self._state = Node.RUNNING with self: yielded = self._generator.next() if yielded is self: self._generator.close() self._generator = self._startgen(True) self._state = Node.PENDING if self._generator else Node.COMPLETED return None blocked = util.ensureList(yielded) self._blocked = len(blocked) self._state = Node.BLOCKED if self._blocked else Node.PENDING return blocked except StopIteration: self._generator = None self._state = Node.COMPLETED if hasattr(self._flowiter, 'close'): self._flowiter.close() self._flowiter = None return None except: self._generator = None self._state = Node.FAILED self._error = sys.exc_info() if hasattr(self._flowiter, 'close'): self._flowiter.close() self._flowiter = None return None