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
|
||||
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sys import argv
|
||||
import re
|
||||
import os
|
||||
from urllib import parse
|
||||
import query
|
||||
|
||||
usage_message = ("USAGE: find_compatible_dts.py <file> <family>\n"
|
||||
"file : The file you want to search in\n"
|
||||
"family : The type of file (C for .c/.cpp/.h/...\n"
|
||||
" D for .dts/.dtsi\n"
|
||||
" B for bindings docs files)")
|
||||
|
||||
ident_list = ""
|
||||
from query import decode
|
||||
|
||||
class FindCompatibleDTS:
|
||||
def __init__(self):
|
||||
# Compile regexes
|
||||
regex_c = re.compile("\s*{*\s*\.compatible\s*=\s*\"(.+?)\"")
|
||||
regex_dts1 = re.compile("\s*compatible")
|
||||
regex_dts2 = re.compile("\"(.+?)\"")
|
||||
regex_bindings = re.compile("([\w-]+,?[\w-]+)")
|
||||
self.regex_c = re.compile("\s*{*\s*\.compatible\s*=\s*\"(.+?)\"")
|
||||
self.regex_dts1 = re.compile("\s*compatible")
|
||||
self.regex_dts2 = re.compile("\"(.+?)\"")
|
||||
self.regex_bindings = re.compile("([\w-]+,?[\w-]+)")
|
||||
|
||||
def parse_c(self, content):
|
||||
return self.regex_c.findall(content)
|
||||
|
||||
def parse_c(content):
|
||||
return regex_c.findall(content)
|
||||
|
||||
def parse_dts(content):
|
||||
def parse_dts(self, content):
|
||||
ret = []
|
||||
if regex_dts1.match(content) != None:
|
||||
ret = regex_dts2.findall(content)
|
||||
if self.regex_dts1.match(content) != None:
|
||||
ret = self.regex_dts2.findall(content)
|
||||
return ret
|
||||
|
||||
def parse_bindings(content):
|
||||
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 regex_bindings.findall(content)
|
||||
return self.regex_bindings.findall(content)
|
||||
|
||||
|
||||
# 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)
|
||||
def run(self, file_lines, family):
|
||||
ident_list = ""
|
||||
|
||||
# Iterate though lines and search for idents
|
||||
for num, line in enumerate(f, 1):
|
||||
for num, line in enumerate(file_lines, 1):
|
||||
line = query.decode(line)
|
||||
if family == 'C':
|
||||
ret = parse_c(line)
|
||||
ret = self.parse_c(line)
|
||||
elif family == 'D':
|
||||
ret = parse_dts(line)
|
||||
ret = self.parse_dts(line)
|
||||
elif family == 'B':
|
||||
ret = parse_bindings(line)
|
||||
ret = self.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)
|
||||
return ident_list
|
||||
|
||||
|
|
|
|||
14
script.sh
14
script.sh
|
|
@ -208,16 +208,6 @@ parse_docs()
|
|||
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()
|
||||
{
|
||||
echo $dts_comp_support
|
||||
|
|
@ -296,10 +286,6 @@ case $cmd in
|
|||
parse_docs
|
||||
;;
|
||||
|
||||
parse-comps)
|
||||
parse_comps
|
||||
;;
|
||||
|
||||
dts-comp)
|
||||
dts_comp
|
||||
;;
|
||||
|
|
|
|||
16
update.py
16
update.py
|
|
@ -23,17 +23,21 @@
|
|||
# This is different from that blob's Git hash.
|
||||
|
||||
from sys import argv
|
||||
from lib import script, scriptLines
|
||||
import lib
|
||||
import data
|
||||
import os
|
||||
from data import PathList
|
||||
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
|
||||
|
||||
dts_comp_support = int(script('dts-comp'))
|
||||
|
||||
compatibles_parser = FindCompatibleDTS()
|
||||
|
||||
db = data.DB(lib.getDataDir(), readonly=False, dtscomp=dts_comp_support)
|
||||
|
||||
# Number of cpu threads (+2 for version indexing)
|
||||
|
|
@ -407,7 +411,7 @@ class UpdateComps(Thread):
|
|||
family = lib.getFileFamily(filename)
|
||||
if family in [None, 'K']: continue
|
||||
|
||||
lines = scriptLines('parse-comps', hash, filename, family)
|
||||
lines = compatibles_parser.run(scriptLines('get-blob', hash), family)
|
||||
comps = {}
|
||||
for l in lines:
|
||||
ident, line = l.split(b' ')
|
||||
|
|
@ -472,7 +476,7 @@ class UpdateCompsDocs(Thread):
|
|||
filename = db.file.get(idx)
|
||||
|
||||
family = 'B'
|
||||
lines = scriptLines('parse-comps', hash, filename, family)
|
||||
lines = compatibles_parser.run(scriptLines('get-blob', hash), family)
|
||||
comps_docs = {}
|
||||
with comps_lock:
|
||||
for l in lines:
|
||||
|
|
|
|||
Loading…
Reference in a new issue