define some parameters, add preamble to partial scripts

This commit is contained in:
2016-05-14 20:26:18 +01:00
parent 878ef2ecd9
commit f12b0e82af

View File

@@ -2,9 +2,14 @@ import sys
import os
import re
# Arguments
file = sys.argv[1]
docker = open(sys.argv[2], 'a')
tmp = sys.argv[3]
# Parameters
tmp = '/build/tmp'
config = '/build/config'
shell = '/bin/bash'
# Remove all normal comments
path = '{}/build/scripts/{}.sh'.format(os.environ['DOCKER_HOME'], file)
@@ -16,18 +21,23 @@ for line in open(path):
# Split on comments starting with ##
parts = re.split('## .*', contents)
first = parts.pop(0).strip()
first = '''\
#!{}
set -ex
source {}
'''.format(shell, config)
# Iterate over parts, except header
i = 0
for part in parts:
if len(part) > 0:
i += 1
# Add reading environment variables
extra = '' if file == 'prepare' else 'export_container_environment\n'
# Write parts file
contents = '{}\n{}{}'.format(first, extra, part)
contents = '{}{}{}'.format(first, extra, part)
partfile = '{}_{}.sh'.format(file, i)
path = '{}/build/parts/{}'.format(os.environ['DOCKER_HOME'], partfile)
open(path, 'w').write(contents)