- def detectProtocol(self, cmdProtocol = None):
- # reuse parent repo protocol
- proc = subprocess.Popen(['git', 'ls-remote', '--get-url', 'origin'], stdout=subprocess.PIPE, universal_newlines=True)
- (stdout, stderr) = proc.communicate()
-
- if proc.returncode != 0:
- raise Exception("Failed to execute 'git ls-remote origin', got %d" % proc.returncode)
- if (stdout[:3] == 'ssh') or (stdout[:3] == 'git'):
- protocol = 'ssh'
- else:
- # remote 'origin' doesn't exist, assume 'https' as checkout protocol
- protocol = 'https'
- return protocol
-
- def selectUrl(self, cmdProtocol = None):
- try:
- if cmdProtocol == None:
- protocol = self.detectProtocol(cmdProtocol)
- else:
- protocol = cmdProtocol
- except:
- # fallback to https on any issues
- protocol = 'https'
-
- if protocol == 'ssh':
- if self.sshUrl != None:
- url = self.sshUrl
- else:
- assert self.httpsUrl != None
- url = self.httpsUrl
- else:
- assert protocol == 'https'
- url = self.httpsUrl
-
- assert url != None
- return url
-
- def update (self, cmdProtocol = None, force = False):
- fullDstPath = os.path.join(EXTERNAL_DIR, self.baseDir, self.extractDir)
-
- url = self.selectUrl(cmdProtocol)