Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modern twisted fix #4

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ flumotion/component/consumers/fgdp/Makefile
flumotion/component/consumers/icystreamer/Makefile
flumotion/component/consumers/httpstreamer/Makefile
flumotion/component/consumers/hlsstreamer/Makefile
flumotion/component/consumers/justintv/Makefile
flumotion/component/consumers/pipeline/Makefile
flumotion/component/consumers/preview/Makefile
flumotion/component/consumers/shout2/Makefile
Expand Down
30 changes: 1 addition & 29 deletions flumotion/common/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,6 @@
__version__ = "$Rev$"


class _PatchedModuleImporter(ihooks.ModuleImporter):
"""
I am overriding ihook's ModuleImporter's import_module() method to
accept (and ignore) the 'level' keyword argument that appeared in
the built-in __import__() function in python2.5.

While no built-in modules in python2.5 seem to use that keyword
argument, 'encodings' module in python2.6 does and so it breaks if
used together with ihooks.

I make no attempt to properly support the 'level' argument -
ihooks didn't make it into py3k, and the only use in python2.6
we've seen so far, in 'encodings', serves as a performance hint
and it seems that can be ignored with no difference in behaviour.
"""

def import_module(self, name, globals=None, locals=None, fromlist=None,
level=-1):
# all we do is drop 'level' as ihooks don't support it, anyway
return ihooks.ModuleImporter.import_module(self, name, globals,
locals, fromlist)


class PackageHooks(ihooks.Hooks):
"""
I am an import Hooks object that makes sure that every package that gets
Expand Down Expand Up @@ -106,12 +83,7 @@ def install(self):
self.debug('installing custom importer')
self._hooks = PackageHooks()
self._hooks.packager = self
if sys.version_info < (2, 6):
self._importer = ihooks.ModuleImporter()
else:
self.debug('python2.6 or later detected - using patched'
' ModuleImporter')
self._importer = _PatchedModuleImporter()
self._importer = ihooks.ModuleImporter()
self._importer.set_hooks(self._hooks)
self._importer.install()

Expand Down
12 changes: 6 additions & 6 deletions flumotion/component/common/streamer/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ def updatePorterDetails(self, path, username, password):
self._pbclient.stopTrying() # Stop trying to connect with the
# old connector.
self._pbclient.resetDelay()
reactor.connectWith(
fdserver.FDConnector, self._porterPath,
self._pbclient, 10, checkPID=False)
c = fdserver.FDConnector(self._porterPath, self._pbclient,
10, checkPID=False, reactor=reactor)
c.connect()
else:
raise errors.WrongStateError(
"Can't specify porter details in master mode")
Expand Down Expand Up @@ -624,9 +624,9 @@ def do_setup(self):

self.info("Starting porter login at \"%s\"", self._porterPath)
# This will eventually cause d to fire
reactor.connectWith(
fdserver.FDConnector, self._porterPath,
self._pbclient, 10, checkPID=False)
c = fdserver.FDConnector(self._porterPath, self._pbclient,
10, checkPID=False, reactor=reactor)
c.connect()
else:
# Streamer is standalone.
try:
Expand Down
1 change: 1 addition & 0 deletions flumotion/component/consumers/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SUBDIRS = \
icystreamer \
hlsstreamer \
httpstreamer \
justintv \
pipeline \
preview \
shout2
10 changes: 10 additions & 0 deletions flumotion/component/consumers/justintv/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include $(top_srcdir)/common/python.mk

component_PYTHON = __init__.py justintv.py
componentdir = $(libdir)/flumotion/python/flumotion/component/consumers/justintv
component_DATA = justintv.xml

clean-local:
rm -rf *.pyc *.pyo

EXTRA_DIST = $(component_DATA)
18 changes: 18 additions & 0 deletions flumotion/component/consumers/justintv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.

__version__ = "$Rev: 5969 $"
60 changes: 60 additions & 0 deletions flumotion/component/consumers/justintv/justintv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.

from flumotion.component import feedcomponent

__all__ = ['Consumer']
__version__ = "$Rev: 7162 $"


class JustinTV(feedcomponent.MultiInputParseLaunchComponent):
LINK_MUXER=False

def get_pipeline_string(self, properties):
self._justintv_user = properties['justintv-user']
self._justintv_key = properties['justintv-key']

assert 'video' in self.eaters
assert 'audio' in self.eaters

# These settings from from
# http://apiwiki.justin.tv/mediawiki/index.php/VLC_Broadcasting_API

#video/x-raw-yuv, width= !
#x264{keyint=60,idrint=2},vcodec=h264,vb=300
videopipe = """\
@ eater:video @ !
videoscale !
x264enc bframes=0 key-int-max=2 bitrate=300 !
muxer.
"""
# acodec=mp4a,ab=32,channels=2,samplerate=2205
audiopipe = """\
@ eater:audio @ !
audioconvert !
audioresample !
audio/x-raw-int,channels=1,samplerate=44100 !
lamemp3enc bitrate=64 mono=1 target=bitrate cbr=1 !
muxer.
"""
# gst-launch-0.10 -v videotestsrc ! ffenc_flv ! flvmux ! rtmpsink location='rtmp://live.justin.tv/app/live_22076196_raZAJ55hsNU4Z9LN130N1GL71KJok6 live=1'
outputpipe = """\
flvmux name=muxer streamable=true !
rtmpsink location="rtmp://live.justin.tv/app/%s live=1"
""" % (self._justintv_key)

return videopipe + "\n\n" + audiopipe + "\n\n" + outputpipe
55 changes: 55 additions & 0 deletions flumotion/component/consumers/justintv/justintv.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<registry>

<components>
<component type="justintv-consumer"
base="flumotion/component/consumers/justintv"
_description="A GStreamer to Justin.TV exporter.">
<source location="flumotion.component.consumers.justintv.justintv" />
<eater name="default" multiple="yes" />
<entries>
<entry type="component" location="justintv.py"
function="JustinTV" />
</entries>

<synchronization required="yes" />

<properties>
<property name="justintv-user" type="string" required="yes"
_description="The Justin.TV username." />
<property name="justintv-key" type="string" required="yes"
_description="The Justin.TV live 'Stream Key'. Can be found at http://www.justin.tv/broadcast/adv_other" />
</properties>
</component>
</components>


<bundles>

<bundle name="justintv-consumer-base">
<dependencies>
<dependency name="component-base" />
</dependencies>

<directories>
<directory name="flumotion/component/consumers/justintv">
<filename location="__init__.py" />
</directory>
</directories>
</bundle>

<bundle name="justintv-consumer-component">
<dependencies>
<dependency name="component" />
<dependency name="justintv-consumer-base" />
</dependencies>

<directories>
<directory name="flumotion/component/consumers/justintv">
<filename location="justintv.py" />
</directory>
</directories>
</bundle>

</bundles>

</registry>
6 changes: 4 additions & 2 deletions flumotion/component/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ def startConnecting(self, host, port, authenticator, timeout=30,
"""
assert self._factory is None
self._factory = FeedClientFactory(self)
reactor.connectWith(PassableClientConnector, host, port,
self._factory, timeout, bindAddress)
c = PassableClientConnector(host, port, self._factory, timeout,
bindAddress, reactor=reactor)
c.connect()

return self._factory.login(authenticator)

def requestFeed(self, host, port, authenticator, fullFeedId):
Expand Down
10 changes: 6 additions & 4 deletions flumotion/component/misc/httpserver/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ def do_setup(self):
self._pbclient.startLogin(creds, self._pbclient.medium)
self.info("Logging to porter on socketPath %s", self._porterPath)
# This will eventually cause d to fire
reactor.connectWith(fdserver.FDConnector, self._porterPath,
self._pbclient, 10, checkPID=False)
c = fdserver.FDConnector(self._porterPath, self._pbclient, 10,
checkPID=False, reactor=reactor)
c.connect()
else:
# File Streamer is standalone.
try:
Expand Down Expand Up @@ -500,8 +501,9 @@ def _updatePath(self, path):
self._pbclient.stopTrying()

self._pbclient.resetDelay()
reactor.connectWith(fdserver.FDConnector, self._porterPath,
self._pbclient, 10, checkPID=False)
c = fdserver.FDConnector(self._porterPath, self._pbclient, 10,
checkPID=False, reactor=reactor)
c.connect()

def _timeoutRequests(self):
self._timeoutRequestsCallLater = None
Expand Down
18 changes: 12 additions & 6 deletions flumotion/component/misc/porter/porter.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,15 @@ def do_setup(self):
except OSError:
pass

self._socketlistener = reactor.listenWith(
fdserver.FDPort, self._socketPath,
serverfactory, mode=self._socketMode)
# listenWith is deprecated but the function never did much anyway
#
# self._socketlistener = reactor.listenWith(
# fdserver.FDPort, self._socketPath,
# serverfactory, mode=self._socketMode)
self._socketlistener = fdserver.FDPort(self._socketPath,
serverfactory, reactor=reactor, mode=self._socketMode)
self._socketlistener.startListening()

self.info("Now listening on socketPath %s", self._socketPath)
except error.CannotListenError:
self.warning("Failed to create socket %s" % self._socketPath)
Expand All @@ -350,9 +356,9 @@ def do_setup(self):
# appropriate protocol (HTTP, RTSP, etc.)
factory = PorterProtocolFactory(self, proto)
try:
reactor.listenWith(
fdserver.PassableServerPort, self._port, factory,
interface=self._interface)
p = fdserver.PassableServerPort(self._port, factory,
interface=self._interface, reactor=reactor)
p.startListening()
self.info("Now listening on interface %r on port %d",
self._interface, self._port)
except error.CannotListenError:
Expand Down
5 changes: 3 additions & 2 deletions flumotion/job/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def main(args):
log.info('job', 'Connecting to worker on socket %s' % (socket))

job_factory = job.JobClientFactory(avatarId)
reactor.connectWith(fdserver.FDConnector, socket, job_factory,
10, checkPID=False)
c = fdserver.FDConnector(socket, job_factory, 10, checkPID=False,
reactor=reactor)
c.connect()

reactor.addSystemEventTrigger('before', 'shutdown',
job_factory.medium.shutdownHandler)
Expand Down
8 changes: 7 additions & 1 deletion flumotion/worker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ def listen(self):
# our particular Port, which creates Transports that we know how to
# pass FDs over.
self.debug("Listening for FD's on unix socket %s", self._socketPath)
port = reactor.listenWith(fdserver.FDPort, self._socketPath, f)

# listenWith is deprecated but the function never did much anyway
#
# port = reactor.listenWith(fdserver.FDPort, self._socketPath, f)
port = fdserver.FDPort(self._socketPath, f, reactor=reactor)
port.startListening()

self._port = port

### portal.IRealm method
Expand Down
8 changes: 6 additions & 2 deletions flumotion/worker/feedserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ def listen(self, bouncer, portNum, unsafeTracebacks=0):
factory = pb.PBServerFactory(portal,
unsafeTracebacks=unsafeTracebacks)

tport = reactor.listenWith(fdserver.PassableServerPort, portNum,
factory)
# listenWith is deprecated but the function never did much anyway
#
# tport = reactor.listenWith(fdserver.PassableServerPort, portNum,
# factory)
tport = fdserver.PassableServerPort(portNum, factory, reactor=reactor)
tport.startListening()

self._tport = tport
self.debug('Listening for feed requests on TCP port %d',
Expand Down
3 changes: 1 addition & 2 deletions tools/httpdigesthasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#
# Headers in this file shall remain intact.


import md5
from haslib import md5
import sys


Expand Down