Пример #1
0
def cleantree(tgt_fs: FS, name: str):
    method = tgt_fs.remove if tgt_fs.isfile(name) else tgt_fs.removetree
    method(name)
    remaining_parts = Path(name).parts
    if len(remaining_parts) > 1:
        # if dst_path included more than 1 directory we are left with the top parent
        tgt_fs.removedir(remaining_parts[0])
Пример #2
0
 def __init__(
     self,
     contains_lidvids: bool,
     subcomponents: Set[S],
     fs: FS,
     filepaths: Set[str],
 ) -> None:
     """
     Create a 'VersionContents' object.  DO NOT USE this
     constructor.  Instead use the static methods
     VersionContents.create_from_lids() and
     VersionContents.create_from_lidvids().
     """
     if not _data_consistent(contains_lidvids, subcomponents):
         raise TypeError(
             "Subcomponents are not consistent, should be all "
             + "livids or all lids."
         )
     self.contains_lidvids = contains_lidvids
     self.subcomponents: Set[S] = subcomponents
     for filepath in filepaths:
         if not isabs(filepath):
             raise ValueError(f"{filepath} is not an absolute path.")
         if not fs.isfile(filepath):
             raise ValueError(f"{filepath} is not a file.")
     self.fs = fs
     self.filepaths = filepaths
Пример #3
0
def _checkin(src_fs: FS,
             src_path: str,
             dst_fs: FS,
             dst_path: str,
             move: bool = False):
    dst_dir = Path(dst_path).parent.as_posix()
    if not dst_fs.exists(dst_dir):
        dst_fs.makedirs(dst_dir)
    if src_fs.isfile(src_path):
        method = move_file if move else copy_file
    else:
        method = move_dir if move else copy_dir
    method(src_fs, src_path, dst_fs, dst_path)
    if move:
        src_fs.settext(rf'{src_path}.checkin',
                       json.dumps({repr(dst_fs): dst_path}))
    return dst_fs, dst_path