Created
June 26, 2019 18:17
-
-
Save jstanley23/9dbb6fb546b136344f94a23b8d566807 to your computer and use it in GitHub Desktop.
Modified __init__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from ZenPacks.zenoss.ZenPackLib import zenpacklib | |
from Products.ZenModel.ZenPack import ZenPack as ZenPackBase | |
from Products.ZenUtils.Utils import unused, zenPath | |
CFG = zenpacklib.load_yaml([os.path.join(os.path.dirname(__file__), "zenpack.yaml")], verbose=False, level=30) | |
schema = CFG.zenpack_module.schema | |
class ZenPack(schema.ZenPackBase): | |
def install(self, app): | |
self.in_install = True | |
super(ZenPack, self).install(app) | |
self.installSymlinks() | |
def remove(self, app, leaveObjects=False): | |
if not leaveObjects: | |
self.in_remove = True | |
self.removeSymlinks() | |
super(ZenPack, self).remove(app, leaveObjects=leaveObjects) | |
self.in_remove = False | |
def _getScriptPaths(self): | |
"""Returns a list of source-destination tuples for all files""" | |
scriptDir = os.path.join(self.path(), "bin") | |
zenBinDir = zenPath("bin") | |
return [ | |
(os.path.join(scriptDir, f), os.path.join(zenBinDir, f)) | |
for f in os.listdir(scriptDir) | |
] | |
def installSymlinks(self): | |
"""Create symbolic links from a list of source-destination tuples""" | |
for src, dst in self._getScriptPaths(): | |
try: | |
os.symlink(src, dst) | |
except OSError: | |
pass | |
def removeSymlinks(self): | |
"""Remove symbolic links for a list of source-destination tuples""" | |
for src, dst in self._getScriptPaths(): | |
try: | |
os.unlink(dst) | |
except OSError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment