pyappify 0.0.2__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyappify-0.0.2 → pyappify-0.0.3}/PKG-INFO +1 -1
- pyappify-0.0.3/pyappify/__init__.py +101 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/pyappify.egg-info/PKG-INFO +1 -1
- {pyappify-0.0.2 → pyappify-0.0.3}/pyproject.toml +1 -1
- pyappify-0.0.2/pyappify/__init__.py +0 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/pyappify/main.py +0 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/pyappify.egg-info/SOURCES.txt +0 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/pyappify.egg-info/dependency_links.txt +0 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/pyappify.egg-info/entry_points.txt +0 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/pyappify.egg-info/requires.txt +0 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/pyappify.egg-info/top_level.txt +0 -0
- {pyappify-0.0.2 → pyappify-0.0.3}/setup.cfg +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# pyappify/__init__.py
|
|
2
|
+
import os
|
|
3
|
+
import signal
|
|
4
|
+
import hashlib
|
|
5
|
+
import shutil
|
|
6
|
+
import urllib.request
|
|
7
|
+
import zipfile
|
|
8
|
+
import threading
|
|
9
|
+
|
|
10
|
+
app_version = os.environ.get("PYAPPIFY_APP_VERSION")
|
|
11
|
+
app_profile = os.environ.get("PYAPPIFY_APP_PROFILE")
|
|
12
|
+
pyappify_version = os.environ.get("PYAPPIFY_VERSION")
|
|
13
|
+
pyappify_executable = os.environ.get("PYAPPIFY_EXECUTABLE")
|
|
14
|
+
|
|
15
|
+
pyappify_upgradeable = os.environ.get("PYAPPIFY_UPGRADEABLE") == '1'
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
pid = int(os.environ.get("PYAPPIFY_PID"))
|
|
19
|
+
except (ValueError, TypeError):
|
|
20
|
+
pid = None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def kill_pyappify():
|
|
24
|
+
if pid:
|
|
25
|
+
try:
|
|
26
|
+
os.kill(pid, signal.SIGTERM)
|
|
27
|
+
except ProcessLookupError:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def upgrade(to_version, executable_sha256, executable_zip_urls, logger=None, stop_event=None):
|
|
32
|
+
if not pyappify_upgradeable or to_version == pyappify_version:
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
def _do_upgrade():
|
|
36
|
+
tmp_dir = os.path.join(os.getcwd(), "tmp")
|
|
37
|
+
try:
|
|
38
|
+
os.makedirs(tmp_dir, exist_ok=True)
|
|
39
|
+
downloaded_zip_path = None
|
|
40
|
+
for url in executable_zip_urls:
|
|
41
|
+
try:
|
|
42
|
+
local_zip_path = os.path.join(tmp_dir, os.path.basename(url))
|
|
43
|
+
with urllib.request.urlopen(url) as response, open(local_zip_path, 'wb') as out_file:
|
|
44
|
+
while True:
|
|
45
|
+
if stop_event and stop_event.is_set():
|
|
46
|
+
if logger:
|
|
47
|
+
logger.info("Upgrade download cancelled by stop event.")
|
|
48
|
+
return
|
|
49
|
+
chunk = response.read(8192)
|
|
50
|
+
if not chunk:
|
|
51
|
+
break
|
|
52
|
+
out_file.write(chunk)
|
|
53
|
+
downloaded_zip_path = local_zip_path
|
|
54
|
+
break
|
|
55
|
+
except Exception as e:
|
|
56
|
+
if logger:
|
|
57
|
+
logger.warning(f"Failed to download from {url}: {e}")
|
|
58
|
+
continue
|
|
59
|
+
|
|
60
|
+
if not downloaded_zip_path:
|
|
61
|
+
if logger:
|
|
62
|
+
logger.error("Failed to download upgrade.")
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
with zipfile.ZipFile(downloaded_zip_path, 'r') as zip_ref:
|
|
66
|
+
zip_ref.extractall(tmp_dir)
|
|
67
|
+
|
|
68
|
+
new_executable_name = os.path.basename(pyappify_executable)
|
|
69
|
+
found_executable_path = None
|
|
70
|
+
for root, _, files in os.walk(tmp_dir):
|
|
71
|
+
if new_executable_name in files:
|
|
72
|
+
found_executable_path = os.path.join(root, new_executable_name)
|
|
73
|
+
break
|
|
74
|
+
|
|
75
|
+
if not found_executable_path:
|
|
76
|
+
if logger:
|
|
77
|
+
logger.error("Executable not found in zip.")
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
sha256_hash = hashlib.sha256()
|
|
81
|
+
with open(found_executable_path, "rb") as f:
|
|
82
|
+
for byte_block in iter(lambda: f.read(4096), b""):
|
|
83
|
+
sha256_hash.update(byte_block)
|
|
84
|
+
|
|
85
|
+
if sha256_hash.hexdigest() != executable_sha256:
|
|
86
|
+
if logger:
|
|
87
|
+
logger.error("SHA256 checksum mismatch.")
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
kill_pyappify()
|
|
91
|
+
shutil.move(found_executable_path, pyappify_executable)
|
|
92
|
+
except Exception as e:
|
|
93
|
+
if logger:
|
|
94
|
+
logger.error(f"Upgrade failed: {e}")
|
|
95
|
+
finally:
|
|
96
|
+
if os.path.exists(tmp_dir):
|
|
97
|
+
shutil.rmtree(tmp_dir)
|
|
98
|
+
|
|
99
|
+
thread = threading.Thread(target=_do_upgrade)
|
|
100
|
+
thread.daemon = True
|
|
101
|
+
thread.start()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|