And now that we’ve parameterized the arguments, we’ll want to focus on a repeatable process for building the Elastic Beanstalk source bundle.
Establish the wordpress directory from the latest sources available:
def establish_wordpress_dir(): script_dir = os.path.dirname(os.path.realpath(__file__)) if not os.path.exists('{0}/wordpress'.format(script_dir)): print("Could not find wordpress directory, downloading latest ...") local_filename, headers = urllib.request.urlretrieve('https://www.wordpress.org/latest.zip') with ZipFile(local_filename) as zip: zip.extractall() # Establish wordpress dir zip_filename = headers.get('Content-Disposition').split('=')[-1] os.rename(local_filename, '{0}/{1}'.format(script_dir, zip_filename))
💡 Reviewing the following was helpful while updating the code to Python 3: https://docs.python.org/3.8/library/zipfile.html.