diff --git a/distrib/build_event.py b/distrib/build_event.py index 1c29edb766..7e5c57a9b8 100644 --- a/distrib/build_event.py +++ b/distrib/build_event.py @@ -11,16 +11,20 @@ import time import glob -FILES_URI = "http://code.iki.fi/builds" +BUILD_URI = "http://code.iki.fi/builds" RFC_TIME = "%a, %d %b %Y %H:%M:%S +0000" -if len(sys.argv) != 4: - print 'The arguments must be: (command) (eventdir) (distribdir)' +if len(sys.argv) < 4: + print 'The arguments must be: (command) (eventdir) (distribdir) [localaptdir]' sys.exit(1) EVENT_DIR = sys.argv[2] #/Users/jaakko/Builds DISTRIB_DIR = sys.argv[3] #/Users/jaakko/Projects/deng +if len(sys.argv) > 4: + APT_REPO_DIR = sys.argv[4] +else: + APT_REPO_DIR = '' def git_checkout(ident): @@ -50,13 +54,25 @@ def remote_copy(src, dst): os.system('scp %s %s' % (src, dst)) +def build_timestamp(tag): + path = os.path.join(EVENT_DIR, tag) + oldest = os.stat(path).st_ctime + + for fn in os.listdir(path): + t = os.stat(os.path.join(path, fn)) + if int(t.st_ctime) < oldest: + oldest = int(t.st_ctime) + + return oldest + + def find_newest_build(): newest = None for fn in os.listdir(EVENT_DIR): if fn[:5] != 'build': continue - s = os.stat(os.path.join(EVENT_DIR, fn)) - if newest is None or newest[0] < s.st_ctime: - newest = (s.st_ctime, fn) + bt = build_timestamp(fn) + if newest is None or newest[0] < bt: + newest = (bt, fn) if newest is None: return {'tag': None, 'time': time.time()} return {'tag': newest[1], 'time': newest[0]} @@ -66,14 +82,13 @@ def builds_by_time(): builds = [] for fn in os.listdir(EVENT_DIR): if fn[:5] == 'build': - s = os.stat(os.path.join(EVENT_DIR, fn)) - builds.append((int(s.st_ctime), fn)) + builds.append((build_timestamp(fn), fn)) builds.sort() builds.reverse() return builds -def encoded_build_description(name): +def html_build_description(name, encoded=True): buildDir = os.path.join(EVENT_DIR, name) msg = '' @@ -91,8 +106,16 @@ def encoded_build_description(name): else: s = '' msg += '

%i file%s available:

' else: @@ -102,9 +125,15 @@ def encoded_build_description(name): msg += '

Build Logs

' # Changes. @@ -112,7 +141,9 @@ def encoded_build_description(name): if os.path.exists(chgFn): msg += '

Revisions

' + file(chgFn, 'rt').read() - return '' + if encoded: return '' + + return msg def todays_build_tag(): @@ -192,6 +223,13 @@ def todays_platform_release(): # Copy any new files. remote_copy(os.path.join('releases', n), os.path.join(EVENT_DIR, todays_build_tag(), n)) + + if APT_REPO_DIR: + # Copy also to the appropriate apt directory. + arch = 'i386' + if '_amd64' in n: arch = 'amd64' + remote_copy(os.path.join('releases', n), + os.path.join(APT_REPO_DIR, 'dists/unstable/main/binary-%s' % arch, n)) # Also the build log. remote_copy('buildlog.txt', os.path.join(EVENT_DIR, todays_build_tag(), @@ -202,6 +240,19 @@ def todays_platform_release(): git_checkout('master') +def write_index_html(tag): + f = file(os.path.join(EVENT_DIR, tag, 'index.html'), 'wt') + print >> f, "" + print >> f, "Build %s" % tag[5:] + print >> f, "" + print >> f, "

Build %s

" % tag[5:] + print >> f, "

The build event was started on %s.

" % (time.strftime(RFC_TIME, + time.gmtime(build_timestamp(tag)))) + print >> f, html_build_description(tag, False) + print >> f, "" + print >> f, "" + + def update_feed(): feedName = os.path.join(EVENT_DIR, "events.rss") print "Updating feed in %s..." % feedName @@ -213,24 +264,26 @@ def update_feed(): print >> out, 'Doomsday Engine Builds' print >> out, 'http://dengine.net/' - print >> out, '' + print >> out, '' % BUILD_URI print >> out, 'Automated binary builds of the Doomsday Engine.' print >> out, 'en-us' print >> out, 'skyjake@users.sourceforge.net (Jaakko Keränen)' - print >> out, '%s' % time.strftime(RFC_TIME, + print >> out, '%s' % time.strftime(RFC_TIME, time.gmtime(find_newest_build()['time'])) - print >> out, '%s' % time.strftime(RFC_TIME, time.gmtime()) print >> out, 'dengBot' print >> out, '720' # 12 hours for timestamp, tag in builds_by_time(): print >> out, '' print >> out, 'Build %s' % tag[5:] + print >> out, '%s/%s/' % (BUILD_URI, tag) print >> out, 'skyjake@users.sourceforge.net (skyjake)' print >> out, '%s' % time.strftime(RFC_TIME, time.gmtime(timestamp)) - print >> out, '%s' % encoded_build_description(tag) + print >> out, '%s' % html_build_description(tag) print >> out, '%s' % tag print >> out, '' + + write_index_html(tag) # Close. print >> out, '' @@ -238,37 +291,16 @@ def update_feed(): def rebuild_apt_repository(): - aptDir = os.path.join(EVENT_DIR, 'apt') + aptDir = APT_REPO_DIR print 'Rebuilding the apt repository in %s...' % aptDir - # Empty the apt directory. - if os.path.exists(aptDir): - shutil.rmtree(aptDir, True) - os.mkdir(aptDir) - - # Copy the packages (preserving metadata). - binDir = os.path.join(aptDir, 'binary') - os.mkdir(binDir) - for timestamp, tag in builds_by_time(): - for debName in glob.glob(os.path.join(EVENT_DIR, tag, '*.deb')): - shutil.copy2(debName, os.path.join(binDir, os.path.basename(debName))) - - # Generate the apt package index. - distsDir = os.path.join(aptDir, 'dists/unstable/main/binary-i386') - os.makedirs(distsDir) - os.chdir(aptDir) - os.system("dpkg-scanpackages -a i386 binary /dev/null > %s" % os.path.join(distsDir, 'Packages')) - os.chdir(distsDir) - os.system("gzip -9 Packages") - - f = file('Release', 'wt') - print >> f, 'Archive: unstable' - print >> f, 'Component: main' - print >> f, 'Origin: skyjake@users.sourceforge.net' - print >> f, 'Label: Automated Doomsday Engine Builds' - print >> f, 'Architecture: i386' - f.close() - + os.system("apt-ftparchive generate ~/Dropbox/APT/ftparchive.conf") + os.system("apt-ftparchive -c ~/Dropbox/APT/ftparchive-release.conf release %s/dists/unstable > %s/dists/unstable/Release" % (aptDir, aptDir)) + os.chdir("%s/dists/unstable" % aptDir) + os.remove("Release.gpg") + os.system("gpg --output Release.gpg -ba Release") + os.system("~/Dropbox/Scripts/mirror-tree.py %s %s" % (aptDir, os.path.join(EVENT_DIR, 'apt'))) + if sys.argv[1] == 'create': create_build_event()