Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def handle(self, *args, **kwargs):

futures = []
with concurrent.futures.ThreadPoolExecutor() as e:
print("Scheduling all metadata update jobs...") # noqa: T201
self.stdout.write("Scheduling all metadata update jobs...")
for blob in blobs:
future = e.submit(self._update_metadata, blob)
futures.append(future)

print("Waiting for all jobs to finish...") # noqa: T201
self.stdout.write("Waiting for all jobs to finish...")

def _determine_cache_control(self, name):
_, ext = os.path.splitext(name)
Expand Down
10 changes: 6 additions & 4 deletions contentcuration/contentcuration/management/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def handle(self, *args, **options):
email = options["email"]
password = options["password"]
if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
print("{} is not a valid email".format(email)) # noqa: T201
self.stderr.write(self.style.ERROR("{} is not a valid email".format(email)))
sys.exit()

# create the cache table
Expand Down Expand Up @@ -191,9 +191,11 @@ def handle(self, *args, **options):
for legacy_node in legacy_clipboard_nodes:
legacy_node.copy_to(target=user1.clipboard_tree)

print( # noqa: T201
"\n\n\nSETUP DONE: Log in as admin to view data (email: {}, password: {})\n\n\n".format(
email, password
self.stdout.write(
self.style.SUCCESS(
"\n\n\nSETUP DONE: Log in as admin to view data (email: {}, password: {})\n\n\n".format(
email, password
)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def handle(self, *args, **options):
self.editor.clipboard_tree.get_descendants().delete()

with ContentNode.objects.delay_mptt_updates():
print("Creating channel...") # noqa: T201
self.stdout.write("Creating channel...")
self.generate_random_channels()

# Make sure we have a channel with a lot of root topics to test initial channel load.
Expand All @@ -33,7 +33,7 @@ def handle(self, *args, **options):
self.editor.clipboard_tree = TreeBuilder(
levels=2, num_children=25, user=self.editor
).root
print( # noqa: T201
self.stdout.write(
"Created clipboard with {} nodes".format(
self.editor.clipboard_tree.get_descendants().count()
)
Expand All @@ -47,12 +47,12 @@ def generate_random_channels(self, num_channels=1):

new_channel.main_tree = TreeBuilder(user=self.editor).root

print( # noqa: T201
self.stdout.write(
"Created channel with {} nodes".format(
new_channel.main_tree.get_descendants().count()
)
)

# make sure we have a trash tree so that can be tested with real data as well.
new_channel.trash_tree = TreeBuilder(user=self.editor).root
print("Created channel with id {}".format(new_channel.pk)) # noqa: T201
self.stdout.write("Created channel with id {}".format(new_channel.pk))
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ def handle(self, *args, **options):
] = objects.get_object_creation_stats_mptt_delay(num_objects, num_runs)
object_types.append("ContentNode-mptt-delay")

print()
print("Test results:")
self.stdout.write("")
self.stdout.write("Test results:")
for object_type in object_types:
run_stats = stats[object_type]
print(
self.stdout.write(
"Stats for creating {} {} objects over {} runs: {}".format(
num_objects, object_type, num_runs, run_stats
)
)

if options["stress_test"]:
print( # noqa: T201
self.stdout.write(
"Running stress test simulating creation / cloning of a channel like KA, "
"this will take at least several minutes. Please do not interrupt if possible!"
)
stats = objects.get_large_channel_creation_stats()
for stat in stats:
print("{}: {}".format(stat, stats[stat]))
self.stdout.write("{}: {}".format(stat, stats[stat]))

finally:
if objects:
Expand Down
13 changes: 8 additions & 5 deletions contentcuration/contentcuration/perftools/objective.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import sys
import time

Expand All @@ -8,6 +9,9 @@
# TODO: Investigate more precise timing libraries


logger = logging.getLogger(__name__)


def print_progress(text):
sys.stdout.write("\r" + text)
sys.stdout.flush()
Expand All @@ -34,7 +38,7 @@ def __del__(self):
)

def cleanup(self):
print("Performing clean up, please wait...") # noqa: T201
logger.info("Performing clean up, please wait...")
try:
if self.root_node:
files = File.objects.filter(contentnode=self.root_node)
Expand All @@ -45,10 +49,9 @@ def cleanup(self):
self.root_node = None
except Exception:
if self.root_node:
print( # noqa: T201
"Error in cleanup. Root node with id {} may still exist.".format(
self.root_node.pk
)
logger.error(
"Error in cleanup. Root node with id %s may still exist.",
self.root_node.pk,
)
raise

Expand Down
11 changes: 7 additions & 4 deletions contentcuration/contentcuration/utils/db_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import os
import random
import string
Expand Down Expand Up @@ -31,6 +32,8 @@
from contentcuration.models import User
from contentcuration.utils.files import duplicate_file

logger = logging.getLogger(__name__)

LICENSE_DESCRIPTION = "Sample text for content with special permissions"
SORT_ORDER = 0

Expand All @@ -43,10 +46,10 @@ def create_user(email, password, first_name, last_name, admin=False):
user.set_password(password)
user.first_name = first_name
user.last_name = last_name
print( # noqa: T201
"User created (email: {}, password: {}, admin: {})".format(
email, password, admin
)
logger.info(
"User created (email: %s, admin: %s)",
email,
admin,
)
user.is_staff = admin
user.is_admin = admin
Expand Down
4 changes: 3 additions & 1 deletion contentcuration/contentcuration/utils/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from contentcuration.utils.files import get_thumbnail_encoding
from contentcuration.utils.sentry import report_exception

logger = logging.getLogger(__name__)


def map_files_to_node(user, node, data): # noqa: C901
"""
Expand Down Expand Up @@ -162,7 +164,7 @@ def map_files_to_slideshow_slide_item(user, node, slides, files):

if not matching_slide:
# TODO(Jacob) Determine proper error type... raise it.
print("NO MATCH") # noqa: T201
logger.warning("NO MATCH for checksum %s", checksum)

file_path = generate_object_storage_name(checksum, filename)
storage = default_storage
Expand Down
2 changes: 1 addition & 1 deletion contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def recurse_nodes(self, node, inherited_fields): # noqa C901


def create_slideshow_manifest(ccnode, user_id=None):
print("Creating slideshow manifest...") # noqa: T201
logging.info("Creating slideshow manifest...")

preset = ccmodels.FormatPreset.objects.filter(pk="slideshow_manifest")[0]
ext = file_formats.JSON
Expand Down
Loading