kopia lustrzana https://github.com/OpenDroneMap/NodeODM
Merge pull request #119 from pierotofy/pynightmare
Deal with Python2 warnings for parsing ODM optionspierotofy-patch-1
commit
fd929e2766
|
@ -17,7 +17,4 @@ COPY . /var/www
|
|||
|
||||
RUN npm install && mkdir tmp
|
||||
|
||||
# Temporary fix to cryptography warning
|
||||
RUN pip install cryptography==2.9.2
|
||||
|
||||
ENTRYPOINT ["/usr/bin/nodejs", "/var/www/index.js"]
|
||||
|
|
|
@ -21,6 +21,9 @@ import sys
|
|||
import imp
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
|
||||
dest_file = os.environ.get("ODM_OPTIONS_TMP_FILE")
|
||||
|
||||
sys.path.append(sys.argv[2])
|
||||
|
||||
|
@ -43,4 +46,9 @@ class ArgumentParserStub(argparse.ArgumentParser):
|
|||
|
||||
odm.parser = ArgumentParserStub()
|
||||
odm.config()
|
||||
print json.dumps(options)
|
||||
out = json.dumps(options)
|
||||
print(out)
|
||||
if dest_file is not None:
|
||||
with open(dest_file, "w") as f:
|
||||
f.write(out)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ let assert = require('assert');
|
|||
let spawn = require('child_process').spawn;
|
||||
let config = require('../config.js');
|
||||
let logger = require('./logger');
|
||||
|
||||
let utils = require('./utils');
|
||||
|
||||
module.exports = {
|
||||
run: function(options, projectName, done, outputReceived){
|
||||
|
@ -113,24 +113,37 @@ module.exports = {
|
|||
}
|
||||
|
||||
// Launch
|
||||
const env = utils.clone(process.env);
|
||||
env.ODM_OPTIONS_TMP_FILE = utils.tmpPath(".json");
|
||||
let childProcess = spawn("python", [path.join(__dirname, "..", "helpers", "odmOptionsToJson.py"),
|
||||
"--project-path", config.odm_path, "bogusname"]);
|
||||
let output = [];
|
||||
"--project-path", config.odm_path, "bogusname"], { env });
|
||||
|
||||
// Cleanup on done
|
||||
let handleResult = (err, result) => {
|
||||
fs.exists(env.ODM_OPTIONS_TMP_FILE, exists => {
|
||||
if (exists) fs.unlink(env.ODM_OPTIONS_TMP_FILE, err => {
|
||||
if (err) console.warning(`Cannot cleanup ${env.ODM_OPTIONS_TMP_FILE}`);
|
||||
});
|
||||
});
|
||||
|
||||
// Don't wait
|
||||
done(err, result);
|
||||
};
|
||||
|
||||
childProcess
|
||||
.on('exit', (code, signal) => {
|
||||
try{
|
||||
let json = JSON.parse(output.join(""));
|
||||
done(null, json);
|
||||
fs.readFile(env.ODM_OPTIONS_TMP_FILE, { encoding: "utf8" }, (err, data) => {
|
||||
if (err) handleResult(new Error(`Cannot read list of options from ODM (from temporary file). Is ODM installed in ${config.odm_path}?`));
|
||||
else{
|
||||
let json = JSON.parse(data);
|
||||
handleResult(null, json);
|
||||
}
|
||||
});
|
||||
}catch(err){
|
||||
done(new Error(`Could not load list of options from OpenDroneMap. Is OpenDroneMap installed in ${config.odm_path}? Make sure that OpenDroneMap is installed and that --odm_path is set properly: ${err.message}`));
|
||||
handleResult(new Error(`Could not load list of options from ODM. Is ODM installed in ${config.odm_path}? Make sure that OpenDroneMap is installed and that --odm_path is set properly: ${err.message}`));
|
||||
}
|
||||
})
|
||||
.on('error', done);
|
||||
|
||||
let processOutput = chunk => output.push(chunk.toString());
|
||||
|
||||
childProcess.stdout.on('data', processOutput);
|
||||
childProcess.stderr.on('data', processOutput);
|
||||
.on('error', handleResult);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const crypto = require('crypto');
|
||||
|
||||
module.exports = {
|
||||
get: function(scope, prop, defaultValue){
|
||||
|
@ -48,5 +50,9 @@ module.exports = {
|
|||
|
||||
clone: function(json){
|
||||
return JSON.parse(JSON.stringify(json));
|
||||
},
|
||||
|
||||
tmpPath: function(extension = ".txt"){
|
||||
return path.join(os.tmpdir(), `nodeodm_${crypto.randomBytes(6).readUIntLE(0,6).toString(36)}${extension}`);
|
||||
}
|
||||
};
|
Ładowanie…
Reference in New Issue