Created changelog file, will be updated after new release
[simpleburner.git] / simpleburner.py
blob5e7bdf5020ec4e0a53c0fc13fe454abec8f51421
1 #!/usr/bin/env python
2 #-*- coding: utf-8 -*-
3 # Copyright (c) 2009, Marcin Karpezo
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without modification,
7 # are permitted provided that the following conditions are met:
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions and the following disclaimer in the documentation
13 # and/or other materials provided with the distribution.
14 # * Neither the name of the simpleburner nor the names of its contributors may
15 # be used to endorse or promote products derived from this software without
16 # specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 import os
30 import sys
31 import subprocess
32 from optparse import OptionParser
34 def programcheck():
35 print "Looking for cdrkit..."
36 if os.path.exists('/usr/bin/wodim') and os.path.exists('/usr/bin/genisoimage'):
37 globals() ["writer"] = 'wodim'
38 globals() ["isomaker"] = 'genisoimage'
39 print "[OK]"
41 else:
42 print >>sys.stderr, "Not found\nLooking for cdrtools..."
43 if os.path.exists('/usr/bin/cdrecord') and os.path.exists('/usr/bin/mkisofs'):
44 globals() ["writer"] = 'cdrecord'
45 globals() ["isomaker"] = 'mkisofs'
46 print "[OK]"
47 else:
48 print >>sys.stderr, "Not found: Please install cdrkit or cdrtools!"
49 sys.exit(1)
50 def optcheck():
51 if not burn:
52 if not datadir:
53 print >>sys.stderr, "Failed! You must deine --data option."
54 sys.exit(1)
55 elif not os.path.exists(datadir):
56 print >>sys.stderr, "Failed! Data directory does not exist!"
57 sys.exit(1)
58 def makeiso():
59 print "Making iso image..."
60 command = "%s -U -quiet -o %s "%s"" % (isomaker, isoname, datadir)
61 makeiso = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True).communicate()[0]
62 if makeiso:
63 print >>sys.stderr, "Failed!"
64 sys.exit(1)
65 else:
66 print "[OK]\nFile stored in %s" % isoname
67 def burniso():
68 print "Burning iso..."
69 if speed:
70 burnspeed = " --speed=%s" % speed
71 else:
72 burnspeed = ''
73 if test == "True":
74 runtest = ' --dummy'
75 else:
76 runtest = ''
77 command = "%s --eject -vs -%s --dev=%s %s %s %s" % (writer, mode, device, burnspeed, runtest, isoname)
78 burniso = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True).communicate()[0]
79 if burniso:
80 print >>sys.stderr, "Failed or ended successfully with warnings"
81 sys.exit(1)
82 else:
83 print "[OK]"
85 if __name__=="__main__":
86 usage = "usage: %prog [options]"
87 parser = OptionParser(usage=usage)
88 parser.add_option("--data", dest="datadir",
89 help="set directory with data to burn")
90 parser.add_option("--name", dest="isoname", default="/tmp/cd.iso",
91 help="set path and/or name of iso image (by default /tmp/cd.iso)")
92 parser.add_option("--device", dest="device", default="/dev/sr0",
93 help="set device to use (default /dev/sr0)")
94 parser.add_option("--speed", dest="speed",
95 help="set burn speed (by default it will be autodetected)")
96 parser.add_option("--mode", dest="mode", default="tao",
97 help="set burn mode; available options are: TAO (default), DAO, SAO, RAW)")
98 parser.add_option("-t", "--test", action="store_true", dest="test", default= False ,
99 help="run in test burn mode")
100 parser.add_option("-b", "--burn-only", action="store_true", dest="burn", default=False,
101 help="run without making iso image")
102 parser.add_option("-m", "--makeiso", action="store_true", dest="make", default=False,
103 help="make only iso image")
105 (options, args) = parser.parse_args()
106 datadir = options.datadir
107 isoname = options.isoname
108 device = options.device
109 speed = options.speed
110 mode = options.mode
111 test = options.test
112 burn = options.burn
113 make = options.make
115 programcheck()
116 optcheck()
117 if burn == True:
118 burniso()
119 elif make == True:
120 makeiso()
121 else:
122 makeiso()
123 burniso()