Skip to content

Commit

Permalink
Builds: Clean up empty directories during purge
Browse files Browse the repository at this point in the history
If an event directory becomes empty it gets deleted.
  • Loading branch information
skyjake committed May 30, 2011
1 parent d5f5771 commit 28ef01e
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions distrib/build_event.py
Expand Up @@ -92,6 +92,24 @@ def find_old_builds(atLeastSecs):
result.append({'time':bt, 'tag':fn})
return result


def find_empty_events(baseDir=None):
result = []
if not baseDir: baseDir = EVENT_DIR
print 'Finding empty subdirs in', baseDir
for fn in os.listdir(baseDir):
path = os.path.join(baseDir, fn)
if os.path.isdir(path):
# Is this an empty directory?
empty = True
for c in os.listdir(path):
if c != '.' and c != '..':
empty = False
break
if empty:
result.append(path)
return result


def builds_by_time():
builds = []
Expand Down Expand Up @@ -449,10 +467,8 @@ def rebuild_apt_repository():


def purge_apt_repository(atLeastSeconds):
aptDir = os.path.join(APT_REPO_DIR, 'dists/unstable/main/binary-')
dirs = ['i386', 'amd64']
for d in dirs:
binDir = aptDir + d
for d in ['i386', 'amd64']:
binDir = os.path.join(APT_REPO_DIR, 'dists/unstable/main/binary-') + d
print 'Pruning binary apt directory', binDir
# Find the old files.
for fn in os.listdir(binDir):
Expand All @@ -476,9 +492,19 @@ def purge_obsolete():
for bld in find_old_builds(threshold):
print bld['tag']
shutil.rmtree(os.path.join(EVENT_DIR, bld['tag']))

print 'Purge done.'


def dir_cleanup():
print 'Event directory cleanup starting...'
# Purge empty event directories.
for bp in find_empty_events():
print 'Deleting', bp
os.rmdir(bp)
print 'Cleanup done.'


if sys.argv[1] == 'create':
create_build_event()

Expand All @@ -497,6 +523,9 @@ def purge_obsolete():
elif sys.argv[1] == 'purge':
purge_obsolete()

elif sys.argv[1] == 'cleanup':
dir_cleanup()

else:
print 'Unknown command:', sys.argv[1]
sys.exit(1)

0 comments on commit 28ef01e

Please sign in to comment.