diff --git a/.gitignore b/.gitignore index 5f79b0bb..d994a1c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ +*.bak *.pyc -.DS_Store -.venv +*.pyo *.secret *.swp +*.tmp +*~ +.DS_Store .vagrant/ +.venv +__pycache__ +github_pat.secret diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2acc07b8..aaa3161d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,18 +1,11 @@ # Opening a PR -Once you open a pull request, ChaosBot will give it X seconds (where X is -determined by github\_api.voting.get\_voting\_window) -before collecting votes. During this time, you should let people know about -your contribution, so that they may vote for it and ensure your hard work gets -merged in. If you do not wish for ChaosBot to consider your PR for merging just -yet, add "WIP" somewhere in your PR title. Remove it when you're ready for voting. + +Once you open a pull request, ChaosBot will give it X seconds (where X is determined by github\_api.voting.get\_voting\_window) before collecting votes. During this time, you should let people know about your contribution, so that they may vote for it and ensure your hard work gets merged in. If you do not wish for ChaosBot to consider your PR for merging just yet, add "WIP" somewhere in your PR title. Remove it when you're ready for voting. # Changing your PR -You may change your PR at any time without losing votes, but keep in mind, any -new changes will reset the vote window for additional time. + +You may change your PR at any time without losing votes, but keep in mind, any new changes will reset the vote window for additional time. # Merging your PR -At the end of the voting window, ChaosBot will review the votes, and if your PR -crosses a threshold, your changes will be merged in. To thank you for your merged -contribution, ChaosBot will then follow you on GitHub. If your changes are not -merged in, take the time to consider the feedback you received, and create a new -PR with changes you believe people will be willing to vote for. + +At the end of the voting window, ChaosBot will review the votes, and if your PR crosses a threshold, your changes will be merged in. To thank you for your merged contribution, ChaosBot will then follow you on GitHub. If your changes are not merged in, take the time to consider the feedback you received, and create a new PR with changes you believe people will be willing to vote for. diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/dev/vagrant/Vagrantfile b/dev/vagrant/Vagrantfile index ab69836e..c2a9e92b 100644 --- a/dev/vagrant/Vagrantfile +++ b/dev/vagrant/Vagrantfile @@ -1,5 +1,5 @@ # -*- mode: ruby -*- -# vi: set ft=ruby : +# vim: ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..7528b674 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1 @@ +From python:onbuild diff --git a/patch.py b/patch.py index b7a719a1..6d34b2ac 100644 --- a/patch.py +++ b/patch.py @@ -1,39 +1,28 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + """ -inject some memoize caching into our github api functions. we're keeping the -caching layer separate from the api layer by doing it this way +Inject some memoize caching into our github api functions. +We're keeping the caching layer separate from the api layer by doing it this way. """ +import inspect +import settings from os.path import dirname, abspath, join from functools import partial -import inspect - from memoize import memoize from memoize.backends import json_backend - import github_api.voting import github_api.repos -import settings - - -THIS_DIR = dirname(abspath(__file__)) - -api_backend = json_backend(join(THIS_DIR, settings.MEMOIZE_CACHE_DIRNAME)) - -# here we're creating a specialized memoize decorator that ignores the "api" -# argument in a function when constructing the memoize key. we do this because -# "api" is a resource that should not be considered as part of the memoize -# key -api_memoize = partial(memoize, blacklist={"api"}, backend=api_backend) - -# a helper for monkey-patch-decorating functions in different modules - - def decorate(fn, dec): + """helper for monkey-patch-decorating functions in different modules""" mod = inspect.getmodule(fn) new_fn = dec(fn) setattr(mod, fn.__name__, new_fn) +cache_dir = join(dirname(abspath(__file__)), settings.MEMOIZE_CACHE_DIRNAME) +api_memoize = partial(memoize, blacklist={"api"}, backend=json_backend(cache_dir)) # now let's memoize some very frequent api calls that don't change often decorate(github_api.voting.get_vote_weight, api_memoize("1d")) diff --git a/redditchaosbot.py b/redditchaosbot.py index 5a765725..8a16f888 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -1,6 +1,9 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import praw -from praw.models import MoreComments import pprint +from praw.models import MoreComments '''Authenticated instance of Reddit''' diff --git a/server/server.py b/server/server.py index 3cf12dde..1f3149a7 100644 --- a/server/server.py +++ b/server/server.py @@ -1,12 +1,12 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import http.server import socketserver import socket -# set the process name to "chaos_server" so we can easily kill it with -# "pkill chaos_server" - - def set_proc_name(newname): + """Change the process name using libc.so.6""" from ctypes import cdll, byref, create_string_buffer libc = cdll.LoadLibrary('libc.so.6') buff = create_string_buffer(len(newname) + 1) @@ -14,22 +14,27 @@ def set_proc_name(newname): libc.prctl(15, byref(buff), 0, 0, 0) -set_proc_name("chaos_server") - -# start server on port 80 -PORT = 80 -Handler = http.server.SimpleHTTPRequestHandler - - class NoTimeWaitTCPServer(socketserver.ThreadingTCPServer): - """ when a socket does is shutdown dance, it ends up in a TIME-WAIT state, - which can prevent rebinding on it quickly. here we say "shut up, socket", - let me rebind anyways even if you're in TIME-WAIT." that will teach it. """ + """When a socket does is shutdown dance, it ends up in a TIME-WAIT state, + which can prevent rebinding on it quickly. Here we say "shut up, socket", + let me rebind anyways even if you're in TIME-WAIT." That will teach it.""" def server_bind(self): self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.bind(self.server_address) -httpd = NoTimeWaitTCPServer(("", PORT), Handler) -httpd.serve_forever() +def main(): + # set the process name to "chaos_server" so we can easily kill it with: + # pkill chaos_server + set_proc_name("chaos_server") + + port = 80 + handler = http.server.SimpleHTTPRequestHandler + httpd = NoTimeWaitTCPServer(("", port), handler) + + # serve HTTP on port 80 + httpd.serve_forever() + +if __name__ == "__main__": + main() diff --git a/startup.d/40-run-puppet.sh b/startup.d/40-run-puppet.sh index df91cb15..400b0184 100644 --- a/startup.d/40-run-puppet.sh +++ b/startup.d/40-run-puppet.sh @@ -1,4 +1,3 @@ -#!/bin/bash - +#!/bin/sh cd puppet -puppet apply --verbose --modulepath=$PWD/modules/ $PWD/manifests/ +puppet apply --verbose --modulepath="$PWD/modules/" "$PWD/manifests/" diff --git a/startup.sh b/startup.sh index 57c2a280..9c34ed82 100755 --- a/startup.sh +++ b/startup.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash cd "$(dirname "$0")" for file in startup.d/*; do diff --git a/utils/utils.py b/utils/utils.py index 8f7e0fbd..386601ad 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import json import os import logging