b.t.l.LocalTransport(transport.Transport) : class documentation

Part of bzrlib.transport.local View In Hierarchy

Known subclasses: bzrlib.transport.local.EmulatedWin32LocalTransport

This is the transport agent for local filesystem access.
Method __init__ Set the base path where files will be stored.
Method clone Return a new LocalTransport with root at self.base + offset
Method abspath Return the full url to the given relative URL.
Method local_abspath Transform the given relative path URL into the actual path on disk
Method relpath Return the local path portion from a given absolute path.
Method has Does the file relpath exist?
Method get Get the file at the given relative path.
Method put_file Copy the file-like object into the location.
Method put_bytes Copy the string into the location.
Method put_file_non_atomic Copy the file-like object into the target location.
Method put_bytes_non_atomic Copy the string into the target location.
Method iter_files_recursive Iter the relative paths of files in the transports sub-tree.
Method mkdir Create a directory at the given path.
Method open_write_stream See Transport.open_write_stream.
Method append_file Append the text in the file-like object into the final location.
Method append_bytes Append the text in the string into the final location.
Method copy Copy the item at rel_from to the location at rel_to
Method rename Rename a file or directory.
Method move Move the item at rel_from to the location at rel_to
Method delete Delete the item at relpath
Method external_url See bzrlib.transport.Transport.external_url.
Method copy_to Copy a set of entries from self into another Transport.
Method listable See Transport.listable.
Method list_dir Return a list of all files at the given location.
Method stat Return the stat information for a file.
Method lock_read Lock the given file for shared (read) access.
Method lock_write Lock the given file for exclusive (write) access.
Method rmdir See Transport.rmdir.
Method readlink See Transport.readlink.
Method hardlink See Transport.link.
Method symlink See Transport.symlink.
Method _abspath Return a path for use in os calls.
Method _put_non_atomic_helper Common functionality information for the put_*_non_atomic.
Method _mkdir Create a real directory, filtering through mode
Method _get_append_file Call os.open() for the given relpath
Method _check_mode_and_size Check the mode of the file, and return the current size
Method _pump_to_fd Copy contents of one file to another.
Method _can_roundtrip_unix_modebits Return true if this transport can store and retrieve unix modebits.

Inherited from Transport:

Method create_prefix Create all the directories leading down to self.base.
Method ensure_base Ensure that the directory this transport references exists.
Method get_segment_parameters Return the segment parameters for the top segment of the URL.
Method recommended_page_size Return the recommended page size for this transport.
Method has_multi Return True/False for each entry in relpaths
Method has_any Return True if any of the paths exist.
Method get_bytes Get a raw string of the bytes for a file at the given location.
Method get_smart_medium Return a smart client medium for this transport if possible.
Method readv Get parts of the file at the given relative path.
Method get_multi Get a list of file-like objects, one for each entry in relpaths.
Method mkdir_multi Create a group of directories
Method append_multi Append the text in each file-like or string object to
Method copy_multi Copy a bunch of entries.
Method copy_tree Copy a subtree from one relpath to another.
Method copy_tree_to_transport Copy a subtree from one transport to another.
Method move_multi Move a bunch of entries.
Method move_multi_to Move a bunch of entries to a single location.
Method delete_multi Queue up a bunch of deletes to be done.
Method delete_tree Delete an entire tree. This may require a listable transport.
Method __repr__ Undocumented
Method stat_multi Stat multiple files and return the information.
Method is_readonly Return true if this connection cannot be written to.
Method disconnect Undocumented
Method _translate_error Translate an IOError or OSError into an appropriate bzr error.
Method _pump Most children will need to copy from one file-like
Method _get_total Try to figure out how many entries are in multi,
Method _report_activity Notify that this transport has activity.
Method _update_pb Update the progress bar based on the current count
Method _iterate_over Iterate over all entries in multi, passing them to func,
Method _readv Get parts of the file at the given relative path.
Method _seek_and_read An implementation of readv that uses fp.seek and fp.read.
Method _sort_expand_and_combine Helper for readv.
Static Method _coalesce_offsets Yield coalesced offsets.
Method _reuse_for Undocumented
Method _redirected_to Returns a transport suitable to re-issue a redirected request.
def __init__(self, base):
Set the base path where files will be stored.
def clone(self, offset=None):
Return a new LocalTransport with root at self.base + offset Because the local filesystem does not require a connection, we can just return a new object.
def _abspath(self, relative_reference):

Return a path for use in os calls.

Several assumptions are made:
  • relative_reference does not contain '..'
  • relative_reference is url escaped.
def abspath(self, relpath):
Return the full url to the given relative URL.
def local_abspath(self, relpath):
Transform the given relative path URL into the actual path on disk

This function only exists for the LocalTransport, since it is the only one that has direct local access. This is mostly for stuff like WorkingTree which needs to know the local working directory. The returned path will always contain forward slashes as the path separator, regardless of the platform.

This function is quite expensive: it calls realpath which resolves symlinks.

def relpath(self, abspath):
Return the local path portion from a given absolute path.
def has(self, relpath):
Does the file relpath exist?

Note that some transports MAY allow querying on directories, but this is not part of the protocol. In other words, the results of t.has("a_directory_name") are undefined.

Returns (type: bool)
def get(self, relpath):
Get the file at the given relative path.
ParametersrelpathThe relative path to the file
def put_file(self, relpath, f, mode=None):
Copy the file-like object into the location.
ParametersrelpathLocation to put the contents, relative to base.
fFile-like object.
modeThe mode for the newly created file, None means just use the default
def put_bytes(self, relpath, bytes, mode=None):
Copy the string into the location.
ParametersrelpathLocation to put the contents, relative to base.
bytesString
def _put_non_atomic_helper(self, relpath, writer, mode=None, create_parent_dir=False, dir_mode=None):
Common functionality information for the put_*_non_atomic.

This tracks all the create_parent_dir stuff.

Parametersrelpaththe path we are putting to.
writerA function that takes an os level file descriptor and writes whatever data it needs to write there.
modeThe final file mode.
create_parent_dirShould we be creating the parent directory if it doesn't exist?
def put_file_non_atomic(self, relpath, f, mode=None, create_parent_dir=False, dir_mode=None):
Copy the file-like object into the target location.

This function is not strictly safe to use. It is only meant to be used when you already know that the target does not exist. It is not safe, because it will open and truncate the remote file. So there may be a time when the file has invalid contents.

ParametersrelpathThe remote location to put the contents.
fFile-like object.
modePossible access permissions for new file. None means do not set remote permissions.
create_parent_dirIf we cannot create the target file because the parent directory does not exist, go ahead and create it, and then try again.
def put_bytes_non_atomic(self, relpath, bytes, mode=None, create_parent_dir=False, dir_mode=None):
Copy the string into the target location.

This function is not strictly safe to use. See Transport.put_bytes_non_atomic for more information.

ParametersrelpathThe remote location to put the contents.
bytesA string object containing the raw bytes to write into the target file.
modePossible access permissions for new file. None means do not set remote permissions.
create_parent_dirIf we cannot create the target file because the parent directory does not exist, go ahead and create it, and then try again.
dir_modePossible access permissions for new directories.
def iter_files_recursive(self):
Iter the relative paths of files in the transports sub-tree.
def _mkdir(self, abspath, mode=None):
Create a real directory, filtering through mode
def mkdir(self, relpath, mode=None):
Create a directory at the given path.
def open_write_stream(self, relpath, mode=None):
See Transport.open_write_stream.
def _get_append_file(self, relpath, mode=None):
Call os.open() for the given relpath
def _check_mode_and_size(self, file_abspath, fd, mode=None):
Check the mode of the file, and return the current size
def append_file(self, relpath, f, mode=None):
Append the text in the file-like object into the final location.
def append_bytes(self, relpath, bytes, mode=None):
Append the text in the string into the final location.
def _pump_to_fd(self, fromfile, to_fd):
Copy contents of one file to another.
def copy(self, rel_from, rel_to):
Copy the item at rel_from to the location at rel_to
def rename(self, rel_from, rel_to):
Rename a file or directory.

This must fail if the destination is a nonempty directory - it must not automatically remove it. It should raise DirectoryNotEmpty, or some other PathError if the case can't be specifically detected.

If the destination is an empty directory or a file this function may either fail or succeed, depending on the underlying transport. It should not attempt to remove the destination if overwriting is not the native transport behaviour. If at all possible the transport should ensure that the rename either completes or not, without leaving the destination deleted and the new file not moved in place.

This is intended mainly for use in implementing LockDir.

def move(self, rel_from, rel_to):
Move the item at rel_from to the location at rel_to
def delete(self, relpath):
Delete the item at relpath
def external_url(self):
See bzrlib.transport.Transport.external_url.
def copy_to(self, relpaths, other, mode=None, pb=None):
Copy a set of entries from self into another Transport.
ParametersrelpathsA list/generator of entries to be copied.
def listable(self):
See Transport.listable.
def list_dir(self, relpath):
Return a list of all files at the given location. WARNING: many transports do not support this, so trying avoid using it if at all possible.
def stat(self, relpath):
Return the stat information for a file.
def lock_read(self, relpath):
Lock the given file for shared (read) access. :return: A lock object, which should be passed to Transport.unlock()
def lock_write(self, relpath):
Lock the given file for exclusive (write) access. WARNING: many transports do not support this, so trying avoid using it
ReturnsA lock object, which should be passed to Transport.unlock()
def rmdir(self, relpath):
See Transport.rmdir.
def readlink(self, relpath):
See Transport.readlink.
def hardlink(self, source, link_name):
See Transport.link.
def symlink(self, source, link_name):
See Transport.symlink.
def _can_roundtrip_unix_modebits(self):
Return true if this transport can store and retrieve unix modebits.

(For example, 0700 to make a directory owner-private.)

Note: most callers will not want to switch on this, but should rather just try and set permissions and let them be either stored or not. This is intended mainly for the use of the test suite.

Warning: this is not guaranteed to be accurate as sometimes we can't be sure: for example with vfat mounted on unix, or a windows sftp server.

API Documentation for Bazaar, generated by pydoctor at 2022-01-22 00:20:18.