Make 'chips' and 'states' of the default, not rfid-read

This commit is contained in:
xdrm-brackets 2017-09-28 19:07:30 +02:00
parent 36b3d01006
commit 56f7f99096
2 changed files with 90 additions and 76 deletions

View File

@ -30,58 +30,8 @@
}
/* [2] Get system states (global_state)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['states']) || !is_array($arr_r['states']) ){
slog('No \'states\' found in response file', "$FEATURE:deploy", 'update');
return 127;
}
/* (2) Reset file */
file_put_contents(STATES_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(STATES_CONF, 'w');
foreach($arr_r['states'] as $state)
$f->fwrite( json_encode([
$state['global_state'],
$state['chips']
]).PHP_EOL );
$f = null;
/* [3] Get chip list (chips)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['chips']) || !is_array($arr_r['chips']) ){
slog('No \'chips\' found in response file', "$FEATURE:deploy", 'update');
return 127;
}
/* (2) Reset file */
file_put_contents(CHIPS_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(CHIPS_CONF, 'w');
foreach($arr_r['chips'] as $chip)
$f->fwrite( json_encode([
(int) $chip['position'],
$chip['pins'],
$chip['states']
]).PHP_EOL );
$f = null;
/* [4] Get auth list (permissions)
/* [2] Get auth list (permissions)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['permissions']) || !is_array($arr_r['permissions']) ){
@ -107,7 +57,7 @@
$f = null;
/* [5] Get action list (with timeout)
/* [3] Get action list (with timeout)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['actions']) || !is_array($arr_r['actions']) ){

View File

@ -109,39 +109,103 @@
/* [5] Launch deploy script for each feature
=========================================================*/
slog('Deploying each feature', "api:deploy", 'update');
/* [4] Deploy default data
=========================================================*/ {
/* (1) For each feature */
foreach($feature as $feat_name){
/* (1) Get system states (global_state)
---------------------------------------------------------*/ {
/* (1) Check data */
if( !isset($arr_r['states']) || !is_array($arr_r['states']) ){
slog('No \'states\' found in response file', "$FEATURE:deploy", 'update');
return 127;
}
/* (2) Reset file */
file_put_contents(STATES_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(STATES_CONF, 'w');
foreach($arr_r['states'] as $state)
$f->fwrite( json_encode([
$state['global_state'],
$state['chips']
]).PHP_EOL );
$f = null;
/* (2) Check if specific data in response */
if( !isset($arr_r['feature'][$feat_name]) ){
slog("No data found for $feat_name", "api:deploy", 'update');
continue;
}
/* (3) Check for feature deploy script */
if( !file_exists(SOURCE_DIR."/feature/$feat_name/deploy") ){
slog("No deploy script found for $feat_name", "api:deploy", 'update');
continue;
/* (2) Get chip list (chips)
---------------------------------------------------------*/ {
/* (1) Check data */
if( !isset($arr_r['chips']) || !is_array($arr_r['chips']) ){
slog('No \'chips\' found in response file', "$FEATURE:deploy", 'update');
return 127;
}
/* (2) Reset file */
file_put_contents(CHIPS_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(CHIPS_CONF, 'w');
foreach($arr_r['chips'] as $chip)
$f->fwrite( json_encode([
(int) $chip['position'],
$chip['pins'],
$chip['states']
]).PHP_EOL );
$f = null;
}
/* (4) Write useful exclusive data to tmp file */
file_put_contents(TMP_DIR."/$feat_name", json_encode($arr_r['feature'][$feat_name]));
/* (4) Execute deploy script */
$sync_suffix = $sync ? ' sync' : '';
if( syscall(SOURCE_DIR."/feature/$feat_name/deploy$sync") !== false )
slog("Successfully deployed $feat_name", 'api:deploy', 'update');
else
slog("Failed deploying $feat_name", 'api:deploy', 'update');
}
/* [5] Launch deploy script for each feature
=========================================================*/ {
slog('Deploying each feature', "api:deploy", 'update');
/* (1) For each feature */
foreach($feature as $feat_name){
/* (2) Check if specific data in response */
if( !isset($arr_r['feature'][$feat_name]) ){
slog("No data found for $feat_name", "api:deploy", 'update');
continue;
}
/* (3) Check for feature deploy script */
if( !file_exists(SOURCE_DIR."/feature/$feat_name/deploy") ){
slog("No deploy script found for $feat_name", "api:deploy", 'update');
continue;
}
/* (4) Write useful exclusive data to tmp file */
file_put_contents(TMP_DIR."/$feat_name", json_encode($arr_r['feature'][$feat_name]));
/* (4) Execute deploy script */
$sync_suffix = $sync ? ' sync' : '';
if( syscall(SOURCE_DIR."/feature/$feat_name/deploy$sync") !== false )
slog("Successfully deployed $feat_name", 'api:deploy', 'update');
else
slog("Failed deploying $feat_name", 'api:deploy', 'update');
}
}
return 0;
}