mirror of
https://github.com/fergalmoran/picard.git
synced 2026-03-01 02:54:01 +00:00
Get rid of USER_DOWNLOADS_DIR, save zipped module in user plugin directory
Suggested by @mineo.
This commit is contained in:
@@ -35,7 +35,6 @@ USER_DIR = os.path.join(
|
||||
)
|
||||
|
||||
USER_PLUGIN_DIR = os.path.join(USER_DIR, "plugins")
|
||||
USER_DOWNLOADS_DIR = os.path.join(USER_DIR, "downloads")
|
||||
|
||||
# AcoustID client API key
|
||||
ACOUSTID_KEY = 'tPrbdkhM'
|
||||
|
||||
@@ -306,7 +306,8 @@ class PluginManager(QtCore.QObject):
|
||||
module_file.close()
|
||||
return plugin
|
||||
|
||||
def install_plugin(self, path, overwrite_confirm=None):
|
||||
def install_plugin(self, path, overwrite_confirm=None, plugin_name=None,
|
||||
plugin_data=None):
|
||||
"""
|
||||
path is either:
|
||||
1) /some/dir/name.py
|
||||
@@ -314,11 +315,13 @@ class PluginManager(QtCore.QObject):
|
||||
3) /some/dir/name.zip (containing either 1 or 2)
|
||||
|
||||
"""
|
||||
zip_plugin = is_zip(path)
|
||||
if not zip_plugin:
|
||||
plugin_name = _plugin_name_from_path(path)
|
||||
else:
|
||||
plugin_name = os.path.splitext(zip_plugin)[0]
|
||||
zip_plugin = False
|
||||
if not plugin_name:
|
||||
zip_plugin = is_zip(path)
|
||||
if not zip_plugin:
|
||||
plugin_name = _plugin_name_from_path(path)
|
||||
else:
|
||||
plugin_name = os.path.splitext(zip_plugin)[0]
|
||||
if plugin_name:
|
||||
try:
|
||||
dirpath = os.path.join(USER_PLUGIN_DIR, plugin_name)
|
||||
@@ -343,7 +346,20 @@ class PluginManager(QtCore.QObject):
|
||||
for filepath in filepaths:
|
||||
os.remove(filepath)
|
||||
if not skip:
|
||||
if os.path.isfile(path):
|
||||
if plugin_data and plugin_name:
|
||||
# zipped module from download
|
||||
zip_plugin = plugin_name + '.zip'
|
||||
zippath = os.path.join(USER_PLUGIN_DIR, zip_plugin)
|
||||
try:
|
||||
with open(zippath, "wb") as zipfile:
|
||||
zipfile.write(plugin_data)
|
||||
except:
|
||||
try:
|
||||
os.remove(zippath)
|
||||
except:
|
||||
pass
|
||||
raise
|
||||
elif os.path.isfile(path):
|
||||
shutil.copy2(path, os.path.join(USER_PLUGIN_DIR,
|
||||
os.path.basename(path)))
|
||||
elif os.path.isdir(path):
|
||||
|
||||
@@ -28,7 +28,6 @@ from picard import config, log
|
||||
from picard.const import (
|
||||
USER_PLUGIN_DIR,
|
||||
PLUGINS_API,
|
||||
USER_DOWNLOADS_DIR,
|
||||
)
|
||||
from picard.plugin import PluginFlags
|
||||
from picard.util import encode_filename, webbrowser2
|
||||
@@ -180,7 +179,10 @@ class PluginsOptionsPage(OptionsPage):
|
||||
if files:
|
||||
files = map(unicode, files)
|
||||
for path in files:
|
||||
self.install_plugin(path)
|
||||
self.tagger.pluginmanager.install_plugin(
|
||||
path,
|
||||
overwrite_confirm=self.overwrite_confirm
|
||||
)
|
||||
|
||||
def overwrite_confirm(self, name):
|
||||
msgbox = QtGui.QMessageBox(self)
|
||||
@@ -190,10 +192,6 @@ class PluginsOptionsPage(OptionsPage):
|
||||
msgbox.setDefaultButton(QtGui.QMessageBox.No)
|
||||
return (msgbox.exec_() == QtGui.QMessageBox.Yes)
|
||||
|
||||
def install_plugin(self, path):
|
||||
self.tagger.pluginmanager.install_plugin(path,
|
||||
overwrite_confirm=self.overwrite_confirm)
|
||||
|
||||
def download_plugin(self):
|
||||
selected = self.ui.plugins.selectedItems()[0]
|
||||
plugin = self.items[selected]
|
||||
@@ -219,13 +217,12 @@ class PluginsOptionsPage(OptionsPage):
|
||||
log.error("Error occurred while trying to download the plugin: '%s'" % plugin.module_name)
|
||||
return
|
||||
|
||||
if not os.path.exists(USER_DOWNLOADS_DIR):
|
||||
os.makedirs(USER_DOWNLOADS_DIR)
|
||||
|
||||
zippath = os.path.join(USER_DOWNLOADS_DIR, plugin.module_name + ".zip")
|
||||
with open(zippath, "wb") as downloadzip:
|
||||
downloadzip.write(response)
|
||||
self.install_plugin(zippath)
|
||||
self.tagger.pluginmanager.install_plugin(
|
||||
None,
|
||||
overwrite_confirm=self.overwrite_confirm,
|
||||
plugin_name=plugin.module_name,
|
||||
plugin_data=response
|
||||
)
|
||||
|
||||
def open_plugin_dir(self):
|
||||
QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.loader % USER_PLUGIN_DIR, QtCore.QUrl.TolerantMode))
|
||||
|
||||
Reference in New Issue
Block a user