Combine CustomUI.xml with template xml files to create a new add-in file. Args: template_path (str): directory for template xml files extracted from a general add-in file. custom_ui_filename (str): full path to CustomUI.xml defining the ribbon UI.
(self, template_path:str, custom_ui_filename:str='CustomUI.xml')
| 16 | |
| 17 | |
| 18 | def create(self, template_path:str, custom_ui_filename:str='CustomUI.xml'): |
| 19 | '''Combine CustomUI.xml with template xml files to create a new add-in file. |
| 20 | |
| 21 | Args: |
| 22 | template_path (str): directory for template xml files extracted from a general add-in file. |
| 23 | custom_ui_filename (str): full path to CustomUI.xml defining the ribbon UI. |
| 24 | ''' |
| 25 | # copy template files to current path if they're not under current path |
| 26 | work_path = os.path.join(self.path, os.path.basename(template_path)) |
| 27 | if work_path.upper() != template_path.upper(): |
| 28 | # delete dest dir if exists, otherwise the copy will be forbidden |
| 29 | if os.path.isdir(work_path): shutil.rmtree(work_path) |
| 30 | shutil.copytree(template_path, work_path) |
| 31 | |
| 32 | # copy customUI.xml to path/template/customUI |
| 33 | dest_ui_path = os.path.join(work_path, 'customUI') |
| 34 | if not os.path.exists(dest_ui_path): |
| 35 | os.mkdir(dest_ui_path) |
| 36 | shutil.copy(custom_ui_filename, dest_ui_path) |
| 37 | |
| 38 | # archive xml files and remove original package |
| 39 | shutil.make_archive(os.path.join(self.path, self.name), 'zip', work_path) |
| 40 | shutil.rmtree(work_path) |
| 41 | |
| 42 | # convert to add-in *.xlam |
| 43 | zip_file = os.path.join(self.path, f'{self.name}.zip') |
| 44 | shutil.move(zip_file, self.xlam_file) |
| 45 | |
| 46 | |
| 47 | def update(self, custom_ui_filename:str='CustomUI.xml'): |