forked from kerlomz/captcha_platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.py
83 lines (64 loc) · 2.49 KB
/
package.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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Author: kerlomz <[email protected]>
import os
import time
import stat
import socket
import paramiko
import platform
import distutils
import tensorflow as tf
tf.compat.v1.disable_v2_behavior()
from enum import Enum, unique
from utils import SystemUtils
from config import resource_path
from PyInstaller.__main__ import run, logger
""" Used to package as a single executable """
if platform.system() == 'Linux':
if distutils.distutils_path.endswith('__init__.py'):
distutils.distutils_path = os.path.dirname(distutils.distutils_path)
with open("./resource/VERSION", "w", encoding="utf8") as f:
today = time.strftime("%Y%m%d", time.localtime(time.time()))
f.write(today)
@unique
class Version(Enum):
CPU = 'CPU'
GPU = 'GPU'
if __name__ == '__main__':
ver = Version.CPU
upload = False
server_ip = ""
username = ""
password = ""
model_dir = "model"
graph_dir = "graph"
if ver == Version.GPU:
opts = ['tornado_server_gpu.spec', '--distpath=dist']
else:
opts = ['tornado_server.spec', '--distpath=dist']
run(opts)
if upload:
transport = paramiko.Transport(sock=(server_ip, 22))
transport.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(transport)
with open("dist/start.sh", "w", encoding="utf8") as f:
f.write("nohup ./captcha_platform_tornado &")
SystemUtils.empty(sftp, '/home/captcha_platform')
logger.info('uploading app...')
SystemUtils.empty(sftp, '/home/captcha_platform/graph')
SystemUtils.empty(sftp, '/home/captcha_platform/model')
for model in os.listdir(model_dir):
if os.path.isdir(model):
continue
sftp.put(os.path.join(model_dir, model), '/home/captcha_platform/model/{}'.format(model))
for graph in os.listdir(graph_dir):
sftp.put(os.path.join(graph_dir, graph), '/home/captcha_platform/graph/{}'.format(graph))
sftp.put("dist/captcha_platform_tornado", '/home/captcha_platform/captcha_platform_tornado')
sftp.put("dist/start.sh", '/home/captcha_platform/start.sh')
sftp.put("config.yaml", '/home/captcha_platform/config.yaml')
sftp.chmod('/home/captcha_platform/captcha_platform_tornado', stat.S_IRWXU)
sftp.chmod('/home/captcha_platform/start.sh', stat.S_IRWXU)
logger.info('uploaded.')
logger.info('update completed!')
transport.close()