Use argparse in helper scripts

This commit is contained in:
Pino de Candia 2017-12-29 03:51:54 -06:00
parent 6ea9865b2a
commit 91c0b33338
2 changed files with 24 additions and 5 deletions

View File

@ -11,12 +11,21 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
import argparse
import json
import sys
import yaml
parser = argparse.ArgumentParser(
description='Convert a multi-line cloud-config into static vendor data '
'format\n: {"cloud-init": <single-line cloud-config>}',
formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument('input_file', type=str)
args = parser.parse_args()
# load from file:
with open(sys.argv[1], 'r') as f:
with open(args.input_file, 'r') as f:
yaml_string = f.read()
print json.dumps({"cloud-init":yaml_string})
print json.dumps({"cloud-init": yaml_string})

View File

@ -11,12 +11,22 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
import argparse
import json
import sys
import yaml
parser = argparse.ArgumentParser(
description='Convert a single-line static vendor data file from'
'\n{"cloud-init": <single-line cloud-config>}'
'\nto multi-line cloud-config.',
formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument('input_file', type=str)
args = parser.parse_args()
# load from file:
with open(sys.argv[1], 'r') as f:
with open(args.input_file, 'r') as f:
js = json.loads(f.read())
print js['cloud-init']