mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-15 01:53:09 +00:00
Run black on scripts/
This commit is contained in:
parent
fbf3a8ab20
commit
abbe301b82
4 changed files with 58 additions and 27 deletions
|
|
@ -23,6 +23,7 @@ import codecs
|
|||
import html
|
||||
from linkcheck import strformat
|
||||
|
||||
|
||||
def main(filename):
|
||||
om = print_memorydump(filename)
|
||||
dirname, basename = os.path.split(filename)
|
||||
|
|
@ -32,13 +33,16 @@ def main(filename):
|
|||
os.mkdir(basedir)
|
||||
write_htmlfiles(om, basedir)
|
||||
|
||||
|
||||
def print_memorydump(filename):
|
||||
from meliae import loader
|
||||
|
||||
om = loader.load(filename, collapse=True)
|
||||
om.remove_expensive_references()
|
||||
print om.summarize()
|
||||
return om
|
||||
|
||||
|
||||
def write_htmlfiles(om, basedir):
|
||||
om.compute_parents()
|
||||
open_files = {}
|
||||
|
|
@ -47,21 +51,24 @@ def write_htmlfiles(om, basedir):
|
|||
write_html_obj(fp, obj, om.objs)
|
||||
close_files(open_files)
|
||||
|
||||
|
||||
def get_file(type_str, open_files, basedir):
|
||||
"""Get already opened file, or open and initialize a new one."""
|
||||
if type_str not in open_files:
|
||||
filename = type_str+".html"
|
||||
encoding = 'utf-8'
|
||||
fd = codecs.open(os.path.join(basedir, filename), 'w', encoding)
|
||||
filename = type_str + ".html"
|
||||
encoding = "utf-8"
|
||||
fd = codecs.open(os.path.join(basedir, filename), "w", encoding)
|
||||
open_files[type_str] = fd
|
||||
write_html_header(fd, type_str, encoding)
|
||||
return open_files[type_str]
|
||||
|
||||
|
||||
def close_files(open_files):
|
||||
for fp in open_files.values():
|
||||
write_html_footer(fp)
|
||||
fp.close()
|
||||
|
||||
|
||||
HtmlHeader = """
|
||||
<!doctype html>
|
||||
<head>
|
||||
|
|
@ -70,10 +77,14 @@ HtmlHeader = """
|
|||
<body>
|
||||
"""
|
||||
|
||||
|
||||
def write_html_header(fp, type_str, encoding):
|
||||
fp.write(HtmlHeader % encoding)
|
||||
fp.write("<h1>Type %s</h1>\n" % type_str)
|
||||
fp.write("<table><tr><th>Address</th><th>Name</th><th>Size</th><th>Parents</th><th>References</th></tr>\n")
|
||||
fp.write(
|
||||
"<table><tr><th>Address</th><th>Name</th><th>Size</th><th>Parents</th><th>References</th></tr>\n"
|
||||
)
|
||||
|
||||
|
||||
def get_children(obj, objs):
|
||||
res = []
|
||||
|
|
@ -89,6 +100,7 @@ def get_children(obj, objs):
|
|||
res.append(entry)
|
||||
return res
|
||||
|
||||
|
||||
def get_parents(obj, objs):
|
||||
res = []
|
||||
for address in obj.parents:
|
||||
|
|
@ -103,6 +115,7 @@ def get_parents(obj, objs):
|
|||
res.append(entry)
|
||||
return res
|
||||
|
||||
|
||||
def write_html_obj(fp, obj, objs):
|
||||
if obj.value is None:
|
||||
value = "None"
|
||||
|
|
@ -115,11 +128,16 @@ def write_html_obj(fp, obj, objs):
|
|||
parents=",".join(get_parents(obj, objs)),
|
||||
value=value,
|
||||
)
|
||||
fp.write("<tr><td>%(address)d</td><td>%(value)s</td><td>%(size)s</td><td>%(children)s</td></tr>\n" % attrs)
|
||||
fp.write(
|
||||
"<tr><td>%(address)d</td><td>%(value)s</td><td>%(size)s</td><td>%(children)s</td></tr>\n"
|
||||
% attrs
|
||||
)
|
||||
|
||||
|
||||
def write_html_footer(fp):
|
||||
fp.write("</table></body></html>")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
filename = sys.argv[1]
|
||||
main(filename)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from __future__ import print_function
|
|||
import fileinput
|
||||
import sys
|
||||
|
||||
|
||||
def main(args):
|
||||
"""Remove lines after marker."""
|
||||
filename = args[0]
|
||||
|
|
@ -15,5 +16,6 @@ def main(args):
|
|||
if line.startswith(marker):
|
||||
break
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
|
|
|||
|
|
@ -5,17 +5,23 @@ import requests
|
|||
|
||||
iana_uri_schemes = "https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml"
|
||||
# CSV format: URI Scheme,Template,Description,Reference
|
||||
csv_iana_uri_schemes_permanent = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-1.csv'
|
||||
csv_iana_uri_schemes_provisional = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-2.csv'
|
||||
csv_iana_uri_schemes_historical = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-3.csv'
|
||||
csv_iana_uri_schemes_permanent = (
|
||||
"https://www.iana.org/assignments/uri-schemes/uri-schemes-1.csv"
|
||||
)
|
||||
csv_iana_uri_schemes_provisional = (
|
||||
"https://www.iana.org/assignments/uri-schemes/uri-schemes-2.csv"
|
||||
)
|
||||
csv_iana_uri_schemes_historical = (
|
||||
"https://www.iana.org/assignments/uri-schemes/uri-schemes-3.csv"
|
||||
)
|
||||
|
||||
iana_uri_schemes_permanent = {}
|
||||
iana_uri_schemes_provisional = {}
|
||||
iana_uri_schemes_historical = {}
|
||||
iana_uri_schemes_other = {
|
||||
"clsid": "Microsoft specific",
|
||||
"find" : "Mozilla specific",
|
||||
"isbn" : "ISBN (int. book numbers)",
|
||||
"clsid": "Microsoft specific",
|
||||
"find": "Mozilla specific",
|
||||
"isbn": "ISBN (int. book numbers)",
|
||||
"javascript": "JavaScript",
|
||||
}
|
||||
|
||||
|
|
@ -58,24 +64,27 @@ ignored_schemes_re = re.compile(ignored_schemes, re.VERBOSE)
|
|||
is_unknown_scheme = ignored_schemes_re.match
|
||||
'''
|
||||
|
||||
|
||||
def main(args):
|
||||
parse_csv_file(csv_iana_uri_schemes_permanent, iana_uri_schemes_permanent)
|
||||
parse_csv_file(csv_iana_uri_schemes_provisional, iana_uri_schemes_provisional)
|
||||
parse_csv_file(csv_iana_uri_schemes_historical, iana_uri_schemes_historical)
|
||||
for scheme in iana_uri_schemes_other:
|
||||
if (scheme in iana_uri_schemes_permanent or
|
||||
scheme in iana_uri_schemes_provisional or
|
||||
scheme in iana_uri_schemes_historical):
|
||||
if (
|
||||
scheme in iana_uri_schemes_permanent
|
||||
or scheme in iana_uri_schemes_provisional
|
||||
or scheme in iana_uri_schemes_historical
|
||||
):
|
||||
raise ValueError(scheme)
|
||||
for scheme in filter_uri_schemes_permanent:
|
||||
if scheme in iana_uri_schemes_permanent:
|
||||
del iana_uri_schemes_permanent[scheme]
|
||||
args = dict(
|
||||
uri = iana_uri_schemes,
|
||||
permanent = get_regex(iana_uri_schemes_permanent),
|
||||
provisional = get_regex(iana_uri_schemes_provisional),
|
||||
historical = get_regex(iana_uri_schemes_historical),
|
||||
other = get_regex(iana_uri_schemes_other),
|
||||
uri=iana_uri_schemes,
|
||||
permanent=get_regex(iana_uri_schemes_permanent),
|
||||
provisional=get_regex(iana_uri_schemes_provisional),
|
||||
historical=get_regex(iana_uri_schemes_historical),
|
||||
other=get_regex(iana_uri_schemes_other),
|
||||
)
|
||||
res = template % args
|
||||
print res
|
||||
|
|
@ -83,8 +92,10 @@ def main(args):
|
|||
|
||||
|
||||
def get_regex(schemes):
|
||||
expr = ["|%s # %s" % (re.escape(scheme).ljust(10), description)
|
||||
for scheme, description in sorted(schemes.items())]
|
||||
expr = [
|
||||
"|%s # %s" % (re.escape(scheme).ljust(10), description)
|
||||
for scheme, description in sorted(schemes.items())
|
||||
]
|
||||
return "\n".join(expr)
|
||||
|
||||
|
||||
|
|
@ -102,5 +113,5 @@ def parse_csv_file(url, res):
|
|||
res[scheme] = description
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ Usage: $0 <filename>
|
|||
import sys
|
||||
import yappi
|
||||
|
||||
|
||||
def main(args):
|
||||
filename = args[0]
|
||||
stats = yappi.YFuncStats()
|
||||
|
|
@ -14,6 +15,5 @@ def main(args):
|
|||
stats.print_all()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
|
|
|||
Loading…
Reference in a new issue