fgmeta/svn_catalog_repository.py

28 lines
871 B
Python
Raw Normal View History

2015-06-05 05:09:46 +08:00
2015-07-26 11:45:01 +08:00
import subprocess, os
2015-06-05 05:09:46 +08:00
import xml.etree.cElementTree as ET
class SVNCatalogRepository:
def __init__(self, path):
2015-07-26 11:45:01 +08:00
if not os.path.exists(path):
raise RuntimeError("No directory at:" + path)
2015-06-05 05:09:46 +08:00
self._path = path
xml = subprocess.check_output(["svn", "info", "--xml", path])
root = ET.fromstring(xml)
2015-07-26 11:45:01 +08:00
if (root.find(".//repository/root") == None):
2015-06-05 05:09:46 +08:00
raise RuntimeError("Not an SVN repository:" + path)
2015-07-26 11:45:01 +08:00
2015-06-05 05:09:46 +08:00
def hasPathChanged(self, path, oldRevision):
return self.scmRevisionForPath(path) != oldRevision
2015-07-26 11:45:01 +08:00
2015-06-05 05:09:46 +08:00
def scmRevisionForPath(self, path):
xml = subprocess.check_output(["svn", "info", "--xml", path])
root = ET.fromstring(xml)
commit = root.find(".//entry/commit")
2015-06-05 05:09:46 +08:00
return commit.get('revision', 0)
2015-07-26 11:45:01 +08:00
2015-06-05 05:09:46 +08:00
def update(self):
subprocess.call(["svn", "update"])