Skip to content

Commit

Permalink
minor refactors/pep8tification (#414)
Browse files Browse the repository at this point in the history
* minor changes/pep8tification
  • Loading branch information
pravinkc authored and jeremycline committed Jun 12, 2017
1 parent 5899512 commit f0553d2
Show file tree
Hide file tree
Showing 39 changed files with 168 additions and 195 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
sudo: true
language: python

# Twisted dropped Python 2.6 support, so install a compatible version on 2.6
install:
- sudo apt-get install swig
- pip install --upgrade pip setuptools
Expand Down
89 changes: 43 additions & 46 deletions doc/conf.py
Expand Up @@ -16,13 +16,10 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os

# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#sys.path.append(os.path.abspath('.'))
# sys.path.append(os.path.abspath('.'))

# General configuration
# ---------------------
Expand All @@ -41,39 +38,39 @@

# [optional] set some of the options listed above...
html_theme_options = {
"sidebarwidth": "200px",
"max_width": "900px",
"compact_width": "800px",
"minimal_width": "700px",
"sidebarwidth": "200px",
"max_width": "900px",
"compact_width": "800px",
"minimal_width": "700px",

# Style it like Fedora..
"bodyfont": "Cantarell",
"bodyfont": "Cantarell",

"highlightcolor": "#4FAF4F",
"highlightcolor": "#4FAF4F",

"sidebarbgcolor": "#FEFEFE",
"sidebarbgcolor": "#FEFEFE",
"sidebartrimcolor": "#FEFEFE",

"sectionbgcolor": "#FEFEFE",
"sectionbgcolor": "#FEFEFE",
"sectiontrimcolor": "#FEFEFE",
"sectiontextcolor": "#444444",

"relbarbgcolor": "#FEFEFE",
"relbartextcolor": "#444444",
"relbarlinkcolor": "#444444",
"relbarbgcolor": "#FEFEFE",
"relbartextcolor": "#444444",
"relbarlinkcolor": "#444444",

"bgcolor": "#FEFEFE",
"textcolor": "#444444",
"linkcolor": "#060", # First Green
"bgcolor": "#FEFEFE",
"textcolor": "#444444",
"linkcolor": "#060", # First Green

"headtextcolor": "#444444",
"headlinkcolor": "#444444",
"headtextcolor": "#444444",
"headlinkcolor": "#444444",

#"codebgcolor"
#"codetextcolor"
"codetrimcolor": "#060", # First Green
# "codebgcolor"
# "codetextcolor"
"codetrimcolor": "#060", # First Green

"footerbgcolor": "#FEFEFE",
"footerbgcolor": "#FEFEFE",

}

Expand All @@ -89,7 +86,7 @@
source_suffix = '.rst'

# The encoding of source files.
#source_encoding = 'utf-8'
# source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'index'
Expand All @@ -109,35 +106,35 @@

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'

# List of documents that shouldn't be included in the build.
#unused_docs = []
# unused_docs = []

# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['.build']

# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
Expand All @@ -153,19 +150,19 @@

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# html_title = None

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# html_logo = None

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# html_favicon = None

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand All @@ -174,11 +171,11 @@

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
html_sidebars = {
Expand All @@ -192,27 +189,27 @@

# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# html_additional_pages = {}

# If false, no module index is generated.
#html_use_modindex = True
# html_use_modindex = True

# If false, no index is generated.
#html_use_index = True
# html_use_index = True

# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False

# If true, the reST sources are included in the HTML build as _sources/<name>.
#html_copy_source = True
# html_copy_source = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''

# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# html_file_suffix = ''

# Output file base name for HTML help builder.
htmlhelp_basename = 'fedmsg'
1 change: 1 addition & 0 deletions extras/stress/mass-sub.py
Expand Up @@ -37,6 +37,7 @@ def run(self):
topic, msg = self.s.recv_multipart()
sys.stdout.flush()


threads = [ThreadedJob() for i in range(N)]
for thread in threads:
thread.start()
Expand Down
20 changes: 9 additions & 11 deletions fedmsg.d/base.py
Expand Up @@ -17,8 +17,6 @@
#
# Authors: Ralph Bean <rbean@redhat.com>

import os

config = dict(
# Set this to dev if you're hacking on fedmsg or an app.
# Set to stg or prod if running in the Fedora Infrastructure
Expand All @@ -31,11 +29,11 @@
## For the fedmsg-hub and fedmsg-relay. ##

# This is a status dir to keep a record of the last processed message
#status_directory=os.getcwd() + "/status",
#status_directory='/var/run/fedmsg/status',
# status_directory=os.getcwd() + "/status",
# status_directory='/var/run/fedmsg/status',

# This is the URL of a datagrepper instance that we can query for backlog.
#datagrepper_url="https://apps.fedoraproject.org/datagrepper/raw",
# datagrepper_url="https://apps.fedoraproject.org/datagrepper/raw",

# We almost always want the fedmsg-hub to be sending messages with zmq as
# opposed to amqp or stomp. You can send with only *one* of the messaging
Expand All @@ -46,12 +44,12 @@

# On the other hand, if you wanted to use STOMP *instead* of zeromq, you
# could do the following...
#zmq_enabled=False,
#stomp_uri='localhost:59597,localhost:59598',
#stomp_user='username',
#stomp_pass='password',
#stomp_ssl_crt='/path/to/an/optional.crt',
#stomp_ssl_key='/path/to/an/optional.key',
# zmq_enabled=False,
# stomp_uri='localhost:59597,localhost:59598',
# stomp_user='username',
# stomp_pass='password',
# stomp_ssl_crt='/path/to/an/optional.crt',
# stomp_ssl_key='/path/to/an/optional.key',

# When subscribing to messages, we want to allow splats ('*') so we tell
# the hub to not be strict when comparing messages topics to subscription
Expand Down
10 changes: 5 additions & 5 deletions fedmsg.d/endpoints.py
Expand Up @@ -26,13 +26,13 @@
# infrastructure's bus. Cool, right? :)
"fedora-infrastructure": [
"tcp://hub.fedoraproject.org:9940",
#"tcp://stg.fedoraproject.org:9940",
# "tcp://stg.fedoraproject.org:9940",
],
#"debian-infrastructure": [
# "debian-infrastructure": [
# "tcp://fedmsg.olasd.eu:9940",
#],
#"anitya-public-relay": [
# ],
# "anitya-public-relay": [
# "tcp://release-monitoring.org:9940",
#],
# ],
},
)
3 changes: 1 addition & 2 deletions fedmsg.d/ssl.py
Expand Up @@ -18,7 +18,6 @@
# Authors: Ralph Bean <rbean@redhat.com>
#
import os
import socket

SEP = os.path.sep
here = os.getcwd()
Expand All @@ -43,7 +42,7 @@
certnames={
# In prod/stg, map hostname to the name of the cert in ssldir.
# Unfortunately, we can't use socket.getfqdn()
#"app01.stg": "app01.stg.phx2.fedoraproject.org",
# "app01.stg": "app01.stg.phx2.fedoraproject.org",
},

# A mapping of fully qualified topics to a list of cert names for which
Expand Down
6 changes: 3 additions & 3 deletions fedmsg/__init__.py
Expand Up @@ -21,6 +21,7 @@

import inspect
import threading
import functools

import fedmsg.core
import fedmsg.config
Expand Down Expand Up @@ -65,6 +66,7 @@ def API_function(doc=None):
def api_function(func):
scrub = inspect.getargspec(func).args

@functools.wraps(func)
def _wrapper(*args, **kw):
if not hasattr(__local, '__context'):
config_overrides = kw.copy()
Expand All @@ -82,17 +84,15 @@ def _wrapper(*args, **kw):
_wrapper.__doc__ = func.__doc__
else:
_wrapper.__doc__ = doc

_wrapper.__name__ = func.__name__
return _wrapper

return api_function


@API_function(doc=fedmsg.core.FedMsgContext.publish.__doc__)
def publish(topic=None, msg=None, **kw):
return __local.__context.publish(topic, msg, **kw)


# This is old-school, and deprecated.
send_message = publish

Expand Down
11 changes: 5 additions & 6 deletions fedmsg/commands/__init__.py
Expand Up @@ -21,7 +21,6 @@
import fedmsg.config
import warnings
import six
import sys

import logging
try:
Expand Down Expand Up @@ -89,12 +88,12 @@ def _daemonize(self):
self.log.warn("PID file exists but with no proc: coup d'etat!")
pidlock.break_lock()

output = file('/var/log/fedmsg/%s.log' % self.name, 'a')
daemon = DaemonContext(pidfile=pidlock, stdout=output, stderr=output)
daemon.terminate = self._handle_signal
with open('/var/log/fedmsg/%s.log' % self.name, 'a') as output:
daemon = DaemonContext(pidfile=pidlock, stdout=output, stderr=output)
daemon.terminate = self._handle_signal

with daemon:
return self.run()
with daemon:
return self.run()

def execute(self):
if self.daemonizable and self.config['daemon'] is True:
Expand Down
4 changes: 1 addition & 3 deletions fedmsg/commands/config.py
Expand Up @@ -24,7 +24,6 @@
import argparse
import six
import sys
import textwrap

import fedmsg.config
import fedmsg.encoding
Expand Down Expand Up @@ -95,8 +94,7 @@ def config():
if args.query:
cur = fedmsg.utils.dict_query(cur, args.query)[args.query]
if cur is None:
print ("Key `%s` does not exist in config" % args.query,
file=sys.stderr)
print("Key `%s` does not exist in config" % args.query, file=sys.stderr)
sys.exit(1)

if isinstance(cur, list):
Expand Down
1 change: 0 additions & 1 deletion fedmsg/commands/gateway.py
Expand Up @@ -20,7 +20,6 @@
"""
"""

import fedmsg
from fedmsg.commands import BaseCommand
from fedmsg.consumers.gateway import GatewayConsumer

Expand Down

0 comments on commit f0553d2

Please sign in to comment.