ia64/xen-unstable

changeset 968:bc77f7e0e1ec

bitkeeper revision 1.622 (3fbd4bebsTJdb-aVkXDUuIpXoNZ5DA)

setup.py, Makefile:
A XenoUtil module containing handy helpers for creating control scripts.
XenoUtil.py:
new file
author kaf24@scramble.cl.cam.ac.uk
date Thu Nov 20 23:19:07 2003 +0000 (2003-11-20)
parents a0a36d4ac8de
children 65538950807b
files .rootkeys tools/xc/py/Makefile tools/xc/py/XenoUtil.py tools/xc/py/setup.py
line diff
     1.1 --- a/.rootkeys	Thu Nov 20 22:00:03 2003 +0000
     1.2 +++ b/.rootkeys	Thu Nov 20 23:19:07 2003 +0000
     1.3 @@ -213,6 +213,7 @@ 3fbba6dc38q-ioRlwSR_quw4G3qUeQ tools/xc/
     1.4  3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/xc/lib/rpm.spec
     1.5  3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/xc/lib/xc.h
     1.6  3fbd0a3dTwnDcfdw0-v46dPbX98zDw tools/xc/py/Makefile
     1.7 +3fbd4bd6GtGwZGxYUJPOheYIR7bPaA tools/xc/py/XenoUtil.py
     1.8  3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/xc/py/setup.py
     1.9  3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/xc/py/xc_py.c
    1.10  3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING
     2.1 --- a/tools/xc/py/Makefile	Thu Nov 20 22:00:03 2003 +0000
     2.2 +++ b/tools/xc/py/Makefile	Thu Nov 20 23:19:07 2003 +0000
     2.3 @@ -6,4 +6,4 @@ install:
     2.4  	python setup.py install
     2.5  
     2.6  clean:
     2.7 -	rm -rf build
     2.8 +	rm -rf build *.pyc *.pyo *.o *.a *~
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/xc/py/XenoUtil.py	Thu Nov 20 23:19:07 2003 +0000
     3.3 @@ -0,0 +1,66 @@
     3.4 +
     3.5 +import string, re, os
     3.6 +
     3.7 +def blkdev_name_to_number(name):
     3.8 +    """Take the given textual block-device name (e.g., '/dev/sda1',
     3.9 +    'hda') and return the device number used by the OS. """
    3.10 +
    3.11 +    if not re.match( '/dev/', name ):
    3.12 +        name = '/dev/' + name
    3.13 +        
    3.14 +    fd = os.popen( '/bin/ls -lL ' + name + ' 2>/dev/null' )
    3.15 +    line = fd.readline()
    3.16 +
    3.17 +    #brw-rw----    1 root     mail       8,   3 Aug 30  2001 /dev/sda3
    3.18 +    m = re.search( '^b\S+\s+\d+\s+\S+\s+\S+\s+(\d+),\s+(\d+)\s+\S+\s+\d+' +
    3.19 +                   '\s+\d+\s+' + name + '$', line )
    3.20 +
    3.21 +    if m:
    3.22 +        # hack -- we just assume device minors are 8 bits
    3.23 +        return (string.atol(m.group(1)) << 8) + string.atol(m.group(2))
    3.24 +    return None
    3.25 +
    3.26 +
    3.27 +# lookup_blkdev_partn_info( '/dev/sda3' )
    3.28 +def lookup_blkdev_partn_info(partition):
    3.29 +    """Take the given block-device name (e.g., '/dev/sda1', 'hda')
    3.30 +    and return a information tuple ( partn-dev, disc-dev, start-sect,
    3.31 +    nr-sects, type )
    3.32 +        partn-dev:  Device number of the given partition
    3.33 +        disc-dev:   Device number of the disc containing the partition
    3.34 +        start-sect: Index of first sector of the partition
    3.35 +        nr-sects:   Number of sectors comprising this partition
    3.36 +        type:       'Disk' or identifying name for partition type
    3.37 +    """
    3.38 +
    3.39 +    if not re.match( '/dev/', partition ):
    3.40 +        partition = '/dev/' + partition
    3.41 +
    3.42 +    drive = re.split( '[0-9]', partition )[0]
    3.43 +
    3.44 +    if drive == partition:
    3.45 +        fd = os.popen( '/sbin/sfdisk -s ' + drive + ' 2>/dev/null' )
    3.46 +        line = fd.readline()
    3.47 +        if line:
    3.48 +            return ( blkdev_name_to_number(drive),
    3.49 +                     blkdev_name_to_number(drive),
    3.50 +                     0,
    3.51 +                     string.atol(line) * 2,
    3.52 +                     'Disk' )
    3.53 +        return None
    3.54 +
    3.55 +    # determine position on disk
    3.56 +    fd = os.popen( '/sbin/sfdisk -d ' + drive + ' 2>/dev/null' )
    3.57 +
    3.58 +    #['/dev/sda3 : start= 16948575, size=16836120, Id=83, bootable\012']
    3.59 +    lines = fd.readlines()
    3.60 +    for line in lines:
    3.61 +        m = re.search( '^' + partition + '\s*: start=\s*([0-9]+), ' +
    3.62 +                       'size=\s*([0-9]+), Id=\s*(\S+).*$', line)
    3.63 +        if m:
    3.64 +            return ( blkdev_name_to_number(partition),
    3.65 +                     blkdev_name_to_number(drive),
    3.66 +                     string.atol(m.group(1)),
    3.67 +                     string.atol(m.group(2)),
    3.68 +                     m.group(3) )
    3.69 +    return None
     4.1 --- a/tools/xc/py/setup.py	Thu Nov 20 22:00:03 2003 +0000
     4.2 +++ b/tools/xc/py/setup.py	Thu Nov 20 23:19:07 2003 +0000
     4.3 @@ -14,3 +14,5 @@ module.extra_objects = ["../lib/libxc.a"
     4.4  module.libraries     = ["z"]
     4.5  
     4.6  setup(name = "Xc", version = "1.0", ext_modules = [module])
     4.7 +
     4.8 +setup(name = "XenoUtil", version = "1.0", py_modules = ["XenoUtil"])