Пример #1
0
    def import_tool(
            self, project, user, project_name=None, mount_point=None,
            mount_label=None, user_name=None, tool_option=None, **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        wiki_avail = extractor.has_wiki()
        if not wiki_avail:
            return

        self.github_wiki_url = extractor.get_page_url(
            'wiki_url').replace('.wiki', '/wiki')
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or 'wiki',
            mount_label=mount_label or 'Wiki',
            import_id={
                'source': self.source,
                'project_name': project_name,
            }
        )
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(
            user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                try:
                    wiki_url = extractor.get_page_url('wiki_url')
                    self.import_pages(wiki_url, history=with_history)
                except git.GitCommandError:
                    log.error(
                        'Unable to clone GitHub wiki: '
                        'wiki_url=%s; '
                        'wiki_avail=%s; '
                        'avail_url=%s',
                        wiki_url, wiki_avail,
                        extractor.get_page_url('project_info'),
                        exc_info=True)
                    raise
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                'import tool %s from %s on %s' % (
                    self.app.config.options.mount_point,
                    project_name,
                    self.source),
                project=project,
                user=user,
                url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Пример #2
0
    def import_tool(self,
                    project,
                    user,
                    project_name=None,
                    mount_point=None,
                    mount_label=None,
                    user_name=None,
                    tool_option=None,
                    **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name)
        if not extractor.has_wiki():
            return

        self.github_wiki_url = extractor.get_page_url('wiki_url').replace(
            '.wiki', '/wiki')
        self.app = project.install_app("Wiki",
                                       mount_point=mount_point or 'wiki',
                                       mount_label=mount_label or 'Wiki',
                                       import_id={
                                           'source': self.source,
                                           'project_name': project_name,
                                       })
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                self.import_pages(extractor.get_page_url('wiki_url'),
                                  history=with_history)
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log('import tool %s from %s on %s' %
                           (self.app.config.options.mount_point, project_name,
                            self.source),
                           project=project,
                           user=user,
                           url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception as e:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Пример #3
0
    def import_tool(
        self,
        project,
        user,
        project_name=None,
        mount_point=None,
        mount_label=None,
        user_name=None,
        tool_option=None,
        **kw
    ):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        if not extractor.has_wiki():
            return

        self.github_wiki_url = extractor.get_page_url("wiki_url").replace(".wiki", "/wiki")
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or "wiki",
            mount_label=mount_label or "Wiki",
            import_id={"source": self.source, "project_name": project_name},
        )
        with_history = tool_option == "import_history"
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                self.import_pages(extractor.get_page_url("wiki_url"), history=with_history)
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                "import tool %s from %s on %s" % (self.app.config.options.mount_point, project_name, self.source),
                project=project,
                user=user,
                url=self.app.url,
            )
            g.post_event("project_updated")
            return self.app
        except Exception as e:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Пример #4
0
    def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None, user_name=None,
                    tool_option=None, **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name)
        if not extractor.has_wiki():
            return

        self.github_wiki_url = extractor.get_page_url('wiki_url').replace('.wiki', '/wiki')
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or 'wiki',
            mount_label=mount_label or 'Wiki',
            import_id={
                'source': self.source,
                'project_name': project_name,
            }
        )
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                self.import_pages(extractor.get_page_url('wiki_url'), history=with_history)
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                'import tool %s from %s on %s' % (
                    self.app.config.options.mount_point,
                    project_name,
                    self.source),
                project=project,
                user=user,
                url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception as e:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Пример #5
0
    def import_tool(self,
                    project,
                    user,
                    project_name=None,
                    mount_point=None,
                    mount_label=None,
                    user_name=None,
                    tool_option=None,
                    **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        wiki_avail = extractor.has_wiki()
        # has_wiki only indicates that wiki is enabled, but it does not mean
        # that it has any pages, so we should check if wiki repo actually
        # exists
        wiki_url = extractor.get_page_url('wiki_url')
        if not wiki_avail or not self.has_wiki_repo(wiki_url):
            return

        self.github_wiki_url = extractor.get_page_url('wiki_url').replace(
            '.wiki', '/wiki')
        self.app = project.install_app("Wiki",
                                       mount_point=mount_point or 'wiki',
                                       mount_label=mount_label or 'Wiki',
                                       import_id={
                                           'source': self.source,
                                           'project_name': project_name,
                                       })
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(
            user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                try:
                    self.import_pages(wiki_url, history=with_history)
                except git.GitCommandError:
                    log.error(
                        'Unable to clone GitHub wiki: '
                        'wiki_url=%s; '
                        'wiki_avail=%s; '
                        'avail_url=%s',
                        wiki_url,
                        wiki_avail,
                        extractor.get_page_url('project_info'),
                        exc_info=True)
                    raise
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log('import tool %s from %s on %s' %
                           (self.app.config.options.mount_point, project_name,
                            self.source),
                           project=project,
                           user=user,
                           url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Пример #6
0
    def import_tool(
        self,
        project,
        user,
        project_name=None,
        mount_point=None,
        mount_label=None,
        user_name=None,
        tool_option=None,
        **kw
    ):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        wiki_avail = extractor.has_wiki()
        # has_wiki only indicates that wiki is enabled, but it does not mean
        # that it has any pages, so we should check if wiki repo actually
        # exists
        wiki_url = extractor.get_page_url("wiki_url")
        if not wiki_avail or not self.has_wiki_repo(wiki_url):
            return

        self.github_wiki_url = extractor.get_page_url("wiki_url").replace(".wiki", "/wiki")
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or "wiki",
            mount_label=mount_label or "Wiki",
            import_id={"source": self.source, "project_name": project_name},
        )
        with_history = tool_option == "import_history"
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                try:
                    self.import_pages(wiki_url, history=with_history)
                except git.GitCommandError:
                    log.error(
                        "Unable to clone GitHub wiki: " "wiki_url=%s; " "wiki_avail=%s; " "avail_url=%s",
                        wiki_url,
                        wiki_avail,
                        extractor.get_page_url("project_info"),
                        exc_info=True,
                    )
                    raise
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                "import tool %s from %s on %s" % (self.app.config.options.mount_point, project_name, self.source),
                project=project,
                user=user,
                url=self.app.url,
            )
            g.post_event("project_updated")
            return self.app
        except Exception:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False