def luks_open_container(filename):
    try:
        fd = os.open(filename, os.O_RDWR)
        mgr = UDisks.ManagerProxy.new_for_bus_sync(
            Gio.BusType(1), 0, "org.freedesktop.UDisks2",
            "/org/freedesktop/UDisks2/Manager", None)
        loop_object_path = mgr.call_loop_setup_sync(
            GLib.Variant('h', 0), GLib.Variant('a{sv}', []),
            Gio.UnixFDList.new_from_array([fd]), None)[0]
        loop_proxy = UDisks.LoopProxy.new_for_bus_sync(
            Gio.BusType(1), 0, "org.freedesktop.UDisks2", loop_object_path,
            None)
        block_proxy = UDisks.BlockProxy.new_for_bus_sync(
            Gio.BusType(1), 0, "org.freedesktop.UDisks2", loop_object_path,
            None)
        if block_proxy.props.id_usage != 'crypto':
            loop_proxy.call_set_autoclear_sync(True, GLib.Variant('a{sv}', []),
                                               None)
            show_error(
                _("The file %s does not seem to be a LUKS encrypted container file!"
                  ) % filename)
    except:
        show_error(
            _("Unknown error occured while trying to open the LUKS container %s"
              ) % filename)
def drive_connected(drive):
    if not drive.has_media():
        return
    voltype = None
    device = drive.get_identifier("unix-device")
    partitions = glob.glob("%s?" % device)
    if len(partitions) == 0:
        try:
            block_proxy = UDisks.BlockProxy.new_for_bus_sync(
                Gio.BusType(1), 0, "org.freedesktop.UDisks2",
                "/org/freedesktop/UDisks2/block_devices/" +
                device.rsplit('/', 1)[1], None)
            voltype = block_proxy.props.id_type
            #voltype = subprocess.Popen(["/usr/bin/sudo", "/sbin/blkid", "-c",
            #                            "/dev/null", "-s", "TYPE", "-o", "value",
            #                            device],
            #                           stdout=subprocess.PIPE).communicate()[0]
        except:
            pass
        if voltype == "":
            _is_truecrypt(device, drive.get_name())
        elif voltype == "crypto_LUKS":
            luks_open_volume(device)
    else:
        for part in partitions:
            try:
                block_proxy = UDisks.BlockProxy.new_for_bus_sync(
                    Gio.BusType(1), 0, "org.freedesktop.UDisks2",
                    "/org/freedesktop/UDisks2/block_devices/" +
                    part.rsplit('/', 1)[1], None)
                voltype = block_proxy.props.id_type
                #voltype = subprocess.Popen(["/usr/bin/sudo", "/sbin/blkid", "-c",
                #                            "/dev/null", "-s", "TYPE", "-o", "value",
                #                            part],
                #                           stdout=subprocess.PIPE).communicate()[0]
            except:
                pass
            if voltype == "":
                _is_truecrypt(part, drive.get_name())
            elif voltype == "crypto_LUKS":
                luks_open_volume(part)