18de809f70db46cfe42a72b76433af3325016c81 lrnassar Wed Nov 23 10:57:02 2022 -0800 Removing bash subprocess calls and other general improvements to thumbnail script in response to CR. Refs #30312 diff --git src/utils/qa/buildPublicSessionThumbnailsIndexPage.py src/utils/qa/buildPublicSessionThumbnailsIndexPage.py index 78ef81f..e32d3c1 100755 --- src/utils/qa/buildPublicSessionThumbnailsIndexPage.py +++ src/utils/qa/buildPublicSessionThumbnailsIndexPage.py @@ -14,61 +14,50 @@ required.add_argument ("saveDir", help = "Server from which to query the hubPublic table. Can be dev, hgwbeta, or rr.") if (len(sys.argv) == 1): parser.print_usage() print("\nFetches thumbnails and descriptions of public sessions from the RR and saves/creates\n" + \ "an html page that can be included in the homepage. Requires the directory in which to save\n" + \ "the pages to be declared.\n\n" + \ "Example run:\n" + \ " buildPublicSessionThumbnailsIndexPage /cluster/home/lrnassar/kent/src/hg/htdocs/\n") exit(0) parser._action_groups.append(optional) options = parser.parse_args() return options -def bash(cmd): - """Run the cmd in bash subprocess""" - try: - rawBashOutput = subprocess.run(cmd, check=True, shell=True,\ - stdout=subprocess.PIPE, universal_newlines=True, stderr=subprocess.STDOUT) - bashStdoutt = rawBashOutput.stdout - except subprocess.CalledProcessError as e: - raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output)) - return(bashStdoutt) - def queryHgPublicSessAndAssignOutputFileAndDir(saveDir): """Curl hgPublicSession and assign output file name/directory""" - hgPublicSessionOutPut = bash('curl -Lk https://genome.ucsc.edu/cgi-bin/hgPublicSessions') + hgPublicSessionOutPut = requests.get('https://genome.ucsc.edu/cgi-bin/hgPublicSessions') outputFile = open(saveDir+'thumbNailLinks.html', 'w') return(hgPublicSessionOutPut, outputFile) def parseHgPublicSessPageAndWriteOut(hgPublicSessionOutPut, saveDir, outputFile): """Parse hgPublicSession curled page, extract thumbnail/url/description and write out to file""" sessionThumbNailsWritten = 1 - for line in hgPublicSessionOutPut.split('\n'): + for line in hgPublicSessionOutPut.text.split('\n'): if "trash" in line and sessionThumbNailsWritten < 4: sessionUrl = "https://genome.ucsc.edu/cgi-bin/"+line.split('"')[1].split("/")[2] trashDirUrl = line.split('"')[3] downloadThumbNailUrl = "https://genome.ucsc.edu/trash/hgPS/"+trashDirUrl.split("/")[3] currentImageFileName = 'sessionThumbNail'+str(sessionThumbNailsWritten)+'.png' img_data = requests.get(downloadThumbNailUrl).content - with open(currentImageFileName, 'wb') as handler: + with open(saveDir+currentImageFileName, 'wb') as handler: handler.write(img_data) - bash('mv '+currentImageFileName+' '+saveDir+currentImageFileName) - bash('chmod 777 '+saveDir+currentImageFileName) + os.chmod(saveDir+currentImageFileName, 0o664) if "Description:" in line and sessionThumbNailsWritten < 4: sessionThumbNailsWritten+=1 sessionDescription = line.split(' ')[1].split('
')[0] outputFile.write('''\n\n''') outputFile.close() - bash('chmod 777 '+saveDir+'thumbNailLinks.html') + os.chmod(saveDir+'thumbNailLinks.html', 0o775) def main(): options = parseArgs() saveDir = options.saveDir hgPublicSessionOutPut, outputFile = queryHgPublicSessAndAssignOutputFileAndDir(saveDir) parseHgPublicSessPageAndWriteOut(hgPublicSessionOutPut, saveDir, outputFile) main()