+pathExists = os.path.exists
+isMount = os.path.ismount
+
+def bestRecordingLocation(candidates):
+ path = ''
+
+ from Components import Harddisk
+ ata_devices = [candidate for candidate in candidates if Harddisk.getDeviceInterface(candidate[1]) == "ata"]
+
+ if len(ata_devices) == 1:
+ path = ata_devices[0][1]
+
+ elif len(ata_devices):
+ best = ""
+ for device in ata_devices:
+ dev = os.path.basename(device[0])
+ if not best or (best > dev):
+ best = dev
+ path = device[1]
+ else: # Find the largest usb disk
+ biggest = 0
+ for candidate in candidates:
+ try:
+ stat = os.statvfs(candidate[1])
+ # must have some free space (i.e. not read-only)
+ if stat.f_bavail:
+ # Free space counts double
+ size = (stat.f_blocks + stat.f_bavail) * stat.f_bsize
+ if size > biggest:
+ path = candidate[1]
+ biggest = size
+ except Exception, e:
+ print "[DRL]", e