Run black on project
Signed-off-by: Alfred Wingate <parona@protonmail.com>
This commit is contained in:
@ -28,25 +28,25 @@ def guess_indent_values(before):
|
||||
def guess_for_tags(tags):
|
||||
for tag in tags:
|
||||
for i in [0, 2, 4, 6, 8, 12, 16]:
|
||||
if '\n%s<%s' % (' ' * i, tag) in before:
|
||||
if "\n%s<%s" % (" " * i, tag) in before:
|
||||
return i, False
|
||||
for i in [0, 1, 2]:
|
||||
if '\n%s<%s' % ('\t' * i, tag) in before:
|
||||
if "\n%s<%s" % ("\t" * i, tag) in before:
|
||||
return i, True
|
||||
return -1, False
|
||||
|
||||
rindent, tab = guess_for_tags(
|
||||
['herd', 'maintainer', 'longdescription', 'use', 'upstream']
|
||||
["herd", "maintainer", "longdescription", "use", "upstream"]
|
||||
)
|
||||
if rindent == -1:
|
||||
rindent = 2
|
||||
rindent_str = ('\t' if tab else ' ') * rindent
|
||||
indent, tab = guess_for_tags(['watch', 'name', 'email'])
|
||||
rindent_str = ("\t" if tab else " ") * rindent
|
||||
indent, tab = guess_for_tags(["watch", "name", "email"])
|
||||
if indent == -1:
|
||||
indent = rindent * 2 if rindent else 4
|
||||
if rindent and rindent_str == '\t':
|
||||
if rindent and rindent_str == "\t":
|
||||
tab = True
|
||||
indent_str = ('\t' if tab else ' ') * indent
|
||||
indent_str = ("\t" if tab else " ") * indent
|
||||
return rindent_str, indent_str
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ def handle_diff(deb_url):
|
||||
|
||||
watch_data = ""
|
||||
|
||||
fp = gzip.open(temp_deb, 'rb')
|
||||
fp = gzip.open(temp_deb, "rb")
|
||||
for line in fp:
|
||||
if re.match(r"\+\+\+ .+?/debian/watch", line):
|
||||
fp.readline() # diff lines, don't care
|
||||
@ -144,8 +144,9 @@ def patch_metadata(package, watch_data, diff=False):
|
||||
data = original
|
||||
|
||||
# clean watch_data
|
||||
watch_data = "\n".join([line for line in watch_data.split("\n")
|
||||
if not line.startswith("#")]) # comments
|
||||
watch_data = "\n".join(
|
||||
[line for line in watch_data.split("\n") if not line.startswith("#")]
|
||||
) # comments
|
||||
|
||||
watch_data = watch_data.replace("\\\n", "") # remove backslashes
|
||||
|
||||
@ -163,10 +164,7 @@ def patch_metadata(package, watch_data, diff=False):
|
||||
continue
|
||||
|
||||
# parse watch_line
|
||||
result = re.match(
|
||||
r'(?:opts=(?:"([^"]+?)"|([^\s]+?)) )?(.*)',
|
||||
watch_line
|
||||
)
|
||||
result = re.match(r'(?:opts=(?:"([^"]+?)"|([^\s]+?)) )?(.*)', watch_line)
|
||||
|
||||
opts_quote, opts, url = result.groups()
|
||||
opts = opts_quote or opts
|
||||
@ -188,21 +186,27 @@ def patch_metadata(package, watch_data, diff=False):
|
||||
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, opts, url)
|
||||
watch_tag = '%s<watch version="%s" %s>%s</watch>' % (
|
||||
indent,
|
||||
version,
|
||||
opts,
|
||||
url,
|
||||
)
|
||||
else:
|
||||
watch_tag = '%s<watch version="%s">%s</watch>' % \
|
||||
(indent, version, url)
|
||||
watch_tag = '%s<watch version="%s">%s</watch>' % (indent, version, url)
|
||||
watch_tags.append(watch_tag)
|
||||
|
||||
watch_tags = "\n".join(watch_tags)
|
||||
|
||||
if '<upstream>' in data:
|
||||
data = data.replace('<upstream>', '<upstream>\n%s' % watch_tags, 1)
|
||||
if "<upstream>" in data:
|
||||
data = data.replace("<upstream>", "<upstream>\n%s" % watch_tags, 1)
|
||||
else:
|
||||
rep = '%s<upstream>\n%s\n%s</upstream>\n</pkgmetadata>' % \
|
||||
(rindent, watch_tags, rindent)
|
||||
data = data.replace('</pkgmetadata>', rep, 1)
|
||||
rep = "%s<upstream>\n%s\n%s</upstream>\n</pkgmetadata>" % (
|
||||
rindent,
|
||||
watch_tags,
|
||||
rindent,
|
||||
)
|
||||
data = data.replace("</pkgmetadata>", rep, 1)
|
||||
|
||||
if not diff:
|
||||
return data
|
||||
@ -214,8 +218,8 @@ def patch_metadata(package, watch_data, diff=False):
|
||||
res = unified_diff(
|
||||
original.splitlines(True),
|
||||
data.splitlines(True),
|
||||
fromfile=os.path.join('a/', metadata_path),
|
||||
tofile=os.path.join('b/', metadata_path),
|
||||
fromfile=os.path.join("a/", metadata_path),
|
||||
tofile=os.path.join("b/", metadata_path),
|
||||
)
|
||||
return "".join([x for x in res])
|
||||
|
||||
@ -223,12 +227,12 @@ def patch_metadata(package, watch_data, diff=False):
|
||||
def process_package(query, diff=False):
|
||||
try:
|
||||
matches = Query(query).smart_find(
|
||||
in_installed=True,
|
||||
in_porttree=True,
|
||||
in_overlay=True,
|
||||
include_masked=True,
|
||||
show_progress=False,
|
||||
no_matches_fatal=False,
|
||||
in_installed=True,
|
||||
in_porttree=True,
|
||||
in_overlay=True,
|
||||
include_masked=True,
|
||||
show_progress=False,
|
||||
no_matches_fatal=False,
|
||||
)
|
||||
except AmbiguousPackageName:
|
||||
logger.error(" Ambiguous package name")
|
||||
@ -240,7 +244,7 @@ def process_package(query, diff=False):
|
||||
|
||||
matches = sorted(matches)
|
||||
package = matches.pop()
|
||||
if '9999' in package.version and len(matches) > 0:
|
||||
if "9999" in package.version and len(matches) > 0:
|
||||
package = matches.pop()
|
||||
|
||||
watch_data = get_watch_data(package)
|
||||
@ -252,16 +256,21 @@ def process_package(query, diff=False):
|
||||
|
||||
def main():
|
||||
import optparse
|
||||
|
||||
p = optparse.OptionParser(
|
||||
usage="usage: %prog <package> [<package> [...]]",
|
||||
)
|
||||
p.add_option('-d', '--diff', action="store_true", dest="diff",
|
||||
default=False,
|
||||
help="Outputs a diff")
|
||||
p.add_option(
|
||||
"-d",
|
||||
"--diff",
|
||||
action="store_true",
|
||||
dest="diff",
|
||||
default=False,
|
||||
help="Outputs a diff",
|
||||
)
|
||||
opts, packages = p.parse_args()
|
||||
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.INFO,
|
||||
format='%(message)s')
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.INFO, format="%(message)s")
|
||||
|
||||
for package in packages:
|
||||
logger.info("Processing %s..." % package)
|
||||
@ -269,5 +278,6 @@ def main():
|
||||
if result:
|
||||
sys.stdout.write(result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user