Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2e358d

Browse files
Use __init__ instead of init.
Also use CDDB_PATH and CDDB_WRITE_DIR environment variables in cddb.py.
1 parent e65cce5 commit b2e358d

8 files changed

Lines changed: 28 additions & 26 deletions

File tree

Lib/irix5/cddb.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Usage is as follows:
55
#
66
# import readcd
7-
# r = readcd.Readcd().init()
8-
# c = Cddb().init(r.gettrackinfo())
7+
# r = readcd.Readcd()
8+
# c = Cddb(r.gettrackinfo())
99
#
1010
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
1111
# starts at 1). When the CD is not recognized, all values will be the empty
@@ -55,7 +55,7 @@ def tochash(toc):
5555
return hash
5656

5757
class Cddb:
58-
def init(self, tracklist):
58+
def __init__(self, tracklist):
5959
if posix.environ.has_key('CDDB_PATH'):
6060
path = posix.environ['CDDB_PATH']
6161
cddb_path = string.splitfields(path, ',')
@@ -104,7 +104,7 @@ def init(self, tracklist):
104104
except IOError:
105105
pass
106106
if not hasattr(self, 'file'):
107-
return self
107+
return
108108
import regex
109109
reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):\t\\(.*\\)')
110110
while 1:
@@ -138,14 +138,17 @@ def init(self, tracklist):
138138
continue
139139
self.track[trackno] = value
140140
f.close()
141-
return self
142141

143142
def write(self):
143+
import posixpath
144144
if posix.environ.has_key('CDDB_WRITE_DIR'):
145145
dir = posix.environ['CDDB_WRITE_DIR']
146146
else:
147147
dir = posix.environ['HOME'] + '/' + _cddbrc
148148
file = dir + '/' + self.id + '.rdb'
149+
if posixpath.exists(file):
150+
# make backup copy
151+
posix.rename(file, file + '~')
149152
f = open(file, 'w')
150153
f.write('album.title:\t' + self.title + '\n')
151154
f.write('album.artist:\t' + self.artist + '\n')

Lib/irix5/cdplayer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Usage is as follows:
55
#
66
# import readcd
7-
# r = readcd.Readcd().init()
8-
# c = Cdplayer().init(r.gettrackinfo())
7+
# r = readcd.Readcd()
8+
# c = Cdplayer(r.gettrackinfo())
99
#
1010
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
1111
# starts at 1). When the CD is not recognized, all values will be the empty
@@ -17,7 +17,7 @@
1717
cdplayerrc = '.cdplayerrc'
1818

1919
class Cdplayer:
20-
def init(self, tracklist):
20+
def __init__(self, tracklist):
2121
import string
2222
self.artist = ''
2323
self.title = ''
@@ -38,7 +38,7 @@ def init(self, tracklist):
3838
import posix
3939
f = open(posix.environ['HOME'] + '/' + cdplayerrc, 'r')
4040
except IOError:
41-
return self
41+
return
4242
import regex
4343
reg = regex.compile('^\\([^:]*\\):\t\\(.*\\)')
4444
s = self.id + '.'
@@ -62,7 +62,6 @@ def init(self, tracklist):
6262
trackno = string.atoi(name[6:])
6363
self.track[trackno] = value
6464
f.close()
65-
return self
6665

6766
def write(self):
6867
import posix

Lib/irix5/readcd.doc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ read and the callbacks will be called.
1818
Initialization.
1919
===============
2020

21-
r = readcd.Readcd().init([cd-player [, mode]])
21+
r = readcd.Readcd([cd-player [, mode]])
2222

2323
The optional arguments are the name of the CD device and the mode.
2424
When "mode" is not specified, it defaults to 'r' (which is the only

Lib/irix5/readcd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _dopnum(self, cb_type, data):
2222
func(arg, cb_type, data)
2323

2424
class Readcd:
25-
def init(self, *arg):
25+
def __init__(self, *arg):
2626
if len(arg) == 0:
2727
self.player = cd.open()
2828
elif len(arg) == 1:
@@ -38,7 +38,6 @@ def init(self, *arg):
3838
self.end = 0
3939
self.status = None
4040
self.trackinfo = None
41-
return self
4241

4342
def eject(self):
4443
self.player.eject()

Lib/plat-irix5/cddb.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Usage is as follows:
55
#
66
# import readcd
7-
# r = readcd.Readcd().init()
8-
# c = Cddb().init(r.gettrackinfo())
7+
# r = readcd.Readcd()
8+
# c = Cddb(r.gettrackinfo())
99
#
1010
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
1111
# starts at 1). When the CD is not recognized, all values will be the empty
@@ -55,7 +55,7 @@ def tochash(toc):
5555
return hash
5656

5757
class Cddb:
58-
def init(self, tracklist):
58+
def __init__(self, tracklist):
5959
if posix.environ.has_key('CDDB_PATH'):
6060
path = posix.environ['CDDB_PATH']
6161
cddb_path = string.splitfields(path, ',')
@@ -104,7 +104,7 @@ def init(self, tracklist):
104104
except IOError:
105105
pass
106106
if not hasattr(self, 'file'):
107-
return self
107+
return
108108
import regex
109109
reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):\t\\(.*\\)')
110110
while 1:
@@ -138,14 +138,17 @@ def init(self, tracklist):
138138
continue
139139
self.track[trackno] = value
140140
f.close()
141-
return self
142141

143142
def write(self):
143+
import posixpath
144144
if posix.environ.has_key('CDDB_WRITE_DIR'):
145145
dir = posix.environ['CDDB_WRITE_DIR']
146146
else:
147147
dir = posix.environ['HOME'] + '/' + _cddbrc
148148
file = dir + '/' + self.id + '.rdb'
149+
if posixpath.exists(file):
150+
# make backup copy
151+
posix.rename(file, file + '~')
149152
f = open(file, 'w')
150153
f.write('album.title:\t' + self.title + '\n')
151154
f.write('album.artist:\t' + self.artist + '\n')

Lib/plat-irix5/cdplayer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Usage is as follows:
55
#
66
# import readcd
7-
# r = readcd.Readcd().init()
8-
# c = Cdplayer().init(r.gettrackinfo())
7+
# r = readcd.Readcd()
8+
# c = Cdplayer(r.gettrackinfo())
99
#
1010
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
1111
# starts at 1). When the CD is not recognized, all values will be the empty
@@ -17,7 +17,7 @@
1717
cdplayerrc = '.cdplayerrc'
1818

1919
class Cdplayer:
20-
def init(self, tracklist):
20+
def __init__(self, tracklist):
2121
import string
2222
self.artist = ''
2323
self.title = ''
@@ -38,7 +38,7 @@ def init(self, tracklist):
3838
import posix
3939
f = open(posix.environ['HOME'] + '/' + cdplayerrc, 'r')
4040
except IOError:
41-
return self
41+
return
4242
import regex
4343
reg = regex.compile('^\\([^:]*\\):\t\\(.*\\)')
4444
s = self.id + '.'
@@ -62,7 +62,6 @@ def init(self, tracklist):
6262
trackno = string.atoi(name[6:])
6363
self.track[trackno] = value
6464
f.close()
65-
return self
6665

6766
def write(self):
6867
import posix

Lib/plat-irix5/readcd.doc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ read and the callbacks will be called.
1818
Initialization.
1919
===============
2020

21-
r = readcd.Readcd().init([cd-player [, mode]])
21+
r = readcd.Readcd([cd-player [, mode]])
2222

2323
The optional arguments are the name of the CD device and the mode.
2424
When "mode" is not specified, it defaults to 'r' (which is the only

Lib/plat-irix5/readcd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _dopnum(self, cb_type, data):
2222
func(arg, cb_type, data)
2323

2424
class Readcd:
25-
def init(self, *arg):
25+
def __init__(self, *arg):
2626
if len(arg) == 0:
2727
self.player = cd.open()
2828
elif len(arg) == 1:
@@ -38,7 +38,6 @@ def init(self, *arg):
3838
self.end = 0
3939
self.status = None
4040
self.trackinfo = None
41-
return self
4241

4342
def eject(self):
4443
self.player.eject()

0 commit comments

Comments
 (0)