#!/usr/bin/python # Copyright 2012 Paul Wise # Released under the MIT/Expat license, see doc/COPYING # Creates a configuration file for Planet Debian derivatives based on the config # snippets of all the derivatives. # # Usage: # aggregate-planet-config import os import sys from tempfile import NamedTemporaryFile as tempfile derivatives = sys.argv[1:-1] config = sys.argv[-1] try: f = open(config) old_config = f.read() f.close() except IOError: old_config = None new_config = [] for d in derivatives: try: f = open(os.path.join(d,'status')) status = f.read().strip() f.close() if status and status != 'active': continue except IOError: pass try: f = open(os.path.join(d,'planet-config')) new_config.append(f.read()) f.close() except IOError: pass new_config = '\n'.join(new_config) if new_config and new_config != old_config: tmp = tempfile(prefix=config+'.tmp.', dir='', delete=False) tmp.write(new_config) tmp.close() dummy = open(tmp.name+'.dummy','w') dummy.close() os.chmod(tmp.name, os.stat(dummy.name).st_mode) os.remove(dummy.name) os.rename(tmp.name, config)