]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - backend/misc.py
3 from __future__
import division
10 from tornado
.escape
import xhtml_escape
12 from constants
import *
15 units
= ("B", "k", "M", "G", "T")
18 while s
>= 1024 and i
< len(units
):
22 return "%d%s" % (round(s
), units
[i
])
32 ret
.append("%s w" % (t
// 604800))
36 ret
.append("%s d" % (t
// 38400))
40 ret
.append("%s h" % (t
// 3600))
44 ret
.append("%s m" % (t
// 60))
48 ret
.append("%s s" % t
)
52 def format_email(email
):
53 m
= re
.match(r
"(.*) <(.*)>", email
)
56 "name" : xhtml_escape(m
.group(1)),
57 "mail" : xhtml_escape(m
.group(2)),
61 "name" : xhtml_escape(email
),
62 "mail" : xhtml_escape(email
),
65 return """<a class="email" href="mailto:%(mail)s">%(name)s</a>""" % fmt
67 def format_filemode(filetype
, filemode
):
75 return prefix
+ tarfile
.filemode(filemode
)[1:]
77 def calc_hash(filename
, algo
="sha512"):
78 assert algo
in hashlib
.algorithms
79 assert os
.path
.exists(filename
)
81 f
= open(filename
, "rb")
85 buf
= f
.read(BUFFER_SIZE
)
95 def calc_hash1(filename
):
98 return calc_hash(filename
, "sha1")
100 def guess_filetype(filename
):
101 # XXX very cheap check. Need to do better here.
102 if tarfile
.is_tarfile(filename
):
105 elif filename
.endswith(".log"):