~cr3/checkbox/floppy_test

« back to all changes in this revision

Viewing changes to scripts/floppy_test

  • Committer: Marc Tardif
  • Date: 2012-06-21 18:40:03 UTC
  • Revision ID: marc.tardif@canonical.com-20120621184003-jw2nzo6eom4djsxk
Ran 2to3 on floppy_test script and updated shebang to python3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
 
1
#!/usr/bin/env python3
2
2
 
3
3
import os
4
4
import sys
5
5
import filecmp
6
 
import commands
 
6
import subprocess
7
7
import posixpath
8
8
 
9
9
DEFAULT_DIR = "/tmp/checkbox.floppy"
28
28
    def run(self):
29
29
        floppyDevice = self.device
30
30
        if floppyDevice:
31
 
            print "  Testing on floppy drive %s " % floppyDevice
 
31
            print("  Testing on floppy drive %s " % floppyDevice)
32
32
        else:
33
 
            print "  Error ! No floppy drive found !"
 
33
            print("  Error ! No floppy drive found !")
34
34
            return 1
35
35
        # remove temp files if they exist
36
36
        os.system("umount /media/floppy 2>/dev/null")
51
51
        os.system("umount %s" % self.image_dir)
52
52
        # start testing
53
53
        (noFloppyDisk, junkOutput1) = \
54
 
            commands.getstatusoutput("dd bs=1c if=%s count=0 2>/dev/null"
 
54
            subprocess.getstatusoutput("dd bs=1c if=%s count=0 2>/dev/null"
55
55
                                     % floppyDevice)
56
56
        if noFloppyDisk != 0:
57
 
            print "Error ! No floppy disc or bad media in %s !" % floppyDevice
 
57
            print("Error ! No floppy disc or bad media in %s !" % floppyDevice)
58
58
            return 1
59
59
        else:
60
60
            # writing files
61
 
            print "  Writing data to floppy disc ... "
 
61
            print("  Writing data to floppy disc ... ")
62
62
            (ddStatus, ddOutput) = \
63
 
                commands.getstatusoutput("dd if=%s of=%s bs=1k count=1440"
 
63
                subprocess.getstatusoutput("dd if=%s of=%s bs=1k count=1440"
64
64
                                         % (self.image, floppyDevice))
65
65
            if ddStatus == 0:
66
 
                print "  Write data to floppy disc done ! "
 
66
                print("  Write data to floppy disc done ! ")
67
67
            else:
68
 
                print "  Error ! Write data to floppy disc error ! "
69
 
                print "  Please check if your floppy disc is write-protected !"
 
68
                print("  Error ! Write data to floppy disc error ! ")
 
69
                print("  Please check if your floppy disc is write-protected !")
70
70
                return 1
71
71
            # comparing files
72
72
            os.system("mount %s %s" % (floppyDevice, self.device_dir))
73
73
            os.system("mount -o loop %s %s" % (self.image, self.image_dir))
74
 
            print "  Comparing files ... "
 
74
            print("  Comparing files ... ")
75
75
            fileList = os.listdir(self.image_dir)
76
76
            returnValue = 0
77
77
            for textFile in fileList:
78
78
                file1 = os.path.join(self.device_dir, textFile)
79
79
                file2 = os.path.join(self.image_dir, textFile)
80
80
                if filecmp.cmp(file1, file2):
81
 
                    print "        comparing file %s" % textFile
 
81
                    print("        comparing file %s" % textFile)
82
82
                else:
83
 
                    print ("  --  Error ! File %s comparison failed ! -- "
84
 
                           % textFile)
 
83
                    print("  --  Error ! File %s comparison failed ! -- "
 
84
                          % textFile)
85
85
                    returnValue = 1
86
 
            print "  File comparison done ! "
 
86
            print("  File comparison done ! ")
87
87
            # remove temp files
88
88
            os.system("umount /media/floppy 2>/dev/null")
89
89
            os.system("umount %s %s " % (self.image_dir, self.device_dir))
90
90
            os.system("rm -rf %s %s %s"
91
91
                      % (self.device_dir, self.image_dir, self.image))
92
 
            print "Done !"
 
92
            print("Done !")
93
93
            return returnValue
94
94
 
95
95