0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Sphinx】reSTファイル内のタイトルにSubversionのリビジョン番号を付与する。

Last updated at Posted at 2021-08-22

1.はじめに(動機)

自分用に貯めてきたSphinxのタイトル末尾にバージョン番号を付けることにしました。
その時のメモを共有します。

ポイント

  • Subversionのリビジョン番号は $Rev$ を埋め込むと、$Rev: 543 $ のようにリビジョン番号を展開する。
  • この $Rev: 543 $543 だけを使いたい。
  • SubWCRev は、Cygwin端末内で作業が完結しないのでイヤ。

2.概要

慣れている人なら、ここを読めば後は自分で作れる。

2.1.見出しの書式と拡張子

見出しの書式は 見出し文字列 [x.y.543]

拡張子 .rstx

  • 見出し文字列 [x.y.$Rev: 543 $]
  • このファイルをSubversionで管理
  • .rst_ はGVimのシンタックスハイライトの設定ができない。

拡張子 .rst

  • 見出し文字列 [x.y.543]
  • .rstx のリビジョン番号を処理して作成。

2.2.仕組み

  1. 元の .rst ファイルを、svn mv.rstx に変更
  2. 変換用スクリプト make-rst の作成と、 Makefile への埋め込み
  3. GVimの対応
    • .rstx をGVimに紐付ける。
    • _gvimrc を編集して、シンタックスハイライトを有効にする。
  4. .rst を無視するように svn:ignore を設定する。

3.詳細

注意) これからの作業で失敗した時のために、全てのファイルをsvn commitする。

3.1.元の拡張を変更

$ find source -name \*.rst -exec svn mv {} {}x \;

※なんかやらかしてしまったら、 svn revert してやり直す。

3.2.変換の仕組み

スクリプト

# !/usr/bin/bash
# .rstx: before
# .rst: after

convert_file()
{
        if [ ${1} -nt ${2} ]
        then
                echo "generate: ${2}"
                sed -e 's/\$Rev: \([0-9][0-9]*\) \$/\1/' ${1} > ${2}
        fi
}

create_rst()
{
        for src in `find $1 -name \*.rstx`
        do
                convert_file $src ${src%.rstx}.rst
        done
}

delete_rst()
{
        find $1 -name \*.rst -exec rm -f {} \;
        return 0
}

main()
{
        if [ "$1" = "" -o "$2" = "" ]
        then
                echo "error: no args"; return 127
        fi

        if [ ! -d $2 ]
        then
                echo "not found: $2"; return 126
        fi

        if [ "$1" = "clean" ]
        then
                delete_rst $2
        else
                create_rst $2
        fi

        return 0
}

main $1 $2 $3
exit $?

Makefile(変更点のみ抜粋)

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
clear: Makefile
        @$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

%: Makefile
        make-rst $@ $(SOURCEDIR)
        @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

3.3.GVimの対応

次の一行を追記する

autocmd BufNewFile,BufRead *.rstx set filetype=rst

3.4.svn:ignore の設定

理由は変わらないがこんなエラーになった。

$ svn ci -m "svn proedit snv:ignore" mathematics
Sending        mathematics
svn: E155011: Commit failed (details follow):
svn: E155011: Directory '/home/USERNAME/sphinx/physics/source/mathematics' is out of date
svn: E160028: Directory '/sphinx/trunk/physics/source/mathematics' is out of date

別の場所で同じものをチェックアウトし、そこで同じことやったら上手くいった。
もしかしたら svn update を実行していれば解決していたのかも。

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?