Next / Previous / Contents / TCC Help System / NM Tech homepage

5. Imports

Here are the modules we'll need to import. First, everybody needs the sys module for standard output and standard error streams, the time module for date and time work, and the os module and stat modules for working with Posix file systems.

hwscan3.py
#================================================================
# Imports
#----------------------------------------------------------------

import sys
import time
import os, stat

Python's standard ldap module handles the extraction of information from the TCC's LDAP server. See the SourceForge page for this module.

hwscan3.py
import ldap

Because LDAP identifies machines by host name, but the GetHardware interface requires an IP address in dotted quartet form, we'll need the standard Python socket interface to translate names to IP addresses.

hwscan3.py
import socket

The GetHardware interface is an XML-RPC service. Python's xmlrpclib handles communications with such interfaces.

hwscan3.py
import xmlrpclib

The program needs to read an XML file (scanreport.xml), and also to generate Web pages as XHTML. The lxml.etree package handles both reading and writing XML; we import it as et. For particulars of this package, see Python XML processing with lxml.

To simplify the generation of XHTML, we use the etbuilder module described in Python XML processing with lxml. This package also provides the lxml.etree module as “et”.

hwscan3.py
from etbuilder import et, E

We also use the pyrang application to generate Python names for all the XML elements and attributes in scanreport.xml. For information on this application, see pyrang: A single-sourcing tool for Python-XML applications. The file built by pyrang from scanreport.xml is named rnc_scanreport.

hwscan3.py
from rnc_scanreport import *

The tccpage2.py module contains the TCCPage class, used for generating whole pages that conform to the standard TCC web page layout. See tccpage.py: Dynamic generation of TCC-style web pages with lxml.

hwscan3.py
import tccpage2