Created
March 24, 2011 14:06
-
-
Save mlashcorp/885113 to your computer and use it in GitHub Desktop.
Method to interact with cdrecord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def burn_data(self,PATH): | |
dir,file = (os.path.split(PATH)) | |
#unmount disc just in case (shouldn't be necessary for a blank disk) | |
p0 = Popen(["umount","/media/CDROM"],stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
#wait for unmount | |
p0.wait() | |
#create the isofs raw image to write to cd | |
p1 = Popen(["mkisofs","-R","-o","image.raw",PATH],stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
#wait for mkisofs to finish | |
p1.wait() | |
#burn isofs image to cd | |
p2 = Popen(["cdrecord","-v","speed=2","image.raw"],stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
#while p2 is running poll will return None | |
while p2.poll() is None: | |
line = p2.stdout.readline() | |
#This means that the cd was unwritable | |
if (find(line, "Re-load disk and hit <CR>") != -1): | |
p2.kill() | |
#in case of success signal from poll is 0 | |
#otherwise we have an error | |
burn_status = str(p2.poll()) | |
p3 = Popen(["eject"],stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
p3.wait() | |
return burn_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment