LoginSignup
1
1

More than 5 years have passed since last update.

svnの指定したユーザーのコミットしたファイルのリストを取得したい

Posted at

Python 2.7.12
svn 1.9.3
Windows Subsystem for Linux

svnリポジトリから指定したユーザーがコミットしたファイルのリストを取得します。

import subprocess
import sys
import xml.etree.ElementTree as ET


def get_commit_files(url, author):
    cmd = 'svn log %s -v --xml' % url

    try:
        result = subprocess.check_output(cmd.split())
    except subprocess.CalledProcessError as e:
        print e.returncode
        print e.cmd
        print e.output,
        sys.exit(1)

    root = ET.fromstring(result)

    files = []
    for child in root:
        if child[0].text == author:
            for path in child.iter('path'):
                if path.attrib.get('kind') == 'file':
                    files.append(path.text)

    for f in sorted(set(files)):
        print(f)


if __name__ == '__main__':
    if len(sys.argv) != 3:
        print('python get_commit_files.py url author')
        sys.exit(1)

    get_commit_files(sys.argv[1], sys.argv[2])
1
1
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
1
1