Change the method of how the filepath are generated
To avoid having to update file or directory paths in 3 script locations (PHP Common, Shell Common and Python File path resolver) The .json file will references by all 3 systems, allowing them to generate paths from one central location. Files can be then moved around, the file updated and all 3 languages will up to date without any other work.
This commit is contained in:
@@ -0,0 +1,280 @@
|
||||
{
|
||||
"directories": {
|
||||
"home": {
|
||||
"description": "The home path for the user with User ID of 1000, this is normally the 'pi' user",
|
||||
"read_setting": null,
|
||||
"return_var": "home"
|
||||
},
|
||||
"birdnet-pi": {
|
||||
"alias_for": "birdnet_pi"
|
||||
},
|
||||
"birdnet_pi": {
|
||||
"description": "The root directory of the BirdNET-pi install",
|
||||
"lives_under": "home",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/BirdNET-Pi",
|
||||
"return_var": ""
|
||||
},
|
||||
"recs_dir": {
|
||||
"alias_for": "recordings_dir"
|
||||
},
|
||||
"recordings_dir": {
|
||||
"description": "The recording directory as specified in the config file (default: BirdSongs)",
|
||||
"lives_under": "home",
|
||||
"read_setting": "RECS_DIR",
|
||||
"replace_setting_text": "$HOME",
|
||||
"replace_setting_text_with": "",
|
||||
"append": ""
|
||||
},
|
||||
"processed": {
|
||||
"description": "The directory which holds the recordings that have been processed",
|
||||
"lives_under": "recordings_dir",
|
||||
"read_setting": "PROCESSED",
|
||||
"replace_setting_text": "${RECS_DIR}",
|
||||
"replace_setting_text_with": "",
|
||||
"append": ""
|
||||
},
|
||||
"extracted": {
|
||||
"description": "The directory which holds the extraction related data from detections",
|
||||
"lives_under": "recordings_dir",
|
||||
"read_setting": "EXTRACTED",
|
||||
"replace_setting_text": "${RECS_DIR}",
|
||||
"replace_setting_text_with": "",
|
||||
"append": ""
|
||||
},
|
||||
"extracted_bydate": {
|
||||
"alias_for": "extracted_by_date"
|
||||
},
|
||||
"extracted_by_date": {
|
||||
"description": "The directory which holds the the extractions from detections as folders by date",
|
||||
"lives_under": "extracted",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/By_Date"
|
||||
},
|
||||
"extracted_charts": {
|
||||
"description": "The directory which holds the spectrogram charts for detections",
|
||||
"lives_under": "extracted",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/Charts"
|
||||
},
|
||||
"shifted_dir": {
|
||||
"alias_for": "shifted_audio"
|
||||
},
|
||||
"shifted_audio": {
|
||||
"description": "The directory which stores any frequency shifted audio",
|
||||
"lives_under": "extracted_by_date",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/shifted"
|
||||
},
|
||||
"database": {
|
||||
"description": "**NOT CURRENTLY USED** The directory which holds files related to the detections database",
|
||||
"lives_under": "birdnet_pi",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/database"
|
||||
},
|
||||
"config": {
|
||||
"description": "The directory which holds configuration files for BirdNET-pi",
|
||||
"lives_under": "birdnet_pi",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/config"
|
||||
},
|
||||
"models": {
|
||||
"alias_for": "model"
|
||||
},
|
||||
"model": {
|
||||
"description": "The directory which holds AI detection models",
|
||||
"lives_under": "birdnet_pi",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/model"
|
||||
},
|
||||
"python3_ve": {
|
||||
"description": "The directory which contains the Python 3 Virtual Environment",
|
||||
"lives_under": "birdnet_pi",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/birdnet\/bin"
|
||||
},
|
||||
"scripts": {
|
||||
"description": "The directory which contains the script files like PHP and Shell scripts",
|
||||
"lives_under": "birdnet_pi",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/scripts"
|
||||
},
|
||||
"stream_data": {
|
||||
"description": "The directory which contains the recordings from RTSP streams",
|
||||
"lives_under": "recordings_dir",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/StreamData"
|
||||
},
|
||||
"templates": {
|
||||
"description": "The directory which contains the templates, like html, CRON script templates",
|
||||
"lives_under": "birdnet_pi",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/templates"
|
||||
},
|
||||
"www": {
|
||||
"alias_for": "web"
|
||||
},
|
||||
"web": {
|
||||
"description": "The directory which any files related to generating the Web UI, index.php, views.php, stylesheets etc",
|
||||
"lives_under": "birdnet_pi",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/homepage"
|
||||
},
|
||||
"www_fonts": {
|
||||
"alias_for": "web_fonts"
|
||||
},
|
||||
"web_fonts": {
|
||||
"description": "The directory which any fonts used by the WebUI or Python scripts",
|
||||
"lives_under": "www",
|
||||
"read_setting": "",
|
||||
"replace_setting_text": "",
|
||||
"replace_setting_text_with": "",
|
||||
"append": "\/static"
|
||||
}
|
||||
},
|
||||
"files": {
|
||||
"analyzing_now.txt": {
|
||||
"lives_under": "birdnet_pi",
|
||||
"append": "\/analyzing_now.txt"
|
||||
},
|
||||
"apprise.txt": {
|
||||
"lives_under": "birdnet_pi",
|
||||
"append": "\/apprise.txt"
|
||||
},
|
||||
"birdnet.conf": {
|
||||
"lives_under": "birdnet_pi",
|
||||
"append": "\/birdnet.conf"
|
||||
},
|
||||
"etc_birdnet.conf": {
|
||||
"lives_under": "",
|
||||
"append": "",
|
||||
"return_var": "\/etc\/birdnet\/birdnet.conf"
|
||||
},
|
||||
"BirdDB.txt": {
|
||||
"lives_under": "birdnet_pi",
|
||||
"append": "\/BirdDB.txt"
|
||||
},
|
||||
"birds.db": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/birds.db"
|
||||
},
|
||||
"blacklisted_images.txt": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/blacklisted_images.txt"
|
||||
},
|
||||
"disk_check_exclude.txt": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/disk_check_exclude.txt"
|
||||
},
|
||||
"email_template": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/email_template"
|
||||
},
|
||||
"email_template2": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/email_template2"
|
||||
},
|
||||
"exclude_species_list.txt": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/exclude_species_list.txt"
|
||||
},
|
||||
"filepath_map.json": {
|
||||
"lives_under": "config",
|
||||
"append": "\/filepath_map.json"
|
||||
},
|
||||
"firstrun.ini": {
|
||||
"lives_under": "birdnet_pi",
|
||||
"append": "\/firstrun.ini"
|
||||
},
|
||||
".gotty": {
|
||||
"lives_under": "home",
|
||||
"append": "\/.gotty"
|
||||
},
|
||||
"HUMAN.txt": {
|
||||
"lives_under": "birdnet_pi",
|
||||
"append": "\/HUMAN.txt"
|
||||
},
|
||||
"IDFILE": {
|
||||
"alias_for": "IdentifiedSoFar.txt"
|
||||
},
|
||||
"IdentifiedSoFar.txt": {
|
||||
"lives_under": "home",
|
||||
"read_setting": "IDFILE",
|
||||
"replace_setting_text": "$HOME",
|
||||
"replace_setting_text_with": "",
|
||||
"append": ""
|
||||
},
|
||||
"include_species_list.txt": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/include_species_list.txt"
|
||||
},
|
||||
"labels.txt": {
|
||||
"lives_under": "model",
|
||||
"append": "\/labels.txt"
|
||||
},
|
||||
"labels.txt.old": {
|
||||
"lives_under": "model",
|
||||
"append": "\/labels.txt.old"
|
||||
},
|
||||
"labels_flickr.txt": {
|
||||
"lives_under": "model",
|
||||
"append": "\/labels_flickr.txt"
|
||||
},
|
||||
"labels_lang.txt": {
|
||||
"lives_under": "model",
|
||||
"append": "\/labels_lang.txt"
|
||||
},
|
||||
"labels_l18n.zip": {
|
||||
"lives_under": "model",
|
||||
"append": "\/labels_l18n.zip"
|
||||
},
|
||||
"labels_nm.zip": {
|
||||
"lives_under": "model",
|
||||
"append": "\/labels_nm.zip"
|
||||
},
|
||||
"lastrun.txt": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/lastrun.txt"
|
||||
},
|
||||
"python3": {
|
||||
"lives_under": "python3_ve",
|
||||
"append": "\/python3 "
|
||||
},
|
||||
"python3_appraise": {
|
||||
"lives_under": "python3_ve",
|
||||
"append": "\/apprise "
|
||||
},
|
||||
"species.py": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/species.py"
|
||||
},
|
||||
"thisrun.txt": {
|
||||
"lives_under": "scripts",
|
||||
"append": "\/thisrun.txt"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
/**
|
||||
* Script to allow easy manipulation and generation of ../config/filepath_map.json
|
||||
* Execute this script with php -a ./generate_filepath_map_file.php
|
||||
*/
|
||||
|
||||
############################
|
||||
# FILE PATH DECLARATIONS
|
||||
############################
|
||||
$file_path_map_array['directories']['home'] = array(
|
||||
'description' => "The home path for the user with User ID of 1000, this is normally the 'pi' user",
|
||||
'read_setting' => null,
|
||||
'return_var' => 'home'
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['directories']['birdnet-pi'] = array('alias_for' => 'birdnet_pi');
|
||||
$file_path_map_array['directories']['birdnet_pi'] = array(
|
||||
'description' => "The root directory of the BirdNET-pi install",
|
||||
'lives_under' => 'home',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/BirdNET-Pi',
|
||||
'return_var' => ''
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['directories']['recs_dir'] = array('alias_for' => 'recordings_dir');
|
||||
$file_path_map_array['directories']['recordings_dir'] = array(
|
||||
'description' => "The recording directory as specified in the config file (default: BirdSongs)",
|
||||
'lives_under' => 'home',
|
||||
'read_setting' => 'RECS_DIR',
|
||||
'replace_setting_text' => '$HOME',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '',
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['directories']['processed'] = array(
|
||||
'description' => "The directory which holds the recordings that have been processed",
|
||||
'lives_under' => 'recordings_dir',
|
||||
'read_setting' => 'PROCESSED',
|
||||
'replace_setting_text' => '${RECS_DIR}',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '',
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['directories']['extracted'] = array(
|
||||
'description' => "The directory which holds the extraction related data from detections",
|
||||
'lives_under' => 'recordings_dir',
|
||||
'read_setting' => 'EXTRACTED',
|
||||
'replace_setting_text' => '${RECS_DIR}',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '',
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['directories']['extracted_bydate'] = array('alias_for' => 'extracted_by_date');
|
||||
$file_path_map_array['directories']['extracted_by_date'] = array(
|
||||
'description' => "The directory which holds the the extractions from detections as folders by date",
|
||||
'lives_under' => 'extracted',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/By_Date',
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['directories']['extracted_charts'] = array(
|
||||
'description' => "The directory which holds the spectrogram charts for detections",
|
||||
'lives_under' => 'extracted',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/Charts',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['shifted_dir'] = array('alias_for' => 'shifted_audio');
|
||||
$file_path_map_array['directories']['shifted_audio'] = array(
|
||||
'description' => "The directory which stores any frequency shifted audio",
|
||||
'lives_under' => 'extracted_by_date',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/shifted',
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['directories']['database'] = array(
|
||||
'description' => "**NOT CURRENTLY USED** The directory which holds files related to the detections database",
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/database',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['config'] = array(
|
||||
'description' => "The directory which holds configuration files for BirdNET-pi",
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/config',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['models'] = array('alias_for' => 'model');
|
||||
$file_path_map_array['directories']['model'] = array(
|
||||
'description' => "The directory which holds AI detection models",
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/model',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['python3_ve'] = array(
|
||||
'description' => "The directory which contains the Python 3 Virtual Environment",
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/birdnet/bin',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['scripts'] = array(
|
||||
'description' => "The directory which contains the script files like PHP and Shell scripts",
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/scripts',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['stream_data'] = array(
|
||||
'description' => "The directory which contains the recordings from RTSP streams",
|
||||
'lives_under' => 'recordings_dir',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/StreamData',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['templates'] = array(
|
||||
'description' => "The directory which contains the templates, like html, CRON script templates",
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/templates',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['www'] = array('alias_for' => 'web');
|
||||
$file_path_map_array['directories']['web'] = array(
|
||||
'description' => "The directory which any files related to generating the Web UI, index.php, views.php, stylesheets etc",
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/homepage',
|
||||
);
|
||||
|
||||
$file_path_map_array['directories']['www_fonts'] = array('alias_for' => 'web_fonts');
|
||||
$file_path_map_array['directories']['web_fonts'] = array(
|
||||
'description' => "The directory which any fonts used by the WebUI or Python scripts",
|
||||
'lives_under' => 'www',
|
||||
'read_setting' => '',
|
||||
'replace_setting_text' => '',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '/static',
|
||||
);
|
||||
|
||||
|
||||
############################
|
||||
# FILE PATH DECLARATIONS
|
||||
############################
|
||||
$file_path_map_array['files']['analyzing_now.txt'] = array(
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'append' => '/analyzing_now.txt'
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['apprise.txt'] = array(
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'append' => '/apprise.txt'
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['birdnet.conf'] = array(
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'append' => '/birdnet.conf'
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['etc_birdnet.conf'] = array(
|
||||
'lives_under' => '',
|
||||
'append' => '',
|
||||
'return_var' => '/etc/birdnet/birdnet.conf'
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['BirdDB.txt'] = array(
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'append' => '/BirdDB.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['birds.db'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/birds.db',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['blacklisted_images.txt'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/blacklisted_images.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['disk_check_exclude.txt'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/disk_check_exclude.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['email_template'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/email_template',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['email_template2'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/email_template2',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['exclude_species_list.txt'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/exclude_species_list.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['filepath_map.json'] = array(
|
||||
'lives_under' => 'config',
|
||||
'append' => '/filepath_map.json',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['firstrun.ini'] = array(
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'append' => '/firstrun.ini',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['.gotty'] = array(
|
||||
'lives_under' => 'home',
|
||||
'append' => '/.gotty',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['HUMAN.txt'] = array(
|
||||
'lives_under' => 'birdnet_pi',
|
||||
'append' => '/HUMAN.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['IDFILE'] = array('alias_for' => 'IdentifiedSoFar.txt');
|
||||
$file_path_map_array['files']['IdentifiedSoFar.txt'] = array(
|
||||
'lives_under' => 'home',
|
||||
'read_setting' => 'IDFILE',
|
||||
'replace_setting_text' => '$HOME',
|
||||
'replace_setting_text_with' => '',
|
||||
'append' => '',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['include_species_list.txt'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/include_species_list.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['labels.txt'] = array(
|
||||
'lives_under' => 'model',
|
||||
'append' => '/labels.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['labels.txt.old'] = array(
|
||||
'lives_under' => 'model',
|
||||
'append' => '/labels.txt.old',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['labels_flickr.txt'] = array(
|
||||
'lives_under' => 'model',
|
||||
'append' => '/labels_flickr.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['labels_lang.txt'] = array(
|
||||
'lives_under' => 'model',
|
||||
'append' => '/labels_lang.txt',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['labels_l18n.zip'] = array(
|
||||
'lives_under' => 'model',
|
||||
'append' => '/labels_l18n.zip',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['labels_nm.zip'] = array(
|
||||
'lives_under' => 'model',
|
||||
'append' => '/labels_nm.zip',
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['files']['lastrun.txt'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/lastrun.txt',
|
||||
);
|
||||
|
||||
|
||||
$file_path_map_array['files']['python3'] = array(
|
||||
'lives_under' => 'python3_ve',
|
||||
'append' => '/python3 ',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['python3_appraise'] = array(
|
||||
'lives_under' => 'python3_ve',
|
||||
'append' => '/apprise ',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['species.py'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/species.py',
|
||||
);
|
||||
|
||||
$file_path_map_array['files']['thisrun.txt'] = array(
|
||||
'lives_under' => 'scripts',
|
||||
'append' => '/thisrun.txt',
|
||||
);
|
||||
|
||||
//Output array as JSON and pretty print it
|
||||
file_put_contents('./filepath_map.json', json_encode($file_path_map_array, JSON_PRETTY_PRINT));
|
||||
+107
-132
@@ -44,6 +44,8 @@ if ($sys_timezone !== "") {
|
||||
|
||||
|
||||
////////// PARSES THE CONFIG FILE //////////
|
||||
$filePathMap_json_path = file_exists('./config/filepath_map.json') ? "./config/filepath_map.json" : "../config/filepath_map.json";
|
||||
$filePathMap_data = [];
|
||||
$config = [];
|
||||
parseConfig();
|
||||
|
||||
@@ -1024,6 +1026,20 @@ function changeLanguage($model, $language)
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads in the JSON file containing data on directory and file paths
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function loadFilePathMap()
|
||||
{
|
||||
global $filePathMap_data, $filePathMap_json_path;
|
||||
if (empty($filePathMap_data)) {
|
||||
$filePathMap_data = json_decode(file_get_contents($filePathMap_json_path), true);
|
||||
}
|
||||
return $filePathMap_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory Path Helper, returns a full directory path for a supplied directory name e.g home, processed, extracted
|
||||
*
|
||||
@@ -1035,61 +1051,56 @@ function getDirectory($dir)
|
||||
global $config, $home;
|
||||
$dir = strtolower($dir);
|
||||
|
||||
if ($dir == "home") {
|
||||
return $home;
|
||||
} else if ($dir == "birdnet-pi" || $dir == "birdnet_pi") {
|
||||
return getDirectory('home') . '/BirdNET-Pi';
|
||||
//
|
||||
} else if ($dir == "recs_dir" || $dir == "recordings_dir") {
|
||||
$recs_dir_setting = $config['RECS_DIR'];
|
||||
return str_replace('$HOME', getDirectory('home'), $recs_dir_setting);
|
||||
//
|
||||
} else if ($dir == "processed") {
|
||||
$processed_dir_setting = $config['PROCESSED'];
|
||||
return getDirectory('recs_dir') . str_replace('${RECS_DIR}', '', $processed_dir_setting);
|
||||
//
|
||||
} else if ($dir == "extracted") {
|
||||
$extracted_dir_setting = $config['EXTRACTED'];
|
||||
return getDirectory('recs_dir') . str_replace('${RECS_DIR}', '', $extracted_dir_setting);
|
||||
//
|
||||
} elseif ($dir == "extracted_bydate" || $dir == "extracted_by_date") {
|
||||
return getDirectory('extracted') . '/By_Date';
|
||||
//
|
||||
} elseif ($dir == "extracted_charts") {
|
||||
return getDirectory('extracted') . '/Charts';
|
||||
//
|
||||
} elseif ($dir == "shifted_audio" || $dir == "shifted_dir") {
|
||||
return getDirectory('home') . '/BirdSongs/Extracted/By_Date/shifted';
|
||||
//
|
||||
} elseif ($dir == "database") {
|
||||
// NOT USED
|
||||
return getDirectory('birdnet_pi') . '/database';
|
||||
//
|
||||
} elseif ($dir == "config") {
|
||||
// NOT USED
|
||||
return getDirectory('birdnet_pi') . '/config';
|
||||
//
|
||||
} elseif ($dir == "models" || $dir == "model") {
|
||||
return getDirectory('birdnet_pi') . '/model';
|
||||
//
|
||||
} elseif ($dir == "python3_ve") {
|
||||
return getDirectory('birdnet_pi') . '/birdnet/bin';
|
||||
//
|
||||
} elseif ($dir == "scripts") {
|
||||
return getDirectory('birdnet_pi') . '/scripts';
|
||||
//
|
||||
} elseif ($dir == "stream_data") {
|
||||
return getDirectory('recs_dir') . '/StreamData';
|
||||
//
|
||||
} elseif ($dir == "templates") {
|
||||
return getDirectory('birdnet_pi') . '/templates';
|
||||
//
|
||||
} elseif ($dir == "web" || $dir == "www") {
|
||||
return getDirectory('birdnet_pi') . '/homepage';
|
||||
//
|
||||
} elseif ($dir == "web_fonts" || $dir == "www_fonts") {
|
||||
return getDirectory('www') . '/static';
|
||||
$filePathMap_directories = loadFilePathMap()['directories'];
|
||||
|
||||
if (array_key_exists($dir, $filePathMap_directories)) {
|
||||
$filePathMap_directories_selected = $filePathMap_directories[$dir];
|
||||
|
||||
//Check to see if directory is an alias for another
|
||||
$dir_alias = $filePathMap_directories_selected['alias_for'] ?? '';
|
||||
if (!empty($dir_alias)) {
|
||||
//If so load in the data for that directory
|
||||
$filePathMap_directories_selected = $filePathMap_directories[$dir_alias];
|
||||
}
|
||||
|
||||
//Gather all the options into variables
|
||||
$setting_value = $filePathMap_directories_selected['read_setting'] ?? '';
|
||||
$lives_under = $filePathMap_directories_selected['lives_under'] ?? '';
|
||||
$replace_text = $filePathMap_directories_selected['replace_setting_text'] ?? '';
|
||||
$replace_text_with = $filePathMap_directories_selected['replace_setting_text_with'] ?? '';
|
||||
$append = $filePathMap_directories_selected['append'] ?? '';
|
||||
$return_var = $filePathMap_directories_selected['return_var'] ?? '';
|
||||
//
|
||||
$return_value = $under_directory = '';
|
||||
|
||||
//Get the directory which the directory we're processing lives under
|
||||
if (!empty($lives_under)) {
|
||||
$under_directory = call_user_func('getDirectory', $lives_under);
|
||||
}
|
||||
|
||||
//Read the specified config file setting
|
||||
if (!empty($setting_value)) {
|
||||
$setting_value = $config[$setting_value];
|
||||
}
|
||||
|
||||
//Replace value in setting, like ${RECS_DIR} etc as they are not expanded
|
||||
if (!empty($replace_text)) {
|
||||
$return_value = str_replace($replace_text, $replace_text_with, $setting_value);
|
||||
} else {
|
||||
$return_value = $setting_value;
|
||||
}
|
||||
|
||||
//If a variable is specified for return, return it first
|
||||
if (!empty($return_var)) {
|
||||
//return the dynamic variable, currently this is just the users home path in $home
|
||||
return ${"{$return_var}"};
|
||||
} else if (!empty($append)) {
|
||||
//Append this to the end of the path, (models, scripts etc) do this as they reside under BirdNET-pi
|
||||
return $under_directory . $append;
|
||||
} else {
|
||||
//Else return the directory and result of the setting manipulation
|
||||
return $under_directory . $return_value;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
@@ -1105,85 +1116,49 @@ function getFilePath($filename)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if ($filename == "analyzing_now.txt") {
|
||||
return getDirectory('birdnet_pi') . "/analyzing_now.txt";
|
||||
//
|
||||
} else if ($filename == "apprise.txt") {
|
||||
return getDirectory('birdnet_pi') . "/apprise.txt";
|
||||
//
|
||||
} else if ($filename == "birdnet.conf") {
|
||||
return getDirectory('birdnet_pi') . "/birdnet.conf";
|
||||
//
|
||||
} else if ($filename == "etc_birdnet.conf") {
|
||||
return "/etc/birdnet/birdnet.conf";
|
||||
//
|
||||
} else if ($filename == "BirdDB.txt") {
|
||||
return getDirectory('birdnet_pi') . "/BirdDB.txt";
|
||||
//
|
||||
} else if ($filename == "birds.db") {
|
||||
return getDirectory('scripts') . "/birds.db";
|
||||
//
|
||||
} else if ($filename == "blacklisted_images.txt") {
|
||||
return getDirectory('scripts') . "/blacklisted_images.txt";
|
||||
//
|
||||
} else if ($filename == "disk_check_exclude.txt") {
|
||||
return getDirectory('scripts') . "/disk_check_exclude.txt";
|
||||
//
|
||||
} else if ($filename == "email_template") {
|
||||
return getDirectory('scripts') . "/email_template";
|
||||
//
|
||||
} else if ($filename == "email_template2") {
|
||||
return getDirectory('scripts') . "/email_template2";
|
||||
//
|
||||
} else if ($filename == "exclude_species_list.txt") {
|
||||
return getDirectory('scripts') . "/exclude_species_list.txt";
|
||||
//
|
||||
} else if ($filename == "firstrun.ini") {
|
||||
return getDirectory('birdnet_pi') . "/firstrun.ini";
|
||||
//
|
||||
} else if ($filename == ".gotty") {
|
||||
return getDirectory('home') . "/.gotty";
|
||||
//
|
||||
} else if ($filename == "HUMAN.txt") {
|
||||
return getDirectory('birdnet_pi') . "/HUMAN.txt";
|
||||
//
|
||||
} else if ($filename == "IdentifiedSoFar.txt" ||$filename == "IDFILE" ) {
|
||||
$id_file_setting = $config['IDFILE'];
|
||||
return getDirectory('home') . str_replace('$HOME', '', $id_file_setting);
|
||||
//
|
||||
} else if ($filename == "include_species_list.txt") {
|
||||
return getDirectory('scripts') . "/include_species_list.txt";
|
||||
//
|
||||
} else if ($filename == "labels.txt" || $filename == "labels.txt.old") {
|
||||
return getDirectory('model') . "/$filename";
|
||||
//
|
||||
} else if ($filename == "labels_flickr.txt") {
|
||||
return getDirectory('model') . "/labels_flickr.txt";
|
||||
//
|
||||
} else if ($filename == "labels_l18n.zip") {
|
||||
return getDirectory('model') . "/labels_l18n.zip";
|
||||
//
|
||||
} else if ($filename == "labels_lang.txt") {
|
||||
return getDirectory('model') . "/labels_lang.txt";
|
||||
//
|
||||
} else if ($filename == "labels_nm.zip") {
|
||||
return getDirectory('model') . "/labels_nm.zip";
|
||||
//
|
||||
} else if ($filename == "lastrun.txt") {
|
||||
return getDirectory('scripts') . "/lastrun.txt";
|
||||
//
|
||||
} else if ($filename == "python3") {
|
||||
return getDirectory('python3_ve') . "/python3 ";
|
||||
//
|
||||
} else if ($filename == "python3_appraise") {
|
||||
return getDirectory('python3_ve') . "/apprise ";
|
||||
//
|
||||
} else if ($filename == "species.py") {
|
||||
return getDirectory('scripts') . "/species.py";
|
||||
//
|
||||
} else if ($filename == "thisrun.txt") {
|
||||
return getDirectory('scripts') . "/thisrun.txt";
|
||||
$filePathMap_files = loadFilePathMap()['files'];
|
||||
|
||||
if (array_key_exists($filename, $filePathMap_files)) {
|
||||
$filePathMap_directories_selected = $filePathMap_files[$filename];
|
||||
|
||||
//Gather all the options into variables
|
||||
$setting_value = $filePathMap_directories_selected['read_setting'] ?? '';
|
||||
$lives_under = $filePathMap_directories_selected['lives_under'] ?? '';
|
||||
$replace_text = $filePathMap_directories_selected['replace_setting_text'] ?? '';
|
||||
$replace_test_with = $filePathMap_directories_selected['replace_setting_text_with'] ?? '';
|
||||
$append = $filePathMap_directories_selected['append'] ?? '';
|
||||
$return_val = $filePathMap_directories_selected['return_var'] ?? '';
|
||||
//
|
||||
$under_directory = '';
|
||||
|
||||
//Get the directory which the directory we're processing lives under
|
||||
if (!empty($lives_under)) {
|
||||
$under_directory = call_user_func('getDirectory', $lives_under);
|
||||
}
|
||||
|
||||
//Read the specified config file setting if any
|
||||
if (!empty($setting_value)) {
|
||||
$setting_value = $config[$setting_value];
|
||||
}
|
||||
|
||||
//Replace value in setting, like ${RECS_DIR} etc as they are not expanded
|
||||
if (!empty($replace_text)) {
|
||||
$return_value = str_replace($replace_text, $replace_test_with, $setting_value);
|
||||
} else {
|
||||
$return_value = $setting_value;
|
||||
}
|
||||
|
||||
//If a variable is specified for return, return it first and directly
|
||||
if (!empty($return_val)) {
|
||||
//return the dynamic variable, currently this is just the users home path in $home
|
||||
return $return_val;
|
||||
} else if (!empty($append)) {
|
||||
//Append this to the end of the path, (models, scripts etc) do this as they reside under BirdNET-pi
|
||||
return $under_directory . $append;
|
||||
} else {
|
||||
//Else return the directory and result of the setting manipulation
|
||||
return $under_directory . $return_value;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
|
||||
@@ -17,6 +17,13 @@ function test()
|
||||
foreach (TEST_HOMES as $_test_home) {
|
||||
$home = $_test_home;
|
||||
|
||||
############################
|
||||
## Directory Path Tests
|
||||
############################
|
||||
$result = getDirectory('home');
|
||||
$expected = $_test_home;
|
||||
($result == $expected) ?: (print "failed directory 'home', expected: " . ($expected) . " got: " . ($result) . "\r\n");
|
||||
|
||||
# DIRECTORY TESTS
|
||||
$result = getDirectory('birdnet_pi');
|
||||
$expected = $_test_home . "/BirdNET-Pi";
|
||||
@@ -78,8 +85,9 @@ function test()
|
||||
$expected = $_test_home . "/BirdNET-Pi/homepage/static";
|
||||
($result == $expected) ?: (print "failed directory 'web_fonts', expected: " . ($expected) . " got: " . ($result) . "\r\n");
|
||||
|
||||
|
||||
############################
|
||||
# FILE PATH TESTS
|
||||
############################
|
||||
$result = getFilePath('analyzing_now.txt');
|
||||
$expected = $_test_home . "/BirdNET-Pi/analyzing_now.txt";
|
||||
($result == $expected) ?: (print "failed file path 'analyzing_now.txt', expected: " . ($expected) . " got: " . ($result) . "\r\n");
|
||||
@@ -128,6 +136,10 @@ function test()
|
||||
$expected = $_test_home . "/BirdNET-Pi/firstrun.ini";
|
||||
($result == $expected) ?: (print "failed file path 'firstrun.ini', expected: " . ($expected) . " got: " . ($result) . "\r\n");
|
||||
|
||||
$result = getFilePath('filepath_map.json');
|
||||
$expected = $_test_home . "/BirdNET-Pi/config/filepath_map.json";
|
||||
($result == $expected) ?: (print "failed file path 'filepath_map.json', expected: " . ($expected) . " got: " . ($result) . "\r\n");
|
||||
|
||||
$result = getFilePath('.gotty');
|
||||
$expected = $_test_home . "/.gotty";
|
||||
($result == $expected) ?: (print "failed file path '.gotty', expected: " . ($expected) . " got: " . ($result) . "\r\n");
|
||||
|
||||
Reference in New Issue
Block a user