def _backup(self, parsed_args): """Backup existing deployed assets """ if self.backup: dep_sys = self.document['deploymentSystem'] dep_path = self.document['deploymentPath'] backup_dep_path = dep_path + '.' + str(seconds()) print_stderr('Backing up agave://{}/{}'.format(dep_sys, dep_path)) start_time = milliseconds() self.messages.append( ('backup', 'src: agave://{}/{}'.format(dep_sys, dep_path))) self.messages.append( ('backup', 'dst: agave://{}/{}'.format(dep_sys, backup_dep_path))) try: manage.move(dep_path, system_id=dep_sys, destination=backup_dep_path, agave=self.tapis_client) print_stderr('Finished ({} msec)'.format(milliseconds() - start_time)) return True except Exception as exc: self.messages.append(('backup', str(exc))) print_stderr('Failed ({} msec)'.format(milliseconds() - start_time)) return False return True
def _upload(self, parsed_args): """Upload asset bundle """ if self.upload: dep_sys = self.document['deploymentSystem'] dep_path = self.document['deploymentPath'] dep_path_parent = os.path.dirname(dep_path) dep_path_temp = os.path.join(dep_path_parent, self._bundle()) print_stderr('Uploading app bundle to agave://{}/{}'.format( dep_sys, dep_path)) start_time = milliseconds() try: # TODO - incorporate working directory manage.makedirs(dep_path_parent, system_id=dep_sys, permissive=True, agave=self.tapis_client) manage.delete(dep_path, system_id=dep_sys, permissive=True, agave=self.tapis_client) uploaded, skipped, errors, ul_bytes, ec_download = upload.upload( self._bundle(), system_id=dep_sys, destination=dep_path_parent, progress=True, agave=self.tapis_client) manage.move(dep_path_temp, system_id=dep_sys, destination=dep_path, agave=self.tapis_client) # Rename dep_path_parent/bundle to dep_path print_stderr('Finished ({} msec)'.format(milliseconds() - start_time)) for u in uploaded: self.messages.append(('upload', u)) for e in errors: self.messages.append(('upload', e)) return True except Exception as exc: self.messages.append(('upload', str(exc))) print_stderr('Failed ({} msec)'.format(milliseconds() - start_time)) return False return True
def _upload(self, parsed_args): """Upload asset bundle """ if self.upload: dep_sys = self.document['deploymentSystem'] dep_path = self.document['deploymentPath'] dep_path_parent = os.path.dirname(dep_path) # need the bundle basename for the upload/move workflow to work bundle_basename = os.path.basename(os.path.normpath( self._bundle())) # add date to make tmpdir unique from bundle and deploymentPath dep_path_temp = os.path.join(dep_path_parent, bundle_basename) \ + datetime.now().strftime("-%Y-%m-%d") print_stderr( 'Uploading app asset directory "{0}" to agave://{1}/{2}'. format(self._bundle(), dep_sys, dep_path)) start_time = milliseconds() try: # First, check existence of bundle. No point in taking other action # if it does not exist if not os.path.exists(self._bundle()): raise FileNotFoundError( 'Unable to locate asset directory "{}"'.format( self._bundle())) try: # need relative destination here because # agavepy permissions check will fail on '/' # for public systems manage.makedirs(os.path.basename(dep_path_temp), system_id=dep_sys, permissive=True, destination=dep_path_parent, agave=self.tapis_client) # clear out destination directory manage.delete(dep_path, system_id=dep_sys, permissive=True, agave=self.tapis_client) except Exception as err: self.messages.append(('upload', str(err))) # upload bundle to tmp dir uploaded, skipped, errors, ul_bytes, ec_download = upload.upload( self._bundle(), system_id=dep_sys, destination=dep_path_temp, progress=True, agave=self.tapis_client) # move tmp dir bundle to the destination dir manage.move(os.path.join(dep_path_temp, bundle_basename), system_id=dep_sys, destination=dep_path, agave=self.tapis_client) # delete tmp dir manage.delete(dep_path_temp, system_id=dep_sys, permissive=True, agave=self.tapis_client) print_stderr('Finished ({} msec)'.format(milliseconds() - start_time)) for u in uploaded: self.messages.append(('upload', u)) for e in errors: self.messages.append(('upload', e)) if len(errors) > 0: if self.ignore_errors is False: raise Exception('Upload failures: {}'.format( errors.join(';'))) return True except Exception as exc: if self.ignore_errors: self.messages.append(('upload', str(exc))) print_stderr('Failed ({} msec)'.format(milliseconds() - start_time)) return False else: raise return True