/usr/lib/python2.6/site-packages
NameSizeModeActions
appdirs-1.4.0.dist-info/-0755rm
argparse-1.4.0.dist-info/-0755rm
babel/-0755rm
Babel-2.1.1.dist-info/-0755rm
Babel-2.3.4.dist-info/-0755rm
backports/-0755rm
backports.ssl_match_hostname-3.4.0.2-py2.6.egg-info/-0755rm
boto/-0755rm
boto-2.34.0-py2.6.egg-info/-0755rm
cffi-1.6.0-py2.6-linux-x86_64.egg/-0755rm
chardet/-0755rm
chardet-2.2.1-py2.6.egg-info/-0755rm
cinderclient/-0755rm
clcommon/-0755rm
cliff/-0755rm
cliff-1.15.0.dist-info/-0755rm
cliff-2.0.0.dist-info/-0755rm
clifftablib/-0755rm
cliff_tablib-1.1-py2.6.egg-info/-0755rm
cloudinit/-0755rm
cloud_init-0.7.5-py2.6.egg-info/-0755rm
cmd2-0.6.8-py2.6.egg-info/-0755rm
concurrent/-0755rm
cryptography-1.3.1-py2.6-linux-x86_64.egg/-0755rm
dateutil/-0755rm
dbus/-0755rm
debtcollector/-0755rm
debtcollector-0.8.0.dist-info/-0755rm
debtcollector-1.3.0.dist-info/-0755rm
decorator-4.0.9.dist-info/-0755rm
dict-0.0.5-py2.6.egg-info/-0755rm
distribute-0.6.10-py2.6.egg-info/-0755rm
dns/-0755rm
enum/-0755rm
enum34-1.0.4-py2.6.egg-info/-0755rm
enum34-1.1.3-py2.6.egg/-0755rm
funcsigs/-0755rm
funcsigs-1.0.2.dist-info/-0755rm
futures-3.0.3.dist-info/-0755rm
futures-3.0.5.dist-info/-0755rm
get-0.0.7-py2.6.egg-info/-0755rm
glanceclient/-0755rm
idna/-0755rm
idna-2.0.dist-info/-0755rm
idna-2.1-py2.6.egg/-0755rm
iniparse/-0755rm
iotop/-0755rm
iotop-0.3.2-py2.6.egg-info/-0755rm
ipaddress-1.0.14-py2.6.egg-info/-0755rm
ipaddress-1.0.16-py2.6.egg/-0755rm
iso8601/-0755rm
iso8601-0.1.10-py2.6.egg-info/-0755rm
iso8601-0.1.11.dist-info/-0755rm
jsonpatch-1.2-py2.6.egg-info/-0755rm
jsonpatch-1.11.dist-info/-0755rm
jsonpatch-1.13.dist-info/-0755rm
jsonpointer-1.9.dist-info/-0755rm
jsonpointer-1.10.dist-info/-0755rm
jsonschema/-0755rm
jsonschema-2.5.1.dist-info/-0755rm
keystoneauth1/-0755rm
keystoneauth1-1.1.0.dist-info/-0755rm
keystoneauth1-2.6.0.dist-info/-0755rm
keystoneclient/-0755rm
markdown/-0755rm
monotonic-0.4-py2.6.egg-info/-0755rm
monotonic-1.1.dist-info/-0755rm
ndg/-0755rm
ndg_httpsclient-0.4.0-py2.6.egg-info/-0755rm
netaddr/-0755rm
netaddr-0.7.18.dist-info/-0755rm
neutronclient/-0755rm
nose/-0755rm
nose-0.10.4-py2.6.egg-info/-0755rm
novaclient/-0755rm
oauth/-0755rm
oauth-1.0.1-py2.6.egg-info/-0755rm
openstack/-0755rm
openstackclient/-0755rm
openstacksdk-0.8.5.dist-info/-0755rm
oslo.config-2.4.0.dist-info/-0755rm
oslo.config-3.9.0.dist-info/-0755rm
oslo.i18n-2.6.0.dist-info/-0755rm
oslo.i18n-3.6.0.dist-info/-0755rm
oslo.serialization-1.9.0.dist-info/-0755rm
oslo.serialization-2.4.0.dist-info/-0755rm
oslo.utils-2.5.0.dist-info/-0755rm
oslo.utils-3.8.0.dist-info/-0755rm
oslo_config/-0755rm
oslo_i18n/-0755rm
oslo_serialization/-0755rm
oslo_utils/-0755rm
os_client_config/-0755rm
os_client_config-1.8.1.dist-info/-0755rm
os_client_config-1.17.0.dist-info/-0755rm
pbr/-0755rm
pbr-1.8.0.dist-info/-0755rm
pbr-1.9.1.dist-info/-0755rm
pip-7.1.2-py2.6.egg/-0755rm
pip-8.1.1-py2.6.egg/-0755rm
pkg_resources/-0755rm
positional/-0755rm
positional-1.1.0-py2.6.egg-info/-0755rm
post-0.0.5-py2.6.egg-info/-0755rm
prettytable-0.7.2-py2.6.egg-info/-0755rm
public-0.0.0-py2.6.egg-info/-0755rm
pyasn1/-0755rm
pyasn1-0.0.12a-py2.6.egg-info/-0755rm
pyasn1-0.1.9-py2.6.egg/-0755rm
pyasn1-0.1.9.dist-info/-0755rm
pycparser/-0755rm
pycparser-2.14-py2.6.egg/-0755rm
pycparser-2.14-py2.6.egg-info/-0755rm
pygments/-0755rm
Pygments-1.1.1-py2.6.egg-info/-0755rm
pyparsing-2.0.3.dist-info/-0755rm
pyparsing-2.1.1.dist-info/-0755rm
python_cinderclient-1.4.0.dist-info/-0755rm
python_cinderclient-1.6.0.dist-info/-0755rm
python_dateutil-1.4.1-py2.6.egg-info/-0755rm
python_glanceclient-1.1.0.dist-info/-0755rm
python_glanceclient-2.0.0.dist-info/-0755rm
python_keystoneclient-1.7.1.dist-info/-0755rm
python_keystoneclient-2.3.1.dist-info/-0755rm
python_neutronclient-3.1.0.dist-info/-0755rm
python_novaclient-2.31.0.dist-info/-0755rm
python_novaclient-4.0.0.dist-info/-0755rm
python_openstackclient-1.7.1.dist-info/-0755rm
python_openstackclient-2.4.0.dist-info/-0755rm
python_swiftclient-2.6.0.dist-info/-0755rm
python_swiftclient-3.0.0.dist-info/-0755rm
pytz/-0755rm
pytz-2015.6.dist-info/-0755rm
pytz-2016.4.dist-info/-0755rm
pyzor-1.0.0-py2.6.egg/-0755rm
query_string-0.0.5-py2.6.egg-info/-0755rm
repoze/-0755rm
repoze.lru-0.6-py2.6.egg-info/-0755rm
request-0.0.5-py2.6.egg-info/-0755rm
requests/-0755rm
requests-2.7.0.dist-info/-0755rm
requests-2.9.1.dist-info/-0755rm
requestsexceptions/-0755rm
requestsexceptions-1.1.3.dist-info/-0755rm
rhn/-0755rm
rpmUtils/-0755rm
rsa/-0755rm
rsa-3.4.2-py2.6.egg-info/-0755rm
self-0.0.5-py2.6.egg-info/-0755rm
setools/-0755rm
setuptools/-0755rm
setuptools-20.10.1.dist-info/-0755rm
six-1.9.0.dist-info/-0755rm
six-1.10.0.dist-info/-0755rm
sos/-0755rm
stevedore/-0755rm
stevedore-1.8.0.dist-info/-0755rm
stevedore-1.12.0.dist-info/-0755rm
supervisor/-0755rm
swiftclient/-0755rm
tablib/-0755rm
tablib-0.10.0.dist-info/-0755rm
unicodecsv/-0755rm
unicodecsv-0.14.1-py2.6.egg-info/-0755rm
urlgrabber/-0755rm
urllib3/-0755rm
urllib3-1.10.2-py2.6.egg-info/-0755rm
urllib3-1.12.dist-info/-0755rm
urllib3-1.15.1.dist-info/-0755rm
warlock/-0755rm
warlock-1.1.0-py2.6.egg-info/-0755rm
warlock-1.2.0-py2.6.egg-info/-0755rm
yum/-0755rm
yumutils/-0755rm
appdirs.py223740755editdlrm
appdirs.pyc206650644editdlrm
argparse.py892140644editdlrm
argparse.pyc668150644editdlrm
argparse.pyo664910644editdlrm
chardet-2.0.1-py2.6.egg-info16050644editdlrm
clsudo.py129530644editdlrm
clsudo.pyc113920644editdlrm
clsudo.pyo113920644editdlrm
cmd2.py650690644editdlrm
cmd2.pyc650190644editdlrm
configobj-4.6.0-py2.6.egg-info3120644editdlrm
configobj.py864470644editdlrm
configobj.pyc664120644editdlrm
configobj.pyo664120644editdlrm
dbus_bindings.py330644editdlrm
dbus_bindings.pyc1850644editdlrm
dbus_bindings.pyo1850644editdlrm
decorator.py157750644editdlrm
decorator.pyc144850644editdlrm
dict.py22390644editdlrm
dnspython-1.11.1-py2.6.egg-info12800644editdlrm
easy-install.pth2760644editdlrm
easy_install.py1260644editdlrm
easy_install.pyc3170644editdlrm
easy_install.pyo3170644editdlrm
get.py3220644editdlrm
hwdata.py81420644editdlrm
hwdata.pyc62830644editdlrm
hwdata.pyo62830644editdlrm
iniparse-0.3.1-py2.6.egg-info10850644editdlrm
ipaddress.py796590644editdlrm
ipaddress.pyc759000644editdlrm
jsonpatch.py159460644editdlrm
jsonpatch.pyc174810644editdlrm
jsonpatch.pyo172770644editdlrm
jsonpointer-1.0-py2.6.egg-info3020644editdlrm
jsonpointer.py66100644editdlrm
jsonpointer.pyc63680644editdlrm
jsonpointer.pyo63680644editdlrm
libproxy.py43300644editdlrm
libproxy.pyc39900644editdlrm
libproxy.pyo39900644editdlrm
lprettytable.py238490755editdlrm
lprettytable.pyc196190644editdlrm
lprettytable.pyo194720644editdlrm
Markdown-2.0.1-py2.6.egg-info13400644editdlrm
monotonic.py53450644editdlrm
monotonic.pyc54790644editdlrm
ndg_httpsclient-0.4.0-py2.6-nspkg.pth2960644editdlrm
ordereddict-1.1-py2.6.egg-info1830644editdlrm
ordereddict-1.2-py2.6.egg-info1830644editdlrm
ordereddict.py42210644editdlrm
ordereddict.pyc44210644editdlrm
ordereddict.pyo44210644editdlrm
pciutils-2.3.5-py2.6.egg-info2420644editdlrm
pkg_resources.py881960644editdlrm
pkg_resources.pyc928750644editdlrm
pkg_resources.pyo928750644editdlrm
post.py2260644editdlrm
prettytable.py542040644editdlrm
prettytable.pyc522520644editdlrm
prettytable.pyo512660644editdlrm
public.py46350644editdlrm
pyOpenSSL-0.15.1-py2.6.egg2357360644editdlrm
pyOpenSSL-16.0.0-py2.6.egg943080644editdlrm
pyparsing.py1582560644editdlrm
pyparsing.pyc1578590644editdlrm
pytz-2010h-py2.6.egg-info225770644editdlrm
query_string.py8400644editdlrm
README1190644editdlrm
repoze.lru-0.6-py2.6-nspkg.pth3070644editdlrm
request.py2070644editdlrm
requests-2.6.0-py2.6.egg-info403570644editdlrm
rhnlib-2.5.22-py2.6.egg-info3390644editdlrm
secureio.py92220644editdlrm
secureio.pyc47210644editdlrm
secureio.pyo47210644editdlrm
self.py7280644editdlrm
setuptools-0.6c11-py2.6.egg-info1440644editdlrm
setuptools-18.3.2-py2.6.egg3590330755editdlrm
setuptools-20.9.0-py2.6.egg4728320644editdlrm
setuptools.pth340644editdlrm
site.py23620644editdlrm
site.pyc17710644editdlrm
site.pyo17710644editdlrm
six.py296640644editdlrm
six.pyc293300644editdlrm
six.pyo269110644editdlrm
supervisor-2.1-py2.6.egg-info7970644editdlrm
urlgrabber-3.9.1-py2.6.egg-info22850644editdlrm
validate.py467680644editdlrm
validate.pyc473840644editdlrm
validate.pyo473840644editdlrm
Edit: /usr/lib/python2.6/site-packages/lprettytable.py (23849B)
#!/usr/bin/env python # # PrettyTable 0.5 # Copyright (c) 2009, Luke Maurits # All rights reserved. # With contributions from: # * Chris Clark # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import cgi import copy import cPickle import sys FRAME = 0 ALL = 1 NONE = 2 class PrettyTable: def __init__(self, fields=None, caching=True, padding_width=1, left_padding=None, right_padding=None): """Return a new PrettyTable instance Arguments: fields - list or tuple of field names caching - boolean value to turn string caching on/off padding width - number of spaces between column lines and content""" # Data self.fields = [] if fields: self.set_field_names(fields) else: self.widths = [] self.aligns = [] self.set_padding_width(padding_width) self.rows = [] self.cache = {} self.html_cache = {} # Options self.hrules = FRAME self.caching = caching self.padding_width = padding_width self.left_padding = left_padding self.right_padding = right_padding self.vertical_char = "|" self.horizontal_char = "-" self.junction_char = "+" def __getslice__(self, i, j): """Return a new PrettyTable whose data rows are a slice of this one's Arguments: i - beginning slice index j - ending slice index""" newtable = copy.deepcopy(self) newtable.rows = self.rows[i:j] return newtable def __str__(self): return self.get_string() ############################## # ATTRIBUTE SETTERS # ############################## def set_field_names(self, fields): """Set the names of the fields Arguments: fields - list or tuple of field names""" # We *may* need to change the widths if this isn't the first time # setting the field names. This could certainly be done more # efficiently. if self.fields: self.widths = [len(field) for field in fields] for row in self.rows: for i in range(0,len(row)): if len(unicode(row[i])) > self.widths[i]: self.widths[i] = len(unicode(row[i])) else: self.widths = [len(field) for field in fields] self.fields = fields self.aligns = len(fields)*["c"] self.cache = {} self.html_cache = {} def set_field_align(self, fieldname, align): """Set the alignment of a field by its fieldname Arguments: fieldname - name of the field whose alignment is to be changed align - desired alignment - "l" for left, "c" for centre and "r" for right""" if fieldname not in self.fields: raise Exception("No field %s exists!" % fieldname) if align not in ["l","c","r"]: raise Exception("Alignment %s is invalid, use l, c or r!" % align) self.aligns[self.fields.index(fieldname)] = align self.cache = {} self.html_cache = {} def set_padding_width(self, padding_width): """Set the number of empty spaces between a column's edge and its content Arguments: padding_width - number of spaces, must be a positive integer""" try: assert int(padding_width) >= 0 except AssertionError: raise Exception("Invalid value for padding_width: %s!" % unicode(padding_width)) self.padding_width = padding_width self.cache = {} self.html_cache = {} def set_left_padding(self, left_padding): """Set the number of empty spaces between a column's left edge and its content Arguments: left_padding - number of spaces, must be a positive integer""" try: assert left_padding == None or int(left_padding) >= 0 except AssertionError: raise Exception("Invalid value for left_padding: %s!" % unicode(left_padding)) self.left_padding = left_padding self.cache = {} self.html_cache = {} def set_right_padding(self, right_padding): """Set the number of empty spaces between a column's right edge and its content Arguments: right_padding - number of spaces, must be a positive integer""" try: assert right_padding == None or int(right_padding) >= 0 except AssertionError: raise Exception("Invalid value for right_padding: %s!" % unicode(right_padding)) self.right_padding = right_padding self.cache = {} self.html_cache = {} def set_border_chars(self, vertical="|", horizontal="-", junction="+"): """Set the characters to use when drawing the table border Arguments: vertical - character used to draw a vertical line segment. Default is | horizontal - character used to draw a horizontal line segment. Default is - junction - character used to draw a line junction. Default is +""" if len(vertical) > 1 or len(horizontal) > 1 or len(junction) > 1: raise Exception("All border characters must be strings of length ONE!") self.vertical_char = vertical self.horizontal_char = horizontal self.junction_char = junction self.cache = {} ############################## # DATA INPUT METHODS # ############################## def add_row(self, row): """Add a row to the table Arguments: row - row of data, should be a list with as many elements as the table has fields""" if len(row) != len(self.fields): raise Exception("Row has incorrect number of values, (actual) %d!=%d (expected)" %(len(row),len(self.fields))) self.rows.append(row) for i in range(0,len(row)): if len(unicode(row[i])) > self.widths[i]: self.widths[i] = len(unicode(row[i])) self.html_cache = {} def add_column(self, fieldname, column, align="c"): """Add a column to the table. Arguments: fieldname - name of the field to contain the new column of data column - column of data, should be a list with as many elements as the table has rows align - desired alignment for this column - "l" for left, "c" for centre and "r" for right""" if len(self.rows) in (0, len(column)): if align not in ["l","c","r"]: raise Exception("Alignment %s is invalid, use l, c or r!" % align) self.fields.append(fieldname) self.widths.append(len(fieldname)) self.aligns.append(align) for i in range(0, len(column)): if len(self.rows) < i+1: self.rows.append([]) self.rows[i].append(column[i]) if len(unicode(column[i])) > self.widths[-1]: self.widths[-1] = len(unicode(column[i])) else: raise Exception("Column length %d does not match number of rows %d!" % (len(column), len(self.rows))) ############################## # MISC PRIVATE METHODS # ############################## def _get_sorted_rows(self, start, end, sortby, reversesort): # Sort rows using the "Decorate, Sort, Undecorate" (DSU) paradigm rows = copy.deepcopy(self.rows[start:end]) sortindex = self.fields.index(sortby) # Decorate rows = [[row[sortindex]]+row for row in rows] # Sort rows.sort(reverse=reversesort) # Undecorate rows = [row[1:] for row in rows] return rows def _get_paddings(self): if self.left_padding is not None: lpad = self.left_padding else: lpad = self.padding_width if self.right_padding is not None: rpad = self.right_padding else: rpad = self.padding_width return lpad, rpad ############################## # ASCII PRINT/STRING METHODS # ############################## def printt(self, start=0, end=None, fields=None, header=True, border=True, hrules=FRAME, sortby=None, reversesort=False): """Print table in current state to stdout. Arguments: start - index of first data row to include in output end - index of last data row to include in output PLUS ONE (list slice style) fields - names of fields (columns) to include sortby - name of field to sort rows by reversesort - True or False to sort in descending or ascending order border - should be True or False to print or not print borders hrules - controls printing of horizontal rules after each row. Allowed values: FRAME, ALL, NONE""" print self.get_string(start, end, fields, header, border, hrules, sortby, reversesort) def get_string(self, start=0, end=None, fields=None, header=True, border=True, hrules=FRAME, sortby=None, reversesort=False): """Return string representation of table in current state. Arguments: start - index of first data row to include in output end - index of last data row to include in output PLUS ONE (list slice style) fields - names of fields (columns) to include sortby - name of field to sort rows by reversesort - True or False to sort in descending or ascending order border - should be True or False to print or not print borders hrules - controls printing of horizontal rules after each row. Allowed values: FRAME, ALL, NONE""" if self.caching: key = cPickle.dumps((start, end, fields, header, border, hrules, sortby, reversesort)) if key in self.cache: return self.cache[key] hrule = hrules or self.hrules bits = [] if not self.fields: return "" if not header: # Recalculate widths - avoids tables with long field names but narrow data looking odd old_widths = self.widths[:] self.widths = [0]*len(self.fields) for row in self.rows: for i in range(0,len(row)): if len(unicode(row[i])) > self.widths[i]: self.widths[i] = len(unicode(row[i])) if header: bits.append(self._stringify_header(fields, border, hrules)) elif border and hrules != NONE: bits.append(self._stringify_hrule(fields, border)) if sortby: rows = self._get_sorted_rows(start, end, sortby, reversesort) else: rows = self.rows[start:end] for row in rows: bits.append(self._stringify_row(row, fields, border, hrule)) if border and not hrule: bits.append(self._stringify_hrule(fields, border)) string = "\n".join(bits) if self.caching: self.cache[key] = string if not header: # Restore previous widths self.widths = old_widths for row in self.rows: for i in range(0,len(row)): if len(unicode(row[i])) > self.widths[i]: self.widths[i] = len(unicode(row[i])) return string def _stringify_hrule(self, fields=None, border=True): if not border: return "" lpad, rpad = self._get_paddings() padding_width = lpad+rpad bits = [self.junction_char] for field, width in zip(self.fields, self.widths): if fields and field not in fields: continue bits.append((width+padding_width)*self.horizontal_char) bits.append(self.junction_char) return "".join(bits) def _stringify_header(self, fields=None, border=True, hrules=FRAME): lpad, rpad = self._get_paddings() bits = [] if border: if hrules != NONE: bits.append(self._stringify_hrule(fields, border)) bits.append("\n") bits.append(self.vertical_char) for field, width in zip(self.fields, self.widths): if fields and field not in fields: continue bits.append(" " * lpad + field.center(width) + " " * rpad) if border: bits.append(self.vertical_char) if border and hrules != NONE: bits.append("\n") bits.append(self._stringify_hrule(fields, border)) return "".join(bits) def _stringify_row(self, row, fields=None, border=True, hrule=False): lpad, rpad = self._get_paddings() bits = [] if border: bits.append(self.vertical_char) for field, value, width, align in zip(self.fields, row, self.widths, self.aligns): if fields and field not in fields: continue if align == "l": bits.append(" " * lpad + unicode(value).ljust(width) + " " * rpad) elif align == "r": bits.append(" " * lpad + unicode(value).rjust(width) + " " * rpad) else: bits.append(" " * lpad + unicode(value).center(width) + " " * rpad) if border: bits.append(self.vertical_char) if border and hrule == ALL: bits.append("\n") bits.append(self._stringify_hrule(fields, border)) return "".join(bits) ############################## # HTML PRINT/STRING METHODS # ############################## def print_html(self, start=0, end=None, fields=None, sortby=None, reversesort=False, format=True, header=True, border=True, hrules=FRAME, attributes=None): """Print HTML formatted version of table in current state to stdout. Arguments: start - index of first data row to include in output end - index of last data row to include in output PLUS ONE (list slice style) fields - names of fields (columns) to include sortby - name of field to sort rows by format - should be True or False to attempt to format alignmet, padding, etc. or not header - should be True or False to print a header showing field names or not border - should be True or False to print or not print borders hrules - include horizontal rule after each row attributes - dictionary of name/value pairs to include as HTML attributes in the tag""" print self.get_html_string(start, end, fields, sortby, reversesort, format, header, border, hrules, attributes) def get_html_string(self, start=0, end=None, fields=None, sortby=None, reversesort=False, format=True, header=True, border=True, hrules=FRAME, attributes=None): """Return string representation of HTML formatted version of table in current state. Arguments: start - index of first data row to include in output end - index of last data row to include in output PLUS ONE (list slice style) fields - names of fields (columns) to include sortby - name of border - should be True or False to print or not print borders format - should be True or False to attempt to format alignmet, padding, etc. or not header - should be True or False to print a header showing field names or not border - should be True or False to print or not print borders hrules - include horizontal rule after each row attributes - dictionary of name/value pairs to include as HTML attributes in the
tag""" if self.caching: key = cPickle.dumps((start, end, fields, format, header, border, hrules, sortby, reversesort, attributes)) if key in self.html_cache: return self.html_cache[key] if format: tmp_html_func=self._get_formatted_html_string else: tmp_html_func=self._get_simple_html_string string = tmp_html_func(start, end, fields, sortby, reversesort, header, border, hrules, attributes) if self.caching: self.html_cache[key] = string return string def _get_simple_html_string(self, start, end, fields, sortby, reversesort, header, border, hrules, attributes): bits = [] # Slow but works table_tag = '") for field in self.fields: if fields and field not in fields: continue bits.append(" " % cgi.escape(unicode(field))) bits.append(" ") # Data if sortby: rows = self._get_sorted_rows(stard, end, sortby, reversesort) else: rows = self.rows for row in self.rows: bits.append(" ") for field, datum in zip(self.fields, row): if fields and field not in fields: continue bits.append(" " % cgi.escape(unicode(datum))) bits.append(" ") bits.append("
%s
%s
") string = "\n".join(bits) return string def _get_formatted_html_string(self, start, end, fields, sortby, reversesort, header, border, hrules, attributes): bits = [] # Slow but works table_tag = '") for field in self.fields: if fields and field not in fields: continue bits.append(" %s" % (lpad, rpad, cgi.escape(unicode(field)))) bits.append(" ") # Data if sortby: rows = self._get_sorted_rows(start, end, sortby, reversesort) else: rows = self.rows for row in self.rows: bits.append(" ") for field, align, datum in zip(self.fields, self.aligns, row): if fields and field not in fields: continue if align == "l": bits.append(" %s" % (lpad, rpad, cgi.escape(unicode(datum)))) elif align == "r": bits.append(" %s" % (lpad, rpad, cgi.escape(unicode(datum)))) else: bits.append(" %s" % (lpad, rpad, cgi.escape(unicode(datum)))) bits.append(" ") bits.append("") string = "\n".join(bits) return string def main(): x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"]) x.set_field_align("City name", "l") # Left align city names x.add_row(["Adelaide",1295, 1158259, 600.5]) x.add_row(["Brisbane",5905, 1857594, 1146.4]) x.add_row(["Darwin", 112, 120900, 1714.7]) x.add_row(["Hobart", 1357, 205556, 619.5]) x.add_row(["Sydney", 2058, 4336374, 1214.8]) x.add_row(["Melbourne", 1566, 3806092, 646.9]) x.add_row(["Perth", 5386, 1554769, 869.4]) print x if len(sys.argv) > 1 and sys.argv[1] == "test": # This "test suite" is hideous and provides poor, arbitrary coverage. # I'll replace it with some proper unit tests Sometime Soon (TM). # Promise. print "Testing field subset selection:" x.printt(fields=["City name","Population"]) print "Testing row subset selection:" x.printt(start=2, end=5) print "Testing hrules settings:" print "FRAME:" x.printt(hrules=FRAME) print "ALL:" x.printt(hrules=ALL) print "NONE:" x.printt(hrules=NONE) print "Testing lack of headers:" x.printt(header=False) x.printt(header=False, border=False) print "Testing lack of borders:" x.printt(border=False) print "Testing sorting:" x.printt(sortby="City name") x.printt(sortby="Annual Rainfall") x.printt(sortby="Annual Rainfall", reversesort=True) print "Testing padding parameter:" x.set_padding_width(0) x.printt() x.set_padding_width(5) x.printt() x.set_left_padding(5) x.set_right_padding(0) x.printt() x.set_right_padding(20) x.printt() x.set_left_padding(None) x.set_right_padding(None) x.set_padding_width(2) print "Testing changing characters" x.set_border_chars("*","*","*") x.printt() x.set_border_chars("!","~","o") x.printt() x.set_border_chars("|","-","+") print "Testing everything at once:" x.printt(start=2, end=5, fields=["City name","Population"], border=False, hrules=True) print "Rebuilding by columns:" x = PrettyTable() x.add_column("City name", ["Adelaide", "Brisbane", "Darwin", "Hobart", "Sydney", "Melbourne", "Perth"]) x.add_column("Area", [1295, 5905, 112, 1357, 2058, 1566, 5385]) x.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092, 1554769]) x.add_column("Annual Rainfall", [600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9, 869.4]) x.printt() print "Testing HTML:" x.print_html() x.print_html(border=False) x.print_html(border=True) x.print_html(format=False) x.print_html(attributes={"name": "table", "id": "table"}) if __name__ == "__main__": main()