Created
May 25, 2012 02:33
-
-
Save shomah4a/2785431 to your computer and use it in GitHub Desktop.
リポジトリいじってみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding:utf-8 -*- | |
import time | |
import datetime | |
from mercurial import localrepo, match, ui as uimod | |
def load_repository(path): | |
u''' | |
ローカルディスクにあるリポジトリを開く | |
''' | |
ui = uimod.ui() | |
return localrepo.localrepository(ui, path) | |
def enum_files(repo, patterns=[]): | |
u''' | |
リポジトリにあるファイルを列挙 | |
patterns は mercurial.match.match を参照 | |
''' | |
return repo.walk(match.match('/', '/', patterns)) | |
def _get_file_last_updates(repo): | |
u''' | |
ファイルごとの最終更新日を取得 | |
消えているファイルも出ちゃう | |
''' | |
def mkupdates(rev): | |
u''' | |
リビジョンから更新日リストを取得 | |
''' | |
ut, _ = rev.date() | |
date = datetime.datetime(*time.localtime(ut)[:-2]) | |
return dict((x, date) for x in rev.files()) | |
return reduce((lambda x, y: dict(x.items()+y.items())), | |
[mkupdates(rev) for rev in reversed(repo)], {}) | |
def get_last_update_dict(repo, pattern): | |
u''' | |
ファイルごとの最終更新日を取得 | |
pattern は mercurial.match.match を参照 | |
''' | |
files = set(enum_files(repo, [pattern])) | |
updates = _get_file_last_updates(repo) | |
return dict(x for x in updates.iteritems() | |
if x[0] in files) | |
if __name__ == '__main__': | |
repo = load_repository(path_to_repos) | |
import pprint | |
pprint.pprint(get_last_update_dict(repo, r're:.*\.rst')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment