20 QObject(parent), m_status(Waiting), m_region(region), m_parameters(parameters)
32 return m_statusMessage;
57 m_monavSettings = filename;
62 return m_transport == other.m_transport && m_region == other.m_region;
67 if (download() && monav() &&
search() && package() && upload()) {
75 void Job::changeStatus(
Job::Status status,
const QString &message)
79 case Waiting: statusType =
"waiting";
break;
80 case Downloading: statusType =
"downloading";
break;
81 case Routing: statusType =
"routing";
break;
82 case Search: statusType =
"search";
break;
83 case Packaging: statusType =
"packaging";
break;
84 case Uploading: statusType =
"uploading";
break;
85 case Finished: statusType =
"finished";
break;
86 case Error: statusType =
"error";
break;
90 m_region.
name() + QLatin1String(
" (" ) + m_transport +
')', statusType, message);
91 m_statusMessage = message;
98 qDebug() <<
"Saving file to " << osmFile().absoluteFilePath();
99 if (osmFile().exists()) {
100 QDateTime now = QDateTime::currentDateTime();
101 if (osmFile().lastModified().daysTo(now) > 7) {
102 qDebug() <<
"Old file is outdated, re-downloading " << osmFile().absoluteFilePath();
103 QFile::remove(osmFile().absoluteFilePath());
105 qDebug() <<
"Old file is still ok, reusing" << osmFile().absoluteFilePath();
111 QStringList arguments;
112 QString url = m_region.
pbfFile();
113 arguments <<
"-O" << osmFile().absoluteFilePath() << url;
114 qDebug() <<
"Downloading " << url;
115 wget.start(
"wget", arguments);
116 wget.waitForFinished(1000 * 60 * 60 * 12);
117 if (wget.exitStatus() == QProcess::NormalExit && wget.exitCode() == 0) {
120 qDebug() <<
"Failed to download " << url;
121 QFile::remove(osmFile().absoluteFilePath());
122 changeStatus(
Error,
"Error downloading .osm.pbf file: " + wget.readAllStandardError());
153 QString
const status = QString(
"Generating offline routing map from %1 (%2).").arg(osmFile().fileName()).arg(
Region::fileSize(osmFile()));
155 QStringList arguments;
156 arguments <<
"-s=" + m_monavSettings;
157 arguments <<
"-i=" + osmFile().absoluteFilePath();
158 arguments <<
"-o=" + monavDir().absoluteFilePath();
159 arguments <<
"-pi=OpenStreetMap Importer" <<
"-pro=Contraction Hierarchies";
160 arguments <<
"-pg=GPS Grid" <<
"-di";
161 arguments <<
"-dro=" + m_transport;
162 arguments <<
"--profile=" + m_profile;
165 monav.start(
"monav-preprocessor", arguments);
166 monav.waitForFinished(1000 * 60 * 60 * 6);
167 if (monav.exitStatus() == QProcess::NormalExit && monav.exitCode() == 0) {
168 qDebug() <<
"Processed osm file for monav";
170 qDebug() <<
"monav exiting with status " << monav.exitCode();
171 changeStatus(
Error,
"Routing map conversion failed: " + monav.readAllStandardError());
175 QFile pluginsFile(monavDir().absoluteFilePath() +
"/plugins.ini");
176 pluginsFile.open(QFile::WriteOnly | QFile::Truncate);
177 QTextStream pluginsStream(&pluginsFile);
178 pluginsStream <<
"[General]\nrouter=Contraction Hierarchies\nrenderer=Mapnik Renderer\ngpsLookup=GPS Grid\naddressLookup=Unicode Tournament Trie\n";
181 QFileInfo subdir = QFileInfo(monavDir().absoluteFilePath() +
"/routing_" + m_transport.toLower());
182 if (subdir.exists() && subdir.isDir()) {
183 QFileInfoList files = QDir(subdir.absoluteFilePath()).entryInfoList(QDir::Files);
184 foreach(
const QFileInfo &file, files) {
185 if (!QFile::rename(file.absoluteFilePath(), monavDir().absoluteFilePath() +
'/' + file.fileName())) {
186 changeStatus(
Error,
"Unable to move monav files to target directory.");
190 QDir(
"/").rmdir(subdir.absoluteFilePath());
192 changeStatus(
Error,
"Unable to find files created by monav");
201 QString
const status = QString(
"Generating offline search database from %1 (%2).").arg(osmFile().fileName()).arg(
Region::fileSize(osmFile()));
202 changeStatus(
Search, status);
203 QStringList arguments;
204 arguments <<
"--name" << m_region.
name();
205 arguments <<
"--version" <<
"0.3";
206 arguments <<
"--date" << QDateTime::currentDateTime().toString(
"MM/dd/yy");
207 arguments <<
"--transport" << m_transport;
208 arguments <<
"--payload" << targetFile().fileName();
209 arguments << osmFile().absoluteFilePath();
210 arguments << searchFile().absoluteFilePath();
211 QFileInfo kmlFile(monavDir().absoluteFilePath() +
"/marble.kml");
212 arguments << kmlFile.absoluteFilePath();
213 QProcess osmAddresses;
214 osmAddresses.start(
"osm-addresses", arguments);
215 osmAddresses.waitForFinished(1000 * 60 * 60 * 18);
216 if (osmAddresses.exitStatus() == QProcess::NormalExit && osmAddresses.exitCode() == 0) {
217 searchFile().refresh();
218 if (!searchFile().exists()) {
219 qDebug() <<
"osm-addresses did not create the .sqlite file";
220 changeStatus(
Error,
"Unknown error when creating the search database");
222 }
else if (searchFile().size() < 8000) {
223 qDebug() <<
"The .sqlite database has a suspiciously small size.";
224 changeStatus(
Error,
"Search database is too small. Too little memory?");
229 if (!kmlFile.exists()) {
230 qDebug() <<
"File marble.kml has not been generated.";
231 changeStatus(
Error,
"Failed to generate marble.kml. Too little memory?");
237 qDebug() <<
"osm-addresses exiting with status " << osmAddresses.exitCode();
238 changeStatus(
Error,
"Error creating search database: " + osmAddresses.readAllStandardError());
245 changeStatus(
Packaging,
"Creating archive.");
246 QStringList arguments;
247 arguments <<
"czf" << targetFile().absoluteFilePath() <<
"earth/monav/" <<
"earth/placemarks";
249 tar.setWorkingDirectory(m_parameters.
base().absolutePath() +
"/data/" + m_region.
id());
250 tar.start(
"tar", arguments);
251 tar.waitForFinished(1000 * 60 * 60);
252 if (tar.exitStatus() == QProcess::NormalExit && tar.exitCode() == 0) {
253 qDebug() <<
"Packaged tar file";
256 changeStatus(
Error,
"Packaging failed: " + tar.readAllStandardError());
263 changeStatus(
Uploading,
"Uploading file");
264 if (targetFile().exists()) {
269 changeStatus(
Error,
"Target file does not exist.");
276 QFile::remove(osmFile().absoluteFilePath());
279 QFileInfo subdir = QFileInfo(monavDir().absoluteFilePath());
280 if (subdir.exists() && subdir.isDir()) {
281 QFileInfoList files = QDir(subdir.absoluteFilePath()).entryInfoList(QDir::Files);
282 foreach(
const QFileInfo &file, files) {
283 QFile::remove(file.absoluteFilePath());
287 QFile::remove(searchFile().absoluteFilePath());
291 QFileInfo Job::osmFile()
293 m_parameters.
base().mkdir(
"download");
294 QFileInfo result(m_parameters.
base(), QString(
"download/") + m_region.
id() +
".osm.pbf");
298 QFileInfo Job::monavDir()
300 QString
const subdir =
"data/" + m_region.
id() +
"/earth/monav/" + m_transport.toLower() +
'/' + m_region.
path();
301 m_parameters.
base().mkpath(subdir);
302 QFileInfo result(m_parameters.
base(), subdir);
306 QFileInfo Job::targetFile()
308 m_parameters.
base().mkdir(
"finished");
309 QFileInfo result(m_parameters.
base(),
"finished/" + m_region.
id() +
'_' + m_transport.toLower() +
".tar.gz");
313 QFileInfo Job::searchFile()
315 QString
const subdir =
"data/" + m_region.
id() +
"/earth/placemarks/" + QFileInfo(m_region.
path()).path();
316 m_parameters.
base().mkpath(subdir);
317 QFileInfo result(m_parameters.
base(), subdir +
'/' + m_region.
id() +
".sqlite");
void setTransport(const QString &transport)
void uploadAndDelete(const Region ®ion, const QFileInfo &file, const QString &transport)
void setProfile(const QString &profile)
void setMonavSettings(const QString &filename)
QString transport() const
void setStatus(const QString &id, const QString &name, const QString &status, const QString &message)
static Upload & instance()
QString statusMessage() const
static Logger & instance()
Job(const Region ®ion, const JobParameters ¶meters, QObject *parent=0)
bool operator==(const Job &other) const
static QString fileSize(const QFileInfo &file)