Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_arches():
"""Gets list of all known architectures"""
arches = ['aarch64', 'noarch', 'ppc', 'riscv64', 's390', 's390x', 'src', 'x86_64']
macros = MacroHelper.dump()
macros = [m for m in macros if m['name'] in ('ix86', 'arm', 'mips', 'sparc', 'alpha', 'power64')]
for m in macros:
arches.extend(MacroHelper.expand(m['value'], '').split())
return arches
and has the same value in both, it's impossible to tell them apart, so only the latter
is considered valid, disregarding the actual condition.
Returns:
A tuple containing: a tuple of all Tags object, new next source index, new next patch index.
Indexed tag names are sanitized, for example 'Source' is replaced with 'Source0'
and 'Patch007' with 'Patch7'.
Tag names are capitalized, section names are lowercase.
"""
result = []
tag_re = re.compile(r'^(?P(?P\w+)\s*:\s*)(?P.+)$')
for line_index, line in enumerate(section_content):
expanded = MacroHelper.expand(line)
if not line or not expanded:
continue
valid = bool(parsed and [p for p in parsed if p == expanded.rstrip()])
m = tag_re.match(line)
if m:
tag_name, tag_index, next_source_index, next_patch_index = cls._sanitize_tag(m.group('name'),
next_source_index,
next_patch_index)
result.append(Tag(section_index, section, line_index, tag_name, m.span('value'), valid, tag_index))
continue
m = tag_re.match(expanded)
if m:
start = line.find(m.group('prefix'))
if start < 0:
# tag is probably defined by a macro, just ignore it
continue
# parse macro arguments
try:
ns, unknown = parser.parse_known_args(args)
except ParseError:
continue
# check if this macro instance is extracting Source0
if ns.T and ns.a != 0 and ns.b != 0:
continue
# check if modification is really necessary
if dirname != ns.n:
new_dirname = dirname
# get %{name} and %{version} macros
macros = [m for m in MacroHelper.filter(self.macros, level=-3) if m['name'] in ('name', 'version')]
# add all macros from spec file scope
macros.extend(MacroHelper.filter(self.macros, level=0))
# omit short macros
macros = [m for m in macros if len(m['value']) > 1]
# ensure maximal greediness
macros.sort(key=lambda k: len(k['value']), reverse=True)
# substitute tokens with macros
for m in macros:
if m['value'] and m['value'] in dirname:
new_dirname = new_dirname.replace(m['value'], '%{{{}}}'.format(m['name']))
args = [macro]
args.extend(['-n', new_dirname])
if ns.a != -1:
args.extend(['-a', str(ns.a)])
break
# redefine macros and update tokens
for index, token in enumerate(tokens):
if token == values[index]:
continue
if not values[index]:
values[index] = '%{nil}' if token[0] == '%' else ''
macros = _find_macros(token)
if macros:
_redefine_macro(macros[0][0], values[index])
else:
tokens[index] = values[index]
result = ''.join(tokens)
_sync_macros(curval + result)
# only change value if necessary
if MacroHelper.expand(curval) == MacroHelper.expand(result):
return curval
return result
def _get_instructions(cls, comments, old_version, new_version):
"""Extract instructions from comments, update version if necessary"""
instructions = []
for comment in comments:
comment = MacroHelper.expand(comment, comment)
comment = MacroHelper.expand(comment, comment)
comment = re.sub(r'^#\s*', '', comment)
comment = comment.replace(old_version, new_version)
instructions.append(comment)
return instructions
def guess_category():
for pkg in self.spc.packages:
header = RpmHeader(pkg.header)
for category in PackageCategory:
if category.value.match(header.name):
return category
for provide in header.providename:
if category.value.match(provide):
return category
return None
self.category = guess_category()
self.sources = self._get_spec_sources_list(self.spc)
self.prep_section = self.spc.prep
self.main_source_index = self._identify_main_source(self.spc)
self.patches = self._get_initial_patches()
self.macros = MacroHelper.dump()
def run(cls, spec_file, rebase_spec_file, **kwargs):
macros = [m for m in rebase_spec_file.macros if m['name'] in MacroHelper.MACROS_WHITELIST]
macros = MacroHelper.expand_macros(macros)
# ensure maximal greediness
macros.sort(key=lambda k: len(k['value']), reverse=True)
for sec_name, sec_content in rebase_spec_file.spec_content.sections:
if sec_name.startswith('%files'):
for index, line in enumerate(sec_content):
new_path = MacroHelper.substitute_path_with_macros(line, macros)
sec_content[index] = new_path
rebase_spec_file.save()
def _parse_list_tags(cls, section: str, section_content: List[str], parsed: List[str], section_index: int,
next_source_index: int, next_patch_index: int) -> Tuple[List[Tag], int, int]:
"""Parses all tags in a %sourcelist or %patchlist section.
Only parses tags that are valid (that is - are in parsed), nothing more can
consistently be detected.
Follows how rpm works, the new Source/Patch tags are indexed starting from
the last parsed Source/Patch tag.
"""
tag = 'Source' if section == '%sourcelist' else 'Patch'
result = []
for i, line in enumerate(section_content):
expanded = MacroHelper.expand(line)
is_comment = SpecContent.get_comment_span(line, section)[0] != len(line)
if not expanded or not line or is_comment or not [p for p in parsed if p == expanded.rstrip()]:
continue
tag_name, tag_index, next_source_index, next_patch_index = cls._sanitize_tag(tag, next_source_index,
next_patch_index)
result.append(Tag(section_index, section, i, tag_name, (0, len(line)), True, tag_index))
return result, next_source_index, next_patch_index
def get_release_number(self) -> str:
"""
Removed in rebasehelper=0.20.0
"""
release = self.header.release
dist = MacroHelper.expand("%{dist}")
if dist:
release = release.replace(dist, "")
return re.sub(r"([0-9.]*[0-9]+).*", r"\1", release)