Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import files for theming #331

Merged
merged 2 commits into from
Mar 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Documentation/Theming_implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ font:
bold: 'FontName-Bold'
```

### What's New
The `whitelabel.yaml` configuration may contain the path to a What's New json file, and an existing json file in the project will be replaced with this json file.
### Files
We can override any file(s) in the project folder(s). To do this, the `whitelabel.yaml` configuration must contain the path to the file to be imported, and the existing file in the project will be replaced with this file.

For this function, the configuration must contain the following parameters:
```yaml
whatsnew:
whatsnew_import_file_path: 'path/to/importing/whats_new.json' # path to what's new json file what should be imported to project
project_whatsnew_file_path: 'path/to/json/file/in/project/whats_new.json' # path to existing json-file in project
files:
file_name:
import_file_path: 'path/to/importing/file_name.any' # path to file what should be imported to project folder
project_file_path: 'path/to/json/file/in/project/file_name.any' # path to existing file in project
```


Expand Down
50 changes: 27 additions & 23 deletions config_script/whitelabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ class WhitelabelApp:
medium: 'FontName-Medium'
semiBold: 'FontName-Semibold'
bold: 'FontName-Bold'
whatsnew:
whatsnew_import_file_path: 'path/to/importing/whats_new.json'
project_whatsnew_file_path: 'path/to/json/file/in/project/whats_new.json'
files:
file_name:
import_file_path: 'path/to/importing/file_name.any'
project_file_path: 'path/to/json/file/in/project/file_name.any'
""")

def __init__(self, **kwargs):
Expand All @@ -71,7 +72,7 @@ def __init__(self, **kwargs):
self.assets = kwargs.get('assets', {})
self.project_config = kwargs.get('project_config', {})
self.font = kwargs.get('font', {})
self.whatsnew = kwargs.get('whatsnew', {})
self.files = kwargs.get('files', {})

if self.project_config:
if "project_path" in self.project_config:
Expand All @@ -85,7 +86,7 @@ def whitelabel(self):
# Update the properties, resources, and configuration of the current app.
self.copy_assets()
self.copy_font()
self.copy_whatsnew()
self.copy_project_files()
if self.project_config:
self.set_app_project_config()

Expand Down Expand Up @@ -458,7 +459,7 @@ def copy_file(self, file_src, file_dest, title):
except IOError as e:
logging.error("Unable to copy file. "+e)
else:
logging.debug(title+" file was copied to project")
logging.debug(title+" file was replaced in project")

def set_font_names(self, font_names):
if "project_font_names_json_path" in self.font:
Expand All @@ -480,27 +481,30 @@ def set_font_names(self, font_names):
else:
logging.error("'project_font_names_json_path' not found in config")

def copy_whatsnew(self):
# check if whatsnew config exists
if self.whatsnew:
if "whatsnew_import_file_path" in self.whatsnew:
whatsnew_import_file_path = self.whatsnew["whatsnew_import_file_path"]
if "project_whatsnew_file_path" in self.whatsnew:
project_whatsnew_file_path = self.whatsnew["project_whatsnew_file_path"]
# if source and destination file exist
if os.path.exists(whatsnew_import_file_path):
if os.path.exists(project_whatsnew_file_path):
self.copy_file(whatsnew_import_file_path, project_whatsnew_file_path, "What's new")
def copy_project_files(self):
# check if files config exists
if self.files:
for copy_file_data in self.files.items():
file_name = copy_file_data[0]
copy_file = copy_file_data[1]
if "import_file_path" in copy_file:
import_file_path = copy_file["import_file_path"]
if "project_file_path" in copy_file:
project_file_path = copy_file["project_file_path"]
# if source and destination file exist
if os.path.exists(import_file_path):
if os.path.exists(project_file_path):
self.copy_file(import_file_path, project_file_path, file_name)
else:
logging.error(project_file_path+" file doesn't exist")
else:
logging.error(project_whatsnew_file_path+" file doesn't exist")
logging.error(import_file_path+" file doesn't exist")
else:
logging.error(whatsnew_import_file_path+" file doesn't exist")
logging.error("'project_file_path' for "+file_name+" not found in config")
else:
logging.error("'project_whatsnew_file_path' not found in config")
else:
logging.error("'whatsnew_import_file_path' not found in config")
logging.error("'import_file_path' for "+file_name+" not found in config")
else:
logging.debug("What's New not found in config")
logging.debug("Project's Files for copying not found in config")

def main():
"""
Expand Down
Loading