remote: HTTP implemented (support only for downloading) (#1350)

* 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
This commit is contained in:
Mr. Outis
2018-11-24 21:22:05 +02:00
committed by Ruslan Kuprieiev
parent f3f5837e20
commit 1e3d752917
14 changed files with 354 additions and 34 deletions
+35
View File
@@ -0,0 +1,35 @@
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()