Пример #1
0
def start_file_logging(level="warning", full_path="/var/tmp/scenic/scenic.log"):
    """
    Starts logging the Master infos to a file.
    @rtype: str path to the log file
    """
    global log
    directory = os.path.dirname(full_path)
    if directory == "":
        directory = os.getcwd()
    if not os.path.exists(directory):
        os.makedirs(directory)
    f = open(full_path, "w")  # erases previous file
    f.close()

    log = logger.start(level=level, to_file=True, log_file_name=full_path)
    return full_path
Пример #2
0
def start_file_logging(level="warning",
                       full_path="/var/tmp/scenic/scenic.log"):
    """
    Starts logging the Master infos to a file.
    @rtype: str path to the log file
    """
    global log
    directory = os.path.dirname(full_path)
    if directory == '':
        directory = os.getcwd()
    if not os.path.exists(directory):
        os.makedirs(directory)
    f = open(full_path, 'w')  # erases previous file
    f.close()

    log = logger.start(level=level, to_file=True, log_file_name=full_path)
    return full_path
Пример #3
0
#!/usr/bin/env python
"""
Gstreamer-related tools.
"""
import pygst
pygst.require('0.10')
import gst
from scenic import logger

log = logger.start(name="gst")


def is_gstreamer_element_found(name):
    """
    Checks if a given Gstreamer element is installed.
    @rettype: bool
    """
    ok = gst.element_factory_find(name) is not None
    if not ok:
        log.info("Could not find Gstreamer element %s." % (name))
    return ok


def is_codec_supported(codec):
    """
    Checks if a codec is supported by the Gstreamer elements found on the system.
    """
    _elements = {
        "mp3": ["lamemp3enc", "mp3parse", "mad"],
        "raw": ["rtpL16pay", "rtpL16depay"],
        "vorbis": ["vorbisenc", "vorbisdec"],
Пример #4
0
# Scenic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.
"""
Tools to help with choosing listening port numbers.
"""

# for port_is_avaiable
import socket
from scenic import logger

log = logger.start(name="ports")

class PortsAllocatorError(Exception):
    """
    Any error raised by the PortsAllocator
    """
    pass

class PortsAllocator(object):
    """
    Allocates ports from a pool
    """
    def __init__(self, minimum=10000, increment=10, maximum=65535):
        self.minimum = minimum
        self.increment = increment
        self.maximum = maximum
Пример #5
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.
"""
Common module for the internationalization in Scenic.

Provides the _(...) function.
"""

import gtk.glade
import gettext
from scenic import configure
from scenic import logger

log = logger.start(name="i18n")

_ = gettext.gettext


def setup_i18n():
    """
    Bind the domain to the locale directory localedir. More concretely, gettext will look for binary .mo  files for the given domain using the path (on Unix): localedir/language/LC_MESSAGES/domain.mo, where languages is searched for in the environment variables LANGUAGE, LC_ALL, LC_MESSAGES, and LANG  respectively.
    """
    gettext.bindtextdomain(configure.APPNAME, configure.LOCALE_DIR)
    gettext.textdomain(configure.APPNAME)
    gtk.glade.bindtextdomain(configure.APPNAME, configure.LOCALE_DIR)
    gtk.glade.textdomain(configure.APPNAME)

    log.debug("i18n has been setup with domain %s and path %s." %
              (gettext.textdomain(), configure.LOCALE_DIR))
Пример #6
0
#
# Scenic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.

from scenic import sig
from scenic import sic
from twisted.internet import reactor
from twisted.internet import defer
from scenic import logger

log = logger.start(name="communication")

# these value should all be readable
CANCEL_REASON_CANCELLED = "cancelled"
REFUSE_REASON_PROBLEMS = "technical problems"
REFUSE_REASON_BUSY = "busy"
REFUSE_REASON_REFUSED = "refused"
REFUSE_REASON_PROBLEM_JACKD_NOT_RUNNING = "jackd is not running"
REFUSE_REASON_PROBLEM_JACKD_RATE_MISMATCH = "jackd rate mismatch"
REFUSE_REASON_XVIDEO_NOT_FOUND = "xvideo extension not found"
REFUSE_REASON_MIDI_DEVICE_NOT_FOUND = "midi device not found"
REFUSE_REASON_CAMERA_NOT_FOUND = "v4l2 device not found"
REFUSE_REASON_DISPLAY_NOT_FOUND = "x11 display not found"
REFUSE_REASON_PROBLEM_UNSUPPORTED_AUDIO_CODEC = "unsupported audio codec"
REFUSE_REASON_PROBLEM_UNSUPPORTED_VIDEO_CODEC = "unsupported video codec"
BYE_REASON_PROBLEMS = "technical problems"
Пример #7
0
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.
"""
Tools to lists available cameras.

Uses milhouse --list-v4l2
"""
import os
import pprint
from twisted.internet import utils
from twisted.internet import defer
from twisted.python import procutils
from twisted.internet import reactor

from scenic import logger
log = logger.start(name="cameras")

ugly_to_beautiful_camera_names = {
    "BT878 video (Osprey 210/220/230": "Osprey 210/220/230",
    "BT878 video (Osprey 100/150 (87": "Osprey 100/150",
    "BT878 video (Hauppauge (bt878))": "Hauppauge WinTV",
    }

def _beautify_camera_name(name):
    """
    Renames a camera with a better name if it's in our list of know camera names.

    @rtype: str
    @type name: str
    """
    global ugly_to_beautiful_camera_names
Пример #8
0
"""
MIDI driver. Used to list MIDI devices.

Uses midistream.
"""
import os
import shlex
from twisted.internet import threads
from twisted.internet import utils
from twisted.internet import defer
from twisted.internet import reactor
from twisted.python import procutils

from scenic import logger

log = logger.start(name="midi")

# $ miditream --list-devices
# List of MIDI devices:
#     Input devices:
#     --------------
#      * input   1            Midi Through Port-0   [closed]
#      * input   3         USB Oxygen 8 v2 MIDI 1   [closed]
#     Output devices:
#     ---------------
#      * output  0            Midi Through Port-0   [closed]
#      * output  2         USB Oxygen 8 v2 MIDI 1   [closed]
#      * output  4                TiMidity port 0   [closed]
#      * output  5                TiMidity port 1   [closed]
#      * output  6                TiMidity port 2   [closed]
#      * output  7                TiMidity port 3   [closed]
Пример #9
0
#
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.

"""
Common module for the internationalization in Scenic.

Provides the _(...) function.
"""

import gtk.glade
import gettext
from scenic import configure
from scenic import logger

log = logger.start(name="i18n")

_ = gettext.gettext

def setup_i18n():
    """
    Bind the domain to the locale directory localedir. More concretely, gettext will look for binary .mo  files for the given domain using the path (on Unix): localedir/language/LC_MESSAGES/domain.mo, where languages is searched for in the environment variables LANGUAGE, LC_ALL, LC_MESSAGES, and LANG  respectively.
    """
    gettext.bindtextdomain(configure.APPNAME, configure.LOCALE_DIR)
    gettext.textdomain(configure.APPNAME)
    gtk.glade.bindtextdomain(configure.APPNAME, configure.LOCALE_DIR)
    gtk.glade.textdomain(configure.APPNAME)

    log.debug("i18n has been setup with domain %s and path %s." % (gettext.textdomain(), configure.LOCALE_DIR))

Пример #10
0
"""
JACK driver

Attributes of its (jackd) devices:
* sample rate
* buffer size
"""

import os
from twisted.internet import utils
from twisted.internet import defer
from twisted.python import procutils
from scenic import logger

log = logger.start(name="jackd")

def _parse_jack_info(text):
    """
    Parses the results of the jack-info command.

    Returns a list of dict :
    [{
    'period': 1024,
    'rate': 44100,
    'latency': 32
    }]
    @rettype: list
    """
    #FIXME: I think jack-info currently only supports reporting
    # infos one a single JACK server. It's rather rare to see someone
Пример #11
0
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.
"""
JACK driver

Attributes of its (jackd) devices:
* sample rate
* buffer size
"""

import os
from twisted.internet import utils
from twisted.internet import defer
from twisted.python import procutils
from scenic import logger

log = logger.start(name="jackd")


def _parse_jack_info(text):
    """
    Parses the results of the jack-info command.

    Returns a list of dict :
    [{
    'period': 1024,
    'rate': 44100,
    'latency': 32
    }]
    @rettype: list
    """
    #FIXME: I think jack-info currently only supports reporting
Пример #12
0
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.
"""
Manages local streamer processes.
"""
from textwrap import wrap
from scenic import process
from scenic import sig
from scenic import dialogs
from scenic.internationalization import _
from scenic import logger
from twisted.python import procutils
from twisted.internet import defer
from twisted.internet import utils
import os

log = logger.start(name="streamer")


class StreamerManager(object):
    """
    Manages local streamer processes.
    """
    def __init__(self, app):
        self.app = app
        self.sender = None
        self.receiver = None
        self.extra_sender = None  # extra sender/receiver used only if not synchronized
        self.extra_receiver = None

        self.midi_receiver = None
        self.midi_sender = None
Пример #13
0
# JSON import:
try:
    import json  # python 2.6
except ImportError:
    import simplejson as json  # python 2.4 to 2.5
try:
    _tmp = json.loads
except AttributeError:
    import warnings
    import sys
    warnings.warn("Use simplejson, not the old json module.")
    sys.modules.pop('json')  # get rid of the bad json module
    import simplejson as json

log = logger.start(name="saving")


def _create_directory_if_it_does_not_exist(dir_path):
    try:
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
            log.info('mkdir %s' % (dir_path))
    except OSError, e:
        msg = 'Error creating directories %s: %s' % (dir_path, e.message)
        log.error(msg)
        raise RuntimeError(msg)


def _save(file_name, data):
    """
Пример #14
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.

"""
Preview Process management.
"""
from scenic import sig
from scenic import process
from scenic.internationalization import _
from scenic import logger

log = logger.start(name="preview")

class Preview(object):
    """
    Local preview - not live
    """
    def __init__(self, app):
        self.app = app
        self.process_manager = None
        self.state = process.STATE_STOPPED
        self.state_changed_signal = sig.Signal()
        self.error_messages = None # either None or a list
        self.warnings = None # either None or a list

    def is_busy(self):
        """
Пример #15
0
"""
MIDI driver. Used to list MIDI devices.

Uses midistream.
"""
import os
import shlex
from twisted.internet import threads
from twisted.internet import utils
from twisted.internet import defer
from twisted.internet import reactor
from twisted.python import procutils

from scenic import logger

log = logger.start(name="midi")

# $ miditream --list-devices
# List of MIDI devices:
#     Input devices:
#     --------------
#      * input   1            Midi Through Port-0   [closed]
#      * input   3         USB Oxygen 8 v2 MIDI 1   [closed]
#     Output devices:
#     ---------------
#      * output  0            Midi Through Port-0   [closed]
#      * output  2         USB Oxygen 8 v2 MIDI 1   [closed]
#      * output  4                TiMidity port 0   [closed]
#      * output  5                TiMidity port 1   [closed]
#      * output  6                TiMidity port 2   [closed]
#      * output  7                TiMidity port 3   [closed]
Пример #16
0
    _tmp = json.loads
except AttributeError:
    import warnings
    import sys
    warnings.warn("Use simplejson, not the old json module.")
    sys.modules.pop('json') # get rid of the bad json module
    import simplejson as json

from twisted.internet import reactor
from twisted.internet import protocol
from twisted.internet import defer
from twisted.protocols import basic
from scenic import sig
from scenic import logger

log = logger.start(name="sic")

class SICProtocol(basic.LineReceiver):
    """
    Receives and sends JSON lines.
    Twisted add to it a factory attribute.
    """
    delimiter = '\n'

    def connectionMade(self):
        if hasattr(self, "factory"):
            if hasattr(self.factory, 'connected_deferred'):
                if not self.factory.connected_deferred.called:
                    self.factory.connected_deferred.callback(self)
            else:
                log.warning("SIC: No connected_deferred")
Пример #17
0
    _tmp = json.loads
except AttributeError:
    import warnings
    import sys
    warnings.warn("Use simplejson, not the old json module.")
    sys.modules.pop('json')  # get rid of the bad json module
    import simplejson as json

from twisted.internet import reactor
from twisted.internet import protocol
from twisted.internet import defer
from twisted.protocols import basic
from scenic import sig
from scenic import logger

log = logger.start(name="sic")


class SICProtocol(basic.LineReceiver):
    """
    Receives and sends JSON lines.
    Twisted add to it a factory attribute.
    """
    delimiter = '\n'

    def connectionMade(self):
        if hasattr(self, "factory"):
            if hasattr(self.factory, 'connected_deferred'):
                if not self.factory.connected_deferred.called:
                    self.factory.connected_deferred.callback(self)
            else:
Пример #18
0
#
# Scenic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.

from scenic import sig
from scenic import sic
from twisted.internet import reactor
from twisted.internet import defer
from scenic import logger

log = logger.start(name="communication")

# these value should all be readable
CANCEL_REASON_CANCELLED = "cancelled"
REFUSE_REASON_PROBLEMS = "technical problems"
REFUSE_REASON_BUSY = "busy"
REFUSE_REASON_REFUSED = "refused"
REFUSE_REASON_PROBLEM_JACKD_NOT_RUNNING = "jackd is not running"
REFUSE_REASON_PROBLEM_JACKD_RATE_MISMATCH = "jackd rate mismatch"
REFUSE_REASON_XVIDEO_NOT_FOUND = "xvideo extension not found"
REFUSE_REASON_MIDI_DEVICE_NOT_FOUND = "midi device not found"
REFUSE_REASON_CAMERA_NOT_FOUND = "v4l2 device not found"
REFUSE_REASON_DISPLAY_NOT_FOUND = "x11 display not found"
REFUSE_REASON_PROBLEM_UNSUPPORTED_AUDIO_CODEC = "unsupported audio codec"
REFUSE_REASON_PROBLEM_UNSUPPORTED_VIDEO_CODEC = "unsupported video codec"
BYE_REASON_PROBLEMS = "technical problems"
Пример #19
0
#!/usr/bin/env python
"""
Gstreamer-related tools.
"""
import pygst
pygst.require('0.10')
import gst
from scenic import logger

log = logger.start(name="gst")

def is_gstreamer_element_found(name):
    """
    Checks if a given Gstreamer element is installed.
    @rettype: bool
    """
    ok = gst.element_factory_find(name) is not None
    if not ok:
        log.info("Could not find Gstreamer element %s." % (name))
    return ok

def is_codec_supported(codec):
    """
    Checks if a codec is supported by the Gstreamer elements found on the system.
    """
    _elements = {
        "mp3": ["lamemp3enc", "mp3parse", "mad"],
        "raw": ["rtpL16pay", "rtpL16depay"],
        "vorbis": ["vorbisenc", "vorbisdec"],
        "theora": ["theoraenc", "theoradec"],
        "h263": ["ffenc_h263p", "ffdec_h263"],
Пример #20
0
"""
Manages local streamer processes.
"""
from textwrap import wrap
from scenic import process
from scenic import sig
from scenic import dialogs
from scenic.internationalization import _
from scenic import logger
from twisted.python import procutils
from twisted.internet import defer
from twisted.internet import utils
import os

log = logger.start(name="streamer")

class StreamerManager(object):
    """
    Manages local streamer processes.
    """
    def __init__(self, app):
        self.app = app
        self.sender = None
        self.receiver = None
        self.extra_sender = None # extra sender/receiver used only if not synchronized
        self.extra_receiver = None

        self.midi_receiver = None
        self.midi_sender = None
        self.state = process.STATE_STOPPED
Пример #21
0
# JSON import:
try:
    import json # python 2.6
except ImportError:
    import simplejson as json # python 2.4 to 2.5
try:
    _tmp = json.loads
except AttributeError:
    import warnings
    import sys
    warnings.warn("Use simplejson, not the old json module.")
    sys.modules.pop('json') # get rid of the bad json module
    import simplejson as json

log = logger.start(name="saving")

def _create_directory_if_it_does_not_exist(dir_path):
    try:
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
            log.info('mkdir %s' % (dir_path))
    except OSError, e:
        msg = 'Error creating directories %s: %s' % (dir_path, e.message)
        log.error(msg)
        raise RuntimeError(msg)

def _save(file_name, data):
    """
    State saving using JSON
Пример #22
0
# Scenic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scenic. If not, see <http://www.gnu.org/licenses/>.
"""
Tools to help with choosing listening port numbers.
"""

# for port_is_avaiable
import socket
from scenic import logger

log = logger.start(name="ports")


class PortsAllocatorError(Exception):
    """
    Any error raised by the PortsAllocator
    """
    pass


class PortsAllocator(object):
    """
    Allocates ports from a pool
    """
    def __init__(self, minimum=10000, increment=10, maximum=65535):
        self.minimum = minimum
Пример #23
0
def start_logging_to_stdout(level="warning"):
    global log
    log = logger.start(level=level)
Пример #24
0
Streamer Process management.
"""
import os
import copy
import time
import logging
import signal
from twisted.internet import error
from twisted.internet import protocol
from twisted.python import procutils
from twisted.internet import utils
from scenic import sig
from scenic import configure
from scenic import logger

log = logger.start(name="process")

# this is used only for processes started using run_once
_original_environment_variables = {}

def save_environment_variables(env):
    """
    Saves the env vars at startup, which does not contain vars we ight override, such as GTK2_RC_FILES

    this is used only for processes started using run_once
    """
    global _original_environment_variables
    _original_environment_variables = copy.deepcopy(env)
    log.debug("Saved original env vars: %s" % (_original_environment_variables))
    log.debug("ID of os.environ: %d. ID of saved env: %d" % (id(os.environ), id(_original_environment_variables)))
Пример #25
0
def start_logging_to_stdout(level="warning"):
    global log
    log = logger.start(level=level)