This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import tempfile | |
s3_bucket = "..." | |
s3_path = "..." | |
s3 = boto3.resource('s3', region_name='eu-west-1') | |
with tempfile.NamedTemporaryFile() as downloaded_file: | |
s3.Object(s3_bucket, s3_path).download_file(downloaded_file.name) | |
# continue processing downloaded_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with tempfile.TemporaryDirectory() as workdir: | |
project_dirname = "project" | |
project_dir = os.path.join(workdir, project_dirname) | |
os.mkdir(project_dir) | |
# do esoteric work within that temporary workdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import os | |
@contextlib.contextmanager | |
def cd(path): | |
"""Set the working directory | |
Temporarily set the working directory inside the context manager and | |
reset it to the previous working directory afterwards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with cd(project_dirname): | |
shutil.make_archive(archive_name, "zip") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with specific_locale(locale.LC_ALL, "en_US"): | |
pass # makes sure that dateformats are English |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import locale | |
@contextlib.contextmanager | |
def specific_locale(category, locale_string): | |
prev_locale_string = locale.getlocale(category) | |
locale.setlocale(category, locale_string) | |
try: | |
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with setenviron(aws_env, PYTHONUNBUFFERED='1'): | |
pass # set aws_env and PYTHONUNBUFFERED before calling script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import os | |
@contextlib.contextmanager | |
def setenviron(envdict=None, **mapping): | |
"""``with`` context to temporarily modify the environment variables""" | |
_environ = os.environ.copy() | |
if envdict: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Server 2 sockets,6 cores each, 2.4ghz | |
# Set ixgbe options | |
# Limit RSS queues to the number of physical cores per cpu | |
# Disable offload | |
# When you change this, you need to run the command and reboot for it to take. | |
echo "options ixgbe LRO=0,0 MQ=1,1 RSS=6,6 VMDQ=0,0 vxlan_rx=0,0" > /etc/modprobe.d/ixgbe.conf | |
# Shut down HT cores | |
for i in $(seq 1 2 23); do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s3bucketname = "hennings-roadworker-backup-bucket" | |
s3prefix = "roadworker/" | |
region = "eu-west-1" | |
codebuild_image = "aws/codebuild/eb-python-2.6-amazonlinux-64:2.1.3" |
NewerOlder