-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
daemon_get_exports.py
58 lines (53 loc) · 1.92 KB
/
daemon_get_exports.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
50
51
52
53
54
55
56
57
58
__filename__ = "daemon_get_exports.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.5.0"
__maintainer__ = "Bob Mottram"
__email__ = "[email protected]"
__status__ = "Production"
__module_group__ = "Core GET"
import os
from httpcodes import http_404
from httpcodes import write2
from httpheaders import set_headers
from httpheaders import set_headers_etag
from utils import get_nickname_from_actor
from blocking import export_blocking_file
def get_exported_blocks(self, path: str, base_dir: str,
domain: str,
calling_domain: str) -> None:
"""Returns an exported blocks csv file
"""
filename = path.split('/exports/', 1)[1]
filename = base_dir + '/exports/' + filename
nickname = get_nickname_from_actor(path)
if nickname:
blocks_str = export_blocking_file(base_dir, nickname, domain)
if blocks_str:
msg = blocks_str.encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/csv',
msglen, None, calling_domain, False)
write2(self, msg)
return
http_404(self, 20)
def get_exported_theme(self, path: str, base_dir: str,
domain_full: str) -> None:
"""Returns an exported theme zip file
"""
filename = path.split('/exports/', 1)[1]
filename = base_dir + '/exports/' + filename
if os.path.isfile(filename):
export_binary = None
try:
with open(filename, 'rb') as fp_exp:
export_binary = fp_exp.read()
except OSError:
print('EX: unable to read theme export ' + filename)
if export_binary:
export_type = 'application/zip'
set_headers_etag(self, filename, export_type,
export_binary, None,
domain_full, False, None)
write2(self, export_binary)
http_404(self, 19)