File: /volume1/@appstore/SynologyPhotos/sdk-plugin/synology_foto_share_transform.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2000 - present Synology Inc. All rights reserved.
from os import environ
from importlib.util import spec_from_file_location, module_from_spec
module_name = "common"
module_path = "/var/packages/SynologyPhotos/target/sdk-plugin/common.py"
spec = spec_from_file_location(module_name, module_path)
common = module_from_spec(spec)
spec.loader.exec_module(common)
def is_tiering_transform():
orig_type = environ.get("ORIG_TYPE")
new_type = environ.get("NEW_TYPE")
if orig_type == "normal" and new_type == "tiering":
return True
if orig_type == "tiering" and new_type == "normal":
return True
return False
class ShareTransform(common.PluginRunner):
def __init__(self):
self._version = "2.0"
def pre(self):
if not is_tiering_transform():
return None
share_name = environ.get("SHARE_NAME")
share_path = environ.get("SHARE_PATH")
is_package_running = self.is_package_running()
if not is_package_running:
return None
self.send_command(
"share-disable",
{
"origin_name": "",
"origin_path": "",
"name": share_name,
"path": share_path,
},
)
def post(self):
if not is_tiering_transform():
return None
share_name = environ.get("SHARE_NAME")
share_path = environ.get("SHARE_PATH")
is_package_running = self.is_package_running()
if not is_package_running:
return None
self.send_command(
"share-enable",
{
"origin_name": "",
"origin_path": "",
"name": share_name,
"path": share_path,
},
)
common.MainBody(ShareTransform())