$search
00001 import os 00002 import subprocess 00003 00004 def get_svn_url(dir_path): 00005 """ 00006 @return: SVN URL of the directory path (output of svn info command), or None if it cannot be determined 00007 """ 00008 if os.path.isdir(os.path.join(dir_path, '.svn')): 00009 output = subprocess.Popen(['svn', 'info', dir_path], stdout=subprocess.PIPE).communicate()[0] 00010 matches = [l for l in output.split('\n') if l.startswith('URL: ')] 00011 if matches: 00012 return matches[0][5:] 00013 return None 00014 00015 def guess_vcs_uri(dir_path): 00016 """ 00017 Guess the repository URI of the version-controlled directory path 00018 @param path: directry path 00019 @type path: str 00020 @return: version control system and URI, e.g. 'svn', 'http://code.ros.org/svn/ros'. Return None, None if VCS cannot be determined. 00021 @rtype: str, str 00022 """ 00023 repo = None, None 00024 try: 00025 if os.path.isdir(os.path.join(dir_path, '.svn')): 00026 # shell out to svn info and parse the output 00027 output = subprocess.Popen(['svn', 'info', dir_path], stdout=subprocess.PIPE).communicate()[0] 00028 matches = [l for l in output.split('\n') if l.startswith('Repository Root: ')] 00029 if matches: 00030 repo = ('svn', matches[0][17:]) 00031 else: 00032 # check parent directories for the .git config directory 00033 dir_path = os.path.abspath(dir_path) 00034 while dir_path and dir_path != os.path.dirname(dir_path) and repo == (None, None): 00035 if os.path.isdir(os.path.join(dir_path, '.git')): 00036 with open(os.path.join(dir_path, '.git', 'config')) as config: 00037 in_section = False 00038 for l in config.readlines(): 00039 if l.strip() == '[remote "origin"]': 00040 in_section = True 00041 elif in_section and l.startswith('\turl = '): 00042 repo = 'git', l[7:].strip() 00043 break 00044 else: 00045 dir_path = os.path.dirname(dir_path) 00046 except Exception as e: 00047 pass 00048 return repo