-
Notifications
You must be signed in to change notification settings - Fork 8
/
SS.py
executable file
·112 lines (95 loc) · 2.99 KB
/
SS.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
#! /usr/bin/python3
import os
# import yaml
import json
from colorama import Fore
import platform
art = """
___ ____ ____ __ __ ____ ___ _ _ ____ ____ ____
/ __)( ___)(_ _)( )( )( _ \ / __)( )_( )(_ _)( ___)(_ _)
\__ \ )__) )( )(__)( )___/ \__ \ ) _ ( _)(_ )__) )(
(___/(____) (__) (______)(__) (___/(_) (_)(____)(__) (__)
"""
def detectOs():
system_name = platform.system()
if system_name == "Linux":
return "Linux"
elif system_name == "Darwin":
return "macOS"
elif system_name == "Windows":
return "Windows"
else:
return None
def valid_input():
while True:
try:
option = int(input(":$ "))
break
except ValueError:
print('Please type a valid option.')
return option
def installer(config,OS):
packages = config[OS]
i = 1
for p in packages:
print('[', i, ']', p[0], '\n')
i = i+1
option = valid_input()
if (option in range(1, len(packages)+1)):
os.system(packages[option-1][1])
else:
print(Fore.YELLOW + "Pick a valid option\n")
return None
def add(config,OS):
print(Fore.YELLOW + "What's the name of the automated command: ")
pack_name = str(input(':$ '))
print(Fore.YELLOW + "What's the command to run the command: ")
pack_com = str(input(':$ '))
pack = [pack_name, pack_com]
config[OS].append(pack)
return config
def remove(config,OS):
packages = config[OS]
i = 1
for p in packages:
print('[', i, ']', p[0], '\n')
i = i+1
print(Fore.YELLOW + "What's the number of the command you want to delete: \n")
option = valid_input()
print(Fore.YELLOW + "Are you sure? y/n")
confirm = str(input(':$ ')).upper().replace(" ", "")
if confirm == "YES" or confirm == "Y" and option in range(1, len(packages)+1):
config[OS].pop(option-1)
elif (confirm == "NO" or confirm == "N"):
print(Fore.YELLOW + "\nBack to the main menu\n")
else:
print(Fore.YELLOW + "\nPick a valid option\n")
return config
def main():
with open('config.json', 'r') as file:
config = json.load(file)
with open('config.json', 'w') as file:
json.dump(config, file)
OS=detectOs()
if not OS:
print(Fore.BLACK+"[!!] Unknown or Unsupported operating system !")
exit()
while True:
print(art)
print(
Fore.CYAN + "[!] Don't forget to give us a star on GitHub.\n")
print(
Fore.RED + "[1] Install packages \n[2] Add a package to the config\n[3] Remove a package from the config\n[4] Exit")
option = valid_input()
if (option == 1):
installer(config,OS)
elif (option == 2):
config = add(config,OS)
elif (option == 3):
config = remove(config,OS)
elif (option == 4):
exit()
else:
print('Please choose an appropriate option.\n')
if __name__ == '__main__':
main()