Skip to content

Commit

Permalink
Remove hard-coded directory path from plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Aug 2, 2019
1 parent 1eb97ea commit 3e97c15
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 17 deletions.
7 changes: 5 additions & 2 deletions plugins/ContentFilter/ContentFilterPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import html
import hashlib
import os

from Plugin import PluginManager
from Translate import Translate
Expand All @@ -10,8 +11,10 @@
from .ContentFilterStorage import ContentFilterStorage


plugin_dir = os.path.dirname(__file__)

if "_" not in locals():
_ = Translate("plugins/ContentFilter/languages/")
_ = Translate(plugin_dir + "/languages/")


@PluginManager.registerTo("SiteManager")
Expand Down Expand Up @@ -210,7 +213,7 @@ def actionWrapper(self, path, extra_headers=None):

def actionUiMedia(self, path, *args, **kwargs):
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)
else:
return super(UiRequestPlugin, self).actionUiMedia(path)
7 changes: 6 additions & 1 deletion plugins/Cors/CorsPlugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import re
import html
import copy
import os

from Plugin import PluginManager
from Translate import Translate


plugin_dir = os.path.dirname(__file__)

if "_" not in locals():
_ = Translate("plugins/Cors/languages/")
_ = Translate(plugin_dir + "/languages/")


def getCorsPath(site, inner_path):
Expand Down
8 changes: 6 additions & 2 deletions plugins/MergerSite/MergerSitePlugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import time
import copy
import os

from Plugin import PluginManager
from Translate import Translate
Expand All @@ -18,8 +19,11 @@
merged_to_merger = {} # {address: [site1, site2, ...]} cache
site_manager = None # Site manager for merger sites


plugin_dir = os.path.dirname(__file__)

if "_" not in locals():
_ = Translate("plugins/MergerSite/languages/")
_ = Translate(plugin_dir + "/languages/")


# Check if the site has permission to this merger site
Expand Down Expand Up @@ -221,7 +225,7 @@ def actionPermissionDetails(self, to, permission):
site = self.server.sites.get(address)
try:
merged_sites.append(site.content_manager.contents.get("content.json").get("title", address))
except Exception as err:
except Exception:
merged_sites.append(address)

details = _["Read and write permissions to sites with merged type of <b>%s</b> "] % merger_type
Expand Down
8 changes: 6 additions & 2 deletions plugins/OptionalManager/UiWebsocketPlugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import time
import html
import os

import gevent

Expand All @@ -9,8 +10,11 @@
from util import helper
from Translate import Translate


plugin_dir = os.path.dirname(__file__)

if "_" not in locals():
_ = Translate("plugins/OptionalManager/languages/")
_ = Translate(plugin_dir + "/languages/")

bigfile_sha512_cache = {}

Expand Down Expand Up @@ -285,7 +289,7 @@ def actionOptionalLimitStats(self, to):
def actionOptionalLimitSet(self, to, limit):
if "ADMIN" not in self.site.settings["permissions"]:
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)
self.response(to, "ok")

Expand Down
3 changes: 1 addition & 2 deletions plugins/Sidebar/SidebarPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
from util import helper
from .ZipStream import ZipStream

plugin_dir = "plugins/Sidebar"
plugin_dir = os.path.dirname(__file__)
media_dir = plugin_dir + "/media"
sys.path.append(plugin_dir) # To able to load geoip lib

loc_cache = {}
if "_" not in locals():
Expand Down
7 changes: 4 additions & 3 deletions plugins/Trayicon/TrayiconPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

allow_reload = False # No source reload supported in this plugin


plugin_dir = os.path.dirname(__file__)

if "_" not in locals():
_ = Translate("plugins/Trayicon/languages/")
_ = Translate(plugin_dir + "/languages/")


@PluginManager.registerTo("Actions")
Expand All @@ -23,8 +26,6 @@ def main(self):

self.main = main

fs_encoding = sys.getfilesystemencoding()

icon = notificationicon.NotificationIcon(
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'trayicon.ico'),
"ZeroNet %s" % config.version
Expand Down
7 changes: 5 additions & 2 deletions plugins/UiConfig/UiConfigPlugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import io
import os

from Plugin import PluginManager
from Config import config
from Translate import Translate


plugin_dir = os.path.dirname(__file__)

if "_" not in locals():
_ = Translate("plugins/UiConfig/languages/")
_ = Translate(plugin_dir + "/languages/")


@PluginManager.afterLoad
Expand Down Expand Up @@ -35,7 +38,7 @@ def actionWrapper(self, path, extra_headers=None):

def actionUiMedia(self, path, *args, **kwargs):
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 debugging merge *.css to all.css and *.js to all.js
from Debug import DebugMedia
Expand Down
9 changes: 6 additions & 3 deletions plugins/disabled-UiPassword/UiPasswordPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import time
import json
import re

import os

from Config import config
from Plugin import PluginManager
from util import helper


plugin_dir = os.path.dirname(__file__)

if "sessions" not in locals().keys(): # To keep sessions between module reloads
sessions = {}

Expand All @@ -21,6 +24,7 @@ def showPasswordAdvice(password):
error_msgs.append("You are using a very short UI password!")
return error_msgs


@PluginManager.registerTo("UiRequest")
class UiRequestPlugin(object):
sessions = sessions
Expand All @@ -45,7 +49,7 @@ def route(self, path):
# Action: Login
@helper.encodeResponse
def actionLogin(self):
template = open("plugins/UiPassword/login.html").read()
template = open(plugin_dir + "/login.html").read()
self.sendHeader()
posted = self.getPosted()
if posted: # Validate http posted data
Expand Down Expand Up @@ -108,7 +112,6 @@ def actionLogout(self):
yield "Error: Invalid session id"



@PluginManager.registerTo("ConfigPlugin")
class ConfigPlugin(object):
def createArguments(self):
Expand Down

0 comments on commit 3e97c15

Please sign in to comment.