Reads the IndexTable index file of commands and templates.
    Args:
      index_file: String, file where template/command mappings reside.
    Raises:
      CliTableError: A template column was not found in the table.
339838
def ReadIndex(self, index_file=None):
        

        self.index_file = index_file or self.index_file
        fullpath = os.path.join(self.template_dir, self.index_file)
        if self.index_file and fullpath not in self.INDEX:
            self.index = IndexTable(self._PreParse, self._PreCompile, fullpath)
            self.INDEX[fullpath] = self.index
        else:
            self.index = self.INDEX[fullpath]

        # Does the IndexTable have the right columns.
        if "Template" not in self.index.index.header:  # pylint: disable=E1103
            raise CliTableError("Index file does not have 'Template' column.")
273246
def get_column_at_index(self, index):
        
        if index is None:
            return None

        url = self.build_url(self._endpoints.get('get_column_index'))
        response = self.session.post(url, data={'index': index})

        if not response:
            return None

        return self.column_constructor(parent=self, **{self._cloud_data_key: response.json()})
996668
def cache_index(index)
      # TODO: atomic rename. Right now we just hope.
      File.open(CACHE_PATH, 'w' ) do |out|
        YAML::dump( index, out )
      end
    end
487996
def get_model_indices(cls, index):
        '''
        
        '''
        try:
            return cls._idx_name_to_mdl_to_mdlidx[index].values()
        except KeyError:
            raise KeyError('Could not find any index named {}. Is this index defined in BUNGIESEARCH["INDICES"]?'.format(index))
15309
def index_template(self, tpl):
        
        objcls = self.inner_class.my_type
        name = getattr(tpl, 'name', '')
        if not name:
            mesg = "a %s template has been defined without name, from: %s" % \
                   (objcls, tpl.imported_from)
            tpl.add_error(mesg)
        elif name in self.name_to_template:
            tpl = self.manage_conflict(tpl, name)
        self.name_to_template[name] = tpl
        logger.debug("Indexed a %s template: %s, uses: %s",
                     tpl.my_type, name, getattr(tpl, 'use', 'Nothing'))
        return tpl
957564
def indexables(self):
        
        if self._indexables is None:

            self._indexables = []

            # index columns
            self._indexables.extend([
                IndexCol(name=name, axis=axis, pos=i)
                for i, (axis, name) in enumerate(self.attrs.index_cols)
            ])

            # values columns
            dc = set(self.data_columns)
            base_pos = len(self._indexables)

            def f(i, c):
                klass = DataCol
                if c in dc:
                    klass = DataIndexableCol
                return klass.create_for_block(i=i, name=c, pos=base_pos + i,
                                              version=self.version)

            self._indexables.extend(
                [f(i, c) for i, c in enumerate(self.attrs.values_cols)])

        return self._indexables
886096
def with_index_lock
      lock_path = "#{@index_file}.lock"
      File.open(lock_path, "w+") do |f|
        f.flock(File::LOCK_EX)
        yield
      end
    end
310449
def _read_table_file(self, table_file):
        """"""
        self._table_file = table_file
        if os.path.exists(self._table_file):
            self._table = Table.read(self._table_file, hdu='JOB_ARCHIVE')
            self._table_ids = Table.read(self._table_file, hdu='FILE_IDS')
        else:
            self._table, self._table_ids = JobDetails.make_tables({})
        self._table_id_array = self._table_ids['file_id'].data
        self._fill_cache()
73234
def _par_read(dirname, compressed=True):
    
    templates = []
    if compressed:
        arc = tarfile.open(dirname, "r:*")
        members = arc.getmembers()
        _parfile = [member for member in members
                    if member.name.split(os.sep)[-1] ==
                    'template_parameters.csv']
        if len(_parfile) == 0:
            arc.close()
            raise MatchFilterError(
                'No template parameter file in archive')
        parfile = arc.extractfile(_parfile[0])
    else:
        parfile = open(dirname + '/' + 'template_parameters.csv', 'r')
    for line in parfile:
        t_in = Template()
        for key_pair in line.rstrip().split(','):
            if key_pair.split(':')[0].strip() == 'name':
                t_in.__dict__[key_pair.split(':')[0].strip()] = \
                    key_pair.split(':')[-1].strip()
            elif key_pair.split(':')[0].strip() == 'filt_order':
                try:
                    t_in.__dict__[key_pair.split(':')[0].strip()] = \
                        int(key_pair.split(':')[-1])
                except ValueError:
                    pass
            else:
                try:
                    t_in.__dict__[key_pair.split(':')[0].strip()] = \
                        float(key_pair.split(':')[-1])
                except ValueError:
                    pass
        templates.append(t_in)
    parfile.close()
    if compressed:
        arc.close()
    return templates
878320
def index_template_absent(name):
    '''
    
    '''

    ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}

    try:
        index_template = __salt__['elasticsearch.index_template_get'](name=name)
        if index_template and name in index_template:
            if __opts__['test']:
                ret['comment'] = 'Index template {0} will be removed'.format(name)
                ret['changes']['old'] = index_template[name]
                ret['result'] = None
            else:
                ret['result'] = __salt__['elasticsearch.index_template_delete'](name=name)
                if ret['result']:
                    ret['comment'] = 'Successfully removed index template {0}'.format(name)
                    ret['changes']['old'] = index_template[name]
                else:
                    ret['comment'] = 'Failed to remove index template {0} for unknown reasons'.format(name)
        else:
            ret['comment'] = 'Index template {0} is already absent'.format(name)
    except Exception as err:
        ret['result'] = False
        ret['comment'] = six.text_type(err)

    return ret
764051
def read_index_iter(self):
        

        with fopen(self.vpk_path, 'rb') as f:
            f.seek(self.header_length)

            while True:
                if self.version > 0 and f.tell() > self.tree_length + self.header_length:
                    raise ValueError("Error parsing index (out of bounds)")

                ext = _read_cstring(f)
                if ext == '':
                    break

                while True:
                    path = _read_cstring(f)
                    if path == '':
                        break
                    if path != ' ':
                        path = os.path.join(path, '')
                    else:
                        path = ''

                    while True:
                        name = _read_cstring(f)
                        if name == '':
                            break

                        (crc32,
                         preload_length,
                         archive_index,
                         archive_offset,
                         file_length,
                         suffix,
                         ) = metadata = list(struct.unpack("IHHIIH", f.read(18)))

                        if suffix != 0xffff:
                            raise ValueError("Error while parsing index")

                        if archive_index == 0x7fff:
                            metadata[3] = self.header_length + self.tree_length + archive_offset

                        metadata = (f.read(preload_length),) + tuple(metadata[:-1])

                        yield path + name + '.' + ext, metadata
1161526
def load_filename(self, filename, index=None):
        
        filename = str(filename)  # QString protection
        if index is None:
            index = self._get_tab_index()
        page = self.pages[index]

        # Maybe this is set on purpose before loading attempt to leave new load_dir set (?)
        self.load_dir, _ = os.path.split(filename)

        clss = page.clss_load
        if len(clss) == 1:
            # If there is only one class to handle the file, will load it in a way that eventual
            # load errors will raise
            f = clss[0]()
            f.load(filename)
        else:
            # At the moment, the multi-class alternative will not display particular error information
            # if the file does not load
            f = f311.load_with_classes(filename, page.clss_load)
            if f is None:
                raise RuntimeError("Could not load '{0!s}'".format(filename))

        self.load(f, index)
1335107
def read_criteria_file(self, criteria_file):
        '''
        
        '''
        if self.data_model == 3:
            self.acceptance_criteria = pmag.initialize_acceptance_criteria(
                data_model=self.data_model)
            self.add_thellier_gui_criteria()
            fnames = {'criteria': criteria_file}
            contribution = cb.Contribution(
                self.WD, custom_filenames=fnames, read_tables=['criteria'])
            if 'criteria' in contribution.tables:
                crit_container = contribution.tables['criteria']
                crit_data = crit_container.df
                crit_data['definition'] = 'acceptance criteria for study'
                # convert to list of dictionaries
                self.crit_data = crit_data.to_dict('records')
                for crit in self.crit_data:  # step through and rename every f-ing one
                    # magic2[magic3.index(crit['table_column'])] # find data
                    # model 2.5 name
                    m2_name = map_magic.convert_intensity_criteria(
                        'magic2', crit['table_column'])
                    if not m2_name:
                        pass
                    elif m2_name not in self.acceptance_criteria:
                        print('-W- Your criteria file contains {}, which is not currently supported in Thellier GUI.'.format(m2_name))
                        print('    This record will be skipped:\n    {}'.format(crit))
                    else:
                        if m2_name != crit['table_column'] and 'scat' not in m2_name != "":
                            self.acceptance_criteria[m2_name]['value'] = float(
                                crit['criterion_value'])
                            self.acceptance_criteria[m2_name]['pmag_criteria_code'] = crit['criterion']
                        if m2_name != crit['table_column'] and 'scat' in m2_name != "":
                            if crit['criterion_value'] == 'True':
                                self.acceptance_criteria[m2_name]['value'] = 1
                            else:
                                self.acceptance_criteria[m2_name]['value'] = 0
            else:
                print("-E- Can't read criteria file")

        else:  # Do it the data model 2.5 way:
            self.crit_data = {}
            try:
                self.acceptance_criteria = pmag.read_criteria_from_file(
                    criteria_file, self.acceptance_criteria)
            except:
                print("-E- Can't read pmag criteria file")
        # guesss if average by site or sample:
        by_sample = True
        flag = False
        for crit in ['sample_int_n', 'sample_int_sigma_perc', 'sample_int_sigma']:
            if self.acceptance_criteria[crit]['value'] == -999:
                flag = True
        if flag:
            for crit in ['site_int_n', 'site_int_sigma_perc', 'site_int_sigma']:
                if self.acceptance_criteria[crit]['value'] != -999:
                    by_sample = False
        if not by_sample:
            self.acceptance_criteria['average_by_sample_or_site']['value'] = 'site'
457697
def load_data_table(file,
                    index_col,
                    show_progress=False):
    
    with ZipFile(file) as zip_file:
        file_names = zip_file.namelist()
        assert len(file_names) == 1, "Expected a single file from Quandl."
        wiki_prices = file_names.pop()
        with zip_file.open(wiki_prices) as table_file:
            if show_progress:
                log.info('Parsing raw data.')
            data_table = pd.read_csv(
                table_file,
                parse_dates=['date'],
                index_col=index_col,
                usecols=[
                    'ticker',
                    'date',
                    'open',
                    'high',
                    'low',
                    'close',
                    'volume',
                    'ex-dividend',
                    'split_ratio',
                ],
            )

    data_table.rename(
        columns={
            'ticker': 'symbol',
            'ex-dividend': 'ex_dividend',
        },
        inplace=True,
        copy=False,
    )
    return data_table
1348664
def load(self, indexables):
        
        try:
            data = Persistence.read(self.path, create_file=True)
        except ValueError:
            data = {}

        return self.load_data(data, indexables)
709190
def render_index_file!(uri_path)
      return unless URI.directory?(uri_path)

      index_match     = File.join(settings.public_dir, "*")
      index_file_path = File.expand_path(uri_path + "index.html", settings.public_dir)

      return unless File.fnmatch(index_match, index_file_path)
      return unless File.file?(index_file_path)

      send_file index_file_path
    end
279404
def ParseFileObject(self, parser_mediator, file_object):
    
    try:
      self._ParseFileHeader(file_object)
    except errors.ParseError as exception:
      raise errors.ParseError(
          'Unable to parse index file header with error: {0!s}'.format(
              exception))
    # Skip over the LRU data, which is 112 bytes in size.
    file_object.seek(112, os.SEEK_CUR)
    self._ParseIndexTable(file_object)