-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from BDadmehr0/python
Refactor & Modular /config python files
- Loading branch information
Showing
13 changed files
with
307 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
import yaml | ||
from typing import Dict, List | ||
|
||
FILE = "language.yaml" | ||
|
||
file = open(FILE, "r", encoding="utf-8") | ||
docs = yaml.safe_load_all(file) | ||
from module.utils import error, load_yaml | ||
from module.validation import validate_item_structure | ||
|
||
FILE = "language.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
def error(msg: str) -> None: | ||
print("Error: " + msg) | ||
exit(1) | ||
|
||
docs: List[Dict] = load_yaml(FILE) | ||
|
||
if __name__ == "__main__": | ||
for doc in docs: | ||
for item in doc["items"]: | ||
if "id" not in item: | ||
print(item) | ||
error("id is required and missed in an item") | ||
|
||
if "name" not in item: | ||
print(item) | ||
error("name is required and missed in an item") | ||
|
||
if "local_name" not in item: | ||
for item in doc.get("items", []): | ||
try: | ||
validate_item_structure(item, LANGUAGES) | ||
except ValueError as e: | ||
print(item) | ||
error("local_name is required and missed in an item") | ||
error(str(e)) | ||
|
||
print(FILE + ": Validation is successful") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import yaml | ||
import os | ||
import sys | ||
|
||
FILE = "global_value.yaml" | ||
sys.path.append( | ||
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module")) | ||
) | ||
|
||
from utils import error, load_yaml | ||
from validation import validate_item_structure | ||
|
||
FILE = os.path.join(os.path.dirname(__file__), "global_value.yaml") | ||
LANGUAGES = ["en", "fa"] | ||
|
||
file = open(FILE, "r", encoding="utf-8") | ||
docs = yaml.safe_load_all(file) | ||
|
||
if __name__ == "__main__": | ||
try: | ||
docs = load_yaml(FILE) | ||
|
||
def error(msg: str) -> None: | ||
print("Error: " + msg) | ||
exit(1) | ||
for doc in docs: | ||
for item in doc.get("items", []): | ||
try: | ||
validate_item_structure(item, LANGUAGES) | ||
except ValueError as e: | ||
print(item) | ||
error(str(e)) | ||
|
||
print(FILE + ": Validation is successful") | ||
|
||
if __name__ == "__main__": | ||
for doc in docs: | ||
for item in doc["items"]: | ||
if "id" not in item: | ||
print(item) | ||
error("id is required and missed in an item") | ||
|
||
if "text" in item: | ||
for lang in LANGUAGES: | ||
if lang not in item["text"]: | ||
print(item) | ||
error("text is required for " + lang + " language") | ||
|
||
print(FILE + ": Validation is successful") | ||
except Exception as e: | ||
error(f"An unexpected error occurred: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,29 @@ | ||
import yaml | ||
import os | ||
import sys | ||
|
||
FILE = "global_value.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
file = open(FILE, "r", encoding="utf-8") | ||
docs = yaml.safe_load_all(file) | ||
sys.path.append( | ||
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module")) | ||
) | ||
|
||
from utils import error, load_yaml | ||
from validation import validate_item_structure | ||
|
||
def error(msg: str) -> None: | ||
print("Error: " + msg) | ||
exit(1) | ||
|
||
FILE = os.path.join(os.path.dirname(__file__), "state.yaml") | ||
LANGUAGES = ["en", "fa"] | ||
|
||
if __name__ == "__main__": | ||
for doc in docs: | ||
for item in doc["items"]: | ||
if "id" not in item: | ||
print(item) | ||
error("id is required and missed in an item") | ||
try: | ||
docs = load_yaml(FILE) | ||
|
||
if "generate_name" not in item: | ||
print(item) | ||
error("generate_name is required") | ||
for doc in docs: | ||
for item in doc.get("items", []): | ||
try: | ||
validate_item_structure(item, LANGUAGES) | ||
except ValueError as e: | ||
print(item) | ||
error(str(e)) | ||
|
||
if "text" in item: | ||
for lang in LANGUAGES: | ||
if lang not in item["text"]: | ||
print(item) | ||
error("text is required for " + lang + " language") | ||
print(FILE + ": Validation is successful") | ||
|
||
print(FILE + ": Validation is successful") | ||
except Exception as e: | ||
error(f"An unexpected error occurred: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,29 @@ | ||
import yaml | ||
import os | ||
import sys | ||
|
||
FILE = "type.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
file = open(FILE, "r", encoding="utf-8") | ||
docs = yaml.safe_load_all(file) | ||
sys.path.append( | ||
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module")) | ||
) | ||
|
||
from utils import error, load_yaml | ||
from validation import validate_item_structure | ||
|
||
def error(msg: str) -> None: | ||
print("Error: " + msg) | ||
exit(1) | ||
|
||
FILE = "type.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
if __name__ == "__main__": | ||
for doc in docs: | ||
for item in doc["items"]: | ||
if "id" not in item: | ||
print(item) | ||
error("id is required and missed in an item") | ||
|
||
if "type" not in item: | ||
print(item) | ||
error("type is required") | ||
|
||
if "generate_name" in item: | ||
if "reserved_values" not in item: | ||
print(item) | ||
error("reserved_values is required") | ||
if "text" not in item: | ||
print(item) | ||
error("text is required") | ||
else: | ||
if "reserved_values" in item: | ||
print(item) | ||
error("Why reserved_values exists for a non-generate_name item?") | ||
if "text" in item: | ||
try: | ||
docs = load_yaml(FILE) | ||
|
||
for doc in docs: | ||
for item in doc.get("items", []): | ||
try: | ||
validate_item_structure(item, LANGUAGES) | ||
except ValueError as e: | ||
print(item) | ||
error("Why text exists for a non-generate_name item?") | ||
error(str(e)) | ||
|
||
if "text" in item: | ||
for lang in LANGUAGES: | ||
if lang not in item["text"]: | ||
print(item) | ||
error("text is required for " + lang + " language") | ||
print(FILE + ": Validation is successful") | ||
|
||
print(FILE + ": Validation is successful") | ||
except Exception as e: | ||
error(f"An unexpected error occurred: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
import yaml | ||
import os | ||
import sys | ||
|
||
sys.path.append( | ||
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module")) | ||
) | ||
|
||
from utils import error, load_yaml | ||
from validation import validate_item_structure | ||
|
||
FILE = "value.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
file = open(FILE, "r", encoding="utf-8") | ||
docs = yaml.safe_load_all(file) | ||
if __name__ == "__main__": | ||
try: | ||
docs = load_yaml(FILE) | ||
|
||
for doc in docs: | ||
for key in doc.get("items", {}): | ||
items = doc["items"][key] | ||
|
||
def error(msg: str) -> None: | ||
print("Error: " + msg) | ||
exit(1) | ||
if items is not None: | ||
for item in items: | ||
validate_item_structure(item, LANGUAGES) | ||
|
||
print(FILE + ": Validation is successful") | ||
|
||
if __name__ == "__main__": | ||
for doc in docs: | ||
for key in doc["items"]: | ||
items = doc["items"][key] | ||
|
||
if items is not None: | ||
for item in items: | ||
if "generate_name" not in item: | ||
print(item) | ||
error("generate_name is required") | ||
|
||
if "text" not in item: | ||
print(item) | ||
error("text is required") | ||
|
||
for lang in LANGUAGES: | ||
if lang not in item["text"]: | ||
print(item) | ||
error("text is required for " + lang + " language") | ||
|
||
print(FILE + ": Validation is successful") | ||
except Exception as e: | ||
error(f"An unexpected error occurred: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import yaml | ||
import os | ||
import sys | ||
|
||
sys.path.append( | ||
os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "module")) | ||
) | ||
|
||
from utils import error, load_yaml | ||
from validation import validate_item_structure | ||
|
||
FILE = "type.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
file = open(FILE, "r", encoding="utf-8") | ||
docs = yaml.safe_load_all(file) | ||
|
||
def main() -> None: # Add the return type annotation here | ||
try: | ||
docs = load_yaml(FILE) | ||
|
||
for doc in docs: | ||
for item in doc.get("items", []): | ||
try: | ||
validate_item_structure(item, LANGUAGES) | ||
except ValueError as e: | ||
print(item) | ||
error(str(e)) | ||
|
||
print(FILE + ": Validation is successful") | ||
|
||
def error(msg: str) -> None: | ||
print("Error: " + msg) | ||
exit(1) | ||
except Exception as e: | ||
error(f"An unexpected error occurred: {e}") | ||
|
||
|
||
if __name__ == "__main__": | ||
for doc in docs: | ||
for item in doc["items"]: | ||
if "id" not in item: | ||
print(item) | ||
error("id is required and missed in an item") | ||
|
||
if "generate_name" not in item: | ||
if "text" in item: | ||
for lang in LANGUAGES: | ||
if lang not in item["text"]: | ||
print(item) | ||
error("text is required for " + lang + " language") | ||
|
||
print(FILE + ": Validation is successful") | ||
main() # Call the main function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,29 @@ | ||
import yaml | ||
|
||
FILE = "type.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
file = open(FILE, "r", encoding="utf-8") | ||
docs = yaml.safe_load_all(file) | ||
import os | ||
import sys | ||
|
||
sys.path.append( | ||
os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "module")) | ||
) | ||
|
||
def error(msg: str) -> None: | ||
print("Error: " + msg) | ||
exit(1) | ||
from utils import error, load_yaml | ||
from validation import validate_item_structure | ||
|
||
FILE = "type.yaml" | ||
LANGUAGES = ["en", "fa"] | ||
|
||
if __name__ == "__main__": | ||
for doc in docs: | ||
for item in doc["items"]: | ||
if "id" not in item: | ||
print(item) | ||
error("id is required and missed in an item") | ||
|
||
if "is_mother" in item: | ||
if item["is_mother"] != True and item["is_mother"] != False: | ||
try: | ||
docs = load_yaml(FILE) | ||
|
||
for doc in docs: | ||
for item in doc.get("items", []): | ||
try: | ||
validate_item_structure(item, LANGUAGES) | ||
except ValueError as e: | ||
print(item) | ||
error("is_mother is invalid in an item") | ||
error(str(e)) | ||
|
||
if "text" in item: | ||
for lang in LANGUAGES: | ||
if lang not in item["text"]: | ||
print(item) | ||
error("text is required for " + lang + " language") | ||
print(FILE + ": Validation is successful") | ||
|
||
print(FILE + ": Validation is successful") | ||
except Exception as e: | ||
error(f"An unexpected error occurred: {e}") |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.