Esempio n. 1
0
def createPackedOutputSandbox(output_patterns, filter, dest_dir):
    """Get all files matching output patterns except filtered with filter and
       put them to the Sandbox tarball in destination directory.
       This function is called by wrapper script at the run time.
    Arguments:
      'output_patterns': list of filenames or patterns.
      'filter': function to filter files (return True to except) 
      'dest_dir': destination directory for tarball
    """

    tgzfile = os.path.join(dest_dir, OUTPUT_TARBALL_NAME)

    try:
        from Ganga.Utility.files import multi_glob, recursive_copy
    except IOError as e:
        import sys

        print("Failed to import files")
        print("sys:")
        print(sys.path)
        print("env:")
        print(os.environ)
        print("ls:")
        print(os.listdir("."))
        print("pattern:")
        print(output_patterns)
        print("destdir:")
        print(dest_dir)

        try:
            import traceback
            traceback.print_stack()
        except:
            pass

        print("Trying fix")
        sys.path.insert(0, os.path.join(os.getcwd(), PYTHON_DIR))

        try:
            from Ganga.Utility.files import multi_glob, recursive_copy
            print("Success!")
        except IOError as e:
            print("Fail!")
            raise e

    outputlist = multi_glob(output_patterns, filter)

    if outputlist:
        with closing(tarfile.open(tgzfile, "w:gz")) as tf:
            tf.dereference = True
            for f in outputlist:
                tf.add(f)
Esempio n. 2
0
def createPackedOutputSandbox(output_patterns, filter, dest_dir):
    """Get all files matching output patterns except filtered with filter and
       put them to the Sandbox tarball in destination directory.
       This function is called by wrapper script at the run time.
    Arguments:
      'output_patterns': list of filenames or patterns.
      'filter': function to filter files (return True to except) 
      'dest_dir': destination directory for tarball
    """

    tgzfile = os.path.join(dest_dir, OUTPUT_TARBALL_NAME)

    try:
        from Ganga.Utility.files import multi_glob, recursive_copy
    except IOError as e:
        import sys

        print("Failed to import files")
        print("sys:")
        print(sys.path)
        print("env:")
        print(os.environ)
        print("ls:")
        print(os.listdir("."))
        print("pattern:")
        print(output_patterns)
        print("destdir:")
        print(dest_dir)

        try:
            import traceback
            traceback.print_stack()
        except:
            pass

        print("Trying fix")
        sys.path.insert(0, os.path.join(os.getcwd(), PYTHON_DIR))

        try:
            from Ganga.Utility.files import multi_glob, recursive_copy
            print("Success!")
        except IOError as e:
            print("Fail!")
            raise e

    outputlist = multi_glob(output_patterns, filter)

    if outputlist:
        with closing(tarfile.open(tgzfile, "w:gz")) as tf:
            tf.dereference = True
            for f in outputlist:
                tf.add(f)
Esempio n. 3
0
def createOutputSandbox(output_patterns, filter, dest_dir):
    """Get all files matching output patterns except filtered with filter and
       write them to the destination directory.
       This function is called by wrapper script at the run time.
    Arguments:
      'output_patterns': list of filenames or patterns.
      'filter': function to filter files (return True to except) 
      'dest_dir': destination directory for output files
    """

    try:
        from Ganga.Utility.files import multi_glob, recursive_copy
    except IOError as e:
        import sys

        print("Failed to import files")
        print("sys:")
        print(sys.path)
        print("env:")
        print(os.environ)
        print("ls:")
        print(os.listdir("."))
        print("pattern:")
        print(output_patterns)
        print("destdir:")
        print(dest_dir)

        try:
            import traceback
            traceback.print_stack()
        except:
            pass

        print("Trying fix")
        sys.path.insert(0, os.path.join(os.getcwd(), PYTHON_DIR))

        try:
            from Ganga.Utility.files import multi_glob, recursive_copy
            print("Success!")
        except IOError as e:
            print("Fail!")
            raise e

    for f in multi_glob(output_patterns, filter):
        try:
            if not os.path.exists(dest_dir):
                os.makedirs(dest_dir)
            recursive_copy(f, dest_dir)
        except Exception as x:
            print("ERROR: (job ###JOBID### createOutput )", x)
Esempio n. 4
0
def createOutputSandbox(output_patterns, filter, dest_dir):
    """Get all files matching output patterns except filtered with filter and
       write them to the destination directory.
       This function is called by wrapper script at the run time.
    Arguments:
      'output_patterns': list of filenames or patterns.
      'filter': function to filter files (return True to except) 
      'dest_dir': destination directory for output files
    """

    try:
        from Ganga.Utility.files import multi_glob, recursive_copy
    except IOError as e:
        import sys

        print("Failed to import files")
        print("sys:")
        print(sys.path)
        print("env:")
        print(os.environ)
        print("ls:")
        print(os.listdir("."))
        print("pattern:")
        print(output_patterns)
        print("destdir:")
        print(dest_dir)

        try:
            import traceback
            traceback.print_stack()
        except:
            pass

        print("Trying fix")
        sys.path.insert(0, os.path.join(os.getcwd(), PYTHON_DIR))

        try:
            from Ganga.Utility.files import multi_glob, recursive_copy
            print("Success!")
        except IOError as e:
            print("Fail!")
            raise e

    for f in multi_glob(output_patterns, filter):
        try:
            if not os.path.exists(dest_dir):
                os.makedirs(dest_dir)
            recursive_copy(f, dest_dir)
        except Exception as x:
            print("ERROR: (job ###JOBID### createOutput )", x)
Esempio n. 5
0
def createOutputSandbox(output_patterns,filter,dest_dir):
    """Get all files matching output patterns except filtered with filter and
       write them to the destination directory.
       This function is called by wrapper script at the run time.
    Arguments:
      'output_patterns': list of filenames or patterns.
      'filter': function to filter files (return True to except) 
      'dest_dir': destination directory for output files
    """

    from Ganga.Utility.files import multi_glob,recursive_copy
    
    for f in multi_glob(output_patterns,filter):
        try:
            recursive_copy(f,dest_dir)
        except Exception,x:
            print "ERROR: (job ###JOBID### createOutput )",x
Esempio n. 6
0
    def _getmatches(self, patterns):
        """Return a list of paths matching the list of path patterns.
        
        Keyword arguments:
        patterns -- A list of path patterns, identifying exported job files.

        Relative paths are evaluated against the current working directory and
        against the Ganga python root, i.e. ganga/python/. Duplicate matches are
        removed (based on absolute file name).
        
        """
        # expand patterns
        patterns = [files.expandfilename(p) for p in patterns]
        # add local patterns absolute or relative to cwd
        cwd = os.getcwd()
        localpatterns = [os.path.join(cwd, p) for p in patterns]
        # add local patterns absolute or relative to Ganga python root
        gangapythonroot = config['System']['GANGA_PYTHONPATH']
        syspatterns = [os.path.join(gangapythonroot, p) for p in patterns]
        # find all matches removing duplicates
        matches = files.multi_glob(localpatterns + syspatterns)
        return matches
Esempio n. 7
0
    def _getmatches(self, patterns):
        """Return a list of paths matching the list of path patterns.
        
        Keyword arguments:
        patterns -- A list of path patterns, identifying exported job files.

        Relative paths are evaluated against the current working directory and
        against the Ganga python root, i.e. ganga/python/. Duplicate matches are
        removed (based on absolute file name).
        
        """
        # expand patterns
        patterns = [files.expandfilename(p) for p in patterns]
        # add local patterns absolute or relative to cwd
        cwd = os.getcwd()
        localpatterns = [os.path.join(cwd, p) for p in patterns]
        # add local patterns absolute or relative to Ganga python root
        gangapythonroot = config['System']['GANGA_PYTHONPATH']
        syspatterns = [os.path.join(gangapythonroot, p) for p in patterns]
        # find all matches removing duplicates
        matches = files.multi_glob(localpatterns + syspatterns)
        return matches
Esempio n. 8
0
def createPackedOutputSandbox(output_patterns,filter,dest_dir):
    """Get all files matching output patterns except filtered with filter and
       put them to the Sandbox tarball in destination directory.
       This function is called by wrapper script at the run time.
    Arguments:
      'output_patterns': list of filenames or patterns.
      'filter': function to filter files (return True to except) 
      'dest_dir': destination directory for tarball
    """

    tgzfile = os.path.join(dest_dir,OUTPUT_TARBALL_NAME)

    from Ganga.Utility.files import multi_glob,recursive_copy
    outputlist = multi_glob(output_patterns,filter)

#
##      Curent release with os module 
#               
    
    if len(outputlist) > 0:
        if os.system("tar czf %s %s"%(tgzfile," ".join(outputlist))) != 0:
            print "ERROR: (job ###JOBID### createPackedOutput ) can't creat tarball"