MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / discover_sg_binary_path

Function discover_sg_binary_path

tools/sgcollect.py:817–850  ·  view source on GitHub ↗

Return the path to the sync gateway binary, returns None if the path is not found. 1. --sync-gateway-executable option, will through an exception if the path does not exist. 2. If the expvars endpoint is available, it will try to get the path from there. 3. Discover the path from a

(
    options: optparse.Values,
    sg_url: Optional[str],
    auth_headers: dict[str, str],
)

Source from the content-addressed store, hash-verified

815
816
817def discover_sg_binary_path(
818 options: optparse.Values,
819 sg_url: Optional[str],
820 auth_headers: dict[str, str],
821) -> str:
822 """
823 Return the path to the sync gateway binary, returns None if the path is not found.
824
825 1. --sync-gateway-executable option, will through an exception if the path does not exist.
826 2. If the expvars endpoint is available, it will try to get the path from there.
827 3. Discover the path from a set of common locations.
828 """
829 if options.sync_gateway_executable:
830 if not os.path.exists(options.sync_gateway_executable):
831 raise Exception(
832 "Path to sync gateway executable passed in does not exist: {0}".format(
833 options.sync_gateway_executable
834 )
835 )
836 return options.sync_gateway_executable
837 if sg_url:
838 sg_binary_path, _ = get_paths_from_expvars(sg_url, auth_headers=auth_headers)
839 if sg_binary_path:
840 return sg_binary_path
841 sg_bin_dirs = [
842 "/opt/couchbase-sync-gateway/bin/sync_gateway", # Linux + OSX
843 R"C:\Program Files (x86)\Couchbase\sync_gateway.exe", # Windows (Pre-2.0)
844 R"C:\Program Files\Couchbase\Sync Gateway\sync_gateway.exe", # Windows (Post-2.0)
845 ]
846
847 for sg_binary_path_candidate in sg_bin_dirs:
848 if os.path.exists(sg_binary_path_candidate):
849 return sg_binary_path_candidate
850 return ""
851
852
853def main() -> NoReturn:

Callers 1

mainFunction · 0.85

Calls 2

get_paths_from_expvarsFunction · 0.85
existsMethod · 0.80

Tested by

no test coverage detected