Publish allexecutables and hexpng.
This commit is contained in:
parent
852504be13
commit
007b4a6e62
2 changed files with 57 additions and 0 deletions
15
Toolbox/allexecutables.py
Normal file
15
Toolbox/allexecutables.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import os
|
||||
|
||||
paths = os.getenv('PATH').split(';')
|
||||
paths = [p for p in paths if os.path.exists(p)]
|
||||
|
||||
extensions = os.getenv('PATHEXT').split(';')
|
||||
extensions = [e.lower() for e in extensions]
|
||||
print('Extensions according to PATHEXT:', extensions)
|
||||
|
||||
for path in paths:
|
||||
print(path)
|
||||
files = os.listdir(path)
|
||||
files = [f for f in files if any(f.lower().endswith(e) for e in extensions)]
|
||||
files = [' ' + f for f in files]
|
||||
print('\n'.join(files))
|
42
Toolbox/hexpng.py
Normal file
42
Toolbox/hexpng.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
import argparse
|
||||
import os
|
||||
import PIL.Image
|
||||
import sys
|
||||
|
||||
|
||||
def full_hex(h):
|
||||
h = h.replace('#', '')
|
||||
if len(h) in [3, 4]:
|
||||
h = ''.join([c * 2 for c in h])
|
||||
if len(h) == 6:
|
||||
h += 'ff'
|
||||
return h
|
||||
|
||||
def hex_to_rgb(h):
|
||||
rgb = [int(h[(2*i):(2*i)+2], 16) for i in range(len(h)//2)]
|
||||
return tuple(rgb)
|
||||
|
||||
def make_hexpng(h, width=1, height=1):
|
||||
h = full_hex(h)
|
||||
rgb = hex_to_rgb(h)
|
||||
filename = '%s.png' % h
|
||||
i = PIL.Image.new('RGBA', size=[width, height], color=rgb)
|
||||
print(filename)
|
||||
i.save(filename)
|
||||
|
||||
def hexpng_argparse(args):
|
||||
make_hexpng(args.hex_value, width=args.width, height=args.height)
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
|
||||
parser.add_argument('hex_value')
|
||||
parser.add_argument('--width', dest='width', type=int, default=1)
|
||||
parser.add_argument('--height', dest='height', type=int, default=1)
|
||||
parser.set_defaults(func=hexpng_argparse)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
args.func(args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main(sys.argv[1:]))
|
Loading…
Reference in a new issue