forked from opengridcc/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
49 lines (35 loc) · 1.28 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import time
from flask import safe_join
class Plot(object):
def __init__(self, title, description=None, content=None):
self.title = title
self.description = description
self._content = None
self.set_content(content)
def set_content(self, content):
self._content = content
def get_content(self):
return self._content
def has_content(self):
return self._content is not None
def is_html(self):
return isinstance(self, Html)
def is_figure(self):
return isinstance(self, Figure)
class Figure(Plot):
def __init__(self, *args, **kwargs):
super(Figure, self).__init__(*args, **kwargs)
class Html(Plot):
def __init__(self, *args, **kwargs):
super(Html, self).__init__(*args, **kwargs)
def set_content(self, path):
if os.path.exists(path):
with open(path, "r") as html_graph:
self._content = html_graph.read()
class Notebook(Plot):
def __init__(self, path, *args, **kwargs):
super(Notebook, self).__init__(*args, **kwargs)
file = safe_join(path, self.title)
self.date_modified = time.ctime(os.path.getmtime(file))
self.filesize = os.path.getsize(file) / 1024