Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_loader.py
Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | def init(self, swh_storage, datadir, tmp_path): | ||||
) | ) | ||||
destination_path = os.path.join(tmp_path, archive_name) | destination_path = os.path.join(tmp_path, archive_name) | ||||
self.destination_path = destination_path | self.destination_path = destination_path | ||||
with_pack_files = self.with_pack_files | with_pack_files = self.with_pack_files | ||||
if with_pack_files: | if with_pack_files: | ||||
# create a bare clone of that repository in another folder, | # create a bare clone of that repository in another folder, | ||||
# all objects will be contained in one or two pack files in that case | # all objects will be contained in one or two pack files in that case | ||||
bare_repo_path = os.path.join(tmp_path, archive_name + "_bare") | http_root_dir = tmp_path | ||||
repo_name = archive_name + "_bare" | |||||
bare_repo_path = os.path.join(http_root_dir, repo_name) | |||||
subprocess.run( | subprocess.run( | ||||
["git", "clone", "--bare", base_repo_url, bare_repo_path], check=True, | ["git", "clone", "--bare", base_repo_url, bare_repo_path], check=True, | ||||
) | ) | ||||
else: | else: | ||||
# otherwise serve objects from the bare repository located in | # otherwise serve objects from the bare repository located in | ||||
# the .git folder of the base repository | # the .git folder of the base repository | ||||
bare_repo_path = os.path.join(destination_path, ".git") | http_root_dir = destination_path | ||||
repo_name = ".git" | |||||
bare_repo_path = os.path.join(http_root_dir, repo_name) | |||||
# spawn local HTTP server that will serve the bare repository files | # spawn local HTTP server that will serve the bare repository files | ||||
hostname = "localhost" | hostname = "localhost" | ||||
handler = partial(SimpleHTTPRequestHandler, directory=bare_repo_path) | handler = partial(SimpleHTTPRequestHandler, directory=http_root_dir) | ||||
httpd = HTTPServer((hostname, 0), handler, bind_and_activate=True) | httpd = HTTPServer((hostname, 0), handler, bind_and_activate=True) | ||||
def serve_forever(httpd): | def serve_forever(httpd): | ||||
with httpd: | with httpd: | ||||
httpd.serve_forever() | httpd.serve_forever() | ||||
thread = Thread(target=serve_forever, args=(httpd,)) | thread = Thread(target=serve_forever, args=(httpd,)) | ||||
thread.start() | thread.start() | ||||
Show All 27 Lines | def init(self, swh_storage, datadir, tmp_path): | ||||
# generate or update the info/refs file used in dumb protocol | # generate or update the info/refs file used in dumb protocol | ||||
subprocess.run( | subprocess.run( | ||||
["git", "-C", bare_repo_path, "update-server-info"], check=True, | ["git", "-C", bare_repo_path, "update-server-info"], check=True, | ||||
) | ) | ||||
return super().load() | return super().load() | ||||
# bare repository with dumb protocol only URL | # bare repository with dumb protocol only URL | ||||
self.repo_url = f"http://{httpd.server_name}:{httpd.server_port}" | self.repo_url = f"http://{httpd.server_name}:{httpd.server_port}/{repo_name}" | ||||
self.loader = DumbGitLoaderTest(swh_storage, self.repo_url) | self.loader = DumbGitLoaderTest(swh_storage, self.repo_url) | ||||
self.repo = repo | self.repo = repo | ||||
yield | yield | ||||
# shutdown HTTP server | # shutdown HTTP server | ||||
httpd.shutdown() | httpd.shutdown() | ||||
thread.join() | thread.join() | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |