Package grizzled :: Module system
[hide private]
[frames] | no frames]

Module system

source code

The grizzled.system module contains some functions and classes that provide information about the Python system (the Python runtime, the language, etc.). It is a conceptual extension of the standard Python sys module.

Functions [hide private]
int
python_version(version)
Convert a Python string version (e.g., "2.5.1", "1.3", "2.6a3") to a numeric version that can meaningfully be compared with the standard sys module's sys.hexversion value.
source code
tuple
split_python_version(version=None)
Convert a binary Python version string (e.g., 0x020501f0) into the same (major, minor, micro, releaselevel, serial) tuple that is found in sys.version_info.
source code
str
python_version_string(version=None)
Convert a numeric Python version (such as sys.hexversion) to a printable string.
source code
 
ensure_version(min_version)
Raise a RuntimeError if the current Python version isn't at least min_version.
source code
class
class_for_name(class_name)
Given fully-qualified class name, load and return the class object.
source code
Variables [hide private]
  RELEASE_LEVEL_RE = re.compile(r'([0-9]+)(.[0-9]+)?')
  RELEASE_LEVELS = {'a': 10, 'b': 11, 'c': 12, 'f': 15}
  RELEASE_LEVEL_NAMES = {10: 'alpha', 11: 'beta', 12: 'candidate...
  log = logging.getLogger('grizzled.system')
  __package__ = None
hash(x)
Function Details [hide private]

python_version(version)

source code 

Convert a Python string version (e.g., "2.5.1", "1.3", "2.6a3") to a numeric version that can meaningfully be compared with the standard sys module's sys.hexversion value.

For example, here's the usual way to ensure that your program is running under Python 2.5.1 or better:

import sys

if sys.hexversion < 0x020501f0:
    raise RuntimeError, 'This program requires Python 2.5.1 or better'

Here's how you'd use python_version() to do the same thing (in an arguably more readable way):

import sys
from grizzled.sys import python_version

if sys.hexversion < python_version("2.5.1"):
    raise RuntimeError, 'This program requires Python 2.5.1 or better'
Parameters:
  • version (str) - string Python version to convert to binary
Returns: int
corresponding integer Python version
Raises:
  • ValueError - version isn't of the form "x", or "x.y" or "x.y.z"

split_python_version(version=None)

source code 
Convert a binary Python version string (e.g., 0x020501f0) into the same (major, minor, micro, releaselevel, serial) tuple that is found in sys.version_info. Thus, for an input value of 0x020501f0, this function returns the tuple (2, 5, 1, 'final', 0).
Parameters:
  • version (int) - Python integer version
Returns: tuple
The (major, minor, micro, releaselevel, serial) tuple
Raises:
  • ValueError - Bad version number

python_version_string(version=None)

source code 
Convert a numeric Python version (such as sys.hexversion) to a printable string.
Parameters:
  • version (int) - Python integer version
Returns: str
The stringified version

ensure_version(min_version)

source code 
Raise a RuntimeError if the current Python version isn't at least min_version. min_version may be an int (e.g., 0x020500f0) or a string (e.g., "2.5.0").
Parameters:
  • min_version (str or int) - minimum version, as a number or string
Raises:
  • TypeError - min_version isn't a string or an integer
  • ValueError - min_version is a bad Python string version
  • RuntimeError - Python version is too old

class_for_name(class_name)

source code 
Given fully-qualified class name, load and return the class object. A fully-qualified class name contains the module and package, in addition to the simple class name (e.g., grizzled.config.Configuration).
Parameters:
  • class_name (str) - fully-qualified class name
Returns: class
the class object
Raises:
  • NameError - Class not found

Variables Details [hide private]

RELEASE_LEVEL_NAMES

Value:
{10: 'alpha', 11: 'beta', 12: 'candidate', 15: 'final'}