Revision 3f6a47a8 lib/utils.py
b/lib/utils.py | ||
---|---|---|
1847 | 1847 |
return ", ".join(["'%s'" % val for val in names]) |
1848 | 1848 |
|
1849 | 1849 |
|
1850 |
def BytesToMebibyte(value): |
|
1851 |
"""Converts bytes to mebibytes. |
|
1852 |
|
|
1853 |
@type value: int |
|
1854 |
@param value: Value in bytes |
|
1855 |
@rtype: int |
|
1856 |
@return: Value in mebibytes |
|
1857 |
|
|
1858 |
""" |
|
1859 |
return int(round(value / (1024.0 * 1024.0), 0)) |
|
1860 |
|
|
1861 |
|
|
1862 |
def CalculateDirectorySize(path): |
|
1863 |
"""Calculates the size of a directory recursively. |
|
1864 |
|
|
1865 |
@type path: string |
|
1866 |
@param path: Path to directory |
|
1867 |
@rtype: int |
|
1868 |
@return: Size in mebibytes |
|
1869 |
|
|
1870 |
""" |
|
1871 |
size = 0 |
|
1872 |
|
|
1873 |
for (curpath, _, files) in os.walk(path): |
|
1874 |
for file in files: |
|
1875 |
st = os.lstat(os.path.join(curpath, file)) |
|
1876 |
size += st.st_size |
|
1877 |
|
|
1878 |
return BytesToMebibyte(size) |
|
1879 |
|
|
1880 |
|
|
1881 |
def GetFreeFilesystemSpace(path): |
|
1882 |
"""Returns the free space on a filesystem. |
|
1883 |
|
|
1884 |
@type path: string |
|
1885 |
@param path: Path on filesystem to be examined |
|
1886 |
@rtype: int |
|
1887 |
@return: Free space in mebibytes |
|
1888 |
|
|
1889 |
""" |
|
1890 |
st = os.statvfs(path) |
|
1891 |
|
|
1892 |
return BytesToMebibyte(st.f_bavail * st.f_frsize) |
|
1893 |
|
|
1894 |
|
|
1850 | 1895 |
def LockedMethod(fn): |
1851 | 1896 |
"""Synchronized object access decorator. |
1852 | 1897 |
|
Also available in: Unified diff