Beispiel #1
0
    def delete(self, *args):
        try:
            result = pc.patch_delete_api(list(args))
        except PatchError as e:
            return dict(error="Error: %s" % e.message)

        pc.patch_sync()

        return result
Beispiel #2
0
    def commit(self, *args):
        try:
            result = pc.patch_commit(list(args))
        except PatchError as e:
            return dict(error=e.message)

        pc.patch_sync()

        return result
Beispiel #3
0
    def del_release(self, *args):
        if len(list(args)) == 0:
            return dict(error="Release must be specified")

        try:
            result = pc.patch_del_release_api(list(args)[0])
        except PatchError as e:
            return dict(error=e.message)

        pc.patch_sync()

        return result
Beispiel #4
0
    def remove(self, *args, **kwargs):
        if pc.any_patch_host_installing():
            return dict(
                error="Rejected: One or more nodes are installing patches.")

        try:
            result = pc.patch_remove_api(list(args), **kwargs)
        except PatchError as e:
            return dict(error="Error: %s" % e.message)

        pc.patch_sync()

        return result
Beispiel #5
0
    def upload_dir(self, **kwargs):
        files = []
        for key, path in kwargs.items():
            LOG.info("upload-dir: Retrieving patches from %s" % path)
            for f in glob.glob(path + '/*.patch'):
                if os.path.isfile(f):
                    files.append(f)

        if len(files) == 0:
            return dict(error="No patches found")

        try:
            result = pc.patch_import_api(sorted(files))
        except PatchError as e:
            return dict(error=e.message)

        pc.patch_sync()

        return result
Beispiel #6
0
    def upload(self):
        assert isinstance(request.POST['file'], cgi.FieldStorage)
        fileitem = request.POST['file']

        if not fileitem.filename:
            return dict(error="Error: No file uploaded")

        fn = '/scratch/' + os.path.basename(fileitem.filename)

        if hasattr(fileitem.file, 'fileno'):
            # This technique cannot copy a very large file. It
            # requires a lot of memory as all data from the
            # source file is read into memory then written to
            # the destination file one chunk
            # open(fn, 'wb').write(fileitem.file.read())

            # Copying file by chunks using OS system calls
            # requires much less memory. A larger chunk
            # size can be used to improve the copy speed;
            # currently 64K chunk size is selected
            dst = os.open(fn, os.O_WRONLY | os.O_CREAT)
            src = fileitem.file.fileno()
            size = 64 * 1024
            n = size
            while n >= size:
                s = os.read(src, size)
                n = os.write(dst, s)
            os.close(dst)
        else:
            open(fn, 'wb').write(fileitem.file.read())

        try:
            result = pc.patch_import_api([fn])
        except PatchError as e:
            os.remove(fn)
            return dict(error=e.message)

        os.remove(fn)

        pc.patch_sync()

        return result