@ -1,13 +1,35 @@
#!/usr/bin/python3
#!/usr/bin/python3
import os
import os # for checking if file exists
import hashlib
import hashlib # for md5sum
from subprocess import run
import sys # for reading cmd args
import shutil # for removind directories recursively
from subprocess import run # running external programs
build_files_src = {}
build_files_src = {}
build_files_level = {}
build_files_level = {}
build_files_toBuild = {}
build_files_toBuild = {}
# Taken from https://www.asciiart.eu/nature/deserts
done_art = r"""
. _ + . ______ . .
( /|\ . | \ . +
. ||||| _ | | | | || .
. ||||| | | _| | | | |_|| .
/\ ||||| . | | | | | | .
__||||_|||||____| |_|_____________\__________
. |||| ||||| /\ _____ _____ . .
|||| ||||| |||| . . . ________
. \|`-'|||| |||| __________ . .
\__ |||| |||| . . .
__ ||||`-'||| . . __________
. . |||| ___/ ___________ .
. _ ||||| . _ . _________
_ ___|||||__ _ \\--// . _
_ `---' .)=\oo|=(. _ . . .
_ ^ . - . \.|
"""
def check_if_file(filename, build_file_name):
def check_if_file(filename, build_file_name):
""" Checks it the given file exists, else print error and exit """
""" Checks it the given file exists, else print error and exit """
if os.path.isfile(filename):
if os.path.isfile(filename):
@ -39,6 +61,11 @@ def update_md5(filename):
with open(".flow/" + fname, "w") as f:
with open(".flow/" + fname, "w") as f:
f.write(getmd5(filename).strip())
f.write(getmd5(filename).strip())
def create_md5(filename):
""" Takes the filename in .flow as var fname and updates it's md5sum value according to contents of var filename """
fname = get_meta_file(filename)
with open(".flow/" + fname, "w") as f:
f.write("new file")
def getstoredmd5(filename):
def getstoredmd5(filename):
""" get value of file's md5 from .flow folder, else create entry. return the (md5, createdEntry)"""
""" get value of file's md5 from .flow folder, else create entry. return the (md5, createdEntry)"""
@ -49,7 +76,7 @@ def getstoredmd5(filename):
md5_returned = f.readline()
md5_returned = f.readline()
else:
else:
print("INFO : md5sum entry not present for " + filename + " creating one.")
print("INFO : md5sum entry not present for " + filename + " creating one.")
upd ate_md5(filename)
cre ate_md5(filename)
return md5_returned
return md5_returned
def recieved_file(filename, level, rebuild):
def recieved_file(filename, level, rebuild):
@ -101,15 +128,44 @@ def recieved_file(filename, level, rebuild):
recieved_file(entry, level + 1, build_files_toBuild[filename])
recieved_file(entry, level + 1, build_files_toBuild[filename])
def remove_if_exists(filename):
""" Check if the given filename exists, if yes then print filename and delete """
if os.path.isfile(filename):
print("Deleting " + filename)
os.remove(filename)
def main():
def main():
with open("build.flow", "r") as main_build_file:
with open("build.flow", "r") as main_build_file:
if not os.path.exists(".flow"):
if not os.path.exists(".flow"):
os.makedirs(".flow")
os.makedirs(".flow")
""" flow clean """
for i in sys.argv:
if i == "clean":
# delete the .flow folder
if os.path.exists(".flow"):
print("Deleting .flow directory")
shutil.rmtree(".flow")
# delete the mentioned files
cleaning_started = False
for line in main_build_file:
entry = line.strip()
if cleaning_started:
remove_if_exists(entry)
if entry == ";!remove!;":
cleaning_started = True
print("Cleaning done")
exit(0)
""" creating data for build process """
for line in main_build_file:
for line in main_build_file:
entry = line.strip()
entry = line.strip()
if os.path.isfile(entry):
if entry == ";!remove!;":
break
elif os.path.isfile(entry):
recieved_file(entry, 0, False)
recieved_file(entry, 0, False)
else:
else:
print("ERROR : " + entry + " is neither a file or a directory")
print("ERROR : " + entry + " is neither a file or a directory")
@ -119,10 +175,10 @@ def main():
print(build_files_src)
print(build_files_src)
print(build_files_toBuild)
print(build_files_toBuild)
print()
print()
print("┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ")
print("<-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> ")
print()
print()
""" Build by using the data structures """
""" Build by using the data """
for f, x in list(build_files_toBuild.items()):
for f, x in list(build_files_toBuild.items()):
if x == False:
if x == False:
del build_files_level[f]
del build_files_level[f]
@ -150,4 +206,12 @@ def main():
for src_file in build_files_src[build_file_name]:
for src_file in build_files_src[build_file_name]:
update_md5(src_file)
update_md5(src_file)
main()
print(done_art)
print("Build Completed Successfully")
print()
print("<-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <->")
print()
if __name__ == "__main__":
main()