Skip to content

Commit

Permalink
Massive pep8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skoczen committed Feb 27, 2015
1 parent 80e5016 commit 804aaf3
Show file tree
Hide file tree
Showing 36 changed files with 201 additions and 127 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This is a first pass at a contribution doc, and will change, but for starters:

- Incoming code should follow PEP8
- Incoming code should follow PEP8 ( run `flake8` )
- If you add new core-level features, write some quick docs in the README. If you're not sure if they're needed, just ask!
- Add your name and attribution to the AUTHORS file.
- Know you have our thanks for helping to make will even better!
34 changes: 16 additions & 18 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
# Welcome to Will's settings.
#
#

# Config and the environment:
# ---------------------------
# Will can use settings from the environment or this file, and sets reasonable defaults.
#
# Best practices: set keys and the like in the environment, and anything you'd be ok
#
# Best practices: set keys and the like in the environment, and anything you'd be ok
# with other people knowing in this file.
#
# To specify in the environment, just prefix with WILL_
# (i.e. WILL_DEFAULT_ROOM becomes DEFAULT_ROOM).
#
# To specify in the environment, just prefix with WILL_
# (i.e. WILL_DEFAULT_ROOM becomes DEFAULT_ROOM).
# In case of conflict, you will see a warning message, and the value in this file will win.



# ------------------------------------------------------------------------------------
# Required settings
# ------------------------------------------------------------------------------------

# The list of plugin modules will should load.
# The list of plugin modules will should load.
# Will recursively loads all plugins contained in each module.


# This list can contain:
#
#
# Built-in core plugins:
# ----------------------
# All built-in modules: will.plugins
Expand All @@ -35,7 +33,7 @@
# All modules: plugins
# A specific module: plugins.module_name
# Specific plugins: plugins.module_name.plugin
#
#
# Plugins anywhere else on your PYTHONPATH:
# -----------------------------------------
# All modules: someapp
Expand All @@ -44,7 +42,7 @@


# By default, the list below includes all the core will plugins and
# all your project's plugins.
# all your project's plugins.

PLUGINS = [
# Built-ins
Expand All @@ -62,9 +60,9 @@

# Don't load any of the plugins in this list. Same options as above.
PLUGIN_BLACKLIST = [
# "will.plugins.friendly.cookies", # But who would deprive will of cookies??
"will.plugins.productivity.hangout", # Because it requires a HANGOUT_URL
"will.plugins.productivity.world_time", # Because it requires a WORLD_WEATHER_ONLINE_V2_KEY key
# "will.plugins.friendly.cookies", # But who would deprive will of cookies??
"will.plugins.productivity.hangout", # Because it requires a HANGOUT_URL
"will.plugins.productivity.world_time", # Because it requires a WORLD_WEATHER_ONLINE_V2_KEY key
]


Expand All @@ -89,15 +87,15 @@
# ROOMS = ['Testing, Will Kahuna',]


# The room will will talk to if the trigger is a webhook and he isn't told a specific room.
# The room will will talk to if the trigger is a webhook and he isn't told a specific room.
# Default is the first of ROOMS.
# DEFAULT_ROOM = 'Testing, Will Kahuna'


# Fully-qualified folders to look for templates in, beyond the two that
# Fully-qualified folders to look for templates in, beyond the two that
# are always included: core will's templates folder, your project's templates folder, and
# all templates folders in included plugins, if they exist.
#
#
# TEMPLATE_DIRS = [
# os.path.abspath("other_folder/templates")
# ]
Expand Down
3 changes: 1 addition & 2 deletions docs/improve.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ If you're looking for plugin inspiration, here are some wills that are open-sour

## Releases

#### 0.8 - February 27, 2015
#### 0.7.2 - February 27, 2015

* Big upgrade! Now only `WILL_USERNAME` and `WILL_PASSWORD` are needed. This solves the impending one-year V2 token expiry, and the need for a V1 token at all.
* Improved handling when `.reply()` is called incorrectly, thanks to a report by [dothak](https://github.com/dothak)
* Fixed the [annoying](https://github.com/skoczen/will/issues/78) "github's ok" on first launch.
* Restored Python 2.6 compatability thanks to the report and patience of [JPerkster](https://github.com/JPerkster).
Expand Down
24 changes: 14 additions & 10 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,65 @@
from fabric.api import *

SITE_DIR = "site"
WHITELIST_DIRS = [".git",]
WHITELIST_FILES = [ ".gitignore", ]
WHITELIST_DIRS = [".git", ]
WHITELIST_FILES = [".gitignore", ]

SANITY_CHECK_PROJECT_FILES = ["fabfile.py", "setup.py", "mkdocs.yml"]
SANITY_CHECK_BUILD_FILES = ["index.html", "js", "css"]


def _splitpath(path):
path = os.path.normpath(path)
return path.split(os.sep)


def tag_release():
# Tag the release:
local("git tag %s" % VERSION)
local("git push --tags")


def upload_release():
local("python setup.py sdist upload")


def release():
deploy_docs()
upload_release()
tag_release()


def deploy_docs():
# Sanity check dir.
root_dir = os.getcwd()
assert all([os.path.exists(os.path.join(root_dir,f)) for f in SANITY_CHECK_PROJECT_FILES])
assert all([os.path.exists(os.path.join(root_dir, f)) for f in SANITY_CHECK_PROJECT_FILES])

local("rm -rf %s" % SITE_DIR)
local("mkdocs build")
tempdir = tempfile.mkdtemp()

local("mv %s/* %s" % (SITE_DIR, tempdir))

current_branch = local("git rev-parse --abbrev-ref HEAD", capture=True)
last_commit = local("git log -1 --pretty=\%B", capture=True)

# Add the new site to build
local("git checkout gh-pages")

# Sanity check dir.
root_dir = os.getcwd()
assert all([os.path.exists(os.path.join(root_dir,f)) for f in SANITY_CHECK_BUILD_FILES])

assert all([os.path.exists(os.path.join(root_dir, f)) for f in SANITY_CHECK_BUILD_FILES])

for root, dirs, files in os.walk(root_dir, topdown=False):
for name in files:
if not name in WHITELIST_FILES and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
if name not in WHITELIST_FILES and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
# print "removing %s" % (os.path.join(root, name))
os.remove(os.path.join(root, name))
for name in dirs:
if not name in WHITELIST_DIRS and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
if name not in WHITELIST_DIRS and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
# print "removing %s" % (os.path.join(root, name))
os.rmdir(os.path.join(root, name))

local("cp -rv %s/* ." % tempdir)
with settings(warn_only=True):
result = local("git diff --exit-code")
Expand Down
1 change: 1 addition & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ sleekxmpp>=1.2
pyandoc
mkdocs
fabric
flake8
mock
nose
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/usr/bin/env python
#!/usr/bin/env python
import os
from setuptools import setup, find_packages
from will import __name__ as PACKAGE_NAME
Expand Down Expand Up @@ -31,11 +31,11 @@
author_email="skoczen@gmail.com",
url="https://github.com/skoczen/will",
version=VERSION,
download_url = ['https://github.com/skoczen/will/tarball/%s' % VERSION, ],
download_url=['https://github.com/skoczen/will/tarball/%s' % VERSION, ],
install_requires=reqs,
packages=find_packages(),
include_package_data=True,
keywords = ["hipchat", "bot"],
keywords=["hipchat", "bot"],
classifiers=[
"Programming Language :: Python",
"License :: OSI Approved :: BSD License",
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = F401,N812,F403,E721,E713
max-line-length = 120
# exclude = tests/*
max-complexity = 12
2 changes: 1 addition & 1 deletion will/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.8"
VERSION = "0.7.2"
35 changes: 21 additions & 14 deletions will/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def start_xmpp_client(self):
self.whitespace_keepalive = True
self.whitespace_keepalive_interval = 30

if settings.ALLOW_INSECURE_HIPCHAT_SERVER == True:
if settings.ALLOW_INSECURE_HIPCHAT_SERVER is True:
self.add_event_handler('ssl_invalid_cert', lambda cert: True)

self.add_event_handler("roster_update", self.join_rooms)
self.add_event_handler("session_start", self.session_start)
self.add_event_handler("message", self.message_recieved)
self.add_event_handler("groupchat_message", self.room_message)

self.register_plugin('xep_0045') # MUC
self.register_plugin('xep_0045') # MUC

def session_start(self, event):
self.send_presence()
Expand Down Expand Up @@ -100,12 +100,10 @@ def update_will_roster_and_rooms(self):
def room_message(self, msg):
self._handle_message_listeners(msg)


def message_recieved(self, msg):
if msg['type'] in ('chat', 'normal'):
self._handle_message_listeners(msg)


def real_sender_jid(self, msg):
# There's a bug in sleekXMPP where it doesn't set the "from_jid" properly.
# Thus, this hideous hack.
Expand All @@ -118,17 +116,21 @@ def real_sender_jid(self, msg):

return msg["from"]


def _handle_message_listeners(self, msg):
if (self.some_listeners_include_me # I've been asked to listen to my own messages
or (msg['type'] in ('chat', 'normal') and self.real_sender_jid(msg) != self.me.jid) # or we're in a 1 on 1 chat and I didn't send it
or (msg["type"] == "groupchat" and msg['mucnick'] != self.nick) ): # we're in group chat and I didn't send it
if (
# I've been asked to listen to my own messages
self.some_listeners_include_me
# or we're in a 1 on 1 chat and I didn't send it
or (msg['type'] in ('chat', 'normal') and self.real_sender_jid(msg) != self.me.jid)
# we're in group chat and I didn't send it
or (msg["type"] == "groupchat" and msg['mucnick'] != self.nick)
):
body = msg["body"]

sent_directly_to_me = False
# If it's sent directly to me, strip off "@will" from the start.
if body[:len(self.handle) + 1].lower() == ("@%s" % self.handle).lower():
body = body[len(self.handle)+1:].strip()
body = body[len(self.handle) + 1:].strip()
msg["body"] = body

sent_directly_to_me = True
Expand All @@ -140,12 +142,17 @@ def _handle_message_listeners(self, msg):
for l in self.message_listeners:
search_matches = l["regex"].search(body)
if (search_matches # The search regex matches and
and (msg['mucnick'] != self.nick or l["include_me"]) # It's not from me, or this search includes me, and
and (msg['type'] in ('chat', 'normal') or not l["direct_mentions_only"] or self.handle_regex.search(body) or sent_directly_to_me) # I'm mentioned, or this is an overheard, or we're in a 1-1
and ((l['admin_only'] and self.message_is_from_admin(msg)) or (not l['admin_only'])) # It's from admins only and sender is an admin, or it's not from admins only
):
# It's not from me, or this search includes me, and
and (msg['mucnick'] != self.nick or l["include_me"])
# I'm mentioned, or this is an overheard, or we're in a 1-1
and (msg['type'] in ('chat', 'normal') or not l["direct_mentions_only"] or
self.handle_regex.search(body) or sent_directly_to_me)
# It's from admins only and sender is an admin, or it's not from admins only
and ((l['admin_only'] and self.message_is_from_admin(msg)) or (not l['admin_only']))
):
try:
thread_args = [msg,] + l["args"]
thread_args = [msg, ] + l["args"]

def fn(listener, args, kwargs):
try:
listener["fn"](*args, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions will/mixins/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from will import settings
from will.decorators import require_settings


class EmailMixin(object):

def send_email(self, from_email=None, email_list=[], subject="", message=""):
Expand Down
3 changes: 2 additions & 1 deletion will/mixins/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import traceback


class ErrorMixin(object):
def get_startup_errors(self):
if hasattr(self, "_startup_errors"):
Expand All @@ -21,4 +22,4 @@ def startup_error(self, error_message, exception_instance):
logging.critical(error_message)

def runtime_error(self, error_message):
logging.critical(error_message)
logging.critical(error_message)
1 change: 0 additions & 1 deletion will/mixins/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ def get_room_from_name_or_id(self, name_or_id):
if "room_id" in room and name_or_id == room["room_id"]:
return room
return None

Loading

0 comments on commit 804aaf3

Please sign in to comment.