Home | Trees | Index | Help |
|
---|
Package CedarBackup2 :: Module writer :: Class CdWriter |
|
object
--+
|
CdWriter
This is a class representing a device that knows how to write CD media. It provides common operations for the device, such as ejecting the media, writing an ISO image to the media, or checking for the current media capacity. It also provides a place to store device attributes, such as whether the device supports writing multisession discs, etc.
This class is implemented in terms of the eject
and
cdrecord
programs, both of which should be available on
most UN*X platforms.
MEDIA_CDR_74
: 74-minute CD-R media (650 MB
capacity)
MEDIA_CDRW_74
: 74-minute CD-RW media (650 MB
capacity)
MEDIA_CDR_80
: 80-minute CD-R media (700 MB
capacity)
MEDIA_CDRW_80
: 80-minute CD-RW media (700 MB
capacity)
Most hardware can read and write both 74-minute and 80-minute CD-R and CD-RW media. Some older drives may only be able to write CD-R media. The difference between the two is that CD-RW media can be rewritten (erased), while CD-R media cannot be.
I do not support any other configurations for a couple of reasons. The first is that I've never tested any other kind of media. The second is that anything other than 74 or 80 minute is apparently non-standard.It's rather difficult to test this code in an automated fashion, even if you have access to a physical CD writer drive. It's even more difficult to test it if you are running on some build daemon (think of a Debian autobuilder) which can't be expected to have any hardware or any media that you could write to.
Because of this, much of the implementation below is in terms of static methods that are supposed to take defined actions based on their arguments. Public methods are then implemented in terms of a series of calls to simplistic static methods. This way, we can test as much as possible of the functionality via testing the static methods, while hoping that if the static methods are called appropriately, things will work properly. It's not perfect, but it's much better than no testing at all.Method Summary | |
---|---|
Initializes a CD writer object. | |
Indicates whether the media is rewritable per configuration. | |
Retrieves properties for a device from cdrecord . | |
Retrieves capacity for the current media in terms of a MediaCapacity object. | |
Gets the ISO boundaries for the media. | |
Calculates capacity for the media in terms of boundaries. (Static method) | |
Opens the device's tray and leaves it open. | |
Closes the device's tray. | |
Opens and then immediately closes the device's tray, to refresh the device's idea of the media. | |
Writes an ISO image to the media in the device. | |
Blanks the media in the device, if the media is rewritable. | |
Parses the output from a cdrecord properties command. (Static method)
| |
Parses the output from a cdrecord capacity command. (Static method)
| |
Builds a list of arguments to be passed to a eject
command. (Static method)
| |
Builds a list of arguments to be passed to a eject
command. (Static method)
| |
Builds a list of arguments to be passed to a cdrecord
command. (Static method)
| |
Builds a list of arguments to be passed to a cdrecord
command. (Static method)
| |
Builds a list of arguments to be passed to a cdrecord
command. (Static method)
| |
Builds a list of arguments to be passed to a cdrecord
command. (Static method)
| |
Property target used to get the device value. | |
Property target used to get the device buffer size. | |
Property target used to get the device-can-eject flag. | |
Property target used to get the device-has-tray flag. | |
Property target used to get the device id. | |
Property target used to get the device-support-multi flag. | |
Property target used to get the device type. | |
Property target used to get the device vendor. | |
Property target used to get the drive speed. | |
Property target used to get the media description. | |
Property target used to get the SCSI id value. | |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) |
Property Summary | |
---|---|
device : Filesystem device name for this writer. | |
scsiId : SCSI id for the device, in the form
[ATA:|ATAPI:]scsibus,target,lun . | |
driveSpeed : Speed at which the drive writes. | |
media : Definition of media that is expected to be in the device. | |
deviceType : Type of the device, as returned from cdrecord -prcap . | |
deviceVendor : Vendor of the device, as returned from cdrecord
-prcap . | |
deviceId : Device identification, as returned from cdrecord
-prcap . | |
deviceBufferSize : Size of the device's write buffer, in bytes. | |
deviceSupportsMulti : Indicates whether device supports multisession discs. | |
deviceHasTray : Indicates whether the device has a media tray. | |
deviceCanEject : Indicates whether the device supports ejecting its media. |
Instance Method Details |
---|
__init__(self,
device,
scsiId,
driveSpeed=None,
mediaType=1,
unittest=False)
|
isRewritable(self)Indicates whether the media is rewritable per configuration. |
_retrieveProperties(self)Retrieves properties for a device from _parsePropertiesOutput :
(deviceType, deviceVendor, deviceId, deviceBufferSize,
deviceSupportsMulti, deviceHasTray, deviceCanEject) .
|
retrieveCapacity(self, entireDisc=False, useMulti=True)Retrieves capacity for the current media in terms of a
entireDisc is passed in as True the
capacity will be for the entire disc, as if it were to be rewritten
from scratch. If the drive does not support writing multisession discs
or if useMulti is passed in as False , the
capacity will also be as if the disc were to be rewritten from scratch,
but the indicated boundaries value will be None . The same
will happen if the disc cannot be read for some reason. Otherwise, the
capacity (including the boundaries) will represent whatever space
remains on the disc to be filled by future sessions.
|
_getBoundaries(self, entireDisc=False, useMulti=True)Gets the ISO boundaries for the media. If IsoImage class. Note that these values are in terms of
ISO sectors, not bytes. Clients should generally consider the
boundaries value opaque, however.
|
openTray(self)Opens the device's tray and leaves it open. This only works if the device has a tray and supports ejecting its media. We have no way to know if the tray is currently open or closed, so we just send the appropriate command and hope for the best. If the device does not have a tray or does not support ejecting its media, then we do nothing.
|
closeTray(self)Closes the device's tray. This only works if the device has a tray and supports ejecting its media. We have no way to know if the tray is currently open or closed, so we just send the appropriate command and hope for the best. If the device does not have a tray or does not support ejecting its media, then we do nothing.
|
refreshMedia(self)Opens and then immediately closes the device's tray, to refresh the device's idea of the media. Sometimes, a device gets confused about the state of its media. Often, all it takes to solve the problem is to eject the media and then immediately reload it. This only works if the device has a tray and supports ejecting its media. We have no way to know if the tray is currently open or closed, so we just send the appropriate command and hope for the best. If the device does not have a tray or does not support ejecting its media, then we do nothing.
|
writeImage(self, imagePath, newDisc=False, writeMulti=True)Writes an ISO image to the media in the device. If If
|
_blankMedia(self)Blanks the media in the device, if the media is rewritable.
|
_getDevice(self)Property target used to get the device value. |
_getDeviceBufferSize(self)Property target used to get the device buffer size. |
_getDeviceCanEject(self)Property target used to get the device-can-eject flag. |
_getDeviceHasTray(self)Property target used to get the device-has-tray flag. |
_getDeviceId(self)Property target used to get the device id. |
_getDeviceSupportsMulti(self)Property target used to get the device-support-multi flag. |
_getDeviceType(self)Property target used to get the device type. |
_getDeviceVendor(self)Property target used to get the device vendor. |
_getDriveSpeed(self)Property target used to get the drive speed. |
_getMedia(self)Property target used to get the media description. |
_getScsiId(self)Property target used to get the SCSI id value. |
Static Method Details |
---|
_calculateCapacity(media, boundaries)Calculates capacity for the media in terms of boundaries. Ifboundaries is None or the lower bound
is 0 (zero), then the capacity will be for the entire disc minus the
initial lead in. Otherwise, capacity will be as if the caller wanted to
add an additional session to the end of the existing data on the
disc.
|
_parsePropertiesOutput(output)Parses the output from a The The output is expected to be a huge long list of strings.
Unfortunately, the strings aren't in a completely regular format.
However, the format of individual lines seems to be regular enough that
we can look for specific values. Two kinds of parsing take place: one
kind of parsing picks out out specific values like the device id,
device vendor, etc. The other kind of parsing just sets a boolean flag
Right now, pretty much nothing in the output is required and we should parse an empty document successfully (albeit resulting in a device that can't eject, doesn't have a tray and doesnt't support multisession discs). I had briefly considered erroring out if certain lines weren't found or couldn't be parsed, but that seems like a bad idea given that most of the information is just for reference. The results are returned as a tuple of the object device attributes:(deviceType, deviceVendor, deviceId, deviceBufferSize,
deviceSupportsMulti, deviceHasTray, deviceCanEject) .
|
_parseBoundariesOutput(output)Parses the output from a The Basically, we expect the list of strings to include just one line, a
pair of values. There isn't supposed to be whitespace, but we allow it
anyway in the regular expression. Any lines below the one line we parse
are completely ignored. It would be a good idea to ignore
IsoImage class. Note that these values are in terms of
ISO sectors, not bytes. Clients should generally consider the
boundaries value opaque, however.
|
_buildOpenTrayArgs(device)Builds a list of arguments to be passed to a eject command to open the
tray and eject the media. No validation is done by this method as to
whether this action actually makes sense.
|
_buildCloseTrayArgs(device)Builds a list of arguments to be passed to a eject command to close the
tray and reload the media. No validation is done by this method as to
whether this action actually makes sense.
|
_buildPropertiesArgs(scsiId)Builds a list of arguments to be passed to a cdrecord command to ask
the device for a list of its capacities via the -prcap
switch.
|
_buildBoundariesArgs(scsiId)Builds a list of arguments to be passed to a cdrecord command to ask
the device for the current multisession boundaries of the media using
the -msinfo switch.
|
_buildBlankArgs(scsiId, driveSpeed=None)Builds a list of arguments to be passed to a cdrecord command to blank
the media in the device identified by scsiId . No
validation is done by this method as to whether the action makes sense
(i.e. to whether the media even can be blanked).
|
_buildWriteArgs(scsiId, imagePath, driveSpeed=None, writeMulti=True)Builds a list of arguments to be passed to a cdrecord command to write
the indicated ISO image (imagePath ) to the media in the
device identified by scsiId . The writeMulti
argument controls whether to write a multisession disc. No validation
is done by this method as to whether the action makes sense (i.e. to
whether the device even can write multisession discs, for
instance).
|
Property Details |
---|
deviceFilesystem device name for this writer.
|
scsiIdSCSI id for the device, in the form[ATA:|ATAPI:]scsibus,target,lun .
|
driveSpeedSpeed at which the drive writes.
|
mediaDefinition of media that is expected to be in the device.
|
deviceTypeType of the device, as returned fromcdrecord -prcap .
|
deviceVendorVendor of the device, as returned fromcdrecord
-prcap .
|
deviceIdDevice identification, as returned fromcdrecord
-prcap .
|
deviceBufferSizeSize of the device's write buffer, in bytes.
|
deviceSupportsMultiIndicates whether device supports multisession discs.
|
deviceHasTrayIndicates whether the device has a media tray.
|
deviceCanEjectIndicates whether the device supports ejecting its media.
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Thu Dec 22 20:45:14 2005 | http://epydoc.sf.net |