-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cytopia/release-0.2
Release 0.2
- Loading branch information
Showing
7 changed files
with
328 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
badchars.egg-info/ | ||
build/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 cytopia <https://github.com/cytopia> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
ifneq (,) | ||
.error This Makefile requires GNU Make. | ||
endif | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Default configuration | ||
# ------------------------------------------------------------------------------------------------- | ||
.PHONY: help build clean | ||
|
||
|
||
VERSION = 2.7 | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Default Target | ||
# ------------------------------------------------------------------------------------------------- | ||
help: | ||
@echo "lint Lint source code" | ||
@echo "build Build Python package" | ||
@echo "dist Create source and binary distribution" | ||
@echo "sdist Create source distribution" | ||
@echo "bdist Create binary distribution" | ||
@echo "clean Build" | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Lint Targets | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
lint: pycodestyle pydocstyle black | ||
|
||
pycodestyle: | ||
docker run --rm -v $(PWD):/data cytopia/pycodestyle --show-source --show-pep8 badchars | ||
|
||
pydocstyle: | ||
docker run --rm -v $(PWD):/data cytopia/pydocstyle badchars | ||
|
||
black: | ||
docker run --rm -v ${PWD}:/data cytopia/black -l 100 badchars | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Build Targets | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
dist: sdist bdist | ||
|
||
sdist: | ||
docker run \ | ||
--rm \ | ||
$$(tty -s && echo "-it" || echo) \ | ||
-v $(PWD):/data \ | ||
-w /data \ | ||
-u $$(id -u):$$(id -g) \ | ||
python:$(VERSION)-alpine \ | ||
python setup.py sdist | ||
|
||
bdist: | ||
docker run \ | ||
--rm \ | ||
$$(tty -s && echo "-it" || echo) \ | ||
-v $(PWD):/data \ | ||
-w /data \ | ||
-u $$(id -u):$$(id -g) \ | ||
python:$(VERSION)-alpine \ | ||
python setup.py bdist_wheel --universal | ||
|
||
build: | ||
docker run \ | ||
--rm \ | ||
$$(tty -s && echo "-it" || echo) \ | ||
-v $(PWD):/data \ | ||
-w /data \ | ||
-u $$(id -u):$$(id -g) \ | ||
python:$(VERSION)-alpine \ | ||
python setup.py build | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Publish Targets | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
checkbuild: | ||
docker run \ | ||
--rm \ | ||
$$(tty -s && echo "-it" || echo) \ | ||
-v $(PWD):/data \ | ||
-w /data \ | ||
python:$(VERSION)-alpine \ | ||
sh -c "pip install twine \ | ||
&& twine check dist/*" | ||
|
||
deploy: | ||
docker run \ | ||
--rm \ | ||
$$(tty -s && echo "-it" || echo) \ | ||
-v $(PWD):/data \ | ||
-w /data \ | ||
python:$(VERSION)-alpine \ | ||
sh -c "pip install twine \ | ||
&& twine upload dist/*" | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Misc Targets | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
clean: | ||
-rm -rf badchars.egg-info/ | ||
-rm -rf dist/ | ||
-rm -rf build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#!/usr/bin/env python | ||
"""Print badchars.""" | ||
|
||
import sys | ||
import argparse | ||
import math | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# GLOBALS | ||
# ------------------------------------------------------------------------------------------------- | ||
DEFAULT_LENGTH = 255 | ||
FORMATS = { | ||
"c": { | ||
"block": {"pre": "char badchars[] = \n", "post": '";'}, | ||
"line": {"pre": ' "', "post": '"'}, | ||
}, | ||
"js": { | ||
"block": {"pre": "var badchars = \n", "post": '";'}, | ||
"line": {"pre": ' "', "post": '" +'}, | ||
}, | ||
"php": { | ||
"block": {"pre": "$badchars = \n", "post": '";'}, | ||
"line": {"pre": ' "', "post": '" +'}, | ||
}, | ||
"python": { | ||
"block": {"pre": "badchars = (\n", "post": '"\n)'}, | ||
"line": {"pre": ' "', "post": '"'}, | ||
}, | ||
} | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# DECORATOR | ||
# ------------------------------------------------------------------------------------------------- | ||
def formatOutput(f): | ||
"""Decorate/format the output of badchars.""" | ||
|
||
def new_f(length, format): | ||
if format is not None: | ||
sys.stdout.write(FORMATS[format]["block"]["pre"]) | ||
f(length, format) | ||
if format is not None: | ||
sys.stdout.write(FORMATS[format]["block"]["post"]) | ||
|
||
return new_f | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# FUNCTIONS | ||
# ------------------------------------------------------------------------------------------------- | ||
@formatOutput | ||
def print_badchars(length, format=None): | ||
"""Print bad characters.""" | ||
if format is None: | ||
for x in range(1, length + 1): | ||
sys.stdout.write("\\x" + "{:02x}".format(x)) | ||
else: | ||
linebreak = 16 | ||
rows = int(math.ceil(float(length) / linebreak)) | ||
count = 0 | ||
for row in range(1, rows + 1): | ||
sys.stdout.write(FORMATS[format]["line"]["pre"]) | ||
for char in range(1, linebreak + 1): | ||
if count == length: | ||
break | ||
count += 1 | ||
sys.stdout.write("\\x" + "{:02x}".format(count)) | ||
if count == length: | ||
break | ||
sys.stdout.write(FORMATS[format]["line"]["post"]) | ||
sys.stdout.write("\n") | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# ARG HELPER | ||
# ------------------------------------------------------------------------------------------------- | ||
def _args_check_length(value): | ||
"""Check arguments for valid length.""" | ||
min_len = 1 | ||
intvalue = int(value) | ||
|
||
if intvalue < min_len: | ||
raise argparse.ArgumentTypeError("%s is an invalid length." % value) | ||
return intvalue | ||
|
||
|
||
def _args_check_format(value): | ||
"""Check arguments for valid format.""" | ||
if value not in FORMATS: | ||
raise argparse.ArgumentTypeError("%s is an invalid format." % value) | ||
return value | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# ENTRYPOINT | ||
# ------------------------------------------------------------------------------------------------- | ||
def main(): | ||
"""Start the program.""" | ||
parser = argparse.ArgumentParser(description="Badchar generator.") | ||
parser.add_argument( | ||
"-v", | ||
"--version", | ||
action="version", | ||
version="%(prog)s 0.2 by cytopia", | ||
help="Show version information,", | ||
) | ||
parser.add_argument( | ||
"-l", | ||
"--length", | ||
metavar="int", | ||
required=False, | ||
type=_args_check_length, | ||
help="Length of badchars to create. Default: " + str(DEFAULT_LENGTH), | ||
) | ||
parser.add_argument( | ||
"-f", | ||
"--format", | ||
metavar="str", | ||
required=False, | ||
type=_args_check_format, | ||
help="Format output: " + ", ".join(FORMATS.keys()), | ||
) | ||
args = parser.parse_args() | ||
length = DEFAULT_LENGTH if args.length is None else args.length | ||
|
||
print_badchars(length, args.format) | ||
sys.stdout.write("\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
# Catch Ctrl+c and exit without error message | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
print() | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[metadata] | ||
description-file = README.md | ||
|
||
[bdist_wheel] | ||
universal=1 | ||
|
||
[pycodestyle] | ||
max-line-length = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from setuptools import setup | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name="badchars", | ||
version="0.2", | ||
description="A badchar generator for different formats.", | ||
license="MIT", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
author="cytopia", | ||
author_email="[email protected]", | ||
url="https://github.com/cytopia/badchars", | ||
install_requires=["argparse"], | ||
scripts=[ | ||
"badchars" | ||
], | ||
classifiers=[ | ||
# How mature is this project? Common values are | ||
# 3 - Alpha | ||
# 4 - Beta | ||
# 5 - Production/Stable | ||
'Development Status :: 5 - Production/Stable', | ||
|
||
# Indicate who your project is intended for | ||
'Intended Audience :: Developers', | ||
'Topic :: Software Development :: Build Tools', | ||
|
||
# License | ||
"License :: OSI Approved :: MIT License", | ||
|
||
# Specify the Python versions you support here. In particular, ensure | ||
# that you indicate whether you support Python 2, Python 3 or both. | ||
"Programming Language :: Python :: 2", | ||
"Programming Language :: Python :: 3", | ||
"Operating System :: OS Independent", | ||
], | ||
) |