diff --git a/3rdparty/composer/ClassLoader.php b/3rdparty/composer/ClassLoader.php index a72151c..7824d8f 100644 --- a/3rdparty/composer/ClassLoader.php +++ b/3rdparty/composer/ClassLoader.php @@ -45,35 +45,34 @@ class ClassLoader /** @var \Closure(string):void */ private static $includeFile; - /** @var ?string */ + /** @var string|null */ private $vendorDir; // PSR-4 /** - * @var array[] - * @psalm-var array> + * @var array> */ private $prefixLengthsPsr4 = array(); /** - * @var array[] - * @psalm-var array> + * @var array> */ private $prefixDirsPsr4 = array(); /** - * @var array[] - * @psalm-var array + * @var list */ private $fallbackDirsPsr4 = array(); // PSR-0 /** - * @var array[] - * @psalm-var array> + * List of PSR-0 prefixes + * + * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2'))) + * + * @var array>> */ private $prefixesPsr0 = array(); /** - * @var array[] - * @psalm-var array + * @var list */ private $fallbackDirsPsr0 = array(); @@ -81,8 +80,7 @@ class ClassLoader private $useIncludePath = false; /** - * @var string[] - * @psalm-var array + * @var array */ private $classMap = array(); @@ -90,21 +88,20 @@ class ClassLoader private $classMapAuthoritative = false; /** - * @var bool[] - * @psalm-var array + * @var array */ private $missingClasses = array(); - /** @var ?string */ + /** @var string|null */ private $apcuPrefix; /** - * @var self[] + * @var array */ private static $registeredLoaders = array(); /** - * @param ?string $vendorDir + * @param string|null $vendorDir */ public function __construct($vendorDir = null) { @@ -113,7 +110,7 @@ public function __construct($vendorDir = null) } /** - * @return string[] + * @return array> */ public function getPrefixes() { @@ -125,8 +122,7 @@ public function getPrefixes() } /** - * @return array[] - * @psalm-return array> + * @return array> */ public function getPrefixesPsr4() { @@ -134,8 +130,7 @@ public function getPrefixesPsr4() } /** - * @return array[] - * @psalm-return array + * @return list */ public function getFallbackDirs() { @@ -143,8 +138,7 @@ public function getFallbackDirs() } /** - * @return array[] - * @psalm-return array + * @return list */ public function getFallbackDirsPsr4() { @@ -152,8 +146,7 @@ public function getFallbackDirsPsr4() } /** - * @return string[] Array of classname => path - * @psalm-return array + * @return array Array of classname => path */ public function getClassMap() { @@ -161,8 +154,7 @@ public function getClassMap() } /** - * @param string[] $classMap Class to filename map - * @psalm-param array $classMap + * @param array $classMap Class to filename map * * @return void */ @@ -179,24 +171,25 @@ public function addClassMap(array $classMap) * Registers a set of PSR-0 directories for a given prefix, either * appending or prepending to the ones previously set for this prefix. * - * @param string $prefix The prefix - * @param string[]|string $paths The PSR-0 root directories - * @param bool $prepend Whether to prepend the directories + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories * * @return void */ public function add($prefix, $paths, $prepend = false) { + $paths = (array) $paths; if (!$prefix) { if ($prepend) { $this->fallbackDirsPsr0 = array_merge( - (array) $paths, + $paths, $this->fallbackDirsPsr0 ); } else { $this->fallbackDirsPsr0 = array_merge( $this->fallbackDirsPsr0, - (array) $paths + $paths ); } @@ -205,19 +198,19 @@ public function add($prefix, $paths, $prepend = false) $first = $prefix[0]; if (!isset($this->prefixesPsr0[$first][$prefix])) { - $this->prefixesPsr0[$first][$prefix] = (array) $paths; + $this->prefixesPsr0[$first][$prefix] = $paths; return; } if ($prepend) { $this->prefixesPsr0[$first][$prefix] = array_merge( - (array) $paths, + $paths, $this->prefixesPsr0[$first][$prefix] ); } else { $this->prefixesPsr0[$first][$prefix] = array_merge( $this->prefixesPsr0[$first][$prefix], - (array) $paths + $paths ); } } @@ -226,9 +219,9 @@ public function add($prefix, $paths, $prepend = false) * Registers a set of PSR-4 directories for a given namespace, either * appending or prepending to the ones previously set for this namespace. * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param string[]|string $paths The PSR-4 base directories - * @param bool $prepend Whether to prepend the directories + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories * * @throws \InvalidArgumentException * @@ -236,17 +229,18 @@ public function add($prefix, $paths, $prepend = false) */ public function addPsr4($prefix, $paths, $prepend = false) { + $paths = (array) $paths; if (!$prefix) { // Register directories for the root namespace. if ($prepend) { $this->fallbackDirsPsr4 = array_merge( - (array) $paths, + $paths, $this->fallbackDirsPsr4 ); } else { $this->fallbackDirsPsr4 = array_merge( $this->fallbackDirsPsr4, - (array) $paths + $paths ); } } elseif (!isset($this->prefixDirsPsr4[$prefix])) { @@ -256,18 +250,18 @@ public function addPsr4($prefix, $paths, $prepend = false) throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; + $this->prefixDirsPsr4[$prefix] = $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( - (array) $paths, + $paths, $this->prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( $this->prefixDirsPsr4[$prefix], - (array) $paths + $paths ); } } @@ -276,8 +270,8 @@ public function addPsr4($prefix, $paths, $prepend = false) * Registers a set of PSR-0 directories for a given prefix, * replacing any others previously set for this prefix. * - * @param string $prefix The prefix - * @param string[]|string $paths The PSR-0 base directories + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 base directories * * @return void */ @@ -294,8 +288,8 @@ public function set($prefix, $paths) * Registers a set of PSR-4 directories for a given namespace, * replacing any others previously set for this namespace. * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param string[]|string $paths The PSR-4 base directories + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories * * @throws \InvalidArgumentException * @@ -481,9 +475,9 @@ public function findFile($class) } /** - * Returns the currently registered loaders indexed by their corresponding vendor directories. + * Returns the currently registered loaders keyed by their corresponding vendor directories. * - * @return self[] + * @return array */ public static function getRegisteredLoaders() { diff --git a/3rdparty/composer/InstalledVersions.php b/3rdparty/composer/InstalledVersions.php index c6b54af..51e734a 100644 --- a/3rdparty/composer/InstalledVersions.php +++ b/3rdparty/composer/InstalledVersions.php @@ -98,7 +98,7 @@ public static function isInstalled($packageName, $includeDevRequirements = true) { foreach (self::getInstalled() as $installed) { if (isset($installed['versions'][$packageName])) { - return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); + return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false; } } @@ -119,7 +119,7 @@ public static function isInstalled($packageName, $includeDevRequirements = true) */ public static function satisfies(VersionParser $parser, $packageName, $constraint) { - $constraint = $parser->parseConstraints($constraint); + $constraint = $parser->parseConstraints((string) $constraint); $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); return $provided->matches($constraint); @@ -328,7 +328,9 @@ private static function getInstalled() if (isset(self::$installedByVendor[$vendorDir])) { $installed[] = self::$installedByVendor[$vendorDir]; } elseif (is_file($vendorDir.'/composer/installed.php')) { - $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require $vendorDir.'/composer/installed.php'; + $installed[] = self::$installedByVendor[$vendorDir] = $required; if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { self::$installed = $installed[count($installed) - 1]; } @@ -340,12 +342,17 @@ private static function getInstalled() // only require the installed.php file if this file is loaded from its dumped location, // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 if (substr(__DIR__, -8, 1) !== 'C') { - self::$installed = require __DIR__ . '/installed.php'; + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require __DIR__ . '/installed.php'; + self::$installed = $required; } else { self::$installed = array(); } } - $installed[] = self::$installed; + + if (self::$installed !== array()) { + $installed[] = self::$installed; + } return $installed; } diff --git a/3rdparty/composer/installed.json b/3rdparty/composer/installed.json index 4cfe4d7..8a07d3a 100644 --- a/3rdparty/composer/installed.json +++ b/3rdparty/composer/installed.json @@ -2,20 +2,20 @@ "packages": [ { "name": "tomitomas/jeedom-tools", - "version": "0.3", - "version_normalized": "0.3.0.0", + "version": "0.8.0", + "version_normalized": "0.8.0.0", "source": { "type": "git", "url": "https://github.com/tomitomas/jeedom-tools.git", - "reference": "8f7d4fe048313088f9105c3814f5148bb9fd0e8d" + "reference": "d07ff69ffbf2c5c92bed7e4d2c3d16a142322d11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tomitomas/jeedom-tools/zipball/8f7d4fe048313088f9105c3814f5148bb9fd0e8d", - "reference": "8f7d4fe048313088f9105c3814f5148bb9fd0e8d", + "url": "https://api.github.com/repos/tomitomas/jeedom-tools/zipball/d07ff69ffbf2c5c92bed7e4d2c3d16a142322d11", + "reference": "d07ff69ffbf2c5c92bed7e4d2c3d16a142322d11", "shasum": "" }, - "time": "2023-02-04T22:06:19+00:00", + "time": "2024-09-04T15:47:28+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -35,7 +35,7 @@ "description": "Generic lib for jeedom plugins", "support": { "issues": "https://github.com/tomitomas/jeedom-tools/issues", - "source": "https://github.com/tomitomas/jeedom-tools/tree/0.3" + "source": "https://github.com/tomitomas/jeedom-tools/tree/0.8.0" }, "install-path": "../tomitomas/jeedom-tools" } diff --git a/3rdparty/composer/installed.php b/3rdparty/composer/installed.php index 5fd8400..ccf53d7 100644 --- a/3rdparty/composer/installed.php +++ b/3rdparty/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'tomitomas/plugin-mybin', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '582673e836635da7c4e75aeb49d8a1ecd0ae1a9c', + 'reference' => 'c93ee6a0f1a224cf07d0e6df1c30bb965322e570', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -11,9 +11,9 @@ ), 'versions' => array( 'tomitomas/jeedom-tools' => array( - 'pretty_version' => '0.3', - 'version' => '0.3.0.0', - 'reference' => '8f7d4fe048313088f9105c3814f5148bb9fd0e8d', + 'pretty_version' => '0.8.0', + 'version' => '0.8.0.0', + 'reference' => 'd07ff69ffbf2c5c92bed7e4d2c3d16a142322d11', 'type' => 'library', 'install_path' => __DIR__ . '/../tomitomas/jeedom-tools', 'aliases' => array(), @@ -22,7 +22,7 @@ 'tomitomas/plugin-mybin' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '582673e836635da7c4e75aeb49d8a1ecd0ae1a9c', + 'reference' => 'c93ee6a0f1a224cf07d0e6df1c30bb965322e570', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/3rdparty/tomitomas/jeedom-tools/src/tomitomasEqLogicTrait.php b/3rdparty/tomitomas/jeedom-tools/src/tomitomasEqLogicTrait.php index a09a909..b64788d 100644 --- a/3rdparty/tomitomas/jeedom-tools/src/tomitomasEqLogicTrait.php +++ b/3rdparty/tomitomas/jeedom-tools/src/tomitomasEqLogicTrait.php @@ -2,12 +2,29 @@ trait tomitomasEqLogicTrait { - public function createCommands(string $file, string $type) { - $configFile = self::getFileContent($file); - $dict = $configFile['dictionary']; + public static function getConfigFileContent($filePath) { + if (!file_exists($filePath)) { + throw new Exception(__("Fichier de configuration non trouvé", __FILE__) . ' ' . $filePath); + } + $content = file_get_contents($filePath); + if (!is_json($content)) { + throw new Exception(__("Fichier de configuration incorrecte", __FILE__) . ' ' . $filePath); + } + $content = translate::exec($content, realpath($filePath)); + return json_decode($content, true); + } + + public function createCommands($filePath, $type = null) { try { - if (isset($configFile['cmds'][$type])) { - $this->createCommandsFromConfigFile($configFile['cmds'][$type], $dict); + + // on traduit le fichier de configuration + $configFile = self::getConfigFileContent($filePath); + + // on lance la création des commandes (déjà traduites) + if ($type == null) { + $this->createCommandsFromConfig($configFile['cmds']); + } elseif (isset($configFile['cmds'][$type])) { + $this->createCommandsFromConfig($configFile['cmds'][$type]); } else { self::error($type . ' not found in config'); } @@ -32,7 +49,7 @@ public static function getFileContent($path) { return $content; } - public function createCommandsFromConfigFile($commands, $dict) { + public function createCommandsFromConfig($commands) { $cmd_updated_by = array(); foreach ($commands as $cmdData) { $cmd = $this->getCmd(null, $cmdData["logicalId"]); @@ -63,18 +80,6 @@ public function createCommandsFromConfigFile($commands, $dict) { if (isset($cmdData["order"])) { $cmd->setOrder($cmdData["order"]); } - - if (isset($cmdData['display'])) { - foreach ($cmdData['display'] as $key => $value) { - $cmd->setDisplay($key, $value); - } - } - - if (isset($cmdData['template'])) { - foreach ($cmdData['template'] as $key => $value) { - $cmd->setTemplate($key, $value); - } - } } $cmd->setName(__($cmdData["name"], __FILE__)); @@ -84,14 +89,22 @@ public function createCommandsFromConfigFile($commands, $dict) { if (isset($cmdData['configuration'])) { foreach ($cmdData['configuration'] as $key => $value) { - if ($key == 'listValueToCreate') { - $key = 'listValue'; - $value = self::createListOption(explode(";", $value), $dict); - } $cmd->setConfiguration($key, $value); } } + if (isset($cmdData['display'])) { + foreach ($cmdData['display'] as $key => $value) { + $cmd->setDisplay($key, $value); + } + } + + if (isset($cmdData['template'])) { + foreach ($cmdData['template'] as $key => $value) { + $cmd->setTemplate($key, $value); + } + } + if (isset($cmdData['updateCmd'])) { $cmd_updated_by[$cmdData["logicalId"]] = $cmdData['updateCmd']; } @@ -110,10 +123,15 @@ public function createCommandsFromConfigFile($commands, $dict) { } } - public static function createListOption($data, $dict) { + public static function createListOption($data, $dict, $filter = array()) { $list = ''; + $needFilter = count($filter) > 0; foreach ($data as $item) { + if ($needFilter && !in_array($item, $filter)) { + self::warning($item . ' ' . __('valeur filtrée, on passe', __FILE__)); + continue; + } $val = $dict[$item] ?? $item; $list .= $item . '|' . $val . ';'; } @@ -126,6 +144,112 @@ public static function getPlurial($nb) { return ($nb > 1) ? 's' : ''; } + public static function getConfigForCommunity($withQuote = true) { + + $infoPlugin = 'Version OS : ' . system::getDistrib() . ' ' . system::getOsVersion() . '
'; + + $infoPlugin .= 'Version PHP : ' . phpversion(); + + if ($withQuote) { + return self::getPreformattedText($infoPlugin); + } + + return $infoPlugin; + } + + public static function getPreformattedText($string) { + return '
```text
' . str_replace(array('', '', ' '), array('', '', ' '), $string) . '
```
'; + } + + public static function backupExclude() { + return [ + 'resources/venv' + ]; + } + + public static function deleteDirectory($dir) { + if (!file_exists($dir)) { + return false; + } + + if (!is_dir($dir)) { + return false; + } + + $items = array_diff(scandir($dir), array('.', '..')); + + foreach ($items as $item) { + $path = $dir . DIRECTORY_SEPARATOR . $item; + + if (is_dir($path)) { + self::deleteDirectory($path); + } else { + unlink($path); + } + } + + return rmdir($dir); + } + + /******************************* + * From @Mips2648 + ******************************* / + + + /** + * Allow to perform a // task exec : now or later + * + * @param string $_method + * @param array|null $_option + * @param string $_date + * @return void + */ + public static function executeAsync(string $_method, $_option = null, $_date = 'now') { + if (!method_exists(__CLASS__, $_method)) { + throw new InvalidArgumentException("Method provided for executeAsync does not exist: {$_method}"); + } + + $cron = new cron(); + $cron->setClass(__CLASS__); + $cron->setFunction($_method); + if (isset($_option)) { + $cron->setOption($_option); + } + $cron->setOnce(1); + $scheduleTime = strtotime($_date); + $cron->setSchedule(cron::convertDateToCron($scheduleTime)); + $cron->save(); + if ($scheduleTime <= strtotime('now')) { + $cron->run(); + self::debug("Task '{$_method}' executed now"); + } else { + self::debug("Task '{$_method}' scheduled at {$_date}"); + } + } + + private static function pythonRequirementsInstalled(string $pythonPath, string $requirementsPath) { + if (!file_exists($pythonPath) || !file_exists($requirementsPath)) { + return false; + } + exec("{$pythonPath} -m pip freeze", $packages_installed); + $packages = join("||", $packages_installed); + exec("cat {$requirementsPath}", $packages_needed); + foreach ($packages_needed as $line) { + if (preg_match('/([^\s]+)[\s]*([>=~]=)[\s]*([\d+\.?]+)$/', $line, $need) === 1) { + if (preg_match('/' . $need[1] . '==([\d+\.?]+)/', $packages, $install) === 1) { + if ($need[2] == '==' && $need[3] != $install[1]) { + return false; + } elseif (version_compare($need[3], $install[1], '>')) { + return false; + } + } else { + return false; + } + } + } + return true; + } + /** ******************** LOGS FUNCTIONS */ diff --git a/composer.lock b/composer.lock index 2c439e8..743bf46 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "tomitomas/jeedom-tools", - "version": "0.3", + "version": "0.8.0", "source": { "type": "git", "url": "https://github.com/tomitomas/jeedom-tools.git", - "reference": "8f7d4fe048313088f9105c3814f5148bb9fd0e8d" + "reference": "d07ff69ffbf2c5c92bed7e4d2c3d16a142322d11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tomitomas/jeedom-tools/zipball/8f7d4fe048313088f9105c3814f5148bb9fd0e8d", - "reference": "8f7d4fe048313088f9105c3814f5148bb9fd0e8d", + "url": "https://api.github.com/repos/tomitomas/jeedom-tools/zipball/d07ff69ffbf2c5c92bed7e4d2c3d16a142322d11", + "reference": "d07ff69ffbf2c5c92bed7e4d2c3d16a142322d11", "shasum": "" }, "type": "library", @@ -38,9 +38,9 @@ "description": "Generic lib for jeedom plugins", "support": { "issues": "https://github.com/tomitomas/jeedom-tools/issues", - "source": "https://github.com/tomitomas/jeedom-tools/tree/0.3" + "source": "https://github.com/tomitomas/jeedom-tools/tree/0.8.0" }, - "time": "2023-02-04T22:06:19+00:00" + "time": "2024-09-04T15:47:28+00:00" } ], "packages-dev": [], @@ -51,5 +51,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" }