First semblance of distutils setuptools. Not complete yet though.
This commit is contained in:
147
example/audio.py
Executable file
147
example/audio.py
Executable file
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env python
|
||||
"""A program to show use of audio controls. See cdda-player from the
|
||||
libcdio distribution for a more complete program.
|
||||
"""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys, os
|
||||
from optparse import OptionParser
|
||||
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import cdio
|
||||
|
||||
def process_options():
|
||||
program = os.path.basename(sys.argv[0])
|
||||
usage_str="""%s [options] [device]
|
||||
Issue analog audio CD controls - like playing""" % program
|
||||
|
||||
optparser = OptionParser(usage=usage_str)
|
||||
|
||||
optparser.add_option("-c", "--close", dest="close",
|
||||
action="store", type='string',
|
||||
help="close CD tray")
|
||||
optparser.add_option("-p", "--play", dest="play",
|
||||
action="store_true", default=False,
|
||||
help="Play entire CD")
|
||||
optparser.add_option("-P", "--pause", dest="pause",
|
||||
action="store_true", default=False,
|
||||
help="pause playing")
|
||||
optparser.add_option("-E", "--eject", dest="eject",
|
||||
action="store_true", default=False,
|
||||
help="Eject CD")
|
||||
optparser.add_option("-r", "--resume", dest="resume",
|
||||
action="store_true", default=False,
|
||||
help="resume playing")
|
||||
optparser.add_option("-s", "--stop", dest="stop",
|
||||
action="store_true", default=False,
|
||||
help="stop playing")
|
||||
optparser.add_option("-t", "--track", dest="track",
|
||||
action="store", type='int',
|
||||
help="play a single track")
|
||||
return optparser.parse_args()
|
||||
|
||||
opts, argv = process_options()
|
||||
|
||||
# Handle closing the CD-ROM tray if that was specified.
|
||||
if opts.close:
|
||||
try:
|
||||
device_name = opts.close
|
||||
cdio.close_tray(device_name)
|
||||
except cdio.DeviceException:
|
||||
print "Closing tray of CD-ROM drive %s failed" % device_name
|
||||
|
||||
|
||||
# While sys.argv[0] is a program name and sys.argv[1] the first
|
||||
# option, argv[0] is the first unprocessed option -- roughly
|
||||
# the equivalent of sys.argv[1].
|
||||
if argv[0:]:
|
||||
try:
|
||||
d = cdio.Device(argv[0])
|
||||
except IOError:
|
||||
print "Problem opening CD-ROM: %s" % device_name
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN)
|
||||
except IOError:
|
||||
print "Problem finding a CD-ROM"
|
||||
sys.exit(1)
|
||||
|
||||
device_name=d.get_device()
|
||||
if opts.play:
|
||||
if d.get_disc_mode() != 'CD-DA':
|
||||
print "The disc on %s I found was not CD-DA, but %s" \
|
||||
% (device_name, d.get_disc_mode())
|
||||
print "I have bad feeling about trying to play this..."
|
||||
|
||||
try:
|
||||
start_lsn = d.get_first_track().get_lsn()
|
||||
end_lsn=d.get_disc_last_lsn()
|
||||
print "Playing entire CD on %s" % device_name
|
||||
d.audio_play_lsn(start_lsn, end_lsn)
|
||||
except cdio.TrackError:
|
||||
pass
|
||||
|
||||
elif opts.track is not None:
|
||||
try:
|
||||
if opts.track > d.get_last_track().track:
|
||||
print "Requested track %d but CD only has %d tracks" \
|
||||
% (opts.track, d.get_last_track().track)
|
||||
sys.exit(2)
|
||||
if opts.track < d.get_first_track().track:
|
||||
print "Requested track %d but first track on CD is %d" \
|
||||
% (opts.track, d.get_first_track().track)
|
||||
sys.exit(2)
|
||||
print "Playing track %d on %s" % (opts.track, device_name)
|
||||
start_lsn = d.get_track(opts.track).get_lsn()
|
||||
end_lsn = d.get_track(opts.track+1).get_lsn()
|
||||
d.audio_play_lsn(start_lsn, end_lsn)
|
||||
except cdio.TrackError:
|
||||
pass
|
||||
|
||||
elif opts.pause:
|
||||
try:
|
||||
print "Pausing playing in drive %s" % device_name
|
||||
d.audio_pause()
|
||||
except cdio.DeviceException:
|
||||
print "Pause failed on drive %s" % device_name
|
||||
elif opts.resume:
|
||||
try:
|
||||
print "Resuming playing in drive %s" % device_name
|
||||
d.audio_resume()
|
||||
except cdio.DeviceException:
|
||||
print "Resume failed on drive %s" % device_name
|
||||
elif opts.stop:
|
||||
try:
|
||||
print "Stopping playing in drive %s" % device_name
|
||||
d.audio_stop()
|
||||
except cdio.DeviceException:
|
||||
print "Stopping failed on drive %s" % device_name
|
||||
elif opts.eject:
|
||||
try:
|
||||
print "Ejecting CD in drive %s" % device_name
|
||||
d.eject_media()
|
||||
except cdio.DriverUnsupportedError:
|
||||
print "Eject not supported for %s" % device_name
|
||||
except cdio.DeviceException:
|
||||
print "Eject of CD-ROM drive %s failed" % device_name
|
||||
|
||||
d.close()
|
||||
121
example/cd-read.py
Executable file
121
example/cd-read.py
Executable file
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env python
|
||||
"""Program to read CD blocks. See read-cd from the libcdio distribution
|
||||
for a more complete program.
|
||||
"""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys, os
|
||||
from optparse import OptionParser
|
||||
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import cdio
|
||||
|
||||
read_modes = {
|
||||
'audio': pycdio.READ_MODE_AUDIO,
|
||||
'm1f1' : pycdio.READ_MODE_M1F1,
|
||||
'm1f2' : pycdio.READ_MODE_M1F2,
|
||||
'm2f1' : pycdio.READ_MODE_M2F1,
|
||||
'm2f2' : pycdio.READ_MODE_M2F2,
|
||||
'data' : None
|
||||
}
|
||||
|
||||
def process_options():
|
||||
program = os.path.basename(sys.argv[0])
|
||||
usage_str="""%s --mode *mode* [options] [device]
|
||||
Read blocks of a CD""" % program
|
||||
|
||||
optparser = OptionParser(usage=usage_str)
|
||||
|
||||
optparser.add_option("-m", "--mode", dest="mode",
|
||||
action="store", type='string',
|
||||
help="CD Reading mode: audio, m1f1, m1f2, " +
|
||||
"m2f1 or m2f2")
|
||||
optparser.add_option("-s", "--start", dest="start",
|
||||
action="store", type='int', default=1,
|
||||
help="Starting block")
|
||||
optparser.add_option("-n", "--number", dest="number",
|
||||
action="store", type='int', default=1,
|
||||
help="Number of blocks")
|
||||
(opts, argv) = optparser.parse_args()
|
||||
if opts.mode is None:
|
||||
print "Mode option must given " + \
|
||||
"(and one of audio, m1f1, m1f2, m1f2 or m1f2)."
|
||||
sys.exit(1)
|
||||
try:
|
||||
read_mode = read_modes[opts.mode]
|
||||
except KeyError:
|
||||
print "Need to use the --mode option with one of" + \
|
||||
"audio, m1f1, m1f2, m1f2 or m1f2"
|
||||
sys.exit(2)
|
||||
|
||||
return opts, argv, read_mode
|
||||
|
||||
import re
|
||||
PRINTABLE = r'[ -~]'
|
||||
pat = re.compile(PRINTABLE)
|
||||
def isprint(c):
|
||||
global pat
|
||||
return pat.match(c)
|
||||
|
||||
def hexdump (buffer, just_hex=False):
|
||||
i = 0
|
||||
while i < len(buffer):
|
||||
if (i % 16) == 0:
|
||||
print ("0x%04x: " % i),
|
||||
print "%02x%02x" % (ord(buffer[i]), ord(buffer[i+1])),
|
||||
if (i % 16) == 14:
|
||||
if not just_hex:
|
||||
s = " "
|
||||
for j in range(i-14, i+2):
|
||||
if isprint(buffer[j]):
|
||||
s += buffer[j]
|
||||
else:
|
||||
s += '.'
|
||||
print s,
|
||||
print
|
||||
i += 2
|
||||
print
|
||||
return
|
||||
|
||||
opts, argv, read_mode = process_options()
|
||||
# While sys.argv[0] is a program name and sys.argv[1] the first
|
||||
# option, argv[0] is the first unprocessed option -- roughly
|
||||
# the equivalent of sys.argv[1].
|
||||
if argv[0:]:
|
||||
try:
|
||||
d = cdio.Device(argv[0])
|
||||
except IOError:
|
||||
print "Problem opening CD-ROM: %s" % argv[0]
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN)
|
||||
except IOError:
|
||||
print "Problem finding a CD-ROM"
|
||||
sys.exit(1)
|
||||
|
||||
## All this setup just to issue this one of these commands.
|
||||
if read_mode == None:
|
||||
blocks, data=d.read_data_blocks(opts.start, opts.number)
|
||||
else:
|
||||
blocks, data=d.read_sectors(opts.start, read_mode, opts.number)
|
||||
hexdump(data)
|
||||
|
||||
60
example/cdchange.py
Executable file
60
example/cdchange.py
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
"""Program to show CD media changing"""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
import sys, time
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import cdio
|
||||
from time import sleep
|
||||
|
||||
sleep_time = 15
|
||||
if sys.argv[1:]:
|
||||
try:
|
||||
d = cdio.Device(sys.argv[1])
|
||||
except IOError:
|
||||
print "Problem opening CD-ROM: %s" % sys.argv[1]
|
||||
sys.exit(1)
|
||||
if sys.argv[2:]:
|
||||
try:
|
||||
sleep_time = int(sys.argv[2])
|
||||
except ValueError, msg:
|
||||
print "Invalid sleep parameter %s" % sys.argv[2]
|
||||
sys.exit(2)
|
||||
else:
|
||||
try:
|
||||
d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN)
|
||||
except IOError:
|
||||
print "Problem finding a CD-ROM"
|
||||
sys.exit(1)
|
||||
|
||||
if d.get_media_changed():
|
||||
print "Initial media status: changed"
|
||||
else:
|
||||
print "Initial media status: not changed"
|
||||
|
||||
print "Giving you %lu seconds to change CD if you want to do so." % sleep_time
|
||||
sleep(sleep_time)
|
||||
if d.get_media_changed():
|
||||
print "Media status: changed"
|
||||
else:
|
||||
print "Media status: not changed"
|
||||
d.close()
|
||||
68
example/device.py
Executable file
68
example/device.py
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python
|
||||
"""Program to show CD-ROM device information"""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os, sys
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import cdio
|
||||
|
||||
def sort_dict_keys(dict):
|
||||
"""Return sorted keys of a dictionary.
|
||||
There's probably an easier way to do this that I'm not aware of."""
|
||||
keys=dict.keys()
|
||||
keys.sort()
|
||||
return keys
|
||||
|
||||
if sys.argv[1:]:
|
||||
try:
|
||||
drive_name = sys.argv[1]
|
||||
d = cdio.Device(sys.argv[1])
|
||||
except IOError:
|
||||
print "Problem opening CD-ROM: %s" % drive_name
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN)
|
||||
drive_name = d.get_device()
|
||||
except IOError:
|
||||
print "Problem finding a CD-ROM"
|
||||
sys.exit(1)
|
||||
|
||||
# Should there should be no "ok"?
|
||||
ok, vendor, model, release = d.get_hwinfo()
|
||||
|
||||
print "drive: %s, vendor: %s, model: %s, release: %s" \
|
||||
% (drive_name, vendor, model, release)
|
||||
|
||||
read_cap, write_cap, misc_cap = d.get_drive_cap()
|
||||
print "Drive Capabilities for %s..." % drive_name
|
||||
|
||||
print "\n".join(cap for cap in sort_dict_keys(read_cap) +
|
||||
sort_dict_keys(write_cap) + sort_dict_keys(misc_cap))
|
||||
|
||||
print "\nDriver Availabiliity..."
|
||||
for driver_name in sort_dict_keys(cdio.drivers):
|
||||
try:
|
||||
if cdio.have_driver(driver_name):
|
||||
print "Driver %s is installed." % driver_name
|
||||
except ValueError:
|
||||
pass
|
||||
d.close()
|
||||
57
example/drives.py
Executable file
57
example/drives.py
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/python
|
||||
# $Id: drives.py,v 1.2 2008/11/24 00:53:59 rocky Exp $
|
||||
"""Program to read CD blocks. See read-cd from the libcdio distribution
|
||||
for a more complete program."""
|
||||
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
# 02110-1301 USA.
|
||||
#
|
||||
|
||||
import os, sys
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import cdio
|
||||
|
||||
def print_drive_class(msg, bitmask, any):
|
||||
cd_drives = cdio.get_devices_with_cap(bitmask, any)
|
||||
|
||||
print "%s..." % msg
|
||||
for drive in cd_drives:
|
||||
print "Drive %s" % drive
|
||||
print "-----"
|
||||
|
||||
cd_drives = cdio.get_devices(pycdio.DRIVER_DEVICE)
|
||||
for drive in cd_drives:
|
||||
print "Drive %s" % drive
|
||||
|
||||
print "-----"
|
||||
|
||||
sys.exit(0)
|
||||
# FIXME: there's a bug in get_drive_with_cap that corrupts memory.
|
||||
print_drive_class("All CD-ROM drives (again)", pycdio.FS_MATCH_ALL, False);
|
||||
print_drive_class("All CD-DA drives...", pycdio.FS_AUDIO, False);
|
||||
print_drive_class("All drives with ISO 9660...", pycdio.FS_ISO_9660, False);
|
||||
print_drive_class("VCD drives...",
|
||||
(pycdio.FS_ANAL_SVCD|pycdio.FS_ANAL_CVD|
|
||||
pycdio.FS_ANAL_VIDEOCD|pycdio.FS_UNKNOWN), True);
|
||||
|
||||
|
||||
|
||||
59
example/eject.py
Executable file
59
example/eject.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python
|
||||
"""Program to Eject and close CD-ROM drive"""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os, sys
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import cdio
|
||||
|
||||
if sys.argv[1:]:
|
||||
try:
|
||||
drive_name=sys.argv[1]
|
||||
d = cdio.Device(drive_name)
|
||||
except IOError:
|
||||
print "Problem opening CD-ROM: %s" % drive_name
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN)
|
||||
drive_name = d.get_device()
|
||||
except IOError:
|
||||
print "Problem finding a CD-ROM"
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
|
||||
print "Ejecting CD in drive %s" % drive_name
|
||||
d.eject_media()
|
||||
try:
|
||||
cdio.close_tray(drive_name)
|
||||
print "Closed tray of CD-ROM drive %s" % drive_name
|
||||
except cdio.DeviceException:
|
||||
print "Closing tray of CD-ROM drive %s failed" % drive_name
|
||||
|
||||
except cdio.DriverUnsupportedError:
|
||||
print "Eject not supported for %s" % drive_name
|
||||
except cdio.DeviceException:
|
||||
print "Eject of CD-ROM drive %s failed" % drive_name
|
||||
|
||||
|
||||
|
||||
|
||||
83
example/iso1.py
Executable file
83
example/iso1.py
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
""" A simple program to show using libiso9660 to list files in a directory of
|
||||
an ISO-9660 image.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to
|
||||
use in the listing. Otherwise a compiled-in default ISO 9660 image
|
||||
name (that comes with the libcdio distribution) will be used."""
|
||||
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os, sys
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import iso9660
|
||||
|
||||
# The default ISO 9660 image if none given
|
||||
ISO9660_IMAGE_PATH="../data"
|
||||
ISO9660_IMAGE=os.path.join(ISO9660_IMAGE_PATH, "copying.iso")
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
iso_image_fname = sys.argv[1]
|
||||
else:
|
||||
iso_image_fname = ISO9660_IMAGE
|
||||
|
||||
iso = iso9660.ISO9660.IFS(source=iso_image_fname)
|
||||
|
||||
if not iso.is_open():
|
||||
print "Sorry, couldn't open %s as an ISO-9660 image." % iso_image_fname
|
||||
sys.exit(1)
|
||||
|
||||
path = '/'
|
||||
|
||||
file_stats = iso.readdir(path)
|
||||
|
||||
id = iso.get_application_id()
|
||||
if id is not None: print "Application ID: %s" % id
|
||||
|
||||
id = iso.get_preparer_id()
|
||||
if id is not None: print "Preparer ID: %s" % id
|
||||
|
||||
id = iso.get_publisher_id()
|
||||
if id is not None: print "Publisher ID: %s" % id
|
||||
|
||||
id = iso.get_system_id()
|
||||
if id is not None: print "System ID: %s" % id
|
||||
|
||||
id = iso.get_volume_id()
|
||||
if id is not None: print "Volume ID: %s" % id
|
||||
|
||||
id = iso.get_volumeset_id()
|
||||
if id is not None: print "Volumeset ID: %s" % id
|
||||
|
||||
dir_tr=['-', 'd']
|
||||
|
||||
for stat in file_stats:
|
||||
# FIXME
|
||||
filename = stat[0]
|
||||
LSN = stat[1]
|
||||
size = stat[2]
|
||||
sec_size = stat[3]
|
||||
is_dir = stat[4] == 2
|
||||
print "%s [LSN %6d] %8d %s%s" % (dir_tr[is_dir], LSN, size, path,
|
||||
iso9660.name_translate(filename))
|
||||
iso.close()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
100
example/iso2.py
Executable file
100
example/iso2.py
Executable file
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python
|
||||
"""A program to show using iso9660 to extract a file from an ISO-9660
|
||||
image.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to use
|
||||
in the extraction. Otherwise a compiled in default ISO 9660 image name
|
||||
(that comes with the libcdio distribution) will be used. A program to
|
||||
show using iso9660 to extract a file from an ISO-9660 image."""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os, sys
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import iso9660
|
||||
|
||||
# Python has rounding (round) and trucation (int), but what about an integer
|
||||
# ceiling function? Until I learn what it is...
|
||||
def ceil(x):
|
||||
return int(round(x+0.5))
|
||||
|
||||
# The default CD image if none given
|
||||
cd_image_path="../data"
|
||||
cd_image_fname=os.path.join(cd_image_path, "isofs-m1.cue")
|
||||
|
||||
# File to extract if none given.
|
||||
iso9660_path="/"
|
||||
local_filename="COPYING"
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
cd_image_fname = sys.argv[1]
|
||||
if len(sys.argv) > 2:
|
||||
local_filename = sys.argv[1]
|
||||
if len(sys.argv) > 3:
|
||||
print """
|
||||
usage: %s [CD-ROM-or-image [filename]]
|
||||
Extracts filename from CD-ROM-or-image.
|
||||
""" % sys.argv[0]
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
cd = iso9660.ISO9660.FS(source=cd_image_fname)
|
||||
except:
|
||||
print "Sorry, couldn't open %s as a CD image." % cd_image_fname
|
||||
sys.exit(1)
|
||||
|
||||
statbuf = cd.stat (local_filename, False)
|
||||
|
||||
if statbuf is None:
|
||||
print "Could not get ISO-9660 file information for file %s in %s" \
|
||||
% (local_filename, cd_image_fname)
|
||||
cd.close()
|
||||
sys.exit(2)
|
||||
|
||||
try:
|
||||
OUTPUT=os.open(local_filename, os.O_CREAT|os.O_WRONLY, 0664)
|
||||
except:
|
||||
print "Can't open %s for writing" % local_filename
|
||||
|
||||
# Copy the blocks from the ISO-9660 filesystem to the local filesystem.
|
||||
blocks = ceil(statbuf['size'] / pycdio.ISO_BLOCKSIZE)
|
||||
for i in range(blocks):
|
||||
lsn = statbuf['LSN'] + i
|
||||
size, buf = cd.read_data_blocks(lsn)
|
||||
|
||||
if size < 0:
|
||||
print "Error reading ISO 9660 file %s at LSN %d" % (
|
||||
local_filename, lsn)
|
||||
sys.exit(4)
|
||||
|
||||
os.write(OUTPUT, buf)
|
||||
|
||||
|
||||
# Make sure the file size has the exact same byte size. Without the
|
||||
# truncate below, the file will a multiple of ISO_BLOCKSIZE.
|
||||
|
||||
os.ftruncate(OUTPUT, statbuf['size'])
|
||||
|
||||
print "Extraction of file '%s' from %s successful." % (
|
||||
local_filename, cd_image_fname)
|
||||
|
||||
os.close(OUTPUT)
|
||||
cd.close()
|
||||
sys.exit(0)
|
||||
100
example/iso3.py
Executable file
100
example/iso3.py
Executable file
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python
|
||||
"""A program to show using iso9660 to extract a file from an ISO-9660
|
||||
image. If a single argument is given, it is used as the ISO 9660
|
||||
image to use in the extraction. Otherwise a compiled in default ISO
|
||||
9660 image name (that comes with the libcdio distribution) will be
|
||||
used."""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os, sys
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import iso9660
|
||||
|
||||
# Python has rounding (round) and truncation (int), but what about an integer
|
||||
# ceiling function? Until I learn what it is...
|
||||
def ceil(x):
|
||||
return int(round(x+0.5))
|
||||
|
||||
# The default ISO 9660 image if none given
|
||||
ISO9660_IMAGE_PATH="../data"
|
||||
ISO9660_IMAGE=os.path.join(ISO9660_IMAGE_PATH, "copying.iso")
|
||||
|
||||
# File to extract if none given.
|
||||
local_filename="copying"
|
||||
|
||||
iso_image_fname = ISO9660_IMAGE
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
iso_image_fname = sys.argv[1]
|
||||
if len(sys.argv) > 2:
|
||||
local_filename = sys.argv[1]
|
||||
if len(sys.argv) > 3:
|
||||
print """
|
||||
usage: %s [ISO9660-image.ISO [filename]]
|
||||
Extracts filename from ISO9660-image.ISO.
|
||||
""" % sys.argv[0]
|
||||
sys.exit(1)
|
||||
|
||||
iso = iso9660.ISO9660.IFS(source=iso_image_fname)
|
||||
|
||||
if not iso.is_open():
|
||||
print "Sorry, couldn't open %s as an ISO-9660 image." % iso_image_fname
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
statbuf = iso.stat (local_filename, True)
|
||||
|
||||
if statbuf is None:
|
||||
print "Could not get ISO-9660 file information for file %s" \
|
||||
% local_filename
|
||||
iso.close()
|
||||
sys.exit(2)
|
||||
|
||||
try:
|
||||
OUTPUT=os.open(local_filename, os.O_CREAT|os.O_WRONLY, 0664)
|
||||
except:
|
||||
print "Can't open %s for writing" % local_filename
|
||||
|
||||
# Copy the blocks from the ISO-9660 filesystem to the local filesystem.
|
||||
blocks = ceil(statbuf['size'] / pycdio.ISO_BLOCKSIZE)
|
||||
for i in range(blocks):
|
||||
lsn = statbuf['LSN'] + i
|
||||
size, buf = iso.seek_read (lsn)
|
||||
|
||||
if size <= 0:
|
||||
print "Error reading ISO 9660 file %s at LSN %d" % (
|
||||
local_filename, lsn)
|
||||
sys.exit(4)
|
||||
|
||||
os.write(OUTPUT, buf)
|
||||
|
||||
|
||||
# Make sure the file size has the exact same byte size. Without the
|
||||
# truncate below, the file will a multiple of ISO_BLOCKSIZE.
|
||||
|
||||
os.ftruncate(OUTPUT, statbuf['size'])
|
||||
|
||||
print "Extraction of file '%s' from %s successful." % (
|
||||
local_filename, iso_image_fname)
|
||||
|
||||
os.close(OUTPUT)
|
||||
iso.close()
|
||||
sys.exit(0)
|
||||
75
example/tracks.py
Executable file
75
example/tracks.py
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python
|
||||
"""A program to show CD information."""
|
||||
#
|
||||
# Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os, sys
|
||||
libdir = os.path.join(os.path.dirname(__file__), '..')
|
||||
if libdir[-1] != os.path.sep:
|
||||
libdir += os.path.sep
|
||||
sys.path.insert(0, libdir)
|
||||
import pycdio
|
||||
import cdio
|
||||
|
||||
if sys.argv[1:]:
|
||||
try:
|
||||
d = cdio.Device(sys.argv[1])
|
||||
except IOError:
|
||||
print "Problem opening CD-ROM: %s" % sys.argv[1]
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN)
|
||||
except IOError:
|
||||
print "Problem finding a CD-ROM"
|
||||
sys.exit(1)
|
||||
|
||||
t = d.get_first_track()
|
||||
if t is None:
|
||||
print "Problem getting first track"
|
||||
sys.exit(2)
|
||||
|
||||
first_track = t.track
|
||||
num_tracks = d.get_num_tracks()
|
||||
last_track = first_track+num_tracks-1
|
||||
|
||||
try:
|
||||
last_session = d.get_last_session()
|
||||
print "CD-ROM %s has %d track(s) and %d session(s)." % \
|
||||
(d.get_device(), d.get_num_tracks(), last_session)
|
||||
except cdio.DriverUnsupportedError:
|
||||
print "CD-ROM %s has %d track(s). " % (d.get_device(), d.get_num_tracks())
|
||||
|
||||
print "Track format is %s." % d.get_disc_mode()
|
||||
|
||||
mcn = d.get_mcn()
|
||||
if mcn:
|
||||
print "Media Catalog Number: %s" % mcn
|
||||
|
||||
print "%3s: %-6s %s" % ("#", "LSN", "Format")
|
||||
i=first_track
|
||||
while (i <= last_track):
|
||||
try:
|
||||
t = d.get_track(i)
|
||||
print "%3d: %06lu %-6s %s" % (t.track, t.get_lsn(),
|
||||
t.get_msf(), t.get_format())
|
||||
except cdio.TrackError:
|
||||
pass
|
||||
i += 1
|
||||
|
||||
print "%3X: %06lu leadout" \
|
||||
% (pycdio.CDROM_LEADOUT_TRACK, d.get_disc_last_lsn())
|
||||
d.close()
|
||||
Reference in New Issue
Block a user