#!/usr/bin/env python
import os
import stat
import config

TEMPLATE_FILE = 'powerline-shell.py.template'
OUTPUT_FILE = 'powerline-shell.py'
SEGMENTS_DIR = 'segments'
THEMES_DIR = 'themes'

def load_source(srcfile):
    try:
        return ''.join(open(srcfile).readlines()) + '\n\n'
    except IOError:
        print 'Could not open', srcfile
        return ''

if __name__ == "__main__":
    try:
        with open('config.py'): pass
    except IOError:
        print 'Please copy config.py.dist to config.py and retry.'
        exit(1)
    source = load_source(TEMPLATE_FILE)
    source += load_source(os.path.join(THEMES_DIR, config.THEME + '.py'))
    for segment in config.SEGMENTS:
        source += load_source(os.path.join(SEGMENTS_DIR, segment + '.py'))
    source += 'sys.stdout.write(powerline.draw())\n'

    try:
        open(OUTPUT_FILE, 'w').write(source)
        st = os.stat(OUTPUT_FILE)
        os.chmod(OUTPUT_FILE, st.st_mode | stat.S_IEXEC)
        print OUTPUT_FILE, 'saved successfully'
    except IOError:
        print 'ERROR: Could not write to powerline-shell.py. Make sure it is writable'

#!/usr/bin/env python
import os
import stat
import config
import shutil

TEMPLATE_FILE = 'powerline-shell.py.template'
OUTPUT_FILE = 'powerline-shell.py'
SEGMENTS_DIR = 'segments'
THEMES_DIR = 'themes'

def load_source(srcfile):
    try:
        return ''.join(open(srcfile).readlines()) + '\n\n'
    except IOError:
        print 'Could not open', srcfile
        return ''

if __name__ == "__main__":
    try:
        with open('config.py'): pass
    except IOError:
        print 'Created personal config.py for your customizations'
        shutil.copyfile('config.py.dist', 'config.py')
    source = load_source(TEMPLATE_FILE)
    source += load_source(os.path.join(THEMES_DIR, config.THEME + '.py'))
    for segment in config.SEGMENTS:
        source += load_source(os.path.join(SEGMENTS_DIR, segment + '.py'))
    source += 'sys.stdout.write(powerline.draw())\n'

    try:
        open(OUTPUT_FILE, 'w').write(source)
        st = os.stat(OUTPUT_FILE)
        os.chmod(OUTPUT_FILE, st.st_mode | stat.S_IEXEC)
        print OUTPUT_FILE, 'saved successfully'
    except IOError:
        print 'ERROR: Could not write to powerline-shell.py. Make sure it is writable'
        exit(1)

Create a config.py rather than having people do it manually.
Create a config.py rather than having people do it manually.
