Author: | Dave Kuhlman |
---|---|
Address: | dkuhlman@rexx.com http://www.rexx.com/~dkuhlman |
Revision: | 1.0a |
Date: | July 24, 2003 |
Copyright: | Copyright (c) 2003 Dave Kuhlman. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Abstract
This document describes zip-ls.py which is an enhanced listing program for Zip files. zip-ls is written in Python.
zip-ls lists the contents of Zip files. It provides controls over which columns are displayed, whether totals are displayed, sorting on various columns, etc. zip-ls uses a configuration file (~/.zip-lsrc), which enables the user to specify default settings for command-line flags.
zip-ls is written in Python, making it very customizable.
You can find it at http://www.rexx.com/~dkuhlman/zip-ls.zip.
Here is the usage information from zip-ls:
Usage: python zip-ls.py [options] <zip_file_name> Options: -h, --help Display this help message. -s, --sort Sort files by x, where x is one of: file_name or fn (default) date_time or dt file_size or fs compress_size or cs -c, --columns Columns to display. Values: s Short; file names only. m Medium (default) l Long v Verbose -r, --reverse Reverse sort -t, --totals Print column totals. Examples: python zip-ls.py stuff.zip python zip-ls.py -s file_name stuff.zip python zip-ls.py --sort=date_time --reverse stuff.zip python zip-ls.py -s compress_size -c m stuff.zip
sort --- Possible values:
columns --- Possible values:
reverse --- If present, the listing is sorted in reverse order.
totals --- If present, include totals.
zip-ls looks for a configuration file named .zip-lsrc in your home directory and, if found, uses the values specified in that file as defaults.
This configuration file follows the format used by ConfigParser from the Python standard library. The only section is "general", which contains the following names:
See the command line documentation for description of these options and their possible values.
Here is a sample configuration file:
[general] columns=l #reverse=0 totals=1 #sort=file_name #sort=date_time
Here are a few comments that might be of help if you feel the need to modify the implementation of zip-ls.
Function formatLine formats a line for each file in the listed archive. Change this function to change the format of the display. This function contains a section (in an if statement) for each option to the columns command line flag. So, for example, you should change the section under:
elif columns == 'l':
in order to change the format when the flag "-c l" is used.
Change function formatDate in order to modify the format of the date.
Change function formatTotalLine in order to modify the format of the totals line. It also contains sections for each of the values for the columns flag.
If you add new command line flags, you will want to change function getDefaultOptions, which reads defaults values from the zip-ls configuration file.
ConfigParser -- Configuration file parser for Python.
zipfile -- Work with ZIP archives in Python.