本文整理汇总了Python中util.Logutil.warn方法的典型用法代码示例。如果您正苦于以下问题:Python Logutil.warn方法的具体用法?Python Logutil.warn怎么用?Python Logutil.warn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Logutil
的用法示例。
在下文中一共展示了Logutil.warn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insertFile
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def insertFile(self, fileName, gameId, fileType, romCollectionId, publisherId, developerId):
log.debug("Begin Insert file: %s" % fileName)
parentId = None
# TODO console and romcollection could be done only once per RomCollection
# fileTypeRow[3] = parent
if fileType.parent == 'game':
parentId = gameId
elif fileType.parent == 'romcollection':
parentId = romCollectionId
elif fileType.parent == 'publisher':
parentId = publisherId
elif fileType.parent == 'developer':
parentId = developerId
log.info("Inserting file with parent {0} (type {1})".format(parentId, fileType.parent))
fileRow = File(self.gdb).getFileByNameAndTypeAndParent(fileName, fileType.id, parentId)
if fileRow is None:
log.info("File does not exist in database. Insert file: %s" % fileName)
f = File(self.gdb)
try:
f.insert((fileName, fileType.id, parentId))
except Exception, (exc):
log.warn("Error inserting into database: %s" % fileName)
示例2: _parse_game_result
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def _parse_game_result(self, response):
""" response is expected to be a JSON object """
result = {}
# Standard fields
for k, v in self._game_mapping.items():
try:
# HACK - for compatibility we need to put each result in an array
#result[k] = response[v]
result[k] = [response[v]]
except KeyError as k:
log.warn("Unable to find key: {0}".format(k))
except Exception as e:
log.warn("Unable to extract data from key {0}".format(e))
# Custom fields (i.e. ones that require special handling
# HACK - for compatibility we need to put each result in an array
result['ReleaseYear'] = [self._parse_date(response['original_release_date'])]
result['Developer'] = self._parse_developers(response['developers'])
result['Publisher'] = self._parse_publishers(response['publishers'])
result['Genre'] = self._parse_genres(response['genres'])
# FIXME TODO Artwork and images are quite cumbersome to get from giantbomb search results
return result
示例3: resolvePath
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def resolvePath(self, paths, gamename, gamenameFromFile, foldername, romCollectionName, publisher, developer):
resolvedFiles = []
for path in paths:
files = []
log.info("resolve path: %s" % path)
if path.find("%GAME%") > -1:
pathnameFromFile = path.replace("%GAME%", gamenameFromFile)
log.info("resolved path from rom file name: %s" % pathnameFromFile)
files = self.getFilesByWildcard(pathnameFromFile)
if len(files) == 0:
files = self.getFilesByGameNameIgnoreCase(pathnameFromFile)
if gamename != gamenameFromFile and len(files) == 0:
pathnameFromGameName = path.replace("%GAME%", gamename)
log.info("resolved path from game name: %s" % pathnameFromGameName)
files = self.getFilesByWildcard(pathnameFromGameName)
if len(files) == 0:
files = self.getFilesByGameNameIgnoreCase(pathnameFromGameName)
if gamename != foldername and len(files) == 0:
pathnameFromFolder = path.replace("%GAME%", foldername)
log.info("resolved path from rom folder name: %s" % pathnameFromFolder)
files = self.getFilesByWildcard(pathnameFromFolder)
if len(files) == 0:
files = self.getFilesByGameNameIgnoreCase(pathnameFromFolder)
# ODO could be done only once per RomCollection
if path.find("%ROMCOLLECTION%") > -1 and romCollectionName is not None and len(files) == 0:
pathnameFromRomCollection = path.replace("%ROMCOLLECTION%", romCollectionName)
log.info("resolved path from rom collection name: {0}".format(pathnameFromRomCollection))
files = self.getFilesByWildcard(pathnameFromRomCollection)
if path.find("%PUBLISHER%") > -1 and publisher is not None and len(files) == 0:
pathnameFromPublisher = path.replace("%PUBLISHER%", publisher)
log.info("resolved path from publisher name: %s" % pathnameFromPublisher)
files = self.getFilesByWildcard(pathnameFromPublisher)
if path.find("%DEVELOPER%") > -1 and developer is not None and len(files) == 0:
pathnameFromDeveloper = path.replace("%DEVELOPER%", developer)
log.info("resolved path from developer name: %s" % pathnameFromDeveloper)
files = self.getFilesByWildcard(pathnameFromDeveloper)
if path.find("%GAME%") == -1 & path.find("%ROMCOLLECTION%") == -1 & path.find(
"%PUBLISHER%") == -1 & path.find("%DEVELOPER%") == -1:
pathnameFromStaticFile = path
log.info("using static defined media file from path: %s" % pathnameFromStaticFile)
files = self.getFilesByWildcard(pathnameFromStaticFile)
if len(files) == 0:
log.warn("No files found for game '%s' at path '%s'. Make sure that file names are matching." % (
gamename, path))
for f in files:
if xbmcvfs.exists(f):
resolvedFiles.append(f)
return resolvedFiles
示例4: __getEncoding
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def __getEncoding(self):
# HACK: sys.getfilesystemencoding() is not supported on all systems (e.g. Android)
try:
encoding = sys.getfilesystemencoding()
except Exception as e:
log.warn("Unable to get filesystem encoding, defaulting to UTF-8")
encoding = 'utf-8'
return encoding
示例5: resolveParseResult
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def resolveParseResult(self, result, itemName):
resultValue = u''
try:
resultValue = result[itemName][0].strip()
if type(resultValue) == str:
resultValue = resultValue.decode('utf-8')
except Exception, (exc):
log.warn(u"Error while resolving item: %s: %s" % (itemName, exc))
示例6: _parse_date
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def _parse_date(self, datestr):
"""Extract the year from a given date string using a given format. This function is used to cater for
an edge case identified in https://forum.kodi.tv/showthread.php?tid=112916&pid=1214507#pid1214507.
Args:
datestr: Input date
Returns:
Year as a %Y format string
"""
if datestr is None:
return '1970'
x = None
for fmt2 in ["%Y-%m-%d", "%Y-%m", "%Y", "%Y-%m-%d %H:%M:%S", "%d/%m/%Y", "%m/%d/%Y"]:
try:
x = datetime.strptime(datestr, fmt2).strftime("%Y")
break
except ValueError as e:
# Skip to the next format
log.warn("ValueError in parseDate: %s" %e)
except TypeError as e:
log.warn("Unable to parse date using strptime, falling back to time function")
try:
x = datetime(*(time.strptime(datestr, fmt2)[0:6])).strftime("%Y")
break
except ValueError as ve:
log.warn("Unable to parse date %s using %s, try next format. %s" %(datestr, fmt2, ve))
if x is not None:
return x
else:
log.warn(u"Unexpected date format: {0}".format(datestr))
return u"1970"
示例7: _parse_screenshots_result
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def _parse_screenshots_result(self, response):
result = {}
screenshots = response['screenshots']
if len(screenshots) == 0:
log.warn("No screenshots found in mobygames response")
return result
#HACK: always return the first screenshot. We could add support for multiple screenshots or screenshot selection.
screenshot = screenshots[0]
result['Filetypescreenshot'] = [screenshot['image']]
return result
示例8: __executeCommand
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def __executeCommand(self, cmd):
# change working directory
path = os.path.dirname(self.romCollection.emulatorCmd)
if os.path.isdir(path):
try:
os.chdir(path)
except OSError:
log.warn("Unable to chdir to {0}".format(path))
if self.romCollection.usePopen:
import subprocess
process = subprocess.Popen(cmd.encode(self.__getEncoding()), shell=True)
process.wait()
else:
os.system(cmd.encode(self.__getEncoding()))
示例9: getRomCollectionById
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def getRomCollectionById(self, id):
"""
Find the matching Rom Collection by ID
Args:
id: the ID of the Rom Collection to be found (as a str)
Returns:
The Rom Collection with the matching ID, or None if not found
"""
try:
return self.romCollections.get(id)
except KeyError as e:
log.warn("Unable to find rom collection with ID {0}".format(id))
return None
示例10: get_platform_for_scraper
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def get_platform_for_scraper(self, platformname):
"""Get the platform identifier used on the corresponding website.
Args:
platformname: The RCB platform name
Returns:
String that is the identifier for the platform on the corresponding website.
"""
try:
ix = self.pmaps.index(self._name)
except ValueError as e:
# Did not find a mapping
log.warn("Did not find a platform mapping for {0}".format(self._name))
ix = 0
return self.consoleDict[platformname][ix]
示例11: getBestResults
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def getBestResults(self, results, gamenameFromFile):
"""
Compare a game name against each item in a result set to work out which is the likely match
Args:
results: A list of dicts with the SearchKey key being the game title in the result set
gamenameFromFile: The title of the game we are trying to match
Returns:
Either None if no match was found, or the title of the matching game (SearchKey key in the dict)
"""
log.info("getBestResults")
if results is None or len(results) == 0:
log.info("No results found with current scraper")
return None
log.info("Searching for game: " + gamenameFromFile)
log.info("%s results found. Try to find best match." % str(len(results)))
result = self.matchGamename(results, gamenameFromFile, False)
if result:
# get name of found result
foundgame = self.resolveParseResult(result, 'SearchKey')
log.info("Using result %s" % foundgame)
return result
# stop searching in accurate mode
if self.update_option == util.SCRAPING_OPTION_AUTO_ACCURATE:
log.warn("No game found with scraping option 'Accurate'. Game will be skipped")
return None
# Ask for correct result in Interactive mode
if self.update_option == util.SCRAPING_OPTION_INTERACTIVE:
res = self.ask_user_for_result(gamenameFromFile, results)
if res == 0: # Skip Game
log.info("No result chosen by user")
return None
else:
selectedGame = self.resolveParseResult(results[res - 1], 'Game')
log.info("Result chosen by user: " + str(selectedGame))
return results[res - 1]
示例12: matchGamename
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def matchGamename(self, results, gamenameFromFile, checkSubtitle):
for idx, result in enumerate(results):
try:
# Check if the result has the correct platform (if needed)
found_platform = self.resolveParseResult(result, 'PlatformSearchKey')
if found_platform != '' and self.expected_platform != found_platform:
log.info("Platform mismatch. %s != %s. Result will be skipped." % (
self.expected_platform, found_platform))
continue
searchKey = self.resolveParseResult(result, 'SearchKey')
# keep it for later reference
searchkey_orig = searchKey
gamename_orig = gamenameFromFile
# if no searchkey is specified first result is valid (1 file per game scenario)
if searchkey_orig == '':
log.info("No searchKey found. Using first result")
return result
log.info("Comparing %s with %s" % (gamename_orig, searchkey_orig))
if gamename_orig == searchkey_orig:
# perfect match
return result
# normalize name and searchkey before comparison
gnu = GameNameUtil()
gamename_normalized = gnu.normalize_name(gamename_orig)
searchkey_normalized = gnu.normalize_name(searchkey_orig)
log.info("Try normalized names. Comparing %s with %s" % (gamename_normalized, searchkey_normalized))
if gamename_normalized == searchkey_normalized:
# perfect match
return result
#strip additional info from gamename
gamename_stripped = gnu.strip_addinfo_from_name(gamename_orig)
gamename_stripped = gnu.normalize_name(gamename_stripped)
log.info("Try with stripped additional info. Comparing %s with %s" % (gamename_stripped, searchkey_normalized))
if gamename_stripped == searchkey_normalized:
# perfect match
return result
except Exception, (exc):
log.warn("An error occured while matching the best result: " + str(exc))
示例13: _parse_search_results
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def _parse_search_results(self, response):
results = []
""" response is expected to be a JSON object """
log.debug("Parsing response for search results: {0}".format(response))
if len(response["games"]) == 0:
log.warn("No results found")
return results
for result in response['games']:
results.append({'id': result['game_id'],
'title': result['title'],
'releaseDate': "", # MobyGames search doesn't return a year in brief mode
'SearchKey': [result['title']]})
log.debug("Found {0} results using requests JSON parser: {1}".format(len(results), results))
return results
示例14: getFilesByGameNameIgnoreCase
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def getFilesByGameNameIgnoreCase(self, pathname):
files = []
dirname = os.path.dirname(pathname)
basename = os.path.basename(pathname)
# search all Files that start with the first character of game name
newpath = util.joinPath(dirname, basename[0].upper() + '*')
filesUpper = glob.glob(newpath)
newpath = util.joinPath(dirname, basename[0].lower() + '*')
filesLower = glob.glob(newpath)
allFiles = filesUpper + filesLower
for file in allFiles:
if pathname.lower() == file.lower():
log.warn("Found path '%s' by search with ignore case." % pathname)
files.append(file)
return files
示例15: insertGameFromDesc
# 需要导入模块: from util import Logutil [as 别名]
# 或者: from util.Logutil import warn [as 别名]
def insertGameFromDesc(self, gamedescription, gamename, romCollection, filenamelist, foldername, isUpdate, gameId):
log.info("insertGameFromDesc")
if gamedescription is not None:
game = self.resolveParseResult(gamedescription, 'Game')
else:
game = ''
# if no game name has been scraped we expect that no results have been found
if game == '':
self.missingDescFile.add_entry(gamename)
if __addon__.getSetting(util.SETTING_RCB_IGNOREGAMEWITHOUTDESC).upper() == 'TRUE':
log.warn("No description found for game '%s'. Game will not be imported." % gamename)
return None
gamedescription = {}
gameId = self.insertData(gamedescription, gamename, romCollection, filenamelist, foldername, isUpdate, gameId)
return gameId