-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyTOSC.py
123 lines (104 loc) · 3.28 KB
/
pyTOSC.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
import sys
import os
full_dir = os.getcwd()
working_index = full_dir.rfind(os.path.normpath("/")) + 1
dir = full_dir[working_index:]
is_pyTOSC_folder = dir == "pyTOSC"
if (is_pyTOSC_folder):
print("Program must be run from containing project directory. Run 'python init.py' first!")
exit()
doUnpack = False
doBuild = False
doClean = False
doCleanLua = False
from pyTOSC.unpack import Unpack
from pyTOSC.pack import Pack
from configparser import ConfigParser
config = ConfigParser()
config.read("config.ini")
UNPACK_FILE = config["pyTOSC"]["UnpackTarget"]
BUILD_FILE = config["pyTOSC"]["BuildXML"]
help_string = """Usage: 'python pyTOSC.py [argument]'
Arguments:
-u, --unpack unpack .tosc file
-b, --build build .tosc file(s)
-c, --clean clean build directory
-l, --clean-lua clean lua directory
Anything else show these arguments
"""
lua_warning = """WARNING: You have selected 'clean lua directory.' This will erase all files in your Lua folder.
It is advised you only do this if you are unpacking a .tosc file. Do you wish to proceed? (Y/n): """
def Clean():
print("Clean selected")
build_files = os.listdir("Build")
for file in build_files:
if file != ".gitignore":
os.remove(os.path.normpath(f'Build/{file}'))
print("Build directory cleaned!")
def CleanLua():
print("Clean Lua selected")
lua_files = os.listdir("Lua")
for file in lua_files:
if file != "Submodules":
os.remove(os.path.normpath(f'Lua/{file}'))
else:
sub_files = os.listdir(os.path.normpath("Lua/Submodules"))
for sub in sub_files:
os.remove(os.path.normpath(f'Lua/Submodules/{sub}'))
print("Lua directory cleaned!")
def Help():
print(help_string)
def ParseChar(char: str):
match char.lower():
case "u":
global doUnpack
doUnpack = True
case "b":
global doBuild
doBuild = True
case "c":
global doClean
doClean = True
case "l":
global doCleanLua
doCleanLua = True
def ParseArgs():
for arg in sys.argv:
# Check for multiple args in one string
if ("-" in arg) and ("--" not in arg):
for char in arg[1:]:
ParseChar(char)
elif ("--" in arg):
match arg.lower():
case "--unpack":
global doUnpack
doUnpack = True
case "--build":
global doBuild
doBuild = True
case "--clean":
global doClean
doClean = True
case "--clean-lua":
global doCleanLua
doCleanLua = True
if doCleanLua:
confirm_clean = input(lua_warning)
if confirm_clean.lower() == "y":
CleanLua()
else:
print("Cancelling clean lua function...")
if doUnpack:
Unpack(UNPACK_FILE)
if doClean:
Clean()
if doBuild:
Pack(BUILD_FILE)
if (doUnpack | doBuild | doClean | doCleanLua) == False:
Help()
if (len(sys.argv) < 2):
print("Expected argument\n")
Help()
exit()
else:
ParseArgs()