Exemplo n.º 1
0
def rest_repository(request):
    # Add new repository
    if request.method == 'POST':
        name=request.POST['name']
        try:
            # check the repo name
            matcher = re.compile("^[A-Za-z]\w{2,}$")
            if matcher.match(name) is None:
                raise Exception("Please enter an alphanumeric name without spaces")
            if(name == ""):
                raise Exception("Please enter a non empty name")
            # create the repo
            repository = Repository(name)
            repository.create()
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)
        except Exception as e:
            return HttpResponseServerError(e)
        
        return HttpResponse("The repository has been successfully created")
    # List retrieve_all repositories
    if request.method == 'GET':
        try:
            # change to the repository directory
            repositories = Repository.retrieve_all()
            # remove the .git at the end
            
            json_reply = jsonpickle.encode(repositories, unpicklable = False)
            return HttpResponse(json_reply)
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)
Exemplo n.º 2
0
def rest_repository(request):
    # Add new repository
    if request.method == 'POST':
        name = request.POST['name']
        try:
            # check the repo name
            matcher = re.compile("^\w{1,}$")
            if matcher.match(name) is None:
                raise Exception(
                    "Please enter an alphanumeric name without spaces")
            if (name == ""):
                raise Exception("Please enter a non empty name")
            # create the repo
            repository = Repository(name)
            repository.create()
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)
        except Exception as e:
            return HttpResponseServerError(e)

        return HttpResponse("The repository has been successfully created")
    # List retrieve_all repositories
    if request.method == 'GET':
        try:
            # change to the repository directory
            repositories = Repository.retrieve_all()
            # remove the .git at the end

            json_reply = jsonpickle.encode(repositories, unpicklable=False)

            return HttpResponse(json_reply)
        except WindowsError as e:
            return HttpResponseServerError(e.strerror)