Improved configuration import

for PowerShell
draft_specifications
meerkat 2021-12-02 22:59:09 +11:00
parent 74d5474b32
commit 8d5cc3f3f5
13 changed files with 183 additions and 53 deletions

View File

@ -1,5 +1,5 @@
[MartiLQ]
[martiLQ]
tags = sample,docs
publisher = meerkat@merebox.com
@ -16,5 +16,5 @@ theme = Documentation
author = Hive
title = {{documentName}}
state = active
expires = 0:0:7
expires = m:0:0:7
urlPrefix = https://github.com/meerkat-manor/marti/blob/draft_specifications/docs/source/

View File

@ -24,7 +24,7 @@ theme = Sample
author = Meerkat
title = {{documentName}}
state = expired
expires = m:0:6:0
expires = m:0:0:7
encoding = UTF-8
version = 1.0
urlPrefix =

View File

@ -1,10 +1,12 @@
. .\source\powershell\MartiLQ.ps1
. .\source\powershell\MartiLQConfiguration.ps1
try {
$describe = "Generate martiLQ definition for DOCS folder "
Write-Host $describe
$x = Import-Configuration -ConfigPath "docs\source\samples\conf\sample_docs.ini"
$oMarti = New-MartiChildItem -SourceFolder "./docs/source" -UrlPath "/docs" -Filter "*.md" -LogPath "./docs/source/samples/powershell/test/Logs" -ExtendAttributes:$true
$oMarti.description = $describe
@ -13,7 +15,6 @@ try {
Set-Content -Path $jsonFile -Value $x
Write-Host "martiLQ definition written to '$jsonFile' "
}
catch {
throw

View File

@ -68,13 +68,13 @@ $env:MARTILQ_PROJECT_PATH=Get-Location
Set-Location -Path (Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "source\golang\client\src") -PassThru
$mfile = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "test/golang/results/test_proc_docs.json"
$cfile = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "docs/source/samples/json/sample_docs.ini"
$cfile = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "docs/source/samples/conf/sample_docs.ini"
$spath = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "docs/source/"
go run . -- -t MAKE -m $mfile -c $cfile -s $spath --title "DOCS Sample" --description "Directory example for DOCS" --filter "w*" --update
$mfile = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "test/golang/results/test_proc_bsb.json"
$cfile = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "docs/source/samples/json/GEN005.ini"
$cfile = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "docs/source/samples/conf/GEN005.ini"
$spath = Join-Path -Path $env:MARTILQ_PROJECT_PATH -ChildPath "docs/source/samples/python/test/http/"
go run . -- -t MAKE -m $mfile -c $cfile -s $spath --title "GEN005" --description "Directory example for BSB" --update

View File

@ -25,9 +25,10 @@ func main() {
dataDirectory := flag.String("data", "", "Data directory content")
templateDirectory := flag.String("template", "", "Template directory content")
trace := flag.Bool("trace", false, "Produce trace logs")
flag.Parse()
if *trace == true {
if *trace {
log.Printf("static folder: %s\n", *staticDirectory)
log.Printf("data folder: %s\n", *dataDirectory)
log.Printf("docs folder: %s\n", *docsDirectory)
@ -39,7 +40,7 @@ func main() {
if (*dataDirectory != "") {
safePath = filepath.FromSlash(filepath.Join(*dataDirectory, strings.Replace(safePath, "data/", "", 1)))
}
if *trace == true {
if *trace {
log.Printf("resolved data folder: %s\n", safePath)
}
http.ServeFile(res, req, safePath)
@ -50,7 +51,7 @@ func main() {
if (*templateDirectory != "") {
safePath = filepath.FromSlash(filepath.Join(*templateDirectory, strings.Replace(safePath, "template/", "", 1)))
}
if *trace == true {
if *trace {
log.Printf("resolved template folder: %s\n", safePath)
}
http.ServeFile(res, req, safePath)
@ -92,34 +93,6 @@ func main() {
})
http.HandleFunc("/docsx/", func( res http.ResponseWriter, req *http.Request ) {
localPath := ""
if (*docsDirectory == "") {
temp := "../../.."
docsDirectory = &temp
localPath = ValidatePath(filepath.FromSlash(*docsDirectory+req.URL.Path))
} else {
localPath = ValidatePath(filepath.FromSlash(*docsDirectory+strings.Replace(req.URL.Path, "docs/", "", 1)))
}
if *trace == true {
log.Printf("resolved docs folder: \"%s\"", localPath)
}
f, err := os.Open(localPath)
if err != nil {
log.Printf("fetch docs error: \"%s\" with %s", localPath, err)
http.NotFound(res, req)
} else {
s, err := f.Stat()
if err != nil || s.IsDir() {
log.Printf("fetch docs stat error: \"%s\"", localPath)
http.NotFound(res, req)
//http.ServeFile(res, req, filepath.FromSlash(*staticDirectory + "/404.html"))
} else {
http.ServeFile(res, req, localPath)
}
}
})
http.HandleFunc("/api/", apiHandler)
http.HandleFunc("/api/view", apiHandlerView)

View File

@ -7,6 +7,9 @@
function New-MartiDefinition
{
Param(
[String] $ConfigPath = $null
)
$oSoftware = [PSCustomObject]@{
extension = "software"
@ -22,7 +25,12 @@ function New-MartiDefinition
}
$oConfig = Get-DefaultConfiguration
if ($null -eq $ConfigPath -or $ConfigPath -eq "") {
$oConfig = Get-Configuration
} else {
$oConfig = Import-Configuration -ConfigPath $ConfigPath
}
if ( $nulll -eq $oConfig.publisher -or $oConfig.publisher -eq "") {
$publisher = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
} else {
@ -54,8 +62,8 @@ function New-MartiDefinition
license = $oConfig.license
state = $oConfig.state
batch = $oConfig.batch
describedBy = ""
landingPage = ""
describedBy = $oConfig.describedBy
landingPage = $oConfig.landingPage
theme =$oConfig.theme
resources = $lresource

View File

@ -4,6 +4,16 @@
$script:SoftwareVersion = "0.0.1"
$global:default_metaFile = "##martilq##.json"
$global:martiLQ_configuration = $null
function Get-Configuration {
if ($null -eq $global:martiLQ_configuration) {
return Get-DefaultConfiguration
} else {
return $global:martiLQ_configuration
}
}
function Get-DefaultConfiguration {
@ -57,6 +67,125 @@ function Get-DefaultConfiguration {
return $oConfiguration
}
function Get-Title {
function Import-Configuration {
Param(
[String] $ConfigPath = $null
)
$oConfig = Get-DefaultConfiguration
$iConfig = $null
if ($null -eq $ConfigPath -or $ConfigPath -eq "") {
if (Test-Path "martilq.ini") {
$ConfigPath = "martilq.ini"
} else {
$homeDir = $env:USERPROFILE
if (Test-Path (Join-Path -Path $homeDir -ChildPath ".martilq/martilq.ini")) {
$ConfigPath = Join-Path -Path $homeDir -ChildPath ".martilq/martilq.ini"
}
}
if ($null -ne $ConfigPath -and $ConfigPath -ne "") {
Write-Log -LogEntry "Using configuration path '$ConfigPath'"
$iConfig = Get-IniFile -Path $ConfigPath
} else {
Write-Log -LogEntry "Using default configuration settings"
}
} else {
if (Test-Path $ConfigPath) {
Write-Log -LogEntry "Using configuration path '$ConfigPath'"
$iConfig = Get-IniFile -Path $ConfigPath
} else {
Write-Log -LogEntry "Could not find configuration path '$ConfigPath' so using default configuration"
}
}
# Now do mapping of values
if ($null -ne $iConfig) {
if ($null -ne $iConfig.General) {
$oConfig.logPath = Set-ConfigurationValue $oConfig.logPath -Value $iConfig.General.logPath
$oConfig.dateFormat = Set-ConfigurationValue $oConfig.dateFormat -Value $iConfig.General.dateFormat
$oConfig.dateTimeFormat = Set-ConfigurationValue $oConfig.dateTimeFormat -Value $iConfig.General.dateTimeFormat
$oConfig.dataPath = Set-ConfigurationValue $oConfig.dataPath -Value $iConfig.General.dataPath
$oConfig.tempPath = Set-ConfigurationValue $oConfig.tempPath -Value $iConfig.General.tempPath
}
if ($null -ne $iConfig.martiLQ) {
if ($null -ne $iConfig.martiLQ.tags -and $iConfig.martiLQ.tags -ne "" -and $iConfig.martiLQ.tags.Length -gt 0 ) {
$oConfig.tags = $iConfig.martiLQ.tags.Split(",")
}
$oConfig.publisher = Set-ConfigurationValue $oConfig.publisher -Value $iConfig.martiLQ.publisher
$oConfig.contactPoint = Set-ConfigurationValue $oConfig.contactPoint -Value $iConfig.martiLQ.contactPoint
$oConfig.accessLevel = Set-ConfigurationValue $oConfig.accessLevel -Value $iConfig.martiLQ.accessLevel
$oConfig.rights = Set-ConfigurationValue $oConfig.rights -Value $iConfig.martiLQ.rights
$oConfig.license = Set-ConfigurationValue $oConfig.license -Value $iConfig.martiLQ.license
$oConfig.batch = Set-ConfigurationValue $oConfig.batch -Value $iConfig.martiLQ.batch
$oConfig.theme = Set-ConfigurationValue $oConfig.theme -Value $iConfig.martiLQ.theme
}
if ($null -ne $iConfig.Resources) {
$oConfig.author = Set-ConfigurationValue $oConfig.author -Value $iConfig.Resources.author
$oConfig.title = Set-ConfigurationValue $oConfig.title -Value $iConfig.Resources.title
$oConfig.state = Set-ConfigurationValue $oConfig.state -Value $iConfig.Resources.state
$oConfig.expires = Set-ConfigurationValue $oConfig.expires -Value $iConfig.Resources.expires
$oConfig.urlPrefix = Set-ConfigurationValue $oConfig.urlPrefix -Value $iConfig.Resources.urlPrefix
$oConfig.compression = Set-ConfigurationValue $oConfig.compression -Value $iConfig.Resources.compression
$oConfig.encryption = Set-ConfigurationValue $oConfig.encryption -Value $iConfig.Resources.encryption
$oConfig.describedBy = Set-ConfigurationValue $oConfig.describedBy -Value $iConfig.Resources.describedBy
$oConfig.landingPage = Set-ConfigurationValue $oConfig.landingPage -Value $iConfig.Resources.landingPage
}
if ($null -ne $iConfig.Hash) {
$oConfig.hashAlgorithm = Set-ConfigurationValue $oConfig.hashAlgorithm -Value $iConfig.Hash.hashAlgorithm
}
}
$global:martiLQ_configuration = $oConfig
return $oConfig
}
Function Set-ConfigurationValue {
Param(
[Parameter(Mandatory=$true)][AllowEmptyString()][String]$OriginalValue,
[Parameter(Mandatory=$true)][AllowEmptyString()][String]$Value
)
if ($null -ne $Value -and $Value -ne "") {
return $Value
} else {
return $OriginalValue
}
}
Function Get-IniFile {
Param(
[Parameter(mandatory=$true)][string]$Path
)
$oIni = @{}
Get-Content $Path | ForEach-Object {
$_.Trim() } | Where-Object {
$_ -notmatch '^(;|$)'
} | ForEach-Object {
if ($_ -match '^\[.*\]$') {
$section = $_ -replace '\[|\]'
$oIni[$section] = @{}
} else {
$key, $value = $_ -split '\s*=\s*', 2
$oIni[$section][$key] = $value
}
}
return $oIni
}

View File

@ -63,7 +63,7 @@ Param(
Write-Log ""
if ($null -eq $Configuration) {
$Configuration = Get-DefaultConfiguration
$Configuration = Get-Configuration
}
if (Test-Path -Path $SourcePath -PathType Leaf) {
@ -172,6 +172,7 @@ Param(
[switch] $Recurse,
[switch] $ExtendAttributes,
[switch] $ExcludeHash,
[String] $ConfigPath,
[String] $LogPath
)
@ -187,7 +188,16 @@ Param(
Write-Log "Parameter: ExcludeHash Value: $ExcludeHash "
Write-Log ""
$oMarti, $oConfig = New-MartiDefinition
$oMarti, $oConfig = New-MartiDefinition -ConfigPath $ConfigPath
if ($null -ne $LogPath -and $LogPath -ne "") {
$oConfig.logPath = $LogPath
}
if ($null -ne $urlPath -and $urlPath -ne "") {
$oConfig.urlPrefix = $urlPath
} else {
$urlPath = $oConfig.urlPrefix
}
$lresource = $oMarti.resources
$SourceFullName = (Get-Item -Path $SourceFolder).FullName
@ -700,8 +710,9 @@ function Compare-MartiResource {
function Set-DefaultExpiryDate{
Param(
[Parameter(Mandatory)][PSCustomObject] $Configuration,
[Parameter(Mandatory)][Datetime] $DocumentDate,
[Parameter(Mandatory)][PSCustomObject] $Configuration
[Parameter][Datetime] $RunDate
)
@ -709,13 +720,21 @@ function Set-DefaultExpiryDate{
$expires = $DocumentDate.AddYears(10)
} else {
$factors = $oConfig.expires.Split(":")
if ($factors[0] -ne "m") {
$expires = $DocumentDate.AddYears(10)
} else {
$expires = $DocumentDate.AddYears($factors[1])
$expires = $expires.AddMonths($factors[2])
$expires = $expires.AddDays($factors[3])
if ($factors[0] -eq "m") {
$expires = $DocumentDate
} elseif ($factors[0] -eq "r") {
if ($null -eq $RunDate) {
$expires = Get-Date
} else {
$expires = $RunDate
}
}
else {
$expires = Get-Date
}
$expires = $expires.AddYears($factors[1])
$expires = $expires.AddMonths($factors[2])
$expires = $expires.AddDays($factors[3])
}
return $expires

View File

@ -38,7 +38,7 @@ print("Definition description is: {}".format(oMarti["description"]))
mlq.CloseLog()
configPath = "./docs/source/samples/json/GEN005.ini"
configPath = "./docs/source/samples/conf/GEN005.ini"
sourcePath = "./docs/source/*"
saveFile = "./test/python/results/test_proc_docs.json"
ProcessFilePath(ConfigPath=configPath, SourcePath=sourcePath, Filter="", Recursive=True, UrlPrefix="https://localhost/", DefinitionPath=saveFile)