diff options
author | Martin Fischer <martin@push-f.com> | 2021-12-23 07:58:20 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-12-23 07:58:20 +0100 |
commit | 4466c97f475f7913dd3f8a31bbe59c2028520927 (patch) | |
tree | d97819fc244b05f433caea1fc1eefca7cf5c5292 | |
parent | c629c3a0f01b7b5ccaacf7fb85df10ae5d59de9b (diff) |
add Makefile and format with black
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | cargo_check.py | 8 | ||||
-rwxr-xr-x | gcl | 56 | ||||
-rwxr-xr-x | mkfeed.py | 28 | ||||
-rwxr-xr-x | pygments_wcag_check.py | 19 |
5 files changed, 92 insertions, 23 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e47e373 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +nothing: + +fmt: + black -S *.py blockpipe gcl shebang diff --git a/cargo_check.py b/cargo_check.py index 3350c56..0246881 100755 --- a/cargo_check.py +++ b/cargo_check.py @@ -15,6 +15,7 @@ with open('Cargo.toml') as f: version = info if isinstance(info, str) else info.get('version') tasks.append((name, version)) + def check_package(info): name, version = info res = sess.get('https://crates.io/api/v1/crates/{}'.format(name)) @@ -22,7 +23,12 @@ def check_package(info): if latest_version['yanked']: print(name, 'was yanked') elif not latest_version['num'].startswith(version): - print('{} is outdated ({}), {} is available'.format(name, version, latest_version['num'])) + print( + '{} is outdated ({}), {} is available'.format( + name, version, latest_version['num'] + ) + ) + pool = Pool() pool.map(check_package, tasks) @@ -9,13 +9,16 @@ import shutil GITCONFIGS = 'gitconfigs/' + class colors: WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' + def print_usage(): - print('''git config linker (gcl): + print( + '''git config linker (gcl): gcl status check the status of the directories in . @@ -30,9 +33,11 @@ def print_usage(): gcl unlink <repo>... undo "gcl link <repo>" (only needed if you want to stop using gcl) -''') +''' + ) sys.exit() + args = sys.argv[1:] if len(args) == 0: print_usage() @@ -40,15 +45,22 @@ if len(args) == 0: if not os.path.exists(GITCONFIGS + '/.git/config'): sys.exit(f'expected {GITCONFIGS} to be a git repository') + def get_link_error(path): configpath = path + '/.git/config' if not os.path.exists(configpath): missing = os.path.relpath(os.path.realpath(configpath)) - return colors.FAIL + 'BROKEN LINK' + colors.ENDC + f' ({missing} does not exist)' - elif os.path.islink(configpath) and os.path.relpath(os.path.realpath(configpath)) != GITCONFIGS + path: + return ( + colors.FAIL + 'BROKEN LINK' + colors.ENDC + f' ({missing} does not exist)' + ) + elif ( + os.path.islink(configpath) + and os.path.relpath(os.path.realpath(configpath)) != GITCONFIGS + path + ): missing = os.path.relpath(os.path.realpath(configpath)) return colors.WARNING + 'LINK MISMATCH' + colors.ENDC + f' ({missing})' + def get_repo_status(path): errors = [] link_error = get_link_error(path) @@ -57,10 +69,25 @@ def get_repo_status(path): if hasremote(path + '/.git/config'): try: - if subprocess.check_output(['git', 'branch', '-r', '--contains', 'HEAD'], cwd=path, stderr=subprocess.DEVNULL) == b'': + if ( + subprocess.check_output( + ['git', 'branch', '-r', '--contains', 'HEAD'], + cwd=path, + stderr=subprocess.DEVNULL, + ) + == b'' + ): errors.append(colors.WARNING + 'UNPUSHED' + colors.ENDC) except subprocess.CalledProcessError as err: - if subprocess.run(['git', 'rev-parse', 'HEAD'], cwd=path, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0: + if ( + subprocess.run( + ['git', 'rev-parse', 'HEAD'], + cwd=path, + stderr=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + ) + == 0 + ): # the first command did not just fail because there are no commits yet raise err else: @@ -70,20 +97,30 @@ def get_repo_status(path): errors.append(colors.WARNING + 'DIRTY' + colors.ENDC) return ', '.join(errors) + def print_repo_table(reponames): maxlen = max([len(s) for s in reponames]) for reponame in reponames: print(f'\t{reponame.ljust(maxlen)} {get_repo_status(reponame)}') print() + linked = [] unlinked = [] not_a_repo = [] + def hasremote(path): config = configparser.ConfigParser() config.read(path) - return any([':' in config[s].get('url','') for s in config.sections() if s.startswith('remote')]) + return any( + [ + ':' in config[s].get('url', '') + for s in config.sections() + if s.startswith('remote') + ] + ) + def scan(): for filename in sorted(os.listdir()): @@ -98,6 +135,7 @@ def scan(): else: unlinked.append(filename) + cmd = args.pop(0) if cmd == 'status': @@ -120,7 +158,9 @@ elif cmd == 'link': for repo in args: configpath = repo + '/.git/config' if not os.path.isfile(configpath): - print(f"skipping '{repo}' because {configpath} is not a file (maybe already linked?)") + print( + f"skipping '{repo}' because {configpath} is not a file (maybe already linked?)" + ) continue if os.path.exists(GITCONFIGS + repo): sys.exit(f"aborting since {GITCONFIGS + repo} already exists") @@ -24,9 +24,11 @@ for filename in sorted(os.listdir(OUTDIR), reverse=True): tree = ET.parse(OUTDIR + filename + '/index.html').getroot() title = tree.find('.//title') data = dict( - title = escape(title.text), - html = ''.join(ET.tostring(c, 'unicode') for c in tree.find('.//div[@id="content"]')), - path = DIR + escape(filename) + title=escape(title.text), + html=''.join( + ET.tostring(c, 'unicode') for c in tree.find('.//div[@id="content"]') + ), + path=DIR + escape(filename), ) dataEl = tree.find('.//meta[@name="dcterms.date"]') if dataEl is not None: @@ -39,14 +41,19 @@ for filename in sorted(os.listdir(OUTDIR), reverse=True): last_updated = max([p['dateMeta'] for p in posts if 'dateMeta' in p]) with open(OUTDIR + 'index.html', 'w') as f: - f.write(f'<h2>{escape(DIRNAME.title())} <a href="{escape(DIR)}atom.xml" style="vertical-align:top">{FEED_SVG}</a></h2>') + f.write( + f'<h2>{escape(DIRNAME.title())} <a href="{escape(DIR)}atom.xml" style="vertical-align:top">{FEED_SVG}</a></h2>' + ) f.write('<ul class="mkfeed-list">') for post in posts: - f.write(f"<li>{post.get('date')}: <a href=\"{post['path']}\">{post['title']}</a></li>") + f.write( + f"<li>{post.get('date')}: <a href=\"{post['path']}\">{post['title']}</a></li>" + ) f.write('</ul>') with open(OUTDIR + 'atom.xml', 'w') as f: - f.write(f'''\ + f.write( + f'''\ <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> @@ -54,9 +61,11 @@ with open(OUTDIR + 'atom.xml', 'w') as f: <title>{TITLE}</title> <link href="{URL}"/> <updated>{last_updated}</updated> - ''') + ''' + ) for post in posts[:10]: - f.write(f''' + f.write( + f''' <entry> <title>{post['title']}</title> <link href="{URL.rstrip('/')}{post['path']}"/> @@ -64,5 +73,6 @@ with open(OUTDIR + 'atom.xml', 'w') as f: <updated>{post.get('dateMeta')}</updated> <content type="html"><![CDATA[{post['html']}]]></content> </entry> - ''') + ''' + ) f.write('</feed>') diff --git a/pygments_wcag_check.py b/pygments_wcag_check.py index 2a1e917..15993eb 100755 --- a/pygments_wcag_check.py +++ b/pygments_wcag_check.py @@ -6,6 +6,7 @@ import statistics import pygments.styles import wcag_contrast_ratio + def hex2rgb(hexstr): hexstr = hexstr.lstrip('#') r = int(hexstr[:2], 16) / 255 @@ -13,6 +14,7 @@ def hex2rgb(hexstr): b = int(hexstr[4:], 16) / 255 return (r, g, b) + total_wcag_fails = 0 styles = [] @@ -26,14 +28,19 @@ for name in pygments.styles.get_all_styles(): hex2rgb(style['color'] or '#000000') # we default to black because browsers also do ), - ttype - ) for ttype, style in style.list_styles() + ttype, + ) + for ttype, style in style.list_styles() ] if len(contrasts) == 0: continue styles.append( - (statistics.mean([x[0] for x in contrasts]), min([x[0] for x in contrasts]), name) + ( + statistics.mean([x[0] for x in contrasts]), + min([x[0] for x in contrasts]), + name, + ) ) bad_contrasts = [c for c in contrasts if not wcag_contrast_ratio.passes_AA(c[0])] @@ -50,10 +57,12 @@ for name in pygments.styles.get_all_styles(): if total_wcag_fails: print(f'found {total_wcag_fails} contrasts that fail to meet the WCAG AA standard') - print('''According to WCAG: + print( + '''According to WCAG: AA contrast is >= 4.5 AAA contrast is >= 7.0 - ''') + ''' + ) print('=== Styles ranked by contrast ===') print(' avg min name') for contrast, minimum, name in sorted(styles): |