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:

Version: 4.0.6 

/ usr / lib / enigma2 / python / Plugins / Extensions / TestCockpit / Test10.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 deleteDirectory, createDirectory, writeFile
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.callbacks = 0
		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
		if self.source and self.destination:
			deleteDirectory(self.source + "/testdir5")
			deleteDirectory(self.destination + "/testdir5")
			createDirectory(self.destination + "/testdir5")
			createDirectory(self.source + "/testdir5/test11/test111")
			writeFile(self.source + "/testdir5/file1.ts", "test")
			writeFile(self.source + "/testdir5/test11/file11.ts", "test")
			writeFile(self.source + "/testdir5/test11/file12.ts", "test")
			writeFile(self.source + "/testdir5/test11/test111/file111.ts", "test")
			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.archive(self.source + "/testdir5", self.destination + "/testdir5", self.archiveCallback)

	def archiveCallback(self, _file_op, _path, _target_dir, error):
		self.callbacks += 1
		logger.info("error: %s, callbacks: %s", error, self.callbacks)
		if self.callbacks >= 4:
			DelayTimer(100, self.checkResult, error)

	def checkResult(self, error):
		success = error == 0
		success = success and (
			self.doesExist(self.destination + "/testdir5")
			and self.doesExist(self.destination + "/testdir5/test11")
			and self.doesExist(self.destination + "/testdir5/test11/test111")
			and self.doesExist(self.destination + "/testdir5/file1.ts")
			and self.doesExist(self.destination + "/testdir5/test11/file11.ts")
			and self.doesExist(self.destination + "/testdir5/test11/file12.ts")
			and self.doesExist(self.destination + "/testdir5/test11/test111/file111.ts")
		)
		success = success and (
			# self.doesNotExist(self.source + "/testdir5")
			self.doesNotExist(self.source + "/testdir5/test11")
			and self.doesNotExist(self.source + "/testdir5/test11/test111")
			and self.doesNotExist(self.source + "/testdir5/file1.ts")
			and self.doesNotExist(self.source + "/testdir5/test11/file11.ts")
			and self.doesNotExist(self.source + "/testdir5/test11/file12.ts")
			and self.doesNotExist(self.source + "/testdir5/test11/test111/file111.ts")
		)

		self.callback(self.index, success)