Ejemplo n.º 1
0
void sRunTest(const string &sTestName, const STestInfo & testInfo, bool keep)
{
    cerr << "Testing " << testInfo.mInFile.GetName() << " against " <<
        testInfo.mOutFile.GetName() << " and " <<
        testInfo.mErrorFile.GetName() << endl;

    string logName = CDirEntry::GetTmpName();
    CErrorLogger logger(logName);

    CGvfReader reader(0);
    CNcbiIfstream ifstr(testInfo.mInFile.GetPath().c_str());

    typedef CGff2Reader::TAnnotList ANNOTS;
    ANNOTS annots;
    try {
        reader.ReadSeqAnnots(annots, ifstr, &logger);
    }
    catch (...) {
        BOOST_ERROR("Error: " << sTestName << " failed during conversion.");
        ifstr.close();
        return;
    }

    string resultName = CDirEntry::GetTmpName();
    CNcbiOfstream ofstr(resultName.c_str());
    for (ANNOTS::iterator cit = annots.begin(); cit != annots.end(); ++cit){
        ofstr << MSerial_AsnText << **cit;
        ofstr.flush();
    }
    ifstr.close();
    ofstr.close();

    bool success = testInfo.mOutFile.CompareTextContents(resultName, CFile::eIgnoreWs);
    if (!success) {
        CDirEntry deResult = CDirEntry(resultName);
        if (keep) {
            deResult.Copy(testInfo.mOutFile.GetPath() + "." + extKeep);
        }
        deResult.Remove();
        CDirEntry(logName).Remove();
        BOOST_ERROR("Error: " << sTestName << " failed due to post processing diffs.");
    }
    CDirEntry(resultName).Remove();

    success = testInfo.mErrorFile.CompareTextContents(logName, CFile::eIgnoreWs);
    CDirEntry deErrors = CDirEntry(logName);
    if (!success  &&  keep) {
        deErrors.Copy(testInfo.mErrorFile.GetPath() + "." + extKeep);
    }
    deErrors.Remove();
    if (!success) {
        BOOST_ERROR("Error: " << sTestName << " failed due to error handling diffs.");
    }
};
Ejemplo n.º 2
0
void s_ResetLibInstallKey(const string& dir, 
                          const string& lib)
{
    string key_file_name(lib);
    NStr::ToLower(key_file_name);
    key_file_name += ".installed";
    string key_file_path = CDirEntry::ConcatPath(dir, key_file_name);
    if ( CDirEntry(key_file_path).Exists() ) {
        CDirEntry(key_file_path).Remove();
    }
}
Ejemplo n.º 3
0
static bool s_SourceFileExists(const string& dir, const string& name)
{
    string path = CDirEntry::ConcatPath(dir, name);

    if ( CDirEntry(path + ".cpp").Exists() )
        return true;
    if ( CDirEntry(path + ".c").Exists() )
        return true;
    
    return false;
}
Ejemplo n.º 4
0
static void s_InitializeECNumberMaps(void)
{
    CFastMutexGuard GUARD(s_ECNumberMutex);
    if (s_ECNumberMapsInitialized) {
        return;
    }
    string dir;
    {{
        string file = g_FindDataFile("ecnum_specific.txt");
        if ( !file.empty() ) {
            dir = CDirEntry::AddTrailingPathSeparator(CDirEntry(file).GetDir());
        }
    }}
    if (dir.empty()) {
        ERR_POST_X(2, Info << "s_InitializeECNumberMaps: "
                   "falling back on built-in data.");
    }
#define LOAD_EC(x) s_LoadECNumberTable \
    (dir, #x, kECNum_##x, sizeof(kECNum_##x) / sizeof(*kECNum_##x), \
     CProt_ref::eEC_##x)
    LOAD_EC(specific);
    LOAD_EC(ambiguous);
    LOAD_EC(replaced);
    LOAD_EC(deleted);
#undef LOAD_EC
    s_ECNumberMapsInitialized = true;
}
Ejemplo n.º 5
0
static void s_InitializeECNumberMaps(void)
{
    CFastMutexGuard GUARD(s_ECNumberMutex);
    if (s_ECNumberMapsInitialized) {
        return;
    }
    string dir;
    const char* env_val = NULL;
    env_val = getenv("NCBI_ECNUM_USE_DATA_DIR_FIRST");
    if (env_val != NULL && NStr::EqualNocase(env_val, "TRUE"))
    {
        string file = g_FindDataFile("ecnum_specific.txt");
        if ( !file.empty() ) {
            dir = CDirEntry::AddTrailingPathSeparator(CDirEntry(file).GetDir());
        }
        if (dir.empty()) {
            ERR_POST_X(2, Info << "s_InitializeECNumberMaps: "
                       "falling back on built-in data.");
        }
    }
#define LOAD_EC(x) s_LoadECNumberTable \
    (dir, #x, kECNum_##x, sizeof(kECNum_##x) / sizeof(*kECNum_##x), \
     CProt_ref::eEC_##x)
    s_ECNumSpecificStatus = LOAD_EC(specific);
    s_ECNumAmbiguousStatus = LOAD_EC(ambiguous);
    s_ECNumReplacedStatus = LOAD_EC(replaced);
    s_ECNumDeletedStatus = LOAD_EC(deleted);
#undef LOAD_EC
    s_ECNumberMapsInitialized = true;
}
Ejemplo n.º 6
0
void CProjSRCResolver::PrepareResolver(void)
{
    if ( !m_Resolver.IsEmpty() )
        return;

    list<string> include_makefiles;
    s_GetMakefileIncludes(m_MakefilePath, 
                          m_SourcesBaseDir, &include_makefiles);

    ITERATE(list<string>, p, include_makefiles) {
        m_MakefileDirs.push_back( CDirEntry(*p).GetDir());
    }
Ejemplo n.º 7
0
//  ----------------------------------------------------------------------------
bool
CMultiFileDestination::Next(
    const string& inPath,
    string& outPath)
//  ----------------------------------------------------------------------------
{
    if (!mBaseValid) {
        return false;
    }
    string inName = CDirEntry(inPath).GetName();
    outPath = CDirEntry::MakePath(mBaseDir, inName, mExtension);
    return true;
}
Ejemplo n.º 8
0
BEGIN_NCBI_SCOPE

// collect include statements and resolve to abs pathes 
static void s_GetMakefileIncludes(const string& applib_mfilepath,
                                  const string& source_base_dir,
                                  list<string>* includes)
{
    includes->clear();

    CNcbiIfstream ifs(applib_mfilepath.c_str(), 
                      IOS_BASE::in | IOS_BASE::binary);
    if ( !ifs )
        NCBI_THROW(CProjBulderAppException, eFileOpen, applib_mfilepath);

    string strline;
    while ( getline(ifs, strline) ) {
        const string include_token("include ");
        strline = NStr::TruncateSpaces(strline);
        if ( NStr::StartsWith(strline, include_token) ) {
            string include = strline.substr(include_token.length());
            
            string root;
            string srcdir_token("$(srcdir)");
            if (include.find(srcdir_token) == 0) {
                root = source_base_dir;
            } else {
                srcdir_token = "$(top_srcdir)";
                if (include.find(srcdir_token) == 0) {
                    root = GetApp().GetProjectTreeInfo().m_Root;
                }
                else {
#if 0
                    srcdir_token = "$(builddir)";
                    if (NStr::StartsWith(include, srcdir_token)) {
                        root = GetApp().GetBuildRoot();
                        if (root.empty()) {
                            root = CDirEntry(GetApp().m_Solution).GetDir();
                        }
                    }
#endif
                }
            }
            if (!root.empty()) {
                include = include.substr(srcdir_token.length());
                include = CDirEntry::ConcatPath(root, include);
                include = CDirEntry::NormalizePath(include);
            }
            includes->push_back(include);
        }
    }
}
Ejemplo n.º 9
0
bool CDebugDumpViewer::x_CheckLocation(const char* file, int line)
{
    const CNcbiRegistry& cfg = CNcbiApplication::Instance()->GetConfig();
    string section("DebugDumpBpt");
    string value = cfg.Get( section, "enabled");
    // the section is absent? - enable all
    if (value.empty()) {
        return true;
    }
    // prerequisite
    bool enabled = ((value != "false") && (value != "0"));
    // Now only listed locations will be treated accordingly

    // smth about this particular file?
    string name = CDirEntry(file).GetName();
    value = cfg.Get(section, name);
    if (value.empty() || (value=="none")) {
        return !enabled; // none are "enabled"
    } else if (value == "all") {
        return enabled;  // all are "enabled"
    }
    // otherwise - look for this particular line
    // location range must be in the form "10,20-30,150-200"
    list<string> loc;
    NStr::Split( value,",",loc, NStr::fSplit_MergeDelimiters | NStr::fSplit_Truncate);
    list<string>::iterator it_loc;
    for (it_loc = loc.begin(); it_loc != loc.end(); ++it_loc) {
        list<string> range;
        list<string>::iterator it_range;
        NStr::Split( *it_loc,"-",range, NStr::fSplit_MergeDelimiters | NStr::fSplit_Truncate);
        int from=0, to;
        try {
            it_range = range.begin();
            from = NStr::StringToInt( *it_range);
            to   = NStr::StringToInt( *(++it_range));
        } catch (...) {
            to = from;
        }
        if ((line >= from) && (line <= to)) {
            return enabled;
        }
    }
    return !enabled;
}
Ejemplo n.º 10
0
string CVResolver::Resolve(const string& acc_or_path) const
{
    if ( !CVPath::IsPlainAccession(acc_or_path) ) {
        // already a path
        return acc_or_path;
    }
    CVPath acc(m_Mgr, acc_or_path, CVPath::eAcc);
    const VPath* path;
    rc_t rc = VResolverLocal(*this, acc, &path);
    if ( rc ) {
        rc = VResolverRemote(*this, eProtocolNone, acc, &path);
    }
    if ( rc ) {
        if ( CDirEntry(acc_or_path).Exists() ) {
            // local file
            return acc_or_path;
        }
        NCBI_THROW2_FMT(CSraException, eNotFound,
                        "Cannot find acc path: "<<acc_or_path, rc);
    }
    return CVPath(path).ToString();
}
Ejemplo n.º 11
0
void CBam2GraphApp::ProcessFile(const string& file)
{
    const CArgs& args = GetArgs();

    string path;
    if ( NStr::StartsWith(file, "http://") ||
         NStr::StartsWith(file, "https://") ||
         NStr::StartsWith(file, "ftp://") ||
         CFile(file).Exists() ) {
        path = file;
    }
    else {
        string dir;
        if ( args["dir"] ) {
            dir = args["dir"].AsString();
        }
        else {
            vector<string> reps;
            NStr::Split("traces02:traces04", ":", reps);
            ITERATE ( vector<string>, it, reps ) {
                string path = CFile::MakePath(CFile::MakePath(NCBI_GetTestDataPath(), *it), dir);
                if ( !CDirEntry(dir).Exists() ) {
                    dir = path;
                    break;
                }
            }
        }

        path = CFile::MakePath(dir, file);
        if ( !CFile(path).Exists() ) {
            vector<string> tt;
            NStr::Split(CFile(file).GetBase(), ".", tt);
            if ( tt.size() > 0 ) {
                path = CFile::MakePath(dir, tt[0]);
                path = CFile::MakePath(path, "alignment");
                path = CFile::MakePath(path, file);
            }
        }
    }
Ejemplo n.º 12
0
void CPIDGuard::Release(void)
{
    if ( !m_Path.empty() ) {
        // MT-Safe protect
        CFastMutexGuard LOCK(s_PidGuardMutex);

        // Read info
        TPid pid = 0;
        unsigned int ref = 0;
        CNcbiIfstream in(m_Path.c_str());
        if ( in.good() ) {
            in >> pid >> ref;
            in.close();
            if ( m_NewPID != pid ) {
                // We do not own this file more
                return;
            }
            if ( ref ) {
                ref--;
            }
            // Check reference counter
            if ( ref ) {
                // Write updated reference counter into the file
                CNcbiOfstream out(m_Path.c_str(),
                                  IOS_BASE::out | IOS_BASE::trunc);
                if ( out.good() ) {
                    out << pid << endl << ref << endl;
                }
                if ( !out.good() ) {
                    NCBI_THROW(CPIDGuardException, eWrite,
                               "Unable to write into PID file " + m_Path +": "
                               + _T_CSTRING(NcbiSys_strerror(errno)));
                }
            } else {
                // Remove the file
                CDirEntry(m_Path).Remove();
            }
        }
Ejemplo n.º 13
0
//Use it for testing
CRef <CSeq_annot> createAnnot(string rid)
{
        CRef <CSeq_annot> m_Annot(new CSeq_annot);

        string path_cgi = CNcbiApplication::Instance()->GetProgramExecutablePath();
        string path_base = CDirEntry(path_cgi).GetDir();  
        string ASN1FilePath  = CDirEntry::MakePath(path_base, "testSeqAnnot.txt");

        LOG_POST(path_cgi);
        LOG_POST(path_base);
        LOG_POST(ASN1FilePath);
        
        try {
            auto_ptr<CObjectIStream> in
             (CObjectIStream::Open(eSerial_AsnText,ASN1FilePath));
            *in >> *m_Annot;        
        }
        catch (CException& e) {
            cerr << "Exception reading SeqAnnot exception message: " + e.GetMsg() << endl;                        
        }
        cerr << MSerial_AsnText << *m_Annot;
        return m_Annot;
}
Ejemplo n.º 14
0
 ITERATE ( vector<string>, it, dirs ) {
     string dir = *it;
     if ( !CDirEntry(dir).Exists() ) {
         continue;
     }
     path = CFile::MakePath(dir, file);
     if ( !CFile(path).Exists() ) {
         SIZE_TYPE p1 = file.rfind('/');
         if ( p1 == NPOS ) {
             p1 = 0;
         }
         else {
             p1 += 1;
         }
         SIZE_TYPE p2 = file.find('.', p1);
         if ( p2 != NPOS ) {
             path = CFile::MakePath(dir, file.substr(p1, p2-p1) + "/alignment/" + file);
         }
     }
     if ( CFile(path).Exists() ) {
         break;
     }
     path.clear();
 }
void CDataToolGeneratedSrc::LoadFrom(const string&          source_file_path,
                                     CDataToolGeneratedSrc* src)
{
    src->Clear();

    string dir;
    string base;
    string ext;
    CDirEntry::SplitPath(source_file_path, &dir, &base, &ext);

    src->m_SourceBaseDir = dir;
    src->m_SourceCPP     = base;
    src->m_SourceFile    = base + ext;

    {{
        // module file
        string module_path = CDirEntry::ConcatPath(dir, 
                                                  base + ".module");
        if ( CDirEntry(module_path).Exists() ) {
            CSimpleMakeFileContents fc(module_path, eMakeType_Undefined);
            CSimpleMakeFileContents::TContents::const_iterator p = 
                fc.m_Contents.find("MODULE_IMPORT");
            if (p != fc.m_Contents.end()) {
                const list<string>& modules = p->second;
                ITERATE(list<string>, p, modules) {
                    // add ext from source file to all modules to import
                    const string& module = *p;
                    src->m_ImportModules.push_back
                                        (CDirEntry::NormalizePath(module + ext));
                }
            }
        } else {
//            PTB_INFO_EX(module_path, ePTB_FileNotFound,
//                        "Datatool module file not found");
        }
    }}
Ejemplo n.º 16
0
static void s_CreateThirdPartyLibsInstallMakefile
                                            (CMsvcSite&   site, 
                                             const list<string> libs_to_install,
                                             const SConfigInfo& config,
                                             const CBuildType&  build_type)
{
    // Create makefile path
    string makefile_path = GetApp().GetProjectTreeInfo().m_Compilers;
    makefile_path = 
        CDirEntry::ConcatPath(makefile_path, 
                              GetApp().GetRegSettings().m_CompilersSubdir);

    makefile_path = CDirEntry::ConcatPath(makefile_path, build_type.GetTypeStr());
    makefile_path = CDirEntry::ConcatPath(makefile_path, config.GetConfigFullName());
    makefile_path = CDirEntry::ConcatPath(makefile_path, 
                                          "Makefile.third_party.mk");

    // Create dir if no such dir...
    string dir;
    CDirEntry::SplitPath(makefile_path, &dir);
    CDir makefile_dir(dir);
    if ( !makefile_dir.Exists() ) {
        CDir(dir).CreatePath();
    }

    CNcbiOfstream ofs(makefile_path.c_str(), 
                      IOS_BASE::out | IOS_BASE::trunc );
    if ( !ofs )
        NCBI_THROW(CProjBulderAppException, eFileCreation, makefile_path);

    GetApp().RegisterGeneratedFile( makefile_path );
    ITERATE(list<string>, n, libs_to_install) {
        const string& lib = *n;
        SLibInfo lib_info;
        site.GetLibInfo(lib, config, &lib_info);
        if ( !lib_info.m_LibPath.empty() ) {
            string bin_dir = lib_info.m_LibPath;
            string bin_path = lib_info.m_BinPath;
            if (bin_path.empty()) {
                bin_path = site.GetThirdPartyLibsBinSubDir();
            }
            bin_dir = 
                CDirEntry::ConcatPath(bin_dir, bin_path);
            bin_dir = CDirEntry::NormalizePath(bin_dir);
            if ( CDirEntry(bin_dir).Exists() ) {
                //
                string key(lib);
                NStr::ToUpper(key);
                key += site.GetThirdPartyLibsBinPathSuffix();

                ofs << key << " = " << bin_dir << "\n";

                s_ResetLibInstallKey(dir, lib);
                site.SetThirdPartyLibBin(lib, bin_dir);
            } else {
                PTB_WARNING_EX(bin_dir, ePTB_PathNotFound,
                               lib << "|" << config.GetConfigFullName()
                               << " disabled, path not found");
            }
        } else {
            PTB_WARNING_EX(kEmptyStr, ePTB_PathNotFound,
                           lib << "|" << config.GetConfigFullName()
                           << ": no LIBPATH specified");
        }
    }
}