The Entry class

class Entry

Bases: fs.FilePath, winsys.core._WinSysObject

Heart of the fs module. This is a subtype of FilePath and therefore of the base unicode type and is the parent of the Dir and File classes and contains all the functionality common to both. It is rarely instantiated itself, altho’ it’s possible to do so.

Attributes: * readable * filepath * created_at * accessed_at * written_at * uncompressed_size * size * attributes * id * n_links * attributes - an :class:`_Attributes object representing combinations of FILE_ATTRIBUTE

Common functionality:

  • Entries compare (eq, lt, etc.) according to their full filepath. To do a content-wise comparison, use equal_contents().
  • Entries are True according to their existence on a filesystem
  • The str representation is the filepath utf8-encoded; unicode is the filepath itself
  • Adding one path to another will use os.path.join semantics
ancestors()

Iterate over this entry’s ancestors, yielding the Dir object corresponding to each one.

Returns:yield a Dir object for each ancestor
as_string()
compress()

Compress this entry; if it is a file, it will be compressed, if it is a directory it will be marked so that any new files added to it will be compressed automatically.

Returns:self
dumped(level=0, show_security=False)
encrypt()

FIXME: Need to work out how to create certificates for this

Returns:self
encryption_users()

FIXME: Need to work out how to create certificates for this

classmethod factory(filepath)
get_accessed_at()

Get and store the latest access time from the filesystem

get_attributes()

Get and store the latest file attributes from the filesystem

get_created_at()

Get and store the latest creation time from the filesystem

get_size()

Get and store the latest (possibly compressed) size from the filesystem

get_written_at()

Get and store the latest modification time from the filesystem

handle(mode='r')
like(pattern)

Return true if this filename’s name (not the path) matches pattern according to fnmatch, eg:

from winsys import fs
for f in fs.files ():
  if f.directory and f.like ("test_*"):
    print f
Parameters:pattern – an fnmatch pattern
Returns:True if this file matches pattern
move(other, callback=None, callback_data=None, clobber=False)

Move this entry to the file/directory represented by other. If other is a directory, self

Parameters:
  • other – anything accepted by entry()
  • callback – a function which will receive a total size & total transferred
  • callback_data – passed as extra data to callback
  • clobber – whether to overwrite the other file if it exists
Returns:

a File object corresponding to the target file

rename(other, callback=None, callback_data=None, clobber=False)

Move this entry to the file/directory represented by other. If other is a directory, self

Parameters:
  • other – anything accepted by entry()
  • callback – a function which will receive a total size & total transferred
  • callback_data – passed as extra data to callback
  • clobber – whether to overwrite the other file if it exists
Returns:

a File object corresponding to the target file

security(options=u'OD')

Return a security.Security object corresponding to this entry’s security attributes. Note that the returning object is a context manager so a common pattern is:

#
# Find all private key files and ensure that only
# the owner has any access.
#
from winsys import fs
for f in fs.flat ("*.ppk"):
  with f.security () as s:
    s.break_inheritance ()
    s.dacl = [(s.owner, "F", "ALLOW")]
Parameters:options – cf security.security()
Returns:a security.Security object which may be used as a context manager
take_control(principal=<Unset>)

Give the logged-on user full control to a file. This may need to be preceded by a call to take_ownership() so that the user gains WRITE_DAC permissions.

Parameters:principal – anything accepted by principal() [logged-on user]
take_ownership(principal=<Unset>)

Set the new owner of the file to be the logged-on user. This is no more than a slight shortcut to the equivalent security operations.

If you specify a principal (other than the logged-in user, the default) you may need to have enabled SE_RESTORE privilege. Even the logged-in user may need to have enabled SE_TAKE_OWNERSHIP if that user has not been granted the appropriate security by the ACL.

Parameters:principal – anything accepted by principal() [logged-on user]
uncompress()

Uncompress this entry; if it is a file, it will be uncompressed, if it is a directory it will be marked so that any new files added to it will not be compressed automatically.

Returns:self
unencrypt()

FIXME: Need to work out how to create certificates for this

Returns:self
accessed_at

Get the access time from the original file read or the latest from the filesystem if none was stored.

archive

Is the archive bit set on the file?

attributes

Get and store the file attributes from the original file read or the latest from the filesystem if none was stored.

compressed

Is the file compressed?

created_at

Get the creation time from the original file read or the latest from the filesystem if none was stored.

directory

Is the file a directory?

encrypted

Is the file encrypted?

hidden

Is the file hidden?

id

Return an id for this file which can be used to compare it to another while both files are open to determine if both are the same physical file.

Determine how many links point to this file. >1 indicates that the file is hardlinked.

normal

Is the file normal?

not_content_indexed

Should the file’s content not be indexed?

offline

Is the file offline?

readable
readonly

Is the file readonly?

reparse_point

Is the file a reparse point?

size

Get and store the (possibly compressed) size from the original file read or the latest from the filesystem if none was stored.

sparse_file

Is the file sparse?

system

Is the file a system file?

temporary

Is the file a temporary file?

uncompressed_size

Get the size of the file data, ignoring any filesystem compression which may have been applied.

virtual

Is the file a virtual file?

written_at

Get and store the modification time from the original file read or the latest from the filesystem if none was stored.

Previous topic

The FilePath class

Next topic

The File class

This Page