bucket_convert_colons - jaybgager/tracertools GitHub Wiki
This function converts file names or paths that contain colons to a Windows-safe alternative and back. This is most commonly used when creating legacy-format neuroglancer volumes with single-resolution unsharded meshes in them and uploading or downloading them to/from a bucket. These types of files require colons in their names - a format forbidden by the Windows OS, which strictly reserves the colon character for drive names (e.g. "C:").
Specifically, this function converts between ":" colon characters and "___" triple-underscores, a generally safe and unused character combination for file storage and access that shouldn't cause side effects.
Arguments:
- file_path (string, mandatory)
- the file name or path you want to convert
- to_windows (boolean, optional, default=True)
- whether you're going from non-windows to Windows (True) or Windows to non-Windows (False)
Returns:
- output_file_path (string)
- the converted file name or path
Examples
Going To Windows From Non-Windows
INPUT:
import tracertools as tt
windows_path = tt.bucket_convert_colons(
file_path = "/home/user/volumes/vol_01/mesh/1:0:1"
)
print(windows_path)
OUTPUT:
"/home/user/volumes/vol_01/mesh/1___0___1"
Going From Windows To Non-Windows
INPUT:
import tracertools as tt
print(
tt.bucket_convert_colons(
file_path = "/home/user/volumes/vol_01/mesh/1___0___1",
to_windows = False,
)
)
OUTPUT:
"/home/user/volumes/vol_01/mesh/1:0:1"