Skip to content

Instantly share code, notes, and snippets.

@mumumu
Last active December 19, 2015 00:39
Show Gist options
  • Save mumumu/5870407 to your computer and use it in GitHub Desktop.
Save mumumu/5870407 to your computer and use it in GitHub Desktop.
php ドキュメントのリポジトリのうち、マスタとなる en と 日本語 の ja を比較し、非常におおまかな差分情報を出力するPythonスクリプト。細かい fuzzy 度合いはわからないので注意。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
phpdoc_rev_compare.py
Description:
php ドキュメントのリポジトリのうち、マスタとなる
en と 日本語 の ja を比較し、以下の情報を出力する
1. en にあるが、 jaに全く反映されていないもの
2. ja にあるが、 en の方が更新されているもの
3. ja にあるが、 en に情報が存在しない、削除されている疑惑があるもの
Requirement:
- Python 2.6 以降
- PySVN
http://pysvn.tigris.org/project_downloads.html
Usage:
1. svn co http://svn.php.net/repository/phpdoc/modules/doc-ja
2. doc-ja ディレクトリ直下にこのスクリプトを置く
python phpdoc_rev_compare.py new_only
en にあるが、 jaに全く反映されていないものだけ出力
python phpdoc_rev_compare.py old_only
ja にあるが、 en の方が更新されているものだけ出力
python phpdoc_rev_compare.py deleted_only
ja にあるが、 en に情報が存在しない、削除されている疑惑があるものだけ出力
"""
import os
import sys
import re
import pysvn
client = pysvn.Client()
def get_last_changed_rev(path):
try:
info = client.info2(path)
return info[0][1].last_changed_rev.number
except:
return None
def compare_revision(path1, path2):
path1_rev = get_last_changed_rev(path1)
path2_rev = get_last_changed_rev(path2)
if sys.argv[1] == 'new_only':
if path1_rev and not path2_rev:
print path2 + ":" + str(path1_rev) + ":" + str(path2_rev)
return
if sys.argv[1] == 'old_only':
if not os.path.isdir(path1) and path2_rev and path1_rev > path2_rev:
print path2 + ":" + str(path1_rev) + ":" + str(path2_rev)
return
if sys.argv[1] == 'deleted_only':
if not path1_rev and path2_rev > 0:
print path2 + ":" + str(path1_rev) + ":" + str(path2_rev)
return
#
# main
#
if len(sys.argv) == 1:
print "invalid argument"
print "usage: python phpdoc_rev_compare.py [new_only|old_only|deleted_only]"
sys.exit(1)
for root, dirs, files in os.walk('en/'):
# ignore svn directory
if re.search("\.svn" ,root):
continue
# compare directory revision
en_root = root
ja_root = re.sub('^en', 'ja', en_root)
compare_revision(en_root, ja_root)
# compare files in directory
for file in files:
en_path = en_root + '/' + file
ja_path = ja_root + '/' + file
compare_revision(en_path, ja_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment