print (helpInfo) sys.exit() elif len(Uoptions) == 2: if Uoptions[1] == "-h": sys.exit(helpInfo) elif Uoptions[1][0] == "-": print "Unknown option %s" % (Uoptions[1]) sys.exit(helpInfo) else: projPathAtRemote = Uoptions[1] else: sys.exit(helpInfo) if not projPathAtRemote: projPathAtRemote = raw_input("Please input the project path string: ") projPathAtRemote = pathInfo_j(projPathAtRemote)[0] while not os.path.exists(projPathAtRemote): print "\nThere is no project as your input ('%s'). \nPlease verify the directory path and the project name to be wiped out.\n" % ( projPathAtRemote ) continueDel = raw_input("Do you want to specify another project to wipe out? y/n: ") print "\n" if continueDel.strip().upper() == "N": sys.exit("Good-bye.\n") break elif continueDel.strip().upper() != "Y": print "Please answer with y or n" else: projPathAtRemote = raw_input("Please input the name of the project which you want to wipe out: ") wipeProj(projPathAtRemote=projPathAtRemote)
def wipeProj(projPathAtRemote): import os, sys, pwd, stat from xml.dom import minidom from osWalk import walktree from userName import userName from UnjoinMail import UnjoinMailSub from pathInfo import pathInfo_j from unjoinProj import unjoinProj from snipTree import snipTree projPathInfo = pathInfo_j(projPathAtRemote) # pathInfo: pathOutput=(pathAbs,projName,projNameA,projNameP,projNameAP,pathPrefix,secId,pidType) # 0 1 2 3 4 5 6 7 # secId = projPathInfo[6] pidType = projPathInfo[7] projName = projPathInfo[1] # give project path (with proj name), relative to pathPrefix as in pathInfo.py projNameP = projPathInfo[3] pathPrefix = projPathInfo[5] if pidType == "private": pid = 1 elif pidType == "shared": pid = 3 else: sys.exit("Wrong project type, contact support") if secId == "BIOSTAT": secIdN = 1 elif secId == "BIOINFO": secIdN = 2 else: sys.exit("Wrong section ID, contact support") print "\nYou are going to permanently wipe out a project with the following parameters:" print " Section : %s" % (projPathInfo[6]) print " Project Type : %s" % (projPathInfo[7]) print " Local Project Path : %s" % (projPathInfo[9]) print "Remote Project Path : %s\n" % (projPathInfo[0]) pathVerify = raw_input("Is the above information correct [y] (y/n) ? ") pathVerify = pathVerify.upper() while not (pathVerify in ["", "Y", "N", "YES", "NO"]): print 'Please answer with "y" or "n" ' pathVerify = raw_input("Are these correct [y] (y/n)? ") pathVerify = pathVerify.upper() if pathVerify in ["N", "NO"]: sys.exit("\n") # ######################################### projPathAtRemote = projPathInfo[0] # os.path.abspath(projPathAtRemote) ProjToBeUnjoind = projPathInfo[1] # projPathAtRemote.split('/')[-1] # name of the project to be unjoined # ######################################### while not os.path.exists(projPathAtRemote): print "\nThere is no project as your input ('%s'). \nPlease verify the project name and directory path.\n" % ( projPathAtRemote ) continueDel = raw_input("Do you wan to specify another project to wipe out? y/n: ") print "\n" if continueDel.strip().upper() == "N": sys.exit("Good-bye.\n") break elif continueDel.strip().upper() != "Y": print "Please answer with y or n" else: projPathAtRemote = raw_input("Please input the name of the project which you want to wipe out: ") # ######################################### if pid in [1, 2]: projPathAtLocal = os.environ["HOME"] + "/MyProjects_" + secId + "/private" + "/" + ProjToBeUnjoind else: projPathAtLocal = os.environ["HOME"] + "/MyProjects_" + secId + "/shared" + "/" + ProjToBeUnjoind homePath = os.environ["HOME"] os.chdir(os.environ["HOME"]) # Initialize as in start.project ##### startprojectXML = r"//genomics/lib/start.project/start.project.xml" BIOINFOprojRootPath = r"//genomics/Projects" BIOSTATprojRootPath = r"/proj/BIOSTAT/Projects" USERprojRootPathPre = r"MyProjects" SHAREDPATH = r"shared" PRIVATEPATH = r"private" continueAsk = 0 while continueAsk == 0: projExist = "No" if not (ProjToBeUnjoind == ""): cask = 0 while cask == 0: string1 = "The project contents of '%s' will be purged. Are you sure ?! y/n: " % (ProjToBeUnjoind) AreYouSure = raw_input(string1) if AreYouSure.strip().upper() == "Y": print "\nDestorying Project. Please wait... \n ......\n" continueAsk = 1 break elif AreYouSure.strip().upper() == "N": # print "Good-bye" continueAsk = 1 print "\n Good-bye.\n" sys.exit() # break else: print "Please answer with y or n" else: print "\nThere is no project as your input. \nPlease verify the directory path and the project name to be wiped out.\n" # (\'%s\')%(ProjToBeUnjoindRawInput) while True: continueDel = raw_input("Do you wan to specify another project to wipe out? y/n: ") print "\n" if continueDel.strip().upper() == "Y": break elif continueDel.strip().upper() == "N": print "Good-bye" continueAsk = 1 sys.exit() break else: print "Please answer with y or n" memberList = [] if os.path.exists(projPathAtRemote): for (basepath, children) in walktree(projPathAtRemote, False): for child in children: DirFile = os.path.join(basepath, child) if os.path.islink(DirFile) and (not os.path.exists(os.path.realpath(DirFile))): # dead link DirFile = os.path.dirname(os.path.join(basepath, child)) folderOwner = pwd.getpwuid(os.stat(DirFile)[4])[0] if os.environ["USER"] != folderOwner: GidOfjoinProjFolder = os.stat(projPathAtRemote)[5] if GidOfjoinProjFolder in os.getgroups(): if (not (oct(os.stat(DirFile)[stat.ST_MODE] & 0777)[2] in ["7", "6", "2", "3"])) or ( not (oct(os.stat(DirFile)[stat.ST_MODE] & 0777)[3] in ["7", "6", "2", "3"]) ): if not (folderOwner in memberList): print DirFile memberList.append(folderOwner) else: print "%s, which is belong to %s, is not allowed to be deleted." % ( DirFile, userName(folderOwner)[1] + userName(folderOwner)[2], ) sys.exit() elif (oct(os.stat(DirFile)[stat.ST_MODE] & 0777)[2] != "7") or ( oct(os.stat(DirFile)[stat.ST_MODE] & 0777)[3] != "7" ): unlock = 'chmod ugo=rwx "%s"' % (DirFile) os.system(unlock) if len(memberList) >= 1: members = "" for member in memberList: memberName = userName(member)[1] + " " + userName(member)[2] members = memberName + ", " + members members = members.rstrip(", ") print 'The project can not be wiped out at this time.\nThere are still members in this project.\nPlease ask "%s" to unjoin project first.' % ( members ) sys.exit() # shared project delete if 3 > 2: if os.path.islink(projPathAtLocal): os.remove(projPathAtLocal) if os.path.exists(homePath + "/.mailboxlist"): UnjoinMailSub(ProjToBeUnjoind, pid, secIdN, ".mailboxlist") if os.path.exists(homePath + "/.subscriptions"): UnjoinMailSub(ProjToBeUnjoind, pid, secIdN, ".subscriptions") if secId == "BIOINFO": projRoot0 = "//genomics" elif secId == "BIOSTAT": projRoot0 = "/proj/BIOSTAT" if pid == 3: pathToXML = projPathAtRemote + "/.common/" + ".proj_info.xml" elif pid in [1, 2]: pathToXML = projPathAtRemote + "/.proj_info.xml" if os.path.exists(pathToXML): xmldoc = minidom.parse(pathToXML) cNodes = xmldoc.childNodes projNum = cNodes[0].getElementsByTagName("projNum") projNameP = projPathInfo[3] projInfoFileName = os.path.basename((projNum)[0].firstChild.nodeValue.strip()) relativePathtoXML = projPathInfo[3] XMLLink = os.path.join( projRoot0, "Projects/.projInfo", (os.path.join(projNameP, projInfoFileName)).replace("/", "=>") ) try: tempstring = 'rm "%s"' % (XMLLink) os.remove(XMLLink) except: aa = 0 if pid == 3: PublicFolder = projRoot0 + "/Public/.projects/" + ProjToBeUnjoind if os.path.exists(PublicFolder): removePublic = 'rm -R -f "%s"' % (PublicFolder) os.system(removePublic) localMail = projPathAtLocal.replace(os.environ["HOME"], os.environ["HOME"] + "/mail") if os.path.exists(localMail): removeMail = 'rm -R -f "%s"' % (localMail) os.system(removeMail) projPathAtRemoteAP = projPathInfo[4] projNameA = projPathInfo[2] moveMain = 'rm -R -f "%s"' % (projPathAtRemote) os.system(moveMain) projPathAtLocal = projPathInfo[9] localPathPrefix = projPathInfo[8] localMail = projPathAtLocal.replace(os.environ["HOME"], os.path.join(os.environ["HOME"], "mail"), 1) if pidType == "private": snipTree(folderPathRaw=os.path.dirname(projPathAtLocal), stopRaw=localPathPrefix) # local main snipTree(folderPathRaw=os.path.dirname(localMail), stopRaw=os.path.join(os.environ["HOME"], "mail")) snipTree(folderPathRaw=projPathAtRemoteAP, stopRaw=pathPrefix) else: snipTree(folderPathRaw=os.path.dirname(projPathAtLocal), stopRaw=localPathPrefix) # local main snipTree(folderPathRaw=os.path.dirname(localMail), stopRaw=os.path.join(os.environ["HOME"], "mail")) snipTree(folderPathRaw=projPathAtRemoteAP, stopRaw=pathPrefix) remotePublicRoot = pathPrefix.replace("/Projects/shared", "/Public/.projects", 1) remotePublic = projPathAtRemoteAP.replace(pathPrefix, remotePublicRoot, 1) snipTree(folderPathRaw=remotePublic, stopRaw=remotePublicRoot) print "Wipeout operation is completed. Good-bye.\n"
projPathAtRemote = Uoptions[1] elif len(Uoptions)==3: if Uoptions[1]!='-q': sys.exit(helpInfo) else: pattern='verbose' projPathAtRemote = Uoptions[2] else: print(helpInfo) sys.exit() if not projPathAtRemote: projPathAtRemote=raw_input('Please input the project path string: ') ################################################# projPathInfo=pathInfo_j(projPathAtRemote) # pathInfo: pathOutput=(pathAbs,projName,projNameA,projNameP,projNameAP,pathPrefix,secId,pidType) # 0 1 2 3 4 5 6 7 # -2 -1 secId=projPathInfo[6] pidType=projPathInfo[7] projName=projPathInfo[1] # give proj path (with proj name), relative to pathPrefix as in pathInfo.py projNameP=projPathInfo[3] ################################################# projPathAtRemote=projPathInfo[0] ProjToBeJoind=projPathInfo[1] #################################################