Support version builds by name
parent
f8ec81de4b
commit
97b69409b6
|
@ -1,13 +1,21 @@
|
|||
#! /usr/bin/env bash
|
||||
# Args: <source> <version> <script> <args...>
|
||||
|
||||
VERSION_ARGS=()
|
||||
|
||||
if [ -z "$VERSIONS_OUT" ]
|
||||
then
|
||||
VERSIONS_OUT=".sources"
|
||||
fi
|
||||
VERSION_ARGS=("${VERSION_ARGS[@]}" "-f" "$VERSIONS_OUT")
|
||||
|
||||
if [ -n "$VERSIONS_NAMES" ]
|
||||
then
|
||||
VERSION_ARGS=("${VERSION_ARGS[@]}" "-n" "$VERSIONS_NAMES")
|
||||
fi
|
||||
|
||||
mkdir -p ".sources" &&
|
||||
while read i
|
||||
do
|
||||
"$3" "$i" "${@:4}" || exit "$?"
|
||||
done < <("$(dirname "$0")/versions.py" -Lf "$VERSIONS_OUT" "$1" "$2")
|
||||
done < <("$(dirname "$0")/versions.py" -L "${VERSION_ARGS[@]}" "$1" "$2")
|
||||
|
|
49
versions.py
49
versions.py
|
@ -13,6 +13,7 @@ if __name__ == "__main__":
|
|||
parser.add_argument("-f", "--files", dest="files", type=str, nargs="?", default=".", help="The target directory to save the generated scripts in. Default: \".\"")
|
||||
parser.add_argument("-l", "--list", dest="list", action="store_const", const=True, default=False, help="Output all gerenated file names.")
|
||||
parser.add_argument("-L", "--list-full", dest="list_full", action="store_const", const=True, default=False, help="Like --list with path from --files.")
|
||||
parser.add_argument("-n", "--names", dest="names", type=str, nargs="?", default=None, help="Are csv file with first the name and second the version name.")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Load source file
|
||||
|
@ -27,22 +28,38 @@ if __name__ == "__main__":
|
|||
configEnding = ""
|
||||
|
||||
# Parse versions
|
||||
versions = {}
|
||||
for version_file in args.versions:
|
||||
versions = yaml.load(open(version_file, "r").read(), Loader=yaml.SafeLoader)
|
||||
for version, attributes in versions.items():
|
||||
# Gen config file
|
||||
tmp = fileData.replace("{{VERSION}}", version)
|
||||
for attributeID, attribute in attributes.items():
|
||||
tmp = tmp.replace("{{" + attributeID + "}}", attribute)
|
||||
for iName, iValue in yaml.load(open(version_file, "r").read(), Loader=yaml.SafeLoader).items():
|
||||
versions[iName] = iValue
|
||||
|
||||
# Save file
|
||||
outFileName = "%s_%s%s" % (configStart, version, configEnding)
|
||||
outFile = os.path.join(args.files, outFileName)
|
||||
with open(outFile, "w") as f:
|
||||
f.write(tmp)
|
||||
# Gen mapping
|
||||
mapping = {}
|
||||
if args.names is None:
|
||||
for iName in versions.keys():
|
||||
mapping[iName] = iName
|
||||
else:
|
||||
for i in filter(bool, open(args.names, "r").read().splitlines()):
|
||||
tmp = i.split(",")
|
||||
assert len(tmp) == 2
|
||||
mapping[tmp[0]] = tmp[1]
|
||||
|
||||
# Log output
|
||||
if args.list_full:
|
||||
print(outFile)
|
||||
else:
|
||||
print(outFileName)
|
||||
# Gen build scripts
|
||||
for version_name, version in mapping.items():
|
||||
# Gen config file
|
||||
tmp = fileData.replace("{{VERSION}}", version)
|
||||
tmp = tmp.replace("{{VERSION_NAME}}", version_name)
|
||||
for attributeID, attribute in versions[version].items():
|
||||
tmp = tmp.replace("{{" + attributeID + "}}", attribute)
|
||||
|
||||
# Save file
|
||||
outFileName = "%s_%s%s" % (configStart, version_name, configEnding)
|
||||
outFile = os.path.join(args.files, outFileName)
|
||||
with open(outFile, "w") as f:
|
||||
f.write(tmp)
|
||||
|
||||
# Log output
|
||||
if args.list_full:
|
||||
print(outFile)
|
||||
else:
|
||||
print(outFileName)
|
||||
|
|
Loading…
Reference in New Issue