[Kde-imaging] [Bug 283650] panorama tool can't find cpfind version on OS X

brad bkn at ithryn.net
Mon Oct 10 21:47:04 UTC 2011


https://bugs.kde.org/show_bug.cgi?id=283650





--- Comment #6 from brad <bkn ithryn net>  2011-10-10 21:47:04 ---
I agree with your sentiment on principle; that is, output should be stable,
reliable and consistant. However in practice, i know that parsing output is
always going to be a moving target; output changes, whether intentionally or
unintentionally; that will trip up programs like digikam trying to parse
output. As a result, i believe the code to parse this output would improve over
time. Also, any disruptions to the output are completely out of our control,
whereas the code to parse the output is completely in our control; so it is
much easier to alter digikam's code than to alter another project's code or
another project's packaging system. Ultimately, this is your code and the
decision to patch is yours, but this bug will persist. 

Below is a version of the checkSystem() function for cpfindbinary.cpp, which
handles and parses the out with a regular expression regardless of where the
version information occurs in the output. It is not as straightforward as i
hoped as QT doesn't appear to allow for variable names of captured text, but
the code is concise (less than 10 lines of functional code for the whole
function). 

Alternatively, you could simply parse the output of 'cpfind -h |grep -v -i
thread' which would eliminate all the ZThread output.


#include <QRegExp>

...

void CPFindBinary::checkSystem()
{
    QProcess process;
    process.start(path(), QStringList() << "-h");
    m_available       = process.waitForFinished();                              

    QRegExp versionRegExp(".*Hugins cpfind (?:Pre-Release
)?((\\d+){1}.(\\d+){1}.(\\d+){0,1}.([0-9a-fxA-FX]+){0,1}).*",
Qt::CaseInsensitive);

    if (versionRegExp.exactMatch(process.readAllStandardOutput()))              
    {                                                                           
        // kDebug() << "cap(0) " << versionRegExp.cap(0); // whole output of
stdout       
        // kDebug() << "cap(1) " << versionRegExp.cap(1); // whole version
string ex. 2011.1.1     
        // kDebug() << "cap(2) " << versionRegExp.cap(2); // major version
string ex. 2011
        // kDebug() << "cap(3) " << versionRegExp.cap(3); // minor version
string ex. 1   
        // kDebug() << "cap(4) " << versionRegExp.cap(4); // patch version
string ex. 1   
        // kDebug() << "cap(5) " << versionRegExp.cap(5); // hex value after
version string        

        m_version = versionRegExp.cap(2); // major version string ex. 2011      
        kDebug() << "Found " << path() << " version: " << version() ;           
    } 
    else                                                                        
    {
        kDebug() << " **** regexp didn't match version";                        
    }                                                                           
}

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Kde-imaging mailing list