1 # This file implements a class which forms an interface to the .cdplayerrc
2 # file that is maintained by SGI's cdplayer program.
8 # c = Cdplayer(r.gettrackinfo())
10 # Now you can use c.artist, c.title and c.track[trackno] (where trackno
11 # starts at 1). When the CD is not recognized, all values will be the empty
13 # It is also possible to set the above mentioned variables to new values.
14 # You can then use c.write() to write out the changed values to the
16 from warnings
import warnpy3k
17 warnpy3k("the cdplayer module has been removed in Python 3.0", stacklevel
=2)
20 cdplayerrc
= '.cdplayerrc'
23 def __init__(self
, tracklist
):
27 if type(tracklist
) == type(''):
29 for i
in range(2, len(tracklist
), 4):
31 (int(tracklist
[i
:i
+2]), \
32 int(tracklist
[i
+2:i
+4]))))
34 self
.track
= [None] + [''] * len(tracklist
)
35 self
.id = 'd' + string
.zfill(len(tracklist
), 2)
36 for track
in tracklist
:
38 self
.id = self
.id + string
.zfill(length
[0], 2) + \
39 string
.zfill(length
[1], 2)
42 f
= open(posix
.environ
['HOME'] + '/' + cdplayerrc
, 'r')
46 reg
= re
.compile(r
'^([^:]*):\t(.*)')
55 match
= reg
.match(line
)
57 print 'syntax error in ~/' + cdplayerrc
59 name
, value
= match
.group(1, 2)
62 elif name
== 'artist':
64 elif name
[:5] == 'track':
65 trackno
= int(name
[6:])
66 self
.track
[trackno
] = value
71 filename
= posix
.environ
['HOME'] + '/' + cdplayerrc
73 old
= open(filename
, 'r')
75 old
= open('/dev/null', 'r')
76 new
= open(filename
+ '.new', 'w')
85 new
.write(self
.id + '.title:\t' + self
.title
+ '\n')
86 new
.write(self
.id + '.artist:\t' + self
.artist
+ '\n')
87 for i
in range(1, len(self
.track
)):
88 new
.write('%s.track.%r:\t%s\n' % (i
, track
))
91 posix
.rename(filename
+ '.new', filename
)