Exemplo n.º 1
0
    def _process_experiment(self, exp):
        if self.dryRun:
            self.stdout.write('Would have archived experiment %s\n' % exp.id)
            return
        tmp_file = None
        try:
            if self.directory:
                pathname = os.path.join(self.directory, 
                                        '%s-archive.tar.gz' % exp.id)
            else:
                tmp_file = NamedTemporaryFile(prefix='mytardis_tmp_ar',
                                              suffix='.tar.gz',
                                              delete=False)
                create_experiment_archive(exp, tmp_file)
            if not self.directory:
                archive_url = self.location.provider.put_archive(
                    tmp_file.name, exp)
                create_archive_record(exp, archive_url)
                if self.verbosity > 0:
                    self.stdout.write('Archived experiment %s to %s\n' %
                                      (exp.id, archive_url))
            else:
                archive_url = None
                if self.verbosity > 0:
                    self.stdout.write('Archived experiment %s to %s\n' %
                                      (exp.id, pathname))
                    
            self.transfer_count += 1
            if self.remove_all:
                remove_experiment(exp)
            elif self.remove_data:
                remove_experiment_data(exp, archive_url, location)

        except ArchivingError as e:          
            self.stderr.write(
                'archiving failed for experiment %s : %s\n' % \
                    (exp.id, e.args[0]))
            self.error_count += 1
        except TransferError as e:
            self.stderr.write(
                'archive export failed experiment %s : %s\n' % \
                    (exp.id, e.args[0]))
            self.error_count += 1
        finally:
            if tmp_file:
                os.unlink(tmp_file.name)
Exemplo n.º 2
0
 def testCreateArchiveRecord(self):
     count = Archive.objects.count()
     archive = create_archive_record(self.experiment, 'http://example.com')
     self.assertEqual(Archive.objects.count(), count + 1)
     self.assertEqual(archive.experiment_owner, 'fred')