Trees | Indices | Help |
|
---|
|
1 #-*- coding: utf8 -* 2 # 3 # Max E. Kuznecov ~syhpoon <syhpoon@syhpoon.name> 2008 4 # 5 # This file is part of XYZCommander. 6 # XYZCommander is free software: you can redistribute it and/or modify 7 # it under the terms of the GNU Lesser Public License as published by 8 # the Free Software Foundation, either version 3 of the License, or 9 # (at your option) any later version. 10 # XYZCommander is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU Lesser Public License for more details. 14 # You should have received a copy of the GNU Lesser Public License 15 # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>. 16 17 import stat 18 19 from libxyz.vfs import types as vfstypes 20 21 _types = ( 22 (stat.S_ISDIR, vfstypes.VFSTypeDir), 23 (stat.S_ISCHR, vfstypes.VFSTypeChar), 24 (stat.S_ISBLK, vfstypes.VFSTypeBlock), 25 (stat.S_ISREG, vfstypes.VFSTypeFile), 26 (stat.S_ISFIFO, vfstypes.VFSTypeFifo), 27 (stat.S_ISLNK, vfstypes.VFSTypeLink), 28 (stat.S_ISSOCK, vfstypes.VFSTypeSocket), 29 ) 3032 """ 33 Find out file type 34 @param st_mode: Raw st_mode obtained from os.stat() 35 """ 36 37 global _types 38 39 for _test, _type in _types: 40 if _test(st_mode): 41 return _type() 42 43 return vfstypes.VFSTypeUnknown()44 45 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4648 """ 49 Format file-object size 50 """ 51 52 _s = long(size) 53 54 _data = ( 55 (1024 * 1024 * 1024, u"G", lambda x, y: u"%.2f" % (float(x) / y)), 56 (1024 * 1024, u"M", lambda x, y: unicode(x / y)), 57 (1024, u"K", lambda x, y: unicode(x / y)), 58 ) 59 60 for _size, _suffix, _func in _data: 61 if _s >= _size: 62 return u"%s%s" % (_func(_s, _size), _suffix) 63 64 return size65
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Aug 3 02:02:17 2009 | http://epydoc.sourceforge.net |