Last active
March 14, 2018 23:21
-
-
Save toorusr/8837656d59bbb3745a505c3e6114d8bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[struc.tur] | |
.struct | |
start | |
ec Creating... | |
mk home | |
mk home/user | |
mk home/user/desktop | |
mk home/user/pictures | |
mk home/user/music | |
mk home/user/things | |
mk home/void | |
mk .secret | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# import | |
import os, sys | |
#d3bugprint | |
def dprint(arg): | |
# print("[D] " + str(arg)) | |
pass | |
# Tur Class | |
class Tur: | |
def __init__(self, tur): | |
tur = self._formatlines(tur) | |
self.turheader = tur[0:3] | |
self.turcontent = tur[3:-1] | |
self.turfooter = tur[-1] | |
dprint(".tur-header: " + str(self.turheader)) | |
dprint(".tur-content: " + str(self.turcontent)) | |
dprint(".tur-footer: " + str(self.turfooter)) | |
val = self._validate(self.turheader, self.turfooter) | |
if val: | |
print("Reading struc.tur file...") | |
self._exec(self._execfilter(self._contentsplit(self.turcontent))) | |
else: | |
print("Syntax error") | |
def _formatlines(self, lineload): | |
lineload_out = [] | |
for line in lineload: | |
line = line.replace("\n", "") | |
lineload_out.append(line) | |
return lineload_out | |
def _validate(self, header, footer): | |
if header[0] == "[struc.tur]" and header[2] == "start" and str(footer) == "end": | |
self.rootpathload = header[1] | |
dprint(self.rootpathload) | |
return 1 | |
else: | |
return 0 | |
def _contentsplit(self, contentload): | |
content_split = [] | |
for content in contentload: | |
csplit = content.split(" ") | |
content_split.append(csplit) | |
dprint(content_split) | |
return content_split | |
def _execfilter(self, csplit): | |
csplit_out = [] | |
counter_val = 0 | |
counter_ival = 0 | |
for item in csplit: | |
if len(item) == 2: | |
item.append(1) # valid exec line | |
counter_val += 1 | |
else: | |
item.append(0) # invalid exec line | |
counter_ival += 1 | |
dprint("valid:" + str(counter_val) + "\ninvalid:" + str(counter_ival) + "\ncsplit:" + str(csplit)) | |
return csplit | |
def _exec(self, ccnt): | |
counter_val = 0 | |
counter_ival = 0 | |
dprint(ccnt) | |
for item in ccnt: | |
if item[2] == 1 and item[0] == "mk": | |
try: | |
os.mkdir(self.rootpathload + "/" + item[1]) | |
counter_val += 1 | |
except FileExistsError: | |
counter_ival += 1 | |
elif item[2] == 1 and item[0] == "ec": | |
print("[FILE_ECHO] " + item[1]) | |
counter_val += 1 | |
else: | |
counter_ival += 1 | |
dprint("valid:" + str(counter_val) + "\ninvalid:" + str(counter_ival)) | |
print("Finished with %i valid and %i invalid executions." % (counter_val, counter_ival)) | |
# init | |
initpathload = "./.struct" | |
if not os.path.isdir("./.struct"): | |
os.mkdir(initpathload, 755) | |
print("Initialized struct") | |
else: | |
print("Struct is already initialized.") | |
# .tur read | |
if os.path.isfile("./struc.tur"): | |
turhandler = open("./struc.tur", "r+") | |
tur = turhandler.readlines() | |
Tur(tur) | |
else: | |
print("There is no struc.tur config. \n create a struct.tur like in the example'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment