-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_appwrite.py
More file actions
133 lines (99 loc) · 4.44 KB
/
Copy pathmy_appwrite.py
File metadata and controls
133 lines (99 loc) · 4.44 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
127
128
129
130
131
132
133
from appwrite.role import Role
import env
import server
def set_funcao(nome_funcao, runtime='python-3.9', execute=None, timeout=120, events=None, cliente=None):
funcao(nome_funcao, runtime, execute, timeout, events)
variable(nome_funcao=nome_funcao, cliente=cliente)
deploy(nome_funcao, runtime=runtime)
def funcao(nome_funcao, runtime='python-3.9', execute=None, timeout=30, events=None):
if execute is None:
execute = [Role.users()]
try:
server.functions.get(nome_funcao)
server.functions.update(nome_funcao, nome_funcao, execute=execute, timeout=timeout, events=events)
print(f'\U0001F195 funcao {nome_funcao} atualizada')
except:
server.functions.create(nome_funcao, nome_funcao, execute=execute,
runtime=runtime,
timeout=timeout,
events=events
)
print(f'\U0001F195 funcao {nome_funcao} CRIADA')
def variable(nome_funcao, cliente=None,):
variables = server.functions.list_variables(nome_funcao)
db = False
projeto = False
key = False
host = False
cliente_v = True
if cliente is not None:
cliente_v = False
for item in variables['variables']:
if item['key'] == 'db':
db = True
server.functions.update_variable(nome_funcao, item['$id'], "db", env.db)
continue
if item['key'] == 'host':
host = True
server.functions.update_variable(nome_funcao, item['$id'], "host", env.host)
continue
if item['key'] == 'projeto':
projeto = True
server.functions.update_variable(nome_funcao, item['$id'], "projeto",
env.project)
continue
if item['key'] == 'key':
key = True
server.functions.update_variable(nome_funcao, item['$id'], "key",
env.function_key)
continue
if cliente:
if item['key'] == 'cliente':
cliente_v = True
server.functions.update_variable(nome_funcao, item['$id'], "cliente",
env.cliente)
continue
else:
cliente_v = False
if not host:
server.functions.create_variable(nome_funcao, "host", env.host)
if not db:
server.functions.create_variable(nome_funcao, "db", env.db)
if not projeto:
server.functions.create_variable(nome_funcao, "projeto", env.project)
if not key:
server.functions.create_variable(nome_funcao, "key", env.function_key)
if not cliente_v:
server.functions.create_variable(nome_funcao, "cliente", env.cliente)
print(f'\U0001F195 variables {nome_funcao} criada')
def deploy(nome_funcao, runtime='python-3.9'):
import subprocess
extensao = 'py'
arquivo = f'{nome_funcao}.{extensao}'
caminho = f'cd function/{nome_funcao}/'
set_projeto = f'appwrite client --endpoint {env.host} --projectId {env.project} --key {env.key}'
if 'dart' in runtime.lower():
arquivo = 'main.dart'
enviar = f'appwrite functions createDeployment --functionId={nome_funcao} --activate=true --entrypoint="{arquivo}" --code="."'
p = subprocess.Popen(f'{caminho};'
f'{set_projeto};'
f'{enviar}',
stdout=subprocess.PIPE, shell=True)
print(p.communicate())
def login_cli():
import subprocess
# Configura o cliente da plataforma Appwrite
cmd_client = f'appwrite client --endpoint {env.host} --projectId {env.project} --key {env.key}'
process_client = subprocess.Popen(cmd_client, stdout=subprocess.PIPE, shell=True)
# Obtém a saída do processo de configuração do cliente
output_client = process_client.communicate()[0]
# Exibe a saída do processo de configuração do cliente
print(output_client.decode('utf-8'))
process = subprocess.Popen('appwrite login', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True)
process.stdin.write(env.cli_email.encode('utf-8') + b'\n')
process.stdin.write(env.cli_password.encode('utf-8') + b'\n')
# Obtém a saída do processo
output, errors = process.communicate()
# Exibe a saída do processo
print(output.decode('utf-8'))