Clean Functionality

1. Clean functionality ( running flow clean )
2. New md5 entry files have data to mark them as new and md5 sum is
not immediatly updated in them.
3. Output art and changes
main
lomna-dev 1 year ago
parent b8f5f32140
commit cfd89b99ca

80
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):
@ -101,15 +128,44 @@ def recieved_file(filename, level, rebuild):
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)
if os.path.isfile(entry):
""" creating data for build process """
for line in main_build_file:
entry = line.strip()
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]
@ -150,4 +206,12 @@ def main():
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()

Loading…
Cancel
Save