From 1acf2dbba350272b06df29fe25d71f248060f1c4 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 16 Jan 2013 09:52:04 -0500 Subject: [PATCH] Use a dictionary for all the pearson stuff to keep the auth/env stuff clean. --- .../student/management/commands/pearson.py | 12 +++++++----- .../management/commands/pearson_export_cdd.py | 8 ++++---- .../management/commands/pearson_export_ead.py | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/common/djangoapps/student/management/commands/pearson.py b/common/djangoapps/student/management/commands/pearson.py index 2a8b02928c..a317b08d62 100644 --- a/common/djangoapps/student/management/commands/pearson.py +++ b/common/djangoapps/student/management/commands/pearson.py @@ -5,6 +5,7 @@ from django.core.management.base import BaseCommand, CommandError import re from dogapi import dog_http_api, dog_stats_api import paramiko +import boto dog_http_api.api_key = settings.DATADOG_API @@ -24,11 +25,11 @@ class Command(BaseCommand): for mode in args: if mode == 'export': - sftp(settings.PEARSON_LOCAL_IMPORT, settings.PEARSON_SFTP_IMPORT) - s3(settings.PEARSON_LOCAL, settings.PEARSON_BUCKET) + sftp(settings.PEARSON[LOCAL_IMPORT], settings.PEARSON[SFTP_IMPORT]) + s3(settings.PEARSON_LOCAL, settings.PEARSON[BUCKET]) elif mode == 'import': - sftp(settings.PEARSON_SFTP_EXPORT, settings.PEARSON_LOCAL_EXPORT) - s3(settings.PEARSON_LOCAL_EXPORT, settings.PEARSON_BUCKET) + sftp(settings.PEARSON[SFTP_EXPORT], settings.PEARSON[LOCAL_EXPORT]) + s3(settings.PEARSON[LOCAL_EXPORT], settings.PEARSON[BUCKET]) else: print("ERROR: Mode must be export or import.") @@ -66,7 +67,8 @@ class Command(BaseCommand): """ Upload file to S3 """ - s3 = boto.connect_s3() + s3 = boto.connect_s3(settings.AWS_ACCESS_KEY_ID, + settings.AWS_SECRET_ACCESS_KEY) from boto.s3.key import Key b = s3.get_bucket(bucket) k = Key(b) diff --git a/common/djangoapps/student/management/commands/pearson_export_cdd.py b/common/djangoapps/student/management/commands/pearson_export_cdd.py index cebc098080..dcb9f5cd97 100644 --- a/common/djangoapps/student/management/commands/pearson_export_cdd.py +++ b/common/djangoapps/student/management/commands/pearson_export_cdd.py @@ -48,12 +48,12 @@ class Command(BaseCommand): # Name will use timestamp -- this is UTC, so it will look funny, # but it should at least be consistent with the other timestamps # used in the system. - if not os.path.isdir(settings.PEARSON_LOCAL_EXPORT): - os.makedirs(settings.PEARSON_LOCAL_EXPORT) - destfile = os.path.join(settings.PEARSON_LOCAL_EXPORT, + if not os.path.isdir(settings.PEARSON[LOCAL_EXPORT]): + os.makedirs(settings.PEARSON[LOCAL_EXPORT]) + destfile = os.path.join(settings.PEARSON[LOCAL_EXPORT], uploaded_at.strftime("cdd-%Y%m%d-%H%M%S.dat")) else: - destfile = os.path.join(settings.PEARSON_LOCAL_EXPORT, + destfile = os.path.join(settings.PEARSON[LOCAL_EXPORT], uploaded_at.strftime("cdd-%Y%m%d-%H%M%S.dat")) diff --git a/common/djangoapps/student/management/commands/pearson_export_ead.py b/common/djangoapps/student/management/commands/pearson_export_ead.py index 5423282346..9520e9d013 100644 --- a/common/djangoapps/student/management/commands/pearson_export_ead.py +++ b/common/djangoapps/student/management/commands/pearson_export_ead.py @@ -50,12 +50,12 @@ class Command(BaseCommand): # Name will use timestamp -- this is UTC, so it will look funny, # but it should at least be consistent with the other timestamps # used in the system. - if not os.path.isdir(settings.PEARSON_LOCAL_EXPORT): - os.makedirs(settings.PEARSON_LOCAL_EXPORT) - destfile = os.path.join(settings.PEARSON_LOCAL_EXPORT, + if not os.path.isdir(settings.PEARSON[LOCAL_EXPORT]): + os.makedirs(settings.PEARSON[LOCAL_EXPORT]) + destfile = os.path.join(settings.PEARSON[LOCAL_EXPORT], uploaded_at.strftime("ead-%Y%m%d-%H%M%S.dat")) else: - destfile = os.path.join(settings.PEARSON_LOCAL_EXPORT, + destfile = os.path.join(settings.PEARSON[LOCAL_EXPORT], uploaded_at.strftime("ead-%Y%m%d-%H%M%S.dat")) dump_all = kwargs['dump_all']