grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a d�tdž%ã@sVdZddlZddlZddlmZmZmZmZGdd„deƒZ dd„Z e d krRe ƒdS) a¼ Implements the base CFSNode class and a few inherited variants. This file is part of RTSLib. Copyright (c) 2011-2013 by Datera, Inc Copyright (c) 2011-2014 by Red Hat, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. éNé)ÚfreadÚfwriteÚ RTSLibErrorÚRTSLibNotInCFSc@s®eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z d&dd„Z d'dd„Z d(dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zeed!d"�Zee d#d"�Zd$d%„ZdS))ÚCFSNodez/sys/kernel/config/targetcCs |j|_dS©N)Ú configfs_dirÚ_path©Úself©r ú//usr/lib/python3.9/site-packages/rtslib/node.pyÚ__init__!szCFSNode.__init__cCs |j|jkSr©r ©r Úotherr r rÚ__eq__$szCFSNode.__eq__cCs |j|jkSrrrr r rÚ__ne__'szCFSNode.__ne__cCs|jSrrr r r rÚ _get_path*szCFSNode._get_pathcCsÐ|dvrtd|ƒ‚|jrt|dkrttj tj |j¡|jd¡rbtt |j¡ƒdsbt  |j¡q˜td|j j ƒ‚n$|js˜|dkr˜t d|j j |jfƒ‚|jsÌzt  |j¡Wntd |j j ƒ‚Yn0d S) a' Creates the configFS node if it does not already exist, depending on the mode. any -> makes sure it exists, also works if the node already does exist lookup -> make sure it does NOT exist create -> create the node which must not exist beforehand )ÚanyÚlookupÚcreatezInvalid mode: %srz/corerz"This %s already exists in configFSrzNo such %s in configfs: %szCould not create %s in configFSN)rÚexistsÚosÚpathÚsamefileÚdirnamer ÚnextÚwalkÚrmdirÚ __class__Ú__name__rÚmkdir)r Úmoder r rÚ_create_in_cfs_ine-s* ÿÿ ÿÿzCFSNode._create_in_cfs_inecCstj |j¡Sr)rrÚisdirr r r rÚ_existsLszCFSNode._existscCs|jstd|jjƒ‚dS)Nz"This %s does not exist in configFS)rrr!r"r r r rÚ _check_selfOsÿzCFSNode._check_selfNcCs°tj |¡sgS|dur,|dur,t |¡}nxg}t |¡D]h}t d||f¡}|durt||tjtj@tjkkrtq:|dur˜||tjtj@tjkkr˜q:| |¡q:|  ¡|S)a List files under a path depending on their owner's write permissions. @param path: The path under which the files are expected to be. If the path itself is not a directory, an empty list will be returned. @type path: str @param writable: If None (default), return all files despite their writability. If True, return only writable files. If False, return only non-writable files. @type writable: bool or None @param readable: If None (default), return all files despite their readability. If True, return only readable files. If False, return only non-readable files. @type readable: bool or None @return: List of file names filtered according to their read/write perms. Nz%s/%s) rrr&ÚlistdirÚstatÚST_MODEÚS_IWUSRÚS_IRUSRÚappendÚsort)r rÚwritableÚreadableÚnamesÚnameZsresr r rÚ _list_filesTs(  ÿÿ zCFSNode._list_filescCs | ¡d|j}| |||¡S)a @param writable: If None (default), return all parameters despite their writability. If True, return only writable parameters. If False, return only non-writable parameters. @type writable: bool or None @param readable: If None (default), return all parameters despite their readability. If True, return only readable parameters. If False, return only non-readable parameters. @type readable: bool or None @return: The list of existing RFC-3720 parameter names. z%s/param©r(rr4©r r0r1rr r rÚlist_parameters}s  zCFSNode.list_parameterscCs | ¡d|j}| |||¡S)a @param writable: If None (default), return all files despite their writability. If True, return only writable files. If False, return only non-writable files. @type writable: bool or None @param readable: If None (default), return all files despite their readability. If True, return only readable files. If False, return only non-readable files. @type readable: bool or None @return: A list of existing attribute names as strings. z %s/attribr5r6r r rÚlist_attributes�s  zCFSNode.list_attributesc Csˆ| ¡d|jt|ƒf}tj |¡s8tdt|ƒƒ‚nLzt|dt|ƒƒWn4ty‚}ztd||fƒ‚WYd}~n d}~00dS)a Sets the value of a named attribute. The attribute must exist in configFS. @param attribute: The attribute's name. It is case-sensitive. @type attribute: string @param value: The attribute's value. @type value: string ú %s/attrib/%súCannot find attribute: %sz%szCannot set attribute %s: %sN©r(rÚstrrÚisfilerrÚ Exception)r Ú attributeÚvaluerÚer r rÚ set_attribute�s  ÿzCFSNode.set_attributecCs@| ¡d|jt|ƒf}tj |¡s4td|ƒ‚nt|ƒSdS)zŠ @param attribute: The attribute's name. It is case-sensitive. @return: The named attribute's value, as a string. r9r:N©r(rr<rr=rr)r r?rr r rÚ get_attribute±s  zCFSNode.get_attributec Cs„| ¡d|jt|ƒf}tj |¡s4td|ƒ‚nLzt|dt|ƒƒWn4ty~}ztd||fƒ‚WYd}~n d}~00dS)a% Sets the value of a named RFC-3720 parameter. The parameter must exist in configFS. @param parameter: The RFC-3720 parameter's name. It is case-sensitive. @type parameter: string @param value: The parameter's value. @type value: string ú %s/param/%szCannot find parameter: %sz%s zCannot set parameter %s: %sNr;)r Ú parameterr@rrAr r rÚ set_parameter½s  zCFSNode.set_parametercCs@| ¡d|jt|ƒf}tj |¡s4td|ƒ‚nt|ƒSdS)z° @param parameter: The RFC-3720 parameter's name. It is case-sensitive. @type parameter: string @return: The named parameter value as a string. rEz"Cannot find RFC-3720 parameter: %sNrC)r rFrr r rÚ get_parameterÐs  zCFSNode.get_parametercCs|jrt |j¡dS)zº If the underlying configFS object does not exist, this method does nothing. If the underlying configFS object exists, this method attempts to delete it. N)rrr rr r r rÚdeleteÝszCFSNode.deletezGet the configFS object path.)Údocz¹Is True as long as the underlying configFS object exists. If the underlying configFS objects gets deleted either by calling the delete() method, or by any other means, it will be False.c Cs–i}i}i}|jddd�D]<}zt| |¡ƒ||<WqtyT| |¡||<Yq0q|rd||d<|jddd�D]}| |¡||<qr|r’||d<|S)NT)r0r1Z attributesÚ parameters)r8ÚintrDÚ ValueErrorr7rH)r ÚdÚattrsÚparamsÚitemr r rÚdumpîs z CFSNode.dump)NN)NN)NN)r"Ú __module__Ú __qualname__r rrrrr%r'r(r4r7r8rBrDrGrHrIÚpropertyrrrRr r r rrs. )     ÿÿrcCsddl}| ¡dS)Nr)ÚdoctestZtestmod)rVr r rÚ_testÿsrWÚ__main__) Ú__doc__rr*ZutilsrrrrÚobjectrrWr"r r r rÚsf