| Server IP : 193.86.120.172 / Your IP : 216.73.216.67 Web Server : Apache/2.4.63 (Unix) System : Linux JServices 3.10.108 #86003 SMP Wed Oct 22 13:20:46 CST 2025 x86_64 User : kubec ( 1026) PHP Version : 8.2.28 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /volume1/@appstore/SynologyPhotos/sdk-plugin/ |
Upload File : |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2000 - present Synology Inc. All rights reserved.
import syslog
from argparse import ArgumentParser
from pathlib import Path
PACKAGE_NAME = "SynologyPhotos"
PACKAGE_PATH = "/var/packages/{}".format(PACKAGE_NAME)
APP_ID = "SYNO.Foto.AppInstance"
RESTART_FLAG_PATH = "{}/var/restart_flag".format(PACKAGE_PATH)
def log(msg):
syslog.syslog(syslog.LOG_ERR, str(msg))
class PluginRunner(object):
def __init__(self):
self._version = "1.0"
@property
def version(self):
return self._version
def pre(self):
pass
def post(self):
pass
def need_hevc(self):
pass
def need_h264(self):
pass
def need_vc1(self):
pass
def restart_package_service(self):
import subprocess
import time
subprocess.check_call(
["synosystemctl", "start", "pkg-SynologyPhotos-StopDaemon.target"]
)
for i in range(20): # sleep up to 20 * 3 = 60 seconds
time.sleep(3)
try:
subprocess.check_call(["/bin/systemctl", "status", "pkg-SynologyPhotos-task-center"])
except subprocess.CalledProcessError as e:
# https://man7.org/linux/man-pages/man1/systemctl.1.html - see 'EXIT STATUS'
if e.returncode == 3:
# task-center is not active
break
subprocess.check_call(["/var/packages/SynologyPhotos/target/usr/bin/synofoto-bin-reset-index-task"])
subprocess.check_call(
["synosystemctl", "start", "pkg-SynologyPhotos-StartDaemon.target"]
)
def send_command(self, command, args=None, binary=None):
self._assertIsAllowedCommand(command)
import subprocess
import json
if binary != None:
command_path = "{}/target/usr/bin/synofoto-bin-{}".format(
PACKAGE_PATH, binary
)
else:
command_path = "{}/target/usr/bin/synofoto-bin-sdk-plugin".format(
PACKAGE_PATH
)
arguments = [command_path, "--{}".format(command)]
if args != None:
args_str = json.dumps(args)
arguments.append(args_str)
subprocess.check_call(arguments)
def _assertIsAllowedCommand(self, command):
allowed_list = [
"group-delete",
"group-rename",
"group-membership-change",
"reload-app-priv",
"user-enable-change",
"user-add",
"user-delete",
"user-rename",
"share-delete",
"check-user-group",
"share-set",
"user-home-enable-change",
"share-enable",
"share-disable",
"set-user-info-expired",
"need-hevc",
"need-h264",
"need-vc1",
"refresh-dsm-user-group",
]
assert command in allowed_list, "command [{}] is not in allowed list".format(
command
)
def is_package_running(self):
import subprocess
res = subprocess.call(["synopkg", "status", "SynologyPhotos"])
return res == 0
def create_restart_flag(self):
Path(RESTART_FLAG_PATH).touch()
def check_restart_flag(self):
return Path(RESTART_FLAG_PATH).exists()
def remove_restart_flag(self):
Path(RESTART_FLAG_PATH).unlink()
def start_timer_service(self, service):
import subprocess
import time
systemd_service = "pkg-SynologyPhotos-{}.timer".format(service)
subprocess.check_call(
["synosystemctl", "start", systemd_service]
)
def MainBody(plugin_instance):
def print_package_info(key):
import subprocess
info = "{}/INFO".format(PACKAGE_PATH)
args = ["/bin/get_key_value", info, key]
output, error = subprocess.Popen(args).communicate()
print(output)
parser = ArgumentParser(description="{} SDK Hooks".format(PACKAGE_NAME))
parser.add_argument("--sdk-mod-ver", action="store_true")
parser.add_argument("--name", action="store_true")
parser.add_argument("--pkg-ver", action="store_true")
parser.add_argument("--vendor", action="store_true")
parser.add_argument("--pre", action="store_true")
parser.add_argument("--post", action="store_true")
parser.add_argument("--need-hevc", action="store_true")
parser.add_argument("--need-h264", action="store_true")
parser.add_argument("--need-vc1", action="store_true")
parser.add_argument("--app-id", action="store_true")
options = parser.parse_args()
if options.sdk_mod_ver:
print(plugin_instance.version)
elif options.name:
print_package_info("package")
elif options.pkg_ver:
print_package_info("version")
elif options.vendor:
print_package_info("maintainer")
elif options.pre:
plugin_instance.pre()
elif options.post:
plugin_instance.post()
elif options.need_hevc:
plugin_instance.need_hevc()
elif options.need_h264:
plugin_instance.need_h264()
elif options.need_vc1:
plugin_instance.need_vc1()
elif options.app_id:
print(APP_ID)