def handleAdd(wfile, request, session): productionName=request["production_name"] productionLocation=request["production_location"] productionSvnUrl=request["production_svnurl"] productionSvnUsername=request["production_svnusername"] productionSvnPassword=request["production_svnpassword"] try: if productionSvnUrl=="": if not path.isdir(productionLocation): wfile.write("[{\"error\":\"Location ["+productionLocation+"] does not exist or is not a directory\"}]\r\n".encode()); else: indexer.insertProduction(productionName, productionLocation); wfile.write("[]\r\n".encode()); else: result, additional = svn.testWorkingFolder(productionLocation, productionSvnUrl); if result in [svn.SVNNOBINDING, svn.SVNNOWORKINGFOLDER]: #ok, checkout needed do checkout svn.svnCheckout(productionLocation, productionSvnUrl, productionSvnUsername, productionSvnPassword); indexer.insertProduction(productionName, productionLocation, productionSvnUrl, productionSvnUsername, productionSvnPassword); wfile.write("[]\r\n".encode()); elif result in [svn.SVNURLSAME]: #ok, do nothing indexer.insertProduction(productionName, productionLocation, productionSvnUrl, productionSvnUsername, productionSvnPassword); wfile.write("[]\r\n".encode()); elif result in [svn.SVNURLDIFF]: #error, user entry wfile.write("[{\"error\":\"Location ["+productionLocation+"] contains content from a different SVN URL\"}]\r\n".encode()); elif result in [svn.SVNWORKINGFOLDERISFILE]: #error, user entry wfile.write("[{\"error\":\"Location ["+productionLocation+"] is a file\"}]\r\n".encode()); except svn.pysvn.ClientError as c: wfile.write("[{\"error\":\""+str(c)+"\"}]\r\n".encode());
def testWorkingFolder(self): #test path is dir currentFile = inspect.currentframe().f_code.co_filename result, additional = svn.testWorkingFolder(currentFile, "http://atmind/svn/test") self.assertEqual(result, svn.SVNWORKINGFOLDERISFILE) #location does not exist result, additional = svn.testWorkingFolder("/bladiebla", "http://atmind/svn/test") self.assertEqual(result, svn.SVNNOWORKINGFOLDER) #non existing url result, additional = svn.testWorkingFolder("/tmp", "http://atmind2/svn/test") self.assertEqual(result, svn.SVNNOBINDING) #different svn, make test dir if os.path.exists("/tmp/test"): retcode = subprocess.call(["rm", "-Rf", "/tmp/test"]) svn.svnCheckout("/tmp/test", "http://atmind/svn/test", "test", "test") result, additional = svn.testWorkingFolder( "/tmp/test", "http://atmind/svn/yofrankie") self.assertEqual(result, svn.SVNURLDIFF) #same svn, make test dir if os.path.exists("/tmp/test"): retcode = subprocess.call(["rm", "-Rf", "/tmp/test"]) svn.svnCheckout("/tmp/test", "http://atmind/svn/test", "test", "test") result, additional = svn.testWorkingFolder("/tmp/test", "http://atmind/svn/test") self.assertEqual(result, svn.SVNURLSAME)
def handleAdd(wfile, request, session): productionName = request["production_name"] productionLocation = request["production_location"] productionSvnUrl = request["production_svnurl"] productionSvnUsername = request["production_svnusername"] productionSvnPassword = request["production_svnpassword"] try: if productionSvnUrl == "": if not path.isdir(productionLocation): wfile.write( "[{\"error\":\"Location [" + productionLocation + "] does not exist or is not a directory\"}]\r\n".encode()) else: indexer.insertProduction(productionName, productionLocation) wfile.write("[]\r\n".encode()) else: result, additional = svn.testWorkingFolder(productionLocation, productionSvnUrl) if result in [svn.SVNNOBINDING, svn.SVNNOWORKINGFOLDER]: #ok, checkout needed do checkout svn.svnCheckout(productionLocation, productionSvnUrl, productionSvnUsername, productionSvnPassword) indexer.insertProduction(productionName, productionLocation, productionSvnUrl, productionSvnUsername, productionSvnPassword) wfile.write("[]\r\n".encode()) elif result in [svn.SVNURLSAME]: #ok, do nothing indexer.insertProduction(productionName, productionLocation, productionSvnUrl, productionSvnUsername, productionSvnPassword) wfile.write("[]\r\n".encode()) elif result in [svn.SVNURLDIFF]: #error, user entry wfile.write( "[{\"error\":\"Location [" + productionLocation + "] contains content from a different SVN URL\"}]\r\n". encode()) elif result in [svn.SVNWORKINGFOLDERISFILE]: #error, user entry wfile.write("[{\"error\":\"Location [" + productionLocation + "] is a file\"}]\r\n".encode()) except svn.pysvn.ClientError as c: wfile.write("[{\"error\":\"" + str(c) + "\"}]\r\n".encode())
def testWorkingFolder(self): #test path is dir currentFile = inspect.currentframe().f_code.co_filename; result, additional = svn.testWorkingFolder(currentFile, "http://atmind/svn/test"); self.assertEqual(result, svn.SVNWORKINGFOLDERISFILE); #location does not exist result, additional = svn.testWorkingFolder("/bladiebla", "http://atmind/svn/test"); self.assertEqual(result, svn.SVNNOWORKINGFOLDER); #non existing url result, additional = svn.testWorkingFolder("/tmp", "http://atmind2/svn/test"); self.assertEqual(result, svn.SVNNOBINDING); #different svn, make test dir if os.path.exists("/tmp/test"): retcode = subprocess.call(["rm", "-Rf", "/tmp/test"]); svn.svnCheckout("/tmp/test", "http://atmind/svn/test", "test", "test"); result, additional = svn.testWorkingFolder("/tmp/test", "http://atmind/svn/yofrankie"); self.assertEqual(result, svn.SVNURLDIFF); #same svn, make test dir if os.path.exists("/tmp/test"): retcode = subprocess.call(["rm", "-Rf", "/tmp/test"]); svn.svnCheckout("/tmp/test", "http://atmind/svn/test", "test", "test"); result, additional = svn.testWorkingFolder("/tmp/test", "http://atmind/svn/test"); self.assertEqual(result, svn.SVNURLSAME);
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