kopia lustrzana https://github.com/OpenDroneMap/NodeODM
Started working on options parser
rodzic
60a682b75a
commit
0d605d4722
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
'''
|
||||
Node-OpenDroneMap Node.js App and REST API to access OpenDroneMap.
|
||||
Copyright (C) 2016 Node-OpenDroneMap Contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
import sys
|
||||
import imp
|
||||
import argparse
|
||||
import json
|
||||
|
||||
imp.load_source('context', sys.argv[2] + '/opendm/context.py')
|
||||
odm = imp.load_source('config', sys.argv[2] + '/opendm/config.py')
|
||||
|
||||
options = {}
|
||||
class ArgumentParserStub(argparse.ArgumentParser):
|
||||
def add_argument(self, *args, **kwargs):
|
||||
argparse.ArgumentParser.add_argument(self, *args, **kwargs)
|
||||
options[args[0]] = {}
|
||||
for name, value in kwargs.items():
|
||||
options[args[0]][str(name)] = str(value)
|
||||
|
||||
odm.parser = ArgumentParserStub()
|
||||
odm.config()
|
||||
print json.dumps(options)
|
6
index.js
6
index.js
|
@ -158,7 +158,7 @@ process.on ('SIGINT', gracefulShutdown);
|
|||
// Startup
|
||||
let taskManager;
|
||||
let server;
|
||||
|
||||
/*
|
||||
async.series([
|
||||
cb => { taskManager = new TaskManager(cb); },
|
||||
cb => { server = app.listen(3000, err => {
|
||||
|
@ -168,4 +168,6 @@ async.series([
|
|||
}
|
||||
], err => {
|
||||
if (err) console.log("Error during startup: " + err.message);
|
||||
});
|
||||
});*/
|
||||
let odmOptionsParser = require('./libs/odmOptionsParser');
|
||||
odmOptionsParser.getOptions(function(){});
|
||||
|
|
|
@ -137,7 +137,7 @@ module.exports = class Task{
|
|||
this.setStatus(statusCodes.CANCELED);
|
||||
|
||||
if (wasRunning && this.runnerProcess){
|
||||
// TODO: this does guarantee that
|
||||
// TODO: this does NOT guarantee that
|
||||
// the process will immediately terminate.
|
||||
// In fact, often times ODM will continue running for a while
|
||||
// This might need to be fixed on ODM's end.
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Node-OpenDroneMap Node.js App and REST API to access OpenDroneMap.
|
||||
Copyright (C) 2016 Node-OpenDroneMap Contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
"use strict";
|
||||
let odmRunner = require('./odmRunner');
|
||||
|
||||
module.exports = {
|
||||
getOptions: function(done){
|
||||
odmRunner.getJsonOptions((err, json) => {
|
||||
if (err) done(err);
|
||||
else{
|
||||
for (let option in json){
|
||||
if (option === "-h") continue;
|
||||
let values = json[option];
|
||||
|
||||
let type = "";
|
||||
let defaultValue = "";
|
||||
let help = values.help || "";
|
||||
let range = values.metavar.replace(/[<>]/g, "").trim();
|
||||
|
||||
switch(values.type.trim()){
|
||||
case "<type 'int'>":
|
||||
type = "int";
|
||||
defaultValue = values['default'] !== undefined ?
|
||||
parseInt(values['default']) :
|
||||
0;
|
||||
break;
|
||||
case "<type 'float'>":
|
||||
type = "float";
|
||||
defaultValue = values['default'] !== undefined ?
|
||||
parseFloat(values['default']) :
|
||||
0.0;
|
||||
break;
|
||||
default:
|
||||
type = "string";
|
||||
defaultValue = values['default'].trim();
|
||||
}
|
||||
|
||||
if (values['default'] === "True"){
|
||||
type = "bool";
|
||||
defaultValue = true;
|
||||
}else if (values['default'] === "False"){
|
||||
type = "bool";
|
||||
defaultValue = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
let result = {
|
||||
type, defaultValue, range, help
|
||||
};
|
||||
|
||||
console.log(values);
|
||||
console.log(result);
|
||||
console.log('-----');
|
||||
}
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
|
@ -44,5 +44,30 @@ module.exports = {
|
|||
});
|
||||
|
||||
return childProcess;
|
||||
},
|
||||
|
||||
getJsonOptions: function(done){
|
||||
// Launch
|
||||
let childProcess = spawn("python", [`${__dirname}/../helpers/odmOptionsToJson.py`,
|
||||
"--project-path", ODM_PATH]);
|
||||
let output = [];
|
||||
|
||||
childProcess
|
||||
.on('exit', (code, signal) => {
|
||||
try{
|
||||
let json = JSON.parse(output.join(""));
|
||||
done(null, json);
|
||||
}catch(err){
|
||||
done(err);
|
||||
}
|
||||
})
|
||||
.on('error', done);
|
||||
|
||||
let processOutput = chunk => {
|
||||
output.push(chunk.toString());
|
||||
};
|
||||
|
||||
childProcess.stdout.on('data', processOutput);
|
||||
childProcess.stderr.on('data', processOutput);
|
||||
}
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue