forked from gcgarner/IOTstack
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added YAML merging Python script, with menu script modifications. Add…
…ed minor changes and bug fixes to backup.
- Loading branch information
Slyke
committed
Apr 26, 2020
1 parent
7689228
commit 694778f
Showing
6 changed files
with
113 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,8 @@ | |
/services/ | ||
/volumes/ | ||
/backups/ | ||
/.tmp/* | ||
docker-compose.yml | ||
.outofdate | ||
.outofdate | ||
|
||
!.gitkeep |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
mosquitto: | ||
ports: | ||
- 1882:1882 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
import yaml | ||
|
||
if len(sys.argv) < 4: | ||
print("Error: Not enough args") | ||
print("Usage:") | ||
print(" yaml_merge.py [inputFile] [mergeFile] [outputFile]") | ||
print("") | ||
print("Example:") | ||
print(" yaml_merge.py ./.tmp/docker-compose.tmp.yml ./compose-override.yml ./docker-compose.yml") | ||
sys.exit(1) | ||
|
||
pathTempDockerCompose = sys.argv[1] | ||
pathOverride = sys.argv[2] | ||
pathOutput = sys.argv[3] | ||
|
||
def mergeYaml(priorityYaml, extensionYaml): | ||
if isinstance(priorityYaml,dict) and isinstance(extensionYaml,dict): | ||
for k,v in extensionYaml.iteritems(): | ||
if k not in priorityYaml: | ||
priorityYaml[k] = v | ||
else: | ||
priorityYaml[k] = mergeYaml(priorityYaml[k],v) | ||
return priorityYaml | ||
|
||
with open(r'%s' % pathTempDockerCompose) as fileTempDockerCompose: | ||
yamlTempDockerCompose = yaml.load(fileTempDockerCompose) | ||
|
||
with open(r'%s' % pathOverride) as fileOverride: | ||
yamlOverride = yaml.load(fileOverride) | ||
|
||
mergedYaml = mergeYaml(yamlOverride, yamlTempDockerCompose) | ||
|
||
with open(r'%s' % pathOutput, 'w') as outputFile: | ||
# yaml.dump(mergedYaml, outputFile, default_flow_style=False, sort_keys=False) # TODO: 'sort_keys' not available in this version of Python/yaml | ||
yaml.dump(mergedYaml, outputFile, default_flow_style=False) # Gotta pretty this up for human consumption |