本文整理汇总了Python中Debug.out方法的典型用法代码示例。如果您正苦于以下问题:Python Debug.out方法的具体用法?Python Debug.out怎么用?Python Debug.out使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Debug
的用法示例。
在下文中一共展示了Debug.out方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: searchBy_Title
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import out [as 别名]
def searchBy_Title(self, searchStr):
""" Search the library by song title where searchStr matches the title.
NB: If searchStr consists of multiple words then ALL words must be found within the title to make a match.
arguments:
searchStr as string "word1 word2..."
returns:
list [songID1, songID2, ...] of songIDs that match the search criteria
"""
Debug.out("Searching", len(self.songs), "song titles")
t1 = time.time()
wordList = MakeWordlist(searchStr)
matchedSongs = []
for songID, songData in self.songs.iteritems():
songTitle = songData['title-search']
asciiSongTitle = songData['title-searchAscii']
matches = [1 for (asciiWord, word) in wordList if asciiWord in asciiSongTitle or word in songTitle]
if len(matches) == len(wordList):
matchedSongs.append(songID)
Debug.out(" Found", len(matchedSongs), "songs in", round(time.time()-t1,6), "seconds")
return matchedSongs
示例2: loadFromLog
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import out [as 别名]
def loadFromLog(self, logFile):
Debug.out("Loading log " + logFile)
if os.path.isfile(logFile):
statinfo = os.stat(logFile)
if not statinfo.st_size:
raise LogError("Log has zero length")
else:
raise LogError("Log doesn't exist!")
try:
f = open(logFile, 'r')
except IOError as err:
raise LogError("Parsing log failed on IOError: " + str(errstr))
t1 = time.time()
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = self.start_element
p.EndElementHandler = self.end_element
p.CharacterDataHandler = self.char_data
p.buffer_text = True
try:
p.ParseFile(f)
Debug.out(" Loaded", self.numLoaded, "rows in", round(time.time() - t1,5), "seconds")
except IOError as err:
raise LogError("Parsing log failed on IOError: " + str(IOError))
except ExpatError as err:
raise LogError("Parsing log failed on XML ExpatError: " + str(err))
finally:
f.close()
示例3: searchBy_Genre
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import out [as 别名]
def searchBy_Genre(self, searchStr):
""" Search the library by Genre Name where searchStr matches the genre name.
NB: If searchStr consists of multiple words then ALL words must be found within the genre name to make a
match.
arguments:
searchStr as string "word1 word2..."
returns:
list [songID1, songID2, ...] of songIDs that match the search criteria
"""
Debug.out("Searching", len(self.byGenre), "genres")
t1 = time.time()
wordList = MakeWordlist(searchStr)
matchedSongs = []
for genre in self.byGenre:
asciiGenre = NiceAscii(genre)
matches = [1 for (asciiWord, word) in wordList if asciiWord in asciiGenre or word in genre]
if len(matches) == len(wordList):
matchedSongs.extend(self.byGenre[genre])
Debug.out(" Found", len(matchedSongs), "songs in", round(time.time()-t1,6), "seconds")
return matchedSongs
示例4: sort_Songs
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import out [as 别名]
def sort_Songs(self, songlist, sortby):
""" Sort a list of songID's by the specified sortby paramaters
arguments:
songlist as list[songID, ... ] of valid songID's in the library
sortby as list[ (field, direction), ... ]
where field in (title,artist,album,genre) and direction in (asc, desc)
returns:
list as [songID, ... ] sorted by the sortby criteria
"""
t1 = time.time()
listToSort = [self.makeSortingTuple(songID, sortby) for songID in songlist]
listToSort.sort()
listSorted = [sortTuple[-1] for sortTuple in listToSort]
Debug.out(" Sorted", len(listSorted),"songs in", round(time.time()-t1,6), "seconds")
return listSorted
示例5: searchBy_Letter
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import out [as 别名]
def searchBy_Letter(self, theLetter):
""" Search the library by a single letter. This returns all "(Artist -) Title" where the first letter begins
with the specified letter.
arguments:
theLetter as string of length 1, where (theLetter == '0' OR theLetter in string.ascii_lowercase)
returns:
None On error only
list [songID1, songID2, ...]
"""
# sanitize data:
theLetter = theLetter[0].lower()
if (theLetter in string.ascii_lowercase or theLetter == '0') and theLetter in self.byLetter:
Debug.out("Searching letter", theLetter)
songList = self.byLetter[theLetter]
return songList
else:
return None
示例6: load
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import out [as 别名]
def load(self, libraryPath):
Debug.out(" Parsing iTunes XML...")
if os.path.isfile(libraryPath):
statinfo = os.stat(libraryPath)
if not statinfo.st_size:
raise LibraryError("iTunes Library zero length")
else:
raise LibraryError("iTunes Library doesn't exist!")
try:
f = open(libraryPath, 'r')
except IOError as err:
raise LibraryError("Opening iTunes Library failed on IOError: " + str(errstr))
t1 = time.time()
self.parser = ParserData()
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = self.start_element
p.EndElementHandler = self.end_element
p.CharacterDataHandler = self.char_data
# important! if you don't set buffer_text to true, the CharacterDataHandler does not always return the
# full text inside of a <tag></tag> pair! this will cause some data to be loaded incompletely unless
# the code implements its own buffering!
p.buffer_text = True
try:
p.ParseFile(f)
t2 = time.time()
Debug.out(" Loaded", len(self.songs), "songs!")
Debug.out(" Parsing took", round(t2 - t1,4), "seconds")
except IOError as err:
raise LibraryError("Parsing iTunes Library failed on IOError: " + str(IOError))
except ExpatError as err:
raise LibraryError("Parsing iTunes Library failed on XML ExpatError: " + str(err))
finally:
f.close()
示例7: searchBy_Any
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import out [as 别名]
def searchBy_Any(self, searchStr):
""" Search the library where searchStr matches any of (title|artist|genre)
NB: If searchStr consists of multiple words then ALL words must be found within at least ONE of the
fields (title|artist|album|genre) to make a match.
arguments:
searchStr as string "word1 word2..."
returns:
list [songID1, songID2, ...] of songIDs that match the search criteria
"""
Debug.out("Searching", len(self.songs), "songs (artist, title, album, genre)")
t1 = time.time()
wordList = MakeWordlist(searchStr)
matchedSongs = []
for songID, songData in self.songs.iteritems():
# search by artist first
songArtist = songData['artist-search']
asciiSongArtist = songData['artist-searchAscii']
i = 0
for (asciiWord, word) in wordList:
if asciiWord in asciiSongArtist or word in songArtist:
i += 1
if i == len(wordList):
matchedSongs.append(songID)
continue
# search by title
songTitle = songData['title-search']
asciiSongTitle = songData['title-searchAscii']
i = 0
for (asciiWord, word) in wordList:
if asciiWord in asciiSongTitle or word in songTitle:
i += 1
if i == len(wordList):
matchedSongs.append(songID)
continue
# search by album
songAlbum = songData['album-search']
asciiSongAlbum = songData['album-searchAscii']
i = 0
for (asciiWord, word) in wordList:
if asciiWord in asciiSongAlbum or word in songAlbum:
i += 1
if i == len(wordList):
matchedSongs.append(songID)
continue
# search by genre
songGenre = songData['genre-search']
songGenreAscii = songData['genre-searchAscii']
i = 0
for (asciiWord, word) in wordList:
if asciiWord in songGenreAscii or word in songGenre:
i += 1
if i == len(wordList):
matchedSongs.append(songID)
continue
#endfor
Debug.out(" Found", len(matchedSongs), "songs in", round(time.time()-t1,6), "seconds")
return matchedSongs