예제 #1
0
    def output_stream_generator(self):
        if get_task_details(self.object.stage.project,
                            self.object.task.name) is None:
            return

        preyield = True  # Use to balance <ul> tags upon error since we're streaming output
        try:
            process = subprocess.Popen(build_command(self.object,
                                                     self.request.session),
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT,
                                       shell=True)

            all_output = ''
            yield '<ul class="output">'
            preyield = False
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() is not None:
                    break

                nextline = '<li class="outputline">{}</li>'.format(nextline)
                if nextline.find('\x1b[32m') != -1:
                    nextline = nextline.replace(
                        '\x1b[32m',
                        '<ul class="outputgreen"><li class="outputline">')
                elif nextline.find('\x1b[31m') != -1:
                    nextline = nextline.replace(
                        '\x1b[31m',
                        '<ul class="outputred"><li class="outputline">')
                if nextline.find('\x1b[0m') != -1:
                    nextline = nextline.replace('\x1b[0m', '</ul></li>')

                all_output += nextline

                yield nextline
                sys.stdout.flush()
            yield '</ul>'
            preyield = True

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(
                self.object.status, ' ' * 1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            if not preyield:
                yield '</ul>'
            message = "An error occurred: " + e.message
            # yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span class="erroroutput">{} </span><br /> {}'.format(
                message, ' ' * 1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format(
                '*1024')
예제 #2
0
def start_task(message):
    time.sleep(1)
    project = Project.objects.get(id=message.content['project_id'])
    deployment = Deployment.objects.get(id=message.content['deployment_id'])
    deployment.output = ''
    deployment.save()

    engine = import_module(settings.SESSION_ENGINE)
    SessionStore = engine.SessionStore
    session = SessionStore(message.content['session_key'])

    if backend.get_task_details(project, deployment.task.name) is None:
        return

    process = subprocess.Popen(
        backend.build_command(project, deployment, session),
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        shell=True,
        executable=getattr(settings, 'SHELL', '/bin/sh'),
    )

    while True:
        nextline = process.stdout.readline()
        if nextline == '' and process.poll() is not None:
            break

        Group("deployment-{}".format(deployment.id)).send({
            "text":
            json.dumps({
                'status':
                'pending',
                'text':
                str('<span class="output-line">{}</span>'.format(
                    ansiconv.to_html(nextline)))
            }),
        })

        deployment.add_output(nextline)

        sys.stdout.flush()

    Deployment.objects.filter(pk=deployment.id).update(
        status=deployment.SUCCESS if process.returncode ==
        0 else deployment.FAILED)

    Group("deployment-{}".format(deployment.id)).send({
        "text":
        json.dumps({
            'status':
            deployment.SUCCESS
            if process.returncode == 0 else deployment.FAILED,
            'text':
            ''
        }),
    })

    deployment_finished.send(deployment, deployment_id=deployment.pk)
예제 #3
0
    def output_stream_generator(self):
        if get_task_details(self.object.stage.project, self.object.task.name) is None:
            return

        preyield = True  # Use to balance <ul> tags upon error since we're streaming output
        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True
            )

            all_output = ''
            yield '<ul class="output">'
            preyield = False
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() is not None:
                    break

                nextline = '<li class="outputline">{}</li>'.format(nextline)
                if nextline.find('\x1b[32m') != -1:
                    nextline = nextline.replace('\x1b[32m', '<ul class="outputgreen"><li class="outputline">')
                elif nextline.find('\x1b[31m') != -1:
                    nextline = nextline.replace('\x1b[31m', '<ul class="outputred"><li class="outputline">')
                if nextline.find('\x1b[0m') != -1:
                    nextline = nextline.replace('\x1b[0m', '</ul></li>')

                all_output += nextline

                yield nextline
                sys.stdout.flush()
            yield '</ul>'
            preyield = True

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(self.object.status, ' '*1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            if not preyield:
                yield '</ul>'
            message = "An error occurred: " + e.message
            # yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span class="erroroutput">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format('*1024')
예제 #4
0
    def output_stream_generator(self):
        if backend.get_task_details(self.project,
                                    self.object.task.name) is None:
            return

        try:
            process = subprocess.Popen(
                backend.build_command(self.project, self.object,
                                      self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True,
                executable=getattr(settings, 'SHELL', '/bin/sh'),
            )

            all_output = ''
            yield '<link rel="stylesheet" type="text/css" href="/static/css/console-style.css">'
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() is not None:
                    break

                all_output += nextline
                nextline = '<span class="output-line">{}</span>'.format(
                    ansiconv.to_html(nextline))
                yield nextline + ' ' * 1024

                sys.stdout.flush()

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(
                self.object.status, ' ' * 1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            message = "An error occurred: " + e.message
            yield '<span class="output-line">{}</span>'.format(
                message) + ' ' * 1024
            yield '<span id="finished" style="display:none;">failed</span> {}'.format(
                '*1024')
예제 #5
0
    def output_stream_generator(self):
        if get_task_details(self.object.stage.project,
                            self.object.task.name) is None:
            return

        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True,
                executable=getattr(settings, 'SHELL', '/bin/sh'),
            )

            all_output = ''
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() != None:
                    break

                all_output += nextline

                yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(
                    nextline, ' ' * 1024)
                sys.stdout.flush()

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(
                self.object.status, ' ' * 1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            message = "An error occurred: " + e.message
            yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(
                message, ' ' * 1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format(
                '*1024')
예제 #6
0
    def output_stream_generator(self):
        if get_task_details(self.project, self.object.task.name) is None:
            return

        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True,
                executable=getattr(settings, 'SHELL', '/bin/sh'),
            )

            all_output = ''
            yield '<link rel="stylesheet" type="text/css" href="/static/css/console-style.css">'
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() is not None:
                    break

                all_output += nextline
                nextline = '<span class="output-line">{}</span>'.format(ansiconv.to_html(nextline))
                yield nextline + ' '*1024

                sys.stdout.flush()

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(self.object.status, ' '*1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            message = "An error occurred: " + e.message
            yield '<span class="output-line">{}</span>'.format(message) + ' '*1024
            yield '<span id="finished" style="display:none;">failed</span> {}'.format('*1024')
예제 #7
0
    def output_stream_generator(self):
        if get_task_details(self.project, self.object.task.name) is None:
            return

        try:
            process = subprocess.Popen(
                build_command(self.object, self.request.session),
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                shell=True,
                executable=getattr(settings, 'SHELL', '/bin/sh'),
            )

            all_output = ''
            while True:
                nextline = process.stdout.readline()
                if nextline == '' and process.poll() != None:
                    break

                all_output += nextline

                yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(nextline, ' '*1024)
                sys.stdout.flush()

            self.object.status = self.object.SUCCESS if process.returncode == 0 else self.object.FAILED

            yield '<span id="finished" style="display:none;">{}</span> {}'.format(self.object.status, ' '*1024)

            self.object.output = all_output
            self.object.save()

            deployment_finished.send(self.object, deployment_id=self.object.pk)

        except Exception as e:
            message = "An error occurred: " + e.message
            yield '<span style="color:rgb(200, 200, 200);font-size: 14px;font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif;">{} </span><br /> {}'.format(message, ' '*1024)
            yield '<span id="finished" style="display:none;">failed</span> {}'.format('*1024')
예제 #8
0
def start_task(message):
    time.sleep(1)
    project = Project.objects.get(id=message.content['project_id'])
    deployment = Deployment.objects.get(id=message.content['deployment_id'])
    deployment.output = ''
    deployment.save()

    engine = import_module(settings.SESSION_ENGINE)
    SessionStore = engine.SessionStore
    session = SessionStore(message.content['session_key'])

    if backend.get_task_details(project, deployment.task.name) is None:
        return

    process = subprocess.Popen(
        backend.build_command(project, deployment, session),
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        stdin=subprocess.PIPE,
        shell=True,
        executable=getattr(settings, 'SHELL', '/bin/sh'),
        close_fds=True
    )

    fd = process.stdout.fileno()
    fl = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

    while True:
        try:
            nextline = process.stdout.readline()
        except IOError as e:
            nextline = ''

        if nextline == '' and process.poll() is not None:
            break
        #
        # next_input = deployment.get_next_input()
        # if next_input:
        #     process.stdin.write(next_input + '\n')

        if nextline:
            Group("deployment-{}".format(deployment.id)).send({
                "text": json.dumps({
                    'status': 'pending',
                    'text': str('<span class="output-line">{}</span>'.format(ansiconv.to_html(nextline)))
                }),
            }, immediately=True)

            deployment.add_output(nextline)

        sys.stdout.flush()

    Deployment.objects.filter(pk=deployment.id).update(
        status=deployment.SUCCESS if process.returncode == 0 else deployment.FAILED
    )

    Group("deployment-{}".format(deployment.id)).send({
        "text": json.dumps({
            'status': deployment.SUCCESS if process.returncode == 0 else deployment.FAILED,
            'text': ''
        }),
    }, immediately=True)

    deployment_finished.send(deployment, deployment_id=deployment.pk)