|
import tomllib |
|
import pathlib |
|
import configparser |
|
import json |
|
import os |
|
import zlib |
|
import sys |
|
import hashlib |
|
|
|
omnispath = pathlib.Path(__file__) / ".." / ".omnis.toml" |
|
|
|
omnis_file = tomllib.load(open(omnispath.resolve(), "rb")) |
|
|
|
print(omnis_file) |
|
|
|
|
|
cfg_path = pathlib.Path(__file__) / ".." / ".craftset.cfg" |
|
|
|
omnis_write = configparser.ConfigParser() |
|
|
|
#hallows = os.popen("ls -1").read().split("\n") |
|
|
|
omnis_write.read(cfg_path.resolve()) |
|
|
|
hallows = [hallowed for hallowed in open(f"{sys.argv[1]}/sanctified.txt").read().split("\n") if (pathlib.Path(__file__)/".."/hallowed).resolve().is_file()] |
|
|
|
|
|
triangulums_raw_record = {} |
|
|
|
for hashtype in ["sha1", "sha256", "md5"]: |
|
triangulums_raw_record[hashtype] = dict([line.split()[::-1] for line in open(f"{sys.argv[1]}/triangulum.{hashtype}.txt").read().split("\n") if len(line.split())==2]) |
|
|
|
|
|
print(triangulums_raw_record) |
|
|
|
#for checkexist in hallows: |
|
# checkfile = pathlib.Path(__file__) / ".." / checkexist |
|
# if checkfile.resolve().is_file(): |
|
# print(checkexist, "EXIST") |
|
# else: |
|
# print(checkexist, "NOT_EXIST", checkfile) |
|
|
|
# print(tuple(hallows)) |
|
# print() |
|
|
|
hallow_entries = {} |
|
|
|
def NOW(): |
|
return os.popen("node -e 'console.log(`UNIXUSAT=${Date.now()}`)'").read().strip() |
|
|
|
def create_triangulum(filename, trihash, grih_ver): |
|
unixusat = NOW().split("=")[1] |
|
return "".join([ |
|
str(zlib.adler32(str.encode(filename))), |
|
"=", |
|
unixusat, |
|
"---", |
|
trihash[0], |
|
"::", |
|
trihash[1], |
|
"::", |
|
trihash[2], |
|
"---", |
|
grih_ver |
|
]) |
|
|
|
def selfscript_hallowing(craftset): |
|
for label in ["check", "dev", "run"]: |
|
tmp_path = pathlib.Path(__file__) / ".." / f".craftset.self{label}.sh" |
|
tmp_path = tmp_path.resolve() |
|
tmp_selfscript = [] |
|
for tri_hashtype in ["md5","sha1","sha256"]: |
|
with open(tmp_path, "rb") as f: |
|
diglet = hashlib.file_digest(f, tri_hashtype) |
|
tmp_selfscript.append(diglet.hexdigest()) |
|
|
|
tmp_option = f"self{label}_hallow" |
|
craftset["craftset"][tmp_option] = "::".join(tmp_selfscript) |
|
unixusat = NOW().split("=")[1] |
|
craftset["craftset"]["unixusat"] = unixusat |
|
note_dev = "<hefajsto> selfscripts edits" |
|
craftset["craftset"]["version"] = grihver_increment(craftset["craftset"]["version"], "r") |
|
repo_update(craftset, note_dev, ["git add .craftset.self*"]) |
|
|
|
|
|
|
|
def grihver_increment(version, level="h"): |
|
grihver = version.split(".") |
|
ver_levels = "grih" |
|
level_above = False |
|
for x in range(4): |
|
if level_above: |
|
grihver[x]="0" |
|
elif level==ver_levels[x]: |
|
level_above=True |
|
grihver[x]=str(int(grihver[x])+1) |
|
return ".".join(grihver) |
|
|
|
def repo_sync(): |
|
for order in ["git fetch", "git pull", "git push"]: |
|
print("#__ \t", order) |
|
os.system(order) |
|
|
|
def repo_update(craftset, note_dev, additional_commands=["git add *"]): |
|
procedure_task = [ |
|
"git add .craftset.cfg", |
|
f"git commit -m '{note_dev} _ {craftset["craftset"]["version"]} # [UNIXUSAT={craftset["craftset"]["unixusat"]}]' " |
|
] |
|
for order in additional_commands: |
|
print("#__ \t", order) |
|
os.system(order) |
|
for order in procedure_task: |
|
print("#__ \t", order) |
|
os.system(order) |
|
|
|
def hallows_reset(craftset, accepted_hallows, checksum_record): |
|
global cfg_path |
|
unixusat = NOW().split("=")[1] |
|
craftset["craftset"]["unixusat"]=unixusat |
|
note_dev = "<hefajsto> hallows reset" |
|
craftset["craftset"]["version"] = grihver_increment(craftset["craftset"]["version"], "r") |
|
craftset.remove_section("hallowed") |
|
craftset.add_section("hallowed") |
|
|
|
repo_update(craftset, note_dev) |
|
|
|
for hallowed in accepted_hallows: |
|
#triangulum = f"{unixusat}---{triangulums_raw_record["md5"][hallowed]}::{triangulums_raw_record["sha1"][hallowed]}::{triangulums_raw_record["sha256"][hallowed]}---1.0.0.0" |
|
tri = [ |
|
checksum_record["md5"][hallowed], |
|
checksum_record["sha1"][hallowed], |
|
checksum_record["sha256"][hallowed] |
|
] |
|
hallow_insert(omnis_write, hallowed, tri) |
|
|
|
def hallow_changed(filename): |
|
return filename in os.popen("git status -s").read() |
|
|
|
def hallow_insert(craftset, filename, trihash): |
|
global cfg_path |
|
unixusat = NOW().split("=")[1] |
|
craftset["craftset"]["unixusat"]=unixusat |
|
|
|
note_dev = "no action" |
|
|
|
if str(zlib.adler32(str.encode(filename))) in craftset["hallowed"]: |
|
craftset["craftset"]["version"] = grihver_increment(craftset["craftset"]["version"], "h") |
|
note_dev = "<hefajsto> UPDATE "+filename |
|
else: |
|
craftset["craftset"]["version"] = grihver_increment(craftset["craftset"]["version"], "i") |
|
note_dev = "<hefajsto> CREATE "+filename |
|
|
|
craftset["hallowed"][str(zlib.adler32(str.encode(filename)))]="".join([ |
|
unixusat, |
|
"---", |
|
trihash[0], |
|
"::", |
|
trihash[1], |
|
"::", |
|
trihash[2], |
|
"---", |
|
craftset["craftset"]["version"] |
|
]) |
|
|
|
with open(cfg_path.resolve(), 'w') as updatefile: |
|
craftset.write(updatefile) |
|
|
|
repo_update(craftset, note_dev, [f"git add {filename}"]) |
|
|
|
# selfscript_hallowing(omnis_write) |
|
|
|
for hallowed in hallows: |
|
if hallow_changed(hallowed): |
|
|
|
#triangulum = f"{unixusat}---{triangulums_raw_record["md5"][hallowed]}::{triangulums_raw_record["sha1"][hallowed]}::{triangulums_raw_record["sha256"][hallowed]}---1.0.0.0" |
|
tri = [ |
|
triangulums_raw_record["md5"][hallowed], |
|
triangulums_raw_record["sha1"][hallowed], |
|
triangulums_raw_record["sha256"][hallowed] |
|
] |
|
hallow_insert(omnis_write, hallowed, tri) |
|
|
|
#omnis_write["hallowed"] = dict(zip(tuple([zlib.adler32(str.encode(hallowed)) for hallowed in hallows]), tuple(hallowed))) |
|
|
|
#hallows_reset(omnis_write, hallows, triangulums_raw_record) |
|
|
|
repo_sync() |
|
|
|
print(json.dumps(hallow_entries, sort_keys=True, indent=4)) |
|
|
|
#[option for option in parser['section3']] |
|
|
|
print(dict(omnis_write)) |
|
|
|
#omnis_write = configparser.ConfigParser() |
|
#print(json.dumps(omnis_file, sort_keys=True, indent=4)) |
|
#omnis_write.read_dict(omnis_file) |
|
|