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 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
예제 #3
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
 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
예제 #5
0
 def accept_roles(self, copy_config, logger, failures):
     try:
         users = self.get_users_of_roles()
     except TerminateError:
         raise TerminateError("Terminate Signaled")
     except (CCTError, Exception) as e:
         if type(e) is not CCTError and type(e) is not SkipSignal:
             logger.error("Problematic Error")
             logger.debug(traceback.format_exc())
         if type(e) is SkipSignal:
             logger.warn("User skipped creating workgroup.")
         logger.error(e.msg)
         logger.error("Not accepting roles")
         return
     for user in users:
         logger.info("Accepting roles for %s" % user)
         parameters = "?"
         for id in self.get_pending_roles_request_ids(
                 copy_config, user, logger):
             parameters += "ids%3Alist=" + id + "&"
         parameters += 'agree=&accept= + Accept + '  # rest of form
         auth = tuple(user.split(':'))
         response = http.http_get_request(
             "%s/updateCollaborations%s" %
             (copy_config.destination_server, parameters),
             auth=auth)  # yes, it is a GET request
         if not http.verify(response, logger):
             logger.error(
                 "Failure accepting pending requests for %s %s %s" %
                 (auth[0], response.status_code, response.reason))
             failures.append((auth[0], " accepting pending role requests"))
예제 #6
0
 def accept_roles(self, copy_config, logger, failures):
     try:
         users = self.get_users_of_roles()
     except TerminateError:
         raise TerminateError("Terminate Signaled")
     except (CCTError, Exception) as e:
         if type(e) is not CCTError and type(e) is not SkipSignal:
             logger.error("Problematic Error")
             logger.debug(traceback.format_exc())
         if type(e) is SkipSignal:
             logger.warn("User skipped creating workgroup.")
         logger.error(e.msg)
         logger.error("Not accepting roles")
         return
     for user in users:
         logger.info("Accepting roles for %s" % user)
         parameters = "?"
         for id in self.get_pending_roles_request_ids(copy_config, user, logger):
             parameters += "ids%3Alist=" + id + "&"
         parameters += 'agree=&accept= + Accept + '  # rest of form
         auth = tuple(user.split(':'))
         response = http.http_get_request("%s/updateCollaborations%s" % (copy_config.destination_server, parameters),
                                          auth=auth)  # yes, it is a GET request
         if not http.verify(response, logger):
             logger.error("Failure accepting pending requests for %s %s %s" %
                          (auth[0], response.status_code, response.reason))
             failures.append((auth[0], " accepting pending role requests"))
예제 #7
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))
 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))
 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]))
    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
예제 #11
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
예제 #12
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
예제 #13
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]))
예제 #14
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
예제 #15
0
 def add_modules_to_collection(self, modules, server, credentials, collection, logger, failures):
     modules_str = ""
     for module in modules:
         modules_str += "%s " % module.destination_id
     logger.info("Adding modules to collection %s: %s" % (collection.title, modules_str))
     auth = tuple(credentials.split(':'))
     data = {"form.submitted": "1",
             "form.action": "submit"}
     collection_url = collection.get_parents_url()
     for module in modules:
         if not module.valid:
             continue
         data["ids:list"] = module.destination_id
         response = http.http_post_request("%s/Members/%s/%s/@@collection-composer-collection-module" %
                                           (server, auth[0], collection_url), auth=auth, data=data)
         if not http.verify(response, logger):
             logger.error("Module %s failed to be added to collection %s" % (module.title, collection.title))
             module.valid = False
             failures.append((module.full_title(), " adding to collection"))
             continue
예제 #16
0
 def add_modules_to_collection(self, modules, server, credentials, collection, logger, failures):
     modules_str = ""
     for module in modules:
         modules_str += "%s " % module.destination_id
     logger.info("Adding modules to collection %s: %s" % (collection.title, modules_str))
     auth = tuple(credentials.split(':'))
     data = {"form.submitted": "1",
             "form.action": "submit"}
     collection_url = collection.get_parents_url()
     for module in modules:
         if not module.valid:
             continue
         data["ids:list"] = module.destination_id
         response = http.http_post_request("%s/Members/%s/%s/@@collection-composer-collection-module" %
                                           (server, auth[0], collection_url), auth=auth, data=data)
         if not http.verify(response, logger):
             logger.error("Module %s failed to be added to collection %s" % (module.title, collection.title))
             module.valid = False
             failures.append((module.full_title(), " adding to collection"))
             continue
예제 #17
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]
예제 #18
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]