Exemplo n.º 1
0
 def upload(self):
     uri = upload(fd=self.local.file, **self.get_sync_data())
     if uri:
         self.is_synchronized = True
         self.remote = uri
     else:
         self.is_synchronized = False
Exemplo n.º 2
0
 def upload(self):
     uri = upload(fd=self.local.file, **self.get_sync_data())
     if uri:
         self.is_synchronized = True
         self.remote = uri
     else:
         self.is_synchronized = False
Exemplo n.º 3
0
 def handle(self, *args, **options):
     for media in Media.objects.order_by('-pk').filter(
             synchronize=True, is_synchronized=False).iterator():
         if media.local:
             for retry in range(1, 5):
                 bucket = '{}-{}'.format(media.bucket_name, retry)
                 print('\nSyncing {}...'.format(bucket))
                 try:
                     uri = upload(user=media.account.user,
                                 passwd=media.account.password,
                                 bucket=media.bucket_name,
                                 metadata=media.metadata,
                                 key=media.key_name,
                                 fd=media.local.file)
                 except Exception, msg:
                     print('Failed: {}'.format(msg))
                 else:
                     if uri:
                         media.is_synchronized = True
                         media.remote = uri
                         media.save()
                         print('OK')
                         break
                     print('Failed')