Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolab committed Jan 14, 2025
1 parent e2dd247 commit b798418
Show file tree
Hide file tree
Showing 225 changed files with 519 additions and 452 deletions.
75 changes: 23 additions & 52 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime
import os
import subprocess
from shlex import quote
import subprocess

from invoke import run as local
from invoke.tasks import task


# Process .env file
if os.path.exists(".env"):
with open(".env") as f:
Expand Down Expand Up @@ -137,15 +138,11 @@ def psql(c, command=None):
@task
def delete_docker_database(c, local_database_name=LOCAL_DATABASE_NAME):
dexec(
"dropdb --if-exists --host db --username={project_name} {database_name}".format(
project_name=PROJECT_NAME, database_name=LOCAL_DATABASE_NAME
),
f"dropdb --if-exists --host db --username={PROJECT_NAME} {LOCAL_DATABASE_NAME}",
"db",
)
dexec(
"createdb --host db --username={project_name} {database_name}".format(
project_name=PROJECT_NAME, database_name=LOCAL_DATABASE_NAME
),
f"createdb --host db --username={PROJECT_NAME} {LOCAL_DATABASE_NAME}",
"db",
)
psql(c, "CREATE SCHEMA heroku_ext;")
Expand All @@ -160,12 +157,8 @@ def import_data(c, database_filename):
delete_docker_database(c)
# Import the database file to the db container
dexec(
"pg_restore --clean --no-acl --if-exists --no-owner --host db \
--username={project_name} -d {database_name} {database_filename}".format(
project_name=PROJECT_NAME,
database_name=LOCAL_DATABASE_NAME,
database_filename=database_filename,
),
f"pg_restore --clean --no-acl --if-exists --no-owner --host db \
--username={PROJECT_NAME} -d {LOCAL_DATABASE_NAME} {database_filename}",
service="db",
)
print(
Expand Down Expand Up @@ -275,12 +268,8 @@ def delete_local_database(c, local_database_name=LOCAL_DATABASE_NAME):

def aws(c, command, aws_access_key_id, aws_secret_access_key):
return local(
"AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_key} "
"aws {command}".format(
access_key_id=aws_access_key_id,
secret_key=aws_secret_access_key,
command=command,
)
f"AWS_ACCESS_KEY_ID={aws_access_key_id} AWS_SECRET_ACCESS_KEY={aws_secret_access_key} "
f"aws {command}"
)


Expand All @@ -291,10 +280,7 @@ def pull_media_from_s3(
aws_storage_bucket_name,
local_media_dir=LOCAL_MEDIA_DIR,
):
aws_cmd = "s3 sync --delete s3://{bucket_name} {local_media}".format(
bucket_name=aws_storage_bucket_name,
local_media=local_media_dir,
)
aws_cmd = f"s3 sync --delete s3://{aws_storage_bucket_name} {local_media_dir}"
aws(c, aws_cmd, aws_access_key_id, aws_secret_access_key)


Expand All @@ -318,11 +304,7 @@ def pull_images_from_s3(
aws_storage_bucket_name,
local_images_dir=LOCAL_IMAGES_DIR,
):
aws_cmd = (
"s3 sync --delete s3://{bucket_name}/original_images {local_media}".format(
bucket_name=aws_storage_bucket_name, local_media=local_images_dir
)
)
aws_cmd = f"s3 sync --delete s3://{aws_storage_bucket_name}/original_images {local_images_dir}"
aws(c, aws_cmd, aws_access_key_id, aws_secret_access_key)
# The above command just syncs the original images, so we need to drop the wagtailimages_renditions
# table so that the renditions will be re-created when requested on the local build.
Expand Down Expand Up @@ -351,18 +333,13 @@ def pull_database_from_heroku(c, app_instance, anonymise=False):
datestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")

local(
"heroku pg:backups:download --output={dump_folder}/{datestamp}.dump --app {app}".format(
app=app_instance, dump_folder=LOCAL_DUMP_DIR, datestamp=datestamp
),
f"heroku pg:backups:download --output={LOCAL_DUMP_DIR}/{datestamp}.dump --app {app_instance}",
)

import_data(c, f"/app/{LOCAL_DUMP_DIR}/{datestamp}.dump")

local(
"rm {dump_folder}/{datestamp}.dump".format(
dump_folder=LOCAL_DUMP_DIR,
datestamp=datestamp,
),
f"rm {LOCAL_DUMP_DIR}/{datestamp}.dump",
)

if anonymise:
Expand Down Expand Up @@ -394,13 +371,9 @@ def make_bold(msg):
def dellar_snapshot(c, filename):
"""Snapshot the database, files will be stored in the db container"""
dexec(
"pg_dump -d {database_name} -U {database_username} > {filename}.psql".format(
database_name=LOCAL_DATABASE_NAME,
database_username=LOCAL_DATABASE_USERNAME,
filename=filename,
),
f"pg_dump -d {LOCAL_DATABASE_NAME} -U {LOCAL_DATABASE_USERNAME} > {filename}.psql",
service="db",
),
)
print("Database snapshot created")


Expand All @@ -409,14 +382,12 @@ def dellar_restore(c, filename):
"""Restore the database from a snapshot in the db container"""
delete_docker_database(c)

dexec(
"psql -U {database_username} -d {database_name} < {filename}.psql".format(
database_name=LOCAL_DATABASE_NAME,
database_username=LOCAL_DATABASE_USERNAME,
filename=filename,
(
dexec(
f"psql -U {LOCAL_DATABASE_USERNAME} -d {LOCAL_DATABASE_NAME} < {filename}.psql",
service="db",
),
service="db",
),
)
print("Database restored.")


Expand All @@ -426,10 +397,10 @@ def dellar_list(c):
print("Database snapshots:")
dexec(
"""for f in *.psql; do
printf ' - %s\n' "${f%.psql}"
done""",
printf ' - %s\n' "${f%.psql}"
done""",
service="db",
),
)
print("Restore with `dellar-restore <snapshot>`")


Expand All @@ -439,7 +410,7 @@ def dellar_remove(c, filename):
dexec(
f"rm {filename}.psql",
service="db",
),
)
print(f"Snapshot {filename} removed")


Expand Down
1 change: 1 addition & 0 deletions gunicorn-conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Replace gunicorn's 'Server' HTTP header to avoid leaking info to attackers
import gunicorn


gunicorn.SERVER_SOFTWARE = ""
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys


if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tbx.settings.production")

Expand Down
1 change: 1 addition & 0 deletions tbx/blog/factories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import factory
import wagtail_factories

from tbx.blog.models import BlogIndexPage, BlogPage
from tbx.core.factories import StoryBlockFactory

Expand Down
1 change: 1 addition & 0 deletions tbx/blog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .models import BlogPage


# Main blog feed


Expand Down
6 changes: 4 additions & 2 deletions tbx/blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

from django.db import migrations, models
import django.db.models.deletion

import modelcluster.fields
import tbx.core.blocks
import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks

import tbx.core.blocks

class Migration(migrations.Migration):

class Migration(migrations.Migration):
initial = True

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Generated by Django 4.2.9 on 2024-01-15 10:16

from django.db import migrations
import tbx.core.blocks

import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks

import tbx.core.blocks

class Migration(migrations.Migration):

class Migration(migrations.Migration):
dependencies = [
("blog", "0001_initial"),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Generated by Django 4.2.9 on 2024-01-15 11:14

from django.db import migrations

import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks


class Migration(migrations.Migration):

dependencies = [
("blog", "0002_remove_blogindexpage_call_to_action_and_more"),
]
Expand Down
6 changes: 4 additions & 2 deletions tbx/blog/migrations/0003_alter_blogpage_body.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Generated by Django 4.2.9 on 2024-01-15 12:25

from django.db import migrations
import tbx.core.blocks

import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks

import tbx.core.blocks

class Migration(migrations.Migration):

class Migration(migrations.Migration):
dependencies = [
("blog", "0002_remove_blogindexpage_call_to_action_and_more"),
]
Expand Down
6 changes: 4 additions & 2 deletions tbx/blog/migrations/0004_alter_blogpage_body.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Generated by Django 4.2.9 on 2024-01-16 13:44

from django.db import migrations
import tbx.core.blocks

import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks

import tbx.core.blocks

class Migration(migrations.Migration):

class Migration(migrations.Migration):
dependencies = [
("blog", "0003_alter_blogpage_body"),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 4.2.9 on 2024-01-15 11:15

from django.db import migrations

from wagtail.blocks.migrations.migrate_operation import MigrateStreamData
from wagtail.blocks.migrations.operations import RenameStreamChildrenOperation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Generated by Django 4.2.9 on 2024-01-15 11:53

from django.db import migrations

import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks


class Migration(migrations.Migration):

dependencies = [
("blog", "0004_data_migration_aligned_and_wide_images"),
]
Expand Down
1 change: 0 additions & 1 deletion tbx/blog/migrations/0006_merge_20240117_1530.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("blog", "0004_alter_blogpage_body"),
("blog", "0005_remove_aligned_and_wide_image_blocks_from_body_streamfield"),
Expand Down
3 changes: 2 additions & 1 deletion tbx/blog/migrations/0007_alter_blogpage_body.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Generated by Django 4.2.9 on 2024-01-18 13:49

from django.db import migrations

import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks


class Migration(migrations.Migration):

dependencies = [
("blog", "0006_merge_20240117_1530"),
]
Expand Down
3 changes: 2 additions & 1 deletion tbx/blog/migrations/0008_alter_blogpage_body.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Generated by Django 4.2.9 on 2024-01-18 14:11

from django.db import migrations

import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
import wagtail.snippets.blocks

import wagtailmarkdown.blocks
import wagtailmedia.blocks


class Migration(migrations.Migration):

dependencies = [
("blog", "0007_alter_blogpage_body"),
]
Expand Down
1 change: 0 additions & 1 deletion tbx/blog/migrations/0009_delete_blogpagerelatedlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("blog", "0008_alter_blogpage_body"),
]
Expand Down
Loading

0 comments on commit b798418

Please sign in to comment.