Skip to content
Snippets Groups Projects
Commit 9c24a7bd authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

consolidate

parent d77c6952
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,13 @@ python update-examples.py <website-source-dir> <BornAgain-source-dir> <BornAgain ...@@ -12,6 +12,13 @@ python update-examples.py <website-source-dir> <BornAgain-source-dir> <BornAgain
import argparse, datetime, os, shutil import argparse, datetime, os, shutil
def log(msg):
flog.write(msg+"\n")
def log2(msg):
print(msg)
log(msg)
def find_files(dir_name): def find_files(dir_name):
""" """
Return recursive list of files in given dir_name Return recursive list of files in given dir_name
...@@ -42,14 +49,23 @@ def find_files_with_same_name(filename_list, name_to_find): ...@@ -42,14 +49,23 @@ def find_files_with_same_name(filename_list, name_to_find):
return same_names return same_names
def copy_files(source_list, destination_list): def update_all_files_of_one_type(source, destination, extension):
""" """
Every file in destination_list will be replaced by the file with the same Every file in dest_list will be replaced by the file with the same
basename found in source_list basename found in source_list
""" """
source_list = get_files(source, extension)
dest_list = get_files(destination, extension)
log2(f'Update {len(dest_list)} {extension} files')
log2(f' from {source}')
log2(f' to {destination}')
log(f' {dest_list}')
missed_files = [] missed_files = []
updated_files = [] updated_files = []
for f in destination_list: for f in dest_list:
found_source = find_files_with_same_name(source_list, os.path.basename(f)) found_source = find_files_with_same_name(source_list, os.path.basename(f))
if len(found_source) == 1: if len(found_source) == 1:
updated_files.append(f) updated_files.append(f)
...@@ -68,19 +84,6 @@ def copy_files(source_list, destination_list): ...@@ -68,19 +84,6 @@ def copy_files(source_list, destination_list):
print(f) print(f)
def update_all_files_of_one_type(source, destination, extension):
source_files = get_files(source, extension)
website_files = get_files(destination, extension)
print(f'Update {len(website_files)} {extension} files ...')
flog.write(f'Update {len(website_files)} {extension} files:')
flog.write(f' {website_files}')
copy_files(source_files, website_files)
def update_website(website_source_dir, ba_source_dir, ba_build_dir): def update_website(website_source_dir, ba_source_dir, ba_build_dir):
""" """
Updates example scripts and images on website. Updates example scripts and images on website.
...@@ -92,25 +95,17 @@ def update_website(website_source_dir, ba_source_dir, ba_build_dir): ...@@ -92,25 +95,17 @@ def update_website(website_source_dir, ba_source_dir, ba_build_dir):
global flog global flog
flog = open(log_path, "a") flog = open(log_path, "a")
print(f'Appending log to {log_path}') print(f'Appending log to {log_path}')
flog.write(f'\n===\n{datetime.datetime.now().strftime("%d%b%y %H:%M:%S")}\n') log(f'\n===\n{datetime.datetime.now().strftime("%d%b%y %H:%M:%S")}')
user_source_dir = os.path.expanduser(ba_source_dir)
user_build_dir = os.path.expanduser(ba_build_dir)
user_image_dir = os.path.join(user_build_dir, "test_output/Functional/PyExamples")
flog.write('Directories:\n')
flog.write(f' website_dir : {website_dirpath}\n')
flog.write(f' source_dir : {user_source_dir}\n')
flog.write(f' build_dir : {user_build_dir}\n')
flog.write(f' image_dir : {user_image_dir}\n')
website = os.path.join(website_dirpath, "static/files/python") update_all_files_of_one_type(
source = os.path.join(user_source_dir, "Examples/Python") os.path.join(ba_source_dir, "Examples/Python"),
update_all_files_of_one_type(source, website_dirpath, '.py') os.path.join(website_dirpath, "static/files/python"),
'.py')
website = os.path.join(website_dirpath, "content/documentation/examples") update_all_files_of_one_type(
source = user_image_dir os.path.join(website_dirpath, "content/documentation/examples"),
update_all_files_of_one_type(source, website_dirpath, '.png') os.path.join(ba_build_dir, "test_output/Functional/PyExamples"),
'.png')
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment