Skip to content

Commit

Permalink
Merge pull request #15 from itoffshore/testing
Browse files Browse the repository at this point in the history
add template regeneration to template downloads
  • Loading branch information
itoffshore committed Oct 23, 2023
2 parents 9371889 + a17de4b commit 3108172
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 10 deletions.
Binary file removed dist/distrobuilder_menu-0.2.0.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/distrobuilder_menu-0.2.1.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "hatchling.build"

[project]
name = "distrobuilder_menu"
version = "0.2.0"
version = "0.2.1"
authors = [
{ name="Stuart Cardall", email="developer@it-offshore.co.uk" },
]
Expand Down
6 changes: 3 additions & 3 deletions src/distrobuilder_menu/api/gethub.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def check_url(self, url):


def download_files(self, file_dict):
""" As input takes a dict with keys: 'url' / 'file' as the
source & destination of file downloads. Input is generated
by update_templates() in the main application.
""" As input takes a list of dicts with keys: 'url' / 'file' as the
source & destination of file downloads. Input is generated by
update_templates() in the main application.
"""
for item in file_dict:
url = item['url']
Expand Down
4 changes: 3 additions & 1 deletion src/distrobuilder_menu/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def main():

# --regen menu option
if ARGS.regenerate:
templates.create_custom_lists()
base_list, custom_list = templates.create_custom_lists()
templates.regenerate_template(base_list)
templates.regenerate_template(custom_list)

# by default show the main menu & also show it after individual options run
common.menu_default()
Expand Down
2 changes: 1 addition & 1 deletion src/distrobuilder_menu/config/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ def get_args(argv=None):
help="regenerate custom templates")
parser.add_argument("-v", "--version", action="version",
help="show dbmenu version",
version='%(prog)s 0.2.0')
version='%(prog)s 0.2.1')

return parser.parse_args(argv)
40 changes: 36 additions & 4 deletions src/distrobuilder_menu/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,43 @@ def update_templates():
# download files
if download_list:
GETHUB.download_files(download_list)
# regenerate base / custom templates
process_updates(download_list)
else:
utils.die(0, f"Template files are up to date: {USER_CONFIG.subdir_images}\n")


def process_updates(download_list):
""" Takes the list of dictionaries generated by update_templates() & compares
destination files with the 'source' key from JSON footers now added to
custom templates (so they can be regenerated)
Args:
download_list (list): list of dicts expecting keys: 'url' / 'file'
"""
regenerate_base, regenerate_custom = [], []
base_list, custom_list = create_custom_lists()

# base_list
for item_file in download_list:
downloaded_file = str(item_file['file'])

for item_json in base_list:
if downloaded_file == item_json['source']:
regenerate_base.append(item_json)

# custom_list
for item_base in regenerate_base:
base_destination = item_base['destination']

for item_custom in custom_list:
if item_custom['source'] == base_destination:
regenerate_custom.append(item_custom)

regenerate_template(regenerate_base)
regenerate_template(regenerate_custom)


def process_data(lxd_json_data):
"""Parses LXD json data & Returns a list of dicts with
relevant template build options.
Expand Down Expand Up @@ -243,12 +276,11 @@ def create_custom_lists():
fail_list.append(key)

if fail_list:
print(f"WARN: unable to regenerate templates: {fail_list} => no dbmenu footer")
print(f"\nWARN: unable to regenerate templates: {fail_list} => no dbmenu footer")
else:
print("INFO: all custom templates have a dbmenu footer")
print("\nINFO: all custom templates have a dbmenu footer")

regenerate_template(base_list)
regenerate_template(custom_list)
return base_list, custom_list


def regenerate_template(json_data_list):
Expand Down

0 comments on commit 3108172

Please sign in to comment.