query: Move dts commands to functions
This commit is contained in:
parent
ac5a64b972
commit
5563feaf78
4 changed files with 17 additions and 13 deletions
|
|
@ -13,7 +13,7 @@ class DtsCompCodeFilter(Filter):
|
||||||
|
|
||||||
def check_if_applies(self, ctx) -> bool:
|
def check_if_applies(self, ctx) -> bool:
|
||||||
return super().check_if_applies(ctx) and \
|
return super().check_if_applies(ctx) and \
|
||||||
ctx.query.query('dts-comp') and \
|
ctx.query.supports_dts_comp() and \
|
||||||
extension_matches(ctx.filepath, {'c', 'cc', 'cpp', 'c++', 'cxx', 'h', 's'})
|
extension_matches(ctx.filepath, {'c', 'cc', 'cpp', 'c++', 'cxx', 'h', 's'})
|
||||||
|
|
||||||
def transform_raw_code(self, ctx, code: str) -> str:
|
def transform_raw_code(self, ctx, code: str) -> str:
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ class DtsCompDocsFilter(Filter):
|
||||||
|
|
||||||
def check_if_applies(self, ctx) -> bool:
|
def check_if_applies(self, ctx) -> bool:
|
||||||
return super().check_if_applies(ctx) and \
|
return super().check_if_applies(ctx) and \
|
||||||
ctx.query.query('dts-comp') and \
|
ctx.query.supports_dts_comp() and \
|
||||||
ctx.filepath.startswith('/Documentation/devicetree/bindings')
|
ctx.filepath.startswith('/Documentation/devicetree/bindings')
|
||||||
|
|
||||||
def transform_raw_code(self, ctx, code: str) -> str:
|
def transform_raw_code(self, ctx, code: str) -> str:
|
||||||
def keep_dtscompB(m):
|
def keep_dtscompB(m):
|
||||||
text = m.group(1)
|
text = m.group(1)
|
||||||
|
|
||||||
if ctx.query.query('dts-comp-exists', quote(text)):
|
if ctx.query.dts_comp_exists(quote(text)):
|
||||||
self.dtscompB.append(text)
|
self.dtscompB.append(text)
|
||||||
return f'__KEEPDTSCOMPB__{ encode_number(len(self.dtscompB)) }'
|
return f'__KEEPDTSCOMPB__{ encode_number(len(self.dtscompB)) }'
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class DtsCompDtsFilter(Filter):
|
||||||
|
|
||||||
def check_if_applies(self, ctx) -> bool:
|
def check_if_applies(self, ctx) -> bool:
|
||||||
return super().check_if_applies(ctx) and \
|
return super().check_if_applies(ctx) and \
|
||||||
ctx.query.query('dts-comp') and \
|
ctx.query.supports_dts_comp() and \
|
||||||
extension_matches(ctx.filepath, {'dts', 'dtsi'})
|
extension_matches(ctx.filepath, {'dts', 'dtsi'})
|
||||||
|
|
||||||
def transform_raw_code(self, ctx, code: str) -> str:
|
def transform_raw_code(self, ctx, code: str) -> str:
|
||||||
|
|
|
||||||
|
|
@ -113,18 +113,11 @@ class Query:
|
||||||
return lib.getFileFamily(filename)
|
return lib.getFileFamily(filename)
|
||||||
|
|
||||||
elif cmd == 'dts-comp':
|
elif cmd == 'dts-comp':
|
||||||
# Get state of dts_comp_support
|
return self.supports_dts_comp()
|
||||||
|
|
||||||
return self.dts_comp_support
|
|
||||||
|
|
||||||
elif cmd == 'dts-comp-exists':
|
elif cmd == 'dts-comp-exists':
|
||||||
# Check if a dts compatible string exists
|
|
||||||
|
|
||||||
ident = args[0]
|
ident = args[0]
|
||||||
if self.dts_comp_support:
|
return self.dts_comp_exists(ident)
|
||||||
return self.db.comps.exists(ident)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
elif cmd == 'keys':
|
elif cmd == 'keys':
|
||||||
# Return all keys of a given database
|
# Return all keys of a given database
|
||||||
|
|
@ -165,6 +158,17 @@ class Query:
|
||||||
else:
|
else:
|
||||||
return 'Unknown subcommand: ' + cmd + '\n'
|
return 'Unknown subcommand: ' + cmd + '\n'
|
||||||
|
|
||||||
|
# Get state of dts_comp_support
|
||||||
|
def supports_dts_comp(self):
|
||||||
|
return self.dts_comp_support
|
||||||
|
|
||||||
|
# Check if a dts compatible string exists
|
||||||
|
def dts_comp_exists(self, ident):
|
||||||
|
if self.dts_comp_support:
|
||||||
|
return self.db.comps.exists(ident)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
# Returns True if file exists
|
# Returns True if file exists
|
||||||
def file_exists(self, version, path):
|
def file_exists(self, version, path):
|
||||||
if version not in self.file_cache:
|
if version not in self.file_cache:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue