Last active
July 13, 2018 21:42
-
-
Save Resisty/1e9abb764eb52a0791a798c8d7c7b356 to your computer and use it in GitHub Desktop.
setup.py
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
#!/usr/bin/env python | |
''' This module serves as a weird example for some nonsense for a friend | |
Place this file in chbuildstatus/ | |
''' | |
import argparse | |
import logging | |
import re | |
import requests | |
FORMAT = """[%(asctime)s] '%(message)s'""" | |
logging.basicConfig(format=FORMAT) | |
LOGGER = logging.getLogger() | |
def fmt_build_url(build_url): | |
''' make sure the build_url formats | |
''' | |
LOGGER.info('Got a build_url: %s', build_url) | |
build_key = None | |
try: | |
build_key = build_url.split('/')[-1] | |
build_key = ('Drone' if 'drone.squarespace.net' in build_url | |
else build_key) | |
assert build_key | |
assert re.match(r'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', build_url) | |
except AssertionError as err: | |
LOGGER.exception('Invalid build_url: %s', build_url) | |
raise RuntimeError(str(err)) | |
LOGGER.info('Found build key: %s', build_key) | |
return build_key | |
def update_build(args): | |
''' Defaults function, called by argparse to create a review | |
''' | |
LOGGER.info('%s a build (%s) for commit %s or something', | |
args.state.capitalize(), | |
args.build_url, | |
args.commit) | |
def chbuildstatus_main(): | |
''' Main function invoked at runtime | |
''' | |
parser = argparse.ArgumentParser('Parse arguments') | |
parser.add_argument('commit', | |
help='The commit') | |
parser.add_argument('build_url', | |
help='The build url', | |
type=fmt_build_url) | |
parser.add_argument('state', | |
help='Success state to us.', | |
choices=['succeed', 'fail']) | |
parser.add_argument("-v", '--verbose', | |
help="Verbose", | |
action='count', | |
default=0) | |
parser.set_defaults(func=update_build) | |
args = parser.parse_args() | |
levels = [logging.WARN, logging.INFO, logging.DEBUG] | |
level = levels[min(len(levels)-1, args.verbose)] | |
LOGGER.setLevel(level) | |
args.func(args) | |
if __name__ == '__main__': | |
chbuildstatus_main() |
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
# Place this file in chbuildstatus/ | |
from . import chbuildstatus_main | |
def main(): | |
''' Provide entrypoint to main console script | |
''' | |
chbuildstatus_main() |
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
#!/usr/bin/env python | |
''' Module for setting up chbuildstatus CLI tool(s) | |
''' | |
#pylint: disable=unused-import | |
from setuptools import setup, find_packages | |
setup( | |
name='chbuildstatus', | |
version='0.1', | |
entry_points={ | |
'console_scripts': [ | |
'chbuildstatus=chbuildstatus.command_line:main', | |
], | |
}, | |
packages=[ | |
'chbuildstatus', | |
], | |
install_requires=[ | |
'requests' | |
] | |
) |
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
(venv๐ ) some_jerk@some_laptop ~/deleteme ๐ ๐ด ๐ chbuildstatus -vvvv commit-butts http://thing.stuff.butts/lol succeed | |
[2018-07-13 14:38:59,881] 'Succeed a build (lol) for commit commit-butts or something' | |
(venv๐ ) some_jerk@some_laptop ~/deleteme ๐ ๐ด ๐ chbuildstatus -vvvv commit-butts http://thing.stuff.butts/lol fail | |
[2018-07-13 14:39:05,374] 'Fail a build (lol) for commit commit-butts or something' | |
(venv๐ ) some_jerk@some_laptop ~/deleteme ๐ ๐ด ๐ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment