r3514 - trunk/scripts

Andres Salomon dilinger at costa.debian.org
Sat Jul 16 00:27:17 UTC 2005


Author: dilinger
Date: 2005-07-16 00:27:16 +0000 (Sat, 16 Jul 2005)
New Revision: 3514

Modified:
   trunk/scripts/split-config
Log:
committing what i have in case my laptop's drive decides to eat itself or
something equally as stupid.


Modified: trunk/scripts/split-config
===================================================================
--- trunk/scripts/split-config	2005-07-16 00:11:13 UTC (rev 3513)
+++ trunk/scripts/split-config	2005-07-16 00:27:16 UTC (rev 3514)
@@ -50,10 +50,10 @@
 
 def parse_config(file, kconf)
 	File.open(file).each { |line|
-		if line =~ /^(CONFIG_\w+)=(\w)$/
-			kconf[$1.upcase] = $2.downcase
+		if line =~ /^(CONFIG_\w+)=(.+)$/
+			kconf[$1] = $2
 		elsif line =~ /^\s*#\s*(CONFIG_\w+) is not set\s*$/
-			kconf[$1.upcase] = 'n'
+			kconf[$1] = 'n'
 		end
 	}
 	kconf
@@ -61,26 +61,23 @@
 
 def configline(key, val)
 	if val == 'n'
-		"# #{key.upcase} is not set\n"
+		"# #{key} is not set\n"
 	else
-		"#{key.upcase}=#{val.downcase}\n"
+		"#{key}=#{val}\n"
 	end
 end
 
 def collect(path, archdirs, flavour)
 	kconf = {}
 	if File.exists?("#{path}/config")
-		puts "parsing #{path}/config"
 		kconf = parse_config("#{path}/config", kconf)
 	end
 	archdirs.split(Regexp.new('/+')).each { |piece|
 		path += piece + '/'
 		if File.exists?("#{path}/config")
-		puts "parsing #{path}/config"
 			kconf = parse_config("#{path}/config", kconf)
 		end
 	}
-		puts "parsing #{path}/config.#{flavour}"
 	parse_config("#{path}/config.#{flavour}", kconf)
 end
 
@@ -102,6 +99,137 @@
 	[ added, removed, changed ]
 end
 
+def prompt_user
+	slong = OPTIONS['subarch'] ? 'per-[S]ubarch, ' : ''
+	sshort = OPTIONS['subarch'] ? 'S' : ''
+	while true
+		print 'Do you want to make this change [G]lobal, per-[A]rch, ' + slong + 'or per-[F]lavour? [GA' + sshort + 'F] '
+		answer = $stdin.gets.chomp.downcase
+		return answer if answer == 'g' || answer == 'a' || answer == 'f'
+		return answer if answer == 's' && OPTIONS['subarch']
+		puts 'Invalid response, please try again.'
+	end
+end
+
+def strip_key(file, key)
+	return unless File.exists?(file)
+
+	lines = File.open(file).readlines
+	remaining = lines - lines.grep(/^#*\s*#{key}[\s=]/)
+	File.open(file, 'w') { |f|
+		remaining.each { |l|
+			f << l
+		}
+	}
+end
+
+def archdirs
+	if $archdirs.nil?
+		base = OPTIONS['dir']
+		$archdirs = Dir.open(base) { |d|
+			d.find_all { |f|
+				File.directory?("#{base}/#{f}") && f !~ /^\./
+			}
+		}
+		#$archdirs = $archdirs - $archdirs.grep(/^\./)
+		$archdirs.collect! { |x| "#{base}/#{x}" }
+	end
+	$archdirs
+end
+
+def subarchdirs
+	if $subarchdirs.nil?
+		$subarchdir = []
+		archdirs().each { |d|
+			sa = Dir.open(d) { |e|
+				e.find_all { |f|
+					File.directory?("#{d}/#{f}") && f !~ /^\./
+				}
+			}
+			sa.collect! { |x| "#{d}/#{x}" }
+			$subarchdirs.concat(sa)
+		}
+	end
+	$subarchdirs
+end
+
+def flavourfiles
+	if $flavourfiles.nil?
+		$flavourfiles = []
+		dirs = archdirs().clone.delete_if { |d|
+			b.find { |e|
+				# if the subarchdir contains the archdir, nuke
+				# the archdir from the list.
+				e.slice(d + '/')
+			}
+		}
+		dirs.concat(subarchdirs())
+		dirs.each { |d|
+			$flavourfiles.concat(Dir.glob("#{d}/config.*"))
+		}
+	end
+	$flavourfiles
+end
+
+def affected_files(answer)
+	files = []
+	base = OPTIONS['dir']
+	case answer
+		when 'g'
+			files << "#{base}/config"
+			files.concat(archdirs().collect { |x| "#{x}/config" })
+			files.concat(subarchdirs().collect { |x| "#{x}/config" })
+			files.concat(flavourfiles())
+		when 'a'
+			files << "#{base}/#{OPTIONS['arch']}/config"
+			files.concat(subarchdirs().collect { |x| "#{x}/config" })
+			files.concat(flavourfiles())
+		when 's'
+			files << "#{base}/#{OPTIONS['arch']}/#{OPTIONS['subarch']}/config"
+			files.concat(flavourfiles())
+		when 'f'
+			if OPTIONS['subarch']
+				files << "#{base}/#{OPTIONS['arch']}/#{OPTIONS['subarch']}/config.#{OPTIONS['flavour']}"
+			else
+				files << "#{base}/#{OPTIONS['arch']}/config.#{OPTIONS['flavour']}"
+			end
+	end
+	files
+end
+
+def add_option(key, val)
+	puts "\n#{key}=#{val} has been added."
+	answer = prompt_user()
+	files = affected_files(answer)
+	files.each { |f|
+		strip_key(f, key)
+	}
+	File.open(files[0], 'a') { |f|
+			f << configline(key, val)
+	}
+end
+
+def remove_option(key, val)
+	puts "\n#{key}=#{val} has been removed."
+	answer = prompt_user()
+	files = affected_files(answer)
+	files.each { |f|
+		strip_key(f, key)
+	}
+end
+
+def update_option(key, oldval, newval)
+	puts "\n#{key} has been changed from '#{oldval}' to '#{newval}'."
+	answer = prompt_user()
+	files = affected_files(answer)
+	files.each { |f|
+		strip_key(f, key)
+	}
+	File.open(files[0], 'a') { |f|
+		f << configline(key, newval)
+	}
+end
+
 def usage(errno)
 	s = errno == 0 ? $stdout : $stderr
 	s.puts "Usage: #{$0} [options] <config dir> <flavour>\n"
@@ -147,6 +275,11 @@
 	else
 		usage(1)
 	end
+
+	unless File.exists?('scripts/kconfig/conf.c')
+		$stderr.puts "#{$0}: script must be run from the top level of a kernel tree!"
+		exit(1)
+	end
 rescue => e
 	usage(1)
 end
@@ -158,13 +291,16 @@
 newconf = parse_config('.config', {})
 added, removed, changed = kdiff(kconf, newconf)
 
-puts "added:"
-puts "\t" + [added].flatten.join(', ')
+[added].flatten.each { |key|
+	add_option(key, newconf[key]) unless key.nil?
+}
 
-puts "\nremoved:"
-puts "\t" + [removed].flatten.join(', ')
+[removed].flatten.each { |key|
+	remove_option(key, kconf[key]) unless key.nil?
+}
 
-puts "\nchanged:"
-puts "\t" + [changed].flatten.join(', ')
+[changed].flatten.each { |key|
+	update_option(key, kconf[key], newconf[key]) unless key.nil?
+}
 
 exit(0)




More information about the Kernel-svn-changes mailing list