#!/usr/bin/env python # # import dialog from os import environ, popen, access import os.path import string import sys import shutil import popen2 import commands import ConfigParser ############################################### class Application: def __init__(self, lame, bladeenc, is_confile, has_section, confile, hostname): d=dialog.Dialog() self.title="CDR - v. 4.0 by EM" self.confile=confile self.hostname=hostname self.burn="burn" # default operation self.overburn='' # set overburning self.description='' self.author='' self.label='' self.lame=lame self.bladeenc=bladeenc self.speed=4 # default writer speed self.cdr_swap="/cdr_swap" # directory where store images self.dev="" # default device self.devtype="" # default device type self.eject="yes" # eject after burning self.burnfree= ' -driveropts=burnfree ' self.cdrdev="" self.dvdrwdev="" self.dvdrwdevtype="" self.selfilehelp=""" Option 1: Through this option you'll enter by hand all files/directories to save saparated by spaces. Option 2: Through this option you'll enter in a loop to permit you to choose files/directories to save using a File Selection Dialog. -------------------- | Directory | Files | | window... | window | -------------------- | /home/path window | -------------------- You can move through the windows using the TAB or CURSOR keys. To select a directory (under the "Directories" window) or a file (under the "Files" window) you have to press the SPACE BAR. To go down to the directories tree you have to select a directory using the SPACE BAR and add by hand a / character at the end of the path window. To go up to the directories tree you have to delete the most rigth paths in the path window: eg. if you have an entry like /home/project/test/ and you want to go to /home/project/ you have to delete the test/ part. You can select ONLY one file or directory from the File Selection Dialog using the SPACE BAR, so you have to select < OK >. You'll then ask if you want to select another file or directory. On the "Directories" or "Files" window you can also use the PAGE-DOWN or PAGE-UP keys to scroll down or up much faster." """ if not is_confile: msg="Configuration file not found.\nDo you want create configuration file\nfor %s ?" % hostname if d.yesno(msg, width=50, title=self.title) == d.DIALOG_OK: cf=1 self.cdr_options(d,cf) else: if not has_section: msg="Found a configuration file.\nDo you want create a configuration section for %s" % hostname if d.yesno(msg, width=40, title=self.title) == d.DIALOG_OK: cf=1 self.cdr_options(d,cf) else: config = ConfigParser.ConfigParser() config.read(self.confile) self.speed=config.get(self.hostname,'cdrw_speed') self.cdr_swap=config.get(self.hostname,'cdr_swap') self.dev=config.get(self.hostname,'cdrw_dev') self.devtype=config.get(self.hostname,'cdrw_devtype') self.eject=config.get(self.hostname,'cdrw_eject') self.burnfree=config.get(self.hostname,'burnfree') self.cdrdev=config.get(self.hostname,'cdr_dev') self.dvdrwdev=config.get(self.hostname,'dvdrw_dev') self.dvdrwdevtype=config.get(self.hostname,'dvdrw_devtype') self.menu(d) def handle_exit_code(self, d, code): if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): if code == d.DIALOG_CANCEL: self.menu(d) else: msg = "You pressed ESC in the last dialog box. Do you want to " \ "exit from cdr?" # "No" or "ESC" will bring the user back to the demo. # DIALOG_ERROR is propagated as an exception and caught in main(). # So we only need to handle OK here. if d.yesno(msg, title=self.title) == d.DIALOG_OK: sys.exit("Exited from %s" % self.title) return 0 else: return 1 # code is d.DIALOG_OK # Display initial menu def menu(self, d): while 1: (code, choose) = d.menu("Choose an option", width=60, title=self.title, item_help=1, choices=[("1", "General options","To use only if you want to override default options"), ("2", "Create image", "Select to create single or multi-session images"), ("3", "Save image", "Select to save single or multi-session images"), ("4", "Blank disc (only for CD-RW)", "Only to blank rewritable CDs"), ("5", "Copy CD to CD", "Select to copy a CD to another CD"), ("6", "DVD write", "Select to write on a DVD"), ("7", "Audio", "Various audio routines"), ("8", "Exit Program", "Exit from program")]) if self.handle_exit_code(d, code): break if choose == '1': self.cdr_options(d) elif choose == '2': self.createMenu(d) elif choose == '3': self.saveMenu(d) elif choose == '4': self.blankDisc(d) elif choose == '5': self.cpCD2CD2(d) elif choose == '6': self.dvdwrite(d) elif choose == '7': self.audioMenu(d) elif choose == '8': sys.exit("Exited from %s \n" % self.title) else: sys.exit("Exited from %s \n" % self.title) ######### Function to create Menu for Image Creation ############# def createMenu(self, d): while 1: (code, choose) = d.menu("Choose a create option", width=60, title=self.title, choices=[("1", "Create single session image"), ("2", "Create multi session image"), ("3", "Return to main menu")]) if self.handle_exit_code(d, code): break if choose == '1': self.create_ssimage(d) elif choose == '2': self.create_msimage(d) else: self.menu(d) ############# function to choose save image options ################### def saveMenu(self, d): while 1: (code, choose) = d.menu("Choose a save option", width=60, title=self.title, choices=[("1", "Save single session image"), ("2", "Save multi session image"), ("3", "Return to main menu")]) if self.handle_exit_code(d, code): break if choose == '1': self.cdrecord(d, mode=1) elif choose == '2': self.cdrecord(d, mode=2) else: self.menu(d) ############# function to choose audio options ######################## def audioMenu(self, d): while 1: (code, choose) = d.menu("Choose an audio option", width=60, title=self.title, choices=[("1", "Read all tracks from an audio CD"), ("2", "Read some tracks from an audio CD"), ("3", "Write tracks"), ("4", "Convert MP3 to WAV"), ("5", "Convert WAV to MP3"), ("6", "Return to main menu"), ("7", "Exit")]) if self.handle_exit_code(d, code): break if choose == "1": self.read_tracks(d, 1) elif choose == "2": self.read_tracks(d, 2) elif choose == "3": self.cdrecord(d, 3) elif choose == "4": self.mp32wav(d) elif choose == "5": self.wav2mp3(d) elif choose == "6": self.menu(d) elif choose == "7": sys.exit("Exit from %s \n" % self.title) else: self.menu(d) ############# function to set some cdr options ######################## def cdr_options(self, d, cf=0): setd = 0 while 1: (code, auto) = d.radiolist( "Autodetect cd-writer device\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("Yes", "Autodetect", 0), ("No", "Manual configuration", 1)]) if self.handle_exit_code(d, code): break while 1: (code, self.speed) = d.radiolist("Select cd-writer speed\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("2", "2x", 0), ("4", "4x", 0), ("6", "6x", 0), ("8", "8x", 1), ("10", "10x", 0), ("12", "12x", 0), ("16", "16x", 0), ("24", "24x", 0)]) if self.handle_exit_code(d, code): break while 1: (code, self.cdr_swap)=d.inputbox("\nEnter directory where CDR will store data", init="/cdr_swap", width=50, title=self.title) if self.handle_exit_code(d, code): break if self.cdr_swap == "": self.menu(d) if not os.path.isdir(self.cdr_swap): msg="%s: directory not found or %s is a file." % (self.cdr_swap, self.cdr_swap) d.msgbox(msg, width=40, title=self.title) self.menu(d) if os.path.isdir(self.cdr_swap) and not access(self.cdr_swap, os.W_OK): msg='Unable to write into %s.\nPermission denied.\nPlease call your sysadm.\n' % self.cdr_swap d.msgbox(msg, width=40, title=self.title) self.menu(d) if auto == 'Yes': pipe = popen2.popen2("cdrecord -scanbus 2>&1") output = pipe[0].readlines() devicelist = [] for i in range(len(output)): line = output[i] if (line[0] == "\t") and (line[1] in string.digits): if string.find(line, "CD-ROM") != -1: channel = line[1] id = line[3] lun = line[5] vendor = "%s %s %s" % (string.strip(line[13:21]), string.strip(line[24:40]), string.strip(line[43:47])) b="%s,%s,%s" % (channel,id,lun) dl=(b, vendor, 0) devicelist.append(dl) ## devicelist.append([channel, id, lun, vendor]) pipe[0].close pipe[0].close pipe = None if len(devicelist) == 0: pipe=popen2.popen2("cdrecord -scanbus dev=ATAPI 2>&1") output = pipe[0].readlines() devicelist = [] for i in range(len(output)): line = output[i] if (line[0] == "\t") and (line[1] in string.digits): if string.find(line, "CD-ROM") != -1: channel=line[1] id=line[3] lun=line[5] vendor="%s %s %s" % (string.strip(line[13:21]), string.strip(line[24:40]), string.strip(line[43:47])) b="%s,%s,%s" % (channel,id,lun) dl=(b, vendor, 0) devicelist.append(dl) ## devicelist.append([channel, id, lun, vendor]) pipe[0].close pipe[0].close pipe=None if len(devicelist) == 0: msg="Couldn't detect your cd-writer.\nPlease make sure that you are root,\nthat you're allowed to read /dev/sg*\nor that you have load modules.\n\nDo you want to set device manually?" if d.yesno(msg, width=50, title=self.title) == d.DIALOG_OK: self.menu(d) else: setd=1 if setd == 1: setd=0 while 1: (code, self.speed) = d.radiolist("Select cd-writer device\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("0,0,0", "device: 0, target 0, lun: 0", 1), ("0,1,0", "device: 0, target: 1, lun: 0", 0), ("0,2,0", "device: 0, target: 2, lun: 0", 0), ("0,3,0", "device: 0, target: 1, lun: 0", 0), ("/dev/cdroms/cdrom0", "ATAPI master cdrom", 0), ("/dev/cdroms/cdrom1", "ATAPI slave cdrom", 0), ("/dev/cdrw", "ATAPI cd-writer", 0), ("/dev/cdrom", "ATAPI generic cdrom device", 0), ("other...", "Enter device manually",0)]) if self.handle_exit_code(d, code): break if dev == 'other...': while 1: (code, dev)=d.inputbox("\nEnter device (in the form /dev/hdNX or 0,0,0)cd ", init="0,0,0", title=self.title) if self.handle_exit_code(d, code): break ## if len(dev) != 5: ## msg="Input error:\nremember to insert device in form:\nchannel,id,lun" ## d.msgbox(msg, width=50, title=self.title) ## self.menu() ## if dev[1] != ',' or dev[3] != ',': ## msg="Input error:\nremember to insert device in form:\nchannel,id,lun" ## d.msgbox(msg, width=40, title=self.title) ## self.menu() self.devtype="ATAPI" else: while 1: (code, self.dev)=d.radiolist("ATAPI DEVICEs found", width=65, title=self.title, choices=devicelist) if self.handle_exit_code(d, code): break self.devtype="ATAPI" ## self.dev="%s,%s,%s" % (ch[0], ch[1], ch[2]) else: msg="\nDetected cd-writer:\nCHANNEL,ID,LUN = %s\nVENDOR = %s" % (devicelist[0][0], devicelist[0][1]) d.msgbox(msg, width=50, height=20, title=self.title) self.dev=devicelist[0][0] elif auto == 'No': while 1: (code, self.cdrdev)=d.inputbox("\nEnter CD-WRITER device", width=50, title=self.title) if self.handle_exit_code(d, code): break if self.cdrdev=="": msg="Without cd-writer device is impossible to write CDs" d.msgbox(msg, width=40, title=self.title) self.menu(d) while 1: (code, self.cdrdev)=d.inputbox("\nEnter CD-READER device (if different by CD-WRITER) or press ENTER", width=50, title=self.title) if self.handle_exit_code(d, code): break while 1: (code, self.dvdrwdev)=d.inputbox("\nEnter DVD-WRITER device (if one) or press ENTER", width=50, title=self.title) if self.handle_exit_code(d, code): break while 1: self.burn = d.radiolist("Select cdr operation\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("burn", "Burn the CD", 0), ("test", "Test without burn the CD",1)]) if self.handle_exit_code(d, code): break while 1: (code, opts) = d.checklist("Select driver options\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("1", "Eject cd when finished",0), ("2", "Burn Free", 1), ("3", "Over Burn", 0)]) if self.handle_exit_code(d, code): break if '1' in opts: self.eject="Yes" else: self.eject="No" if '2' in opts: self.burnfree=' -driveropts=burnfree ' else: self.burnfree=' ' # vecchie versioni di cdrecord non supportano noburnfree #self.burnfree=' -driveropts=noburnfree ' if '3' in opts: self.overburn = ' -overburn ' else: self.overburn='' ## msg="eject=%s burnfree=%s overburn=%s" % (self.eject, self.burnfree, self.overburn) ## d.msgbox(msg) info=0 ##~ msg="\nDo you want to write personal\ninformations on the CD?" ##~ if not d.yesno(msg, width=50, title=self.title): ##~ self.menu() ##~ else: ##~ info=1 ##~ ##~ if info==1: ##~ author=d.inputbox("\nEnter the author", width=50, title=self.title) ##~ if author==None: ##~ self.menu() ##~ if author: ##~ self.author=" -p %s " % author ##~ description=d.inputbox("\nEnter a description of CD content", width=50, title=self.title) ##~ if description==None: ##~ self.menu() ##~ if description: ##~ self.description=" -A %s " % description ##~ label=d.inputbox("\nEnter a label", width=50, title=self.title) ##~ if label==None: ##~ self.menu() ##~ if label: ##~ self.label=" -V %s " % label # Configuration file creation for the hostname if cf: try: f=open(self.confile, 'a') except IOError, (errno, strerror): sys.exit("I/O Error(%s): %s %s\n" % (errno, confile, strerror)) f.write("[%s]\n" % self.hostname) f.write("cdrw_speed=%s\n" % self.speed) f.write("cdr_swap=%s\n" % self.cdr_swap) f.write("cdrw_devtype=%s\n" % self.devtype) f.write("cdrw_dev=%s\n" % self.dev) f.write("cdrw_eject=%s\n" % self.eject) f.write("cdr_dev=%s\n" % self.cdrdev) f.write("burnfree=%s\n" % self.burnfree) f.write("dvdrw_dev=%s\n" % self.dvdrwdev) f.write("dvdrw_devtype=\n") f.close() while 1: (code, choose) = d.menu("Choose an option", width=60, title=self.title, choices=[("1", "Create single session image"), ("2", "Save single session image"), ("3", "Create multi session image"), ("4", "Save multi session image"), ("5", "Copy CD to CD"), ("6", "Blank disc"), ("7", "DVD write"), ("8", "Audio selections"), ("9", "Return to main menu"), ("10", "Exit")]) if self.handle_exit_code(d, code): break if choose == "1": self.create_ssimage(d) elif choose == "3": self.create_msimage(d) elif choose == "2": self.cdrecord(d,1) elif choose == "4": self.cdrecord(d, 2) elif choose == '6': self.blankDisc(d) elif choose == "5": self.cpCD2CD2(d) elif choose == '7': self.dvdwrite(d) elif choose == "8": self.audioMenu(d) elif choose == "9": self.menu(d) elif choose == "10": sys.exit("Exited from %s" % self.title) ############# function to check cd size ######################## def get_media_capacity(self): if self.devtype=="ATAPI": DEV="ATA:%s" % self.dev else: DEV="%s" % self.dev media_raw_info=popen2.popen2('cdrdao disk-info --device %s 2>&1' % DEV) lines=media_raw_info[0].readlines() for line in lines: if line.startswith('Total Capacity'): if line.split(':')[1].strip()=='n/a': return None return line.split()[6].split('/')[0] return None def get_media_capacity_remaining(self): if self.devtype=="ATAPI": DEV="ATA:%s" % self.dev else: DEV="%s" % self.dev media_raw_info=popen2.popen2('cdrdao disk-info --device %s 2>&1' % DEV) lines=media_raw_info[0].readlines() for line in lines: if line.startswith('Remaining Capacity'): if line.split(':')[1].strip()=='n/a': return None return line.split()[6].split('/')[0] return None def check_media_empty(self): """check if cdrom is empty using cdrdao""" if self.devtype=="ATAPI": DEV="ATA:%s" % self.dev else: DEV="%s" % self.dev media_raw_info=popen2.popen2('cdrdao disk-info --device %s 2>&1' % DEV) lines=media_raw_info[0].readlines() for line in lines: if line.startswith('CD-R empty'): if line.split(':')[1].strip()=='yes': return True return False return False def check_if_appendable(self): """check if cdrom is empty using cdrdao""" if self.devtype=="ATAPI": DEV="ATA:%s" % self.dev else: DEV="%s" % self.dev media_raw_info=popen2.popen2('cdrdao disk-info --device %s 2>&1' % DEV) lines=media_raw_info[0].readlines() for line in lines: if line.startswith('Appendable'): if line.split(':')[1].strip()=='yes': return True return False return False ############# function to create single session image ################ def create_ssimage(self, d, mntpoint=''): """ Function to create a single session image """ #msg='Options: cdr_swap=%s \n dev=%s \n speed=%s \n burn=%s \n eject=%s\n author=%s\n description=%s\n label=%s\n' % (self.cdr_swap, self.dev, self.speed, self.burn, self.eject, self.author, self.description, self.label) #d.msgbox(msg, title=self.title) IMAGE="%s/image.cdr" % self.cdr_swap if self.devtype=="ATAPI": DEV="dev=ATAPI:%s" % self.dev else: DEV="dev=%s" % self.dev MKISOFS="/usr/bin/mkisofs" MKISOFS_OPTIONS=" -v -l -r -T -f -J -hide-joliet-trans-tbl %s %s %s " % (self.description, self.author, self.label) CDRECORD="/usr/bin/cdrecord" CDRECORD_OPTIONS=" -v " #msg='Options: cdr_swap=%s \n %s \n speed=%s \n burn=%s \n eject=%s\n' % (cdr_swap, DEV, speed, burn, eject) #d.msgbox(msg, title=self.title) if not os.path.isdir(self.cdr_swap): msg="%s: directory not found or %s is a file." % (self.cdr_swap, self.cdr_swap) d.msgbox(msg, width=40, title=self.title) self.menu(d) if os.path.isdir(self.cdr_swap) and not access(self.cdr_swap, os.W_OK): msg='Unable to write into %s.\nPermission denied.\nPlease call your sysadm.\n' % self.cdr_swap d.msgbox(msg, width=40, title=self.title) self.menu(d) if os.path.isfile(IMAGE): msg='There is a multi session image in %s.\nDo you want to remove it?\n' % self.cdr_swap if d.yesno(msg, width=50, title=self.title) != d.DIALOG_OK: self.menu(d) else: try: os.unlink(IMAGE) except: msg='Cannot remove old image\n\n %s.\n\nPermission denied.\nPlease call your sysadm.\n' % IMAGE d.msgbox(msg, height=20, width=60, title=self.title) self.menu(d) if self.devtype=="ATAPI": msg="""Have you inserted a recordable cdrom in the CD-WRITER?\n\n Note: you have an ATAPI CD-WRITER, the eject operation will take more time.\n To avoid this, you can select YES and insert the CD into the CD-WRITER manually.\n\n Note that if there isn't a CD on the CD-WRITER the program enter in a loop trying to detect the size of the media. """ else: msg="""Have you inserted a recordable cdrom in the CD-WRITER?\n\n Note that if there isn't a CD on the CD-WRITER the program enter in a loop trying to detect the size of the media.""" if d.yesno(msg, height=20, width=50, title=self.title) != d.DIALOG_OK: command="%s %s -eject 2>&1" % (CDRECORD, DEV) pipe=popen2.popen2(command) output=pipe[0].readlines() for i in range(len(output)): line=output[i] if string.find(line, 'WARNING') != -1: msg="WARNING: \nOperation not permitted.\nCannot do mlockall." d.msgbox(msg, width=50, title=self.title) self.menu(d) pipe[0].close() pipe[1].close() d.msgbox("Please, insert a recordable cdrom in CD-WRITER \nand press ENTER when ready.", width=40, title=self.title) cap=self.get_media_capacity() if cap: msg="CD capacity: %s MB\n\nIs it correct?" % cap if d.yesno(msg) != d.DIALOG_OK: while 1: (code, cap)=d.radiolist("Capacity in MB of your recordable cdrom\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("650","",0), ("700","",0), ("800","",1)]) if self.handle_exit_code(d, code): break else: while 1: (code, cap)=d.radiolist("Capacity in MB of your recordable cdrom\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("650","",0), ("700","",0), ("800","",1)]) if self.handle_exit_code(d, code): break isempty=self.check_media_empty() if not isempty: msg="Your CD isn't empty. You cannot create a single session" d.msgbox(msg,width=40, title=self.title) self.menu(d) while 1: (code, fsel)=d.menu("Select the file selection mode", width=65, title=self.title, item_help=1, help_button=1, choices=[("1","Enter manually each file/directory",""), ("2","Through File Selection Dialog","")]) if code=="help": msg=self.selfilehelp d.msgbox(msg, width=65, height=20, title=self.title) continue if self.handle_exit_code(d, code): break if len(mntpoint) == 0: if fsel=="1": while 1: (code, files) = d.inputbox("\nEnter files/directories to save", init="", width=60, title=self.title) if self.handle_exit_code(d, code): break if files is None: self.menu(d) if len(files) == 0: self.menu(d) else: files="" risp=d.DIALOG_OK while risp==d.DIALOG_OK: while 1: root_dir = os.sep # This is OK for UNIX systems dir = os.getenv("HOME", root_dir) # Make sure the directory we chose ends with os.sep() so that dialog # shows its contents right away if dir and dir[-1] != os.sep: dir = dir + os.sep (code, path) = d.fselect(dir, 10, 50, title=self.title) if self.handle_exit_code(d, code): break files=files+" "+path ## d.msgbox(files) msg="Do you want to select another file or directory?" risp=d.yesno(msg, title=self.title) else: files=mntpoint f2s=string.split(files, " ") tots=0 ## msg="%s" % f2s ## d.msgbox(msg) ## total files size calculation for i in range(len(f2s)): if len(f2s[i])<=1: continue if os.path.isfile(f2s[i]) or os.path.isdir(f2s[i]): size=self.du(f2s[i]) tots=tots+size else: msg="\n %s: no such file or directory. \n" % f2s[i] d.msgbox(msg, width=40, title=self.title) self.menu(d) icap=int(cap) if (tots/1048576) > int(cap): ## if tots > (icap*1024*1024): msg='The size of your data is too large: %s bytes\n\nDo you want to use overburn option? (You can write more than 15MB)' % tots if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: self.menu(d) else: self.overburn=' -overburn ' kb=tots/1024 if kb > 1024: mb=kb/1024 msg='The total size of your files/directories is:\n %s MBytes\n\nContinue?' % mb else: msg='The total size of your files/directories is:\n %s KBytes\n\nContinue?' % kb if d.yesno(msg, width=50, title=self.title) != d.DIALOG_OK: self.menu(d) if len(mntpoint) > 0: command="%s %s -o %s %s" % (MKISOFS, MKISOFS_OPTIONS, IMAGE, mntpoint) else: command="%s %s -o %s -graft-points " % (MKISOFS, MKISOFS_OPTIONS, IMAGE) for i in range(len(f2s)): if len(f2s[i])<=1: continue if os.path.isdir(f2s[i]): if string.find(f2s[i],"/") != -1: filename=string.split(f2s[i],"/")[-1] command="%s %s/=%s" % (command, filename, f2s[i]) else: command="%s %s/=%s" % (command, f2s[i], f2s[i]) else: command="%s %s" % (command, f2s[i]) command="%s 2>&1" % command pipe=popen2.popen2(command) line=None d.gauge_start("Progress: 0%", title=' Image Creation ') p=0 while (line != ""): line=pipe[0].readline() if string.find(line, "Unable") != -1: msg="\nmkisofs: \nUnable to open %s." % IMAGE d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line, "done") != -1: sline=string.lstrip(line) i=string.find(sline,"%"); p=float(sline[:i]) msg='Creation percentage: %2.2f ' % p d.gauge_update(p, msg, update_text=1) d.gauge_stop() pipe[0].close() pipe[1].close() msg="The new image %s was created.\nDo you want save it?" % IMAGE if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: self.menu(d) else: self.cdrecord(d, 1) sys.exit() ############ function to create multi session image ################ def create_msimage(self, d): """ Function to create multi session image """ #msg='Options: cdr_swap=%s \n dev=%s \n speed=%s \n burn=%s \n eject=%s\n' % (cdr_swap, dev, speed, burn, eject) #d.msgbox(msg, title=self.title) IMAGE="%s/imageM.cdr" % self.cdr_swap if self.devtype=="ATAPI": DEV="dev=ATAPI:%s" % self.dev else: DEV="dev=%s" % self.dev MKISOFS="/usr/bin/mkisofs" MKISOFS_OPTIONS=" -v -l -r -T -f -J -hide-joliet-trans-tbl %s %s %s " % (self.description, self.author, self.label) CDRECORD="/usr/bin/cdrecord" DIRM="%s/multi" % self.cdr_swap if not os.path.isdir(self.cdr_swap): msg="%s: directory not found or %s is a file." % (self.cdr_swap, self.cdr_swap) d.msgbox(msg, width=40, title=self.title) self.menu(d) if os.path.isdir(self.cdr_swap) and not access(self.cdr_swap, os.W_OK): msg='Unable to write into %s.\nPermission denied.\nPlease call your sysadm.\n' % self.cdr_swap d.msgbox(msg, width=40, title=self.title) self.menu(d) if os.path.isdir(DIRM): try: shutil.rmtree(DIRM) except: msg='Cannot remove\n\n %s.\nPermission denied.\n\nPlease call your sysadm.\n' % DIRM d.msgbox(msg, height=30, width=60, title=self.title) self.menu(d) if os.path.isfile(IMAGE): msg='There is a multi session image in %s.\nDo you want to remove it?\n' % self.cdr_swap if d.yesno(msg, width=50, title=self.title) != d.DIALOG_OK: self.menu(d) else: try: os.unlink(IMAGE) except: msg='Cannot remove old image %s.\nPermission denied.\nPlease call your sysadm.\n' % IMAGE d.msgbox(msg, width=40, title=self.title) self.menu(d) if self.devtype=="ATAPI": msg="""Have you inserted a recordable cdrom in the CD-WRITER?\n\n Note: you have an ATAPI CD-WRITER, the eject operation will take more time.\n To avoid this, you can select YES and insert the CD into the CD-WRITER manually.\n\n Note that if there isn't a CD on the CD-WRITER the program enter in a loop trying to detect the size of the media. """ else: msg="""Have you inserted a recordable cdrom in the CD-WRITER?\n\n Note that if there isn't a CD on the CD-WRITER the program enter in a loop trying to detect the size of the media.""" if d.yesno(msg, height=30, width=50, title=self.title) != d.DIALOG_OK: command="%s %s -eject 2>&1" % (CDRECORD, DEV) pipe=popen2.popen2(command) output=pipe[0].readlines() for i in range(len(output)): line=output[i] if string.find(line, 'WARNING') != -1: msg="WARNING: \nOperation not permitted.\nCannot do mlockall." d.msgbox(msg, width=40, title=self.title) self.menu(d) pipe[0].close() pipe[1].close() d.msgbox("Please, insert a recordable cdrom into CD-WRITER \nand press ENTER when ready.", width=50, title=self.title) cap=self.get_media_capacity() if cap: msg="CD capacity: %s MB\n\nIs it correct?" % cap if d.yesno(msg, title=self.title) != d.DIALOG_OK: while 1: (code, cap)=d.radiolist("Capacity in MB of your recordable cdrom\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("650","",0), ("700","",0), ("800","",1)]) if self.handle_exit_code(d, code): break else: while 1: (code, cap)=d.radiolist("Capacity in MB of your recordable cdrom\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("650","",0), ("700","",0), ("800","",1)]) if self.handle_exit_code(d, code): break newcd=0 command = "%s %s -msinfo 2>&1" % (CDRECORD, DEV) pipe=popen2.popen2(command) output=pipe[0].readlines() for i in range(len(output)): line=output[i] if string.find(line, 'Cannot open SCSI driver.') != -1: msg="\n Cannot open SCSI driver.\n\nTry to choose CD-writer options\nand set Autodetect cd-writer" d.msgbox(msg, width=50, title=self.title) self.menu(d) if string.find(line, 'No disk / Wrong disk!') != -1: msg="\n Input/output error.\nNo disk on cd writer or wrong disk." d.msgbox(msg, width=50, title=self.title) self.menu(d) if string.find(line, 'no CD/DVD-Drive found on this target') != -1: msg="\n Sorry, no CD/DVD-Drive found on this target." d.msgbox(msg, width=50, title=self.title) self.menu(d) if string.find(line, 'Cannot read first writable address') != -1: msg='\n Cannot read first writable address. \n The CD should be corrupted.' d.msgbox(msg, width=50, title=self.title) self.menu(d) if string.find(line, 'Cannot read session offset') != -1: newcd=1 elif string.find(line,'0,0') != -1: newcd=1 else: ms=line newcd=2 pipe[0].close pipe[1].close msinfo=ms[:-1] if newcd == 1: d.msgbox("\nFound a new CD\n", width=40, title=self.title) elif newcd == 2: ifappendable=self.check_if_appendable() if not ifappendable: msg="The CD doesn't accept new data" d.msgbox(msg, width=40, title=self.title) self.menu(d) ## command="%s %s -toc" % (CDRECORD, DEV) ## tracks=0 ## f='' ## pipe=popen2.popen2(command) ## output=pipe[0].readlines() ## for i in range(len(output)): ## line=output[i] ## if string.find(line, 'track:') != -1: ## tracks=tracks+1 ## if (line[0:15] == 'track:lout lba:'): ## f=line[16:26] ## ## est=int(f) ## ## sizest=est*2048/1024 # size estimation of cd tracks ## tracks=tracks-1 ## if sizest > 1024: ## sizest=sizest/1024 ## msg="\nFound %d tracks\nOccupation size estimation:\n %sMB" % (tracks, sizest) ## else: ## msg="\nFound %d tracks\nOccupation size estimation:\n %sKB" % (tracks, sizest) remaining_space=self.get_media_capacity_remaining() msg="Space remaining on CD: %s MB" % remaining_space d.msgbox(msg, width=40, title=self.title) while 1: (code, fsel)=d.menu("Select the file selection mode", width=65, title=self.title, item_help=1, help_button=1, choices=[("1","Enter manually each file/directory",""), ("2","Through File Selection Dialog","")]) if code=="help": msg=self.selfilehelp d.msgbox(msg, width=65, height=20, title=self.title) continue if self.handle_exit_code(d, code): break if fsel=="1": while 1: (code, files) = d.inputbox("\nEnter files/directories to save", init="", width=60, title=self.title) if self.handle_exit_code(d, code): break if files is None: self.menu(d) if len(files) == 0: self.menu(d) else: files="" risp=d.DIALOG_OK while risp==d.DIALOG_OK: while 1: root_dir = os.sep # This is OK for UNIX systems dir = os.getenv("HOME", root_dir) # Make sure the directory we chose ends with os.sep() so that dialog # shows its contents right away if dir and dir[-1] != os.sep: dir = dir + os.sep (code, path) = d.fselect(dir, 10, 50, title=self.title) if self.handle_exit_code(d, code): break files=files+" "+path ## d.msgbox(files) msg="Do you want to select another file or directory?" risp=d.yesno(msg, title=self.title) f2s=string.split(files, " ") tots=0 ## total files size calculation for i in range(len(f2s)): if len(f2s[i])<=1: continue if os.path.isfile(f2s[i]) or os.path.isdir(f2s[i]): size=self.du(f2s[i]) tots=tots+size else: msg="\n %s: no such file or directory. \n" % f2s[i] d.msgbox(msg, width=40, title=self.title) self.menu(d) icap=int(cap) if newcd == 1: if (tots/1048576) > int(cap): ## if tots > (icap*1000000): msg="The size of your data is too large: %s bytes" % tots d.msgbox(msg, width=40, title=self.title) self.menu(d) else: ## if (tots + est*2048) > (icap*1000000): # check if there is space available on CD if (tots/1048576) > int(remaining_space): msg='The size of your data is too large: %s bytes' % tots d.msgbox(msg, width=40, title=self.title) self.menu(d) kb=tots/1024 if kb > 1024: mb=kb/1024 msg='The total size of your files/directories is:\n %s MBytes\n\nContinue?' % mb else: msg='The total size of your files/directories is:\n %s KBytes\n\nContinue?' % kb if newcd == 2: msg="%s\nNow your data are copied into swap directory.\nThis may take some time.\n\nContinue?" % msg if d.yesno(msg, width=60, title=self.title) != d.DIALOG_OK: self.menu(d) command="%s %s -o %s " % (MKISOFS, MKISOFS_OPTIONS, IMAGE) if newcd == 2: if (not os.path.exists(DIRM)): try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to create %s: \n %s.' % (DIRM, strerror) d.msgbox(msg, width=40, title=self.title) self.menu(d) else: cmd="rm -rf %s 2>&1" % DIRM pipe=popen2.popen2(cmd) output=pipe[0].readlines() for i in range(len(output)): line=output[i] if string.find(line, "Permission denied") != -1: msg="\nCannot unlink %s.\nPermission denied." % DIRM d.msgbox(msg, width=40, title=self.title) self.menu(d) pipe[0].close pipe[1].close try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to create %s: \n %s.' % (DIRM, strerror) d.msgbox(msg, width=40, title=self.title) self.menu(d) for i in range(len(f2s)): cmd = "cp -rd %s %s 2>/dev/null" % (f2s[i], DIRM) os.system(cmd) if newcd == 1: command=" %s -graft-points " % command for i in range(len(f2s)): if len(f2s[i])<=1: continue if os.path.isdir(f2s[i]): if string.find(f2s[i],"/") != -1: filename=string.split(f2s[i],"/")[-1] command="%s %s/=%s" % (command, filename, f2s[i]) else: command="%s %s/=%s" % (command, f2s[i], f2s[i]) else: command="%s %s" % (command, f2s[i]) elif newcd == 2: command=" %s -C%s -M%s %s" % (command, msinfo, DEV, DIRM) command="%s 2>&1" % command pipe=popen2.popen2(command) line=None d.gauge_start("Progress: 0%", title=' Image Creation ') p=0 while (line != ""): line=pipe[0].readline() if string.find(line, "Unable") != -1: msg="mkisofs: \nUnable to open %s." % IMAGE d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line, "Read error on old image") != -1: msg="mkisofs:\nRead error on old image" d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line, "done") != -1: sline=string.lstrip(line) i=string.find(sline,"%"); if i != -1: p=float(sline[:i]) msg='Creation percentage: %2.2f ' % p d.gauge_update(p, msg, update_text=1) d.gauge_stop() pipe[0].close() pipe[1].close() if os.path.exists(DIRM): cmd="rm -rf %s" % DIRM line=commands.getoutput(cmd) if string.find(line, "Permission denied") != -1: msg='\n Unable to remove %s: \n Permission denied.' % (DIRM) d.msgbox(msg, width=40, title=self.title) self.menu(d) if not os.path.isfile(IMAGE): msg="There was a problem during image creation" d.msgbox(msg, width=40, title=self.title) self.menu(d) # msg="The new image %s was created.\nDo you want save it?" % IMAGE if d.yesno(msg, width=50, title=self.title) != d.DIALOG_OK: self.menu(d) else: self.cdrecord(d, 2) sys.exit() ############ Saving images ################################### def cdrecord(self, d, mode=1): # mode == 1: save single session image # mode == 2: save multi session image # mode == 3: save audio tracks #msg='Options: cdr_swap=%s \n dev=%s \n speed=%s \n burn=%s \n eject=%s\n' % (cdr_swap, dev, speed, burn, eject) #d.msgbox(msg, title=self.title) if mode == 1: IMAGE = "%s/image.cdr" % self.cdr_swap msg = "Ready to write single session image on" elif mode == 2: IMAGE = "%s/imageM.cdr" % self.cdr_swap msg = "Ready to write multi session image on" elif mode == 3: while 1: (code, cap)=d.radiolist("Capacity in MB of your recordable cdrom\n(Remember to press the space bar to select the option)", width=65, title=self.title, choices=[("650","",0), ("700","",0), ("800","",1)]) if self.handle_exit_code(d, code): break icap=int(cap) DIRM = "%s/AUDIO" % self.cdr_swap try: wav_list = os.listdir(DIRM) except OSError, (errno, strerror): msg="Enter WAV files directory:" while 1: (code, DIRM)=d.inputbox(msg, width=40, title=self.title) if self.handle_exit_code(d, code): break if len(DIRM) == 0: self.menu(d) elif DIRM == "": self.menu(d) try: wav_list = os.listdir(DIRM) except OSError, (errno, strerror): msg="\nCannot read the contents of %s.\n%s\n\nAre you sure that there are wav\nfiles into %s?" % (DIRM, strerror, DIRM) d.msgbox(msg, height=15, width=50, title=self.title) self.audioMenu(d) n_tracks = len(wav_list) if n_tracks == 0: msg = "\nNo tracks found to write." d.msgbox(msg, width=40, title=self.title) self.menu(d) n = 0 tracks_to_write = "" for i in wav_list: if i[len(i)-3:len(i)] == 'wav': tracks_to_write = "%s %s/%s" % (tracks_to_write, DIRM, i) n=n+1 if n == 0: msg = "\nNo tracks found to write." d.msgbox(msg, width=40, title=self.title) self.menu(d) size=self.du(DIRM) if size > (icap*1024*1024): msg='The size of your data is too large: %s bytes\n\nDo you want to use overburn option? (You can write more than 15MB)' % size if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: self.menu(d) else: self.overburn=' -overburn ' kb=size/1024 if kb > 1024: mb=kb/1024 msg='The total size of your files/directories is: %s MBytes\n\nContinue?' % mb else: msg='The total size of your files/directories is: %s KBytes\n\nContinue?' % kb if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: self.menu(d) msg="Ready to write %s tracks on" % n if self.devtype=="ATAPI": DEV="dev=ATAPI:%s" % self.dev else: DEV="dev=%s" % self.dev SPEED="-speed=%s" % self.speed CDRECORD="/usr/bin/cdrecord" if self.burn == 'test': CDRECORD_OPTIONS=" -v -dummy %s %s " % (self.overburn, self.burnfree) else: CDRECORD_OPTIONS=" -v %s %s " % (self.overburn, self.burnfree) if self.eject == 'Yes': CDRECORD_OPTIONS='%s -eject' % CDRECORD_OPTIONS LOG="/tmp/cdr_log" AUDIO_OPTS=" -swab -pad -audio " if os.path.isfile(LOG): try: os.unlink(LOG) except: LOG='/tmp/cdr_log2' msg="%s\nDEVICE=%s at speed=%s, mode=%s,\neject=%s driveropts=%s\nStart to write?" % (msg, self.dev, self.speed, self.burn, self.eject, self.burnfree) if d.yesno(msg, height=30, width=60, title=self.title) != d.DIALOG_OK: self.menu(d) if mode==2: msg='\n It seems to be necessary to reload the media.\n Choose [YES] to continue or [NO] to skip.' if d.yesno(msg, width=50, title=self.title) != d.DIALOG_OK: pass else: cmd='%s %s -eject' % (CDRECORD, DEV) commands.getoutput(cmd) cmd='%s %s -load' % (CDRECORD, DEV) msg=commands.getoutput(cmd) if string.find(msg, 'not ready') != -1: msg='\n Device not ready. \n Please, contact your system administrator.' d.msgbox(msg, width=50, title=self.title) self.menu(d) if mode == 1 or mode == 2: if not os.path.isfile(IMAGE): msg="CDR:\nNo image found to save" d.msgbox(msg, width=40, title=self.title) self.menu(d) if mode == 1: command = "%s %s %s %s %s 2>%s " % (CDRECORD, DEV, SPEED, CDRECORD_OPTIONS, IMAGE, LOG) elif mode == 2: command = "%s %s %s -multi %s %s 2>%s" % (CDRECORD, DEV, SPEED, CDRECORD_OPTIONS, IMAGE, LOG) elif mode == 3: command = "%s %s %s %s %s %s 2>%s" % (CDRECORD, DEV, SPEED, CDRECORD_OPTIONS, AUDIO_OPTS, tracks_to_write, LOG) os.system(command) if os.path.isfile(LOG): f=open(LOG,"r") log=f.readlines() f.close() for i in range(len(log)): line=log[i] if string.find(line, 'WARNING: Cannot set RR-scheduler') != -1: pass elif string.find(line, "Drive does not support TAO recording") != -1: if mode == 1: command = "%s %s %s %s %s 2>%s " % (CDRECORD, DEV, SPEED, CDRECORD_OPTIONS, IMAGE, LOG) elif mode == 2: command = "%s %s %s -multi %s %s 2>%s" % (CDRECORD, DEV, SPEED, CDRECORD_OPTIONS, IMAGE, LOG) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) os.system(command) break elif string.find(line, "Bad driver opts 'burnfree'") != -1: msg="Warning: your cdrecord version doesn't supply burnfree option.\nTry to disable burnfree option in CD-writer options." d.msgbox(msg, height=20, width=70, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) elif string.find(line, 'WARNING') != -1: msg="Warning: Operation not permitted.\nCannot start to write CD\nPossible CD rewritable not formatted\nor device error." d.msgbox(msg, width=50, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) elif string.find(line, 'Input/output error') != -1: msg="Error: Input/Output error.\nAn error occurred during cd write.\nProbably bad medium." d.msgbox(msg, width=50, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) elif string.find(line, 'Medium Error') != -1: msg="Error: Medium error.\nAn error occurred during cd write.\nProbably bad medium." d.msgbox(msg, width=50, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) elif string.find(line, "No disk / Wrong disk!") != -1: msg="\nCannot write on cd:\nNo disk or wrong disk." d.msgbox(msg, width=40, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) elif string.find(line, "Cannot open SCSI driver") != -1: msg="\nCannot open SCSI driver.\nModules problem?" d.msgbox(msg, width=40, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) if mode == 1 or mode == 2: if self.burn=='test': msg="\nBurning test ended succesfully\n" d.msgbox(msg, title=self.title) self.menu(d) try: output=commands.getoutput("rm -f %s 2>/dev/null" % IMAGE) except: pass try: output=commands.getoutput("rm -f %s" % LOG) except: pass msg="CDR:\nThe image has been saved on your CD and removed\nfrom disk." elif mode == 3: msg="CDR:\n all tracks was write on your CD" d.msgbox(msg, width=50, title=self.title) self.menu(d) ################################################################### ##### DVD ############ DVD write using growisofs ############################# def dvdwrite(self, d): d=dialog.Dialog() pipe = popen("/usr/bin/which growisofs 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no growisofs in") != -1): msg="You haven't the program to write DVD" d.msgbox(msg, width=40, title=self.title) self.menu(d) if self.dvdrwdev=='': msg="""Device to write DVD not present.\n Define it using 'General options' from the principal menu or edit /etc/cdr.conf""" d.msgbox(msg, width=50, title=self.title) self.menu(d) self.dvdmenu(d) def dvdmenu(self, d): while 1: (code, choose) = d.menu("Choose a DVD options", width=65, title=self.title, choices=[("1", "Write a DVD"), ("2", "Return to main menu"), ("3", "Exit")]) if self.handle_exit_code(d, code): break if choose == "1": self.dvdwriting(d) elif choose == "2": self.menu(d) elif choose == "3": sys.exit("Exit from %s " % self.title) def dvdwriting(self, d): msg="""This routine is in beta test. \n Actually it's possible only to write a single big image (4.7GB) at once. All the operations takes a long time.\n\n Do you want to continue?""" if d.yesno(msg, width=60, height=20, title=self.title) != d.DIALOG_OK: self.menu(d) while 1: (code, fsel)=d.menu("Select the file selection mode", width=65, title=self.title, item_help=1, help_button=1, choices=[("1","Enter manually each file/directory",""), ("2","Through File Selection Dialog","")]) if code=="help": msg=self.selfilehelp d.msgbox(msg, width=65, height=20, title=self.title) continue if self.handle_exit_code(d, code): break if fsel=="1": while 1: (code, files) = d.inputbox("\nEnter files/directories to save", init="", width=60, title=self.title) if self.handle_exit_code(d, code): break if files is None: self.menu(d) if len(files) == 0: self.menu(d) else: files="" risp=d.DIALOG_OK while risp==d.DIALOG_OK: while 1: root_dir = os.sep # This is OK for UNIX systems dir = os.getenv("HOME", root_dir) # Make sure the directory we chose ends with os.sep() so that dialog # shows its contents right away if dir and dir[-1] != os.sep: dir = dir + os.sep (code, path) = d.fselect(dir, 10, 50, title=self.title) if self.handle_exit_code(d, code): break files=files+" "+path ## d.msgbox(files) msg="Do you want to select another file or directory?" risp=d.yesno(msg, title=self.title) f2s=string.split(files, " ") command="growisofs -Z %s -iso-level 4 -J -r -graft-points" % self.dvdrwdev for i in range(len(f2s)): if len(f2s[i])<=1: continue if os.path.isfile(f2s[i]) or os.path.isdir(f2s[i]): if os.path.isdir(f2s[i]): if string.find(f2s[i],"/") != -1: filename=string.split(f2s[i],"/")[-1] command="%s %s/=%s" % (command, filename, f2s[i]) else: command="%s %s/=%s" % (command, f2s[i], f2s[i]) else: command="%s %s" % (command, f2s[i]) else: msg="\n %s: no such file or directory. \n" % f2s[i] d.msgbox(msg, width=40, title=self.title) self.menu(d) msg="""Now the program start to check the total size of your data and burn your DVD. These operations takes a long time, so don't worry if the progress bar doesn't start. If you stops these operations you can fall down the DVD. Are you sure to continue?""" if d.yesno(msg, width=60, height=20, title=self.title) != d.DIALOG_OK: self.menu(d) command="%s 2>&1" % command os.system(command) pipe=popen2.popen2(command) line=None d.gauge_start("Progress: 0%", title=' Image Creation ') p=0 while (line != ""): line=pipe[0].readline() if string.find(line, "Unable") != -1: msg="\nmkisofs: \nUnable to open %s." % IMAGE d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line,"not recognized") != -1: msg="Cannot access to DVD media.\nDid you inserted a DVD on DVD-WRITER?" d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line,"No space left on device") != -1: msg="The size of your data is out of media." d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line,"blocks are free") != -1: ## msg="The size of your data (%d bytes) is out of media." % (int(line.split[6])*2) msg="The size of your data is out of media." d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line,"Unit won't start") != -1: msg="Cannot access to DVD media.\nDid you inserted a DVD on DVD-WRITER?" d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line,"unsupported MMC") != -1: msg="Cannot access to DVD media.\nDid you inserted a DVD on DVD-WRITER?" d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(line, "done") != -1: sline=string.lstrip(line) i=string.find(sline,"%"); p=float(sline[:i]) msg='Creation percentage: %2.2f ' % p d.gauge_update(p, msg, update_text=1) d.gauge_stop() pipe[0].close() pipe[1].close() msg="DVD created" d.msgbox(msg, width=40, title=self.title) self.menu(d) #################### Copy CD to CD using cdrdao ###################### def cpCD2CD2(self, d): if self.devtype=="ATAPI": DEV="dev=ATAPI:%s" % self.dev else: DEV="dev=%s" % self.dev dest=self.cdr_swap+'/image.cdr' if d.yesno("Do you want simulate the copy operations?", width=40, title=self.title) != d.DIALOG_OK: simulate=False else: simulate=True if d.yesno("Do you want to eject the CD after the copy?", width=40, title=self.title) != d.DIALOG_OK: eject=False else: eject=True cdrdao_line="cdrdao " if self.cdrdev=='': cdrdao_line = cdrdao_line + "copy " if simulate: cdrdao_line = cdrdao_line + "--simulate " if eject: cdrdao_line = cdrdao_line + "--eject " cdrdao_line = cdrdao_line + "--datafile " + dest + " --device " + self.dev + " " cdrdao_line = cdrdao_line + " --speed " + self.speed + " --fast-toc" msg="Place source CD in the recording unit.\n\nAnd press ENTER to begin reading" d.msgbox(msg,width=40,title=self.title) os.system(cdrdao_line) self.menu(d) else: cdrdao_line = cdrdao_line + "copy " if simulate: cdrdao_line = cdrdao_line + "--simulate " if eject: cdrdao_line = cdrdao_line + "--eject " cdrdao_line = cdrdao_line + "--device " + self.dev + " " cdrdao_line = cdrdao_line + "--source-device " + self.cdrdev + " " cdrdao_line = cdrdao_line + " --speed " + self.speed + " --on-the-fly --fast-toc " msg="Place the source CD in the CD drive\nand place a blank media in the recording unit.\n\nPress ENTER to begin on-the-fly copy" d.msgbox(msg, width=40,title=self.title) os.system(cdrdao_line) self.menu(d) ############# Blanck CD-WR ############################## def blankDisc(self, d): if self.devtype=="ATAPI": DEV="dev=ATAPI:%s" % self.dev else: DEV="dev=%s" % self.dev CDRECORD="/usr/bin/cdrecord " LOG="/tmp/cdr_log" msg="\nI'll do some checks before start.\nIts will takes a while." d.msgbox(msg, width=50, title=self.title) command=CDRECORD + DEV + ' -atip' output=commands.getoutput(command) if string.find(output, 'No disk / Wrong disk!') != -1: msg="\nNo disk / Wrong disk!" d.msgbox(msg, width=40, title=self.title) self.menu(d) if string.find(output, 'no CD/DVD-Drive found on this target') != -1: msg="\nSorry,\n no CD/DVD-Drive found on this target" d.msgbox(msg, width=50, title=self.title) self.menu(d) elif string.find(output, 'Is not erasable') != -1: msg="\nYou have insert a non rewritable CD" d.msgbox(msg, width=50, title=self.title) command=CDRECORD + DEV + ' -eject' output=commands.getoutput(command) self.menu(d) while 1: (code, choose)=d.radiolist("Select the blanking option", width=65, title=self.title, choices=[("All", "(take a long time)", 0), ("Fast", "Session (erase last session)",1)]) if self.handle_exit_code(d, code): break command=CDRECORD + DEV + " -speed=%s " % self.speed if choose=="All (take a long time)": command=command + " -blank=all 2>%s" % LOG elif choose=="Fast": command=command + " -blank=fast 2>%s" % LOG elif choose=="Session (erase last session)": command=command + " -blank=session 2>%s" % LOG msg="I'm ready to blank the CD.\nAre you sure to start?" if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: self.menu(d) if os.path.isfile(LOG): try: os.unlink(LOG) except: LOG='/tmp/cdr_log2' os.system(command) if os.path.isfile(LOG): f=open(LOG,"r") log=f.readlines() f.close() for i in range(len(log)): line=log[i] if string.find(line, 'WARNING') != -1: msg="Warning: Operation not permitted.\nCannot start to blank CD\nPossible wrong permissions to the device\nor device error." d.msgbox(msg, width=40, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) if string.find(line, "No disk / Wrong disk!") != -1: msg="\nCannot write on cd:\nNo disk or wrong disk." d.msgbox(msg, width=40, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) if string.find(line, "Cannot open SCSI driver") != -1: msg="\nCannot open SCSI driver.\nModules problem?" d.msgbox(msg, width=40, title=self.title) cmd="rm -f %s 2>/dev/null" % LOG os.system(cmd) self.menu(d) msg="\nYour disk is now blank" d.msgbox(msg, title=self.title) self.menu(d) sys.exit() ################################################################### ############## A U D I O F U N C T I O N S ############# ################################################################### #### function to read all audio tracks from an audio CD ########### def read_tracks(self, d, mode): CDREADER=self.cdrdev if CDREADER=='': while 1: (code, CDREADER)=d.inputbox("Unable to found cdrom device.\nEnter cdrom device:", width=40, title=self.title) if self.handle_exit_code(d, code): break if CDREADER=='': self.audioMenu(d) SWAP=self.cdr_swap DIRM="%s/AUDIO" % self.cdr_swap if self.devtype=="ATAPI": DEV="dev=ATAPI:%s" % self.dev else: DEV="dev=%s" % self.dev CDDA2WAV="/usr/bin/cdda2wav" IOPTS=" -N -J -v2 -I cooked_ioctl " # the -v options will be obsolete in the new versions of cdda2wav READOPTS=" -D %s -x -B -H -g -O wav " % CDREADER # Read options explain: # -x -> sets maximum (CD) quality # -B -> copies each track into separate file # -H -> does not write an info file and a cddb file # -g -> formats the output to be better parsable by gui frontends msg="Please insert an audio CD into CD Reader.\n\nPress ENTER when ready" d.msgbox(msg, width=50, title=self.title) command="%s -D%s %s 2>&1" % (CDDA2WAV, CDREADER, IOPTS) #d.msgbox(command) pipe=popen2.popen2(command) line=None boolTrackInfo=0 totalTime=0 numberOfTracks=0 while(line != ""): line=pipe[0].readline() stripped = string.strip(line) # remove leading or triling whitespaces if string.find(stripped, "Permission denied") != -1: msg="Unable to open audio CD.\nPermission denied while opening /dev/cdrom" d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if string.find(stripped, "No medium found") != -1: msg="\nUnable to read the audio CD.\nNo medium found." d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if string.find(stripped, "No such device") != -1: msg="\nUnable to read the audio CD.\nNo such device." d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if string.find(stripped, "Wrong medium type") != -1: msg='\n Unable to read the audio CD. \nWring medium type.' d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if string.find(stripped, "Input/output error") != -1: msg='\n Unable to read audio CD.\nNo medium found' d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if string.lower(stripped[0:18]) == "table of contents:": # compares first 18 characters TrackNum = string.find(stripped, "total tracks:") + 13 # find return the lowest index in stripped where the substring is found. In this case 19. # In fact from "Table of......." to the first character of 'total' there is 19 characters. # I add 13 to include 'total tracks:' # At the end the TrackNum variable is equal to 32 TrackNumEnd = string.find(stripped[TrackNum:], ",") + TrackNum # after the number of tracks there is a comma numberOfTracks = stripped[TrackNum:TrackNumEnd] TotalTime = string.find(stripped, "total time ") + 11 TotalTimeEnd = string.find(stripped[TotalTime:], ")") + TotalTime totalTime = stripped[TotalTime:TotalTimeEnd] boolTrackInfo = 0 elif (boolTrackInfo == 1): if stripped[0] in string.digits: songs = string.split(stripped, ",") for intCounter in range(len(songs)): # print a list of all tracks song = string.strip(songs[intCounter]) if (song != ""): tracknum = int(strip(song[:string.find(song, ".")])) length = string.strip(song[string.find(song, "(") + 1:string.find(song, ")")]) trackString = "Track: %s - Length: %s" % (string.zfill(tracknum, 2), length) # print trackString else: boolTrackInfo = 0 msg="Summary of source audio CD:\n\nTotal number of traks: %s\nTotal time: %s" % (numberOfTracks, totalTime) d.msgbox(msg, width=40, title=self.title) if (not os.path.exists(DIRM)): try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to create %s: \n %s.' % (DIRM, strerror) d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) else: cmd="rm -rf %s 2>&1" % DIRM pipe=popen2.popen2(cmd) output=pipe[0].readlines() for i in range(len(output)): line=output[i] if string.find(line, "Permission denied") != -1: msg="\nCannot unlink %s.\nPermission denied." % DIRM d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) pipe[0].close pipe[1].close try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to create %s: %s.\n' % (DIRM, strerror) d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) nof=int(numberOfTracks) if mode == 2: while 1: (code, track_list)=d.inputbox("\nEnter the number of each track\nthat you want save separated by comma", init="", width=40, title=TITLE) if handle_exit_code(d, code): break if track_list == "": self.audioMenu(d) tl=string.split(track_list, ',') for i in tl: if int(i) > nof: msg="Number of track %s is too big.\nMax tracks is: %s" % (i, numberOfTracks) d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if int(i) < 1: msg="\n\nWhat's means???" d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) # tracks = "%s %s" % (tracks, i) command = "%s %s" % (CDDA2WAV, READOPTS) for track in tl: try: record = "%s -t %s+%s %s/track-%s.wav" % (command, track, track, DIRM, track) # print record os.system(record) except KeyboardInterrupt: cmd="rm -rf %s 2>/dev/null" % DIRM os.system(cmd) self.audioMenu(d) elif mode == 1: command = "%s %s" % (CDDA2WAV, READOPTS) for track in range(1, nof): try: record = "%s -t %s+%s %s/track-%s.wav 2>&1" % (command, track, track, DIRM, track) os.system(record) except KeyboardInterrupt: cmd="rm -rf %s 2>/dev/null" % DIRM os.system(cmd) self.audioMenu(d) msg="\nAll your tracks are saved on\n%s" % DIRM d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) ########### function to convert MP3 files to WAV ######################### def mp32wav(self, d): #msg='Options: cdr_swap=%s \n dev=%s \n speed=%s \n burn=%s \n eject=%s\n' % (cdr_swap, dev, speed, burn, eject) #d.msgbox(msg, title=self.title) DIRM="%s/AUDIO" % self.cdr_swap MPG123="/usr/bin/mpg123" MPG123_OPTIONS=" --stereo -s " SOX="/usr/bin/sox" SOX_OPTIONS=" -t raw -r 44100 -w -s -c 2 - -t wav " if (not os.path.exists(DIRM)): try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to crete %s:\n %s.' % (DIRM, strerror) d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) else: msg="Directory %s exist. Should be empty, delete it?" % DIRM if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: cmd="rm -rf %s 2>&1" % DIRM pipe=popen2.popen2(cmd) output=pipe[0].readlines() for i in range(len(output)): line=output[i] if string.find(line, "Permission denied") != -1: msg="\nCannot unlink %s.\nPermission denied." % DIRM d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) pipe[0].close pipe[1].close try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to create %s: \n %s.' % (DIRM, strerror) d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) while 1: (code, mp3_dir)=d.inputbox("\nEnter the directory where MP3 files are stored.\n\ If your MP3 filenames are more than 70\ncharacters the output list should be bad.",width=60, height=15, init="", title=self.title) if self.handle_exit_code(d, code): break if mp3_dir == "": self.audioMenu(d) if not os.path.isdir(mp3_dir): msg="\n%s not found" % mp3_dir d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) try: mp3_list=os.listdir(mp3_dir) except OSError, (errno, strerror): msg="\nOS Error: %s" % strerror d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) except IOError, (errno, strerror): msg="\IO Error: %s" % strerror d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) #### create a list with only file *.mp3 ##### mp3_list3=[] for i in range(0, len(mp3_list)): path="%s/%s" % (mp3_dir, mp3_list[i]) if os.path.isfile(path): if string.lower(mp3_list[i][-4:]) == ".mp3": tp=(mp3_list[i],"",0) mp3_list3.append(tp) if len(mp3_list3) == 0: msg="\nNo MP3 files in %s" % mp3_dir d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) try: while 1: (code, mp3_files)=d.checklist("\nChoose MP3 files to convert", width=54, height=15, list_height=10, choices=mp3_list3) if self.handle_exit_code(d, code): break except IOError: msg="Some problems occurred during check\nof %s mp3 files.\nProbably you have special characters\n\ in some mp3 files\n like `" % mp3_dir d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if len(mp3_files) == 0: msg="\nNo MP3 files selected for conversion" d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) msg="\nYou have selected %s MP3 files to convert.\nThe convertion will take some times.\nStart convertion?" % len(mp3_files) if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: self.audioMenu(d) for i in range(0, len(mp3_files)): song="" for x in range(len(mp3_files[i])): if mp3_files[i][x] == " ": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == "'": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == "(": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == ")": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == "&": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == "]": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == "[": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == "{": song="%s\%s" % (song, mp3_files[i][x]) elif mp3_files[i][x] == "}": song="%s\%s" % (song, mp3_files[i][x]) else: song="%s%s" % (song, mp3_files[i][x]) # command="ls -la %s/%s" % (mp3_dir, song) # os.system(command) # print song if i<10: ns='0%s' % i else: ns=i command="%s %s %s/%s | %s %s %s/track_%s.wav 2>&1" % (MPG123, MPG123_OPTIONS, mp3_dir, song, SOX, SOX_OPTIONS, DIRM, ns) os.system(command) msg="Conversion complete.\nYou can found your wav files\n into %s" % DIRM d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) ########### function to convert WAV files to MP3 ######################### def wav2mp3(self, d): #msg='Options: cdr_swap=%s \n dev=%s \n speed=%s \n burn=%s \n eject=%s\n' % (cdr_swap, dev, speed, burn, eject) #d.msgbox(msg, title=self.title) if self.lame==1 or self.bladeenc==1: while 1: (code, PROGRAM)=d.radiolist('Choose the program to use fo conversion', width=50, title=self.title, choices=[("1", 'lame', 1), ("2", 'bladeenc', 0)]) if self.handle_exit_code(d, code): break elif self.lame==1 or self.bladeenc==0: PROGRAM='/usr/bin/lame -h ' elif self.bladeenc==1 or self.lame==0: PROGRAM='/usr/bin/bladeenc ' else: msg="You haven't program to do the conversion" d.msgbox(msg, title=self.title) self.audioMenu(d) DIRM="%s/AUDIO" % self.cdr_swap if (not os.path.exists(DIRM)): try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to crete %s:\n %s.' % (DIRM, strerror) d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) else: msg="Directory %s exist. Should be empty, delete it?" % DIRM if d.yesno(msg, width=40, title=self.title): cmd="rm -rf %s 2>&1" % DIRM pipe=popen2.popen2(cmd) output=pipe[0].readlines() for i in range(len(output)): line=output[i] if string.find(line, "Permission denied") != -1: msg="\nCannot unlink %s.\nPermission denied." % DIRM d.msgbox(msg, title=self.title) self.audioMenu(d) pipe[0].close pipe[1].close try: os.mkdir(DIRM, 0777) except OSError, (errno, strerror): msg='\n Unable to create %s: \n %s.' % (DIRM, strerror) d.msgbox(msg, title=self.title) self.audioMenu(d) while 1: (code, wav_dir)=d.inputbox("\nEnter the directory where WAV files are stored.\n\ If your WAV filenames are more than 70\ncharacters the output list should be bad.",width=60, height=15, init="", title=self.title) if self.handle_exit_code(d, code): break if wav_dir == "": self.audioMenu(d) if not os.path.isdir(wav_dir): msg="\n%s not found" % wav_dir d.msgbox(msg, title=self.title) self.audioMenu(d) try: wav_list=os.listdir(wav_dir) except OSError, (errno, strerror): msg="\nOS Error: %s" % strerror d.msgbox(msg, title=self.title) self.audioMenu(d) except IOError, (errno, strerror): msg="\IO Error: %s" % strerror d.msgbox(msg, title=self.title) self.audioMenu(d) #### create a list with only file *.wav ##### wav_list3=[] for i in range(0, len(wav_list)): path="%s/%s" % (wav_dir, wav_list[i]) if os.path.isfile(path): if string.lower(wav_list[i][-4:]) == ".wav": wl=(wav_list[i],"",0) wav_list3.append(wl) if len(wav_list3) == 0: msg="\nNo WAV files in %s" % wav_dir d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) try: while 1: (code, wav_files)=d.checklist("\nChoose WAV files to convert", width=60, title=self.title, choices=wav_list3) if self.handle_exit_code(d, code): break except IOError: msg="Some problems occurred during check\nof %s wav files.\nProbably you have special characters\n\ in some wav files\n like `" % wav_dir d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) if len(wav_files) == 0: msg="\nNo WAV files selected for conversion" d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) msg="\nYou have selected %s WAV files to convert.\nThe convertion will take some times.\nStart convertion?" % len(wav_files) if d.yesno(msg, width=40, title=self.title) != d.DIALOG_OK: self.audioMenu(d) for i in range(0, len(wav_files)): song="" for x in range(len(wav_files[i])): if wav_files[i][x] == " ": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == "'": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == "(": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == ")": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == "&": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == "]": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == "[": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == "{": song="%s\%s" % (song, wav_files[i][x]) elif wav_files[i][x] == "}": song="%s\%s" % (song, wav_files[i][x]) else: song="%s%s" % (song, wav_files[i][x]) if i<10: ns='0%s' % i else: ns=i command="%s %s/%s %s/%s.mp3 2>&1" % (PROGRAM, wav_dir, song, DIRM, song[:-4]) os.system(command) msg="Conversion complete.\nYou can found your mp3 files\n into %s" % DIRM d.msgbox(msg, width=40, title=self.title) self.audioMenu(d) ######################################################### ####### U T I L I T I E S ############ ######################################################### ######################################################### def mount(self, d, mntpoint): cmd="grep cdrom /etc/fstab" output=commands.getoutput(cmd) if len(output) > 2: CDREADER=string.split(output)[0] else: while 1: (code,CDREADER)=d.inputbox("Unable to found cdrom device.\nEnter cdrom device:", width=40, title=self.title) if self.handle_exit_code(d, code): break if CDREADER=='': self.menu(d) cmd='/bin/mount -t iso9660 %s %s' % (CDREADER, mntpoint) mnt=commands.getoutput(cmd) d.msgbox(mnt, width=50) if string.find(mnt, 'already mounted', 0) != -1: msg='\n Cdrom already mounted. \n\n Continue?.' if d.yesno(msg, title=self.title) != d.DIALOG_OK: self.menu(d) else: pass elif string.find(mnt, 'No medium found') != -1: msg='\n Unable to mount cdrom. \n No medium found.' d.msgbox(msg, width=40, title=self.title) self.menu(d) elif string.find(mnt, 'only root can do that') != -1: msg='\n Unable to mount cdrom. \n Only root can do that.' d.msgbox(msg, title=self.title) self.menu(d) elif string.find(mnt, 'does not exist') != -1: msg='\n Unable to mount cdrom. \n mount point %s does not exist.' % mntpoint d.msgbox(msg, title=self.title) self.menu(d) elif string.find(mnt, 'is write-protected, mounting read-only') != -1: pass elif len(mnt) > 0: msg='\n Unable to mount cdrom. Please, contact your system administrator.' d.msgbox(msg, width=50, title=self.title) self.menu(d) else: msg='\n CDROM mounted on %s \n Ready to proceed.' % mntpoint d.msgbox(msg, title=self.title) return ##### Remove a file or directory (recursive) and return the number of directories, files, bytes & links deleted ##### def rm(self, file, maximum = -1, deleted = 0): directories = files = bytes = links = 0L if os.path.islink(file): if (maximum == -1) or ((maximum != -1) and (deleted < maximum)): links = links + 1 os.unlink(file) elif os.path.isfile(file): filesize = os.lstat(file)[6] if (maximum == -1) or ((maximum != -1) and ((deleted + filesize) < maximum)): bytes = bytes + filesize files = files + 1 os.unlink(file) else: filelist = os.listdir(file) for i in range(len(filelist)): result = rm(file + "/" + filelist[i], maximum, bytes) directories = directories + result[0] files = files + result[1] bytes = bytes + result[2] links = links + result[3] filelist = os.listdir(file) if (maximum == -1) or ((len(filelist) == 0) and (maximum != -1) and (deleted < maximum)): os.rmdir(file) directories = directories + 1 return [directories, files, bytes, links] ############ function to obtain total size of selected files ##### def du(self, file): from os import listdir, lstat if (os.path.islink(file)) or (os.path.isfile(file)): size = lstat(file)[6] else: try: filelist = listdir(file) size = 0 for i in range(len(filelist)): size = size + self.du(file + "/" + filelist[i]) except: pass return size ################# function to strip each value of a list ########################### def striplist(list): from string import strip for i in range(len(list)): list[i] = strip(list[i]) return list ############# MAIN PROGRAM ############### def main(): ### Checking for required programs ### Check mkisofs sys.stdout.write("Checking for required programs: ") sys.stdout.write("mkisofs") pipe=popen("/usr/bin/which mkisofs 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no mkisofs in") != -1): mkisofs = 0 else: mkisofs = 1 ### Check cdrecord sys.stdout.write(" cdrecord") pipe = popen("/usr/bin/which cdrecord 2>&1") output = striplist(pipe.readlines()) pipe.close() if(string.find(output[0], "no cdrecord in") != -1): cdrec = 0 else: cdrec = 1 ### Check cdrdao sys.stdout.write(" cdrdao") pipe = popen("/usr/bin/which cdrdao 2>&1") output = striplist(pipe.readlines()) pipe.close() if(string.find(output[0], "no cdrdao in") != -1): cdrdao = 0 else: cdrdao = 1 ### Check isoinfo sys.stdout.write(" isoinfo") pipe = popen("/usr/bin/which isoinfo 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no isoinfo in") != -1): isoinfo = 0 else: isoinfo = 1 ### Check mpg123 sys.stdout.write(" mpg123") pipe = popen("/usr/bin/which mpg123 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no mpg123 in") != -1): mpg123 = 0 else: mpg123 = 1 ### Check cdda2wav sys.stdout.write(" cdda2wav") pipe = popen("/usr/bin/which cdda2wav 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no cdda2wav in") != -1): cdda2wav = 0 else: cdda2wav = 1 ### Check sox sys.stdout.write(" sox") pipe = popen("/usr/bin/which sox 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no sox in") != -1): sox = 0 else: sox = 1 ### Check lame sys.stdout.write(" lame") pipe = popen("/usr/bin/which lame 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no lame in") != -1): lame = 0 else: lame = 1 ### Check bladeenc sys.stdout.write(" bladeenc") pipe = popen("/usr/bin/which bladeenc 2>&1") output=striplist(pipe.readlines()) pipe.close() if (string.find(output[0], "no bladeenc in") != -1): bladeenc = 0 else: bladeenc = 1 sys.stdout.write("\n") if (mkisofs == 0) or (cdrec == 0) or (cdrdao == 0) or (cdda2wav == 0) or (mpg123 == 0) or (sox == 0): sys.stdout.write("The following program(s) couldn't be found:\n") if (mkisofs == 0): sys.stdout.write("mksiofs ") if (cdrec == 0): sys.stdout.write("cdrecord ") if (cdrdao == 0): sys.stdout.write("cdrdao ") if (isoinfo == 0): sys.stdout.write("isoinfo ") if (cdda2wav == 0): sys.stdout.write("cdda2wav ") if (mpg123 == 0): sys.stdout.write("mpg123 ") if (sox == 0): sys.stdout.write("sox ") sys.stdout.write("\nThese tools are necessary to use CDR\n") sys.exit(1) ##### Check for configuration file # Check for global configuration file confile="/etc/cdr.conf" hostname=os.environ.get('HOSTNAME') is_confile=0 has_section=0 if not os.path.isfile(confile): # Check for user custom configuration file confile=os.path.abspath(os.path.join(os.environ.get('HOME'),'.cdrrc') ) if not os.path.isfile(confile): is_confile=0 else: is_confile=1 else: is_confile=1 if is_confile==1: config = ConfigParser.ConfigParser() config.read(confile) if config.has_section(hostname): has_section=1 ##### Start DIALOG application app=Application(lame, bladeenc, is_confile, has_section, confile, hostname) app.menu() ########################################### if __name__ == '__main__': main()