diff --git a/flow b/flow index 886223c..dff78a2 100755 --- a/flow +++ b/flow @@ -1,13 +1,35 @@ #!/usr/bin/python3 -import os -import hashlib -from subprocess import run +import os # for checking if file exists +import hashlib # for md5sum +import sys # for reading cmd args +import shutil # for removind directories recursively +from subprocess import run # running external programs build_files_src = {} build_files_level = {} build_files_toBuild = {} +# Taken from https://www.asciiart.eu/nature/deserts +done_art = r""" + . _ + . ______ . . + ( /|\ . | \ . + + . ||||| _ | | | | || . +. ||||| | | _| | | | |_|| . + /\ ||||| . | | | | | | . +__||||_|||||____| |_|_____________\__________ +. |||| ||||| /\ _____ _____ . . + |||| ||||| |||| . . . ________ + . \|`-'|||| |||| __________ . . + \__ |||| |||| . . . + __ ||||`-'||| . . __________ +. . |||| ___/ ___________ . + . _ ||||| . _ . _________ +_ ___|||||__ _ \\--// . _ + _ `---' .)=\oo|=(. _ . . . +_ ^ . - . \.| +""" + def check_if_file(filename, build_file_name): """ Checks it the given file exists, else print error and exit """ if os.path.isfile(filename): @@ -39,6 +61,11 @@ def update_md5(filename): with open(".flow/" + fname, "w") as f: 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): """ 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() else: print("INFO : md5sum entry not present for " + filename + " creating one.") - update_md5(filename) + create_md5(filename) return md5_returned def recieved_file(filename, level, rebuild): @@ -99,17 +126,46 @@ def recieved_file(filename, level, rebuild): entry = line.strip() check_if_file(entry, 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(): with open("build.flow", "r") as main_build_file: if not os.path.exists(".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: entry = line.strip() - if os.path.isfile(entry): + if entry == ";!remove!;": + break + elif os.path.isfile(entry): recieved_file(entry, 0, False) else: print("ERROR : " + entry + " is neither a file or a directory") @@ -119,10 +175,10 @@ def main(): print(build_files_src) print(build_files_toBuild) print() - print("┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ") + print("<-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <->") print() - """ Build by using the data structures """ + """ Build by using the data """ for f, x in list(build_files_toBuild.items()): if x == False: del build_files_level[f] @@ -149,5 +205,13 @@ def main(): build_file_name = item[0] for src_file in build_files_src[build_file_name]: update_md5(src_file) - -main() + + print(done_art) + print("Build Completed Successfully") + print() + print("<-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <->") + print() + + +if __name__ == "__main__": + main()