Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Modify code to enhance readability #27

Merged
merged 5 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ end-matter:
wg-common:
include-wg: True
wg-fullname: Common Metrics WG
github-link: None
github-branch: None
repo-link: None
repo-branch: None
focus-areas:
contributions:
- technical-fork.md
Expand All @@ -43,8 +43,8 @@ wg-common:
wg-diversity-inclusion:
include-wg: False
wg-fullname: Diversity, Equity and Inclusion WG
github-link: None
github-branch: None
repo-link: None
repo-branch: None
focus-areas:
# communication-inclusivity:
# - alternatives.md
Expand Down Expand Up @@ -96,8 +96,8 @@ wg-diversity-inclusion:
wg-evolution:
include-wg: False
wg-fullname: Evolution WG
github-link: None
github-branch: None
repo-link: None
repo-branch: None
focus-areas:
code-development-activity:
- branch-lifecycle.md
Expand Down Expand Up @@ -129,8 +129,8 @@ wg-evolution:
wg-risk:
include-wg: False
wg-fullname: Risk WG
github-link: None
github-branch: None
repo-link: None
repo-branch: None
focus-areas:
business-risk:
# - average-issue-resolution-time.md
Expand Down Expand Up @@ -163,8 +163,8 @@ wg-risk:
wg-value:
include-wg: True
wg-fullname: Value WG
github-link: None
github-branch: None
repo-link: None
repo-branch: None
focus-areas:
communal-value:
# - project-popularity.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ end-matter:
wg-common:
include-wg: False
wg-fullname: Common Metrics WG
github-link: https://github.com/chaoss/wg-common
github-branch: master
repo-link: https://github.com/chaoss/wg-common
repo-branch: master
focus-areas:
contributions:
- technical-fork.md
Expand All @@ -42,8 +42,8 @@ wg-common:
wg-diversity-inclusion:
include-wg: False
wg-fullname: Diversity, Equity and Inclusion WG
github-link: https://github.com/chaoss/wg-diversity-inclusion
github-branch: master
repo-link: https://github.com/chaoss/wg-diversity-inclusion
repo-branch: master
focus-areas:
# communication-inclusivity:
# - alternatives.md
Expand Down Expand Up @@ -95,8 +95,8 @@ wg-diversity-inclusion:
wg-evolution:
include-wg: False
wg-fullname: Evolution WG
github-link: https://github.com/chaoss/wg-evolution
github-branch: master
repo-link: https://github.com/chaoss/wg-evolution
repo-branch: master
focus-areas:
code-development-activity:
- branch-lifecycle.md
Expand Down Expand Up @@ -128,8 +128,8 @@ wg-evolution:
wg-risk:
include-wg: False
wg-fullname: Risk WG
github-link: https://github.com/chaoss/wg-risk
github-branch: master
repo-link: https://github.com/chaoss/wg-risk
repo-branch: master
focus-areas:
business-risk:
# - average-issue-resolution-time.md
Expand Down Expand Up @@ -162,8 +162,8 @@ wg-risk:
wg-value:
include-wg: True
wg-fullname: Value WG
github-link: https://github.com/chaoss/wg-value
github-branch: master
repo-link: https://github.com/chaoss/wg-value
repo-branch: master
focus-areas:
communal-value:
- project-popularity.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ end-matter:
wg-common:
include-wg: False
wg-fullname: Common Metrics WG
github-link: https://github.com/chaoss/wg-common
github-branch: master
repo-link: https://github.com/chaoss/wg-common
repo-branch: master
focus-areas:
contributions:
- technical-fork.md
Expand All @@ -42,8 +42,8 @@ wg-common:
wg-diversity-inclusion:
include-wg: False
wg-fullname: Diversity, Equity and Inclusion WG
github-link: https://github.com/chaoss/wg-diversity-inclusion
github-branch: master
repo-link: https://github.com/chaoss/wg-diversity-inclusion
repo-branch: master
focus-areas:
# communication-inclusivity:
# - alternatives.md
Expand Down Expand Up @@ -95,8 +95,8 @@ wg-diversity-inclusion:
wg-evolution:
include-wg: False
wg-fullname: Evolution WG
github-link: https://github.com/chaoss/wg-evolution
github-branch: master
repo-link: https://github.com/chaoss/wg-evolution
repo-branch: master
focus-areas:
code-development-activity:
- branch-lifecycle.md
Expand Down Expand Up @@ -128,8 +128,8 @@ wg-evolution:
wg-risk:
include-wg: False
wg-fullname: Risk WG
github-link: https://github.com/chaoss/wg-risk
github-branch: master
repo-link: https://github.com/chaoss/wg-risk
repo-branch: master
focus-areas:
business-risk:
# - average-issue-resolution-time.md
Expand Down Expand Up @@ -162,8 +162,8 @@ wg-risk:
wg-value:
include-wg: True
wg-fullname: Value WG
github-link: https://github.com/chaoss/wg-value
github-branch: master
repo-link: https://github.com/chaoss/wg-value
repo-branch: master
focus-areas:
communal-value:
- project-popularity.md
Expand Down
4 changes: 2 additions & 2 deletions automation-english/english_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def english_main(english_yml_filename):
if yaml_data[wg_name]['include-wg']:

# clone repo with specified branch in yaml data
print(f"\nCloning from URL: {yaml_data[wg_name]['github-link']}\nBranch: {yaml_data[wg_name]['github-branch']}\n")
helper.clone_repo(yaml_data[wg_name]['github-link'], wg_name, yaml_data[wg_name]['github-branch'])
print(f"\nCloning from URL: {yaml_data[wg_name]['repo-link']}\nBranch: {yaml_data[wg_name]['repo-branch']}\n")
helper.clone_repo(yaml_data[wg_name]['repo-link'], wg_name, yaml_data[wg_name]['repo-branch'])

main.included_wgs.append(wg_name)
included_focus_areas = []
Expand Down
46 changes: 34 additions & 12 deletions automation-english/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class color:


def copy_file(source_filepath, dest_path):
"""Copies file from source path to destination.
Replaces the file if it already exists
"""

if os.path.isfile(dest_path):
print(color.RED,f"Warning: File with same name already exists at destination: {source_filepath}",color.END)
Expand All @@ -39,6 +42,9 @@ def copy_file(source_filepath, dest_path):
sys.exit(1)

def copy_dir_files(source_folder_path, dest_folder_path):
"""Copies all files from source directory to destination directory
Replaces the files if they already exist
"""

try:
if os.path.isdir(source_folder_path):
Expand All @@ -58,13 +64,16 @@ def copy_dir_files(source_folder_path, dest_folder_path):
sys.exit(1)

def convert_md2tex(md_filename, latex_filename):
"""Converts specified markdown file to LaTeX"""

print(f"Converting {md_filename} file to LaTeX")
output = pypandoc.convert_file(md_filename, 'latex', outputfile=latex_filename, extra_args=['-f', 'gfm'])
assert output == ""
print(f"Created successfully: {latex_filename}")

def clean_directory(folder_path):
"""Deletes the specified directory"""

try:
if os.path.isdir(folder_path):
print(f"\nCleaning directory: {folder_path}")
Expand All @@ -74,6 +83,7 @@ def clean_directory(folder_path):
print(color.RED,f"\nWarning: Unable to clean directory: {folder_path}",color.END)

def load_yaml(file_path):
"""Loads data from given YAML file in the form of dictionary"""

try:
with open(file_path) as stream:
Expand All @@ -86,6 +96,7 @@ def load_yaml(file_path):
sys.exit(1)

def decrease_level(metric_path):
"""Replaces '# ' with '### ' anywhere in the file"""

try:
print(f"\nDecreasing heading levels by 2 in metric: {metric_path}")
Expand All @@ -96,20 +107,23 @@ def decrease_level(metric_path):
sys.exit(1)

def delete_dictkey(key, dictionary):
"""Deletes given key from given dictionary"""

if key in dictionary:
del dictionary[key]
else:
print(color.RED,f"Warning: Key- {key} not found in {dictionary}",color.RED)

def is_url(string):
"""Checks if the given string is a valid URL"""

if validators.url(string):
return True
else:
return False

def clone_repo(url, name, branch):
"""Clones repository and checkout the given branch"""

try:
subprocess.check_call(['git', 'clone', '-b', branch, url, name])
Expand All @@ -119,6 +133,9 @@ def clone_repo(url, name, branch):
sys.exit(1)

def add_front_matter(yaml_data):
"""Creates the latex file to add content just after
the table of contents in PDF
"""

# Create and include front matter files
with open("front-matter.tex", "w") as front_matter:
Expand Down Expand Up @@ -152,6 +169,7 @@ def add_front_matter(yaml_data):
master_file.write("\n\include{front-matter}")

def add_end_matter(yaml_data):
"""Creates latex file to add content at the end of PDF"""

# Create and include end matter files
with open("end-matter.tex", "w") as end_matter:
Expand Down Expand Up @@ -185,16 +203,20 @@ def add_end_matter(yaml_data):
convert_md2tex("LICENSE.md", "LICENSE.tex")
end_matter.write("\clearpage\n\section{LICENSE}\n\input{LICENSE}\n")
else:
print(color.RED,f"Error: Could not incorporate {page} in end matter.\nPlease make sure that the filename is valid. Only Markdown/LaTeX file format is supported.",color.END)
print(color.RED,f"Error: Could not incorporate {page} in end matter.")
print(f"Please make sure that the filename is valid. Only Markdown/LaTeX file format is supported.",color.END)
sys.exit(1)

else:
print(color.RED,"Warning: No documents detected for the end-matter",color.END)


def spilt_by_colon(string):
"""Splits the string in two using priority list of colon delimiters.
Returns only the latter half
"""

colon_list = [":**", ":",":", "ː", "˸", "᠄", "⍠", "꞉", "︓", " "]
colon_list = [":**", ":**", ":", ":", "ː", "˸", "᠄", "⍠", "꞉", "︓", " "]
i=0
while (i<len(colon_list)):
try:
Expand All @@ -209,6 +231,7 @@ def spilt_by_colon(string):
sys.exit(1)

def extract_question(metric):
"""Extracts the name and question from the given metric"""

with open(metric) as f:
data = f.readlines()
Expand All @@ -226,6 +249,7 @@ def extract_question(metric):
return metric_name, metric_question

def extract_goal(focus_area_README):
"""Extracts the name and goal from given focus area README"""

with open(focus_area_README) as f:
data = f.readlines()
Expand All @@ -240,13 +264,13 @@ def extract_goal(focus_area_README):
return focus_area_name, focus_area_goal

def generate_focus_areas(focus_area_filename, focus_area_README, metrics, english_template):
"""Dynamically creates the table of metrics"""

table_head = english_template.template_focus_areas
table_tail = english_template.template_end

focus_area_name, focus_area_goal = extract_goal(focus_area_README)

# table_head = table_head.replace("$FOCUS_AREA_NAME$", focus_area_name.title().replace('-', ' '))
table_head = table_head.replace("$FOCUS_AREA_NAME$", focus_area_name)
table_head = table_head.replace("$FOCUS_AREA_GOAL$", focus_area_goal)

Expand All @@ -266,10 +290,11 @@ def generate_focus_areas(focus_area_filename, focus_area_README, metrics, englis

print(f"\nGenerating focus-area file = {focus_area_filename}")

def focus_areas_table(wg_tex_file, section_name, focus_areas_list, english_template):
def focus_areas_table(wg_tex_file, section_name, focus_areas_list, language_template):
"""Dynamically creates tables of focus areas in a working group"""

table_head = english_template.template_working_group
table_tail = english_template.template_end
table_head = language_template.template_working_group
table_tail = language_template.template_end

table_head = table_head.replace("$SECTION_NAME$", section_name)

Expand All @@ -294,14 +319,11 @@ def print_summary(wg_count, focus_area_count, metric_count):
print("="*29,color.END)

def print_final_msg(pdf_filename):

print(color.CYAN)
print("Created the final PDF ->",color.GREEN,pdf_filename)
print(color.CYAN)

final_path = "./output/" + pdf_filename
print("\nLogs are saved in",color.GREEN,"logs.txt",color.CYAN)
print("Output PDF is saved in",color.GREEN,final_path,color.END)

# if __name__ == "__main__":
#
# print(spilt_by_colon("**目标:** 了解组织和个人正在做出哪些贡献。"))
print("\nLogs are saved in", color.GREEN, "logs.txt", color.CYAN)
print("Output PDF is saved in", color.GREEN, final_path, color.END)
4 changes: 2 additions & 2 deletions automation-english/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
english_yml_filename = "english_working-groups-config.yml"
spanish_yml_filename = "spanish_working-groups-config.yml"
chinese_yml_filename = "chinese_working-groups-config.yml"
translations = {"github-link": "https://github.com/chaoss/translations", "github-branch": "main", "repo-name": "translations" }
translations = {"repo-link": "https://github.com/chaoss/translations", "repo-branch": "main", "repo-name": "translations" }
master_file_path = "master.tex"
test_dir = "test_env"
current_dir = "./"
Expand Down Expand Up @@ -79,7 +79,7 @@ def main():
print(helper.color.END)

# clone translation repo and auto-detect langauge
helper.clone_repo(translations["github-link"], translations["repo-name"],translations["github-branch"])
helper.clone_repo(translations["repo-link"], translations["repo-name"],translations["repo-branch"])
detected_languages = [dir for dir in sorted(os.listdir(translations["repo-name"])) if os.path.isdir(os.path.join(translations["repo-name"], dir)) and dir[0] != "."]
print(helper.color.YELLOW)
print("="*60)
Expand Down