Пример #1
0
    def publish_module(self, module_url, credentials, logger, new=True):
        """
        Publishes the module at [module_url] with [credentials] using HTTP requests.

        Returns the published module ID.
        Raises a CustomError on http request failure.
        """
        username, password = credentials.split(':')
        data1 = {"message": "created module", "form.button.publish": "Publish", "form.submitted": "1"}
        response1 = http.http_post_request("%smodule_publish_description" % module_url, auth=(username, password),
                                           data=data1)
        if not http.verify(response1, logger):

            raise CCTError("publish module for %s request 1 failed: %s %s" %
                           (module_url, response1.status_code, response1.reason))
        if new:
            data2 = {"message": "created module", "publish": "Yes, Publish"}
            response2 = http.http_post_request("%spublishContent" % module_url, auth=(username, password), data=data2)
            if not http.verify(response2, logger):
                raise CCTError("publish module for %s request 2 failed: %s %s" %
                               (module_url, response1.status_code, response1.reason))

            # extract module ID
            url = response2.url.encode('UTF-8')
            end_id = regex.search('/content_published', url).start()
            beg = url.rfind('/', 0, end_id) + 1
            return url[beg:end_id], url
        else:
            return module_url[module_url.rfind('/', 0, -1) + 1:-1], module_url
Пример #2
0
 def add_subcollections(self, titles, server, credentials, collection, logger):
     logger.info("Adding subcollections to collection %s: %s" % (collection.title, titles))
     auth = tuple(credentials.split(':'))
     base = "%s/Members/%s/%s/" % (server, auth[0], collection.get_parents_url())
     data4 = {"form.submitted": "1",
              "titles": "\n".join(titles),
              "submit": "Add new subcollections"}
     subcollection = '@@collection-composer-collection-subcollection'
     response = http.http_post_request(base + subcollection, auth=auth, data=data4)
     if not http.verify(response, logger):
         raise CCTError("Creation of subcollection(s) %s request failed: %s %s" %
                        (titles, response.status_code, response.reason))
     text = response.text[len("close:["):-1]
     text = text.split("},{")
     subcollections = []
     for subcollection_response in text:
         subcollection_id_start = regex.search(r'nodeid\':\'', subcollection_response).end()
         subcollection_id = subcollection_response[subcollection_id_start:
                                                   subcollection_response.find("'", subcollection_id_start)]
         subcollection_title_start = regex.search(r'text\':\s*\'', subcollection_response).end()
         subcollection_title = subcollection_response[subcollection_title_start:
                                                      subcollection_response.find("'", subcollection_title_start)]
         subcollection = Collection(subcollection_title, subcollection_id)
         subcollection.parent = collection
         collection.add_member(subcollection)
         subcollections.append(subcollection)
     return subcollections
Пример #3
0
 def publish_collection(self, server, credentials, collection, logger):
     logger.info("Publishing collection %s" % collection.title)
     auth = tuple(credentials.split(':'))
     publish_message = "Initial publish"
     data1 = {"message": publish_message,
              "form.button.publish": "Publish",
              "form.submitted": "1"}
     response1 = http.http_post_request("%s/Members/%s/%s/collection_publish" % (server, auth[0], collection.id),
                                        auth=auth, data=data1)
     if not http.verify(response1, logger):
         raise CCTError("Publishing collection %s request 1 failed: %s %s" %
                        (collection.title, response1.status_code, response1.reason))
     data2 = {"message": publish_message,
              "publish": "Yes, Publish"}
     response2 = http.http_post_request("%s/Members/%s/%s/publishContent" % (server, auth[0], collection.id),
                                        auth=auth, data=data2)
     if not http.verify(response2, logger):
         raise CCTError("Publishing collection %s request 2 failed: %s %s" %
                        (collection.title, response2.status_code, response2.reason))
Пример #4
0
    def create_module(self, title, credentials, workspace_url, logger):
        """
        Creates a module with [title] in [workspace_url] with [credentials].

        Returns the url of the created module.

        Raises CustomError on failed http requests.
        """
        username, password = credentials.split(':')
        auth = username, password

        data1 = {"type_name": "Module",
                 "workspace_factories:method": "Create New Item"}

        response1 = http.http_post_request(workspace_url, auth=auth, data=data1)
        if not http.verify(response1, logger):
            raise CCTError("create module for %s request 1 failed: %s %s" %
                           (title, response1.status_code, response1.reason))
        cc_license = self.get_license(response1, logger)
        data2 = {"agree": "on",
                 "form.button.next": "Next >>",
                 "license": cc_license,
                 "form.submitted": "1"}
        data3 = {"title": title,
                 "master_language": "en",
                 "language": "en",
                 "license": cc_license,
                 "form.button.next": "Next >>",
                 "form.submitted": "1"}
        response2 = http.http_post_request(response1.url.encode('UTF-8'), auth=auth, data=data2)
        if not http.verify(response2, logger):
            raise CCTError("create module for %s request 2 failed: %s %s" %
                           (title, response2.status_code, response2.reason))
        r2url = response2.url.encode('UTF-8')
        create_url = r2url[:regex.search('cc_license', r2url).start()]
        response3 = http.http_post_request("%scontent_title" % create_url, auth=auth, data=data3)
        if not http.verify(response3, logger):
            raise CCTError("create module for %s request 3 failed: %s %s" %
                           (title, response3.status_code, response3.reason))
        return create_url
Пример #5
0
 def create_collection(self, credentials, title, server, logger):
     logger.info("Creating collection %s" % title)
     auth = tuple(credentials.split(':'))
     data0 = {"type_name": "Collection",
              "workspace_factories:method": "Create New Item"}
     response0 = http.http_post_request("%s/Members/%s" % (server, auth[0]), auth=auth, data=data0)
     if not http.verify(response0, logger):
         raise CCTError("Creation of collection %s request 2 failed: %s %s" %
                        (title, response0.status_code, response0.reason))
     cc_license = self.get_license(response0, logger)
     data1 = {"agree": "on",
              "form.button.next": "Next >>",
              "license": cc_license,
              "type_name": "Collection",
              "form.submitted": "1"}
     data2 = {"title": title,
              "master_language": "en",
              "language": "en",
              "collectionType": "",
              "keywords:lines": "",
              "abstract": "",
              "license": cc_license,
              "form.button.next": "Next >>",
              "form.submitted": "1"}
     response1 = http.http_post_request(response0.url, auth=auth, data=data1)
     if not http.verify(response1, None):
         raise CCTError("Creation of collection %s request 2 failed: %s %s" %
                        (title, response1.status_code, response1.reason))
     url = response1.url
     base = url[:url.rfind('/')+1]
     response2 = http.http_post_request("%s/content_title" % base, auth=auth, data=data2)
     if not http.verify(response2, None):
         raise CCTError("Creation of collection %s request 3 failed: %s %s" %
                        (title, response2.status_code, response2.reason))
     start = base[:-1].rfind('/')+1
     return Collection(title, str(base[start:-1]))
Пример #6
0
 def get_pending_roles_request_ids(self, copy_config, credentials, logger):
     ids = []
     auth = tuple(credentials.split(':'))
     response1 = http.http_get_request("%s/collaborations" %
                                       copy_config.destination_server,
                                       auth=auth)
     if not http.verify(response1, logger):
         raise CCTError("FAILURE getting pending role requests: %s %s" %
                        (response1.status_code, response1.reason))
     else:
         html = response1.text
         pattern = regex.compile('name="ids:list" value=".*"')
         matching_items = regex.finditer(pattern, html)
         for match in matching_items:
             string = match.group(0)
             ids.append(string[string.find('value="') + 7:-1])
     return ids
Пример #7
0
    def get_users_of_roles(self):
        users = set()
        for creator in self.config.creators:
            users.add(creator)
        for maintainer in self.config.maintainers:
            users.add(maintainer)
        for rightholder in self.config.rightholders:
            users.add(rightholder)

        users_and_creds = []
        for user in users:
            try:
                password = self.config.settings[user]
                users_and_creds.append("%s:%s" % (user, password))
            except KeyError:
                if not (self.config.credentials.split(':')[0] == user):
                    raise CCTError(
                        "Could not find credentials for user involved in roles, check settings file for: "
                        + user)
        return users_and_creds
Пример #8
0
    def create_workgroup(self, workgroup, server, credentials, logger):
        """
        Creates a workgroup with [title] on [server] with [credentials] using
        HTTP requests.

        Returns:
          None

        Modifies:
          The workgroup provided is updated with the new found information: id and url
        """
        username, password = credentials.split(':')
        data = {"title": workgroup.title, "form.button.Reference": "Create", "form.submitted": "1"}
        response = http.http_post_request("%s/create_workgroup" % server, auth=(username, password), data=data)
        if not http.verify(response, logger):
            raise CCTError("%s %s" % (response.status_code, response.reason))

        # extract workgroup ID
        url = response.url.encode('UTF-8')
        id_start = regex.search('GroupWorkspaces/', url).end()
        id_end = url.find('/', id_start)
        workgroup.id = url[id_start:id_end]
        workgroup.url = url[:id_end]