diff options
author | Karel Kočí <cynerd@email.cz> | 2015-08-28 17:45:26 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2015-08-28 17:45:26 +0200 |
commit | 21d73b4159d65ec1279ed603bc67f32fb8346f37 (patch) | |
tree | 5cc41ba8fb8e1663c620364d7e0f6ccfe5a02022 /scripts | |
parent | 2fc5841f903699c04b31a5fef2561639e03fc4dd (diff) | |
download | linux-conf-perf-21d73b4159d65ec1279ed603bc67f32fb8346f37.tar.gz linux-conf-perf-21d73b4159d65ec1279ed603bc67f32fb8346f37.tar.bz2 linux-conf-perf-21d73b4159d65ec1279ed603bc67f32fb8346f37.zip |
Reimplement fromfolder script
Removing configuration options from configuration file according to
definition folder. New implementation allows to specify required
configuration options that shouldn't be removed in any case.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/from_folder | 10 | ||||
-rwxr-xr-x | scripts/fromfolder.py | 71 |
2 files changed, 71 insertions, 10 deletions
diff --git a/scripts/from_folder b/scripts/from_folder deleted file mode 100755 index 8801a48..0000000 --- a/scripts/from_folder +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -FOLDER=linux/kernel - -CONF=`find $FOLDER -name Kconfig | xargs grep -e ^config | cut -d ' ' -f2` - -REG=`echo $CONF | tr " " "|" | sed 's/^/\(/' | sed 's/$/\)/'` - -#egrep "$REG" $1 -egrep -v "$REG" $1 > $2 diff --git a/scripts/fromfolder.py b/scripts/fromfolder.py new file mode 100755 index 0000000..d5bb2b3 --- /dev/null +++ b/scripts/fromfolder.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +import os +import sys +import re +from conf import conf +from conf import sf + +def loadfromKconfig(file): + found = set() + for ln in open(file): + if re.search('^config', ln): + name = ln[7:].rstrip() + found.add(name) + return found + +def loadfromfolder(folder): + found = set() + for l in os.listdir(folder): + if os.path.isdir(folder + '/' + l): + found = found | loadfromfolder(folder + '/' + l) + elif os.path.isfile(folder + '/' + l) and re.search('Kconfig', l): + found = found | loadfromKconfig(folder + '/' + l) + return found + +def removefrom(file, outfile, removelist): + alllines = [] + for ln in open(file): + alllines.append(ln.rstrip()) + + for rl in removelist: + for ln in alllines: + if re.search('^CONFIG_' + rl + '=', ln): + print('removing ' + ln) + alllines.remove(ln) + + with open(outfile, 'w') as f: + for ln in alllines: + f.write(ln + '\n') + +################################################################################# + +# TODO propper argument parsing +if __name__ == '__main__': + folder = sys.argv[1] + inputfile = sys.argv[2] + outputfile = sys.argv[3] + if not len(sys.argv) < 5: + exceptfile = sys.argv[4] + + exceptconf = set() + if os.path.isfile(exceptfile): + for ln in open(exceptfile): + lns = ln.rstrip() + if lns: + exceptconf.add(lns) + + rem = loadfromfolder(sf(conf.linux_sources + '/' + folder)) + + for ec in exceptconf: + rrlist = [] + for r in rem: + if re.match(ec, r): + print('except ' + r) + rrlist.append(r) + for r in rrlist: + try: + rem.remove(r) + except KeyError: + pass + + removefrom(inputfile, outputfile, rem) |