def targetPathToName(path): name = "" path = path.strip() if git.isGitRepo(path): if os.path.isdir(path): name = os.path.basename(path) elif utilityFunctions.isURL(path): name = utilityFunctions.URLToFilename(path) if name.endswith(".git"): name = name[:-4] elif svn.isSvnRepo(path): if path.endswith(os.sep): path = path[:-1] if path.endswith("/trunk") or path.endswith("\trunk"): path = path[:-6] if os.path.isdir(path): name = os.path.basename(path) elif utilityFunctions.isURL(path): name = utilityFunctions.URLToFilename(path) elif utilityFunctions.isURL(path): name = utilityFunctions.URLToFilename(path) name = utilityFunctions.splitFileName(name)[0] elif os.path.isfile(path) and utilityFunctions.validateCompressedFile(path, logger): name = utilityFunctions.splitFileName(path)[0] elif os.path.isdir(path): if path.endswith(os.sep): name = os.path.basename(path[:-1]) else: name = os.path.basename(path) else: logger.writeError("Could not convert given target path to name: " + path) return name
def fetch(pythonCallInfo): outfd = logger.getOutFd(pythonCallInfo.target.name, "fetch") if git.isGitRepo(pythonCallInfo.target.path): if not git.gitCheckout(pythonCallInfo.target.path, pythonCallInfo.target.outputPath): pythonCallInfo.logger.writeError("Given Git repo '" + pythonCallInfo.target.path +"' was unable to be checked out") pythonCallInfo.success = False else: pythonCallInfo.target.path = pythonCallInfo.target.outputPath pythonCallInfo.success = True elif hg.isHgRepo(pythonCallInfo.target.path): if not hg.hgCheckout(pythonCallInfo.target.path, pythonCallInfo.target.outputPath): pythonCallInfo.logger.writeError("Given Hg repo '" + pythonCallInfo.target.path +"' was unable to be checked out") pythonCallInfo.success = False else: pythonCallInfo.target.path = pythonCallInfo.target.outputPath pythonCallInfo.success = True elif svn.isSvnRepo(pythonCallInfo.target.path): if not svn.svnCheckout(pythonCallInfo.target.path, pythonCallInfo.target.outputPath, outfd): pythonCallInfo.logger.writeError("Given Svn repo '" + pythonCallInfo.target.path +"' was unable to be checked out") pythonCallInfo.success = False else: pythonCallInfo.target.path = pythonCallInfo.target.outputPath pythonCallInfo.success = True elif utilityFunctions.isURL(pythonCallInfo.target.path): filenamePath = os.path.join(pythonCallInfo.options.downloadDir, utilityFunctions.URLToFilename(pythonCallInfo.target.path)) if not os.path.exists(pythonCallInfo.options.downloadDir): os.mkdir(pythonCallInfo.options.downloadDir) urllib.urlretrieve(pythonCallInfo.target.path, filenamePath) pythonCallInfo.target.path = filenamePath pythonCallInfo.success = True elif os.path.isdir(pythonCallInfo.target.path): if pythonCallInfo.target.outputPathSpecified and \ os.path.abspath(pythonCallInfo.target.path) != os.path.abspath(pythonCallInfo.target.outputPath): distutils.dir_util.copy_tree(pythonCallInfo.target.path, pythonCallInfo.target.outputPath) pythonCallInfo.target.path = pythonCallInfo.target.outputPath pythonCallInfo.success = True elif os.path.isfile(pythonCallInfo.target.path): pythonCallInfo.success = True return pythonCallInfo