Package: node.ext.fs
node.ext.fsOverviewnode.ext.fsis a node implementation for file system directories. It is
the successor ofnode.ext.directory.For more information aboutnodeseehttps://pypi.python.org/pypi/node.UsageCreate new file:fromnode.ext.fsimportFilefile_path='file.txt'f=File(name=file_path)# set contents via data attributef.data='data\n'# set contents via lines attributef.lines=['data']# set permissionsf.fs_mode=0o644# persistf()Read existing file:file_path='file.txt'f=File(name=file_path)assert(f.data=='data\n')assert(f.lines==['data'])assert(f.fs_mode==0o644)Files with binary data:fromnode.ext.fsimportMODE_BINARYfile_path='file.txt'f=File(name=file_path)f.mode=MODE_BINARYf.data=b'\x00\x00'assert(f.data==b'\x00\x00')# lines property won't work if file in binary modef.lines# raises RuntimeErrorCreate directory:fromnode.ext.fsimportDirectorydir_path='.'d=Directory(name=dir_path)# add subdirectories and filesd['sub']=Directory()d['file.txt']=File()# set permissions for directoryd['sub'].fs_mode=0o755# persistd()Read existing directory:dir_path='.'d=Directory(name=dir_path)>>>d.printtree()<class 'node.ext.fs.directory.Directory'>: .
  <class 'node.ext.fs.directory.File'>: file.txt
  <class 'node.ext.fs.directory.Directory'>: subDefining the default factories for files and directories is done by settingdefault_file_factoryrespectivedefault_directory_factory:classCustomFile(File):passclassCustomDirectory(Directory):default_file_factory=CustomFileCustomDirectory.default_directory_factory=CustomDirectorydir_path='.'d=CustomDirectory(name=dir_path)>>>d.printtree()<class '...CustomDirectory'>: .
  <class '...CustomFile'>: file.txt
  <class '...CustomDirectory'>: subDefine wildcard factories. Factories can be defined for directories and files.
Pattern matching is done usingfnmatch. Seenode.behaviors.WildcardFactory:classTextFile(File):passclassLogsDirectory(Directory):passd=Directory(name='.',factories={'*.txt':TextFile,'logs':LogsDirectory})Now when reading children, factories matching the file or directory name
patterns are used to instantiate the children, using the default factories if
no pattern matches.>>>os.mkdir('logs')>>>os.mkdir('other')>>>withopen('file.txt','w')asf:...f.write('text')>>>withopen('file.rst','w')asf:...f.write('rst')>>>d=Directory(...name='.',...factories={...'*.txt':TextFile,...'logs':LogsDirectory...})>>>d.printtree()<class 'node.ext.fs.directory.Directory'>: .
  <class '...File'>: file.rst
  <class '...TextFile'>: file.txt
  <class '...LogsDirectory'>: logs
  <class '...Directory'>: otherPython VersionsPython 2.7, 3.7+May work with other versions (untested)ContributorsRobert Niederreiter (Author)Changes1.1 (2022-12-21)Introducenode.ext.fs.interfaces.IDirectory.renameand implement innode.ext.fs.directory.DirectoryStorage.
[rnix]Do not allow setting and deleting of directory children defined inignores.
[rnix]1.0 (2022-10-06)Subclassthreading.localfornode.ext.fs.directory._directory_contextobjects in order to safely
provide default values.
[rnix]IntroduceIFileIOinterface andFileIOplumbing behavior.
[rnix]IntroduceIFileNodeinterface.
[rnix]Passnameandparentto default file and directory factories.
[rnix]DirectoryStorageacceptsfs_pathkeyword argument.
[rnix]Rename_FSModeMixinplumbing behavior toFSMode. Setting the actual
file mode is now done by plumbing__call__function.
[rnix]IntroduceFSLocationplumbing behavior.
[rnix]Breaking ChangesPackage has been renamed fromnode.ext.directorytonode.ext.fs.
There are too many breaking changes for a sane deprecation path.
[rnix]DirectoryStorage.__init__no longer accepts deprecatedbackupkeyword
argument.
[rnix]DirectoryStorage.child_directory_factoryhas been renamed todefault_directory_factory[rnix]DirectoryStoragederives fromnode.behaviors.WildcardFactorynow.
Own factory pattern logic working with file endings has been removed.
Patterns must be adopted.
[rnix]Remove globalfile_factoriesandDirectoryStorage.file_factories.
Wildcard pattern related factories are defined viaDirectoryStorage.factoriesnow.
[rnix]RemoveIFileAddedEventandnode.ext.fs.eventsmodule. If you need
lifecycle events, usenode.behaviors.Lifecycleinstead.
[rnix]BasicFileandDirectoryobjects no longer use referencing related
plumbung behaviors. You need to define your own base objects plumbingINodeReferenceimplemeting behaviors.
[rnix]ReduceIFileinterface. It no longer inherits fromILeafand default
file implementation related attributes were moved toIFileNodeinterface.
This way it is possible to implement very custom file implementations without
breaking the interface contract.
[rnix]RenameFileStoragetoFileNode. It no longer inherits fromDictStorage. Further file data is no longer kept in memory unless it
changes, then it’s kept until it gets written to disk.
[rnix]FileNodeandDirectoryStoragenot inherits from_FSModeMixinrespective nowFSModebehavior any more.FSModebehavior must be applied explicit on nodes which should provide this
behavior.
[rnix]Rename_fs_pathhelper function toget_fs_path.
[rnix]Rename_fs_modehelper function toget_fs_mode.
[rnix]0.8 (2022-03-21)Replace deprecated use ofNodifybyMappingNode.
[rnix]Replace deprecated use ofAdoptbyMappingAdopt.
[rnix]0.7Python 3 support.
[rnix, 2017-06-06]fs_modeis read from filesystem if file or directory exists and
fs_mode not set explicitely.
[rnix, 2017-06-06]Removebackupoption fromIDirectoryinterface. It never really
worked properly and conceptuallyIDirectoryis the wrong place for
handling backups of files.
[rnix, 2017-06-04]0.6Introducenode.ext.directory.interfaces.IFile.direct_syncsetting.
[rnix, 2017-01-30]Completenode.ext.directory.interfaces.IFileandnode.ext.directory.interfaces.IDirectoryto reflect implemented features.
[rnix, 2017-01-30]Movenode.ext.directory.directory.MODE_TEXTandnode.ext.directory.directory.MODE_BINARYtonode.ext.directory.interfaces.
[rnix, 2017-01-30]0.5.4Check whether directory to be peristed already exists by name as file innode.ext.directory.FileStorage.__call__.
[rnix, 2015-10-05]Implement fallback topathinnode.ext.directory.FileStorage.__call__iffs_pathnot exists.
[rnix, 2015-10-05]Implement fallback topathinnode.ext.directory.FileStorage._get_dataiffs_pathnot exists.
[rnix, 2015-10-05]Set initial mode withself.modeproperty setter instead of internalself._modeinnode.ext.directory.FileStorage._get_mode.
[rnix, 2015-10-05]0.5.3Remove deleted keys from internal reference after__call__in order
to return the correct result when adding a file or directory with the same
key again.
[rnix, 2015-07-20]0.5.2Use try/except instead of iteration to check whether directory child already
in memory.
[rnix, 2015-05-12]0.5.1Always useos.chmodfor setting directory permissions, not only if
already exists.
[rnix, 2015-03-03]0.5Introducefs_modeon directories and files.
[rnix, 2015-03-03]0.4Return empty list inFile.linesif no data.
[rnix, 2015-02-18]Consider filesystem encoding. Defaults to UTF-8.
[rnix, 2015-02-18]Tree locking on modification.
[rnix, 2014-09-02]Prevent empty keys in__setitem__.
[rnix, 2014-09-02]Useplumbingdecorator.
[rnix, 2014-08-25]0.3introducedefault_file_factoryon directories for controlling default
file child creation.
[rnix, 2013-12-09]move file logic inFileStoragebehavior.
[rnix, 2013-08-06]makefile_factoriesa class property on directory storage.
[rnix, 2013-08-06]makeignoresa class property on directory storage.
[rnix, 2013-08-06]Cleanup interfaces.
[rnix, 2013-08-06]0.2Almost complete rewrite. Fits now paradigms of node based API’s.
[rnix, 2012-01-30]0.1initialLicenseCopyright (c) 2010-2021, BlueDynamics Alliance, Austria
Copyright (c) 2021-2022, Node Contributors
All rights reserved.Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.