-
Notifications
You must be signed in to change notification settings - Fork 1
/
fluffy.py
executable file
·142 lines (114 loc) · 4.15 KB
/
fluffy.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
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
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Fluffy Launcher
# @raycast.mode silent
# Optional parameters:
# @raycast.icon images/fluffy-icon.png
# @raycast.argument1 {"type": "text", "placeholder": "install/start/stop/update/uninstall", "optional": false}
# Documentation:
# @raycast.description Usage: fluffy <install/start/stop/update/uninstall>
import importlib
import subprocess
depends = [
('psutil', 'psutil'),
('requests', 'requests')
]
for pack_name, imp_name in depends:
try:
importlib.import_module(imp_name)
except:
p = subprocess.Popen(f'/usr/bin/env python3 -m pip install {pack_name}', stdout=subprocess.PIPE, shell=True)
p.wait()
import sys
args = sys.argv[1:]
import os
import signal
import psutil
import requests
FLUFFY_VERSION_FILE = 'fluffy/VERSION'
FLUFFY_PID_FILE = 'fluffy/fluffy.pid'
def get_latest_version():
try:
response = requests.get('https://api.github.com/repos/iewnfod/fluffy/releases/latest')
if response.status_code == 200:
latest_version = response.json()['tag_name']
return latest_version
except Exception as e:
print(f"Error fetching latest version: {e}")
return None
def save_version_to_file(version):
try:
with open(FLUFFY_VERSION_FILE, 'w') as file:
file.write(version)
except Exception as e:
print(f"Error saving version to file: {e}")
def read_version_from_file():
try:
with open(FLUFFY_VERSION_FILE, 'r') as file:
return file.read().strip()
except Exception as e:
print(f"Error reading version from file: {e}")
return None
def download_fluffy():
folder_name = "fluffy"
if not os.path.exists(folder_name):
os.makedirs(folder_name)
latest_version = get_latest_version()
save_version_to_file(latest_version)
os.system('wget -O fluffy/fluffy https://github.com/iewnfod/fluffy/releases/latest/download/fluffy')
os.system('chmod +x fluffy/fluffy')
print("✅ Fluffy has been installed!")
def run_fluffy_background():
try:
for proc in psutil.process_iter(['name']):
if 'fluffy' in proc.info['name']:
print("❓ Fluffy process already running!")
return
process = subprocess.Popen(['./fluffy/fluffy'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
with open(FLUFFY_PID_FILE, 'w') as pid_file:
pid_file.write(str(process.pid))
print("🚀 Fluffy is running in the background!")
except Exception as e:
print(f"An error occurred while starting Fluffy: {e}")
def kill_process():
if os.path.exists(FLUFFY_PID_FILE):
with open(FLUFFY_PID_FILE, 'r') as pid_file:
pid = int(pid_file.read().strip())
os.kill(pid, signal.SIGTERM)
os.remove(FLUFFY_PID_FILE)
print("🛑 Fluffy process terminated.")
else:
print("⚠️ Fluffy process is not running.")
def update_fluffy():
latest_version = get_latest_version()
if latest_version:
saved_version = read_version_from_file()
if latest_version != saved_version:
os.system(f'wget -O fluffy/fluffy https://github.com/iewnfod/fluffy/releases/latest/download/fluffy')
save_version_to_file(latest_version)
else:
print("🤔 Fluffy is already up to date.")
def uninstall_fluffy():
if os.path.exists("fluffy"):
subprocess.run(["rm", "-rf", "fluffy"])
app_support_path = os.path.expanduser("~/Library/Application Support/com.iewnfod.fluffy")
if os.path.exists(app_support_path):
subprocess.run(["rm", "-rf", app_support_path])
print("🗑 Fluffy has been uninstalled.")
def main():
args = sys.argv[1:]
if args and args[0] == 'install':
download_fluffy()
elif args and args[0] == 'start':
run_fluffy_background()
elif args and args[0] == 'stop':
kill_process()
elif args and args[0] == "update":
update_fluffy()
elif args and args[0] == "uninstall":
uninstall_fluffy()
else:
print("Invalid arguments.")
if __name__ == "__main__":
main()