Skip to content

Commit

Permalink
Merge pull request #14 from poissoncorp/v5.2
Browse files Browse the repository at this point in the history
Handle Single File App Raven.Server files (for 6.1)
  • Loading branch information
poissoncorp authored Jul 15, 2024
2 parents 5c876e4 + d8b0022 commit 5ef8b40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
12 changes: 12 additions & 0 deletions ravendb_embedded/provide.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ def provide(self, target_directory):

class ExternalServerProvider(ProvideRavenDBServer):
SERVER_DLL_FILENAME = "Raven.Server.dll"
SERVER_SFA_FILENAME = "Raven.Server"

def __init__(self, server_location: str):
self.server_location = server_location
self.is_single_file_app = False

file_server_location = os.path.abspath(server_location)

Expand All @@ -97,6 +99,16 @@ def __init__(self, server_location: str):
self.inner_provider = CopyServerProvider(server_location)
return

# Also look for Single File App file - Raven.Server
if os.path.isdir(file_server_location) and os.path.exists(
os.path.join(file_server_location, self.SERVER_SFA_FILENAME)
):
self.is_single_file_app = True
self.inner_provider = CopyServerProvider(server_location)
return



raise ValueError(
f"Unable to find RavenDB server (expected directory with {self.SERVER_DLL_FILENAME}) or zip file. "
f"Used directory = {server_location}"
Expand Down
31 changes: 18 additions & 13 deletions ravendb_embedded/raven_server_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cryptography.hazmat.primitives import hashes
from ravendb.exceptions.raven_exceptions import RavenException

from ravendb_embedded.provide import ExternalServerProvider
from ravendb_embedded.options import ServerOptions
from ravendb_embedded.runtime_framework_version_matcher import (
RuntimeFrameworkVersionMatcher,
Expand All @@ -30,21 +31,24 @@ def run(options: ServerOptions) -> subprocess.Popen:
if not options.logs_path.strip():
raise ValueError("logs_path cannot be None or whitespace")

is_sfa = isinstance(options.provider, ExternalServerProvider) and options.provider.is_single_file_app
file_name = "Raven.Server" if is_sfa else "Raven.Server.dll"

server_paths = [
"Raven.Server.dll",
"Server/Raven.Server.dll",
"contentFiles/any/any/RavenDBServer/Raven.Server.dll",
f"{file_name}",
f"Server/{file_name}",
f"contentFiles/any/any/RavenDBServer/{file_name}",
]

server_dll_path = None
server_file_path = None

for path in server_paths:
full_path = os.path.join(options.target_server_location, path)
if os.path.exists(full_path):
server_dll_path = full_path
server_file_path = full_path
break

if server_dll_path is None:
if server_file_path is None:
raise RavenException("Server file was not found in any of the expected locations.")

if not options.dot_net_path.strip():
Expand Down Expand Up @@ -106,13 +110,14 @@ def run(options: ServerOptions) -> subprocess.Popen:
command_line_args.extend([f"--ServerUrl={options.server_url}"])

command_line_args[:0] = options.command_line_args
command_line_args.insert(0, server_dll_path)
command_line_args.insert(0, options.dot_net_path)

if options.framework_version:
framework_version = RuntimeFrameworkVersionMatcher.match(options)
command_line_args.insert(1, framework_version)
command_line_args.insert(1, "--fx-version")
command_line_args.insert(0, server_file_path)
if not is_sfa:
command_line_args.insert(0, options.dot_net_path)

if options.framework_version:
framework_version = RuntimeFrameworkVersionMatcher.match(options)
command_line_args.insert(1, framework_version)
command_line_args.insert(1, "--fx-version")

process_builder = subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process = process_builder
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import urllib.request
from setuptools.command.sdist import sdist

RAVENDB_VERSION = "5.4.116"
RAVENDB_VERSION = "5.4.200"
ZIP_FILE_NAME = "server.zip"
RAVENDB_DOWNLOAD_URL = f"https://www.nuget.org/api/v2/package/RavenDB.Embedded/{RAVENDB_VERSION}"

Expand Down Expand Up @@ -45,7 +45,7 @@ def run(self):
package_dir={"ravendb_embedded": "ravendb_embedded"},
include_package_data=True,
long_description=open("README.rst").read(),
version="5.2.6",
version="5.2.6.post1",
description="RavenDB Embedded library to run RavenDB in an embedded way",
author="RavenDB",
author_email="support@ravendb.net",
Expand Down

0 comments on commit 5ef8b40

Please sign in to comment.