def main(): dirFile = open('oldDirectories.txt') for dir in dirFile.readlines(): destDir = dir.replace('/mvista/dev_area', '/mvista/dev_area/removal').replace('\n', '') if destDir[len(destDir) - 1] == "/": buildIndex = destDir[0:-1].rindex("/") else: buildIndex = destDir.rindex("/") # if False: # print "**" # print "" # print 'dir - %s' % dir # print 'sudo mkdir -p ' + dir.replace('/mvista/dev_area' , '/mvista/dev_area/removal') # print "sudo mv %s" % (dir) + ' ' + destDir[0:buildIndex] # print "**" # print "" cmd = dir + ' ' + destDir[0:buildIndex] cmd = cmd.replace("\n", "") #system('sudo mkdir -p ' + dir.replace('/mvista/dev_area' , '/mvista/dev_area/removal') ) retentionLog.logInfo("Deleting Build %s" % dir) if "RELEASED_by_buildtag" not in dir: lt_os.system("sudo rm -rf %s" % dir, False)
def warningMessage(): lt_os.system( '/home/build/build_scripts/utils/findOldDirs.py > /home/build/build_scripts/utils/trashed_dirs', True) try: removal_list = open('/home/build/build_scripts/utils/trashed_dirs') except: sys.stderr.write('Failure Encountered while opening Trash listings\n') sys.exit(1) warning_message = "Build will be removing stuff from dev_area in two days \n\n\n" warning_subject = "TEST TEST Build will delete stuff in two days" for line in removal_list: warning_message += line #Standard SMTP SETUP smtpObject = smtplib.SMTP() mailMsg = MIMEText(warning_message) mailMsg['From'] = sender mailMsg['To'] = destinationEmail #Change to engr at some point mailMsg['Subject'] = warning_subject #Send Message smtpObject.connect(smtpServer) # print "OMG MAIL BEING SENT!" smtpObject.sendmail(sender, destinationEmail, mailMsg.as_string()) smtpObject.close() return
def cleanupLogs(): regexp = re.compile(r"/.*/(.*\d+_\d+).*") removalDirs = open("oldDirectories.txt", "r") for line in removalDirs.readlines(): if "RELEASED_by_buildtag" not in line: extracted = regexp.match(line) lt_os.system ("sudo rm -rf /export/logs/" + extracted.group(1), False)
def printBuildsMenu(): while True: print """ [1] Scan for old directories, saving list to oldDirectories.txt. [2] Read directories from oldDirectories.txt and email a warning. [3] Move directories to /dev_area/removal [4] Delete logs. [5] Sync Database. [6] Back """ input = raw_input("Your Choice: ") if input == '1': cls() dbi.dumpAllKeepers() lt_os.system('./findOldDirs.py > oldDirectories.txt', True) lt_os.system( './findDirs.py --path /mvista/dev_area/foundation >> oldDirectories.txt', True) cls() print "Old non-exempt directories written to oldDirectories.txt" elif input == '2': cls() sendEmail() print "Email sent to [email protected]." elif input == '3': cls() moveDirs.main() elif input == '4': cleanup.cleanupLogs() elif input == '5': cleanup.cleanupDB() elif input == '6': cls() printMainMenu()
#!/usr/bin/env python import sys, os, DBInteraction, moveDirs, cleanup,lt_os dbi = DBInteraction if __name__ in ['__main__']: dbi.testDB() #Sync DB with Bugz dbi.removeAllBugz() dbi.addBugzToDB() dbi.repopulateDB() #Write the kept builds to /tmp/KEEPERS for legacy findOldDirs.py script. dbi.dumpAllKeepers() #Run legacy script! lt_os.system('./findOldDirs.py > oldDirectories.txt', True) lt_os.system('./findDirs.py --path /mvista/dev_area/foundation >> oldDirectories.txt', True) moveDirs.main() cleanup.cleanupLogs() cleanup.cleanupDB()
def moveToRemoval(): lt_os.system( '/home/build/build_scripts/utils/findOldDirs.py > /home/build/build_scripts/utils/trashed_dirs', True) try: removal_list = open('/home/build/build_scripts/utils/trashed_dirs') except: sys.stderr.write('Failure Encounters while opening Trash listings\n') sys.exit(1) #Our regular expression for parsing, the third and fourth portions of the directory name are the most important, they tell us #the product as well as the type of thing we're moving: log, cdimage, async #/mvista/dev_area/<product>/<type> #we have to be careful with type, type can end up being: async, logs, cdimages #If we get a cdimages, we have to check more to see if its async cdimages #logs also don't follow the standard. If the bottom part is confusing as all hell that's the reason why msg = "These directories have been removed from /mvista/dev_area\n\n\n" parser = re.compile(r'/mvista/dev_area/(.+)/(.+)/') buildtagRegEx = re.compile(r'.+\d\d\d\d\d\d_\d+') for removalDir in removal_list: parsed = parser.match(removalDir) if parsed: #find out the product: cge, foundation, pro, tsuki, etc product = parsed.group(1) #Simple case: buildtag if buildtagRegEx.match(parsed.group(2)): removeLocation = '/mvista/dev_area/%s/REMOVE/build/' % ( product) #Found: async elif parsed.group(2) == 'async': removeLocation = '/mvista/dev_area/%s/REMOVE/async/' % ( product) #Found: cdimages elif parsed.group(2) == 'cdimages': removeLocation = '/mvista/dev_area/%s/REMOVE/cdimages/' % ( product) #Found: logs elif parsed.group( 2 ) == 'logs': #if we're here we know its not an async so this one is easy removeLocation = '/mvista/dev_area/%s/REMOVE/logs/' % (product) else: print "NO MATCH: %s" % removalDir removeLocation = None if DEBUG: if removeLocation != None: print "mkdir -p %s" % removeLocation print "mv %s %s" % (string.strip(removalDir), removeLocation) else: if removeLocation != None: lt_os.system("mkdir -p %s" % removeLocation, False) lt_os.system( "mv %s %s" % (string.strip(removalDir), removeLocation), False) parsed = None #Add to email message msg += removalDir #This should already have the newline in it, so im not gonna mess with it #Send email of removed Directories: if DEBUG: print "Sending email..." print msg else: smtpObject = smtplib.SMTP() mailMsg = MIMEText(msg) mailMsg['From'] = sender mailMsg['To'] = destinationEmail mailMsg['Subject'] = '/mvista/dev_area/ Cleanup list' #Send Message smtpObject.connect(smtpServer) smtpObject.sendmail(sender, destinationEmail, mailMsg.as_string()) smtpObject.close()
def deleteRemovalDirs(): lt_os.system('rm -rf `find | grep REMOVE`', False)