Skip to content

Commit 828df8d

Browse files
author
Chris Maunder
committed
Checks on null ExternalModulesDirPath
1 parent a8833c4 commit 828df8d

File tree

5 files changed

+58
-42
lines changed

5 files changed

+58
-42
lines changed

src/SDK/NET/Common/ModuleDescription.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ public static void Initialise(this ModuleDescription module, string currentServe
181181
module.CheckVersionAgainstModuleReleases();
182182
SetLatestCompatibleVersion(module, currentServerVersion);
183183

184-
// REVIEW: [Chris] The module.IsCompatible() method is not used here because it doesn't check the
185-
// LatestCompatibleRelease property. However, it there is a LatestCompatibleRelease, then the module
186-
// is compatible.
187-
184+
// The module.IsCompatible() method is not used here because it doesn't check the
185+
// LatestCompatibleRelease property. However, if there is a LatestCompatibleRelease,
186+
// then the module *is* compatible.
188187
module.Status = module.LatestCompatibleRelease is not null
189188
? ModuleStatusType.Available : ModuleStatusType.NotAvailable;
190189

src/server/Modules/ModuleSettings.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ private void ExpandMacros()
286286
_moduleOptions.ModulesDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.ModulesDirPath)!);
287287
_moduleOptions.PreInstalledModulesDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.PreInstalledModulesDirPath)!);
288288
_moduleOptions.DemoModulesDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.DemoModulesDirPath)!);
289-
_moduleOptions.ExternalModulesDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.ExternalModulesDirPath)!);
289+
if (!string.IsNullOrWhiteSpace(_moduleOptions.ExternalModulesDirPath))
290+
_moduleOptions.ExternalModulesDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.ExternalModulesDirPath)!);
290291
_moduleOptions.DownloadedModulePackagesDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.DownloadedModulePackagesDirPath)!);
291292
_moduleOptions.DownloadedModelsPackagesDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.DownloadedModelsPackagesDirPath)!);
292293
_moduleOptions.ModuleInstallerScriptsDirPath = Path.GetFullPath(ExpandOption(_moduleOptions.ModuleInstallerScriptsDirPath)!);
@@ -334,7 +335,8 @@ private void ExpandMacros()
334335
value = value.Replace(PreinstalledModulesDirPathMarker, _moduleOptions.PreInstalledModulesDirPath);
335336
value = value.Replace(ModulesDirPathMarker, _moduleOptions.ModulesDirPath);
336337
value = value.Replace(DemoModulesDirPathMarker, _moduleOptions.DemoModulesDirPath);
337-
value = value.Replace(ExternalModulesDirPath, _moduleOptions.ExternalModulesDirPath);
338+
if (!string.IsNullOrWhiteSpace(_moduleOptions.ExternalModulesDirPath))
339+
value = value.Replace(ExternalModulesDirPath, _moduleOptions.ExternalModulesDirPath);
338340
value = value.Replace(PlatformMarker, SystemInfo.Platform.ToLower());
339341
value = value.Replace(OSMarker, SystemInfo.OperatingSystem.ToLower());
340342
value = value.Replace(PythonPathMarker, _moduleOptions.PythonRelativeInterpreterPath);

src/server/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ private static (string?,string?, string?, string?) EnsureDirectories(IConfigurat
707707
demoModulesDirPath = Text.FixSlashes(demoModulesDirPath?.Replace("%ROOT_PATH%", rootPath));
708708
demoModulesDirPath = Path.GetFullPath(demoModulesDirPath);
709709
externalModulesDirPath = Text.FixSlashes(externalModulesDirPath?.Replace("%ROOT_PATH%", rootPath));
710-
externalModulesDirPath = Path.GetFullPath(externalModulesDirPath);
710+
if (!string.IsNullOrWhiteSpace(externalModulesDirPath))
711+
externalModulesDirPath = Path.GetFullPath(externalModulesDirPath);
711712

712713
// create the directories if the don't exist
713714
if (!Directory.Exists(runtimesDirPath))

src/setup.bat

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ set allowSharedPythonInstallsForModules=true
4848

4949
:: Debug flags for downloads and installs
5050

51+
:: If you wish to allow external modules
52+
set installExternalModules=false
53+
5154
:: Setup only the server, nothing else
5255
set setupServerOnly=false
5356

@@ -363,7 +366,11 @@ if /i "!executionEnvironment!" == "Development" (
363366
pushd !rootDirPath!\utils\ParseJSON
364367
if not exist ParseJSON.exe (
365368
call "!utilsScript!" WriteLine "Building ParseJSON"
366-
dotnet build /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary -c Release >NUL
369+
if /i "!verbosity!" == "quiet" (
370+
dotnet build /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary -c Release >NUL
371+
) else (
372+
dotnet build /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary -c Release
373+
)
367374
if exist .\bin\Release\net7.0\ move .\bin\Release\net7.0\* . >nul
368375
)
369376
popd
@@ -437,25 +444,27 @@ if /i "!setupMode!" == "SetupEverything" (
437444
if "!moduleInstallErrors!" NEQ "" set success=false
438445
)
439446

440-
call "!utilsScript!" WriteLine
441-
call "!utilsScript!" WriteLine "Processing External CodeProject.AI Server Modules" "White" "DarkGreen" !lineWidth!
442-
call "!utilsScript!" WriteLine
447+
if /i "!installExternalModules!" == "true" (
448+
call "!utilsScript!" WriteLine
449+
call "!utilsScript!" WriteLine "Processing External CodeProject.AI Server Modules" "White" "DarkGreen" !lineWidth!
450+
call "!utilsScript!" WriteLine
443451

444-
if exist !externalModulesDirPath! (
445-
for /f "delims=" %%D in ('dir /a:d /b "!externalModulesDirPath!"') do (
446-
set moduleDirName=%%~nxD
447-
set moduleDirPath=!externalModulesDirPath!\!moduleDirName!
452+
if exist !externalModulesDirPath! (
453+
for /f "delims=" %%D in ('dir /a:d /b "!externalModulesDirPath!"') do (
454+
set moduleDirName=%%~nxD
455+
set moduleDirPath=!externalModulesDirPath!\!moduleDirName!
448456

449-
call "!utilsScript!" GetModuleIdFromModuleSettingsFile "!moduleDirPath!\modulesettings.json"
450-
set moduleId=!moduleSettingValue!
457+
call "!utilsScript!" GetModuleIdFromModuleSettingsFile "!moduleDirPath!\modulesettings.json"
458+
set moduleId=!moduleSettingValue!
451459

452-
call :DoModuleInstall "!moduleId!" "!moduleDirPath!" "Esternal" errors
453-
if "!moduleInstallErrors!" NEQ "" set success=false
460+
call :DoModuleInstall "!moduleId!" "!moduleDirPath!" "Esternal" errors
461+
if "!moduleInstallErrors!" NEQ "" set success=false
462+
)
463+
) else (
464+
call "!utilsScript!" WriteLine "No external modules found" !color_mute!
454465
)
455-
) else (
456-
call "!utilsScript!" WriteLine "No external modules found" !color_mute!
457466
)
458-
467+
459468
call "!utilsScript!" WriteLine
460469
call "!utilsScript!" WriteLine "Module setup Complete" "Green"
461470

src/setup.sh

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ attemptSudoWithoutAdminRights=true
6464

6565
# Debug flags for downloads and installs
6666

67+
# IF you wish to allow external modules
68+
installExternalModules=false
69+
6770
# Perform *only* the post install self tests
6871
selfTestOnly=false
6972

@@ -940,30 +943,32 @@ if [ "$setupMode" = 'SetupEverything' ]; then
940943
fi
941944
done
942945

943-
# Walk through the modules directoorym for modules that live in the external
944-
# folder. For isntance modules that are in extenal Git repos / projects
946+
if [ "$installExternalModules" == "true" ]; then
947+
# Walk through the modules directoorym for modules that live in the external
948+
# folder. For isntance modules that are in extenal Git repos / projects
945949

946-
writeLine
947-
writeLine "Processing External CodeProject.AI Server Modules" "White" "DarkGreen" $lineWidth
948-
writeLine
950+
writeLine
951+
writeLine "Processing External CodeProject.AI Server Modules" "White" "DarkGreen" $lineWidth
952+
writeLine
949953

950-
if [ -d "$externalModulesDirPath" ]; then
951-
for d in ${externalModulesDirPath}/*/ ; do
952-
moduleDirName=$(basename "$d")
953-
moduleDirPath="${externalModulesDirPath}/${moduleDirName}"
954-
moduleId=$(getModuleIdFromModuleSettings "${moduleDirPath}/modulesettings.json")
954+
if [ -d "$externalModulesDirPath" ]; then
955+
for d in ${externalModulesDirPath}/*/ ; do
956+
moduleDirName=$(basename "$d")
957+
moduleDirPath="${externalModulesDirPath}/${moduleDirName}"
958+
moduleId=$(getModuleIdFromModuleSettings "${moduleDirPath}/modulesettings.json")
955959

956-
currentDir="$(pwd)"
957-
doModuleInstall "${moduleId}" "${moduleDirPath}" "External"
958-
cd "$currentDir" >/dev/null
960+
currentDir="$(pwd)"
961+
doModuleInstall "${moduleId}" "${moduleDirPath}" "External"
962+
cd "$currentDir" >/dev/null
959963

960-
if [ "${module_install_errors}" != "" ]; then
961-
success=false
962-
writeLine "Install failed: ${module_install_errors}" "$color_error"
963-
fi
964-
done
965-
else
966-
writeLine "No external modules found" "$color_mute"
964+
if [ "${module_install_errors}" != "" ]; then
965+
success=false
966+
writeLine "Install failed: ${module_install_errors}" "$color_error"
967+
fi
968+
done
969+
else
970+
writeLine "No external modules found" "$color_mute"
971+
fi
967972
fi
968973

969974
writeLine

0 commit comments

Comments
 (0)