def push_vistrail_to_repository(self, branching=False): """ uploads current VisTrail to web repository """ self._repository_status['details'] = "Pushing to repository..." self._push_button.setEnabled(False) self._branch_button.setEnabled(False) self.update_push_information() try: # create temp file (fd, filename) = tempfile.mkstemp(suffix='.vt', prefix='vt_tmp') os.close(fd) # writing tmp vt and switching back to orginal vt locator = ZIPFileLocator(filename) controller = vistrails.api.get_current_controller() tmp_controller = VistrailController(controller.vistrail.do_copy(), locator) tmp_controller.changed = True tmp_controller.write_vistrail(locator) # check if this vt is from the repository if controller.vistrail.get_annotation('repository_vt_id'): repository_vt_id = controller.vistrail.get_annotation('repository_vt_id').value else: repository_vt_id = -1 # upload vistrail temp file to repository register_openers(cookiejar=self.dialog.cookiejar) project = self.serverCombo.itemData(self.serverCombo.currentIndex())[0] if project == "Default": project = "" params = {'vistrail_file': open(filename, 'rb'), 'action': 'upload', 'name': controller.locator.short_name, 'repository_vt_id': repository_vt_id if not branching else -1, 'is_runnable': not bool(len(self.unsupported_packages)+ \ len(self.local_data_modules)), 'vt_id': 0, 'branched_from': "" if not branching else repository_vt_id, 'project': project, 'everyone_can_view': self.perm_view.checkState(), 'everyone_can_edit': self.perm_edit.checkState(), 'everyone_can_download': self.perm_download.checkState() } upload_url = "%s/vistrails/remote_upload/" % \ self.config.webRepositoryURL datagen, headers = multipart_encode(params) request = urllib2.Request(upload_url, datagen, headers) result = urllib2.urlopen(request) updated_response = result.read() os.unlink(filename) if updated_response[:6] == "upload": # No update, just upload if result.code != 200: self._repository_status['details'] = \ "Push to repository failed" debug.critical("Push to repository failed (Please contact an administrator)") else: repository_vt_id = int(updated_response[8:]) controller.vistrail.set_annotation('repository_vt_id', repository_vt_id) controller.vistrail.set_annotation('repository_creator', self.dialog.loginUser) # ensure that the annotations get saved controller.set_changed(True) self._repository_status['details'] = \ "Push to repository was successful" else: # update, load updated vistrail if result.code != 200: self._repository_status['details'] = "Update Failed" debug.critical("Update vistrail in web repository failed (Please contact an administrator)") else: debug.log("getting version from web") # request file to download download_url = "%s/vistrails/download/%s/" % \ (self.config.webRepositoryURL, updated_response) request = urllib2.Request(download_url) result = urllib2.urlopen(request) updated_file = result.read() # create temp file of updated vistrail (fd, updated_filename) = tempfile.mkstemp(suffix='.vtl', prefix='vtl_tmp') os.close(fd) updated_vt = open(updated_filename, 'w') updated_vt.write(updated_file) updated_vt.close() # switch vistrails to updated one controller = vistrails.api.get_current_controller() updated_locator = FileLocator(updated_filename) (up_vistrail, abstractions, thumbnails, mashups) = \ load_vistrail(updated_locator) # FIXME need to figure out what to do with this !!! controller.set_vistrail(up_vistrail, controller.vistrail.locator, abstractions, thumbnails, mashups) # update version tree drawing controller.recompute_terse_graph() controller.invalidate_version_tree() os.remove(updated_filename) os.remove(updated_filename[:-1]) self._repository_status['details'] = \ "Update to repository was successful" except Exception, e: debug.critical("An error occurred", str(e)) self._repository_status['details'] = "An error occurred"