1
0
Fork 0
fgmeta/git_catalog_repository.py

51 lines
1.6 KiB
Python
Raw Normal View History

2015-06-04 21:09:46 +00:00
# git diff --quiet e5f841bc84d31fee339191a59b8746cb4eb8074c -- ./Aircraft/
2015-06-04 21:09:46 +00:00
import subprocess
import os, sgprops
2015-06-04 21:09:46 +00:00
class GITCatalogRepository:
def __init__(self, node, singleAircraft = False):
self._path = node.getValue("path")
if not os.path.exists(os.path.join(self._path , ".git")):
raise RuntimeError("not a Git directory:" + self._path )
self._usesSubmodules = node.getValue("uses-submodules", False)
2015-06-04 21:09:46 +00:00
self._singleAircraft = singleAircraft
self._currentRevision = subprocess.check_output(["git", "rev-parse", "HEAD"],
2015-06-04 21:09:46 +00:00
cwd = self._path)
self._aircraftPath = None
if node.hasChild("scan-suffix"):
self._aircraftPath = os.path.join(path, node.getValue("scan-suffix"))
@property
def path(self):
return self._path
@property
def aircraftPath(self):
return self._aircraftPath
2015-06-04 21:09:46 +00:00
def hasPathChanged(self, path, oldRev):
diffArgs = ["git", "diff", "--quiet", oldRev, "--"]
if not (self._usesSubmodules and self._singleAircraft):
diffArgs.append(path)
2015-06-04 21:09:46 +00:00
return subprocess.call(diffArgs, cwd = self._path)
def update(self):
subprocess.call(["git", "pull"])
self._currentRevision = subprocess.check_output(["git", "rev-parse", "HEAD"],
2015-06-04 21:09:46 +00:00
cwd = self._path)
2015-06-04 21:09:46 +00:00
if self._usesSubmodules:
subprocess.call(["git", "submodule", "update"], cwd = self._path)
2015-06-04 21:09:46 +00:00
def scmRevisionForPath(self, path):
if self._usesSubmodules:
return subprocess.check_output(["git", "rev-parse", "HEAD"], cwd = self._path)
2015-06-04 21:09:46 +00:00
return self._currentRevision