find_compatibles_dts: Convert to a python class to increase performances
Signed-off-by: Maxime Chretien <maxime.chretien@bootlin.com>
This commit is contained in:
parent
2162fe88e6
commit
e2adc03d1e
3 changed files with 44 additions and 83 deletions
|
|
@ -18,77 +18,48 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.
|
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from sys import argv
|
|
||||||
import re
|
import re
|
||||||
import os
|
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
import query
|
from query import decode
|
||||||
|
|
||||||
usage_message = ("USAGE: find_compatible_dts.py <file> <family>\n"
|
class FindCompatibleDTS:
|
||||||
"file : The file you want to search in\n"
|
def __init__(self):
|
||||||
"family : The type of file (C for .c/.cpp/.h/...\n"
|
# Compile regexes
|
||||||
" D for .dts/.dtsi\n"
|
self.regex_c = re.compile("\s*{*\s*\.compatible\s*=\s*\"(.+?)\"")
|
||||||
" B for bindings docs files)")
|
self.regex_dts1 = re.compile("\s*compatible")
|
||||||
|
self.regex_dts2 = re.compile("\"(.+?)\"")
|
||||||
|
self.regex_bindings = re.compile("([\w-]+,?[\w-]+)")
|
||||||
|
|
||||||
ident_list = ""
|
def parse_c(self, content):
|
||||||
|
return self.regex_c.findall(content)
|
||||||
|
|
||||||
# Compile regexes
|
def parse_dts(self, content):
|
||||||
regex_c = re.compile("\s*{*\s*\.compatible\s*=\s*\"(.+?)\"")
|
ret = []
|
||||||
regex_dts1 = re.compile("\s*compatible")
|
if self.regex_dts1.match(content) != None:
|
||||||
regex_dts2 = re.compile("\"(.+?)\"")
|
ret = self.regex_dts2.findall(content)
|
||||||
regex_bindings = re.compile("([\w-]+,?[\w-]+)")
|
return ret
|
||||||
|
|
||||||
|
def parse_bindings(self, content):
|
||||||
|
# There are a lot of wrong results
|
||||||
|
# but we don't apply that to a lot of files
|
||||||
|
# so it should be fine
|
||||||
|
return self.regex_bindings.findall(content)
|
||||||
|
|
||||||
def parse_c(content):
|
def run(self, file_lines, family):
|
||||||
return regex_c.findall(content)
|
ident_list = ""
|
||||||
|
|
||||||
def parse_dts(content):
|
# Iterate though lines and search for idents
|
||||||
ret = []
|
for num, line in enumerate(file_lines, 1):
|
||||||
if regex_dts1.match(content) != None:
|
line = query.decode(line)
|
||||||
ret = regex_dts2.findall(content)
|
if family == 'C':
|
||||||
return ret
|
ret = self.parse_c(line)
|
||||||
|
elif family == 'D':
|
||||||
|
ret = self.parse_dts(line)
|
||||||
|
elif family == 'B':
|
||||||
|
ret = self.parse_bindings(line)
|
||||||
|
|
||||||
def parse_bindings(content):
|
for i in range(len(ret)):
|
||||||
# There are a lot of wrong results
|
ident_list += str(parse.quote(ret[i])) + ' ' + str(num) + '\n'
|
||||||
# but we don't apply that to a lot of files
|
|
||||||
# so it should be fine
|
|
||||||
return regex_bindings.findall(content)
|
|
||||||
|
|
||||||
|
return ident_list
|
||||||
|
|
||||||
# Main
|
|
||||||
# Test and get args
|
|
||||||
if len(argv) < 3:
|
|
||||||
print("ERROR: Missing arguments !\n" + usage_message)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
filename = argv[1]
|
|
||||||
family = argv[2]
|
|
||||||
|
|
||||||
# Make sure it's an accepted family
|
|
||||||
if not family in ['C', 'D', 'B']:
|
|
||||||
print("ERROR: Unknown family !\n" + usage_message)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# Make sure file exists
|
|
||||||
try:
|
|
||||||
f = open(filename, 'rb')
|
|
||||||
except IOError:
|
|
||||||
print("ERROR: File doesn't exist !\n" + usage_message)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# Iterate though lines and search for idents
|
|
||||||
for num, line in enumerate(f, 1):
|
|
||||||
line = query.decode(line)
|
|
||||||
if family == 'C':
|
|
||||||
ret = parse_c(line)
|
|
||||||
elif family == 'D':
|
|
||||||
ret = parse_dts(line)
|
|
||||||
elif family == 'B':
|
|
||||||
ret = parse_bindings(line)
|
|
||||||
|
|
||||||
for i in range(len(ret)):
|
|
||||||
ident_list += str(parse.quote(ret[i])) + ' ' + str(num) + '\n'
|
|
||||||
|
|
||||||
# Print the list and exit
|
|
||||||
print(ident_list, end='')
|
|
||||||
exit(0)
|
|
||||||
|
|
|
||||||
14
script.sh
14
script.sh
|
|
@ -208,16 +208,6 @@ parse_docs()
|
||||||
rm -rf "$tmpfile"
|
rm -rf "$tmpfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_comps()
|
|
||||||
{
|
|
||||||
tmpfile=`mktemp`
|
|
||||||
|
|
||||||
git cat-file blob "$opt1" > "$tmpfile"
|
|
||||||
"$script_dir/find_compatible_dts.py" "$tmpfile" "$opt3" || exit "$?"
|
|
||||||
|
|
||||||
rm -rf "$tmpfile"
|
|
||||||
}
|
|
||||||
|
|
||||||
dts_comp()
|
dts_comp()
|
||||||
{
|
{
|
||||||
echo $dts_comp_support
|
echo $dts_comp_support
|
||||||
|
|
@ -296,10 +286,6 @@ case $cmd in
|
||||||
parse_docs
|
parse_docs
|
||||||
;;
|
;;
|
||||||
|
|
||||||
parse-comps)
|
|
||||||
parse_comps
|
|
||||||
;;
|
|
||||||
|
|
||||||
dts-comp)
|
dts-comp)
|
||||||
dts_comp
|
dts_comp
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
16
update.py
16
update.py
|
|
@ -23,17 +23,21 @@
|
||||||
# This is different from that blob's Git hash.
|
# This is different from that blob's Git hash.
|
||||||
|
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from lib import script, scriptLines
|
|
||||||
import lib
|
|
||||||
import data
|
|
||||||
import os
|
import os
|
||||||
from data import PathList
|
|
||||||
from threading import Thread, Lock, Event, Condition
|
from threading import Thread, Lock, Event, Condition
|
||||||
|
|
||||||
|
import lib
|
||||||
|
from lib import script, scriptLines
|
||||||
|
import data
|
||||||
|
from data import PathList
|
||||||
|
from find_compatible_dts import FindCompatibleDTS
|
||||||
|
|
||||||
verbose = False
|
verbose = False
|
||||||
|
|
||||||
dts_comp_support = int(script('dts-comp'))
|
dts_comp_support = int(script('dts-comp'))
|
||||||
|
|
||||||
|
compatibles_parser = FindCompatibleDTS()
|
||||||
|
|
||||||
db = data.DB(lib.getDataDir(), readonly=False, dtscomp=dts_comp_support)
|
db = data.DB(lib.getDataDir(), readonly=False, dtscomp=dts_comp_support)
|
||||||
|
|
||||||
# Number of cpu threads (+2 for version indexing)
|
# Number of cpu threads (+2 for version indexing)
|
||||||
|
|
@ -407,7 +411,7 @@ class UpdateComps(Thread):
|
||||||
family = lib.getFileFamily(filename)
|
family = lib.getFileFamily(filename)
|
||||||
if family in [None, 'K']: continue
|
if family in [None, 'K']: continue
|
||||||
|
|
||||||
lines = scriptLines('parse-comps', hash, filename, family)
|
lines = compatibles_parser.run(scriptLines('get-blob', hash), family)
|
||||||
comps = {}
|
comps = {}
|
||||||
for l in lines:
|
for l in lines:
|
||||||
ident, line = l.split(b' ')
|
ident, line = l.split(b' ')
|
||||||
|
|
@ -472,7 +476,7 @@ class UpdateCompsDocs(Thread):
|
||||||
filename = db.file.get(idx)
|
filename = db.file.get(idx)
|
||||||
|
|
||||||
family = 'B'
|
family = 'B'
|
||||||
lines = scriptLines('parse-comps', hash, filename, family)
|
lines = compatibles_parser.run(scriptLines('get-blob', hash), family)
|
||||||
comps_docs = {}
|
comps_docs = {}
|
||||||
with comps_lock:
|
with comps_lock:
|
||||||
for l in lines:
|
for l in lines:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue