Repository navigation
Expand file tree
/
Copy pathbinary.py
More file actions
83 lines (68 loc) · 2.93 KB
/
Copy pathbinary.py
File metadata and controls
83 lines (68 loc) · 2.93 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
# pystackql/core/binary.py
"""
Binary management module for PyStackQL.
This module handles the installation, version checking, and management
of the StackQL binary executable.
"""
import os
from ..utils import (
is_binary_local,
get_platform,
get_download_dir,
get_binary_name,
setup_binary,
get_binary_version
)
class BinaryManager:
"""Manages the StackQL binary installation and versions.
This class is responsible for ensuring the StackQL binary is available
and correctly configured for use.
"""
def __init__(self, download_dir=None):
"""Initialize the BinaryManager.
Args:
download_dir (str, optional): Directory to store the binary. Defaults to None.
"""
self.platform_info, self.system = get_platform()
# Determine binary location
if self.system == 'Linux' and is_binary_local(self.system) and download_dir is None:
self.bin_path = '/usr/local/bin/stackql'
self.download_dir = '/usr/local/bin'
else:
# Use provided download_dir or default
self.download_dir = download_dir if download_dir else get_download_dir()
# Create a user-supplied download directory if it does not exist
# (get_download_dir already ensures the default location exists).
if not os.path.exists(self.download_dir):
os.makedirs(self.download_dir, exist_ok=True)
self.bin_path = os.path.join(self.download_dir, get_binary_name(self.system))
# Check if binary exists and get version
self._ensure_binary_exists()
def _ensure_binary_exists(self):
"""Ensure the binary exists, download it if not."""
if os.path.exists(self.bin_path):
# Binary exists, get version
self.version, self.sha = get_binary_version(self.bin_path)
else:
# Binary doesn't exist, download it
setup_binary(self.download_dir, self.system)
self.version, self.sha = get_binary_version(self.bin_path)
def upgrade(self, showprogress=True):
"""Upgrade the StackQL binary to the latest version.
Args:
showprogress (bool, optional): Whether to show download progress. Defaults to True.
Returns:
str: A message indicating the new version
"""
setup_binary(self.download_dir, self.system, showprogress)
self.version, self.sha = get_binary_version(self.bin_path)
return f"stackql upgraded to version {self.version}"
def get_version_info(self):
"""Get the version information for the binary.
Returns:
dict: Version information including version and sha
"""
return {
"version": self.version,
"sha": self.sha
}