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

Commit

Permalink
Merge pull request #29 from chaoss/common-dev-3
Browse files Browse the repository at this point in the history
Merge 'english_release.py' and 'translations_release.py' to 'metric_release.py'
  • Loading branch information
ritik-malik committed Aug 9, 2021
2 parents 5e05b12 + 18ffb85 commit 097122d
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ wg-common:
wg-fullname: Common Metrics WG
repo-link: None
repo-branch: None
focus-areas-location: translations/chinese/wg-common/focus-areas
focus-areas:
contributions:
- technical-fork.md
Expand All @@ -45,6 +46,7 @@ wg-diversity-inclusion:
wg-fullname: Diversity, Equity and Inclusion WG
repo-link: None
repo-branch: None
focus-areas-location: translations/chinese/wg-diversity-inclusion/focus-areas
focus-areas:
# communication-inclusivity:
# - alternatives.md
Expand Down Expand Up @@ -98,6 +100,7 @@ wg-evolution:
wg-fullname: Evolution WG
repo-link: None
repo-branch: None
focus-areas-location: translations/chinese/wg-evolution/focus-areas
focus-areas:
code-development-activity:
- branch-lifecycle.md
Expand Down Expand Up @@ -131,6 +134,7 @@ wg-risk:
wg-fullname: Risk WG
repo-link: None
repo-branch: None
focus-areas-location: translations/chinese/wg-risk/focus-areas
focus-areas:
business-risk:
# - average-issue-resolution-time.md
Expand Down Expand Up @@ -165,6 +169,7 @@ wg-value:
wg-fullname: Value WG
repo-link: None
repo-branch: None
focus-areas-location: translations/chinese/wg-value/focus-areas
focus-areas:
communal-value:
# - project-popularity.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ wg-common:
wg-fullname: Common Metrics WG
repo-link: https://github.com/chaoss/wg-common
repo-branch: master
focus-areas-location: wg-common/focus-areas
focus-areas:
contributions:
- technical-fork.md
Expand All @@ -44,6 +45,7 @@ wg-diversity-inclusion:
wg-fullname: Diversity, Equity and Inclusion WG
repo-link: https://github.com/chaoss/wg-diversity-inclusion
repo-branch: master
focus-areas-location: wg-diversity-inclusion/focus-areas
focus-areas:
# communication-inclusivity:
# - alternatives.md
Expand Down Expand Up @@ -97,6 +99,7 @@ wg-evolution:
wg-fullname: Evolution WG
repo-link: https://github.com/chaoss/wg-evolution
repo-branch: master
focus-areas-location: wg-evolution/focus-areas
focus-areas:
code-development-activity:
- branch-lifecycle.md
Expand Down Expand Up @@ -130,6 +133,7 @@ wg-risk:
wg-fullname: Risk WG
repo-link: https://github.com/chaoss/wg-risk
repo-branch: master
focus-areas-location: wg-risk/focus-areas
focus-areas:
business-risk:
# - average-issue-resolution-time.md
Expand Down Expand Up @@ -164,6 +168,7 @@ wg-value:
wg-fullname: Value WG
repo-link: https://github.com/chaoss/wg-value
repo-branch: master
focus-areas-location: wg-value/focus-areas
focus-areas:
communal-value:
- project-popularity.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ wg-common:
wg-fullname: Common Metrics WG
repo-link: https://github.com/chaoss/wg-common
repo-branch: master
focus-areas-location: translations/spanish/wg-common/focus-areas
focus-areas:
contributions:
- technical-fork.md
Expand All @@ -44,6 +45,7 @@ wg-diversity-inclusion:
wg-fullname: Diversity, Equity and Inclusion WG
repo-link: https://github.com/chaoss/wg-diversity-inclusion
repo-branch: master
focus-areas-location: translations/spanish/wg-diversity-inclusion/focus-areas
focus-areas:
# communication-inclusivity:
# - alternatives.md
Expand Down Expand Up @@ -97,6 +99,7 @@ wg-evolution:
wg-fullname: Evolution WG
repo-link: https://github.com/chaoss/wg-evolution
repo-branch: master
focus-areas-location: translations/spanish/wg-evolution/focus-areas
focus-areas:
code-development-activity:
- branch-lifecycle.md
Expand Down Expand Up @@ -130,6 +133,7 @@ wg-risk:
wg-fullname: Risk WG
repo-link: https://github.com/chaoss/wg-risk
repo-branch: master
focus-areas-location: translations/spanish/wg-risk/focus-areas
focus-areas:
business-risk:
# - average-issue-resolution-time.md
Expand Down Expand Up @@ -164,6 +168,7 @@ wg-value:
wg-fullname: Value WG
repo-link: https://github.com/chaoss/wg-value
repo-branch: master
focus-areas-location: translations/spanish/wg-value/focus-areas
focus-areas:
communal-value:
- project-popularity.md
Expand Down
4 changes: 4 additions & 0 deletions automation/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def clone_repo(url, name, branch):

try:
subprocess.check_call(['git', 'clone', '-b', branch, url, name])
except subprocess.CalledProcessError:
print(color.RED,f"Error: Repository with name: {name} already exists")
print("Please ensure only one link is present in the YAML file")

except:
print(color.RED,f"Error: Unable to clone/checkout repository from {url}")
print("Verify the repository details specified in YAML file.",color.END)
Expand Down
File renamed without changes.
22 changes: 8 additions & 14 deletions automation/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import os
import english_release
import translations_release
import helper
import metrics_release

##### Global Vars #####

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 = {"repo-link": "https://github.com/chaoss/translations", "repo-branch": "main", "repo-name": "translations" }
master_file_path = "master.tex"
test_dir = "test_env"
current_dir = "./"
included_wgs = []



def language_input():
Expand All @@ -38,11 +33,8 @@ def language_input():

def main():

global included_wgs
global english_yml_filename
global master_file_path
global test_dir
global current_dir

# select language
language = language_input()
Expand All @@ -61,8 +53,8 @@ def main():


# Copy the scripts
helper.copy_dir_files("../active_user_input", current_dir)
helper.copy_dir_files("../passive_user_input", current_dir)
helper.copy_dir_files("../active_user_input", "./")
helper.copy_dir_files("../passive_user_input", "./")

if language == '1':
print(helper.color.GREEN)
Expand All @@ -71,7 +63,8 @@ def main():
print(helper.color.END)

# main over - switch to new script
english_release.english_main(english_yml_filename)
# english_release.english_main(english_yml_filename)
metrics_release.release_main("english")

else:
print(helper.color.GREEN)
Expand Down Expand Up @@ -101,7 +94,8 @@ def main():
helper.color.END

# main over - call translation scripts
translations_release.translations_main(detected_languages[user_inp])
# translations_release.translations_main(detected_languages[user_inp])
metrics_release.release_main(detected_languages[user_inp])

if __name__ == "__main__":
main()
168 changes: 168 additions & 0 deletions automation/metrics_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import os
import shutil
import main
import helper
import table_templates
import inspect
import sys
from pydoc import locate

def check_is_yml_file(language, yml_filename):

print("Check: Searching for YML file")
if os.path.isfile(yml_filename):
print(f"Found YML file successfully: {yml_filename}\n")
return True
else:
print(helper.color.RED,f"Error: Unable to detect YML file for {language}.")
print(f"Specify/check if the filename is: {yml_filename}",helper.color.END)
return False
sys.exit(1)

def check_is_cover_file(language, cover_filename):

print("Check: Searching for cover page file")
if os.path.isfile(cover_filename):
print(f"Found cover page file successfully: {cover_filename}\n")
else:
print(helper.color.RED,f"Error: Unable to detect cover page file for {language}.")
print(f"Specify/check if the filename is: {cover_filename}",helper.color.END)
sys.exit(1)

def check_is_class_exist(language, class_name):

print("Check: Finding language class in templates")

if bool(class_name in [class_tuple[0] for class_tuple in inspect.getmembers(table_templates)]):
print(f"Class found successfully: {class_name}\n")
else:
print(helper.color.RED,f"Error: Unable to detect language class - '{class_name}' for language {language}")
print("Make sure that class for language exists or create one in 'table_templates.py' ",helper.color.END)
sys.exit(1)


def release_main(language):

included_wgs = []
focus_area_count = 0
metric_count = 0
yml_filename = language + "_working-groups-config.yml"
cover_filename = language + "_cover.tex"
class_name = language.title()

print()
check_is_yml_file(language, yml_filename)
check_is_cover_file(language, cover_filename)
check_is_class_exist(language, class_name)
print(helper.color.GREEN, "Passed all checks successfully", helper.color.END)


# Read the yml file
print("\nReading the YML file:\n")
yaml_data = helper.load_yaml(yml_filename)

# add front and end matter
helper.add_front_matter(yaml_data)
helper.add_end_matter(yaml_data)

# delete front and end matter from yml
helper.delete_dictkey("front-matter", yaml_data)
helper.delete_dictkey("end-matter", yaml_data)


language_class = locate('table_templates.' + class_name)
language_template = language_class()

# LOOP #1: For Working Groups
for wg_name in yaml_data.keys():
if yaml_data[wg_name]['include-wg']:

if helper.is_url(yaml_data[wg_name]['repo-link']):
# clone repo with specified branch in yaml data
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'])

else:
print(helper.color.RED, f"Warning: In {yaml_data[wg_name]['wg-fullname']}, {yaml_data[wg_name]['repo-link']} is not a valid URL ")
print("Check the repository details in the YAML file", helper.color.END)

included_wgs.append(wg_name)
included_focus_areas = []
focus_area_README_list = []

# LOOP #2: For Focus Areas
for focus_area, metrics in yaml_data[wg_name]["focus-areas"].items():
converted_tex_files = []
if metrics is not None:

# LOOP #3: For Metrics
for metric in metrics:
metric_path = os.path.join(yaml_data[wg_name]["focus-areas-location"], focus_area, metric)

shutil.copy2(metric_path, "./")
# helper.copy_file(metric_path, "./")
helper.decrease_level(metric)
tex_filename = os.path.splitext((metric))[0] + ".tex"

helper.convert_md2tex(metric, tex_filename)
converted_tex_files.append(tex_filename)

# copy images of particular focus-area
if not os.path.isdir("images"):
print(f"\nMaking images directory")
os.makedirs("images")
helper.copy_dir_files(
os.path.join(yaml_data[wg_name]["focus-areas-location"], focus_area, "images"),
os.path.join("./", "images"))

focus_area_README = os.path.join(yaml_data[wg_name]["focus-areas-location"], focus_area, "README.md")

# to be used in focus-areas table for WG.tex
focus_area_README_list.append([focus_area, focus_area_README])

# create focus_area.tex file and add table
focus_area_filename = wg_name + "_" + focus_area + ".tex"
helper.generate_focus_areas(focus_area_filename, focus_area_README, metrics,
language_template)
included_focus_areas.append(focus_area_filename)

# Add inclusion commands for metrics
with open(focus_area_filename, "a") as fa_tex_file:
fa_tex_file.write("\n")
for metric_tex_file in converted_tex_files:
fa_tex_file.write(f"\input{{{os.path.splitext(metric_tex_file)[0]}}} \n")

metric_count += len(converted_tex_files)

# create WG.tex file
wg_tex_file_path = os.path.join("./", wg_name + ".tex")

with open(wg_tex_file_path, "w") as wg_tex_file:
wg_tex_file.write("\n")

# add focus areas table to WG.tex
helper.focus_areas_table(wg_tex_file, yaml_data[wg_name]['wg-fullname'], focus_area_README_list,
language_template)
wg_tex_file.write("\n\clearpage\n")

for fa in included_focus_areas:
wg_tex_file.write(f"\input{{{os.path.splitext(fa)[0]}}} \n")

focus_area_count += len(included_focus_areas)

# create master file to include WG.tex files
with open(main.master_file_path, "a") as master_file:
master_file.write("\n")

for wg in included_wgs:
master_file.write(f"\include{{{wg}}} \n")

master_file.write("\n\end{document}\n")

# create final PDF
pdf_filename = language_template.convert_tex2pdf(main.master_file_path)
helper.copy_file(pdf_filename, "../output")

helper.print_summary(len(included_wgs), focus_area_count, metric_count)
helper.print_final_msg(pdf_filename)

2 changes: 1 addition & 1 deletion automation/table_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pypandoc
from datetime import datetime

class english:
class English:

template_working_group = r'''
\section{$SECTION_NAME$}
Expand Down

0 comments on commit 097122d

Please sign in to comment.