Skip to content

Commit

Permalink
fixed some things
Browse files Browse the repository at this point in the history
  • Loading branch information
priestc committed Apr 10, 2012
1 parent 7d07f36 commit d4c3229
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
26 changes: 8 additions & 18 deletions easydump/management/commands/load_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import logging
log = logging.getLogger(__name__)

from dateutil.parser import parse as iso_parse
from django.conf import settings
from easydump.mixins import EasyDumpCommand

from easydump.utils import key_parser

class Command(EasyDumpCommand):
"""
Retrieve a dump file from S3, then apply it to the database
Expand Down Expand Up @@ -38,26 +39,15 @@ def get_latest(self, bucket, prefix):
"""
none = datetime.datetime(1,1,1) # always be expired

def parser(key):
def p(name, prefix):
"""
given a key, parse out the prefix and parse into a datetime object
(for comparison)
A new parser function because the sorted() function can't compare
datetime objects with None, so instead of None, return a really really
old datetime object.
"""

try:
key_prefix, iso_date = key.split('|')
except:
# some weird key that was not put there by easydump
log.info("found weird key: %s" % key)
return none

if prefix == key_prefix:
return iso_parse(iso_date)
else:
log.info("wrong prefix: %s" % key)
return none
return key_parser(name, prefix) or none

keys = [{'dt': parser(k.name), 'string': k.name} for k in bucket.list()]
keys = [{'dt': p(k.name, prefix), 'string': k.name} for k in bucket.list()]
latest = sorted(keys, key=lambda x: x['dt'])[-1]
key = latest['string']
dt = latest['dt']
Expand Down
6 changes: 3 additions & 3 deletions easydump/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def _get_database(self):

def _get_dumper(self):
"""
Based on which kind of database theis manifest is for, get teh proper
dumper object
Based on which kind of database theis manifest is for, get the proper
dumper object.
"""
engine = self.database['ENGINE']
if 'postgis' in engine:
Expand All @@ -54,7 +54,7 @@ def _get_dumper(self):

def _get_tables(self):
"""
return all the database tables that we are going to dump.
Return all the database tables that we are going to dump.
"""

all_models = models.get_models()
Expand Down

0 comments on commit d4c3229

Please sign in to comment.