Populate the template and compare to ``README``.

    Raises:
        ValueError: If the current README doesn't agree with the expected
            value computed from the template.
775321
def readme_verify():
    
    expected = populate_readme(REVISION, RTD_VERSION)
    # Actually get the stored contents.
    with open(README_FILE, "r") as file_obj:
        contents = file_obj.read()
    if contents != expected:
        err_msg = "\n" + get_diff(
            contents, expected, "README.rst.actual", "README.rst.expected"
        )
        raise ValueError(err_msg)

    else:
        print("README contents are as expected.")
34433
def readme():
    
    path = os.path.realpath(os.path.join(os.path.dirname(__file__), 'README.rst'))
    handle = None
    try:
        handle = codecs.open(path, encoding='utf-8')
        return handle.read(131072)
    except IOError:
        return ''
    finally:
        getattr(handle, 'close', lambda: None)()
1109078
def populate(self, installed_bots=None):
        
        if self.ready:
            return

        # populate() might be called by two threads in parallel on servers
        # that create threads before initializing the WSGI callable.
        with self._lock:
            if self.ready:
                return

            # An RLock prevents other threads from entering this section. The
            # compare and set operation below is atomic.
            if self.loading:
                # Prevent re-entrant calls to avoid running AppConfig.ready()
                # methods twice.
                raise RuntimeError("populate() isn't re-entrant")
            self.loading = True

            # Phase 1: Initialize bots
            for entry in installed_bots or {}:
                if isinstance(entry, Bot):
                    cls = entry
                    entry = '.'.join([cls.__module__, cls.__name__])
                bot_reg = BotRegistry.create(entry)
                if bot_reg.label in self.bots:
                    raise ImproperlyConfigured(
                        "Bot labels aren't unique, "
                        "duplicates: %s" % bot_reg.label)

                self.bots[bot_reg.label] = bot_reg
                bot_reg.bots = self

            # Check for duplicate bot names.
            counts = Counter(
                bot_reg.name for bot_reg in self.bots.values())
            duplicates = [
                name for name, count in counts.most_common() if count > 1]
            if duplicates:
                raise ImproperlyConfigured(
                    "Bot names aren't unique, "
                    "duplicates: %s" % ", ".join(duplicates))

            self.bots_ready = True

            # Phase 2: import config files
            for bot in self.bots.values():
                bot.import_configs()

            self.configs_ready = True

            self.ready = True
1033483
def sync_readmes():
    
    print("syncing README")
    with open("README.md", 'r') as reader:
        file_text = reader.read()
    with open("README", 'w') as writer:
        writer.write(file_text)
882760
def _actually_populate_keyvals(filename):
        
        assert isinstance(filename, str)
        keyvals = {}
        with open(filename, 'r') as f:
            for line in f:
                line = line.strip("\r\n")
                pieces = line.split(_KeyValuePersister._delimiter)
                if len(pieces) >= 2:
                    key = pieces[0]
                    val = _KeyValuePersister._delimiter.join(pieces[1:])
                    keyvals[key] = val
        return keyvals
1065668
def write_readme(self, role):
        
        j2_out = self.readme_template.render(self.readme_template_vars)

        self.update_gen_report(role, "readme", j2_out)
897273
def convert(self, value, view):
        
        is_mapping = isinstance(self.template, MappingTemplate)

        for candidate in self.allowed:
            try:
                if is_mapping:
                    if isinstance(candidate, Filename) and \
                            candidate.relative_to:
                        next_template = candidate.template_with_relatives(
                            view,
                            self.template
                        )

                        next_template.subtemplates[view.key] = as_template(
                            candidate
                        )
                    else:
                        next_template = MappingTemplate({view.key: candidate})

                    return view.parent.get(next_template)[view.key]
                else:
                    return view.get(candidate)
            except ConfigTemplateError:
                raise
            except ConfigError:
                pass
            except ValueError as exc:
                raise ConfigTemplateError(exc)

        self.fail(
            u'must be one of {0}, not {1}'.format(
                repr(self.allowed), repr(value)
            ),
            view
        )
1225896
def _get_template_dict(template):
    
    if isinstance(template, str):
        return parse_template(template)

    if isinstance(template, dict):
        return copy.deepcopy(template)

    raise ValueError('Input template should be a string or dictionary')
482702
def get_readme():
    """"""
    pandoc = None
    for path in os.environ["PATH"].split(os.pathsep):
        path = path.strip('"')
        pandoc = os.path.join(path, 'pandoc')
        if os.path.isfile(pandoc) and os.access(pandoc, os.X_OK):
            break
        else:
            pandoc = None
    try:
        if pandoc:
            cmd = [pandoc, '-t', 'rst', 'README.md']
            long_description = os.popen(' '.join(cmd)).read()
        else:
            raise ValueError
    except BaseException:
        long_description = open("README.md").read()
    return long_description
1144903
def load_file(self, input_file):
        
        pyimg = imp.load_source('image2py_taf', input_file)
        self.files = pyimg.data
        self.set_template(templates.templateByName(pyimg.template))
1137159
def readme(self):
        
        url = self._build_url('readme', base_url=self._api)
        json = self._json(self._get(url), 200)
        return Contents(json, self) if json else None
1208082
def convertReadAlignment(self, read, readGroupSet, readGroupId):
        
        samFile = self.getFileHandle(self._dataUrl)
        # TODO fill out remaining fields
        # TODO refine in tandem with code in converters module
        ret = protocol.ReadAlignment()
        # ret.fragmentId = 'TODO'
        ret.aligned_quality.extend(read.query_qualities)
        ret.aligned_sequence = read.query_sequence
        if SamFlags.isFlagSet(read.flag, SamFlags.READ_UNMAPPED):
            ret.ClearField("alignment")
        else:
            ret.alignment.CopyFrom(protocol.LinearAlignment())
            ret.alignment.mapping_quality = read.mapping_quality
            ret.alignment.position.CopyFrom(protocol.Position())
            ret.alignment.position.reference_name = samFile.getrname(
                read.reference_id)
            ret.alignment.position.position = read.reference_start
            ret.alignment.position.strand = protocol.POS_STRAND
            if SamFlags.isFlagSet(read.flag, SamFlags.READ_REVERSE_STRAND):
                ret.alignment.position.strand = protocol.NEG_STRAND
            for operation, length in read.cigar:
                gaCigarUnit = ret.alignment.cigar.add()
                gaCigarUnit.operation = SamCigar.int2ga(operation)
                gaCigarUnit.operation_length = length
                gaCigarUnit.reference_sequence = ""  # TODO fix this!
        ret.duplicate_fragment = SamFlags.isFlagSet(
            read.flag, SamFlags.DUPLICATE_READ)
        ret.failed_vendor_quality_checks = SamFlags.isFlagSet(
            read.flag, SamFlags.FAILED_QUALITY_CHECK)
        ret.fragment_length = read.template_length
        ret.fragment_name = read.query_name
        for key, value in read.tags:
            # Useful for inspecting the structure of read tags
            # print("{key} {ktype}: {value}, {vtype}".format(
            #     key=key, ktype=type(key), value=value, vtype=type(value)))
            protocol.setAttribute(ret.attributes.attr[key].values, value)

        if SamFlags.isFlagSet(read.flag, SamFlags.MATE_UNMAPPED):
            ret.next_mate_position.Clear()
        else:
            ret.next_mate_position.Clear()
            if read.next_reference_id != -1:
                ret.next_mate_position.reference_name = samFile.getrname(
                    read.next_reference_id)
            else:
                ret.next_mate_position.reference_name = ""
            ret.next_mate_position.position = read.next_reference_start
            ret.next_mate_position.strand = protocol.POS_STRAND
            if SamFlags.isFlagSet(read.flag, SamFlags.MATE_REVERSE_STRAND):
                ret.next_mate_position.strand = protocol.NEG_STRAND
        if SamFlags.isFlagSet(read.flag, SamFlags.READ_PAIRED):
            ret.number_reads = 2
        else:
            ret.number_reads = 1
        ret.read_number = -1
        if SamFlags.isFlagSet(read.flag, SamFlags.FIRST_IN_PAIR):
            if SamFlags.isFlagSet(read.flag, SamFlags.SECOND_IN_PAIR):
                ret.read_number = 2
            else:
                ret.read_number = 0
        elif SamFlags.isFlagSet(read.flag, SamFlags.SECOND_IN_PAIR):
            ret.read_number = 1
        ret.improper_placement = not SamFlags.isFlagSet(
            read.flag, SamFlags.READ_PROPER_PAIR)
        ret.read_group_id = readGroupId
        ret.secondary_alignment = SamFlags.isFlagSet(
            read.flag, SamFlags.SECONDARY_ALIGNMENT)
        ret.supplementary_alignment = SamFlags.isFlagSet(
            read.flag, SamFlags.SUPPLEMENTARY_ALIGNMENT)
        ret.id = readGroupSet.getReadAlignmentId(ret)
        return ret
909182
def _adjust_template(filepath, translate):
    
    with open(filepath, 'r') as file:
        filedata = file.read()

    filedata = _multiple_replace(filedata, translate)

    with open(filepath, 'w') as file:
        file.write(filedata)
1219055
def get_readme():
    """"""
    try:
        import pypandoc
        description = pypandoc.convert('README.md', 'rst')
    except (IOError, ImportError):
        description = open('README.md').read()

    return description
600280
def parse_readme():
    
    name = None
    re_mod = re.compile(r'^\#\#\# <a name="(?P<name>[a-z_0-9]+)"></a>')
    readme_file = os.path.join(modules_directory(), "README.md")
    modules_dict = {}
    with open(readme_file) as f:
        for row in f.readlines():
            match = re_mod.match(row)
            if match:
                name = match.group("name")
                modules_dict[name] = []
                continue
            if row.startswith("---"):
                name = None
                continue
            if name:
                modules_dict[name].append(row)
    return modules_dict
608030
def _get_template(self, template_name, template_file):
        
        template = os.path.join(self.location, 'templates',
                                template_name, template_file)
        return jinja2.Template(open(template).read())
946114
def filled_out_template(filename, **substitutions):
    ''''''
    res = None
    with open(filename, 'r') as fp:
        template = fp.read()
        res = filled_out_template_str(template, **substitutions)
    return res