-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhelpers.py
More file actions
126 lines (101 loc) · 2.5 KB
/
helpers.py
File metadata and controls
126 lines (101 loc) · 2.5 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from application import app
from flask import render_template
import time
def flatten(l):
for el in l:
if hasattr(el, "__iter__") and not isinstance(el, basestring):
for sub in flatten(el):
yield sub
else:
yield el
def parse_options_header(header):
headers = map(lambda s: s.strip(), header.split(';'))
def split_quotes(s):
if len(s) < 2:
return s
if s[0] == s[-1] == '"' or s[0] == s[-1] == '\'':
return s[1:-2]
else:
return s
def parse_header(s):
if '=' in s:
tmp1 = [split_quotes(x) for x in s.split('=')]
if len(tmp1) < 2:
return {tmp1: tmp1}
else:
return {tmp1[0]: s[len(tmp1[0]) + 2:-1]}
elif ':' in s:
tmp1 = [split_quotes(x) for x in s.split(':')]
if len(tmp1) < 2:
return {tmp1: tmp1}
else:
return {tmp1[0]: s[len(tmp1[0]) + 1]}
else:
return {s: s}
headers = [parse_header(x) for x in headers]
return headers
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
def datetimeformat(value, format='%H:%M / %d-%m-%Y'):
return time.strftime(format, time.localtime(value))
def random_file_name():
import random, hashlib
r = random.random()
m = hashlib.md5()
m.update(str(r))
return m.hexdigest()
def get_file_content(filepath):
file = open(filepath)
data = file.read()
file.close()
return data
def move_file_to_store(data, name, type, tags):
from application import db
from flask import url_for
from docs import Blob
from models import Resource
blob_key = Blob(data).save()
resource = Resource(name=name, type=type, blob_key=blob_key, tags=tags)
db.session.add(resource)
db.session.commit()
return url_for('resource.get_by_name', resource_name=name)
def gen_mesh_obj_json(geom_url):
result = {}
result['version'] = '0.0.1'
result['meshName'] = 'mesh_from_obj'
result['typeName'] = 'mesh from obj'
result['meshType'] = 'mesh_from_obj'
result['thumbnailUrl'] = ''
result['type'] = 'import'
result['geometry_url'] = geom_url
result['material'] = {
'type': 'basic',
'map': {
'url': get_default_texture()
},
'transparent': True,
'opacity': 1
}
result['receiveShadow'] = True
result['doubleSided'] = True
result['castShadow'] = True
result['position'] = {
'x': 0,
'y': 0,
'z': 0
}
result['rotation'] = {
'x': 0,
'y': 0,
'z': 0
}
result['scale'] = {
'x': 1.0,
'y': 1.0,
'z': 1.0
}
return result
def get_default_texture():
return "/static/resources/images/shicai/shicai005.jpg"
env = app.jinja_env
env.filters['datetimeformat'] = datetimeformat