euscanwww: Removing useless stuff while creating watch tag
* Removing useless options or actions * Fixing handling of substitution regex Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
parent
e2890c6364
commit
9f164ed22c
@ -166,16 +166,26 @@ def patch_metadata(metadata_path, watch_data, diff=False):
|
||||
watch_line
|
||||
)
|
||||
|
||||
attrs_quote, attrs, url = result.groups()
|
||||
attrs = attrs_quote or attrs
|
||||
opts_quote, opts, url = result.groups()
|
||||
opts = opts_quote or opts
|
||||
|
||||
if attrs:
|
||||
attrs = [x.replace('=', '="') + '"' for x in attrs.split(",")]
|
||||
attrs = " ".join(attrs)
|
||||
if opts:
|
||||
# clean opts, skip useless ones
|
||||
valid = ("uversionmangle", "versionmangle", "downloadurlmangle")
|
||||
cleaned_opts = []
|
||||
for opt in opts.split(","):
|
||||
opt_name, opt_value = opt.split("=")
|
||||
if opt_name in valid:
|
||||
cleaned_opts.append('%s="%s"' % (opt_name, opt_value))
|
||||
opts = " ".join(cleaned_opts)
|
||||
|
||||
if attrs:
|
||||
# clean url from useless stuff. Just keep <base> [<filepattern>]
|
||||
url_search = re.search(r"^([^\s]+)(?: ([^\s]*\([^\s]+\)[^\s]*))?", url)
|
||||
url = " ".join([x for x in url_search.groups() if x is not None])
|
||||
|
||||
if opts:
|
||||
watch_tag = '%s<watch version="%s" %s>%s</watch>' % \
|
||||
(indent, version, attrs, url)
|
||||
(indent, version, opts, url)
|
||||
else:
|
||||
watch_tag = '%s<watch version="%s">%s</watch>' % \
|
||||
(indent, version, url)
|
||||
|
@ -26,7 +26,11 @@ def can_handle(pkg, url):
|
||||
def parse_mangles(mangles, string):
|
||||
for mangle in mangles:
|
||||
# convert regex from perl format to python format
|
||||
# there are some regex in this format: s/pattern/replacement/
|
||||
m = re.match(r"s/(.*[^\\])/(.*)/", mangle)
|
||||
if not m:
|
||||
# or in this format s|pattern|replacement|
|
||||
m = re.match(r"s\|(.*[^\\])\|(.*)\|", mangle)
|
||||
pattern, repl = m.groups()
|
||||
repl = re.sub(r"\$(\d+)", r"\\\1", repl)
|
||||
string = re.sub(pattern, repl, string)
|
||||
|
Loading…
Reference in New Issue
Block a user