Returns the allocated disk space for the given path in bytes.

    :param path: String representing the path as it would be given to the `du`
      command. Best to give an absolute path here.
174471
def get_disk_usage(path):
    
    cmd = 'du -sh --block-size=1 {0}'.format(path)
    total = getoutput(cmd).split()[0]
    return int(total)
571378
def raw_filesize(path):
    # type: (str) -> Optional[int]
    
    with open('/dev/null', 'w') as devnull:
        status, output = shell("du", "-bs", path, raise_on_status=False,
                               stderr=devnull)
    if status != 0:
        return None
    # output is: <size>\t<path>\n
    return int(output.split("\t", 1)[0])
1312768
def tar_files(self, path: Path) -> bytes:
        
        tarstream = BytesIO()
        tar = tarfile.TarFile(fileobj=tarstream, mode='w')
        tar.add(str(path), arcname="data", recursive=True)
        tar.close()
        return tarstream.getvalue()
1066092
def size(pathname):
    
    if os.path.isfile(pathname):
        return os.path.getsize(pathname)
    return sum([size('{}/{}'.format(pathname, name)) for name in get_content_list(pathname)])
497570
def file_or_folder(path):
        
        target = unicode(path)
        return Folder(target) if os.path.isdir(target) else File(target)
1009399
def isempty(path):
    
    if op.isdir(path):
        return [] == os.listdir(path)
    elif op.isfile(path):
        return 0 == os.stat(path).st_size
    return None
260628
def _allocate_disk_space(self):
        # type: (Descriptor) -> None
        
        with self._meta_lock:
            if self._allocated or self._offset != 0:
                return
            # set local path view
            allocatesize = self._set_final_path_view()
            # check if path already exists and is of sufficient size
            if (not self.final_path.exists() or
                    self.final_path.stat().st_size != allocatesize):
                # create parent path
                self.final_path.parent.mkdir(
                    mode=0o750, parents=True, exist_ok=True)
                # allocate file
                with self.final_path.open('wb') as fd:
                    if allocatesize > 0:
                        try:
                            os.posix_fallocate(fd.fileno(), 0, allocatesize)
                        except AttributeError:
                            fd.seek(allocatesize - 1)
                            fd.write(b'\0')
            self._allocated = True
501946
def _get_checksum(path):
    

    # md5 uses a 512-bit digest blocks, let's scale by defined block_size
    _md5 = hashlib.md5()
    chunk_size = 128 * _md5.block_size

    try:
        with open(path, 'rb') as _file:
            for chunk in iter(lambda: _file.read(chunk_size), ''):
                _md5.update(chunk)
        return _md5.hexdigest()

    except IOError:
        return None
433901
def _get_long_path_name(path):
  

  # Thanks to http://stackoverflow.com/a/3694799/791713
  buf = ctypes.create_unicode_buffer(len(path) + 1)
  GetLongPathNameW = ctypes.windll.kernel32.GetLongPathNameW
  res = GetLongPathNameW(path, buf, len(path) + 1)
  if res == 0 or res > 260:
    return path
  else:
    return buf.value
704952
def resource_string(self, path):
        
        opener = self.get_opener(path)
        filename = opener.get_filename
        try:
            size = os.path.getsize(filename)
            if size > 50 * 1024 * 1024:
                logger.warning(
                    'Reading large resource to memory: %s. Size: %s bytes',
                    filename, size)
        except Exception as exc:
            logger.debug('Unable to check resource size %s. %s', filename, exc)
        with opener(filename, 'r') as resource:
            content = resource.read()
        return content
566412
def read(path):
    
    data = None
    with open(path, 'r') as f:
        data = f.read()
    f.close()
    return data
414098
def __folder_size(self, path):
        """"""

        ret = 0
        for f in scandir(path):
            if f.is_dir() and (f.name != '.' or f.name != '..'):
                ret += self.__folder_size(os.path.join(path, f.name))
            else:
                try:
                    ret += f.stat().st_size
                except OSError:
                    pass

        return ret
1367479
def get_base_path(path):
        
        if "%" not in path:
            return path

        path = os.path.split(path)[0]

        while "%" in path:
            path = os.path.split(path)[0]

        return path
1162752
def get_full_archive_path(self, path):
        
        return os.path.join(self.archive_dir, path.lstrip('/'))
1137737
def absolute_path(self, path, start):
        
        if posixpath.isabs(path):
            path = posixpath.join(staticfiles_storage.location, path)
        else:
            path = posixpath.join(start, path)
        return posixpath.normpath(path)
504077
def _SetPath(self, path):
    
    old_path = self._path
    if old_path and not io_wrapper.IsCloudPath(old_path):
      try:
        # We're done with the path, so store its size.
        size = tf.io.gfile.stat(old_path).length
        logger.debug('Setting latest size of %s to %d', old_path, size)
        self._finalized_sizes[old_path] = size
      except tf.errors.OpError as e:
        logger.error('Unable to get size of %s: %s', old_path, e)

    self._path = path
    self._loader = self._loader_factory(path)
156416
def count(self, path):
        
        try:
            res = self.get_bite().count(self.list_path(path)).next()
            dir_count = res['directoryCount']
            file_count = res['fileCount']
            content_size = res['spaceConsumed']
        except StopIteration:
            dir_count = file_count = content_size = 0
        return {'content_size': content_size, 'dir_count': dir_count,
                'file_count': file_count}