コード例 #1
0
def restricted_ldenviron(projects=None, msg=None):
    """
    a context helper to limit ROOT automatic loading of dictionaries
    to a given set of cmt-projects (LCGCMT, AtlasCore, ...)
    """
    if projects is None:
        # nothing to do.
        # execute user stuff
        yield
        # end of story
        return

    if isinstance(projects, str):
        projects = [p.strip() for p in projects.split() if p.strip() != '']
    if not isinstance(projects, (list, tuple)):
        raise TypeError("projects has to be a list, tuple or space-separated"
                        " string")

    import os, sys
    from PyCmt.Cmt import CmtWrapper
    cmt = CmtWrapper()

    def _get_projects_paths(project_names, cmt=cmt):
        """return the list of paths of a project and its dependencies
        """
        if isinstance(project_names, str):
            project_names = project_names.split()
        projects = []
        for proj_name in project_names:
            projects.extend(cmt.project_deps(proj_name) + [proj_name])
        projects = list(set(projects))
        proj_paths = []
        tree = cmt.project_tree()
        for p in projects:
            path = tree[p].path
            proj_paths.append(path)
        return proj_paths

    # select only projects user asked for (and their dependencies)
    usr_projects = _get_projects_paths(projects)
    # get the same thing for all the projects we are currently using
    cur_projects = _get_projects_paths(cmt.projects_dag()[0].name)
    # intersect:
    blacklist = [p for p in cur_projects if p not in usr_projects]

    original_env = os.environ.copy()
    orig_ld_path = os.environ.get('LD_LIBRARY_PATH', '')
    orig_bin_path = os.environ.get('PATH', '')

    if 0:
        print ":::cmt projects:", usr_projects
        print ":::blacklist:", blacklist

    def _slim_down(orig_path, blacklist=blacklist):
        """helper method to slim down a path by removing every entry which
        starts with some element of the blacklist
        """
        new_path = []
        for d in orig_path.split(os.pathsep):
            # removing every entry which is in the blacklist
            burned = [p for p in blacklist if d.startswith(p)]
            if len(burned) == 0:
                new_path.append(d)
        return os.pathsep.join(new_path)

    # slim-down LD_LIBRARY_PATH
    new_ld_path = _slim_down(orig_ld_path)
    # and the PATH (to keep everything consistent)
    new_bin_path = _slim_down(orig_bin_path)

    # commit the new values
    os.environ['LD_LIBRARY_PATH'] = new_ld_path
    os.environ['PATH'] = new_bin_path

    # execute user stuff...
    try:
        yield
    finally:
        # restore original environment
        os.environ.update(original_env)
コード例 #2
0
def _get_currentpath():
    from PyCmt.Cmt import CmtWrapper
    cmt = CmtWrapper()
    installarea = cmt.show(macro_value='CMTINSTALLAREA')
    prefix = cmt.show(macro_value='cmt_installarea_prefix')
    return installarea.rstrip(prefix).rstrip(os.sep)
コード例 #3
0
ファイル: helper.py プロジェクト: pradloff/analysis-framework
def restricted_ldenviron(projects=None, msg=None):
    """
    a context helper to limit ROOT automatic loading of dictionaries
    to a given set of cmt-projects (LCGCMT, AtlasCore, ...)
    """
    if projects is None:
        # nothing to do.
        # execute user stuff
        yield
        # end of story
        return

    if isinstance(projects, str):
        projects = [p.strip() for p in projects.split() if p.strip() != '']
    if not isinstance(projects, (list, tuple)):
        raise TypeError("projects has to be a list, tuple or space-separated"
                        " string")

    import os, sys
    from PyCmt.Cmt import CmtWrapper
    cmt = CmtWrapper()
    def _get_projects_paths(project_names, cmt=cmt):
        """return the list of paths of a project and its dependencies
        """
        if isinstance(project_names, str):
            project_names = project_names.split()
        projects = []
        for proj_name in project_names:
            projects.extend(cmt.project_deps(proj_name) + [proj_name])
        projects = list(set(projects))
        proj_paths = []
        tree = cmt.project_tree()
        for p in projects:
            path = tree[p].path
            proj_paths.append(path)
        return proj_paths
        
    # select only projects user asked for (and their dependencies)
    usr_projects = _get_projects_paths(projects)
    # get the same thing for all the projects we are currently using
    cur_projects = _get_projects_paths(cmt.projects_dag()[0].name)
    # intersect:
    blacklist = [p for p in cur_projects if p not in usr_projects]
    
    original_env = os.environ.copy()
    orig_ld_path = os.environ.get('LD_LIBRARY_PATH', '')
    orig_bin_path= os.environ.get('PATH', '')
    
    if 0:
        print ":::cmt projects:",usr_projects
        print ":::blacklist:",blacklist

    def _slim_down(orig_path, blacklist=blacklist):
        """helper method to slim down a path by removing every entry which
        starts with some element of the blacklist
        """
        new_path = []
        for d in orig_path.split(os.pathsep):
            # removing every entry which is in the blacklist
            burned = [p for p in blacklist if d.startswith(p)]
            if len(burned) == 0:
                new_path.append(d)
        return os.pathsep.join(new_path)
            
    # slim-down LD_LIBRARY_PATH
    new_ld_path = _slim_down(orig_ld_path)
    # and the PATH (to keep everything consistent)
    new_bin_path= _slim_down(orig_bin_path)
    
    # commit the new values
    os.environ['LD_LIBRARY_PATH'] = new_ld_path
    os.environ['PATH'] = new_bin_path

    # execute user stuff...
    try:
        yield
    finally:
        # restore original environment
        os.environ.update(original_env)
コード例 #4
0
def _get_currentpath():
    from PyCmt.Cmt import CmtWrapper
    cmt = CmtWrapper()
    installarea = cmt.show(macro_value='CMTINSTALLAREA')
    prefix = cmt.show(macro_value='cmt_installarea_prefix')
    return installarea.rstrip(prefix).rstrip(os.sep)
コード例 #5
0
# @file PyUtils/bin/gen-typereg-dso.py
# @purpose a python script to workaround various limitations of rootmap files
#          and reflex/cint typename impedance mismatches
# @author Sebastien Binet <*****@*****.**>
# @date   February 2009

__doc__ = '''a python script to workaround various limitations of rootmap
files and reflex/cint typename impedance mismatches.
'''
__version__ = '$Revision: 1.1 $'
__author__ = 'Sebastien Binet <*****@*****.**>'

if __name__ == "__main__":
    import sys
    import os
    import PyUtils.Dso as Dso
    oname = 'typereg_dso_db.csv'
    if len(sys.argv) > 1:
        oname = sys.argv[1]
    else:
        from PyCmt.Cmt import CmtWrapper
        project_root = CmtWrapper().projects()[0]
        from PyUtils.path import path
        oname = path(project_root) / "InstallArea" / "share" / oname
        if not os.path.exists(oname.dirname()):
            os.makedirs(oname.dirname())
            pass
    rflx_names = Dso.gen_typeregistry_dso(oname)
    sys.exit(0)