-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdlib.py
41 lines (35 loc) · 1012 Bytes
/
stdlib.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
import os
import sys
import platform
from color import *
class Directory:
def Exists(directory):
if not os.path.isdir(directory):
return False
return True
class File:
def GetBasename(file):
return os.path.basename(file)
def Exists(file):
if not os.path.isfile(file):
return False
return True
def GetSystemUser():
return os.popen("users")\
.read()\
.strip()\
.split()
def CheckUID():
try:
if os.geteuid():
print(f"{BAD}Run {TITLE}{File.GetBasename(sys.argv[0])}{BAD} as root.{ENDC}")
sys.exit(1)
except AttributeError:
# Don't use color vars here. Windows can't interpret them.
print(f"{File.GetBasename(sys.argv[0])} can't run on Windows.")
sys.exit(1)
def CheckPlatforms(badOS):
for os in badOS:
if platform.system() == os:
print(f"{File.GetBasename(sys.argv[0])} can't run on {os}.")
sys.exit(1)