mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-24 00:26:08 +00:00
Drop PLUGIN_ACTION_UPDATE in plugin and simplify code
Since there are only 2 actions possible, install & update, use a bool
This commit is contained in:
@@ -40,7 +40,6 @@ from picard import (
|
||||
version_to_string,
|
||||
)
|
||||
from picard.const import (
|
||||
PLUGIN_ACTION_UPDATE,
|
||||
PLUGINS_API,
|
||||
USER_PLUGIN_DIR,
|
||||
)
|
||||
@@ -386,7 +385,7 @@ class PluginManager(QtCore.QObject):
|
||||
log.debug("Removing file %r", update)
|
||||
os.remove(update)
|
||||
|
||||
def install_plugin(self, path, action, overwrite_confirm=None, plugin_name=None,
|
||||
def install_plugin(self, path, update=False, overwrite_confirm=None, plugin_name=None,
|
||||
plugin_data=None):
|
||||
"""
|
||||
path is either:
|
||||
@@ -408,7 +407,7 @@ class PluginManager(QtCore.QObject):
|
||||
# zipped module from download
|
||||
zip_plugin = plugin_name + '.zip'
|
||||
dst = os.path.join(USER_PLUGIN_DIR, zip_plugin)
|
||||
if action == PLUGIN_ACTION_UPDATE:
|
||||
if update:
|
||||
dst += '.update'
|
||||
if os.path.isfile(dst):
|
||||
os.remove(dst)
|
||||
@@ -429,19 +428,19 @@ class PluginManager(QtCore.QObject):
|
||||
raise
|
||||
elif os.path.isfile(path):
|
||||
dst = os.path.join(USER_PLUGIN_DIR, os.path.basename(path))
|
||||
if action == PLUGIN_ACTION_UPDATE:
|
||||
if update:
|
||||
dst += '.update'
|
||||
if os.path.isfile(dst):
|
||||
os.remove(dst)
|
||||
shutil.copy2(path, dst)
|
||||
elif os.path.isdir(path):
|
||||
dst = os.path.join(USER_PLUGIN_DIR, plugin_name)
|
||||
if action == PLUGIN_ACTION_UPDATE:
|
||||
if update:
|
||||
dst += '.update'
|
||||
if os.path.isdir(dst):
|
||||
shutil.rmtree(dst)
|
||||
shutil.copytree(path, dst)
|
||||
if action != PLUGIN_ACTION_UPDATE:
|
||||
if not update:
|
||||
try:
|
||||
installed_plugin = self.load_plugin(zip_plugin or plugin_name, USER_PLUGIN_DIR)
|
||||
except Exception as e:
|
||||
|
||||
@@ -397,8 +397,11 @@ class PluginsOptionsPage(OptionsPage):
|
||||
version = plugin.version
|
||||
item.setText(COLUMN_VERSION, version)
|
||||
|
||||
def download_processor(action):
|
||||
self.download_plugin(item, action)
|
||||
def download_and_install():
|
||||
self.download_plugin(item)
|
||||
|
||||
def download_and_update():
|
||||
self.download_plugin(item, update=True)
|
||||
|
||||
def uninstall_processor():
|
||||
self.uninstall_plugin(item)
|
||||
@@ -429,7 +432,7 @@ class PluginsOptionsPage(OptionsPage):
|
||||
button.setEnabled(False)
|
||||
|
||||
if bt_action == PLUGIN_ACTION_INSTALL:
|
||||
button.released.connect(partial(download_processor, bt_action))
|
||||
button.released.connect(download_and_install)
|
||||
else:
|
||||
button.released.connect(uninstall_processor)
|
||||
|
||||
@@ -443,7 +446,7 @@ class PluginsOptionsPage(OptionsPage):
|
||||
if item.is_uninstalled or item.marked_for_update:
|
||||
button.setEnabled(False)
|
||||
|
||||
button.released.connect(partial(download_processor, PLUGIN_ACTION_UPDATE))
|
||||
button.released.connect(download_and_update)
|
||||
|
||||
self.ui.plugins.header().resizeSections(QtWidgets.QHeaderView.ResizeToContents)
|
||||
|
||||
@@ -490,23 +493,23 @@ class PluginsOptionsPage(OptionsPage):
|
||||
)
|
||||
if files:
|
||||
for path in files:
|
||||
self.manager.install_plugin(path, action=PLUGIN_ACTION_INSTALL)
|
||||
self.manager.install_plugin(path)
|
||||
|
||||
def download_plugin(self, item, action):
|
||||
def download_plugin(self, item, update=False):
|
||||
plugin = item.plugin
|
||||
|
||||
self.tagger.webservice.get(
|
||||
PLUGINS_API['host'],
|
||||
PLUGINS_API['port'],
|
||||
PLUGINS_API['endpoint']['download'],
|
||||
partial(self.download_handler, action, plugin=plugin),
|
||||
partial(self.download_handler, update, plugin=plugin),
|
||||
parse_response_type=None,
|
||||
priority=True,
|
||||
important=True,
|
||||
queryargs={"id": plugin.module_name}
|
||||
)
|
||||
|
||||
def download_handler(self, action, response, reply, error, plugin):
|
||||
def download_handler(self, update, response, reply, error, plugin):
|
||||
if error:
|
||||
msgbox = QtWidgets.QMessageBox(self)
|
||||
msgbox.setText(_("The plugin '%s' could not be downloaded.") % plugin.module_name)
|
||||
@@ -519,7 +522,7 @@ class PluginsOptionsPage(OptionsPage):
|
||||
|
||||
self.manager.install_plugin(
|
||||
None,
|
||||
action,
|
||||
update=update,
|
||||
plugin_name=plugin.module_name,
|
||||
plugin_data=response,
|
||||
)
|
||||
@@ -541,7 +544,7 @@ class PluginsOptionsPage(OptionsPage):
|
||||
|
||||
def dropEvent(self, event):
|
||||
for path in [os.path.normpath(u.toLocalFile()) for u in event.mimeData().urls()]:
|
||||
self.manager.install_plugin(path, action=PLUGIN_ACTION_INSTALL)
|
||||
self.manager.install_plugin(path)
|
||||
|
||||
|
||||
register_options_page(PluginsOptionsPage)
|
||||
|
||||
Reference in New Issue
Block a user