source: trunk/pxeconfig/hexls @ 17

Last change on this file since 17 was 17, checked in by sscpbas, 22 years ago

Fixed a bug in hexls. The regexp to determine if a filename is PXE
boot file was wrong.

File size: 1.6 KB
RevLine 
[3]1#! /usr/bin/env python
[14]2# Copyright (C) 2002
[6]3#
[14]4# This file is part of the pxeconfig utils
[6]5#
[14]6# This program is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any
9# later version.
[6]10#
[14]11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
[6]15#
[14]16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19#
[3]20'''
21hexls.py - Lists directory contents, but converts the hexadecimal IP numbers
22to dotted decimal notation (so you can at least see what you're doing..!!)
23
24Author: Walter de Jong <walter@sara.nl>
25Date:   January 2002
26
27CVS info
[17]28  $Date: 2002/09/10 14:10:47 $
29  $Revision: 1.4 $
[3]30'''
31
32import os
33import string
34import re
35
36def hexls(path):
37        '''list directory, convert hexadecimal to dotted decimal'''
38
[17]39        regexp = re.compile('[' + string.hexdigits + ']{8}' )
[3]40        for f in os.listdir(path):
41                if regexp.match(f) and len(f) == 8:
42                        digit1 = string.atoi(f[:2], 16)
43                        digit2 = string.atoi(f[2:4], 16)
44                        digit3 = string.atoi(f[4:6], 16)
45                        digit4 = string.atoi(f[6:], 16)
46
47                        print '%s => %d.%d.%d.%d' % (f, digit1, digit2, digit3, digit4)
48                else:
49                        if f[0] != '.':
50                                print f
51
52
53if __name__ == '__main__':
54        import sys
55
56        if len(sys.argv) > 1:
57                for dir in sys.argv[1:]:
58                        hexls(dir)
59        else:
60                hexls('.')
61
62# EOB
63
Note: See TracBrowser for help on using the repository browser.