This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Wrapper: | |
def __init__(self, wrapped_class): | |
self.wrapped_class = wrapped_class() | |
def __getattr__(self, item): | |
attr = self.wrapped_class.__getattribute__(item) | |
if callable(attr): | |
@wraps(attr) | |
def wrap(*args, **kwargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render_without_context(template_name, **context): | |
env = jinja2.Environment( | |
loader=jinja2.PackageLoader('ui') | |
) | |
template = env.get_template(template_name) | |
return template.render(**context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_size(size_bytes): | |
if size_bytes == 0: | |
return "0B" | |
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") | |
i = int(math.floor(math.log(size_bytes, 1024))) | |
p = math.pow(1024, i) | |
s = round(size_bytes / p, 2) | |
return "%s %s" % (s, size_name[i]) |
NewerOlder