def _jockey_reply (self, conn, result): debugprint ("Got Jockey result: %s" % repr (result)) try: self._installed_files = result[1] except: self._installed_files = [] self._query_cups ()
def composeSong(analysis_result_json_string, sleep_result_json_string): respiration_timestamps, respiration_cycle_lengths, ihr_timestamps, ihr_values, actigram_timestamps = reader.getSignalAnalysisResults(analysis_result_json_string) reader.processSleepData(sleep_result_json_string) actigram = reader.processActigram(actigram_timestamps) respiration = reader.processRespirationVariability(analysis_result_json_string) IHR = reader.processIHR(ihr_timestamps, ihr_values) reader.syncStages(IHR) #take tempos and stages and make the faster stages have more beats and slower ones less. Gets stages from reader... nightLength = reader.getNightLength() generateKunquat.makeDirectories() generateKunquat.makeFiles() voices = 2 #not counting actigramtrack scaletype = 1#0 for minor, 1 for Major music.generate([], voices, reader.getNightLength(), reader.getStages(), respiration, scaletype, actigram) #second last parameter = rythm dencity, last parameter = volume variation #music.actigramNoise(actigram) music.setTempos(IHR) #works with both respiration and IHR voices = music.howManyVoices() #now counting actigramtrack for i in range(voices): #for each voice (if several) # print str(i)+":" # if (i==2): # print music.getVoice(i) generateKunquat.columnWriter(i, music.getVoice(i)) generateKunquat.patternWriter(music.getLength()+4) #debug.debugRythm(music) debug.debugprint(music)
def _jockey_reply(self, conn, result): debugprint("Got Jockey result: %s" % repr(result)) self._jockey_has_answered = True try: self._installed_files = result[1] except: self._installed_files = [] self._query_cups()
def _query_cups (self): debugprint ("Asking CUPS for PPDs") if (not self._conn): c = asyncconn.Connection (host=self._host, encryption=self._encryption, reply_handler=self._cups_connect_reply, error_handler=self._cups_error) self._conn = c else: self._cups_connect_reply(self._conn, None)
def _query_cups(self): debugprint("Asking CUPS for PPDs") if (not self._conn): c = asyncconn.Connection(host=self._host, encryption=self._encryption, reply_handler=self._cups_connect_reply, error_handler=self._cups_error) self._conn = c else: self._cups_connect_reply(self._conn, None)
def destroy (self): debugprint ("DESTROY: %s" % self) if self._dialog: self._dialog.destroy () self._dialog = None self._parent = None if self._conn: self._conn.destroy () self._conn = None
def _query_jockey(self): debugprint("Asking Jockey to install drivers") try: obj = self._bus.get_object("com.ubuntu.DeviceDriver", "/GUI") jockey = dbus.Interface(obj, "com.ubuntu.DeviceDriver") r = jockey.search_driver("printer_deviceid:%s" % self._device_id, reply_handler=self._jockey_reply, error_handler=self._jockey_error, timeout=3600) except Exception as e: self._jockey_error(e)
def _query_jockey (self): debugprint ("Asking Jockey to install drivers") try: obj = self._bus.get_object ("com.ubuntu.DeviceDriver", "/GUI") jockey = dbus.Interface (obj, "com.ubuntu.DeviceDriver") r = jockey.search_driver ("printer_deviceid:%s" % self._device_id, reply_handler=self._jockey_reply, error_handler=self._jockey_error, timeout=3600) except Exception as e: self._jockey_error (e)
def destroy(self): debugprint("DESTROY: %s" % self) if self._dialog: self._dialog.destroy() self._dialog = None self._parent = None if self._conn: self._conn.destroy() self._conn = None
def _call_with_pk_and_fallback(self, use_fallback, pk_function_name, pk_args, fallback_function, *args, **kwds): pk_function = None # take signature from kwds if is provided dbus_args_signature = kwds.pop('signature', None) if not use_fallback: cups_pk = self._get_cups_pk() if cups_pk: try: pk_function = cups_pk.get_dbus_method(pk_function_name) except dbus.exceptions.DBusException: pass if use_fallback or not pk_function: return fallback_function(*args, **kwds) pk_retval = 'PolicyKit communication issue' while True: try: # FIXME: async call or not? pk_retval = pk_function(*pk_args, signature=dbus_args_signature) # if the PK call has more than one return values, we pop the # first one as the error message if type(pk_retval) == tuple: retval = pk_retval[1:] # if there's no error, then we can safely return what we # got if pk_retval[0] == '': # if there's only one item left in the tuple, we don't # want to return the tuple, but the item if len(retval) == 1: return retval[0] else: return retval break except dbus.exceptions.DBusException as e: if e.get_dbus_name() == CUPS_PK_NEED_AUTH: debugprint("DBus exception: %s" % e.get_dbus_message()) raise cups.IPPError(cups.IPP_NOT_AUTHORIZED, 'pkcancel') break # The PolicyKit call did not work (either a PK-error and we got a dbus # exception that wasn't handled, or an error in the mechanism itself) if pk_retval != '': debugprint('PolicyKit call to %s did not work: %s' % (pk_function_name, repr(pk_retval))) return fallback_function(*args, **kwds)
def _jockey_error(self, exc): debugprint("Got Jockey error: %s" % repr(exc)) if self._need_requery_cups: self._query_cups() else: if self._conn != None: self._conn.destroy() self._conn = None if self._dialog != None: self._dialog.destroy() self._dialog = None self.emit('finished')
def _jockey_error (self, exc): debugprint ("Got Jockey error: %s" % repr (exc)) if self._need_requery_cups: self._query_cups () else: if self._conn != None: self._conn.destroy () self._conn = None if self._dialog != None: self._dialog.destroy () self._dialog = None self.emit ('finished')
def _call_with_pk_and_fallback(self, use_fallback, pk_function_name, pk_args, fallback_function, *args, **kwds): pk_function = None # take signature from kwds if is provided dbus_args_signature = kwds.pop('signature', None) if not use_fallback: cups_pk = self._get_cups_pk() if cups_pk: try: pk_function = cups_pk.get_dbus_method(pk_function_name) except dbus.exceptions.DBusException: pass if use_fallback or not pk_function: return fallback_function(*args, **kwds) pk_retval = 'PolicyKit communication issue' while True: try: # FIXME: async call or not? pk_retval = pk_function(*pk_args, signature = dbus_args_signature) # if the PK call has more than one return values, we pop the # first one as the error message if type(pk_retval) == tuple: retval = pk_retval[1:] # if there's no error, then we can safely return what we # got if pk_retval[0] == '': # if there's only one item left in the tuple, we don't # want to return the tuple, but the item if len(retval) == 1: return retval[0] else: return retval break except dbus.exceptions.DBusException as e: if e.get_dbus_name() == CUPS_PK_NEED_AUTH: debugprint ("DBus exception: %s" % e.get_dbus_message ()) raise cups.IPPError(cups.IPP_NOT_AUTHORIZED, 'pkcancel') break # The PolicyKit call did not work (either a PK-error and we got a dbus # exception that wasn't handled, or an error in the mechanism itself) if pk_retval != '': debugprint ('PolicyKit call to %s did not work: %s' % (pk_function_name, repr (pk_retval))) return fallback_function(*args, **kwds)
def __init__(self, device_id=None, parent=None, device_uri=None, host=None, encryption=None, language=None, device_make_and_model=None): GObject.GObject.__init__(self) debugprint("+%s" % self) self._device_id = device_id self._device_uri = device_uri self._device_make_and_model = device_make_and_model self._parent = parent self._host = host self._encryption = encryption self._language = language self._installed_files = [] self._conn = None self._ppds = None self._exc = None self._ppdsmatch_result = None self._jockey_queried = False self._jockey_has_answered = False self._local_cups = (self._host == None or self._host == "localhost" or self._host[0] == '/') try: self._bus = dbus.SessionBus() except: debugprint("Failed to get session bus") self._bus = None fmt = _("Searching") self._dialog = Gtk.MessageDialog(parent=parent, modal=True, destroy_with_parent=True, message_type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.CANCEL, text=fmt) self._dialog.format_secondary_text(_("Searching for drivers")) self._dialog.connect("response", self._dialog_response)
def __init__ (self, device_id=None, parent=None, device_uri=None, host=None, encryption=None, language=None, device_make_and_model=None): GObject.GObject.__init__ (self) debugprint ("+%s" % self) self._device_id = device_id self._device_uri = device_uri self._device_make_and_model = device_make_and_model self._parent = parent self._host = host self._encryption = encryption self._language = language self._installed_files = [] self._conn = None self._ppds = None self._exc = None self._ppdsmatch_result = None self._jockey_queried = False self._jockey_has_answered = False self._local_cups = (self._host == None or self._host == "localhost" or self._host[0] == '/') try: self._bus = dbus.SessionBus () except: debugprint ("Failed to get session bus") self._bus = None fmt = _("Searching") self._dialog = Gtk.MessageDialog (parent=parent, flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.CANCEL, message_format=fmt) self._dialog.format_secondary_text (_("Searching for drivers")) self._dialog.connect ("response", self._dialog_response)
def _query_packagekit (self): debugprint ("Asking PackageKit to install drivers") try: xid = self._parent.window.xid except: xid = 0 try: obj = self._bus.get_object ("org.freedesktop.PackageKit", "/org/freedesktop/PackageKit") proxy = dbus.Interface (obj, "org.freedesktop.PackageKit.Modify") resources = [self._gpk_device_id] interaction = "hide-finished" debugprint ("Calling InstallPrinterDrivers (%s, %s, %s)" % (repr (xid), repr (resources), repr (interaction))) proxy.InstallPrinterDrivers (dbus.UInt32 (xid), resources, interaction, reply_handler=self._packagekit_reply, error_handler=self._packagekit_error, timeout=3600) except Exception, e: debugprint ("Failed to talk to PackageKit: %s" % e) if self._dialog: self._dialog.show_all () self._query_cups ()
def composeSong(analysis_result_json_string, sleep_result_json_string): respiration_timestamps, respiration_cycle_lengths, ihr_timestamps, ihr_values, actigram_timestamps = reader.getSignalAnalysisResults( analysis_result_json_string) reader.processSleepData(sleep_result_json_string) actigram = reader.processActigram(actigram_timestamps) respiration = reader.processRespirationVariability( analysis_result_json_string) IHR = reader.processIHR(ihr_timestamps, ihr_values) reader.syncStages( IHR ) #take tempos and stages and make the faster stages have more beats and slower ones less. Gets stages from reader... nightLength = reader.getNightLength() generateKunquat.makeDirectories() generateKunquat.makeFiles() voices = 2 #not counting actigramtrack scaletype = 1 #0 for minor, 1 for Major music.generate( [], voices, reader.getNightLength(), reader.getStages(), respiration, scaletype, actigram ) #second last parameter = rythm dencity, last parameter = volume variation #music.actigramNoise(actigram) music.setTempos(IHR) #works with both respiration and IHR voices = music.howManyVoices() #now counting actigramtrack for i in range(voices): #for each voice (if several) # print str(i)+":" # if (i==2): # print music.getVoice(i) generateKunquat.columnWriter(i, music.getVoice(i)) generateKunquat.patternWriter(music.getLength() + 4) #debug.debugRythm(music) debug.debugprint(music)
def _query_packagekit(self): debugprint("Asking PackageKit to install drivers") try: obj = self._bus.get_object("org.freedesktop.PackageKit", "/org/freedesktop/PackageKit") proxy = dbus.Interface(obj, "org.freedesktop.PackageKit.Modify") resources = [self._gpk_device_id] interaction = "hide-finished" debugprint("Calling InstallPrinterDrivers (%s, %s, %s)" % (repr(0), repr(resources), repr(interaction))) proxy.InstallPrinterDrivers(dbus.UInt32(0), resources, interaction, reply_handler=self._packagekit_reply, error_handler=self._packagekit_error, timeout=3600) except Exception as e: debugprint("Failed to talk to PackageKit: %s" % repr(e)) if self._dialog: self._dialog.show_all() self._query_cups()
def __del__ (self): debug.debugprint ("-%s" % self)
def __del__(self): debug.debugprint("-%s" % self)
def getDevices(self, *args, **kwds): use_pycups = False limit = 0 include_schemes = [] exclude_schemes = [] timeout = 0 if len(args) == 4: (use_pycups, limit, include_schemes, exclude_schemes, timeout) = self._args_to_tuple([int, str, str, int], *args) else: if kwds.has_key('timeout'): timeout = kwds['timeout'] if kwds.has_key('limit'): limit = kwds['limit'] if kwds.has_key('include_schemes'): include_schemes = kwds['include_schemes'] if kwds.has_key('exclude_schemes'): exclude_schemes = kwds['exclude_schemes'] pk_args = (timeout, limit, include_schemes, exclude_schemes) try: result = self._call_with_pk_and_fallback(use_pycups, 'DevicesGet', pk_args, self._connection.getDevices, *args, **kwds) except TypeError: debugprint ("DevicesGet API exception; using old signature") if kwds.has_key ('timeout'): use_pycups = True # Convert from list to string if len (include_schemes) > 0: include_schemes = reduce (lambda x, y: x + "," + y, include_schemes) else: include_schemes = "" if len (exclude_schemes) > 0: exclude_schemes = reduce (lambda x, y: x + "," + y, exclude_schemes) else: exclude_schemes = "" pk_args = (limit, include_schemes, exclude_schemes) result = self._call_with_pk_and_fallback(use_pycups, 'DevicesGet', pk_args, self._connection.getDevices, *args, **kwds) # return 'result' if fallback was called if len (result.keys()) > 0 and type (result[result.keys()[0]]) == dict: return result result_str = {} if result != None: for i in result.keys(): if type(i) == dbus.String: result_str[str(i)] = str(result[i]) else: result_str[i] = result[i] # cups-pk-helper returns all devices in one dictionary. # Keys of different devices are distinguished by ':n' postfix. devices = {} n = 0 postfix = ':' + str (n) device_keys = [x for x in result_str.keys() if x.endswith(postfix)] while len (device_keys) > 0: device_uri = None device_dict = {} for i in device_keys: key = i[:len(i) - len(postfix)] if key != 'device-uri': device_dict[key] = result_str[i] else: device_uri = result_str[i] if device_uri != None: devices[device_uri] = device_dict n += 1 postfix = ':' + str (n) device_keys = [x for x in result_str.keys() if x.endswith(postfix)] return devices
def __del__ (self): debug.debugprint ("-_PK1AsyncMethodCall: %s" % self)
def __del__ (self): try: os.unlink (self._filename) debug.debugprint ("Removed tempfile %s" % self._filename) except: debug.debugprint ("No tempfile to remove")
def __del__(self): debug.debugprint("-_PK1AsyncMethodCall: %s" % self)
def __del__(self): try: os.unlink(self._filename) debug.debugprint("Removed tempfile %s" % self._filename) except: debug.debugprint("No tempfile to remove")
def get_error(self): debugprint("%s: stored error is %s" % (self, repr(self._exc))) return self._exc
def _packagekit_reply(self): debugprint("Got PackageKit reply") self._need_requery_cups = True if self._dialog: self._dialog.show_all() self._query_cups()
def _packagekit_error (self, exc): debugprint ("Got PackageKit error: %s" % repr (exc)) if self._dialog: self._dialog.show_all () self._query_cups ()
def _packagekit_reply (self): debugprint ("Got PackageKit reply") self._need_requery_cups = True if self._dialog: self._dialog.show_all () self._query_cups ()
def _packagekit_error(self, exc): debugprint("Got PackageKit error: %s" % repr(exc)) if self._dialog: self._dialog.show_all() self._query_cups()
def get_error (self): debugprint ("%s: stored error is %s" % (self, repr (self._exc))) return self._exc
def getDevices(self, *args, **kwds): use_pycups = False limit = 0 include_schemes = [] exclude_schemes = [] timeout = 0 if len(args) == 4: (use_pycups, limit, include_schemes, exclude_schemes, timeout) = self._args_to_tuple([int, str, str, int], *args) else: if 'timeout' in kwds: timeout = kwds['timeout'] if 'limit' in kwds: limit = kwds['limit'] if 'include_schemes' in kwds: include_schemes = kwds['include_schemes'] if 'exclude_schemes' in kwds: exclude_schemes = kwds['exclude_schemes'] pk_args = (timeout, limit, include_schemes, exclude_schemes) try: result = self._call_with_pk_and_fallback( use_pycups, 'DevicesGet', pk_args, self._connection.getDevices, *args, **kwds) except TypeError: debugprint("DevicesGet API exception; using old signature") if 'timeout' in kwds: use_pycups = True # Convert from list to string if len(include_schemes) > 0: include_schemes = reduce(lambda x, y: x + "," + y, include_schemes) else: include_schemes = "" if len(exclude_schemes) > 0: exclude_schemes = reduce(lambda x, y: x + "," + y, exclude_schemes) else: exclude_schemes = "" pk_args = (limit, include_schemes, exclude_schemes) result = self._call_with_pk_and_fallback( use_pycups, 'DevicesGet', pk_args, self._connection.getDevices, *args, **kwds) # return 'result' if fallback was called if len(result.keys()) > 0 and type(result[list( result.keys())[0]]) == dict: return result result_str = {} if result is not None: for i in result.keys(): if type(i) == dbus.String: result_str[str(i)] = str(result[i]) else: result_str[i] = result[i] # cups-pk-helper returns all devices in one dictionary. # Keys of different devices are distinguished by ':n' postfix. devices = {} n = 0 postfix = ':' + str(n) device_keys = [x for x in result_str.keys() if x.endswith(postfix)] while len(device_keys) > 0: device_uri = None device_dict = {} for i in device_keys: key = i[:len(i) - len(postfix)] if key != 'device-uri': device_dict[key] = result_str[i] else: device_uri = result_str[i] if device_uri is not None: devices[device_uri] = device_dict n += 1 postfix = ':' + str(n) device_keys = [x for x in result_str.keys() if x.endswith(postfix)] return devices