Пример #1
0
    def add_additional_resource(self, description, location, copy_file=False):
        """
        Add any kind of additional resource.
        If copy_file is set to False, the location and description will be added as-is.
        This is useful e.g. for the case of providing a URL to a web-based resource.

        If copy_file is set to True, we will try to copy the file from the location you have given
        into the output directory. This only works if the location is a local file.
        If the location you gave does not exist or points to a file larger than 100 MB,
        a RuntimeError will be raised.
        While the file checks are performed immediately (i.e. the file must exist when this
        function is called), the actual copying only happens once create_files function of the
        submission object is called.

        :param description: Description of what the resource is.
        :type description: string.

        :param location: Can be either a URL pointing to a web-based resource or a local file path.
        :type: string

        :param copy_file: If set to true, will attempt to copy a local file to the tar ball.
        :type copy_file: bool
        """

        resource = {}
        resource["description"] = description
        if copy_file:
            helpers.check_file_existence(location)
            helpers.check_file_size(location, upper_limit=100)
            resource["location"] = os.path.basename(location)
        else:
            resource["location"] = location

        self.additional_resources.append(resource)
        self.files_to_copy.append(location)
Пример #2
0
    def copy_files(self, outdir):
        """
        Copy the files in the files_to_copy list to the output directory.

        :param outdir: Output directory path to copy to.
        :type outdir: string
        """
        for ifile in self.files_to_copy:
            helpers.check_file_existence(ifile)
            helpers.check_file_size(ifile, upper_limit=100)
            shutil.copy2(ifile, outdir)
Пример #3
0
 def cfile(self, cfile):
     """
     Define the '.C' file to read from.
     """
     if isinstance(cfile, str):
         if not cfile.lower().endswith(".c"):
             raise RuntimeError(
                 "CFileReader: Input file is not a .C file (name does not end in .C)!"
             )
         if check_file_existence(cfile):
             self._cfile = open(cfile, "r")
     elif six.PY2:
         if isinstance(cfile, file):  # pylint:disable=E0602
             self._cfile = cfile
         else:
             raise ValueError(
                 "CFileReader: Encountered unknown type of variable passed as cfile argument: "
                 + str(type(cfile)))
     else:
         if isinstance(cfile, io.TextIOBase):
             self._cfile = cfile
         else:
             raise ValueError(
                 "CFileReader: Encountered unknown type of variable passed as cfile argument: "
                 + str(type(cfile)))
     if not self._cfile:
         raise IOError("CFileReader: File not opened properly.")
Пример #4
0
    def tfile(self, tfile):
        """
        Define the TFile to read from.

        :param tfile: ROOT file to read from.
        Can either be an already open TFile or a path to the file on disk.
        :type tfile: TFile or str
        """
        if isinstance(tfile, str):
            if not tfile.endswith(".root"):
                raise RuntimeError(
                    "RootFileReader: Input file is not a ROOT file (name does not end in .root)!"
                )
            if check_file_existence(tfile):
                self._tfile = r.TFile(tfile)
        elif isinstance(tfile, r.TFile):
            self._tfile = tfile
        else:
            raise ValueError(
                "RootReader: Encountered unkonown type of variable passed as tfile argument: "
                + str(type(tfile)))

        if not self._tfile:
            raise IOError("RootReader: File not opened properly.")