Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Side by Side Diff: scripts/slave/slave_utils.py

Issue 9972002: Delete snapshots more than a day old. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/build/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Functions specific to build slaves, shared by several buildbot scripts. 5 """Functions specific to build slaves, shared by several buildbot scripts.
6 """ 6 """
7 7
8 import datetime
9 import glob
8 import inspect 10 import inspect
9 import os 11 import os
10 import re 12 import re
11 import socket 13 import socket
12 import sys 14 import sys
13 import tempfile 15 import tempfile
14 import time 16 import time
15 17
16 from common import chromium_utils 18 from common import chromium_utils
17 from slave import xvfb 19 from slave import xvfb
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 os.remove(full_path) 486 os.remove(full_path)
485 elif os.path.isdir(full_path): 487 elif os.path.isdir(full_path):
486 chromium_utils.RemoveDirectory(full_path) 488 chromium_utils.RemoveDirectory(full_path)
487 else: 489 else:
488 print "Temp item wasn't a file or directory?" 490 print "Temp item wasn't a file or directory?"
489 except OSError, e: 491 except OSError, e:
490 print >> sys.stderr, e 492 print >> sys.stderr, e
491 # Don't fail. 493 # Don't fail.
492 494
493 495
496 def RemoveOldSnapshots(dir):
497 """Removes ChromiumSnapshot files more than one day old. Such snapshots are
498 created when certain tests timeout (e.g., Chrome Frame integration tests)."""
499 # Compute the file prefix of a snapshot created one day ago.
500 yesterday = datetime.datetime.now() - datetime.timedelta(1)
501 old_snapshot = 'ChromiumSnapshot%04d%02d%02d%02d%02d%02d' % \
Marc-Antoine Ruel (Google) 2012/04/14 23:43:55 style nit: I prefer () to \ also we don't put whi
grt (UTC plus 2) 2012/04/17 17:17:24 Thanks, done.
502 ( yesterday.year, yesterday.month, yesterday.day, yesterday.hour,
503 yesterday.minute, yesterday.second )
504 # Collect snapshots at least as old as that one created a day ago.
505 to_delete = []
506 for snapshot in glob.iglob(os.path.join(dir, 'ChromiumSnapshot*.png')):
507 if os.path.basename(snapshot) < old_snapshot:
508 to_delete.append(snapshot)
509 # Delete the collected snapshots.
510 for snapshot in to_delete:
511 print "Removing old snapshot: %s" % snapshot
512 try:
513 os.remove(snapshot)
514 except OSError, e:
515 print >> sys.stderr, e
516
517
494 def RemoveChromeDesktopFiles(): 518 def RemoveChromeDesktopFiles():
495 """Removes Chrome files (i.e. shortcuts) from the desktop of the current user. 519 """Removes Chrome files (i.e. shortcuts) from the desktop of the current user.
496 This does nothing if called on a non-Windows platform.""" 520 This does nothing if called on a non-Windows platform."""
497 if chromium_utils.IsWindows(): 521 if chromium_utils.IsWindows():
498 desktop_path = os.environ['USERPROFILE'] 522 desktop_path = os.environ['USERPROFILE']
499 desktop_path = os.path.join(desktop_path, 'Desktop') 523 desktop_path = os.path.join(desktop_path, 'Desktop')
500 LogAndRemoveFiles(desktop_path, '^(Chromium|chrome) \(.+\)?\.lnk$') 524 LogAndRemoveFiles(desktop_path, '^(Chromium|chrome) \(.+\)?\.lnk$')
525 RemoveOldSnapshots(desktop_path)
501 526
502 527
503 def RemoveChromeTemporaryFiles(): 528 def RemoveChromeTemporaryFiles():
504 """A large hammer to nuke what could be leaked files from unittests or 529 """A large hammer to nuke what could be leaked files from unittests or
505 files left from a unittest that crashed, was killed, etc.""" 530 files left from a unittest that crashed, was killed, etc."""
506 # NOTE: print out what is cleaned up so the bots don't timeout if 531 # NOTE: print out what is cleaned up so the bots don't timeout if
507 # there is a lot to cleanup and also se we see the leaks in the 532 # there is a lot to cleanup and also se we see the leaks in the
508 # build logs. 533 # build logs.
509 # At some point a leading dot got added, support with and without it. 534 # At some point a leading dot got added, support with and without it.
510 kLogRegex = '^\.?(com\.google\.Chrome|org\.chromium)\.' 535 kLogRegex = '^\.?(com\.google\.Chrome|org\.chromium)\.'
(...skipping 15 matching lines...) Expand all
526 if ns_temp_dir: 551 if ns_temp_dir:
527 LogAndRemoveFiles(ns_temp_dir, kLogRegex) 552 LogAndRemoveFiles(ns_temp_dir, kLogRegex)
528 for i in ('Chromium', 'Google Chrome'): 553 for i in ('Chromium', 'Google Chrome'):
529 # Remove dumps. 554 # Remove dumps.
530 crash_path = '%s/Library/Application Support/%s/Crash Reports' % ( 555 crash_path = '%s/Library/Application Support/%s/Crash Reports' % (
531 os.environ['HOME'], i) 556 os.environ['HOME'], i)
532 LogAndRemoveFiles(crash_path, r'^.+\.dmp$') 557 LogAndRemoveFiles(crash_path, r'^.+\.dmp$')
533 else: 558 else:
534 raise NotImplementedError( 559 raise NotImplementedError(
535 'Platform "%s" is not currently supported.' % sys.platform) 560 'Platform "%s" is not currently supported.' % sys.platform)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698