aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2015-11-12 11:38:35 -0800
committerZac Medico <zmedico@gentoo.org>2015-11-13 09:21:45 -0800
commit497f743cd3aab57f1220dd7dcd64b5bfce7af6c6 (patch)
tree04854452f892252f7e597ed2469a29d8f98cee79
parentebuild: unset all funcs/vars that start with ___ (diff)
downloadportage-497f743cd3aab57f1220dd7dcd64b5bfce7af6c6.tar.gz
portage-497f743cd3aab57f1220dd7dcd64b5bfce7af6c6.tar.bz2
portage-497f743cd3aab57f1220dd7dcd64b5bfce7af6c6.zip
FindVCS: support optional cwd argument
Since os.chdir calls may not be safe to use in threads, iterators, or event-driven code, make FindVCS support a cwd argument which defaults to the current working directory. Acked-by: Alexander Berntsen <bernalex@gentoo.org>
-rw-r--r--pym/repoman/vcs/vcs.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/pym/repoman/vcs/vcs.py b/pym/repoman/vcs/vcs.py
index 49d305891..a4633350d 100644
--- a/pym/repoman/vcs/vcs.py
+++ b/pym/repoman/vcs/vcs.py
@@ -39,15 +39,25 @@ _FindVCS_data = (
)
-def FindVCS():
- """ Try to figure out in what VCS' working tree we are. """
+def FindVCS(cwd=None):
+ """
+ Try to figure out in what VCS' working tree we are.
+
+ @param cwd: working directory (default is os.getcwd())
+ @type cwd: str
+ @return: list of strings describing the discovered vcs types
+ @rtype: list
+ """
+
+ if cwd is None:
+ cwd = os.getcwd()
outvcs = []
def seek(depth=None):
""" Seek for VCSes that have a top-level data directory only. """
retvcs = []
- pathprep = ''
+ pathprep = cwd
while depth is None or depth > 0:
for vcs_type in _FindVCS_data:
@@ -70,10 +80,10 @@ def FindVCS():
return retvcs
# Level zero VCS-es.
- if os.path.isdir('CVS'):
+ if os.path.isdir(os.path.join(cwd, 'CVS')):
outvcs.append('cvs')
if os.path.isdir('.svn'): # <1.7
- outvcs.append('svn')
+ outvcs.append(os.path.join(cwd, 'svn'))
# If we already found one of 'level zeros', just take a quick look
# at the current directory. Otherwise, seek parents till we get