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
|
import base64
from photoblaster.modules import ModuleBase
import urlparse
import re
from photoblaster._file import File
class PbLandscape(ModuleBase):
try:
example_params = {
'imgdata': open(
'./photoblaster/modules/pblandscape/_base64img', 'rb').read(),
'texture': 'http://someurl.biz/someimg.jpg',
'heightmap': 'http://someurl.biz/someimg.jpg',
'name': 'donkey'
}
except:
example_params = {}
def __init__(self, **kwargs):
super(PbLandscape, self).__init__(**kwargs)
_definitions = {
'heightmap': {'type': 'string'},
'imgdata': {'type': 'raw'},
'texture': {'type': 'string'},
'username': {'type': 'string'},
}
self.params.definitions_import(
_definitions,
kwargs,
classname=self.__class__.__name__)
namepart = re.sub(r'https?:?/?/?', '', str(self.params.texture))
self.set_output_file(
File(
namepart=namepart,
classname=self.__class__.__name__,
extension="png",
username=self.params.username
)
)
self._db_url_param = str(self.params.texture)
def _saveImgData(self):
try:
up = urlparse.urlparse(str(self.params.imgdata))
head, data = up.path.split(',', 1)
# bits = head.split(';')
# Do something smart with charset and b64 instead of assuming
plaindata = base64.b64decode(data)
with open(
self.get_output_file().get_filepath(), 'wb') as f:
f.write(plaindata)
except Exception as e:
self.err_warn(str(e))
def create(self):
self._saveImgData()
super(PbLandscape, self).create()
def get_class():
return PbLandscape
|