|
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 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | import array |
|---|
| 6 | import stat |
|---|
| 7 | |
|---|
| 8 | from time import time, strftime, localtime |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | def 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 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 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(): |
|---|
| 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'] |
|---|