ソースを参照

serve.py initial: mock pepmda.zip server to be used with env ENIGMAIL_PEP_DOWNLOAD_URL

master
arian.sanusi@pep.foundation Arian Sanusi (p≡p Foundation) 2年前
コミット
10e36b1b51
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 49B08FCFF6BC3B2
2個のファイルの変更73行の追加0行の削除
  1. +2
    -0
      Makefile
  2. +71
    -0
      serve.py

+ 2
- 0
Makefile ファイルの表示

@@ -91,3 +91,5 @@ build/enigmail-$(ENIG_ID_DARWIN).xpi build/enigmail-$(ENIG_ID_WIN).xpi build/eni
$(MAKE) -C enigmail
cp enigmail/build/enigmail-2.0.xpi $@

serve:
common/serve.py

+ 71
- 0
serve.py ファイルの表示

@@ -0,0 +1,71 @@
#!/usr/bin/python3

from http.server import HTTPServer, BaseHTTPRequestHandler
from hashlib import sha256
import re
import os, os.path
import sys

{"url": "", "hash": "", "pepVersion": ""}

def sha256sum(fd):
if isinstance(fd,str):
fd = open(fd,'rb')
return sha256(fd.read()).hexdigest()

class pepmda_handler(BaseHTTPRequestHandler):
'''dummy getPepDownload.svc'''

def do_HEAD(s):
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()

def do_GET(s):
s.send_response(200)

print(s.path)
if s.path[1:] == pepmda:
s.send_header("Content-type", "application/zip")
s.end_headers()
s.wfile.write(open(pepmda_path,'rb').read())

else:
s.send_header("Content-type", "text/html")
s.end_headers()
s.wfile.write(str.encode('{"url": "http://localhost:%i/%s", "hash": "%s", "pepVersion": ""}'%(port,pepmda,pepmda_hash)))


if __name__ == '__main__':
try:
open(sys.argv[1])

except IndexError:
# try to find pepmda where it's put by build system
buildd = os.path.join(os.environ['HOME'],'build')
for i in os.listdir(buildd):
if re.match(r'^enigmail-.*zip$',i):
pepmda = i
pepmda_path = os.path.join(buildd,i)
break
else:
print('no pepmda found, exiting')
exit(1)

except FileNotFoundError:
print('given path does not exist, exiting')
exit(1)

else:
pepmda_path = sys.argv[1]
pepmda = os.path.basename(pepmda_path)

try:
port = int(sys.argv[2])
except IndexError:
port = 8000

httpd = HTTPServer(('localhost', port), pepmda_handler)
pepmda_hash = sha256sum(pepmda_path)
httpd.serve_forever()


読み込み中…
キャンセル
保存