本文整理汇总了Python中picard.log.warning函数的典型用法代码示例。如果您正苦于以下问题:Python warning函数的具体用法?Python warning怎么用?Python warning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warning函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_action_toolbar
def create_action_toolbar(self):
if self.toolbar:
self.toolbar.clear()
self.removeToolBar(self.toolbar)
self.toolbar = toolbar = QtWidgets.QToolBar(_("Actions"))
self.insertToolBar(self.search_toolbar, self.toolbar)
self.update_toolbar_style()
toolbar.setObjectName("main_toolbar")
def add_toolbar_action(action):
toolbar.addAction(action)
widget = toolbar.widgetForAction(action)
widget.setFocusPolicy(QtCore.Qt.TabFocus)
widget.setAttribute(QtCore.Qt.WA_MacShowFocusRect)
for action in config.setting['toolbar_layout']:
if action == 'cd_lookup_action':
add_toolbar_action(self.cd_lookup_action)
if len(self.cd_lookup_menu.actions()) > 1:
button = toolbar.widgetForAction(self.cd_lookup_action)
button.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup)
button.setMenu(self.cd_lookup_menu)
elif action == 'separator':
toolbar.addSeparator()
else:
try:
add_toolbar_action(getattr(self, action))
except AttributeError:
log.warning('Warning: Unknown action name "%r" found in config. Ignored.', action)
self.show_toolbar()
示例2: load_remote_image
def load_remote_image(self, url, mime, data):
try:
coverartimage = CoverArtImage(url=url.toString(), data=data)
except CoverArtImageError as e:
log.warning("Can't load image: %s" % unicode(e))
return
pixmap = QtGui.QPixmap()
pixmap.loadFromData(data)
self.__set_data([mime, data], pixmap=pixmap)
if isinstance(self.item, Album):
album = self.item
album.metadata.append_image(coverartimage)
for track in album.tracks:
track.metadata.append_image(coverartimage)
for file in album.iterfiles():
file.metadata.append_image(coverartimage)
elif isinstance(self.item, Track):
track = self.item
track.metadata.append_image(coverartimage)
for file in track.iterfiles():
file.metadata.append_image(coverartimage)
elif isinstance(self.item, File):
file = self.item
file.metadata.append_image(coverartimage)
self.currentImage = len(self.metadata.images) - 1
self.__update_image_count()
示例3: main
def main(localedir=None, autoupdate=True):
# Some libs (ie. Phonon) require those to be set
QtWidgets.QApplication.setApplicationName(PICARD_APP_NAME)
QtWidgets.QApplication.setOrganizationName(PICARD_ORG_NAME)
signal.signal(signal.SIGINT, signal.SIG_DFL)
picard_args, unparsed_args = process_picard_args()
if picard_args.version:
return version()
if picard_args.long_version:
return longversion()
tagger = Tagger(picard_args, unparsed_args, localedir, autoupdate)
# Initialize Qt default translations
translator = QtCore.QTranslator()
locale = QtCore.QLocale()
translation_path = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)
log.debug("Looking for Qt locale %s in %s", locale.name(), translation_path)
if translator.load(locale, "qtbase_", directory=translation_path):
tagger.installTranslator(translator)
else:
log.warning('Error loading Qt locale %s', locale.name())
tagger.startTimer(1000)
sys.exit(tagger.run())
示例4: load_plugindir
def load_plugindir(self, plugindir):
plugindir = os.path.normpath(plugindir)
if not os.path.isdir(plugindir):
log.warning("Plugin directory %r doesn't exist", plugindir)
return
# first, handle eventual plugin updates
for updatepath in [os.path.join(plugindir, file) for file in os.listdir(plugindir) if file.endswith(".update")]:
path = os.path.splitext(updatepath)[0]
name = is_zip(path)
if not name:
name = _plugin_name_from_path(path)
if name:
self.remove_plugin(name)
os.rename(updatepath, path)
log.debug("Updating plugin %r (%r))", name, path)
else:
log.error("Cannot get plugin name from %r", updatepath)
# now load found plugins
names = set()
for path in [os.path.join(plugindir, file) for file in os.listdir(plugindir)]:
name = is_zip(path)
if not name:
name = _plugin_name_from_path(path)
if name:
names.add(name)
log.debug("Looking for plugins in directory %r, %d names found", plugindir, len(names))
for name in sorted(names):
self.load_plugin(name, plugindir)
示例5: _coverart_downloaded
def _coverart_downloaded(self, coverartimage, data, http, error):
"""Handle finished download, save it to metadata"""
self.album._requests -= 1
if error:
self.album.error_append(u'Coverart error: %s' % (unicode(http.errorString())))
elif len(data) < 1000:
log.warning("Not enough data, skipping %s" % coverartimage)
else:
self._message(
N_("Cover art of type '%(type)s' downloaded for %(albumid)s from %(host)s"),
{
'type': coverartimage.types_as_string(),
'albumid': self.album.id,
'host': coverartimage.host
},
echo=None
)
try:
self._set_metadata(coverartimage, data)
except CoverArtImageIOError:
# It doesn't make sense to store/download more images if we can't
# save them in the temporary folder, abort.
return
self.next_in_queue()
示例6: create_action_toolbar
def create_action_toolbar(self):
if getattr(self, 'toolbar', None):
self.toolbar.clear()
self.removeToolBar(self.toolbar)
self.toolbar = toolbar = QtGui.QToolBar(_(u"Actions"))
self.insertToolBar(self.search_toolbar, self.toolbar)
self.toolbar_toggle_action = self.toolbar.toggleViewAction()
self.update_toolbar_style()
toolbar.setObjectName("main_toolbar")
def add_toolbar_action(action):
toolbar.addAction(action)
widget = toolbar.widgetForAction(action)
widget.setFocusPolicy(QtCore.Qt.TabFocus)
widget.setAttribute(QtCore.Qt.WA_MacShowFocusRect)
for action in config.setting['toolbar_layout']:
if action not in ('cd_lookup_action', 'separator'):
try:
add_toolbar_action(getattr(self, action))
except AttributeError:
log.warning('Warning: Unknown action name "%r" found in config. Ignored.', action)
elif action == 'cd_lookup_action':
add_toolbar_action(self.cd_lookup_action)
drives = get_cdrom_drives()
if len(drives) > 1:
self.cd_lookup_menu = QtGui.QMenu()
for drive in drives:
self.cd_lookup_menu.addAction(drive)
self.cd_lookup_menu.triggered.connect(self.tagger.lookup_cd)
button = toolbar.widgetForAction(self.cd_lookup_action)
button.setPopupMode(QtGui.QToolButton.MenuButtonPopup)
button.setMenu(self.cd_lookup_menu)
elif action == 'separator':
toolbar.addSeparator()
示例7: load_remote_image
def load_remote_image(self, url, mime, data):
try:
coverartimage = CoverArtImage(
url=url.toString(),
types=['front'],
data=data
)
except CoverArtImageError as e:
log.warning("Can't load image: %s" % e)
return
if config.setting["load_image_behavior"] == 'replace':
set_image = set_image_replace
debug_info = "Replacing with dropped %r in %r"
else:
set_image = set_image_append
debug_info = "Appending dropped %r to %r"
update = True
if isinstance(self.item, Album):
album = self.item
album.enable_update_metadata_images(False)
set_image(album, coverartimage)
for track in album.tracks:
set_image(track, coverartimage)
track.metadata_images_changed.emit()
for file in album.iterfiles():
set_image(file, coverartimage)
file.metadata_images_changed.emit()
file.update()
album.enable_update_metadata_images(True)
album.update_metadata_images()
album.update(False)
elif isinstance(self.item, Track):
track = self.item
track.album.enable_update_metadata_images(False)
set_image(track, coverartimage)
track.metadata_images_changed.emit()
for file in track.iterfiles():
set_image(file, coverartimage)
file.metadata_images_changed.emit()
file.update()
track.album.enable_update_metadata_images(True)
track.album.update_metadata_images()
track.album.update(False)
elif isinstance(self.item, File):
file = self.item
set_image(file, coverartimage)
file.metadata_images_changed.emit()
file.update()
else:
debug_info = "Dropping %r to %r is not handled"
update = False
log.debug(debug_info, coverartimage, self.item)
if update:
self.cover_art.set_metadata(self.item.metadata)
self.show()
示例8: queue_images
def queue_images(self):
# this method has to return CoverArtProvider.FINISHED or
# CoverArtProvider.WAIT
old = getattr(self, 'queue_downloads') #compat with old plugins
if callable(old):
log.warning('CoverArtProvider: queue_downloads() was replaced by queue_images()')
return old()
else:
raise NotImplementedError
示例9: on_remote_image_fetched
def on_remote_image_fetched(self, data, reply, error):
mime = reply.header(QtNetwork.QNetworkRequest.ContentTypeHeader)
if mime in ('image/jpeg', 'image/png'):
self.load_remote_image(mime, data)
elif reply.url().hasQueryItem("imgurl"):
# This may be a google images result, try to get the URL which is encoded in the query
url = QtCore.QUrl(reply.url().queryItemValue("imgurl"))
self.fetch_remote_image(url)
else:
log.warning("Can't load image with MIME-Type %s", mime)
示例10: _display_artwork
def _display_artwork(self, images, col):
"""Draw artwork in corresponding cell if image type matches type in Type column.
Arguments:
images -- The images to be drawn.
col -- Column in which images are to be drawn. Can be _new_cover_col or _existing_cover_col.
"""
row = 0
row_count = self.artwork_table.rowCount()
for image in images:
while row != row_count:
image_type = self.artwork_table.item(row, self.artwork_table._type_col)
if image_type and image_type.data(QtCore.Qt.UserRole) == image.types_as_string():
break
row += 1
if row == row_count:
continue
data = None
try:
if image.thumbnail:
try:
data = image.thumbnail.data
except CoverArtImageIOError as e:
log.warning(e)
pass
else:
data = image.data
except CoverArtImageIOError:
log.error(traceback.format_exc())
continue
item = QtWidgets.QTableWidgetItem()
item.setData(QtCore.Qt.UserRole, image)
pixmap = QtGui.QPixmap()
if data is not None:
pixmap.loadFromData(data)
item.setToolTip(
_("Double-click to open in external viewer\n"
"Temporary file: %s\n"
"Source: %s") % (image.tempfile_filename, image.source))
infos = []
if image.comment:
infos.append(image.comment)
infos.append("%s (%s)" %
(bytes2human.decimal(image.datalength),
bytes2human.binary(image.datalength)))
if image.width and image.height:
infos.append("%d x %d" % (image.width, image.height))
infos.append(image.mimetype)
img_wgt = self.artwork_table.get_coverart_widget(pixmap, "\n".join(infos))
self.artwork_table.setCellWidget(row, col, img_wgt)
self.artwork_table.setItem(row, col, item)
row += 1
示例11: _coverart_downloaded
def _coverart_downloaded(self, coverartimage, data, http, error):
"""Handle finished download, save it to metadata"""
self.album._requests -= 1
if error:
self.album.error_append(u'Coverart error: %s' % (unicode(http.errorString())))
elif len(data) < 1000:
log.warning("Not enough data, skipping %s" % coverartimage)
else:
self._message(
N_("Cover art of type '%(type)s' downloaded for %(albumid)s from %(host)s"),
{
'type': coverartimage.types_as_string(),
'albumid': self.album.id,
'host': coverartimage.host
},
echo=None
)
try:
coverartimage.set_data(data)
if coverartimage.can_be_saved_to_metadata:
log.debug("Cover art image downloaded: %r [%s]" %
(
coverartimage,
coverartimage.imageinfo_as_string()
)
)
self.metadata.append_image(coverartimage)
for track in self.album._new_tracks:
track.metadata.append_image(coverartimage)
# If the image already was a front image,
# there might still be some other non-CAA front
# images in the queue - ignore them.
if not self.front_image_found:
self.front_image_found = coverartimage.is_front_image()
else:
log.debug("Thumbnail for cover art image downloaded: %r [%s]" %
(
coverartimage,
coverartimage.imageinfo_as_string()
)
)
except CoverArtImageIOError as e:
self.album.error_append(unicode(e))
self.album._finalize_loading(error=True)
# It doesn't make sense to store/download more images if we can't
# save them in the temporary folder, abort.
return
except CoverArtImageIdentificationError as e:
self.album.error_append(unicode(e))
self.download_next_in_queue()
示例12: _save_and_rename
def _save_and_rename(self, old_filename, metadata):
"""Save the metadata."""
# Check that file has not been removed since thread was queued
# Also don't save if we are stopping.
if self.state == File.REMOVED:
log.debug("File not saved because it was removed: %r", self.filename)
return None
if self.tagger.stopping:
log.debug("File not saved because %s is stopping: %r", PICARD_APP_NAME, self.filename)
return None
new_filename = old_filename
if not config.setting["dont_write_tags"]:
save = partial(self._save, old_filename, metadata)
if config.setting["preserve_timestamps"]:
try:
self._preserve_times(old_filename, save)
except self.PreserveTimesStatError as why:
log.warning(why)
# we didn't save the file yet, bail out
return None
except self.FilePreserveTimesUtimeError as why:
log.warning(why)
else:
save()
# Rename files
if config.setting["rename_files"] or config.setting["move_files"]:
new_filename = self._rename(old_filename, metadata)
# Move extra files (images, playlists, etc.)
if config.setting["move_files"] and config.setting["move_additional_files"]:
self._move_additional_files(old_filename, new_filename)
# Delete empty directories
if config.setting["delete_empty_dirs"]:
dirname = os.path.dirname(old_filename)
try:
self._rmdir(dirname)
head, tail = os.path.split(dirname)
if not tail:
head, tail = os.path.split(head)
while head and tail:
try:
self._rmdir(head)
except BaseException:
break
head, tail = os.path.split(head)
except EnvironmentError:
pass
# Save cover art images
if config.setting["save_images_to_files"]:
self._save_images(os.path.dirname(new_filename), metadata)
return new_filename
示例13: _coverart_downloaded
def _coverart_downloaded(self, coverartimage, data, http, error):
"""Handle finished download, save it to metadata"""
self.album._requests -= 1
if error:
self._coverart_http_error(http)
elif len(data) < 1000:
log.warning("Not enough data, skipping %s" % coverartimage)
else:
self._message(
N_("Cover art of type '%(type)s' downloaded for %(albumid)s from %(host)s"),
{
'type': ','.join(coverartimage.types),
'albumid': self.album.id,
'host': coverartimage.host
}
)
mime = mimetype.get_from_data(data, default="image/jpeg")
try:
self.metadata.make_and_add_image(
mime,
data,
types=coverartimage.types,
comment=coverartimage.comment,
is_front=coverartimage.is_front
)
for track in self.album._new_tracks:
track.metadata.make_and_add_image(
mime,
data,
types=coverartimage.types,
comment=coverartimage.comment,
is_front=coverartimage.is_front
)
# If the image already was a front image,
# there might still be some other non-CAA front
# images in the queue - ignore them.
if not self.front_image_found:
self.front_image_found = coverartimage.is_front_image()
except (IOError, OSError) as e:
self.album.error_append(e.message)
self.album._finalize_loading(error=True)
# It doesn't make sense to store/download more images if we can't
# save them in the temporary folder, abort.
return
self._download_next_in_queue()
示例14: load_plugin
def load_plugin(self, name, plugindir):
try:
info = imp.find_module(name, [plugindir])
except ImportError:
log.error("Failed loading plugin %r", name)
return None
plugin = None
try:
index = None
for i, p in enumerate(self.plugins):
if name == p.module_name:
log.warning("Module %r conflict: unregistering previously" \
" loaded %r version %s from %r",
p.module_name,
p.name,
p.version,
p.file)
_unregister_module_extensions(name)
index = i
break
plugin_module = imp.load_module(_PLUGIN_MODULE_PREFIX + name, *info)
plugin = PluginWrapper(plugin_module, plugindir, file=info[1])
versions = [version_from_string(v) for v in
list(plugin.api_versions)]
compatible_versions = list(set(versions) & self._api_versions)
if compatible_versions:
log.debug("Loading plugin %r version %s, compatible with API: %s",
plugin.name,
plugin.version,
", ".join([version_to_string(v, short=True) for v in
sorted(compatible_versions)]))
plugin.compatible = True
setattr(picard.plugins, name, plugin_module)
if index is not None:
self.plugins[index] = plugin
else:
self.plugins.append(plugin)
else:
log.warning("Plugin '%s' from '%s' is not compatible"
" with this version of Picard."
% (plugin.name, plugin.file))
except VersionError as e:
log.error("Plugin %r has an invalid API version string : %s", name, e)
except:
log.error("Plugin %r : %s", name, traceback.format_exc())
if info[0] is not None:
info[0].close()
return plugin
示例15: load_plugindir
def load_plugindir(self, plugindir):
plugindir = os.path.normpath(plugindir)
if not os.path.isdir(plugindir):
log.warning("Plugin directory %r doesn't exist", plugindir)
return
names = set()
for path in [os.path.join(plugindir, file) for file in os.listdir(plugindir)]:
name = _plugin_name_from_path(path)
if name:
names.add(name)
log.debug("Looking for plugins in directory %r, %d names found",
plugindir,
len(names))
for name in sorted(names):
self.load_plugin(name, plugindir)