Skip to content

Commit

Permalink
Merge branch 'master' of ssh://deng.git.sourceforge.net/gitroot/deng/…
Browse files Browse the repository at this point in the history
…deng
  • Loading branch information
skyjake committed Mar 1, 2011
2 parents 919fdf6 + 1308ba5 commit 2204315
Showing 1 changed file with 80 additions and 48 deletions.
128 changes: 80 additions & 48 deletions distrib/build_event.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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]}
Expand All @@ -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 = ''
Expand All @@ -91,8 +106,16 @@ def encoded_build_description(name):
else:
s = ''
msg += '<p>%i file%s available:</p><ul>' % (len(files), s)
for f in files:
msg += '<li><a href="%s/%s/%s">%s</a></li>' % (FILES_URI, name, f, f)
for f in files:
if '.dmg' in f:
platName = "Mac OS X: "
elif '.exe' in f:
platName = "Windows: "
elif '.deb' in f:
platName = "Ubuntu: "
else:
platName = ''
msg += '<li>%s<a href="%s/%s/%s">%s</a></li>' % (platName, BUILD_URI, name, f, f)
msg += '</ul>'

else:
Expand All @@ -102,17 +125,25 @@ def encoded_build_description(name):
msg += '<p><b>Build Logs</b></p><ul>'
for f in glob.glob(os.path.join(buildDir, 'build*txt')):
os.system('gzip -9 %s' % f)
for f in glob.glob(os.path.join(buildDir, 'build*txt.gz')):
f = os.path.basename(f)
msg += '<li><a href="%s/%s/%s">%s</a></li>' % (FILES_URI, name, f, f)
for p in ['darwin', 'win32', 'linux2']:
msg += '<li>%s:' % p
files = glob.glob(os.path.join(buildDir, 'build*%s*txt.gz' % p))
if len(files):
for f in files:
f = os.path.basename(f)
msg += ' <a href="%s/%s/%s">%s</a>' % (BUILD_URI, name, f, f)
else:
msg += ' no logs available.'
msg += '</ul>'

# Changes.
chgFn = os.path.join(buildDir, 'changes.html')
if os.path.exists(chgFn):
msg += '<p><b>Revisions</b></p>' + file(chgFn, 'rt').read()

return '<![CDATA[' + msg + ']]>'
if encoded: return '<![CDATA[' + msg + ']]>'

return msg


def todays_build_tag():
Expand Down Expand Up @@ -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(),
Expand All @@ -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, "<html>"
print >> f, "<head><title>Build %s</title></head>" % tag[5:]
print >> f, "<body>"
print >> f, "<h1>Build %s</h1>" % tag[5:]
print >> f, "<p>The build event was started on %s.</p>" % (time.strftime(RFC_TIME,
time.gmtime(build_timestamp(tag))))
print >> f, html_build_description(tag, False)
print >> f, "</body>"
print >> f, "</html>"


def update_feed():
feedName = os.path.join(EVENT_DIR, "events.rss")
print "Updating feed in %s..." % feedName
Expand All @@ -213,62 +264,43 @@ def update_feed():

print >> out, '<title>Doomsday Engine Builds</title>'
print >> out, '<link>http://dengine.net/</link>'
print >> out, '<atom:link href="http://code.iki.fi/builds/events.rss" rel="self" type="application/rss+xml" />'
print >> out, '<atom:link href="%s/events.rss" rel="self" type="application/rss+xml" />' % BUILD_URI
print >> out, '<description>Automated binary builds of the Doomsday Engine.</description>'
print >> out, '<language>en-us</language>'
print >> out, '<webMaster>skyjake@users.sourceforge.net (Jaakko Keränen)</webMaster>'
print >> out, '<pubDate>%s</pubDate>' % time.strftime(RFC_TIME,
print >> out, '<lastBuildDate>%s</lastBuildDate>' % time.strftime(RFC_TIME,
time.gmtime(find_newest_build()['time']))
print >> out, '<lastBuildDate>%s</lastBuildDate>' % time.strftime(RFC_TIME, time.gmtime())
print >> out, '<generator>dengBot</generator>'
print >> out, '<ttl>720</ttl>' # 12 hours

for timestamp, tag in builds_by_time():
print >> out, '<item>'
print >> out, '<title>Build %s</title>' % tag[5:]
print >> out, '<link>%s/%s/</link>' % (BUILD_URI, tag)
print >> out, '<author>skyjake@users.sourceforge.net (skyjake)</author>'
print >> out, '<pubDate>%s</pubDate>' % time.strftime(RFC_TIME, time.gmtime(timestamp))
print >> out, '<description>%s</description>' % encoded_build_description(tag)
print >> out, '<description>%s</description>' % html_build_description(tag)
print >> out, '<guid isPermaLink="false">%s</guid>' % tag
print >> out, '</item>'

write_index_html(tag)

# Close.
print >> out, '</channel>'
print >> out, '</rss>'


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()
Expand Down

0 comments on commit 2204315

Please sign in to comment.