File: reducemodules.py

package info (click to toggle)
pgi 0.9.6.3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,792 kB
  • ctags: 801
  • sloc: sh: 4,540; python: 3,069; xml: 1,895; makefile: 1,727; perl: 1,080; ansic: 647; lisp: 151
file content (63 lines) | stat: -rwxr-xr-x 1,684 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python

# $Progeny: reducemodules.py,v 1.4 2002/02/04 23:36:25 jlicquia Exp $

# reducemodules.py - reduce a module list to fit in a given amount of
# space
#
# Copyright (c) 2002 Progeny Linux Systems, Inc.
#
# License: GPL
# 
# Usage: reducemodules.py <kernel-version> <size>
#
# This script takes a priority-sorted list of modules on stdin.  It
# calculates the dependencies on each module, adds their sizes to a
# running size total, and outputs the module's path (and its
# dependencies) on stdout.  Once the running size exceeds the size
# passed on the command line, stop.

import sys
import os
import string

tooldir = os.environ["TOOLS"]
kernel = sys.argv[1]
max_size = int(sys.argv[2])
total_size = 0
mod_list_read = []

input = sys.stdin
output = sys.stdout

def get_module_paths(module):
    global tooldir
    global kernel
    global mod_list_read
    global input

    mod_list = []
    modpaths = os.popen("sh %s/modtofile.sh %s %s" % (tooldir, kernel, module))
    modules_size = 0
    for line in modpaths.readlines():
        module_path = string.strip(line)
        if module_path in mod_list_read:
            continue
        if not os.path.exists(module_path):
            continue

        mod_size = (os.stat(module_path))[6]
        modules_size = modules_size + mod_size
        mod_list.append(module_path)

    return (modules_size, mod_list)

for module in input.readlines():
    (mod_size, mod_list) = get_module_paths(string.strip(module))
    if total_size + mod_size > max_size:
        continue

    total_size = total_size + mod_size
    mod_list_read.extend(mod_list)
    for mod_path in mod_list:
        output.write(mod_path + "\n")