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): ...@@ -44,7 +44,7 @@ class Command(BaseCommand):
default=False, default=False,
help='Retrieve the destination to export to from django? True/False'), help='Retrieve the destination to export to from django? True/False'),
make_option('--destination', make_option('--destination',
action='store_true', action='store',
dest='destination', dest='destination',
default=None, default=None,
help='Where to store the exported files') help='Where to store the exported files')
...@@ -61,24 +61,22 @@ class Command(BaseCommand): ...@@ -61,24 +61,22 @@ class Command(BaseCommand):
# Name will use timestamp -- this is UTC, so it will look funny, # Name will use timestamp -- this is UTC, so it will look funny,
# but it should at least be consistent with the other timestamps # but it should at least be consistent with the other timestamps
# used in the system. # used in the system.
if options['dest-from-settings'] is True: if 'dest-from-settings' in options:
if settings.PEARSON[LOCAL_EXPORT]: if LOCAL_EXPORT in settings.PEARSON:
dest = settings.PEARSON[LOCAL_EXPORT] dest = settings.PEARSON[LOCAL_EXPORT]
else: else:
raise CommandError('--dest-from-settings was enabled but the' raise CommandError('--dest-from-settings was enabled but the'
'PEARSON[LOCAL_EXPORT] setting was not set.') 'PEARSON[LOCAL_EXPORT] setting was not set.')
elif options['destination']: elif 'destination' in options:
dest = options['destination'] dest = options['destination']
else: 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): if not os.path.isdir(dest):
os.makedirs(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 # strings must be in latin-1 format. CSV parser will
# otherwise convert unicode objects to ascii. # otherwise convert unicode objects to ascii.
......
...@@ -30,7 +30,7 @@ class Command(BaseCommand): ...@@ -30,7 +30,7 @@ class Command(BaseCommand):
default=False, default=False,
help='Retrieve the destination to export to from django? True/False'), help='Retrieve the destination to export to from django? True/False'),
make_option('--destination', make_option('--destination',
action='store_true', action='store',
dest='destination', dest='destination',
default=None, default=None,
help='Where to store the exported files'), help='Where to store the exported files'),
...@@ -55,22 +55,21 @@ class Command(BaseCommand): ...@@ -55,22 +55,21 @@ class Command(BaseCommand):
# Name will use timestamp -- this is UTC, so it will look funny, # Name will use timestamp -- this is UTC, so it will look funny,
# but it should at least be consistent with the other timestamps # but it should at least be consistent with the other timestamps
# used in the system. # used in the system.
if options['dest-from-settings'] is True: if 'dest-from-settings' in options:
if settings.PEARSON[LOCAL_EXPORT]: if LOCAL_EXPORT in settings.PEARSON:
dest = settings.PEARSON[LOCAL_EXPORT] dest = settings.PEARSON[LOCAL_EXPORT]
else: else:
raise CommandError('--dest-from-settings was enabled but the' raise CommandError('--dest-from-settings was enabled but the'
'PEARSON[LOCAL_EXPORT] setting was not set.') 'PEARSON[LOCAL_EXPORT] setting was not set.')
elif options['destination']: elif destinations in options:
dest = options['destination'] dest = options['destination']
else: 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): if not os.path.isdir(dest):
os.makedirs(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'] dump_all = kwargs['dump_all']
......
...@@ -14,7 +14,7 @@ class Command(BaseCommand): ...@@ -14,7 +14,7 @@ class Command(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
make_option('--mode', make_option('--mode',
action='store_true', action='store',
dest='mode', dest='mode',
default='both', default='both',
help='mode is import, export, or both'), help='mode is import, export, or both'),
...@@ -55,11 +55,11 @@ class Command(BaseCommand): ...@@ -55,11 +55,11 @@ class Command(BaseCommand):
password=settings.PEARSON[SFTP_PASSWORD]) password=settings.PEARSON[SFTP_PASSWORD])
sftp = paramiko.SFTPClient.from_transport(t) sftp = paramiko.SFTPClient.from_transport(t)
if os.path.isdir(files_from): 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, sftp.put(files_from+'/'+filename,
files_to+'/'+filename) files_to+'/'+filename)
else: else:
for file in sftp.listdir(files_from): for filename in sftp.listdir(files_from):
sftp.get(files_from+'/'+filename, sftp.get(files_from+'/'+filename,
files_to+'/'+filename) files_to+'/'+filename)
except: 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