Remove hard-coded directory path from plugins

This commit is contained in:
shortcutme 2019-08-02 16:05:19 +02:00
parent 1eb97ea381
commit 3e97c154a0
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
8 changed files with 39 additions and 17 deletions

View file

@ -2,6 +2,7 @@ import time
import re import re
import html import html
import hashlib import hashlib
import os
from Plugin import PluginManager from Plugin import PluginManager
from Translate import Translate from Translate import Translate
@ -10,8 +11,10 @@ from Config import config
from .ContentFilterStorage import ContentFilterStorage from .ContentFilterStorage import ContentFilterStorage
plugin_dir = os.path.dirname(__file__)
if "_" not in locals(): if "_" not in locals():
_ = Translate("plugins/ContentFilter/languages/") _ = Translate(plugin_dir + "/languages/")
@PluginManager.registerTo("SiteManager") @PluginManager.registerTo("SiteManager")
@ -210,7 +213,7 @@ class UiRequestPlugin(object):
def actionUiMedia(self, path, *args, **kwargs): def actionUiMedia(self, path, *args, **kwargs):
if path.startswith("/uimedia/plugins/contentfilter/"): if path.startswith("/uimedia/plugins/contentfilter/"):
file_path = path.replace("/uimedia/plugins/contentfilter/", "plugins/ContentFilter/media/") file_path = path.replace("/uimedia/plugins/contentfilter/", plugin_dir + "/media/")
return self.actionFile(file_path) return self.actionFile(file_path)
else: else:
return super(UiRequestPlugin, self).actionUiMedia(path) return super(UiRequestPlugin, self).actionUiMedia(path)

View file

@ -1,11 +1,16 @@
import re import re
import html import html
import copy import copy
import os
from Plugin import PluginManager from Plugin import PluginManager
from Translate import Translate from Translate import Translate
plugin_dir = os.path.dirname(__file__)
if "_" not in locals(): if "_" not in locals():
_ = Translate("plugins/Cors/languages/") _ = Translate(plugin_dir + "/languages/")
def getCorsPath(site, inner_path): def getCorsPath(site, inner_path):

View file

@ -1,6 +1,7 @@
import re import re
import time import time
import copy import copy
import os
from Plugin import PluginManager from Plugin import PluginManager
from Translate import Translate from Translate import Translate
@ -18,8 +19,11 @@ if "merger_db" not in locals().keys(): # To keep merger_sites between module re
merged_to_merger = {} # {address: [site1, site2, ...]} cache merged_to_merger = {} # {address: [site1, site2, ...]} cache
site_manager = None # Site manager for merger sites site_manager = None # Site manager for merger sites
plugin_dir = os.path.dirname(__file__)
if "_" not in locals(): if "_" not in locals():
_ = Translate("plugins/MergerSite/languages/") _ = Translate(plugin_dir + "/languages/")
# Check if the site has permission to this merger site # Check if the site has permission to this merger site
@ -221,7 +225,7 @@ class UiWebsocketPlugin(object):
site = self.server.sites.get(address) site = self.server.sites.get(address)
try: try:
merged_sites.append(site.content_manager.contents.get("content.json").get("title", address)) merged_sites.append(site.content_manager.contents.get("content.json").get("title", address))
except Exception as err: except Exception:
merged_sites.append(address) merged_sites.append(address)
details = _["Read and write permissions to sites with merged type of <b>%s</b> "] % merger_type details = _["Read and write permissions to sites with merged type of <b>%s</b> "] % merger_type

View file

@ -1,6 +1,7 @@
import re import re
import time import time
import html import html
import os
import gevent import gevent
@ -9,8 +10,11 @@ from Config import config
from util import helper from util import helper
from Translate import Translate from Translate import Translate
plugin_dir = os.path.dirname(__file__)
if "_" not in locals(): if "_" not in locals():
_ = Translate("plugins/OptionalManager/languages/") _ = Translate(plugin_dir + "/languages/")
bigfile_sha512_cache = {} bigfile_sha512_cache = {}
@ -285,7 +289,7 @@ class UiWebsocketPlugin(object):
def actionOptionalLimitSet(self, to, limit): def actionOptionalLimitSet(self, to, limit):
if "ADMIN" not in self.site.settings["permissions"]: if "ADMIN" not in self.site.settings["permissions"]:
return self.response(to, {"error": "Forbidden"}) return self.response(to, {"error": "Forbidden"})
config.optional_limit = re.sub("\.0+$", "", limit) # Remove unnecessary digits from end config.optional_limit = re.sub(r"\.0+$", "", limit) # Remove unnecessary digits from end
config.saveValue("optional_limit", limit) config.saveValue("optional_limit", limit)
self.response(to, "ok") self.response(to, "ok")

View file

@ -18,9 +18,8 @@ from Translate import Translate
from util import helper from util import helper
from .ZipStream import ZipStream from .ZipStream import ZipStream
plugin_dir = "plugins/Sidebar" plugin_dir = os.path.dirname(__file__)
media_dir = plugin_dir + "/media" media_dir = plugin_dir + "/media"
sys.path.append(plugin_dir) # To able to load geoip lib
loc_cache = {} loc_cache = {}
if "_" not in locals(): if "_" not in locals():

View file

@ -8,8 +8,11 @@ from Translate import Translate
allow_reload = False # No source reload supported in this plugin allow_reload = False # No source reload supported in this plugin
plugin_dir = os.path.dirname(__file__)
if "_" not in locals(): if "_" not in locals():
_ = Translate("plugins/Trayicon/languages/") _ = Translate(plugin_dir + "/languages/")
@PluginManager.registerTo("Actions") @PluginManager.registerTo("Actions")
@ -23,8 +26,6 @@ class ActionsPlugin(object):
self.main = main self.main = main
fs_encoding = sys.getfilesystemencoding()
icon = notificationicon.NotificationIcon( icon = notificationicon.NotificationIcon(
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'trayicon.ico'), os.path.join(os.path.dirname(os.path.abspath(__file__)), 'trayicon.ico'),
"ZeroNet %s" % config.version "ZeroNet %s" % config.version

View file

@ -1,12 +1,15 @@
import io import io
import os
from Plugin import PluginManager from Plugin import PluginManager
from Config import config from Config import config
from Translate import Translate from Translate import Translate
plugin_dir = os.path.dirname(__file__)
if "_" not in locals(): if "_" not in locals():
_ = Translate("plugins/UiConfig/languages/") _ = Translate(plugin_dir + "/languages/")
@PluginManager.afterLoad @PluginManager.afterLoad
@ -35,7 +38,7 @@ class UiRequestPlugin(object):
def actionUiMedia(self, path, *args, **kwargs): def actionUiMedia(self, path, *args, **kwargs):
if path.startswith("/uimedia/plugins/uiconfig/"): if path.startswith("/uimedia/plugins/uiconfig/"):
file_path = path.replace("/uimedia/plugins/uiconfig/", "plugins/UiConfig/media/") file_path = path.replace("/uimedia/plugins/uiconfig/", plugin_dir + "/media/")
if config.debug and (file_path.endswith("all.js") or file_path.endswith("all.css")): if config.debug and (file_path.endswith("all.js") or file_path.endswith("all.css")):
# If debugging merge *.css to all.css and *.js to all.js # If debugging merge *.css to all.css and *.js to all.js
from Debug import DebugMedia from Debug import DebugMedia

View file

@ -3,12 +3,15 @@ import random
import time import time
import json import json
import re import re
import os
from Config import config from Config import config
from Plugin import PluginManager from Plugin import PluginManager
from util import helper from util import helper
plugin_dir = os.path.dirname(__file__)
if "sessions" not in locals().keys(): # To keep sessions between module reloads if "sessions" not in locals().keys(): # To keep sessions between module reloads
sessions = {} sessions = {}
@ -21,6 +24,7 @@ def showPasswordAdvice(password):
error_msgs.append("You are using a very short UI password!") error_msgs.append("You are using a very short UI password!")
return error_msgs return error_msgs
@PluginManager.registerTo("UiRequest") @PluginManager.registerTo("UiRequest")
class UiRequestPlugin(object): class UiRequestPlugin(object):
sessions = sessions sessions = sessions
@ -45,7 +49,7 @@ class UiRequestPlugin(object):
# Action: Login # Action: Login
@helper.encodeResponse @helper.encodeResponse
def actionLogin(self): def actionLogin(self):
template = open("plugins/UiPassword/login.html").read() template = open(plugin_dir + "/login.html").read()
self.sendHeader() self.sendHeader()
posted = self.getPosted() posted = self.getPosted()
if posted: # Validate http posted data if posted: # Validate http posted data
@ -108,7 +112,6 @@ class UiRequestPlugin(object):
yield "Error: Invalid session id" yield "Error: Invalid session id"
@PluginManager.registerTo("ConfigPlugin") @PluginManager.registerTo("ConfigPlugin")
class ConfigPlugin(object): class ConfigPlugin(object):
def createArguments(self): def createArguments(self):