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
17 cdplayerrc
= '.cdplayerrc'
20 def __init__(self
, tracklist
):
24 if type(tracklist
) == type(''):
26 for i
in range(2, len(tracklist
), 4):
28 (string
.atoi(tracklist
[i
:i
+2]), \
29 string
.atoi(tracklist
[i
+2:i
+4]))))
31 self
.track
= [None] + [''] * len(tracklist
)
32 self
.id = 'd' + string
.zfill(len(tracklist
), 2)
33 for track
in tracklist
:
35 self
.id = self
.id + string
.zfill(length
[0], 2) + \
36 string
.zfill(length
[1], 2)
39 f
= open(posix
.environ
['HOME'] + '/' + cdplayerrc
, 'r')
43 reg
= re
.compile(r
'^([^:]*):\t(.*)')
52 match
= reg
.match(line
)
54 print 'syntax error in ~/' + cdplayerrc
56 name
, value
= match
.group(1, 2)
59 elif name
== 'artist':
61 elif name
[:5] == 'track':
62 trackno
= string
.atoi(name
[6:])
63 self
.track
[trackno
] = value
68 filename
= posix
.environ
['HOME'] + '/' + cdplayerrc
70 old
= open(filename
, 'r')
72 old
= open('/dev/null', 'r')
73 new
= open(filename
+ '.new', 'w')
82 new
.write(self
.id + '.title:\t' + self
.title
+ '\n')
83 new
.write(self
.id + '.artist:\t' + self
.artist
+ '\n')
84 for i
in range(1, len(self
.track
)):
85 new
.write(self
.id + '.track.' + `i`
+ ':\t' + \
89 posix
.rename(filename
+ '.new', filename
)