Repository URL to install this package:
#!/usr/bin/python
# coding=utf-8
#
# Copyright (C) 2018-2025 by dream-alpha
#
# In case of reuse of this source code please do not remove this copyright.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For more information on the GNU General Public License see:
# <http://www.gnu.org/licenses/>.
import os
from Plugins.SystemPlugins.CacheCockpit.FileManager import FileManager
from Plugins.SystemPlugins.MountCockpit.MountCockpit import MountCockpit
from .Debug import logger
from .FileUtils import createDirectory, deleteDirectory, writeFile
from .FileManagerUtils import FILE_OP_MOVE
from .FileChecks import FileChecks
from .DelayTimer import DelayTimer
class Test(FileChecks):
def __init__(self, _session):
logger.info("...")
FileChecks.__init__(self)
self.home_dir = MountCockpit.getInstance().getHomeDir("MVC")
mounted_bookmarks = MountCockpit.getInstance().getMountedBookmarks("MVC")
self.source = ""
if len(mounted_bookmarks) >= 2:
self.source = mounted_bookmarks[0]
self.destination = mounted_bookmarks[1]
self.file_manager = FileManager.getInstance("MVC")
def start(self, index, callback):
self.index = index
self.callback = callback
self.prepareTest1()
def prepareTest1(self):
logger.info("...")
if self.source:
deleteDirectory(os.path.dirname(self.source) + "/linkdir")
createDirectory(os.path.dirname(self.source) + "/linkdir/test1")
os.system("rm %s" % self.source + "/linkdir")
writeFile(os.path.dirname(self.source) + "/linkdir/test1/test11.ts", "test")
writeFile(os.path.dirname(self.source) + "/linkdir/test1/test12.ts", "test")
os.system("ln -s %s %s" % (os.path.dirname(self.source) + "/linkdir", self.source))
deleteDirectory(self.source + "/trashcan")
createDirectory(self.source + "/trashcan")
self.file_manager.clearDatabase()
self.file_manager.onDatabaseLoaded(self.databaseLoaded)
self.file_manager.loadDatabase()
else:
logger.error("only one bookmark available, skipping test...")
self.callback(self.index, True)
def databaseLoaded(self):
logger.info("...")
self.file_manager.execFileOp(FILE_OP_MOVE, self.source + "/linkdir/test1/test11.ts", self.source + "/trashcan/linkdir/test1", self.moveCallback)
def moveCallback(self, _file_op, _path, _target_dir, error):
logger.info("error: %s", error)
DelayTimer(100, self.checkResult, error)
def checkResult(self, error):
logger.info("checking > trashcan...")
success = error == 0
logger.debug("checking files that should exist...")
success = success and (
self.doesExist(self.source + "/trashcan/linkdir/test1/test11.ts")
and self.doesExist(self.source + "/trashcan/linkdir/test1")
)
logger.debug("checking file that should NOT exist...")
success = success and (
self.doesNotExist(self.source + "/linkdir/test1/test11.ts")
)
if success:
self.move2()
else:
self.callback(self.index, success)
def move2(self):
logger.info("...")
self.file_manager.execFileOp(FILE_OP_MOVE, self.source + "/trashcan/linkdir/test1/test11.ts", self.source + "/linkdir/test1", self.moveCallback2)
def moveCallback2(self, _file_op, _path, _target_dir, error):
logger.info("error: %s", error)
DelayTimer(100, self.checkResult2, error)
def checkResult2(self, error):
logger.info("checking < trashcan...")
success = error == 0
logger.debug("checking files that should exist...")
success = success and (
self.doesExist(self.source + "/linkdir/test1/test11.ts")
)
logger.debug("checking files that should NOT exist...")
success = success and (
self.doesNotExist(self.source + "/trashcan/linkdir/test1/test11.ts")
and self.doesNotExist(self.source + "/trashcan/test1")
)
self.callback(self.index, success)