4Suite™ API Documentation

# ► Module Ft.Lib.CommandLine.CommandLineUtil

Utility functions used by command-line scripts

    Copyright 2004 Fourthought, Inc. (USA).
    Detailed license and copyright information: http://4suite.org/COPYRIGHT
    Project home, documentation, distributions: http://4suite.org/

Classes: ArgumentError, GetoptError |  |  |  | Functions: SourceArgToInputSource, SourceArgToUri, wrap_text

## Classes

class ArgumentError(Exception)

  ### Methods inherited from class Exception

  __getitem__, __init__, __str__
class GetoptError(Exception)

  ### Methods inherited from class Exception

  __getitem__, __init__, __str__

## Functions

SourceArgToInputSource(arg, factory, *v_args, **kw_args)
  Some command-line scripts take an argument that is supposed to be either "-" (denoting standard input) or a URI reference that can be resolved against the URI equivalent of the current working directory. This function processes such an argument, given as a string, and returns an appropriate InputSource object.

      Since users tend to expect local OS paths to work as URIs, this
      function will accept and use an OS path argument if does appear to
      point to an existing local file, even though this could interfere
      with catalog-based resolution.

      Raises a ValueError if arg is neither a local file nor a valid URI
      reference nor "-". Raises a UriException if a stream for the
      InputSource could not be opened (e.g., when the URI refers to a
      directory or unreadable file).

      Extra arguments given to this function are passed to the
      InputSourceFactory method that creates the InputSource instance.
      The factory must support the methods fromStream() and fromUri(),
      as defined in Ft.Xml.InputSource.InputSourceFactory. The factory
      must also provide a resolver object with a normalize() method that
      can resolve a URI reference against a base URI, returning a URI.

SourceArgToUri(arg, resolver=<Ft.Lib.Uri.FtUriResolver instance at 0xb7bda14c>)
  Some command-line scripts take an argument that is supposed to be either "-" (denoting standard input) or a URI reference that can be resolved against the URI equivalent of the current working directory. This function processes such an argument, given as a string, and returns an appropriate URI.

      Since users tend to expect local OS paths to work as URIs, this
      function will accept and use an OS path argument if does appear to
      point to an existing local file, even though this could interfere
      with catalog-based resolution.

      Raises a ValueError if arg is neither a local file nor a valid URI
      reference nor "-".

      The resolver object must support a normalize() method that
      can resolve a URI reference against a base URI, returning a URI.

wrap_text(text, width)
  Split 'text' into multiple lines of no more than 'width' characters each, and return the result as a list of strings.

      This function differs from distutils.fancy_getopt.wrap_text() in
      that the distutils version collapses blank lines; this one doesn't.

      See also: Ft.Lib.Wrap()