|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #!/usr/bin/env python3
- # -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil -*-
- # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
-
- # Deploy to NEXUS3/35 with sqlite3 database
- import os
- import sys
- import json
- import requests
- import base64
-
-
- DEFAULT_HOST = 'http://172.23.140.35:12345'
- DEFAULT_DIR = "/home/data0/map-data"
-
-
- def img2base64(img_path: str) -> str:
- if not os.path.isfile(img_path):
- return ''
- img_path = os.path.abspath(img_path)
- return str(base64.b64encode(open(img_path, 'rb').read()), encoding='utf-8')
-
-
- if __name__ == '__main__':
- if len(sys.argv) < 2:
- print("Please provide required directory path of the extracted package.")
- sys.exit(0)
-
- dir_path = os.path.abspath(sys.argv[1])
- if not os.path.isdir(dir_path):
- raise Exception("The first argument is not a valid directory path.")
-
- description = ''
- catalog = ''
- version = ''
- image_base64_str = ''
- zh_name = ''
- en_name = ''
-
- for item in os.listdir(dir_path):
- dpath = os.path.join(dir_path, item)
- if os.path.isdir(dpath):
- catalog = item
- version = os.listdir(dpath)[0]
- elif item == 'description':
- description = open(dpath).read()
- try:
- info = json.loads(description)
- en_name = info['enName'] if 'enName' in info else ''
- zh_name = info['zhName'] if 'zhName' in info else ''
- info = info['description'] if 'description' in info else ''
- except:
- info = description
- elif item.endswith('.png'):
- image_base64_str = img2base64(dpath)
- json_obj = {'version': version,
- 'catalog': catalog,
- 'description': info,
- 'enName': en_name,
- 'zhName': zh_name,
- 'picture': image_base64_str,
- 'value': "{}/{}/{}/".format(DEFAULT_HOST, catalog, version)}
- url = "http://172.23.140.35:8888/ns/deploy"
- res = requests.post(url, json=json_obj)
- res.raise_for_status()
|