def update_service_document(self): """ Fetch the service document from self.sd_iri and updates based on that. Updates AU size and collection IRI. Returns True on success, False on error. No updates performed on error.""" try: self.sword_connection = sword2.Connection(self.sd_iri, download_service_document=True, on_behalf_of=self.content_provider_id) except Exception: # TODO make this more specific LOGGER.exception("Error getting service document from SWORD server.") return False # AU size self.au_size = self.sword_connection.maxUploadSize * 1000 # Convert from kB # Collection IRI # Workspaces are a list of ('workspace name', [collections]) tuples # Currently only support one workspace, so take the first one try: self.collection_iri = self.sword_connection.workspaces[0][1][0].href except IndexError: LOGGER.warning("No collection IRI found in LOCKSS-o-matic service document.") return False # Checksum type - LOM specific tag root = self.sword_connection.sd.service_dom self.checksum_type = root.findtext('lom:uploadChecksumType', namespaces=utils.NSMAP) self.save() return True
def connect(self): self.sword = sword2.Connection( service_document_iri=self.sd_uri, user_name=self.username, user_pass=self.password, ca_certs=self.cert, disable_ssl_certificate_validation=self.disable_ssl, ) # Update history with data retrieval attempt self.sword.get_service_document() self.status = self.sword.history[1]['payload']['response']['status'] self.connected = True if self.status == 200 else False
def _get_sword_connection(self): if self.sword_connection is None: LOGGER.debug('Getting sword connection') self.sword_connection = sword2.Connection( service_document_iri=self.sd_iri, download_service_document=True, user_name=self.user, user_pass=self.password, keep_history=False, cache_deposit_receipts=False, http_impl=sword2.http_layer.HttpLib2Layer(cache_dir=None) # http_impl=sword2.http_layer.UrlLib2Layer(), # This causes the deposit receipt to return the wrong URLs ) LOGGER.debug('Getting service document') self.sword_connection.get_service_document() return self.sword_connection
def __init__(self, service_document_url, user_name, user_pass): """ Initialise a new DSpace object. This begins by setting up a connection to the DSpace server using the credentials provided by the user in the 'user_name' and 'user_pass' arguments. """ # Set up a connection to the DSpace server. self.connection = sword2.Connection(service_document_url, user_name, user_pass) # Get the Service Document. self.connection.get_service_document() _LOG.debug("Service document: %s" % self.connection.sd) # Check that the Service Document has been parsed successfully, and that it is a valid document. assert self.connection.sd != None assert self.connection.sd.parsed assert self.connection.sd.valid # Retrieve the list of available workspaces. self.workspaces = self.connection.workspaces _LOG.debug("Workspaces: %s" % (self.workspaces, )) return
def get_conn(self): if self.repository.endpoint is None: raise DepositError(__("No servicedocument provided.")) return sword2.Connection(self.repository.endpoint, user_name=self.repository.username, user_pass=self.repository.password)