Exemplo n.º 1
0
 def __enter__  ( self ) :
     
     self.previous    = tempfile.tempdir        
     if  self.tmp_dir is None or writeable ( self.tmp_dir ) : 
         tempfile.tempdir = self.tmp_dir
         
     return self.__tmp_dir
Exemplo n.º 2
0
 def __init__ ( self , build = None ) :
     
     ##
     if build and writeable ( build ) :
         self.__build   = build
         self.__created = False 
     else : 
         self.__created = True             
         self.__build   = make_build_dir ()
         
     self.__prev   = ROOT.gSystem.SetBuildDir ( self.__build )
Exemplo n.º 3
0
def make_build_dir ( build = None ) :
    """Create proper temporary directory for ROOT builds
    """

    if not build or not writeable  ( build ) : 
        from ostap.utils.cleanup import CleanUp 
        build = CleanUp.tempdir ( prefix = 'ostap-build-' )

    if not os.path.exists ( build ) :
        make_dir ( build )
        
    return build
Exemplo n.º 4
0
 def __init__   ( self , temp_dir = None ) :
     
     self.__tmp_dir = temp_dir if ( temp_dir is None or writeable ( temp_dir ) ) else tmp_dir ( os.getpid () )  
     self.previous  = None
Exemplo n.º 5
0
re_format   = r"-(\d{4}-(\D&\S){3}-\d{2})-" 
# =============================================================================
user = whoami ()
# =============================================================================            
## temporary directory for <code>tempfile</code> module
base_tmp_dir = None
for_cleanup  = False 
# =============================================================================

## 1) check the environment variable OSTAP_TMPDIR 
if not base_tmp_dir :
    base_tmp_dir = os.environ.get  ( 'OSTAP_TMP_DIR' , None )
    ##
    if base_tmp_dir and not os.path.exists ( base_tmp_dir ) :
        base_tmp_dir = make_dir  ( base_tmp_dir ) 
    if base_tmp_dir and not writeable ( base_tmp_dir ) :
        logger.warning ('Directory ``%s'' is not writeable!' % base_tmp_dir )
        base_tmp_dir = None
        
## 2) get from configuration file 
if not base_tmp_dir :
    ## 2) check the configuration file 
    import ostap.core.config as OCC 
    base_tmp_dir = OCC.general.get ( 'TMP_DIR' , None )
    del OCC

    if base_tmp_dir and not os.path.exists ( base_tmp_dir ) :
        base_tmp_dir = make_dir ( base_tmp_dir ) 
    if base_tmp_dir and not writeable ( base_tmp_dir ) :
        logger.warning ('Directory ``%s'' is not writeable!' % base_tmp_dir )
        base_tmp_dir = None
Exemplo n.º 6
0
    )
# =============================================================================
import ROOT, os, glob  
from   ostap.utils.basic import make_dir, writeable 
# =============================================================================
build_dir  = None
prefix_dir = 'ostap-build-dir-'
# =============================================================================
# 1) use environment variable 
if not build_dir :

    build_dir = os.environ.get ( 'OSTAP_BUILD_DIR' , '' )
    
    if build_dir and not os.path.exists ( build_dir ) :
        build_dir = make_dir ( build_dir ) 
    if build_dir and not writeable ( build_dir ) :
        logger.warning ('Directory %s is not writeable!' % tmp_dir )
        build_dir = None

## 2) get from configuration file 
if not build_dir :
    ## 2) check the configuration file 
    import ostap.core.config as OCC 
    build_dir = OCC.general.get ( 'BUILD_DIR' , None )
    del OCC
    
    if build_dir and not os.path.exists ( build_dir ) :
        build_dir = make_dir ( build_dir ) 
    if build_dir and not writeable ( build_dir ) :
        logger.warning ('Directory %s is not writeable!' % tmp_dir )
        build_dir = None
Exemplo n.º 7
0
    def copy_files ( self , new_dir , parallel = False ) :
        """copy all the files to new directory
        - new directory will be created (if needed)
        - common path (prefix) for all files will be replaced by new directory
        """
        
        from ostap.utils.basic  import writeable,    copy_file
        from ostap.io.root_file import copy_file as copy_root_file 

        ## create directory if needed 
        if not os.path.exists ( new_dir ) : os.makedirs ( new_dir )
        
        assert writeable ( new_dir ), \
               "New directory ``%s'' is not writable!" % new_dir 

        nd = os.path.abspath  ( new_dir )
        nd = os.path.normpath ( nd      ) 
        nd = os.path.realpath ( nd      )
        
        cp = self.commonpath

        
        if parallel :

            regular_files  = [] 
            root_files     = [] 
            for f in self.__files :
                fs = os.path.normpath ( strip_protocol ( f ) ) 
                nf = fs.replace ( cp , nd ) 
                nf = os.path.normpath ( nf )
                pair = f , nf 
                if has_protocol ( f ) : root_files   .append ( pair )
                else                  : regular_files.append ( pair ) 
                
            from ostap.parallel.parallel_copy import copy_files as parallel_copy
            copied1 = []
            copied2 = []
            
            if regular_files :
                copied1 = parallel_copy ( regular_files , maxfiles = 1 , copier = copy_file      , progress = not self.silent )
            if root_files :
                copied2 = parallel_copy (    root_files , maxfiles = 1 , copier = copy_root_file , progress = not self.silent )
                
            copied  = [ d[1] for d in copied1 ] + [ d[1] for d in copied2 ] 

        else :
            
            copied = []
            from ostap.utils.progress_bar import progress_bar
            nf = len ( self.__files ) 
            for f in progress_bar ( self.__files , silent = self.silent or nf <=1 ) :
                
                fs = os.path.normpath ( strip_protocol ( f ) ) 
                nf = fs.replace ( cp , nd ) 
                nf = os.path.normpath ( nf )
                
                if not has_protocol ( f ) :
                    result = copy_file      ( f , nf , progress = ( 1 == nf ) and self.verbose ) 
                else                      :
                    result = copy_root_file ( f , nf , progress = ( 1 == nf ) and self.verbose ) 
                    
                copied.append ( result )
                
        copied = tuple ( copied )
        return self.clone ( files = copied , patterns = () )