Skip to main content

Filesystem directory abstraction based on nodes

Project description

node.ext.directory

Latest PyPI version Number of PyPI downloads Test node.ext.directory

Maintenance mode

This package is in maintenance mode. The successor of this package is https://pypi.python.org/pypi/node.ext.fs.

Overview

node.ext.directory is a node implementation for file system directories.

For more information about node see https://pypi.python.org/pypi/node.

Usage

Create new file:

from node.ext.directory import File

file_path = 'file.txt'
f = File(name=file_path)

# set contents via data attribute
f.data = 'data\n'

# set contents via lines attribute
f.lines = ['data']

# set permissions
f.fs_mode = 0o644

# persist
f()

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:

from node.ext.directory import MODE_BINARY

file_path = 'file.txt'
f = File(name=file_path)
f.mode = MODE_BINARY

f.data = b'\x00\x00'

assert(f.data == b'\x00\x00')

# lines property won't work if file in binary mode
f.lines  # raises RuntimeError

Create directory:

from node.ext.directory import Directory

dir_path = '.'
d = Directory(name=dir_path)

# add subdirectories and files
d['sub'] = Directory()
d['file.txt'] = File()

# set permissions for directory
d['sub'].fs_mode = 0o755

# persist
d()

Read existing directory:

dir_path = '.'
d = Directory(name=dir_path)
>>> d.printtree()
<class 'node.ext.directory.directory.Directory'>: .
  <class 'node.ext.directory.directory.File'>: file.txt
  <class 'node.ext.directory.directory.Directory'>: sub

Define file factories:

from node.ext import directory

class PyFile(File):
    pass

# set global factories
directory.file_factories['.py'] = PyFile

# set local factories
d = Directory(name='.', factories={'.py': PyFile})

when reading .py files, PyFile is used to instanciate children:

>>> with open('foo.py', 'w') as f:
...     f.write('#')

>>> d = Directory(name='.', factories={'.py': PyFile})
>>> d.printtree()
<class 'node.ext.directory.directory.Directory'>: .
  <class '...PyFile'>: foo.py

Python Versions

  • Python 2.7, 3.7+

  • May work with other versions (untested)

Contributors

  • Robert Niederreiter (Author)

Changes

2.0.0 (2026-02-03)

  • Refactor package layout to use pyproject.toml and implicit namespace packages. [rnix]

0.8.2 (2025-10-25)

  • Pin upper versions of dependencies. [rnix]

0.8.1 (2024-05-23)

  • Fix deprecated imports. [rnix]

  • Add note about successor package. [rnix]

0.8 (2022-03-21)

  • Replace deprecated use of Nodify by MappingNode. [rnix]

  • Replace deprecated use of Adopt by MappingAdopt. [rnix]

0.7

  • Python 3 support. [rnix, 2017-06-06]

  • fs_mode is read from filesystem if file or directory exists and fs_mode not set explicitely. [rnix, 2017-06-06]

  • Remove backup option from IDirectory interface. It never really worked properly and conceptually IDirectory is the wrong place for handling backups of files. [rnix, 2017-06-04]

0.6

  • Introduce node.ext.directory.interfaces.IFile.direct_sync setting. [rnix, 2017-01-30]

  • Complete node.ext.directory.interfaces.IFile and node.ext.directory.interfaces.IDirectory to reflect implemented features. [rnix, 2017-01-30]

  • Move node.ext.directory.directory.MODE_TEXT and node.ext.directory.directory.MODE_BINARY to node.ext.directory.interfaces. [rnix, 2017-01-30]

0.5.4

  • Check whether directory to be peristed already exists by name as file in node.ext.directory.FileStorage.__call__. [rnix, 2015-10-05]

  • Implement fallback to path in node.ext.directory.FileStorage.__call__ if fs_path not exists. [rnix, 2015-10-05]

  • Implement fallback to path in node.ext.directory.FileStorage._get_data if fs_path not exists. [rnix, 2015-10-05]

  • Set initial mode with self.mode property setter instead of internal self._mode in node.ext.directory.FileStorage._get_mode. [rnix, 2015-10-05]

0.5.3

  • Remove 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.2

  • Use try/except instead of iteration to check whether directory child already in memory. [rnix, 2015-05-12]

0.5.1

  • Always use os.chmod for setting directory permissions, not only if already exists. [rnix, 2015-03-03]

0.5

  • Introduce fs_mode on directories and files. [rnix, 2015-03-03]

0.4

  • Return empty list in File.lines if 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]

  • Use plumbing decorator. [rnix, 2014-08-25]

0.3

  • introduce default_file_factory on directories for controlling default file child creation. [rnix, 2013-12-09]

  • move file logic in FileStorage behavior. [rnix, 2013-08-06]

  • make file_factories a class property on directory storage. [rnix, 2013-08-06]

  • make ignores a class property on directory storage. [rnix, 2013-08-06]

  • Cleanup interfaces. [rnix, 2013-08-06]

0.2

  • Almost complete rewrite. Fits now paradigms of node based API’s. [rnix, 2012-01-30]

0.1

  • initial

License

Copyright (c) 2010-2021, BlueDynamics Alliance, Austria Copyright (c) 2021-2025, 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

node_ext_directory-2.0.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

node_ext_directory-2.0.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file node_ext_directory-2.0.0.tar.gz.

File metadata

  • Download URL: node_ext_directory-2.0.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for node_ext_directory-2.0.0.tar.gz
Algorithm Hash digest
SHA256 0c2922d70cbc5a0fd962f35632fe2f7ff1f75dbcbd76bbda989fe399dbb50c36
MD5 97fcd15ecd0ff675fe325d101e192d16
BLAKE2b-256 5305834a9361075fe0dc2e5c5ee9a0fa97204842ef6c37d9ddba42ce9802c492

See more details on using hashes here.

File details

Details for the file node_ext_directory-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for node_ext_directory-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 215c3b3e95435f54404946c451450aee3ae333b025b3c9c81b77ec0925264b4f
MD5 c7bf539b33d154075333ae17e79bcf70
BLAKE2b-256 fcc9504dbf271840d51070b7d8e86c0463d5996a4b1d5fc072a4a91de19927a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page