Updated README
[simpleburner.git] / simpleburner.py
blob1ef6c82d032f9bae17b50a2f1a3724e6156d8a39
1 #!/usr/bin/env python
2 #-*- coding: utf-8 -*-
4 # Copyright 2009 Marcin Karpezo <sirmacik at gmail dot com>
5 # license = GPLv3
6 # version = 0.2
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import os
22 import sys
23 import subprocess
24 from optparse import OptionParser
26 def programcheck():
27 print "Looking for cdrkit..."
28 if os.path.exists('/usr/bin/wodim') and os.path.exists('/usr/bin/genisoimage'):
29 globals() ["writer"] = 'wodim'
30 globals() ["isomaker"] = 'genisoimage'
31 print "[OK]"
33 else:
34 print >>sys.stderr, "Not found\nLooking for cdrtools..."
35 if os.path.exists('/usr/bin/cdrecord') and os.path.exists('/usr/bin/mkisofs'):
36 globals() ["writer"] = 'cdrecord'
37 globals() ["isomaker"] = 'mkisofs'
38 print "[OK]"
39 else:
40 print >>sys.stderr, "Not found: Please install cdrkit or cdrtools!"
41 sys.exit(1)
42 def makeiso():
43 print "Making iso image..."
44 command = "%s -U -o %s %s" % (isomaker, isoname, datadir)
45 makeiso = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True).communicate()[0]
46 if makeiso:
47 print >>sys.stderr, "Failed!"
48 sys.exit(1)
49 else:
50 print "[OK]"
51 def burniso():
52 print "Burning iso..."
53 if speed:
54 burnspeed = " --speed=%s" % speed
55 else:
56 burnspeed = ''
57 if test == "True":
58 runtest = ' --dummy'
59 else:
60 runtest = ''
61 command = "%s --eject -v --dev=%s %s %s %s" % (writer, device, burnspeed, runtest, isoname)
62 burniso = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True).communicate()[0]
63 if burniso:
64 print >>sys.stderr, "Failed!"
65 sys.exit(1)
66 else:
67 print "[OK]"
68 if __name__=="__main__":
69 usage = "usage: %prog [options]"
70 parser = OptionParser(usage=usage)
71 parser.add_option("--data", dest="datadir",
72 help="set directory with data to burn")
73 parser.add_option("--name", dest="isoname",
74 help="set path and/or name of iso image")
75 parser.add_option("--device", dest="device", default="/dev/sr0",
76 help="set device to use (default /dev/sr0)")
77 parser.add_option("--speed", dest="speed",
78 help="set burn speed (by default it will be autodetected)")
79 parser.add_option("-t", "--test", action="store_true", dest="test", default= False ,
80 help="run in test burn mode")
81 parser.add_option("-b", "--burn-only", action="store_true", dest="burn", default=False,
82 help="run without making iso image")
83 parser.add_option("-m", "--makeiso", action="store_true", dest="make", default=False,
84 help="make only iso image")
86 (options, args) = parser.parse_args()
87 datadir = options.datadir
88 isoname = options.isoname
89 device = options.device
90 speed = options.speed
91 test = options.test
92 burn = options.burn
93 make = options.make
95 print burn, make
96 programcheck()
98 if burn == True:
99 burniso()
100 elif make == True:
101 makeiso()
102 else:
103 makeiso()
104 burniso()