Note this is for eb python platform, it is different for Docker
cd /opt/python/current/app
import os | |
import shlex | |
import subprocess | |
from subprocess import PIPE, STDOUT | |
from django.core.management.base import BaseCommand | |
class Command(BaseCommand): | |
help = 'Kill local processes running runserver command' |
# If bucket is private | |
AWS_ACCESS_KEY = 'your access key' | |
AWS_SECRET_KEY = 'your secret key' | |
AWS_REGION = 'your region' | |
session = boto3.session.Session( | |
aws_access_key_id=AWS_ACCESS_KEY, | |
aws_secret_access_key=AWS_SECRET_KEY, | |
region_name=AWS_REGION | |
) |
# Compress with gzip | |
tar -zcvf myTar.tar.gz *.files | |
# Uncompress with gzip, http://www.cyberciti.biz/faq/tar-extract-linux/ | |
tar -xzvf myTar.tar.gz | |
# http://stackoverflow.com/questions/3964681/find-all-files-in-directory-with-extension-txt-in-python | |
# Using glob | |
import glob, os | |
os.chdir("/mydir") | |
for file in glob.glob("*.txt"): | |
print(file) | |
# Using listdir | |
import os | |
for file in os.listdir("/mydir"): |
""" | |
FROM: http://blog.elsdoerfer.name/2012/07/26/make-pyyaml-output-an-ordereddict/ | |
Make PyYAML output an OrderedDict. | |
It will do so fine if you use yaml.dump(), but that generates ugly, | |
non-standard YAML code. | |
To use yaml.safe_dump(), you need the following. | |
""" | |
def represent_odict(dump, tag, mapping, flow_style=None): | |
"""Like BaseRepresenter.represent_mapping, but does not issue the sort(). |
from contextlib import contextmanager | |
@contextmanager | |
def tag(name): | |
print("<%s>" % name) | |
yield | |
print("</%s>" % name) | |
>>> with tag("h1"): | |
... print("foo") |
>>> a, b, c = 1, 2, 3 | |
>>> a, b, c | |
(1, 2, 3) | |
>>> a, b, c = [1, 2, 3] | |
>>> a, b, c | |
(1, 2, 3) | |
>>> a, b, c = (2 * i + 1 for i in range(3)) | |
>>> a, b, c | |
(1, 3, 5) | |
>>> a, (b, c), d = [1, (2, 3), 4] |
req_exclusions = ['setuptools', 'pytest'] | |
def get_requirements(): | |
reqs = [] | |
with open('requirements.txt', 'r') as f: | |
for line in f: | |
add = True | |
for req in req_exclusions: | |
if req in line: |