mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 15:28:27 +01:00
* remote: HTTP implemented (support only for downloading) * Remove duplicated content in the schema * Chomp trailing spaces in test_remote * remote http: Implement pull/fetch * add some tests * Update dvc/remote/http.py Co-Authored-By: mroutis <[email protected]> * Update dvc/remote/http.py Co-Authored-By: mroutis <[email protected]> * correct test * rehprase error message * add __init__ for utils * try to fix windows test
36 lines
1022 B
Python
36 lines
1022 B
Python
import hashlib
|
|
import os
|
|
import threading
|
|
|
|
try:
|
|
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
except ImportError:
|
|
from BaseHTTPServer import HTTPServer
|
|
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
|
|
|
|
|
class ETagHandler(SimpleHTTPRequestHandler):
|
|
def end_headers(self):
|
|
file = self.translate_path(self.path)
|
|
|
|
if not os.path.isdir(file) and os.path.exists(file):
|
|
with open(file, 'r') as fd:
|
|
etag = hashlib.md5(fd.read().encode('utf8')).hexdigest()
|
|
self.send_header('ETag', etag)
|
|
|
|
SimpleHTTPRequestHandler.end_headers(self)
|
|
|
|
|
|
class StaticFileServer():
|
|
def __init__(self):
|
|
self.httpd = HTTPServer(('localhost', 8000), ETagHandler)
|
|
|
|
def __enter__(self):
|
|
self.server_thread = threading.Thread(target=self.httpd.serve_forever)
|
|
self.server_thread.daemon = True
|
|
self.server_thread.start()
|
|
|
|
def __exit__(self, *args):
|
|
self.httpd.shutdown()
|
|
self.httpd.server_close()
|