root/trunk/twisted/conch/ls.py

Revision 25412, 1.7 KB (checked in by exarkun, 22 months ago)

Merge lsline-3503

Author: exarkun
Reviewer: therve
Fixes: #3503

Fix the status listing formatting function twisted.conch.ls.lsLine so that
it formats days properly on Windows and so that it includes the actually value
for the minute field in the minute field instead of using the value for the
seconds field instead.

Line 
1# -*- test-case-name: twisted.conch.test.test_cftp -*-
2# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
3# See LICENSE for details.
4
5import array
6import stat
7
8from time import time, strftime, localtime
9
10
11def lsLine(name, s):
12    mode = s.st_mode
13    perms = array.array('c', '-'*10)
14    ft = stat.S_IFMT(mode)
15    if stat.S_ISDIR(ft): perms[0] = 'd'
16    elif stat.S_ISCHR(ft): perms[0] = 'c'
17    elif stat.S_ISBLK(ft): perms[0] = 'b'
18    elif stat.S_ISREG(ft): perms[0] = '-'
19    elif stat.S_ISFIFO(ft): perms[0] = 'f'
20    elif stat.S_ISLNK(ft): perms[0] = 'l'
21    elif stat.S_ISSOCK(ft): perms[0] = 's'
22    else: perms[0] = '!'
23    # user
24    if mode&stat.S_IRUSR:perms[1] = 'r'
25    if mode&stat.S_IWUSR:perms[2] = 'w'
26    if mode&stat.S_IXUSR:perms[3] = 'x'
27    # group
28    if mode&stat.S_IRGRP:perms[4] = 'r'
29    if mode&stat.S_IWGRP:perms[5] = 'w'
30    if mode&stat.S_IXGRP:perms[6] = 'x'
31    # other
32    if mode&stat.S_IROTH:perms[7] = 'r'
33    if mode&stat.S_IWOTH:perms[8] = 'w'
34    if mode&stat.S_IXOTH:perms[9] = 'x'
35    # suid/sgid
36    if mode&stat.S_ISUID:
37        if perms[3] == 'x': perms[3] = 's'
38        else: perms[3] = 'S'
39    if mode&stat.S_ISGID:
40        if perms[6] == 'x': perms[6] = 's'
41        else: perms[6] = 'S'
42    l = perms.tostring()
43    l += str(s.st_nlink).rjust(5) + ' '
44    un = str(s.st_uid)
45    l += un.ljust(9)
46    gr = str(s.st_gid)
47    l += gr.ljust(9)
48    sz = str(s.st_size)
49    l += sz.rjust(8)
50    l += ' '
51    sixmo = 60 * 60 * 24 * 7 * 26
52    if s.st_mtime + sixmo < time(): # last edited more than 6mo ago
53        l += strftime("%b %d  %Y ", localtime(s.st_mtime))
54    else:
55        l += strftime("%b %d %H:%M ", localtime(s.st_mtime))
56    l += name
57    return l
58
59
60__all__ = ['lsLine']
Note: See TracBrowser for help on using the browser.