9
from subprocess import Popen, PIPE
11
DEFAULT_DIR = '/tmp/checkbox.optical'
12
DEFAULT_DEVICE_DIR = 'device'
13
DEFAULT_IMAGE_DIR = 'image'
16
CDROM_ID = '/lib/udev/cdrom_id'
18
def _command(command, shell=True):
26
def _command_out(command, shell=True):
27
proc = _command(command, shell)
28
return proc.communicate()[0].strip()
30
def compare_tree(source, target):
31
for dirpath, dirnames, filenames in os.walk(source):
32
#if both tree are empty return false
33
if dirpath == source and dirnames == [] and filenames == []:
35
for name in filenames:
36
file1 = os.path.join(dirpath, name)
37
file2 = file1.replace(source, target, 1)
38
if os.path.isfile(file1) and not os.path.islink(file1):
39
if filecmp.cmp(file1, file2):
47
def read_test(device):
49
device_dir = os.path.join(DEFAULT_DIR, DEFAULT_DEVICE_DIR)
50
image_dir = os.path.join(DEFAULT_DIR, DEFAULT_IMAGE_DIR)
52
for dir in (device_dir, image_dir):
53
if posixpath.exists(dir):
55
os.makedirs(device_dir)
58
_command("umount %s" % device).communicate()
59
mount = _command("mount -o ro %s %s" % (device, device_dir))
61
if mount.returncode != 0:
64
_command("cp -dpR %s %s" % (device_dir, image_dir)).communicate()
65
if compare_tree(device_dir, image_dir):
70
_command("umount %s" % device_dir).communicate(3)
71
for dir in (device_dir, image_dir):
72
if posixpath.exists(dir):
82
def get_capabilities(device):
83
cmd = "%s %s" % (CDROM_ID, device)
84
capabilities = _command_out(cmd)
85
return capabilities.split('\n')
92
capabilities = get_capabilities(device)
93
for capability in capabilities:
94
if capability[:3] == 'ID_':
95
cap = capability[3:-2]
96
if cap == 'CDROM' or cap == 'CDROM_DVD':
99
for test in set(tests):
100
sys.stdout.write("Testing %s on %s ... " % (test, device))
101
tester = "%s_test" % test
102
return_values.append(globals()[tester](device))
105
return False in return_values
107
if __name__ == "__main__":
108
sys.exit(main(sys.argv[1:]))