configure the app to work in any environment
This commit is contained in:
parent
dd79b88b3c
commit
014f6a3135
65
addrbook.rex
65
addrbook.rex
@ -10,7 +10,11 @@
|
||||
**************************************************************************/
|
||||
signal on HALT name ProgramHalt
|
||||
.environment['STOPNOW'] = 0
|
||||
call setEnv
|
||||
rc = setEnv("./config.json")
|
||||
if rc \= 0 then do
|
||||
say "Configuration failed."
|
||||
exit rc
|
||||
end
|
||||
|
||||
app = .AddressBookApp~new()
|
||||
app~run()
|
||||
@ -51,20 +55,59 @@ Exit
|
||||
db~closeDb()
|
||||
return
|
||||
|
||||
::ROUTINE setEnv
|
||||
.environment~home = SysGetpwnam("gmgauthier", "d")
|
||||
.environment~projectRoot = .home||"/Projects/rexx-address-book"
|
||||
.environment~pkgPath = .projectRoot||"/app"
|
||||
.environment~dbPath = .projectRoot||"/db"
|
||||
.environment~dbFile = .dbPath||"/contacts.sqlite"
|
||||
.environment["REXX_PATH"] = .projectRoot||";"||.pkgPath||";"||.dbPath||";"
|
||||
/******** HELPER FUNCTIONS ****************/
|
||||
|
||||
/* Configuration Retrieval */
|
||||
::ROUTINE setConfig
|
||||
use arg filespec
|
||||
|
||||
file = .Stream~new(filespec)
|
||||
json_string = ""
|
||||
do file~lines
|
||||
json_string = json_string||file~lineIn
|
||||
end
|
||||
json_config = .json~new()~fromJSON(json_string)
|
||||
Do index over json_config~allIndexes
|
||||
val = json_config[index]
|
||||
INTERPRET '.environment~'index' = "'val'"'
|
||||
END
|
||||
return 0
|
||||
|
||||
/** SET ENV **/
|
||||
::ROUTINE setEnv
|
||||
use arg configFilePath
|
||||
|
||||
rc = 0
|
||||
.environment~home = SysGetpwuid(SysGetuid(), "d")
|
||||
if configFilePath = .nil | configFilePath = '' then do
|
||||
configFilePath = .environment~home||"/.config/rexx-address-book/config.json" /* assume its in the same location */
|
||||
Say "No config specified. Default will be used at : "configFilePath
|
||||
END
|
||||
|
||||
if SysFileExists(configFilePath) then do
|
||||
call setConfig(configFilePath)
|
||||
/* set up the database config */
|
||||
IF .environment~dbFile = .nil then do
|
||||
.environment~dbFile = .environment~home||"/.local/share/rexx-address-book/rexx-address-book/contacts.db"
|
||||
say "Config has no detabase specified. A default will be created at: ".environment~dbFile
|
||||
END
|
||||
IF \SysFileExists(.environment~dbFile) then do
|
||||
say "Specified database not found. A new database will be created."
|
||||
END
|
||||
END
|
||||
else do
|
||||
say "No config file Not Found at: "configFilePath
|
||||
rc = -1
|
||||
END
|
||||
|
||||
return rc
|
||||
|
||||
/** External Libraries **/
|
||||
::requires 'app/appdb.cls'
|
||||
::requires 'app/appui.cls'
|
||||
::requires 'app/utils.rex'
|
||||
::requires 'appdb.cls'
|
||||
::requires 'appui.cls'
|
||||
::requires 'utils.rex'
|
||||
|
||||
::requires 'ooSQLite.cls'
|
||||
::requires "rxunixsys" LIBRARY
|
||||
::requires 'ncurses.cls'
|
||||
::requires 'json.cls'
|
@ -1,11 +1,12 @@
|
||||
::ROUTINE SysWait PUBLIC
|
||||
use arg seconds
|
||||
address system 'sleep' seconds
|
||||
return
|
||||
use arg seconds
|
||||
address system 'sleep' seconds
|
||||
return
|
||||
|
||||
|
||||
/* Handle program termination */
|
||||
::ROUTINE ProgramHalt
|
||||
signal off halt
|
||||
Say "PROGRAM TERMINATED AT THE KEYBOARD"
|
||||
exit 0
|
||||
exit 0
|
||||
|
||||
|
3
config.json
Normal file
3
config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"dbFile":"/home/gmgauthier/Projects/rexx-address-book/db/contacts.sqlite"
|
||||
}
|
Loading…
Reference in New Issue
Block a user