You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

deploy.py 2.1 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil -*-
  3. # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
  4. # Deploy to NEXUS3/35 with sqlite3 database
  5. import os
  6. import sys
  7. import json
  8. import requests
  9. import base64
  10. DEFAULT_HOST = 'http://172.23.140.35:12345'
  11. DEFAULT_DIR = "/home/data0/map-data"
  12. def img2base64(img_path: str) -> str:
  13. if not os.path.isfile(img_path):
  14. return ''
  15. img_path = os.path.abspath(img_path)
  16. return str(base64.b64encode(open(img_path, 'rb').read()), encoding='utf-8')
  17. if __name__ == '__main__':
  18. if len(sys.argv) < 2:
  19. print("Please provide required directory path of the extracted package.")
  20. sys.exit(0)
  21. dir_path = os.path.abspath(sys.argv[1])
  22. if not os.path.isdir(dir_path):
  23. raise Exception("The first argument is not a valid directory path.")
  24. description = ''
  25. catalog = ''
  26. version = ''
  27. image_base64_str = ''
  28. zh_name = ''
  29. en_name = ''
  30. for item in os.listdir(dir_path):
  31. dpath = os.path.join(dir_path, item)
  32. if os.path.isdir(dpath):
  33. catalog = item
  34. version = os.listdir(dpath)[0]
  35. elif item == 'description':
  36. description = open(dpath).read()
  37. try:
  38. info = json.loads(description)
  39. en_name = info['enName'] if 'enName' in info else ''
  40. zh_name = info['zhName'] if 'zhName' in info else ''
  41. info = info['description'] if 'description' in info else ''
  42. except:
  43. info = description
  44. elif item.endswith('.png'):
  45. image_base64_str = img2base64(dpath)
  46. json_obj = {'version': version,
  47. 'catalog': catalog,
  48. 'description': info,
  49. 'enName': en_name,
  50. 'zhName': zh_name,
  51. 'picture': image_base64_str,
  52. 'value': "{}/{}/{}/".format(DEFAULT_HOST, catalog, version)}
  53. url = "http://172.23.140.35:8888/ns/deploy"
  54. res = requests.post(url, json=json_obj)
  55. res.raise_for_status()