Пример #1
0
int CTAbleValApp::Run(void)
{
    const CArgs& args = GetArgs();

    Setup(args);

    m_LogStream = args["logfile"] ? &(args["logfile"].AsOutputFile()) : &NcbiCout;
    m_logger.Reset(new CMessageListenerLenient());
    m_logger->SetProgressOstream(m_LogStream);

    // note - the C Toolkit uses 0 for SEV_NONE, but the C++ Toolkit uses 0 for SEV_INFO
    // adjust here to make the inputs to table2asn match tbl2asn expectations
    //m_ReportLevel = args["R"].AsInteger() - 1;
    //m_LowCutoff = static_cast<EDiagSev>(args["Q"].AsInteger() - 1);
    //m_HighCutoff = static_cast<EDiagSev>(args["P"].AsInteger() - 1);

    CTabDelimitedValidator::RegisterAliases(args["aliases"]?&args["aliases"].AsInputFile():0);

    if (args["print-supported"])
    {
        CColumnValidatorRegistry::GetInstance().PrintSupported(ncbi::cout);
        return 0;
    }

    m_comma_separated = args["comma"];
    if (args["columns"])
    {
        m_columns_def = args["columns"].AsString();
        NStr::ToLower(m_columns_def);
    }
    if (args["required"])
    {
        m_required_cols = args["required"].AsString();
        NStr::ToLower(m_required_cols);
    }

    if (args["ignore"])
    {
        m_ignored_cols = args["ignore"].AsString();
        NStr::ToLower(m_ignored_cols);
    }
    if (args["unique"])
    {
        m_unique_cols = args["unique"].AsString();
        NStr::ToLower(m_unique_cols);
    }
    
     
    m_no_header = args["no-header"];
    m_skip_empty = args["skip-empty"];
    m_format = args["format"].AsString();
    m_ignore_unknown_types = args["ignore-unknown"];

    if (args["discouraged"])
    {
       m_discouraged = args["discouraged"].AsString();
       NStr::ToLower(m_discouraged);
    }

    if (args["require-one"])
    {
        m_require_one = args["require-one"].GetStringList();
    }

    // Designate where do we output files: local folder, specified folder or a specific single output file
    if (args["o"])
    {
        m_output = &args["o"].AsOutputFile();
    }
    else
    {
        if (args["r"])
        {
            m_ResultsDirectory = args["r"].AsString();
        }
        else
        {
            m_ResultsDirectory = ".";
        }
        m_ResultsDirectory = CDir::AddTrailingPathSeparator(m_ResultsDirectory);

        CDir outputdir(m_ResultsDirectory);
        if (!IsDryRun())
        if (!outputdir.Exists())
            outputdir.Create();
    }

    try
    {
    // Designate where do we get input: single file or a folder or folder structure
        if ( args["p"] )
        {
            CDir directory(args["p"].AsString());
            if (directory.Exists())
            {
                CMaskFileName masks;
                masks.Add("*" +args["x"].AsString());

                ProcessOneDirectory (directory, masks, args["E"].AsBoolean());
            }
        } else {
            if (args["i"])
            {
                ProcessOneFile (args["i"].AsString());
            }
        }
    }
    catch (CException& e)
    {
        m_logger->PutError(*CLineError::Create(CLineError::eProblem_GeneralParsingError, eDiag_Error, 
            "", 0, "", "", "",
            e.GetMsg()));
    }

    if (m_logger->Count() == 0)
        return 0;
    else
    {
        m_logger->Dump(*m_LogStream);

        int errors = m_logger->LevelCount(eDiag_Critical) + 
                     m_logger->LevelCount(eDiag_Error) + 
                     m_logger->LevelCount(eDiag_Fatal);
        // all errors reported as failure
        if (errors > 0)
            return 1;
        
        // only warnings reported as 2 
        if (m_logger->LevelCount(eDiag_Warning)>0)
            return 2;

        // otherwise it's ok
        return 0;
    }
}