-
Notifications
You must be signed in to change notification settings - Fork 0
/
intall_then_invoke_plugin_immediately.py
113 lines (102 loc) · 6.1 KB
/
intall_then_invoke_plugin_immediately.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
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
# encoding: utf-8
"""
当在这个脚本里用base64_en_de.py把一段字符串->zip包
解压缩zip包并安装成为plugin
**要在这个脚本里能立即调用这个插件**
"""
import tempfile
import base64_en_de
import os
import zipfile
import subprocess
import shutil
from stevedore.driver import DriverManager
# scheduler目录和setup.py -> scheduler.zip -> base64_en_de.encode_zip_to_string -> DATA
DATA = """
UEsDBAoAAAAAAAlI5EgAAAAAAAAAAAAAAAAKABwAc2NoZWR1bGVyL1VUCQADEYh6V3AFfVd1eAsAAQQ
AAAAABAAAAABQSwMEFAAAAAgAoEXkSEQJAUoQAQAAJQIAAAgAHABzZXR1cC5weVVUCQADe4R6V9kHfV
d1eAsAAQQAAAAABAAAAABtkU1rwzAMhu/5FYYe3EIXVgY7BAzdDrvttlsZQUuU1sy2jOwUsrH/Pi9Ou
rWrLsKP9OrLHZMVAWPvI5EJQltPHDNZi067tvbQvMMeQzHCZSGSObCoZCCGm9AcsO0NslyPoSNy0OSU
3JS3E2oxNKx9HPGPqLwUQR8PxEo+w6N2+zNYowVtlGx6G+sYebu5vysbslOSNxA7YhvUTj64Qb5mnBs
mmN8L4ZmOOg2S0q5NsBC/NpWY91ZnV1iuclS7xvQtzrxuIYJ64R5zGF3kofakXRris5hLX/auxK7401
lIi5Z4eIOAQolTXplxld3l8U5iBteS/ScO6VMNVtldE08Lf2X3oX0doEP1BCakdVbFN1BLAwQKAAAAA
AAD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9AEAABIAGAAAAAAAAAAAAKSB5QEAAHNjaGVkdWxlci9iYXNlLnB5Y1VU
BQADm3B6V3V4CwABBAAAAAAEAAAAAFBLAQIeAxQAAAAIAIY65EhJg3/2SQAAAGwAAAAWABgAAAAAAAA
AAACkgTkDAABzY2hlZHVsZXIvX19pbml0X18ucHljVVQFAAObcHpXdXgLAAEEAAAAAAQAAAAAUEsBAh
4DFAAAAAgAdkfkSORhfyGsAAAA9gAAABMAGAAAAAAAAQAAAKSB0gMAAHNjaGVkdWxlci9tZW1vcnkuc
HlVVAUAA/CHeld1eAsAAQQAAAAABAAAAABQSwECHgMUAAAACAAsNuRI993dQYMAAACvAAAAEQAYAAAA
AAABAAAApIHLBAAAc2NoZWR1bGVyL2Jhc2UucHlVVAUAA2Rpeld1eAsAAQQAAAAABAAAAABQSwECHgM
UAAAACAAJSORIr76d6V8BAAB5AgAAFAAYAAAAAAAAAAAApIGZBQAAc2NoZWR1bGVyL3NpbXBsZS5weW
NVVAUAAxGIeld1eAsAAQQAAAAABAAAAABQSwECHgMUAAAACAAGSORIQnJN5K8AAAAAAQAAEwAYAAAAA
AABAAAApIFGBwAAc2NoZWR1bGVyL3NpbXBsZS5weVVUBQADC4h6V3V4CwABBAAAAAAEAAAAAFBLAQIe
AxQAAAAIAAlI5Ej68PtTUQEAAGMCAAAUABgAAAAAAAAAAACkgUIIAABzY2hlZHVsZXIvbWVtb3J5LnB
5Y1VUBQADEYh6V3V4CwABBAAAAAAEAAAAAFBLBQYAAAAACgAKAGoDAADhCQAAAAA=
"""
TMPDIR = tempfile.mkdtemp(prefix='sora')
ZIP_FILE_NAME = 'scheduluer.zip'
def unzip(source_filename, dest_dir):
with zipfile.ZipFile(source_filename) as zf:
zf.extractall(dest_dir)
def install_plugin():
file_path = '%s%s%s' % (TMPDIR, os.sep, ZIP_FILE_NAME)
base64_en_de.decode_string_to_zip(DATA, '\n', '', file_path)
unzip(file_path, TMPDIR)
cmd = 'python setup.py install'
sub = subprocess.Popen(cmd.split(), stderr=subprocess.PIPE, stdout=subprocess.PIPE, cwd=TMPDIR)
sub.wait()
def clear():
shutil.rmtree(TMPDIR, ignore_errors=True)
shutil.rmtree('/usr/local/lib/python2.7/dist-packages/sora_scheduler-1.0-py2.7.egg', ignore_errors=True)
if __name__ == '__main__':
print 'TMPDIR = %s' % TMPDIR
install_plugin()
try:
mgr = DriverManager(namespace='sora.scheduler', name='memorybase', invoke_on_load=True)
dt = {13: 'id1', 324: 'id2', 434: 'id3', 'memory': [13, 324, 434]}
mgr.driver.scheduler(dt)
except Exception as exc_info:
print '*' * 80
print "When try to load plugin, errors happen,detail: %s" % str(exc_info)
print '*' * 80
finally:
clear()