示例#1
0
    def create_submission(self, url_name, long_name, parent_project_url, owner):
        """
        :param url_name: The urlname given by the user. Do not include /'es or username!
        """
        # Form the git clone url (see functional requirements)
        submission_full_git_url = owner + "/submissions/" + url_name

        submission_db = self.mongo.gitsubmit.submissions
        project_db = self.mongo.gitsubmit.projects
        class_db = self.mongo.gitsubmit.classes

        # Make sure the url_name is unique
        shortname_check_doc = submission_db.find_one({"gitolite_url": submission_full_git_url})
        if shortname_check_doc is not None:
            raise UrlNameAlreadyTakenError("That url name is already taken.")

        # Ensure the parent project exists
        parent_project_obj = project_db.find_one({"gitolite_url": parent_project_url})
        if parent_project_obj is None:
            raise ProjectDoesNotExistError(str(parent_project_url))
        parent_class_obj = class_db.find_one({"url_name": parent_project_obj["parent"]})
        if parent_class_obj is None:
            raise ClassDoesNotExistError(str(parent_project_obj["parent"]))
        parent_class_url = parent_class_obj["url_name"]

        gw = GitoliteWrapper(self.glpath)
        # Make sure the owner exists
        gw.get_user_or_error(owner)

        # This is what actually causes the fork
        fork_callstring = "ssh git@" + self.ssh_host + " fork " + parent_project_url + " " + submission_full_git_url
        subprocess.call(fork_callstring, shell=True)

        # now create_repo sets the repo ACCESS rights in gitolite
        gw.create_repo(submission_full_git_url, owner)

        # If we got here, nothing went wrong, stuff it in the db
        submission_obj = {"gitolite_url": submission_full_git_url,
                          "long_name": long_name,
                          "owner": owner,
                          "parent": parent_project_url,
                          "contributors": [owner]}

        result = submission_db.insert_one(submission_obj)

        dest_dir = os.path.abspath(os.path.join(self.repo_root, submission_full_git_url+".git"))

        exists = os.path.exists(dest_dir)

        dest_file = os.path.join(dest_dir, "hooks", "pre-receive")
        src_hook = os.path.abspath(os.path.join("hooks", "pre-receive"))

        print "src", src_hook
        print "dest", dest_file
        print "exists", exists

        shutil.copy(src_hook, dest_file)

        return result
示例#2
0
    def create_project(self, url_name, long_name, description, parent_class_url_name, is_team_based, due_date, owner, max_team_size=4):
        """
        :param url_name: The raw project url name. Do not include the parent class or /'es!
        """
        # apply defaults in case None
        if max_team_size is None:
            max_team_size = 4

        # form the git clone url (see functional requirements)
        gitolite_url = parent_class_url_name + "/" + url_name

        project_db = self.mongo.gitsubmit.projects
        class_db = self.mongo.gitsubmit.classes

        # Make sure the url_name is unique
        shortname_check_doc = project_db.find_one({"gitolite_url": gitolite_url})
        if shortname_check_doc is not None:
            raise UrlNameAlreadyTakenError("That url name is already taken for that class.")

        # Ensure the parent class exists
        parent_class_obj = class_db.find_one({"url_name": parent_class_url_name})
        if parent_class_obj is None:
            raise ClassDoesNotExistError(str(parent_class_url_name))

        gw = GitoliteWrapper(self.glpath)
        # Make sure the owner exists
        gw.get_user_or_error(owner)

        # Add the teachers of the parent class to the project with RW permissions
        repo = gw.create_repo(gitolite_url, owner)
        for teacher in parent_class_obj["teachers"]:
            gw.give_user_readwrite_permission(teacher, repo.name)

        due_datetime = datetime.strptime(due_date, TIME_FORMAT)

        # If we've gotten here without exception, add to the DB
        project_obj = {"gitolite_url": gitolite_url,
                       "url_name": url_name,
                       "long_name": long_name,
                       "description": description,
                       "parent": parent_class_url_name,
                       "is_team_based": is_team_based,
                       "owner": owner,
                       "due": due_datetime,
                       "max_team_size": max_team_size}

        return project_db.insert_one(project_obj)