From fb6561d590b494b25f96489eda89adfad6bd557a Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Mon, 10 Aug 2009 21:01:08 +0200 Subject: Moved mappings from ec2-set-sources-list to ec2init. Moved everything else from ec2-set-sources-list to ec2-set-defaults. Removed call to ec2-set-sources-list from init script. Removed ec2-set-sources-list. --- ec2-set-defaults.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'ec2-set-defaults.py') diff --git a/ec2-set-defaults.py b/ec2-set-defaults.py index f6d6a038..878d4889 100755 --- a/ec2-set-defaults.py +++ b/ec2-set-defaults.py @@ -3,8 +3,8 @@ # Fetch the availabity zone and create the sources.list # Copyright (C) 2008-2009 Canonical Ltd. # -# Author: Chuck Short -# Soren Hansen +# Authors: Chuck Short +# Soren Hansen # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, as @@ -23,31 +23,31 @@ import subprocess import ec2init -def get_location_from_availability_zone(availability_zone): - if availability.startswith('us-'): - return 'us' - elif availability.startswith('eu-'): - return 'eu' - raise Exception('Could not determine location') - -location_archive_map = { - 'us' : 'http://us.ec2.archive.ubuntu.com/ubuntu', - 'eu' : 'http://eu.ec2.archive.ubuntu.com/ubuntu' -} - -location_locale_map = { - 'us' : 'en_US.UTF-8', - 'eu' : 'en_GB.UTF-8' -} - def main(): ec2 = ec2init.EC2Init() - location = get_location_from_availability_zone(ec2.get_availability_zone()) + availability_zone = ec2.get_availability_zone() + location = ec2.get_location_from_availability_zone(availability_zone) + mirror = ec2.get_mirror_from_availability_zone(availability_zone) + + locale = ec2.location_locale_map[location] + apply_locale(locale) + + generate_sources_list(mirror) + +def apply_locale(locale): + subprocess.Popen(['locale-gen', locale]).communicate() + subprocess.Popen(['update-locale', locale]).communicate() + +def generate_sources_list(self, mirror) + stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate() + codename = stdout.strip() - locale = location_locale_map[location] - subprocess.Popen(['locale-gen', locale]).communicate() - subprocess.Popen(['update-locale', locale]).communicate() + mp = { 'mirror' : mirror, 'codename' : codename } + t = Template(file='/etc/ec2-init/templates/sources.list.tmpl', searchList=[mp]) + f = open(SOURCES_LIST, 'w') + f.write(t.respond()) + f.close() if __name__ == '__main__': main() -- cgit v1.2.3