-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsk-samurai.py
executable file
·100 lines (73 loc) · 2.85 KB
/
jsk-samurai.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
#!/usr/bin/env python3
# ====================================================== project information ===
# author : jimmy mg lim ([email protected])
# source : https://github.com/mirageglobe/swissknife
# version : 1.0.0
# --------------------------------------------------------------- references ---
import os
import platform
import socket
import sys
samuraimap = {}
# ---------------------------------------------------------------- functions ---
def loadoptions(ninja=False,showcmd=False):
print("==================================")
print("samurai for mac")
print("modes: ninja={0},".format(ninja), "showcmd={0}".format(showcmd))
print("system:","{0}".format(platform.system()),"({0})".format(platform.release()))
print("==================================")
for key, value in sorted(samuraimap.items()):
if showcmd:
print("[", key, "] -", value['name'], " ::> " , value['cmd'])
else:
print("[", key, "] -", value['name'])
def runcommand(cmdstring):
return_value = os.system(cmdstring)
# --------------------------------------------------------------------- main ---
if __name__ == "__main__":
# ===============================
# checks for system
# ===============================
if platform.system() != 'Darwin':
print("[Samurai] System incompatible, please run samurai.py instead.")
sys.exit(1)
# ===============================
# setting arguments
# ===============================
ninja_active = False
showcmd_active = False
# adding ninja mode here - ninja mode activated within menu
# in ninja mode, the commands are not executed; until the end. if you run ninja, it will create a scroll.sh with bash commands which can be used with vagrant
# export DEBIAN_FRONTEND=noninteractive
# apt-get -y install package1 package2
# ===============================
# default load of system
# ===============================
avatar = "[samurai]"
gloop = True
# ===============================
# entering loop of samurai
# ===============================
runcommand("clear")
while gloop:
gchoice = 9999
loadoptions(ninja_active,showcmd_active)
gchoice = input("================================== \n{0} What is your command? : ".format(avatar))
if gchoice.isdigit():
gchoice = int(gchoice)
else:
gchoice = 9999
if gchoice == 0:
break
if gchoice == 3:
showcmd_active = not showcmd_active
# toggle showcmd mode
if gchoice in samuraimap:
runcommand(samuraimap[gchoice]['cmd'])
if not samuraimap[gchoice]['responsesuccess']:
print("{0}".format(avatar), samuraimap[gchoice]['responsesuccess'])
else:
print("{0} Command is does not exist. Please enter number.".format(avatar))
# load the options again. does not work if placed in above array
input("enter to continue")
runcommand("clear")