-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdater.py
85 lines (63 loc) · 1.86 KB
/
Updater.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# MODULES
from vars import *
import os
import sys
import time
import shutil
import logging
import wget
from zipfile import ZipFile
from distutils.dir_util import copy_tree
# APP START
# gettext multilang
_ = translate.gettext
translate.install()
if os.path.exists(updateDirPath):
# print("Update exist!")
if os.path.isfile(updateDirPath):
# print("Update is NOT a directiry! Remove file Update")
os.remove(updateDirPath, dir_fd=None)
else:
# print("Update is a directory! Remove directory Update")
shutil.rmtree(updateDirPath)
# print("Create directory Update")
os.mkdir(updateDirPath, mode=0o777, dir_fd=None)
else:
# print("Update DOESN'T exist! Create directory Update")
os.mkdir(updateDirPath, mode=0o777, dir_fd=None)
try:
# get file update
print(_("App update..."))
print("\r")
# download app update
wget.download("ftp://" + ftpServerUser + ":" + ftpServerPass + "@" + ftpServerHost + ":" + ftpServerPort + ftpPath +
appNameZip, out=updateDirPath)
# wait update for write to disk
time.sleep(5)
print("\n")
# try unzip
try:
# unzip app
with ZipFile(updateDirPath + '/' + appNameZip, 'r') as zipObj:
# Extract all contents of zip file in current directory
zipObj.extractall(updateDirPath)
except Exception as e:
print(_("Fail to unzip update"))
logging.error('Error at %s', 'division', exc_info=e)
pass
except Exception as e:
print(_("Fail to download update"))
logging.error('Error at %s', 'division', exc_info=e)
pass
time.sleep(3)
try:
copy_tree(updateDirPath + '/' + appDirName, "")
except Exception:
pass
print(_("This window will be closed automatically..."))
time.sleep(3)
# start app
os.startfile(appExeFile)
sys.exit()