gravityatom / make_theme

Themify virtual machine for cybersecurity training
0 stars 1 forks source link

No background image file in avengers theme #3

Open dmacduff opened 2 years ago

dmacduff commented 2 years ago

Summary

make_theme.py fails when run with --theme avengers due to no avengers.jpg file.

Error trace:

sudo ./make_theme.py --theme avengers
Traceback (most recent call last):
  File "/home/demo/make_theme/./make_theme.py", line 522, in <module>
    set_customizations(theme_conf)
  File "/home/demo/make_theme/./make_theme.py", line 57, in set_customizations
    set_background(theme_conf['background_image'])
  File "/home/demo/make_theme/./make_theme.py", line 271, in set_background
    shutil.copyfile(bg_path, bg_usr_share_path)
  File "/usr/lib/python3.10/shutil.py", line 254, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/home/demo/make_theme/themes/avengers/avengers.jpg'
dmacduff commented 2 years ago

I would label this bug if I could.

dmacduff commented 2 years ago

The best fix for this might be to update the code to handle an absent background image file, and allow themification to proceed. E.g.

    try:
        shutil.copyfile(bg_path, bg_usr_share_path)
    except FileNotFoundError as err:
        logger.warning("FileNotFoundError error: {0}".format(err))
        exit()
        ## Uncomment the logger warning and comment out above warning and exit if you want themes to proceed in the absence of a background image
        # print("Caught this exception, but still want it to error out because a theme is no good without a background!", file=sys.stderr)
        #logger.error("Could not find background file " + bg_path + "FileNotFoundError error: {0}".format(err))
        #raise

However, the desktop background code could probably use some more extensive refactoring (based on the TODO in the set_background function description), so perhaps best to leave this as an exercise for later.

dmacduff commented 2 years ago

Fix

Use an image from the Library of Congress (public domain) for this theme. Update README.md accordingly. wget https://tile.loc.gov/storage-services/service/pnp/cph/3b30000/3b35000/3b35100/3b35121r.jpg -O avengers.jpg