File: kdeps

package info (click to toggle)
alsa-driver 1.0.13-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 20,108 kB
  • ctags: 50,477
  • sloc: ansic: 319,881; sh: 32,930; makefile: 2,015; python: 1,527; perl: 1,316; xml: 896; awk: 66
file content (152 lines) | stat: -rw-r--r-- 3,242 bytes parent folder | download | duplicates (5)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#! /usr/bin/python
#  -*- Python -*-

"""ALSA toplevel module dependency update utility

This script allows synchronization of ALSA toplevel module dependency
stored in scripts/Modules.dep using mod-deps tool.

This tool is intended mainly for internal use of Jaroslav Kysela.

Usage:
	%(PROGRAM)s [options] command

Where options is:

	-h
	--help
		Print this help

	-C <path>
	--cvsroot=<path>
		Set root of ALSA CVS repository

"""

import os
import sys
import string
import re
import time
import dircache
import getopt

# define for documentation
PROGRAM = sys.argv[0]

# define working directories
CVSROOT = '~/alsa'
BKROOT = '~/linux/work'

# exclude some files or directories
ALSA_EXCLUDE_DIR = ['/', '/core/ioctl32', '/core/oss', '/core/seq/oss', '/scripts', '/oss']

# dependency block identifier
DEP_ID = ['# Toplevel Module Dependency\n',
	  '# Module Dependency\n']

def usage(code, msg=''):
	print __doc__ % globals()
	if msg:
		print msg
	sys.exit(code)

def get_cvs_root():
	return os.path.expanduser(CVSROOT + '/alsa-kernel')

def print_file(fp, lines):
	for line in lines:
		fp.write(line)

def do_diff(file):
	path, file = os.path.split(file)
	os.chdir(path)
	cmd = 'cvs diff -uN %s' % file
	fp = os.popen(cmd)
	lines = fp.readlines()
	fp.close()
	print_file(sys.stdout, lines)

def update_makefile(base, file):
	fp = open(base + file)
	lines = fp.readlines()
	fp.close()

	fidx = -1
	idx = 0
	while idx < len(lines):
		# print lines[idx]
		if DEP_ID.count(lines[idx]) > 0:
			del lines[idx]
			while re.compile('[' + string.letters + ']+').search(lines[idx]):
				del lines[idx]
			fidx = idx
			break
		idx = idx + 1

	if fidx < 0:
		print 'File %s does not contain dependency section' % file
		return

	xpath, xfile = os.path.split(file)
	cmd = get_cvs_root() + '/scripts/mod-deps --makefile --dir %s ' % ('linux/sound' + xpath) + \
	      get_cvs_root() + '/scripts/Modules.dep'
	fp = os.popen(cmd)
	nlines = fp.readlines()
	fp.close()

	fp = open(base + file + '.new', 'w')
	print_file(fp, lines[0:idx])
	print_file(fp, nlines)
	print_file(fp, lines[idx:])
	fp.close()

	os.rename(base + file + '.new', base + file)

	# do_diff(base + file)

def update_makefiles(base, dir):
	# Read all entries
	fp = open(base + dir + 'CVS/Entries')
	entries = fp.readlines()
	fp.close()

	# Process Makefile entries
	if not ALSA_EXCLUDE_DIR.count(dir) and not ALSA_EXCLUDE_DIR.count(dir[0:-1]):
		print dir[0:-1]
		for e in entries:
			try:
				flags, name, rev, time, unk1, unk2 = string.split(e, '/')
				if string.count(flags, 'D') <= 0 and name == 'Makefile':
					update_makefile(base, dir + name)
			except ValueError, msg:
				pass

	# Process directory entries
	for e in entries:
		try:
			flags, name, rev, time, unk1, unk2 = string.split(e, '/')
			if string.count(flags, 'D') > 0:
				update_makefiles(base, dir + name + '/')
		except ValueError, msg:
			pass

def main():
	try:
		opts, args = getopt.getopt(sys.argv[1:], 'hC:',
					   ['cvsroot=', 'help']);
	except getopt.error, msg:
		usage(1, msg)

	# parse the options
	for opt, arg in opts:
		if opt in ('-h', '--help'):
			usage(0)
		elif opt == '--cvsroot':
			CVSROOT = arg

	update_makefiles(get_cvs_root(), '/')

if __name__ == '__main__':
	main()
	sys.exit(0)