Example #1
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
            )

            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()

        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')
Example #2
0
    def get_form(self, form_class):

        stage_configurations = self.stage.get_queryset_configurations()

        form = form_class(**self.get_form_kwargs())

        used_arg_names = []

        # We want to inject fields into the form for the configurations they've marked as prompt
        for config in stage_configurations:
            if config.task_argument and config.task_name != self.task_name:
                continue

            if not config.prompt_me_for_input:
                if config.task_argument:
                    used_arg_names.append(config.key)
                continue

            str_config_key = 'configuration_value_for_{}'.format(config.key)

            if config.data_type == config.BOOLEAN_TYPE:
                field = BooleanField(widget=Select(choices=((False, 'False'), (True, 'True'))))
                field.coerce=lambda x: x == 'True',
            elif config.data_type == config.NUMBER_TYPE:
                field = FloatField()
            else:
                field = CharField()

                if config.sensitive_value:
                    field.widget = PasswordInput()

                if config.task_argument:
                    used_arg_names.append(config.key)
                    field.label = 'Argument value for ' + config.key

            field.initial = config.value

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        task_details = get_task_details(self.stage.project, self.task_name)

        for arg in task_details[2]:
            if isinstance(arg, tuple):
                name, default = arg
            else:
                name, default = arg, None

            if name in used_arg_names:
                continue

            str_config_key = 'configuration_value_for_{}'.format(name)

            field = CharField(label='Argument value for ' + name, initial=default)

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        return form
Example #3
0
    def get_form(self, form_class):

        stage_configurations = self.stage.get_queryset_configurations()

        form = form_class(**self.get_form_kwargs())

        used_arg_names = []

        # We want to inject fields into the form for the configurations they've marked as prompt
        for config in stage_configurations:
            if config.task_argument and config.task_name != self.task_name:
                continue

            if not config.prompt_me_for_input:
                if config.task_argument:
                    used_arg_names.append(config.key)
                continue

            str_config_key = 'configuration_value_for_{}'.format(config.key)

            if config.data_type == config.BOOLEAN_TYPE:
                field = BooleanField(widget=Select(choices=((False, 'False'), (True, 'True'))))
                field.coerce=lambda x: x == 'True',
            elif config.data_type == config.NUMBER_TYPE:
                field = FloatField()
            else:
                field = CharField()

                if config.sensitive_value:
                    field.widget = PasswordInput()

                if config.task_argument:
                    used_arg_names.append(config.key)
                    field.label = 'Argument value for ' + config.key

            field.initial = config.value

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        task_details = get_task_details(self.stage.project, self.task_name)

        for arg in task_details[2]:
            if isinstance(arg, tuple):
                name, default = arg
            else:
                name, default = arg, None

            if name in used_arg_names:
                continue

            str_config_key = 'configuration_value_for_{}'.format(name)

            field = CharField(label='Argument value for ' + name, initial=default)

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        return form
Example #4
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')
Example #5
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')
Example #6
0
    def dispatch(self, request, *args, **kwargs):
        #save the stage for later
        self.stage = get_object_or_404(models.Stage, pk=int(kwargs['pk']))

        task_details = get_task_details(self.stage.project, self.kwargs['task_name'])

        if task_details is None:
            messages.error(self.request, '"{}" is not a valid task.'. format(self.kwargs['task_name']))
            return HttpResponseRedirect(reverse('projects_stage_view', kwargs={'project_id': self.stage.project_id, 'pk': self.stage.pk }))

        self.task_name = task_details[0]
        self.task_description = task_details[1]

        return super(DeploymentCreate, self).dispatch(request, *args, **kwargs)
Example #7
0
    def dispatch(self, request, *args, **kwargs):
        self.project = get_object_or_404(models.Project, id=kwargs['project_id'])
        self.stage = get_object_or_404(models.Stage, id=self.kwargs['stage_id'], project=self.project)
        task_details = get_task_details(self.project, self.kwargs['task_name'])

        if task_details is None:
            messages.error(self.request, '"{}" is not a valid task.'. format(self.kwargs['task_name']))
            return HttpResponseRedirect(
                reverse('projects_stage_view', kwargs={'project_id': self.stage.project_id, 'pk': self.stage.pk})
            )

        self.task_name = task_details[0]
        self.task_description = task_details[1]

        return super(DeploymentCreate, self).dispatch(request, *args, **kwargs)
Example #8
0
    def dispatch(self, request, *args, **kwargs):
        self.project = get_object_or_404(models.Project, id=kwargs['project_id'])
        self.stage = get_object_or_404(models.Stage, id=self.kwargs['stage_id'], project=self.project)
        task_name = request.GET.get('task', None)
        task_details = get_task_details(self.project, task_name)

        if task_details is None:
            messages.error(self.request, '"{}" is not a valid task.'. format(task_name))
            return HttpResponseRedirect(
                reverse('projects_stage_view', kwargs={'project_id': self.stage.project_id, 'pk': self.stage.pk})
            )

        self.task_name = task_details[0]
        self.task_description = task_details[1]

        return super(DeploymentCreate, self).dispatch(request, *args, **kwargs)
Example #9
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')
Example #10
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')