Exemplo n.º 1
0
    def __init__(self,
                 ami_rootdir,
                 array='LA',
                 working_dir='/tmp',
                 additional_env_variables=None,
                 timeout=120,
                 ):
        """
        Spawn an AMI-REDUCE instance.

        This will automatically update the list of available files,
        but will not load the full info for each file, as this is time consuming.
        (See :py:func:`load_obs_info`.)

        """
        if len(ami_rootdir) > 16:
            warnings.warn("Long AMI root path detected - this may cause bugs!\n"
                          "It is recommended to use a short symlink instead.\n")
        if working_dir is None:
            working_dir = ami_rootdir
        if not os.access(os.path.join(ami_rootdir, 'bin', 'reduce'), os.R_OK):
            raise IOError("Cannot access ami-reduce binary at: " +
                               os.path.join(ami_rootdir, 'bin', 'reduce'))
        self.working_dir = working_dir
        ami_env = init_ami_env(ami_rootdir)
        if additional_env_variables is not None:
            ami_env.update(additional_env_variables)
        self.child = pexpect.spawn('tcsh -c reduce',
                          cwd=self.working_dir,
                          env=ami_env,
                          timeout=timeout)
        self.child.expect(self.prompt)
        # Records all known information about the fileset.
        # Each file entry is initialised to a ``defaultdict(lambda : None)``
        # So if we attempt to access an unknown file attribute we get a sensible
        # answer rather than an exception.
        self.files = dict()
        # Used for updating the relevant record in self.files, also logging:
        self.active_file = None

        if array == 'LA':
            self.switch_to_large_array()
        elif array != 'SA':
            raise ValueError("Initialisation error: Array must be 'LA' or 'SA'.")
        self.array = array
        self.update_files()

        self.file_log = None
        self.file_cmd_log = None
Exemplo n.º 2
0
    def __init__(self,
                 ami_rootdir,
                 ami_version,
                 array='LA',
                 working_dir='/tmp',
                 additional_env_variables=None,
                 timeout=120,
                 ):
        """
        Spawn an AMI-REDUCE instance.

        This will automatically update the list of available files,
        but will not load the full info for each file, as this is time consuming.
        (See :py:func:`load_obs_info`.)

        """
        self.ami_version = ami_version
        if ami_version == AmiVersion.digital:
            self.reduce_binary = 'reduce_dc'
            self.prompt = self.dc_prompt
        elif ami_version == AmiVersion.legacy:
            self.reduce_binary = 'reduce'
            self.prompt = self.legacy_prompt

        else:
            raise RuntimeError("Unrecognised 'reduce' binary name supplied; "
                               "unclear which command line prompt to expect")

        if len(ami_rootdir) > 16:
            warnings.warn("Long AMI root path detected - this may cause bugs!\n"
                          "It is recommended to use a short symlink instead.\n")
        if working_dir is None:
            working_dir = ami_rootdir
        if not os.access(os.path.join(ami_rootdir, 'bin', self.reduce_binary), os.R_OK):
            raise IOError("Cannot access ami-reduce binary at: " +
                          os.path.join(ami_rootdir, 'bin', self.reduce_binary))
        self.working_dir = working_dir
        ami_env = init_ami_env(ami_rootdir)
        if additional_env_variables is not None:
            ami_env.update(additional_env_variables)
        logger.debug("Spawning instance of "+self.reduce_binary+"...")
        self.child = pexpect.spawn('tcsh -c '+ self.reduce_binary,
                                   cwd=self.working_dir,
                                   env=ami_env,
                                   timeout=timeout)
        self.child.expect(self.prompt)
        logger.debug("...success.")
        # Records all known information about the fileset.
        self.files = dict()
        # Used for updating the relevant record in self.files, also logging:
        self.active_file = None

        if array == 'LA':
            self.switch_to_large_array()
        elif array != 'SA':
            raise ValueError(
                "Initialisation error: Array must be 'LA' or 'SA'.")
        self.array = array
        self.update_files()

        self.file_log = None
        self.file_cmd_log = None