GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — fullstackpython.com/update_s3.py at master · alldev0825/fullstackpython.com Expand file tree/ Copy pathupdate_s3.pyMore file actions 55 lines (48 loc) · 2.01 KB / Copy pathupdate_s3.pyFile metadata and controls55 lines (48 loc) · 2.01 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 import boto3 import filecmp import os UPDATED_SITE_DIR = os.environ.get('UPDATED_SITE_DIR') CURRENT_SITE_DIR = os.environ.get('CURRENT_SITE_DIR') BUCKET_NAME = os.environ.get('S3_BUCKET_NAME') def upload_with_content_type(file, full_key, auto): content_type = "default" if file.endswith(".html"): content_type = "text/html" elif file.endswith(".css"): content_type = "text/css" elif file.endswith(".jpg"): content_type = "image/jpeg" elif file.endswith(".png"): content_type = "image/png" elif file.endswith(".xml"): content_type = "application/xml" print("uploading \"{}\" as {}".format(full_key, content_type)) if content_type is "default": bucket.put_object(Key=full_key, Body=auto, ACL='public-read') else: bucket.put_object(Key=full_key, Body=auto, ACL='public-read', ContentType=content_type) if __name__ == "__main__": s3 = boto3.resource('s3') bucket = s3.Bucket(BUCKET_NAME) for root, dirs, files in os.walk(os.getcwd() + UPDATED_SITE_DIR): subdir = root[(len(os.getcwd())+len(UPDATED_SITE_DIR)):len(root)] if subdir.startswith('/'): subdir = subdir[1:] for file in files: current_file = str(os.path.join(root, file)).\ replace(UPDATED_SITE_DIR, CURRENT_SITE_DIR) updated_file = str(os.path.join(root, file)) files_match = False try: files_match = filecmp.cmp(current_file, updated_file, shallow=False) except FileNotFoundError: pass # files_match already set to False if not files_match and file is not ".DS_Store": with open(os.path.join(root, file), "rb") as auto: full_key = file if subdir: full_key = subdir + '/' + file upload_with_content_type(file, full_key, auto) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |