Remove force flags and update extractor/contractor hashes

with command line arguments and argument files data.
This commit is contained in:
Michael Krasnyk 2016-05-26 07:05:44 +02:00
parent 797f2a196b
commit aaa27333ba
No known key found for this signature in database
GPG Key ID: A277FCFBE39A658D
5 changed files with 57 additions and 35 deletions

View File

@ -228,14 +228,17 @@ module.exports = function () {
});
this.Given(/^the raster source$/, (data, callback) => {
this.updateFingerprintExtract(data);
fs.writeFile(path.resolve(this.TEST_FOLDER, 'rastersource.asc'), data, callback);
});
this.Given(/^the speed file$/, (data, callback) => {
this.updateFingerprintContract(data);
fs.writeFile(path.resolve(this.TEST_FOLDER, 'speeds.csv'), data, callback);
});
this.Given(/^the turn penalty file$/, (data, callback) => {
this.updateFingerprintContract(data);
fs.writeFile(path.resolve(this.TEST_FOLDER, 'penalties.csv'), data, callback);
});
@ -249,11 +252,13 @@ module.exports = function () {
});
this.Given(/^the data has been extracted$/, (callback) => {
this.osmData.populate(() => {
this.writeAndExtract((err) => {
if (err) this.processError = err;
callback();
});
});
});
this.Given(/^the data has been contracted$/, (callback) => {
this.reprocess((err) => {

View File

@ -59,7 +59,6 @@ module.exports = function () {
var hashContract = (cb) => {
this.hashOfFiles(util.format('%s/osrm-contract%s', this.BIN_PATH, this.EXE), (hash) => {
this.binContractHash = hash;
this.fingerprintContract = this.hashString(this.binContractHash);
cb();
});
};
@ -79,16 +78,18 @@ module.exports = function () {
.defer(hashContract)
.defer(hashRouted)
.awaitAll(() => {
this.fingerprintExtract = this.hashString([this.profileHash, this.luaLibHash, this.binExtractHash].join('-'));
this.AfterConfiguration(() => {
callback();
});
});
};
this.setProfileBasedHashes = () => {
this.fingerprintExtract = this.hashString([this.profileHash, this.luaLibHash, this.binExtractHash].join('-'));
this.fingerprintContract = this.hashString(this.binContractHash);
this.updateFingerprintExtract = (str) => {
this.fingerprintExtract = this.hashString([this.fingerprintExtract, str].join('-'));
};
this.updateFingerprintContract = (str) => {
this.fingerprintContract = this.hashString([this.fingerprintContract, str].join('-'));
};
this.setProfile = (profile, cb) => {
@ -97,22 +98,24 @@ module.exports = function () {
this.profile = profile;
this.hashProfile((hash) => {
this.profileHash = hash;
this.setProfileBasedHashes();
this.updateFingerprintExtract(this.profileHash);
cb();
});
} else cb();
} else {
this.updateFingerprintExtract(this.profileHash);
cb();
}
};
this.setExtractArgs = (args, callback) => {
this.extractArgs = args;
this.forceExtract = true;
this.forceContract = true;
this.updateFingerprintExtract(args);
callback();
};
this.setContractArgs = (args, callback) => {
this.contractArgs = args;
this.forceContract = true;
this.updateFingerprintContract(args);
callback();
};
};

View File

@ -260,6 +260,13 @@ module.exports = function () {
});
};
var renameIfExists = (file, cb) => {
fs.stat([this.osmData.extractedFile, file].join('.'), (doesNotExistErr, exists) => {
if (exists) rename(file, cb);
else cb();
});
};
var copy = (file, cb) => {
this.log(util.format('Copying %s.%s to %s.%s', this.osmData.extractedFile, file, this.osmData.contractedFile, file), 'preprocess');
fs.createReadStream([this.osmData.extractedFile, file].join('.'))
@ -273,11 +280,15 @@ module.exports = function () {
var q = d3.queue();
['osrm.hsgr','osrm.fileIndex','osrm.geometry','osrm.nodes','osrm.ramIndex','osrm.core','osrm.edges','osrm.datasource_indexes','osrm.datasource_names','osrm.level','osrm.icd'].forEach((file) => {
['osrm.hsgr','osrm.ebg','osrm.enw','osrm.level','osrm.core','osrm.fileIndex','osrm.geometry','osrm.nodes','osrm.ramIndex','osrm.edges','osrm.datasource_indexes','osrm.datasource_names','osrm.icd','osrm.names','osrm.restrictions','osrm.properties','osrm'].forEach((file) => {
q.defer(rename, file);
});
['osrm.names','osrm.restrictions','osrm.properties','osrm'].forEach((file) => {
['osrm.edge_segment_lookup','osrm.edge_penalties'].forEach(file => {
q.defer(renameIfExists, file);
});
[].forEach((file) => {
q.defer(copy, file);
});
@ -292,35 +303,36 @@ module.exports = function () {
var noop = (cb) => cb();
this.reprocess = (callback) => {
this.osmData.populate(() => {
this.isContracted((isContracted) => {
if (!isContracted) {
this.writeAndExtract((e) => {
if (e) return callback(e);
this.isContracted((isContracted) => {
var contractFn = (isContracted && !this.forceContract) ? noop : this.contractData;
if (isContracted) this.log('Already contracted ' + this.osmData.contractedFile, 'preprocess');
contractFn((e) => {
this.forceContract = false;
this.contractData((e) => {
if (e) return callback(e);
this.logPreprocessDone();
callback();
});
});
} else {
this.log('Already contracted ' + this.osmData.contractedFile, 'preprocess');
callback();
}
});
});
};
this.writeAndExtract = (callback) => {
this.osmData.populate(() => {
this.writeInputData((e) => {
if (e) return callback(e);
this.isExtracted((isExtracted) => {
var extractFn = (isExtracted && !this.forceExtract) ? noop : this.extractData;
var extractFn = isExtracted ? noop : this.extractData;
if (isExtracted) this.log('Already extracted ' + this.osmData.extractedFile, 'preprocess');
extractFn((e) => {
this.forceExtract = false;
callback(e);
});
});
});
});
};
this.reprocessAndLoadData = (callback) => {

View File

@ -20,6 +20,8 @@ module.exports = function () {
this.hasLoggedScenarioInfo = false;
this.setGridSize(this.DEFAULT_GRID_SIZE);
this.setOrigin(this.DEFAULT_ORIGIN);
this.fingerprintExtract = this.hashString([this.luaLibHash, this.binExtractHash].join('-'));
this.fingerprintContract = this.hashString(this.binContractHash);
callback();
});