Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

dream-alpha / enigma2-plugin-extensions-testcockpit   deb

Repository URL to install this package:

/ usr / lib / enigma2 / python / Plugins / Extensions / TestCockpit / Test5.py

#!/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/>.


from Plugins.SystemPlugins.CacheCockpit.FileManager import FileManager
from Plugins.SystemPlugins.MountCockpit.MountCockpit import MountCockpit
from .Debug import logger
from .FileUtils import createDirectory, writeFile
from .FileManagerUtils import FILE_OP_DELETE, 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) >= 1:
			self.source = mounted_bookmarks[0]
		self.file_manager = FileManager.getInstance("MVC")

	def start(self, index, callback):
		self.index = index
		self.callback = callback
		self.file_manager.execFileOp(FILE_OP_DELETE, self.source + "/test5", None, self.prepareTest1)

	def prepareTest1(self, *__):
		self.file_manager.execFileOp(FILE_OP_DELETE, self.source + "/test6", None, self.prepareTest2)

	def prepareTest2(self, *__):
		if self.source:
			writeFile(self.source + "/testfile.ts", "test")
			createDirectory(self.source + "/test5/test11/test111")
			writeFile(self.source + "/test5/file1.ts", "test")
			writeFile(self.source + "/test5/test11/file11.ts", "test")
			writeFile(self.source + "/test5/test11/file12.ts", "test")
			writeFile(self.source + "/test5/test11/test111/file111.ts", "test")
			self.file_manager.clearDatabase()
			self.file_manager.onDatabaseLoaded(self.databaseLoaded)
			self.file_manager.loadDatabase()
		else:
			self.callback(self.index, False)

	def databaseLoaded(self):
		logger.info("...")
		self.file_manager.execFileOp(FILE_OP_MOVE, self.source + "/test5", self.source + "/test6", self.moveCallback)

	def moveCallback(self, _file_op, _path, _target_dir, error):
		logger.info("error: %s", error)
		DelayTimer(1000, self.checkResult, error)

	def checkResult(self, error):
		success = error == 0
		success = success and (
			self.doesExist(self.source + "/test6/test5")
			and self.doesExist(self.source + "/test6/test5/test11")
			and self.doesExist(self.source + "/test6/test5/test11/test111")
			and self.doesExist(self.source + "/test6/test5/file1.ts")
			and self.doesExist(self.source + "/test6/test5/test11/file11.ts")
			and self.doesExist(self.source + "/test6/test5/test11/file12.ts")
			and self.doesExist(self.source + "/test6/test5/test11/test111/file111.ts")
		)
		success = success and (
			self.doesNotExist(self.source + "/test5")
			and self.doesNotExist(self.source + "/test5/test11")
			and self.doesNotExist(self.source + "/test5/test11/test111")
			and self.doesNotExist(self.source + "/test5/file1.ts")
			and self.doesNotExist(self.source + "/test5/test11/file11.ts")
			and self.doesNotExist(self.source + "/test5/test11/file12.ts")
			and self.doesNotExist(self.source + "/test5/test11/test111/file111.ts")
		)
		if success:
			self.file_manager.execFileOp(FILE_OP_MOVE, self.source + "/testfile.ts", self.source + "/test7", self.moveCallback2)
		else:
			self.callback(self.index, success)

	def moveCallback2(self, _file_op, _path, _target_dir, error):
		logger.info("error: %s", error)
		DelayTimer(1000, self.checkResult2, error)

	def checkResult2(self, error):
		logger.info("error: %s", error)
		success = error == 0
		success = success and (
			self.doesExist(self.source + "/test7")
			and self.doesExist(self.source + "/test7/testfile.ts")
			and self.doesNotExist(self.source + "/testfile.ts")
		)
		self.callback(self.index, success)