Merge pull request #119 from pierotofy/pynightmare

Deal with Python2 warnings for parsing ODM options
pierotofy-patch-1
Piero Toffanin 2020-08-03 15:17:46 -04:00 zatwierdzone przez GitHub
commit fd929e2766
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 40 dodań i 16 usunięć

Wyświetl plik

@ -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"]

Wyświetl plik

@ -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)

Wyświetl plik

@ -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);
}
};

Wyświetl plik

@ -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}`);
}
};