Skip to content

Commit

Permalink
Initial shot at Python 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
bkabrda committed Apr 13, 2015
1 parent 1b01533 commit 05a7a47
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"

install:
- python setup.py install
Expand All @@ -18,3 +19,4 @@ notifications:
matrix:
allow_failures:
- python: "3.3"
- python: "3.4"
9 changes: 5 additions & 4 deletions extras/git-hooks/post-receive
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import sys
from collections import defaultdict

import pygit2
import six

import fedmsg
import fedmsg.config
Expand All @@ -21,7 +22,7 @@ username = getpass.getuser()

repo = pygit2.Repository(abspath)

print "Emitting a message to the fedmsg bus."
print("Emitting a message to the fedmsg bus.")
config = fedmsg.config.load_config([], None)
config['active'] = True
config['endpoints']['relay_inbound'] = config['relay_inbound']
Expand Down Expand Up @@ -89,7 +90,7 @@ for line in lines:
revs = [head.id]

def _build_commit(rev):
commit = repo.revparse_single(unicode(rev))
commit = repo.revparse_single(six.text_type(rev))

# Tags are a little funny, and vary between versions of pygit2, so we'll
# just ignore them as far as fedmsg is concerned.
Expand All @@ -108,7 +109,7 @@ for line in lines:
files=files,
total=total,
),
rev=unicode(rev),
rev=six.text_type(rev),
path=abspath,
repo=repo_name,
branch=branch,
Expand All @@ -117,7 +118,7 @@ for line in lines:

commits = map(_build_commit, revs)

print "* Publishing information for %i commits" % len(commits)
print("* Publishing information for %i commits" % len(commits))
for commit in reversed(commits):
if commit is None:
continue
Expand Down
8 changes: 4 additions & 4 deletions extras/stress/mass-sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ def run(self):
thread.start()

pid = os.getpid()
print prefix, "Checking pid", pid
print(prefix, "Checking pid", pid)
target = 200
length = 0
while length <= target:
length = len(os.listdir("/proc/%i/fd/" % os.getpid()))
print prefix, length, "is less than", target
print(prefix, length, "is less than", target)
time.sleep(1)

print prefix, "ready to receive..."
print(prefix, "ready to receive...")

for thread in threads:
thread.join()

print prefix, "Done."
print(prefix, "Done.")
2 changes: 1 addition & 1 deletion fedmsg/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def execute(self):
try:
return self.run()
except KeyboardInterrupt:
print
print()
2 changes: 1 addition & 1 deletion fedmsg/commands/collectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def dump(self):
# Print out the collectd feedback.
# This is sent to stdout while other log messages are sent to stderr.
for k, v in sorted(self._dict.items()):
print self.formatter(k, v)
print(self.formatter(k, v))

# Reset each entry to zero
for k, v in sorted(self._dict.items()):
Expand Down
3 changes: 2 additions & 1 deletion fedmsg/commands/tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import pygments
import pygments.lexers
import pygments.formatters
import six

import fedmsg
import fedmsg.encoding
Expand Down Expand Up @@ -139,7 +140,7 @@ def formatter(d):
if self.config['query']:
def formatter(d):
result = fedmsg.utils.dict_query(d, self.config['query'])
return ", ".join([unicode(value) for value in result.values()])
return ", ".join([six.text_type(value) for value in result.values()])

if self.config['terse']:
formatter = lambda d: "\n" + fedmsg.meta.msg2repr(d, **self.config)
Expand Down
14 changes: 7 additions & 7 deletions fedmsg/commands/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import subprocess
import sys
import threading
import Queue
from six.moves import queue

import fedmsg
import fedmsg.encoding
Expand Down Expand Up @@ -110,11 +110,11 @@ def run(self):
max_queue_size = int(self.config['max_queue_size'])

timer = None
queue = Queue.Queue()
que = queue.Queue()

def execute_queue():
while not queue.empty():
message = queue.get()
while not que.empty():
message = que.get()

result = self.run_command(self.config['command'], message)

Expand All @@ -129,7 +129,7 @@ def execute_queue():
if not inclusive_regexp.search(topic):
continue

queue.put(message)
que.put(message)

if timer is not None:
# Try to cancel it
Expand All @@ -138,8 +138,8 @@ def execute_queue():
# Either there was no timer yet, or it was still waiting
# -> Let's start a new one
if (max_queue_size > 0 and
queue.qsize() > max_queue_size):
# If the queue is too big, let's just run it NOW
que.qsize() > max_queue_size):
# If the que is too big, let's just run it NOW
timer = threading.Timer(0, execute_queue)
else:
timer = threading.Timer(wait_for,
Expand Down
2 changes: 1 addition & 1 deletion fedmsg/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def tail_messages(self, topic="", passive=False, **kw):
failed_hostnames = []
subs = {}
watched_names = {}
for _name, endpoint_list in self.c['endpoints'].iteritems():
for _name, endpoint_list in six.iteritems(self.c['endpoints']):

# You never want to actually subscribe to this thing, but sometimes
# it appears in the endpoints list due to a hack where it gets
Expand Down
5 changes: 5 additions & 0 deletions fedmsg/crypto/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
log.warn("Crypto disabled %r" % e)
disabled = True

import six

if six.PY3:
long = int


def sign(message, ssldir=None, certname=None, **config):
""" Insert two new fields into the message dict and return it.
Expand Down
11 changes: 8 additions & 3 deletions fedmsg/meta/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import time

import arrow
import six


class BaseProcessor(object):
Expand Down Expand Up @@ -187,6 +188,7 @@ def avatars(self, msg, **config):
return dict()


@six.add_metaclass(abc.ABCMeta)
class BaseConglomerator(object):
""" Base Conglomerator. This abstract base class must be extended.
Expand All @@ -202,8 +204,6 @@ class BaseConglomerator(object):
This BaseConglomerator is meant to be extended many times over to provide
plugins that know how to conglomerate different combinations of messages.
"""
__metaclass__ = abc.ABCMeta

def __init__(self, processor, internationalization_callable, **conf):
self.processor = processor
self._ = internationalization_callable
Expand Down Expand Up @@ -320,7 +320,12 @@ def list_to_series(items, N=3, oxford_comma=True):
if not items:
return "(nothing)"

items = list(set(items))
# uniqify items while preserving the order
olditems = items
items = []
for i in olditems:
if i not in items:
items.append(i)

if len(items) == 1:
return items[0]
Expand Down
Loading

0 comments on commit 05a7a47

Please sign in to comment.