changed update.py

This commit is contained in:
TristanAncelet 2021-09-04 23:25:50 -05:00
parent 7631164249
commit 437f21cb13

View File

@ -20,9 +20,15 @@ def make_readme_article_name(filename):
def articles_in_directory(directory): def articles_in_directory(directory):
files = list() files = list()
for file in os.listdir(directory): for file in os.listdir(directory):
if is_markdown_file(file) and file := "README.md": if is_markdown_file(file) and file != "README.md":
files.append(file) files.append(file)
def get_section_dirs():
dirs = list()
for dir in os.listdir():
if dir not in [".git"] and os.path.isdir(dir):
dirs.append(dir)
return dirs
def readme_matches_directory_contents(directory): def readme_matches_directory_contents(directory):
return True if (articles_in_readme(os.path.join(directory, 'README.md')) == os.listdir(directory)) else False return True if (articles_in_readme(os.path.join(directory, 'README.md')) == os.listdir(directory)) else False
@ -30,18 +36,17 @@ def readme_matches_directory_contents(directory):
def update_readme_contents(directory): def update_readme_contents(directory):
readme_path = os.path.join(directory,"README.md") readme_path = os.path.join(directory,"README.md")
files_difference = list(set(articles_in_directory(directory))-set(articles_in_readme(readme_path))) if readme_matches_directory_contents(directory):
if len(files_difference) == 0:
logging.debug("update_readme_contents : {} : there were no differences between directory and file".format(readme_path)) logging.debug("update_readme_contents : {} : there were no differences between directory and file".format(readme_path))
else: else:
with open(readme_path, 'a') as file: with open(readme_path, 'a') as file:
files_difference = list(set(articles_in_directory(directory))-set(articles_in_readme(readme_path)))
for item in files_difference: for item in files_difference:
file.write(f"- [{make_readme_article_name(item)}]({item})") file.write(f"- [{make_readme_article_name(item)}]({item})")
file.close()
if __name__ == "__main__":
for directory in get_section_dirs():
for directory in os.listdir(): update_readme_contents(directory)
if os.path.isdir(directory):
readme