Package flumotion :: Package worker :: Package checks :: Module check
[hide private]

Source Code for Module flumotion.worker.checks.check

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  import gst 
 23   
 24  from twisted.internet import defer 
 25  from flumotion.common import errors, log, messages, gstreamer 
 26   
 27  from flumotion.common.messages import N_ 
 28  T_ = messages.gettexter('flumotion') 
 29       
30 -def handleGStreamerDeviceError(failure, device):
31 """ 32 Handle common GStreamer GstErrors or other. 33 Return a message or None. 34 """ 35 m = None 36 37 if failure.check(errors.GStreamerGstError): 38 source, gerror, debug = failure.value.args 39 log.debug('check', 40 'GStreamer GError: %s (domain %s, code %d, debug %s)' % ( 41 gerror.message, gerror.domain, gerror.code, debug)) 42 43 if gerror.domain == "gst-resource-error-quark": 44 if gerror.code == int(gst.RESOURCE_ERROR_OPEN_READ): 45 m = messages.Error(T_( 46 N_("Could not open device '%s' for reading. Check permissions on the device."), device)) 47 elif gerror.code == int(gst.RESOURCE_ERROR_OPEN_READ_WRITE): 48 m = messages.Error(T_( 49 N_("Could not open device '%s'. Check permissions on the device."), device)) 50 elif gerror.code == int(gst.RESOURCE_ERROR_BUSY): 51 m = messages.Error(T_( 52 N_("Device '%s' is already in use."), device)) 53 elif gerror.code == int(gst.RESOURCE_ERROR_SETTINGS): 54 m = messages.Error(T_( 55 N_("Device '%s' did not accept the requested settings."), 56 device), 57 debug="%s\n%s" % (gerror.message, debug)) 58 59 # fallback GStreamer GstError handling 60 if not m: 61 m = messages.Error(T_(N_("Internal GStreamer error.")), 62 debug="%s\n%s: %d\n%s" % ( 63 gerror.message, gerror.domain, gerror.code, debug)) 64 elif failure.check(errors.GStreamerError): 65 m = messages.Error(T_(N_("Internal GStreamer error.")), 66 debug=debugFailure(failure)) 67 log.debug('check', 'handleGStreamerError: returning %r' % m) 68 return m
69
70 -def debugFailure(failure):
71 """ 72 Create debug info from a failure. 73 """ 74 return "Failure %r: %s\n%s" % (failure, failure.getErrorMessage(), 75 failure.getTraceback())
76
77 -def callbackResult(value, result):
78 """ 79 I am a callback to add to a do_element_check deferred. 80 """ 81 log.debug('check', 'returning succeeded Result, value %r' % (value, )) 82 result.succeed(value) 83 return result
84
85 -def errbackResult(failure, result, id, device):
86 """ 87 I am an errback to add to a do_element_check deferred, after your 88 specific one. 89 """ 90 m = None 91 if failure.check(errors.GStreamerGstError): 92 m = handleGStreamerDeviceError(failure, device) 93 94 if not m: 95 log.debug('check', 'unhandled failure: %r (%s)\nTraceback:\n%s' % ( 96 failure, failure.getErrorMessage(), failure.getTraceback())) 97 m = messages.Error(T_(N_("Could not probe device '%s'."), device), 98 debug=debugFailure(failure)) 99 100 m.id = id 101 result.add(m) 102 return result
103
104 -def errbackNotFoundResult(failure, result, id, device):
105 """ 106 I am an errback to add to a do_element_check deferred 107 to check for RESOURCE_ERROR_NOT_FOUND, and add a message to the result. 108 """ 109 failure.trap(errors.GStreamerGstError) 110 source, gerror, debug = failure.value.args 111 112 if gerror.domain == "gst-resource-error-quark" and \ 113 gerror.code == int(gst.RESOURCE_ERROR_NOT_FOUND): 114 m = messages.Warning(T_( 115 N_("No device found on %s."), device), id=id) 116 result.add(m) 117 return result 118 119 # let failure fall through otherwise 120 return failure
121
122 -class CheckProcError(Exception):
123 'Utility error for element checker procedures' 124 data = None 125
126 - def __init__(self, data):
127 self.data = data
128
129 -def checkPlugin(pluginName, packageName, minimumVersion=None):
130 """ 131 Check if the given plug-in is available. 132 Return a result with an error if it is not, or not new enough. 133 134 @rtype: L{messages.Result} 135 """ 136 result = messages.Result() 137 version = gstreamer.get_plugin_version(pluginName) 138 if not version: 139 m = messages.Error(T_( 140 N_("This host is missing the '%s' GStreamer plug-in.\n"), 141 pluginName)) 142 m.add(T_(N_( 143 "Please install '%s'.\n"), packageName)) 144 result.add(m) 145 else: 146 if version < minimumVersion: 147 m = messages.Error(T_( 148 N_("Version %s of the '%s' GStreamer plug-in is too old.\n"), 149 ".".join([str(x) for x in version]), pluginName), 150 id = 'plugin-%s-check' % pluginName) 151 m.add(T_(N_( 152 "Please upgrade '%s' to version %s."), packageName, 153 ".".join([str(x) for x in minimumVersion]))) 154 result.add(m) 155 156 result.succeed(None) 157 return defer.succeed(result)
158