diff options
-rw-r--r-- | datastore_reader/_datastore_reader.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/datastore_reader/_datastore_reader.py b/datastore_reader/_datastore_reader.py index 9417581..e9d8f76 100644 --- a/datastore_reader/_datastore_reader.py +++ b/datastore_reader/_datastore_reader.py @@ -63,8 +63,13 @@ def extract_backup(backup_serial, backup_path): """ tmp_path = os.path.join(c.main.working_dir, 'tmp', backup_serial) - with tarfile.open(backup_path) as t: - t.extractall(tmp_path) + try: + with tarfile.open(backup_path) as t: + t.extractall(tmp_path) + except Exception, e: + # TODO use a real logging system + print '%s - failed -> %s' % (backup_serial, e) + return None # datastore should be as follow datastore_path = os.path.join(tmp_path, STORE_PATH) # check path or raise an error @@ -72,7 +77,9 @@ def extract_backup(backup_serial, backup_path): return datastore_path # Oups else: - raise Exception('bad data store path for serial: %s!' % backup_serial) + # TODO use a real logging system + print 'bad data store path for serial: %s!' % backup_serial + return None def list_backups(working_dir): @@ -118,6 +125,9 @@ def read_backups(): for backup_serial, backup_path in list_backups(c.main.working_dir): # extract backup datastore_path = extract_backup(backup_serial, backup_path) + # little check - may be we have got an error during extract + if not datastore_path: + continue # list metadata for meta_path in list_meta_files(datastore_path): # parse the metadata file @@ -127,6 +137,11 @@ def read_backups(): # write meta info in a new csv row according config row = list() for k in columns: + # quick date formating + if k == 'timestamp': + d = datetime.fromtimestamp(meta_dict[k]) + meta_dict[k] = d.strftime(c.main.date_format) + # add row to csv queue row.append(meta_dict[k] if k in meta_dict else '') # write row writer.writerow(row) |