00001
00002
00003
00004
00005
00006 HUDSON_APTCACHECLEANUP_CONFIG = """<?xml version='1.0' encoding='UTF-8'?>
00007 <project>
00008 <description>aptcache cleanup for MACHINEID</description>
00009 <logRotator>
00010 <daysToKeep>5</daysToKeep>
00011 <numToKeep>-1</numToKeep>
00012 </logRotator>
00013 <keepDependencies>false</keepDependencies>
00014 <properties>
00015 <hudson.plugins.trac.TracProjectProperty>
00016 <tracWebsite>http://code.ros.org/trac/ros/</tracWebsite>
00017 </hudson.plugins.trac.TracProjectProperty>
00018 </properties>
00019 <assignedNode>MACHINEID</assignedNode>
00020 <canRoam>false</canRoam>
00021 <disabled>false</disabled>
00022 <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
00023 <triggers class="vector">
00024 <hudson.triggers.TimerTrigger>
00025 <spec>TIME_TRIGGER</spec>
00026 </hudson.triggers.TimerTrigger>
00027 </triggers>
00028 <concurrentBuild>false</concurrentBuild>
00029 <builders>
00030 <hudson.tasks.Shell>
00031 <command>cat > $WORKSPACE/script.py <<DELIM
00032 #!/usr/bin/env python
00033
00034 import os
00035 import shutil
00036
00037 def get_dir_size(start_path):
00038 if not os.path.isdir(path):
00039 return 0
00040 total_size = 0
00041 for dirpath, dirnames, filenames in os.walk(start_path):
00042 for f in filenames:
00043 fp = os.path.join(dirpath, f)
00044 total_size += os.path.getsize(fp)
00045
00046 return total_size
00047
00048 distros = ['jaunty', 'karmic', 'lucid', 'maverick', 'natty']
00049 arches = ['i386', 'amd64']
00050
00051 for d in distros:
00052 for a in arches:
00053 path = os.path.join('/home/rosbuild/aptcache', '%s-%s'%(d,a))
00054 gigs = get_dir_size(path)/1024/1024/1024.0
00055 print path, gigs
00056 if gigs > 5.0: # if more than 5 gigs used clear it
00057 print "deleting %s"%path
00058 shutil.rmtree(path) # destroy whole tree
00059 os.makedirs(path) #restore empty directory after deleting it
00060
00061
00062 DELIM
00063
00064 set -o errexit
00065
00066 python $WORKSPACE/script.py
00067 </command>
00068 </hudson.tasks.Shell>
00069 </builders>
00070 <publishers>
00071 <hudson.tasks.BuildTrigger>
00072 <childProjects>JOB_CHILDREN</childProjects>
00073 <threshold>
00074 <name>SUCCESS</name>
00075 <ordinal>0</ordinal>
00076 <color>BLUE</color>
00077 </threshold>
00078 </hudson.tasks.BuildTrigger>
00079 <hudson.plugins.emailext.ExtendedEmailPublisher>
00080 <recipientList>EMAIL</recipientList>
00081 <configuredTriggers>
00082 <hudson.plugins.emailext.plugins.trigger.UnstableTrigger>
00083 <email>
00084 <recipientList></recipientList>
00085 <subject>$PROJECT_DEFAULT_SUBJECT</subject>
00086 <body>$PROJECT_DEFAULT_CONTENT</body>
00087 <sendToDevelopers>true</sendToDevelopers>
00088 <sendToRecipientList>true</sendToRecipientList>
00089 <contentTypeHTML>false</contentTypeHTML>
00090 <script>true</script>
00091 </email>
00092 </hudson.plugins.emailext.plugins.trigger.UnstableTrigger>
00093 <hudson.plugins.emailext.plugins.trigger.FailureTrigger>
00094 <email>
00095 <recipientList></recipientList>
00096 <subject>$PROJECT_DEFAULT_SUBJECT</subject>
00097 <body>$PROJECT_DEFAULT_CONTENT</body>
00098 <sendToDevelopers>true</sendToDevelopers>
00099 <sendToRecipientList>true</sendToRecipientList>
00100 <contentTypeHTML>false</contentTypeHTML>
00101 <script>true</script>
00102 </email>
00103 </hudson.plugins.emailext.plugins.trigger.FailureTrigger>
00104 <hudson.plugins.emailext.plugins.trigger.StillFailingTrigger>
00105 <email>
00106 <recipientList></recipientList>
00107 <subject>$PROJECT_DEFAULT_SUBJECT</subject>
00108 <body>$PROJECT_DEFAULT_CONTENT</body>
00109 <sendToDevelopers>true</sendToDevelopers>
00110 <sendToRecipientList>true</sendToRecipientList>
00111 <contentTypeHTML>false</contentTypeHTML>
00112 <script>true</script>
00113 </email>
00114 </hudson.plugins.emailext.plugins.trigger.StillFailingTrigger>
00115 <hudson.plugins.emailext.plugins.trigger.FixedTrigger>
00116 <email>
00117 <recipientList></recipientList>
00118 <subject>$PROJECT_DEFAULT_SUBJECT</subject>
00119 <body>$PROJECT_DEFAULT_CONTENT</body>
00120 <sendToDevelopers>true</sendToDevelopers>
00121 <sendToRecipientList>true</sendToRecipientList>
00122 <contentTypeHTML>false</contentTypeHTML>
00123 <script>true</script>
00124
00125 </email>
00126 </hudson.plugins.emailext.plugins.trigger.FixedTrigger>
00127 <hudson.plugins.emailext.plugins.trigger.StillUnstableTrigger>
00128 <email>
00129 <recipientList></recipientList>
00130 <subject>$PROJECT_DEFAULT_SUBJECT</subject>
00131 <body>$PROJECT_DEFAULT_CONTENT</body>
00132 <sendToDevelopers>true</sendToDevelopers>
00133 <sendToRecipientList>true</sendToRecipientList>
00134 <contentTypeHTML>false</contentTypeHTML>
00135 <script>true</script>
00136 </email>
00137 </hudson.plugins.emailext.plugins.trigger.StillUnstableTrigger>
00138 </configuredTriggers>
00139 <defaultSubject>$DEFAULT_SUBJECT</defaultSubject>
00140 <defaultContent>$DEFAULT_CONTENT</defaultContent>
00141 <defaultContentTypeHTML>false</defaultContentTypeHTML>
00142 <defaultContentIsScript>true</defaultContentIsScript>
00143 </hudson.plugins.emailext.ExtendedEmailPublisher>
00144 </publishers>
00145 <buildWrappers/>
00146 </project>
00147 """
00148
00149 import roslib; roslib.load_manifest("job_generation")
00150 from job_generation.jobs_common import *
00151 import hudson
00152 import urllib
00153 import optparse
00154 import yaml
00155
00156
00157 MACHINEIDS = ['bf1', 'bf2', 'bf3', 'bf4-wgsf6', 'bf5-wgsf7']
00158
00159 def aptcachecleanup_job_name(machineid):
00160 return "-".join(['debbuild-aptcachecleanup', machineid])
00161
00162
00163 def create_aptcachecleanup_configs():
00164
00165
00166 configs = {}
00167 for machine in MACHINEIDS:
00168 name = aptcachecleanup_job_name(machine)
00169
00170 time_trigger = '1 2 * * *'
00171 job_children = ''
00172
00173 hudson_config = HUDSON_APTCACHECLEANUP_CONFIG
00174 hudson_config = hudson_config.replace('TIME_TRIGGER', time_trigger)
00175 hudson_config = hudson_config.replace('JOB_CHILDREN', job_children)
00176 hudson_config = hudson_config.replace('MACHINEID', machine)
00177 hudson_config = hudson_config.replace('EMAIL', 'tfoote+aptcachecleanup_debs@willowgarage.com')
00178 configs[name] = hudson_config
00179 return configs
00180
00181
00182
00183
00184 def main():
00185 parser = optparse.OptionParser()
00186 parser.add_option('--delete', dest = 'delete', default=False, action='store_true',
00187 help='Delete jobs from Hudson')
00188 (options, args) = parser.parse_args()
00189
00190
00191
00192 info = urllib.urlopen(CONFIG_PATH).read().split(',')
00193 hudson_instance = hudson.Hudson(SERVER, info[0], info[1])
00194
00195
00196 print 'Creating aptcachecleanup Hudson jobs:'
00197 aptcachecleanup_configs = create_aptcachecleanup_configs()
00198
00199 for job_name in aptcachecleanup_configs:
00200 exists = hudson_instance.job_exists(job_name)
00201
00202
00203 if options.delete and exists:
00204 print "Deleting job %s"%job_name
00205 hudson_instance.delete_job(job_name)
00206
00207
00208 elif exists:
00209 print " - %s"%job_name
00210 hudson_instance.reconfig_job(job_name, aptcachecleanup_configs[job_name])
00211
00212
00213 elif not exists:
00214 print " - %s"%job_name
00215 hudson_instance.create_job(job_name, aptcachecleanup_configs[job_name])
00216
00217
00218
00219 if __name__ == '__main__':
00220 main()
00221
00222
00223
00224