ari's enigmail/pEp-on-linux build system this _also_ lives in https://pep.foundation/dev/repos/enigmailpEp/ in linux
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8KB

  1. #!/usr/bin/python3
  2. from http.server import HTTPServer, BaseHTTPRequestHandler
  3. from hashlib import sha256
  4. import re
  5. import os, os.path
  6. import sys
  7. {"url": "", "hash": "", "pepVersion": ""}
  8. def sha256sum(fd):
  9. if isinstance(fd,str):
  10. fd = open(fd,'rb')
  11. return sha256(fd.read()).hexdigest()
  12. class pepmda_handler(BaseHTTPRequestHandler):
  13. '''dummy getPepDownload.svc'''
  14. def do_HEAD(s):
  15. s.send_response(200)
  16. s.send_header("Content-type", "text/html")
  17. s.end_headers()
  18. def do_GET(s):
  19. s.send_response(200)
  20. print(s.path)
  21. if s.path[1:] == pepmda:
  22. s.send_header("Content-type", "application/zip")
  23. s.end_headers()
  24. s.wfile.write(open(pepmda_path,'rb').read())
  25. else:
  26. s.send_header("Content-type", "text/html")
  27. s.end_headers()
  28. s.wfile.write(str.encode('{"url": "http://localhost:%i/%s", "hash": "%s", "pepVersion": ""}'%(port,pepmda,pepmda_hash)))
  29. if __name__ == '__main__':
  30. try:
  31. open(sys.argv[1])
  32. except IndexError:
  33. # try to find pepmda where it's put by build system
  34. buildd = os.path.join(os.environ['HOME'],'build')
  35. for i in os.listdir(buildd):
  36. if re.match(r'^enigmail-.*zip$',i):
  37. pepmda = i
  38. pepmda_path = os.path.join(buildd,i)
  39. break
  40. else:
  41. print('no pepmda found, exiting')
  42. exit(1)
  43. except FileNotFoundError:
  44. print('given path does not exist, exiting')
  45. exit(1)
  46. else:
  47. pepmda_path = sys.argv[1]
  48. pepmda = os.path.basename(pepmda_path)
  49. try:
  50. port = int(sys.argv[2])
  51. except IndexError:
  52. port = 8000
  53. httpd = HTTPServer(('localhost', port), pepmda_handler)
  54. pepmda_hash = sha256sum(pepmda_path)
  55. httpd.serve_forever()