commit: 497f743cd3aab57f1220dd7dcd64b5bfce7af6c6 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Thu Nov 12 19:38:35 2015 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Fri Nov 13 17:21:45 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=497f743c
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 <AT> gentoo.org> pym/repoman/vcs/vcs.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pym/repoman/vcs/vcs.py b/pym/repoman/vcs/vcs.py index 49d3058..a463335 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