def test_delete_project(self):
     repository = ProjectRepository()
     project = repository.create(name=u"Test Project", build_script=u"make test", scm_repository="git_repo1")
     repository.delete(project.id)
     
     projects = repository.get_all()
     
     self.assertEqual(len(projects), 0)
    def test_delete_project(self):
        repository = ProjectRepository()
        project = self.create_project(name=u"Test Project")

        elixir.session.flush()
        elixir.session.commit()

        repository.delete(project.id)

        elixir.session.flush()
        elixir.session.commit()

        projects = repository.get_all()

        self.assertEqual(len(projects), 0)
Beispiel #3
0
class ProjectController(object):
    def __init__(self):
        self.repository = ProjectRepository()

    @cherrypy.expose
    @template.output("create_project.html")
    def new(self):
        return template.render()

    @cherrypy.expose
    def create(self, name, build_script, scm_repository):
        project = self.repository.create(name=name, build_script=build_script, scm_repository=scm_repository)
        raise cherrypy.HTTPRedirect("/")

    @cherrypy.expose
    @template.output("project_details.html")
    def default(self, project_id):
        project = self.repository.get(project_id)
        return template.render(project=project)

    @cherrypy.expose
    def delete(self, project_id):
        self.repository.delete(project_id)
        raise cherrypy.HTTPRedirect("/")
Beispiel #4
0
class ProjectController(BaseController):
    def __init__(self):
        self.repository = ProjectRepository()
        self.build_service = BuildService()

    @authenticated()
    @template.output("create_project.html")
    def new(self):
        return template.render(authenticated=self.authenticated(), project=None)

    @authenticated()
    @template.output("create_project.html")
    def edit(self, project_id):
        project = self.repository.get(project_id)
        return template.render(authenticated=self.authenticated(), project=project)

    def __process_tabs_for(self, data):
        tabs = None
        if data.has_key("additional_tab_name"):
            tab_names = [name for name in data["additional_tab_name"] if name != u""]
            tab_commands = [command for command in data["additional_tab_command"] if command != u""]
            tab_content_types = [
                content_type for content_type in data["additional_tab_content_type"] if content_type != u""
            ][1:]

            if len(tab_names) > len(tab_commands) or len(tab_names) > len(tab_content_types):
                raise ValueError("The number of tabs, commands and content types MUST be the same.")

            tabs = []
            for tab_index in range(len(tab_names)):
                tab = ProjectTab(
                    name=tab_names[tab_index],
                    command=tab_commands[tab_index],
                    content_type=tab_content_types[tab_index],
                )
                tabs.append(tab)
        return tabs

    def __process_file_locators_for(self, data):
        locators = None
        if data.has_key("additional_file_locator"):
            locators = [locator for locator in data["additional_file_locator"] if locator != u""]
        return locators

    @authenticated()
    def create(self, name, build_script, scm_repository, monitor_changes=None, **data):
        project = self.repository.create(
            name=name,
            build_script=build_script,
            scm_repository=scm_repository,
            monitor_changes=not monitor_changes is None,
            tabs=self.__process_tabs_for(data),
            file_locators=self.__process_file_locators_for(data),
        )
        PluginEvents.on_project_created(project)
        raise cherrypy.HTTPRedirect("/")

    @authenticated()
    def update(self, project_id, name, build_script, scm_repository, monitor_changes=None, **data):
        project = self.repository.get(project_id)
        project.name = name
        project.build_script = build_script
        project.scm_repository = scm_repository
        project.monitor_changes = not monitor_changes is None
        self.repository.update(
            project, self.__process_tabs_for(data), file_locators=self.__process_file_locators_for(data)
        )
        PluginEvents.on_project_updated(project)
        raise cherrypy.HTTPRedirect("/")

    @authenticated()
    def delete(self, project_id):
        project = self.repository.get(project_id)
        self.repository.delete(project_id)
        self.build_service.delete_scm_repository(project)
        PluginEvents.on_project_deleted(project)
        raise cherrypy.HTTPRedirect("/")

    @authenticated()
    def build(self, project_id):
        print "Adding project %s to the queue" % project_id
        SkinkContext.current().build_queue.append(project_id)
        raise cherrypy.HTTPRedirect("/project/%s" % project_id)

    @template.output("current_build.html")
    def current_build_report(self, **data):
        return template.render(authenticated=self.authenticated())

    def current_status(self, **data):
        ctx = SkinkContext.current()
        result = {}
        result["project"] = ctx.current_project and ctx.current_project.name or ""
        result["project_id"] = ctx.current_project and ctx.current_project.id or ""
        result["command"] = ctx.current_command
        result["log"] = ctx.current_log and u"<br />".join(unicode(ctx.current_log).splitlines()[-30:]) or ""

        return demjson.encode(result)

    def build_status(self, **data):
        ctx = SkinkContext.current()
        projects = self.repository.get_all()
        projects_being_built = [int(project_id) for project_id in ctx.projects_being_built]
        result = {}
        for project in projects:
            if project.id in projects_being_built:
                result[project.id] = (project.name, "BUILDING")
            else:
                result[project.id] = (
                    project.name,
                    (project.last_builds is not None and len(project.last_builds) > 0) and "BUILT" or "UNKNOWN",
                )

        return "\n".join(["%s=%s@@%s" % (k, v[0], v[1]) for k, v in result.items()])

    @template.output("project_details.html")
    def details(self, project_id):
        return self.render_details(project_id)

    @template.output("project_details.html")
    def build_details(self, project_id, build_id):
        return self.render_details(project_id, build_id)

    def build_tab_details(self, build_tab_id):
        return self.repository.get_build_tab_by_id(build_tab_id=build_tab_id).log

    def build_file_details(self, build_file_id):
        build_file = self.repository.get_build_file_by_id(build_file_id=build_file_id)
        response.headers["Content-Type"] = "application/x-download"
        response.headers["Content-Disposition"] = 'attachment; filename="%s"' % build_file.name
        response.headers["Accept-Ranges"] = "bytes"
        response.headers["Content-Length"] = len(build_file.content)
        response.body = build_file.content
        return response.body

    def get_all_status(self, **data):
        projects = self.repository.get_all()
        serialized_projects = []
        for project in projects:
            serialized_projects.append(project.to_dict())
        values = {}
        values["projects"] = serialized_projects

        cherrypy.response.headers["Content-Type"] = "application/json"
        return demjson.encode(values)

    def render_details(self, project_id, build_id=None):
        project = self.repository.get(project_id)
        if not build_id:
            build = project.last_builds and project.last_builds[0] or None
        else:
            build = project.get_build_by_id(int(build_id))
        build_log = ""
        if build and build.log:
            build_log = highlight(build.log, BashLexer(), HtmlFormatter())
        return template.render(
            authenticated=self.authenticated(), project=project, current_build=build, build_log=build_log
        )