Commit 0555ebc4 by Ashley Penney

Bunch of fixes to how I do if/else checks, fix a typo in Command and

repair the for filename part of sftp.
parent 378b1ff0
......@@ -44,7 +44,7 @@ class Command(BaseCommand):
default=False,
help='Retrieve the destination to export to from django? True/False'),
make_option('--destination',
action='store_true',
action='store',
dest='destination',
default=None,
help='Where to store the exported files')
......@@ -61,24 +61,22 @@ 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 options['dest-from-settings'] is True:
if settings.PEARSON[LOCAL_EXPORT]:
if 'dest-from-settings' in options:
if LOCAL_EXPORT in settings.PEARSON:
dest = settings.PEARSON[LOCAL_EXPORT]
else:
raise CommandError('--dest-from-settings was enabled but the'
'PEARSON[LOCAL_EXPORT] setting was not set.')
elif options['destination']:
elif 'destination' in options:
dest = options['destination']
else:
raise ComamndError('--destination or --dest-from-settings must be used')
raise CommandError('--destination or --dest-from-settings must be used')
if not os.path.isdir(dest):
os.makedirs(dest)
destfile = os.path.join(dest, uploaded_at.strftime("cdd-%Y%m%d-%H%M%S.dat"))
else:
destfile = os.path.join(dest, uploaded_at.strftime("cdd-%Y%m%d-%H%M%S.dat"))
destfile = os.path.join(dest, uploaded_at.strftime("cdd-%Y%m%d-%H%M%S.dat"))
# strings must be in latin-1 format. CSV parser will
# otherwise convert unicode objects to ascii.
......
......@@ -30,7 +30,7 @@ class Command(BaseCommand):
default=False,
help='Retrieve the destination to export to from django? True/False'),
make_option('--destination',
action='store_true',
action='store',
dest='destination',
default=None,
help='Where to store the exported files'),
......@@ -55,22 +55,21 @@ 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 options['dest-from-settings'] is True:
if settings.PEARSON[LOCAL_EXPORT]:
if 'dest-from-settings' in options:
if LOCAL_EXPORT in settings.PEARSON:
dest = settings.PEARSON[LOCAL_EXPORT]
else:
raise CommandError('--dest-from-settings was enabled but the'
'PEARSON[LOCAL_EXPORT] setting was not set.')
elif options['destination']:
elif destinations in options:
dest = options['destination']
else:
raise ComamndError('--destination or --dest-from-settings must be used')
raise CommandError('--destination or --dest-from-settings must be used')
if not os.path.isdir(dest):
os.makedirs(dest)
destfile = os.path.join(dest, uploaded_at.strftime("ead-%Y%m%d-%H%M%S.dat"))
else:
destfile = os.path.join(dest, uploaded_at.strftime("ead-%Y%m%d-%H%M%S.dat"))
destfile = os.path.join(dest, uploaded_at.strftime("ead-%Y%m%d-%H%M%S.dat"))
dump_all = kwargs['dump_all']
......
......@@ -14,7 +14,7 @@ class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--mode',
action='store_true',
action='store',
dest='mode',
default='both',
help='mode is import, export, or both'),
......@@ -55,11 +55,11 @@ class Command(BaseCommand):
password=settings.PEARSON[SFTP_PASSWORD])
sftp = paramiko.SFTPClient.from_transport(t)
if os.path.isdir(files_from):
for file in os.listdir(files_from):
for filename in os.listdir(files_from):
sftp.put(files_from+'/'+filename,
files_to+'/'+filename)
else:
for file in sftp.listdir(files_from):
for filename in sftp.listdir(files_from):
sftp.get(files_from+'/'+filename,
files_to+'/'+filename)
except:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment