Mercurial > hg > svcore
comparison transform/FileFeatureWriter.cpp @ 689:573d45e9487b
Merge from debug-output branch
author | Chris Cannam |
---|---|
date | Tue, 14 Jun 2011 14:47:59 +0100 |
parents | 06f13a3b9e9e |
children | 1424aa29ae95 |
comparison
equal
deleted
inserted
replaced
688:be43b2fe68e8 | 689:573d45e9487b |
---|---|
44 if (m_support & SupportOneFilePerTrackTransform) { | 44 if (m_support & SupportOneFilePerTrackTransform) { |
45 m_manyFiles = true; | 45 m_manyFiles = true; |
46 } else if (m_support & SupportOneFileTotal) { | 46 } else if (m_support & SupportOneFileTotal) { |
47 m_singleFileName = QString("output.%1").arg(m_extension); | 47 m_singleFileName = QString("output.%1").arg(m_extension); |
48 } else { | 48 } else { |
49 cerr << "FileFeatureWriter::FileFeatureWriter: ERROR: Invalid support specification " << support << endl; | 49 DEBUG << "FileFeatureWriter::FileFeatureWriter: ERROR: Invalid support specification " << support << endl; |
50 } | 50 } |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 FileFeatureWriter::~FileFeatureWriter() | 54 FileFeatureWriter::~FileFeatureWriter() |
58 delete m_streams.begin()->second; | 58 delete m_streams.begin()->second; |
59 m_streams.erase(m_streams.begin()); | 59 m_streams.erase(m_streams.begin()); |
60 } | 60 } |
61 while (!m_files.empty()) { | 61 while (!m_files.empty()) { |
62 if (m_files.begin()->second) { | 62 if (m_files.begin()->second) { |
63 cerr << "FileFeatureWriter::~FileFeatureWriter: NOTE: Closing feature file \"" | 63 DEBUG << "FileFeatureWriter::~FileFeatureWriter: NOTE: Closing feature file \"" |
64 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; | 64 << m_files.begin()->second->fileName() << "\"" << endl; |
65 delete m_files.begin()->second; | 65 delete m_files.begin()->second; |
66 } | 66 } |
67 m_files.erase(m_files.begin()); | 67 m_files.erase(m_files.begin()); |
68 } | 68 } |
69 } | 69 } |
126 m_baseDir = i->second.c_str(); | 126 m_baseDir = i->second.c_str(); |
127 } else if (i->first == "many-files") { | 127 } else if (i->first == "many-files") { |
128 if (m_support & SupportOneFilePerTrackTransform && | 128 if (m_support & SupportOneFilePerTrackTransform && |
129 m_support & SupportOneFilePerTrack) { | 129 m_support & SupportOneFilePerTrack) { |
130 if (m_singleFileName != "") { | 130 if (m_singleFileName != "") { |
131 cerr << "FileFeatureWriter::setParameters: WARNING: Both one-file and many-files parameters provided, ignoring many-files" << endl; | 131 DEBUG << "FileFeatureWriter::setParameters: WARNING: Both one-file and many-files parameters provided, ignoring many-files" << endl; |
132 } else { | 132 } else { |
133 m_manyFiles = true; | 133 m_manyFiles = true; |
134 } | 134 } |
135 } | 135 } |
136 } else if (i->first == "one-file") { | 136 } else if (i->first == "one-file") { |
140 // may be on by default (for any FileFeatureWriter | 140 // may be on by default (for any FileFeatureWriter |
141 // that supports OneFilePerTrackTransform but not | 141 // that supports OneFilePerTrackTransform but not |
142 // OneFilePerTrack), so we need to be able to | 142 // OneFilePerTrack), so we need to be able to |
143 // override it | 143 // override it |
144 // if (m_manyFiles) { | 144 // if (m_manyFiles) { |
145 // cerr << "FileFeatureWriter::setParameters: WARNING: Both many-files and one-file parameters provided, ignoring one-file" << endl; | 145 // DEBUG << "FileFeatureWriter::setParameters: WARNING: Both many-files and one-file parameters provided, ignoring one-file" << endl; |
146 // } else { | 146 // } else { |
147 m_singleFileName = i->second.c_str(); | 147 m_singleFileName = i->second.c_str(); |
148 // } | 148 // } |
149 } | 149 } |
150 } | 150 } |
151 } else if (i->first == "stdout") { | 151 } else if (i->first == "stdout") { |
152 if (m_support & SupportOneFileTotal) { | 152 if (m_support & SupportOneFileTotal) { |
153 if (m_singleFileName != "") { | 153 if (m_singleFileName != "") { |
154 cerr << "FileFeatureWriter::setParameters: WARNING: Both stdout and one-file provided, ignoring stdout" << endl; | 154 DEBUG << "FileFeatureWriter::setParameters: WARNING: Both stdout and one-file provided, ignoring stdout" << endl; |
155 } else { | 155 } else { |
156 m_stdout = true; | 156 m_stdout = true; |
157 } | 157 } |
158 } | 158 } |
159 } else if (i->first == "append") { | 159 } else if (i->first == "append") { |
168 FileFeatureWriter::getOutputFilename(QString trackId, | 168 FileFeatureWriter::getOutputFilename(QString trackId, |
169 TransformId transformId) | 169 TransformId transformId) |
170 { | 170 { |
171 if (m_singleFileName != "") { | 171 if (m_singleFileName != "") { |
172 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { | 172 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { |
173 cerr << endl << "FileFeatureWriter: ERROR: Specified output file \"" << m_singleFileName.toStdString() << "\" exists and neither --" << getWriterTag().toStdString() << "-force nor --" << getWriterTag().toStdString() << "-append flag is specified -- not overwriting" << endl; | 173 cerr << endl << "FileFeatureWriter: ERROR: Specified output file \"" << m_singleFileName << "\" exists and neither --" << getWriterTag() << "-force nor --" << getWriterTag() << "-append flag is specified -- not overwriting" << endl; |
174 cerr << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag().toStdString() << "-force" << endl << "and --" << getWriterTag().toStdString() << "-append options" << endl; | 174 DEBUG << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag() << "-force" << endl << "and --" << getWriterTag() << "-append options" << endl; |
175 return ""; | 175 return ""; |
176 } | 176 } |
177 return m_singleFileName; | 177 return m_singleFileName; |
178 } | 178 } |
179 | 179 |
191 basename = QFileInfo(infilename).completeBaseName(); | 191 basename = QFileInfo(infilename).completeBaseName(); |
192 if (scheme.length() == 1) { | 192 if (scheme.length() == 1) { |
193 infilename = scheme + ":" + infilename; // DOS drive! | 193 infilename = scheme + ":" + infilename; // DOS drive! |
194 } | 194 } |
195 | 195 |
196 // cerr << "trackId = " << trackId.toStdString() << ", url = " << url.toString().toStdString() << ", infilename = " | 196 // cerr << "trackId = " << trackId << ", url = " << url.toString() << ", infilename = " |
197 // << infilename.toStdString() << ", basename = " << basename.toStdString() << ", m_baseDir = " << m_baseDir.toStdString() << endl; | 197 // << infilename << ", basename = " << basename << ", m_baseDir = " << m_baseDir << endl; |
198 | 198 |
199 if (m_baseDir != "") dirname = QFileInfo(m_baseDir).absoluteFilePath(); | 199 if (m_baseDir != "") dirname = QFileInfo(m_baseDir).absoluteFilePath(); |
200 else if (local) dirname = QFileInfo(infilename).absolutePath(); | 200 else if (local) dirname = QFileInfo(infilename).absolutePath(); |
201 else dirname = QDir::currentPath(); | 201 else dirname = QDir::currentPath(); |
202 | 202 |
203 // cerr << "dirname = " << dirname.toStdString() << endl; | 203 // cerr << "dirname = " << dirname << endl; |
204 | 204 |
205 QString filename; | 205 QString filename; |
206 | 206 |
207 if (m_manyFiles && transformId != "") { | 207 if (m_manyFiles && transformId != "") { |
208 filename = QString("%1_%2.%3").arg(basename).arg(transformId).arg(m_extension); | 208 filename = QString("%1_%2.%3").arg(basename).arg(transformId).arg(m_extension); |
213 filename.replace(':', '_'); // ':' not permitted in Windows | 213 filename.replace(':', '_'); // ':' not permitted in Windows |
214 | 214 |
215 filename = QDir(dirname).filePath(filename); | 215 filename = QDir(dirname).filePath(filename); |
216 | 216 |
217 if (QFileInfo(filename).exists() && !(m_force || m_append)) { | 217 if (QFileInfo(filename).exists() && !(m_force || m_append)) { |
218 cerr << endl << "FileFeatureWriter: ERROR: Output file \"" << filename.toStdString() << "\" exists (for input file or URL \"" << trackId.toStdString() << "\" and transform \"" << transformId.toStdString() << "\") and neither --" << getWriterTag().toStdString() << "-force nor --" << getWriterTag().toStdString() << "-append is specified -- not overwriting" << endl; | 218 cerr << endl << "FileFeatureWriter: ERROR: Output file \"" << filename << "\" exists (for input file or URL \"" << trackId << "\" and transform \"" << transformId << "\") and neither --" << getWriterTag() << "-force nor --" << getWriterTag() << "-append is specified -- not overwriting" << endl; |
219 cerr << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag().toStdString() << "-force" << endl << "and --" << getWriterTag().toStdString() << "-append options" << endl; | 219 DEBUG << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag() << "-force" << endl << "and --" << getWriterTag() << "-append options" << endl; |
220 return ""; | 220 return ""; |
221 } | 221 } |
222 | 222 |
223 return filename; | 223 return filename; |
224 } | 224 } |
261 | 261 |
262 if (filename == "") { // stdout or failure | 262 if (filename == "") { // stdout or failure |
263 return 0; | 263 return 0; |
264 } | 264 } |
265 | 265 |
266 cerr << "FileFeatureWriter: NOTE: Using output filename \"" | 266 DEBUG << "FileFeatureWriter: NOTE: Using output filename \"" |
267 << filename.toStdString() << "\"" << endl; | 267 << filename << "\"" << endl; |
268 | 268 |
269 if (m_append) { | 269 if (m_append) { |
270 cerr << "FileFeatureWriter: NOTE: Calling reviewFileForAppending" << endl; | 270 DEBUG << "FileFeatureWriter: NOTE: Calling reviewFileForAppending" << endl; |
271 reviewFileForAppending(filename); | 271 reviewFileForAppending(filename); |
272 } | 272 } |
273 | 273 |
274 QFile *file = new QFile(filename); | 274 QFile *file = new QFile(filename); |
275 QIODevice::OpenMode mode = (QIODevice::WriteOnly); | 275 QIODevice::OpenMode mode = (QIODevice::WriteOnly); |
327 | 327 |
328 | 328 |
329 void | 329 void |
330 FileFeatureWriter::finish() | 330 FileFeatureWriter::finish() |
331 { | 331 { |
332 // cerr << "FileFeatureWriter::finish()" << endl; | 332 // DEBUG << "FileFeatureWriter::finish()" << endl; |
333 | 333 |
334 if (m_singleFileName != "" || m_stdout) return; | 334 if (m_singleFileName != "" || m_stdout) return; |
335 | 335 |
336 while (!m_streams.empty()) { | 336 while (!m_streams.empty()) { |
337 m_streams.begin()->second->flush(); | 337 m_streams.begin()->second->flush(); |
338 delete m_streams.begin()->second; | 338 delete m_streams.begin()->second; |
339 m_streams.erase(m_streams.begin()); | 339 m_streams.erase(m_streams.begin()); |
340 } | 340 } |
341 while (!m_files.empty()) { | 341 while (!m_files.empty()) { |
342 if (m_files.begin()->second) { | 342 if (m_files.begin()->second) { |
343 cerr << "FileFeatureWriter::finish: NOTE: Closing feature file \"" | 343 DEBUG << "FileFeatureWriter::finish: NOTE: Closing feature file \"" |
344 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; | 344 << m_files.begin()->second->fileName() << "\"" << endl; |
345 delete m_files.begin()->second; | 345 delete m_files.begin()->second; |
346 } | 346 } |
347 m_files.erase(m_files.begin()); | 347 m_files.erase(m_files.begin()); |
348 } | 348 } |
349 m_prevstream = 0; | 349 m_prevstream = 0; |