Example #1
0
def sendmailPB(s,projName,projpp,EMailAdd,goodbyeText):
    # this function is for shared and private project Information and Project established notice.
    import os, smtplib
    import time
    from userName import userName
    
    if userName()[1]!='' or userName()[2]!='':
        FLName=userName()[1]+' '+userName()[2]
    else:
        FLName=os.environ['LOGNAME']    
    
    From=EMailAdd
    To=EMailAdd
    Date = time.ctime(time.time())
    Subject = "Project initialization: \'%s\'" %(projName)
    Text = '''\n%s\nTo unjoin the project, please login analysis.xxx.xxx.xxx, copy and paste the following line at your shell's prompt:
    unjoin.project %s\n
Let us cooperate to get this project well done.\n
Sincerely,
%s
Email: %s 
    ''' %(goodbyeText,projpp, FLName,From)  #os.environ['LOGNAME']
    #Format mail message
    mMessage = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n%s\n' %
                (From, To, Date, Subject, Text))     
    rCode = s.sendmail(From, To, mMessage)
    s.quit()
    if rCode:
        print 'Error Sending Message. Please verify your emaill address.'
Example #2
0
def sendmailSI(s,projName,projpp,EMailAdd):
    # this function is for shared project Invitation
    import os, smtplib
    import time
    from userName import userName
    
    if userName()[1]!='' or userName()[2]!='':
        FLName=userName()[1]+' '+userName()[2]
    else:
        FLName=os.environ['LOGNAME']
    
    From=EMailAdd
    To=EMailAdd
    Date = time.ctime(time.time())
    Subject = "Project Invitation: \'%s\'" %(projName)
    Text = '''Dear project analyst:\n
You are invited to join the project:  %s.\n
Instructions to join:
1. login analysis.xxx.xxx.xxx using your Unix user id and password.
2. run the following command at the command line
    join.project %s\n
Instructions to unjoin:
1. login analysis.xxx.xxx.xxx using your Unix user id and password.
2. run the following command at the command line
    unjoin.project %s\n
Let us cooperate to get this project well done.\n
Sincerely,
%s
Email: %s 
    ''' %(projName, projpp, projpp, FLName,From)
    #Format mail message
    mMessage = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n%s\n' %
                (From, To, Date, Subject, Text))     
    rCode = s.sendmail(From, To, mMessage)
    s.quit()
    if rCode:
        print 'Error Sending Message. Please verify your email address.'
    else:
        print '\nTwo auto generated emails have been successfully sent to you at %s.' %(To)
        print 'To invite other project member(s), please forward the Project Invitation Email.\n'          
Example #3
0
 def _inputAnalyst(self):
     if self.pattern=='verbose':
         moreAnalyst = 1
         while moreAnalyst >0:
                 analyst = {}
                 cask=0
                 while cask==0:
                        try:
                                AnaNameQ="Your FirstName and LastName: [%s %s] " %(userName()[1],userName()[2])
                                RAnaNameQ=raw_input(AnaNameQ)
                                if RAnaNameQ!='' and RAnaNameQ!='\n':
                                   analystFname,analystLname = RAnaNameQ.split()
                                   analystLname = analystLname.strip()
                                else:
                                   analystFname=userName()[1]
                                   analystLname=userName()[2]
                                cask=1
                        except:
                                print "Please input the information in the formate as in the [ ]"                                  
                 analystType = raw_input("Category (1: Ph.D statistician, 2: MS statistician, 3: Stats Programmer): ")
                 while analystType not in ('1','2','3'):
                         analystType = raw_input("Only 1, 2 or 3 are valid: ")
                 analyst['firstName'] = analystFname
                 analyst['lastName'] = analystLname
                 analyst['category'] = analystType
                 analyst['email'] = 'NoValue'
                 analyst['joinDate'] = time.ctime()
                 analyst['unjoinDate'] ='NoValue'  #time.asctime(time.strptime("1 Jan 00 1:1am", "%d %b %y %I:%M%p"))  #'Sat Jan  1 01:01:00 2000'
                 analyst['loginName']=os.environ['USER']                        
                 self.analysts.append(analyst)
                 moreAnalyst = -1
     if self.pattern=='non-verbose':
           analyst = {}  
           if userName()[1]!='':
               analyst['firstName'] = userName()[1]
           else:
               analyst['firstName'] =' '
           if userName()[2]!='':
               analyst['lastName'] = userName()[2]
           else:
               analyst['lastName'] =' '        
           analyst['category'] = ' '
           analyst['email'] = 'NoValue'
           analyst['joinDate'] = time.ctime()
           analyst['unjoinDate'] ='NoValue'  #time.asctime(time.strptime("1 Jan 00 1:1am", "%d %b %y %I:%M%p"))  #'Sat Jan  1 01:01:00 2000'
           analyst['loginName']=os.environ['USER']  
           self.analysts.append(analyst)                
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"
Example #5
0
def delProj(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_d,pathInfo_ks
    from unjoinProj import unjoinProj
    from snipTree import snipTree
    
    ##################################
    projPathInfo=pathInfo_d(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]
    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")    
    
    if projPathInfo[7]=='shared':
        print "\nYou are going to delete 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()
        #print pathVerify
        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("Please change to your home directory and rerun the start.project.")    
    
    ###########################################
    projPathAtRemote=projPathInfo[0]           
    ProjToBeUnjoind=projPathInfo[1]            

    ###########################################

    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 delete? 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 delete: ")    

    ############################################
    
    # get local proj path ###
    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 the 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'
    
    ###############
    if pidType == 'private':
        try:    
            unjoinProj(projPathAtRemote=projPathAtRemote,pattern='non-verbose',pd='Tt')
        except:
            sys.exit("Errors. Pleasee contact support.")
        print "Deleting.... Please wait.\n   .... "    
        sys.exit("Delete completed. Good bye.")
    ################
    
    
    ################
    continueAsk=0
    while continueAsk==0:
        projExist="No"
        if ( not(ProjToBeUnjoind=='')) :  
            cask=0
            while cask==0:
                string1='Are you sure to delete the whole project \'%s\'  y/n ?: ' %(ProjToBeUnjoind) 
                AreYouSure=raw_input(string1)
                if (AreYouSure.strip().upper() == 'Y'): 
                    print "\nDeleting. Please wait... \n ......\n"
                    continueAsk=1
                    break
                elif (AreYouSure.strip().upper() == 'N'):
                    continueAsk=1
                    print '\n Good-bye.\n'
                    sys.exit()
                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 deleted.\n"  #(\'%s\')%(ProjToBeUnjoindRawInput)
            while True:        
                continueDel=raw_input("Do you wan to specify another project to delete? 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"
    #############################################
    DirFileInfo=[] 
    memberList=[] 
    if os.path.exists(projPathAtRemote):
       for (basepath, children) in walktree(projPathAtRemote,False):
          for child in children:
             DirFile=os.path.join(basepath, child)
             folderOwner=pwd.getpwuid(os.stat(DirFile)[4])[0]        #lstat ==>stat
             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','3','2'])) and (not (oct(os.stat(DirFile)[stat.ST_MODE] & 0777)[3] in ['7','6','3','2'])): 
                        if not(folderOwner in memberList):
                            #print DirFile
                            DirFileInfo.append(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.lstat(DirFile)[stat.ST_MODE] & 0777)[1:3]!=['7','7','7']): 
                unlock='chmod ugo=rwx \"%s\"' %(DirFile)
                os.system(unlock)
       if os.environ["USER"]==pwd.getpwuid(os.stat(projPathAtRemote)[4])[0]:
          if (oct(os.lstat(projPathAtRemote)[stat.ST_MODE] & 0777)[1:3]!=['7','7','7']):
                unlock='chmod ugo=rwx \"%s\"' %(projPathAtRemote)
                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 deleted 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'
        pathToXML=projPathAtRemote+'/.common/'+'.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',projInfoFileName.replace('/','=>'))
            try:            
                os.remove(XMLLink)
                os.remove('.'+XMLLink)
            except:
                aa=0 
        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]           
        if projPathAtRemote!=os.path.join(projPathAtRemoteAP,'.'+projInfoFileName):
            moveMain='mv \"%s\" \"%s\"' %(projPathAtRemote, os.path.join(projPathAtRemoteAP,'.'+projInfoFileName))
            os.system(moveMain)
            newDeletedName=(os.path.join(projNameP,projInfoFileName)).replace('/','=>')
            move2deleted=os.path.join(os.path.dirname(pathPrefix),'.deleted',newDeletedName)
            move2='mv \"%s\" \"%s\"' %(os.path.join(projPathAtRemoteAP,'.'+projInfoFileName),move2deleted)
            os.system(move2)
            projInfoLink=os.path.join(os.path.dirname(pathPrefix),'.projInfo',newDeletedName)
            if os.path.exists(projInfoLink):
                os.remove(projInfoLink)
        projPathAtLocal= projPathInfo[9]
        localPathPrefix=projPathInfo[8]
        localMail=projPathAtLocal.replace(os.environ['HOME'],os.path.join(os.environ['HOME'],'mail'),1)
        if pidType=='shared':
           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 "Delete completed. Good-bye."
# 1. update info in projInfo.xml: path of proj changed => projNum  
# 2. update the sym link in /proj/BIOSTAT/Projects/.projInfo/...
# 4. Send emails to all users: 1.notice the moving 2. local files rewrite 3. member's Common file sys link rewrite.
#                                                (member should have full rights for 2 & 3, since they are owned by members.)
# 3. self local file re-link
    
# 1 and 2 start here
currentMemberInfo=[]
try:    
    if pidType_old=='shared': 
        if oldisproj=='yes' and newisproj=='no':
            if os.path.exists(pathAbs_new):
                print "The new project place is not available for using. Choose ohter place to move to."
                sys.exit()
            sponsorId=pwd.getpwuid(os.lstat(pathAbs_old)[4])[0]
            sponsorName=userName(sponsorId)[1]+' '+userName(sponsorId)[2]
            if (os.environ["USER"]==sponsorId):
                iscurrenmember=0
            pathToXML=os.path.join(pathAbs_old,'.common','.proj_info.xml')
            pathToXML_new=os.path.join(pathAbs_new,'.common','.proj_info.xml')
        elif oldisproj=='no' and newisproj=='yes':
            sponsorId=pwd.getpwuid(os.lstat(pathAbs_new)[4])[0]
            sponsorName=userName(sponsorId)[1]+' '+userName(sponsorId)[2]
            if (os.environ["USER"]!=sponsorId):
                iscurrenmember=1
    # also, not allow unjoined member to move project.            
            pathToXML=os.path.join(pathAbs_new,'.common','.proj_info.xml')
            pathToXML_new=os.path.join(pathAbs_new,'.common','.proj_info.xml')
        else:
            if oldisproj=='yes' and newisproj=='yes':  
                print '''%s is an existed project. Please select other project path''' %(pathAbs_new)
Example #7
0
def pathInfo_d(pathRaw):
    import os,sys,pwd,stat
    pathOutput=pathInfo_base(pathRaw)
    pathabs=pathOutput[0]
    pathPrefix=pathOutput[5]
    projName=pathOutput[1]
    secId=pathOutput[6]
    pidType=pathOutput[7]
     
    pathInfo_ks(pathOutput)
    
    folderStatus=0
    if (not os.path.isfile(os.path.join(pathabs,'.proj_info.xml'))) \
        and ((not os.path.isfile(os.path.join(pathabs,'.common','.proj_info.xml'))) \
            and (not os.path.exists(os.path.join(pathabs,'.public')))):       
        print '''%s is not an existed project. \nPlease check.''' %(pathabs)
        folderStatus=1
        sys.exit()
    
    if secId=='BIOSTAT':
        grpName='staff'
        grpId=10   #50  #10   #20
    elif secId=='BIOINFO':
        grpName=secId
        grpId=301     #301  #301
    else: sys.exit("Wrong secId, contact support")
    
    if not os.path.exists(pathPrefix):
        os.makedirs(pathPrefix,mode=0755)           #only needed for private proj
        os.chown(pathPrefix,-1,grpId)
    if (not(grpId in os.getgroups())):
        print "You do not have group permission to write in the path."
        sys.exit()
        
    
    dir0=os.path.dirname(projName)
    dirsRaw=[dir0]
    while dir0!='':
        dir0=os.path.dirname(dir0)
        if dir0!='':
            dirsRaw.append(dir0)
    dirsRaw.sort()
    dirs=tuple(dirsRaw)
    
    for item in dirs:
        dirCurrent=os.path.join(pathPrefix, item)
        if not os.path.exists(dirCurrent):
            print "The proj path does nor exist. Plese verify and try again."
        else:
            if os.path.isfile(os.path.join(dirCurrent,'.proj_info.xml')):
                    print '''%s is an existed project. \nUsing the same name as both project name and project path is not allowed.\nPlease select other project path''' %(dirCurrent)
                    folderStatus=1
                    continue
            if os.path.isfile(os.path.join(dirCurrent,'.common','.proj_info.xml')) \
                    or os.path.exists(os.path.join(dirCurrent,'.public')):
                    print '''%s is an existed project. \nUsing the same name as both project name and project path is not allowed.\nPlease select other project path''' %(dirCurrent)               
                    folderStatus=1
                    continue
                
    folderOwner=pwd.getpwuid(os.lstat(pathabs)[4])[0]
    folderGid=os.stat(pathabs)[5]
    if os.environ["USER"]!=folderOwner:
        if (folderGid!=grpId) or (oct(os.stat(pathabs)[stat.ST_MODE] & 0777)[2]!='7'): 
            userNameInfo=userName(folderOwner)
            print "You do not have permission to write in %s.\nPlease ask %s %s, who is the owner of this folder, to reset permission for you. " %(pathabs,userNameInfo[1],userNameInfo[2])  #grpId and group permission problem ==>exit
            folderStatus=1
            os.exit()
        else:
            if (oct(os.stat(pathabs)[stat.ST_MODE] & 0777)[1:2]!=['7','7']):
                tempstring='chmod ug+rwx \"%s\"' %(dirCurrent)   # inherit group ID in this path
                os.system(tempstring)
            if folderGid!=grpId:
                os.chown(pathabs,-1,grpId)
    if pidType=='private':
        tempstring='chmod -R go=rx \"%s\"' %(pathPrefix) 
        os.system(tempstring)
    
    if folderStatus==1:
        sys.exit()
    else:
        return pathOutput
Example #8
0
def pathInfo(pathRaw):
    import os,sys,pwd,stat
    from userName import userName
    pathOutput=pathInfo_base(pathRaw)
    # Input pathprefix and projName(relative path to pathPrefix)
    # pathInfo: pathOutput=(pathAbs,projName,projNameA,projNameP,projNameAP,pathPrefix,secId,pidType,localPathPrefix,projPathAtLocal)
    #                          0       1         2        3         4           5         6    7            8             9
    #                                                                                                      -2            -1
    pathabs=pathOutput[0]
    pathPrefix=pathOutput[5]
    projName=pathOutput[1]
    secId=pathOutput[6]
    pidType=pathOutput[7]
    projNameP=pathOutput[3]
    
    folderStatus=0
    if os.path.isfile(os.path.join(pathabs,'.proj_info.xml')):
        print '''%s is an existed project. \nUsing the same name as both project name and project path is not allowed.\nPlease select other project path''' %(pathabs)
        folderStatus=1
        sys.exit()
    if os.path.isfile(os.path.join(pathabs,'.common','.proj_info.xml')) \
        or os.path.exists(os.path.join(pathabs,'.public')):
        print '''%s is an existed project. \nUsing the same name as both project name and project path is not allowed.\nPlease select other project path''' %(pathabs) 
        folderStatus=1
        sys.exit()
    
    if secId=='BIOSTAT':
        grpName='staff'
        grpId=10  #50  #10   #20
    elif secId=='BIOINFO':
        grpName=secId
        grpId=301     #301  #301
    else: sys.exit("Wrong secId, contact support")
    
    if not os.path.exists(pathPrefix):
        os.makedirs(pathPrefix,mode=0755) 
        os.chown(pathPrefix,-1,grpId)
    if (not(grpId in os.getgroups())):
        print "You do not have group permission to write in the path."
        sys.exit()
        
    
    dir0=os.path.dirname(projName)
    dirsRaw=[dir0]
    while dir0!='':
        dir0=os.path.dirname(dir0)
        if dir0!='':
            dirsRaw.append(dir0)
    dirsRaw.sort()
    dirs=tuple(dirsRaw)
    
    for item in dirs:
        dirCurrent=os.path.join(pathPrefix, item)
        if not os.path.exists(dirCurrent):
            tempstring='mkdir -m0775 \"%s\"' %(dirCurrent) 
            os.system(tempstring)
            os.chown(dirCurrent,-1,grpId)
            tempstring='chmod ug+s \"%s\"' %(dirCurrent)
            os.system(tempstring)
        else:
            if os.path.isfile(os.path.join(dirCurrent,'.proj_info.xml')):
                    print '''%s is an existed project. \nUsing the same name as both project name and project path is not allowed.\nPlease select other project path''' %(dirCurrent)
                    folderStatus=1
                    continue
            if os.path.isfile(os.path.join(dirCurrent,'.common','.proj_info.xml')) \
                    or os.path.exists(os.path.join(dirCurrent,'.public')):
                    print '''%s is an existed project. \nUsing the same name as both project name and project path is not allowed.\nPlease select other project path''' %(dirCurrent)               
                    folderStatus=1
                    continue
            folderOwner=pwd.getpwuid(os.lstat(dirCurrent)[4])[0]
            folderGid=os.stat(dirCurrent)[5]
            if os.environ["USER"]!=folderOwner:
                if (folderGid!=grpId) or (oct(os.stat(dirCurrent)[stat.ST_MODE] & 0777)[2]!='7'): 
                    userNameInfo=userName(folderOwner)
                    print "You do not have permission to write in %s.\nPlease ask %s %s, who is the owner of this folder, to reset permission for you. " %(dirCurrent,userNameInfo[1],userNameInfo[2])  #grpId and group permission problem ==>exit
                    folderStatus=1
                    continue
            else:
                if (oct(os.stat(dirCurrent)[stat.ST_MODE] & 0777)[1:2]!=['7','7']):
                    tempstring='chmod ug+rwx \"%s\"' %(dirCurrent)
                    os.system(tempstring)
                if folderGid!=grpId:
                    os.chown(dirCurrent,-1,grpId)

    if pidType=='shared':
        if secId=='BIOSTAT':
            publicPrefix='/proj/BIOSTAT/Public/.projects'
            projInfoPrefix='/proj/BIOSTAT/Projects/.projInfo'
        elif secId=='BIOINFO':
            publicPrefix='//genomics/Public/.projects'
            projInfoPrefix='//genomics/Projects/.projInfo'
        old_umask=os.umask(0002)    
        if not os.path.exists(publicPrefix):
            os.makedirs(publicPrefix,mode=0775)
            os.chown(publicPrefix,-1,grpId)
        umask_back=os.umask(old_umask)
        pubdirs=os.path.join(publicPrefix,projNameP) 
        dir0=projNameP
        dirsRaw=[dir0]        
        while dir0!='':
            dir0=os.path.dirname(dir0)
            if dir0!='':
                dirsRaw.append(dir0)
        dirsRaw.sort()
        dirs=tuple(dirsRaw)
        prefixs=publicPrefix    
        for item in dirs:
            dirCurrent=os.path.join(prefixs, item)
            if not os.path.exists(dirCurrent):
                tempstring='mkdir -m0775 \"%s\"' %(dirCurrent) 
                os.system(tempstring)
                os.chown(dirCurrent,-1,grpId)   
                tempstring='chmod -R ug+s \"%s\"' %(dirCurrent)  
                os.system(tempstring)
            else:
                folderOwner=pwd.getpwuid(os.lstat(dirCurrent)[4])[0]
                folderGid=os.stat(dirCurrent)[5]
                if os.environ["USER"]!=folderOwner:
                    if (folderGid!=grpId) or (oct(os.stat(dirCurrent)[stat.ST_MODE] & 0777)[2]!='7'): 
                        userNameInfo=userName(folderOwner)
                        print "You do not have permission to write in %s.\nPlease ask %s %s, who is the owner of this folder, to reset permission for you. " %(dirCurrent,userNameInfo[1],userNameInfo[2])  #grpId and group permission problem ==>exit
                        folderStatus=1
                        continue
                else:
                    if (oct(os.stat(dirCurrent)[stat.ST_MODE] & 0777)[1:2]!=['7','7']):
                        tempstring='chmod ug+rwx \"%s\"' %(dirCurrent) 
                        os.system(tempstring)
                    if folderGid!=grpId:
                        os.chown(dirCurrent,-1,grpId) 
                    tempstring='chmod ug+s \"%s\"' %(dirCurrent)
                    os.system(tempstring) 
                        
    if pidType=='private':
        tempstring='chmod -R go=rx \"%s\"' %(pathPrefix) 
        os.system(tempstring)
    
    if folderStatus==1:
        sys.exit()
    else:
        return pathOutput