Browse Source

refactoring

master
Sven Ullmann 2 years ago
parent
commit
860bb6ec08
  1. 38
      src/commands/configure-plugin
  2. 14
      src/commands/create-project
  3. 12
      src/commands/list-projects
  4. 2
      src/commands/remove-project
  5. 5
      src/includes/config.php
  6. 31
      src/includes/configure-json-file
  7. 25
      src/includes/configure-json-file.php
  8. 6
      src/includes/main_functions

38
src/commands/configure-plugin

@ -0,0 +1,38 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Configures a plugin"
echo
echoSubTitle "Usage:"
echo
echo "configure-plugin [shortname] [plugin]"
echo
echo "--help Prints this message"
echo " "
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
shortname=$(getArgument "$1" "shortname required" true)
plugin=$(getArgument "$2" "plugin required" true)
customer=$(getConfig false "project_manager.projects.$shortname.customer")
project=$(getConfig false "project_manager.projects.$shortname.project")
project_dir="$project_manager_dir/data/$customer/$project"
config_path="$project_dir/etc/$plugin/config.json"
if [ ! -f "$config_path" ]
then
echo
echoError "Could not load configuration file: $config_path"
echo
exit
fi
echo
echoMainTitle "Configure Plugin: $plugin"
echo
configureJsonFile "$config_path"

14
src/commands/create-project

@ -23,10 +23,11 @@ function usage {
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
customer="$(getArgument "$1" "$(usageError "Invalid customer")" true)"
project="$(getArgument "$2" "$(usageError "Invalid project")" true)"
shortname="$(getArgument "$3" "$(usageError "Invalid shortname")" true)"
customer="$(getArgument "$1" "Invalid customer" true)"
project="$(getArgument "$2" "Invalid project" true)"
shortname="$(getArgument "$3" "Invalid shortname" true)"
has_shortname="$(hasConfig false "project_manager.projects.$shortname")"
workspaces_dir="$(getConfig false "project_manager.workspaces_dir")"
if [ "$has_shortname" == true ]
then
@ -47,7 +48,7 @@ echo
echoMainTitle "Create project"
project_dir="$project_manager_dir/data/$customer/$project"
workspace_dir="$project_manager_workspaces_dir/$customer/$project"
workspace_dir="$workspaces_dir/$customer/$project"
echo
echoSubTitle "Please verify data"
@ -60,8 +61,9 @@ confirm
cryptkey="$(randkey)"
setConfig false "project_manager.projects.$shortname.customer" "$customer"
setConfig false "project_manager.projects.$shortname.project" "$project"
escapedShortname=${shortname//./\\.}
setConfig false "project_manager.projects.$escapedShortname.customer" "$customer"
setConfig false "project_manager.projects.$escapedShortname.project" "$project"
setConfig "$shortname" "project.cryptkey" "$cryptkey"
runPostscripts "create-project" "$shortname"

12
src/commands/list-projects

@ -2,8 +2,6 @@
### DO NOT EDIT THIS FILE
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
function usage {
echo
echoMainTitle "List all projects"
@ -16,7 +14,9 @@ function usage {
echo
}
projects="$(getConfig "project_manager_dir.projects")"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
projects="$(getConfig false "project_manager_dir.projects")"
function listProjects {
echo >&2
@ -24,8 +24,8 @@ function listProjects {
echo >&2
for shortname in "${projects[@]}"
do
customer="$(getConfig "project_manager_dir.projects.$shortname.customer")"
project="$(getConfig "project_manager_dir.projects.$shortname.project")"
customer="$(getConfig false "project_manager_dir.projects.$shortname.customer")"
project="$(getConfig false "project_manager_dir.projects.$shortname.project")"
echo "- Shortname: $shortname
Customer: $customer
Project: $project" >&2
@ -45,4 +45,4 @@ else
listProjects
fi
runPostscripts "list-projects"
runPostscripts false "list-projects"

2
src/commands/remove-project

@ -18,7 +18,7 @@ function usage {
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
shortname="$(getArgument "$1" "$(usageError "shortname required")" true)"
shortname="$(getArgument "$1" "shortname required" true)"
if [ "$(hasConfig false "project_manager.projects.$shortname")" == false ]
then

5
src/includes/config.php

@ -57,7 +57,7 @@ function loadProjectConfig()
$dh = opendir($plugin_dir);
if ($dh) {
while (false !== ($plugin = readdir($dh))) {
if ('.' === $plugin || '..' === $plugin || !is_dir($plugin_dir / $plugin)) {
if ('.' === $plugin || '..' === $plugin || !is_dir("$plugin_dir/$plugin")) {
continue;
}
$config_file = "$plugin_dir/$plugin/config.json";
@ -83,7 +83,10 @@ function parsePath()
{
global $configPath;
$parsedPath = '';
$configPath = str_replace('\\.', '<dot-escaped>', $configPath);
foreach (explode('.', $configPath) as $part) {
$part = str_replace('<dot-escaped>', '.', $part);
$part = str_replace("'", "\\'", $part);
$parsedPath .= "['$part']";
}
return $parsedPath;

31
src/includes/configure-json-file

@ -0,0 +1,31 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Sumedia Project Manager Configure Configuration File"
echo
echoSubTitle "Usage:"
echo
echo "configure-json-file filePath"
echo
echo "--help Prints this message"
echo " "
exit
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/bash_header"
filePath="$(getArgument "$1" "Parameter filePath not given" true)"
if [ ! -f "$filePath" ]
then
echo
echoError "Could not find configuration file: $filePath"
echo
exit;
fi
PHP=`which php`
script="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/configure-json-file.php"
$PHP "$script" "$@"

25
src/includes/configure-json-file.php

@ -0,0 +1,25 @@
<?php
### DO NOT EDIT THIS FILE
global $project_manager_dir, $shortname, $configPath, $configuration, $value;
$configuration = [];
$jsonFile = $_SERVER['argv'][1];
$configuration = json_decode(file_get_contents($jsonFile), true);
function readNext($config, &$current) {
foreach ($config as $key => $value) {
if (is_array($value) && !isset($value[0])) {
readNext($value, $current[$key]);
} else {
$prompt = "$key [default:$value]";
$current[$key] = readline($prompt);
}
}
}
foreach ($configuration as $key => $config) {
readNext($config, $configuration[$key]);
}
file_put_contents($jsonFile, json_encode($configuration, JSON_PRETTY_PRINT && JSON_ERROR_NONE && JSON_UNESCAPED_SLASHES));

6
src/includes/main_functions

@ -339,4 +339,10 @@ then
local configScript="$project_manager_dir/src/includes/json"
echo "$(source "$configScript" has "$container" "$configPath")"
}
function configureJsonFile {
local jsonPath="$(getArgument "$1" "json file path required" true)"
local configScript="$project_manager_dir/src/includes/configure-json-file"
source "$configScript" "$jsonPath"
}
fi
Loading…
Cancel
Save