Log that target_file is going to be generated, and calculate its
    content by applying the linesubst() transformation with the given
    variables to each given lines.
765340
def txtsubst(lines, variables, target_file=None, charset=None):
    
    if target_file:
        LOG.info("In process of generating file %r", target_file)

    if not charset:
        return [linesubst(line, variables) for line in lines]

    ret = []
    for line in lines:
        linesub = linesubst(line, variables)
        if isinstance(line, unicode):
            ret.append(linesub.encode(charset))
        else:
            ret.append(linesub)
    return ret
1245485
def concat_generator(filename, up_threshold, low_threshold=10):
  """"""
  txt = ""
  for line in tf.gfile.Open(filename):
    line = line.strip()
    if len(txt) + len(line) + 1 >= up_threshold:
      ret = txt
      txt = ""
      # We don't yield very short long parts to prevent noisy examples.
      if len(ret) > low_threshold and len(ret) < up_threshold:
        yield {"targets": ret}

    if not txt:
      txt = line
    else:
      txt = " ".join([txt, line])
861646
def create_line_generator(self):
        

        if self.file_name.endswith(".gz"):
            if sys.version_info.major == 3:
                gz = gzip.open(self.file_name, mode='rt', encoding=self.encoding)
            else:
                gz = gzip.open(self.file_name, mode='rt')

            for line in gz.readlines():
                yield line

            gz.close()
        else:
            if sys.version_info.major == 3:
                # Python 3 native `open` is much faster
                file = open(self.file_name, mode='r', encoding=self.encoding)
            else:
                # Python 2 needs the codecs package to deal with encoding
                file = codecs.open(self.file_name, mode='r', encoding=self.encoding)

            for line in file:
                yield line

            file.close()
531615
function genDeps(basePath, targets) {
  var provideMap = new ProvideMap_();
  var requireMap = new RequireMap_();

  var files = [];
  targets.forEach(function(target) {
    files = files.concat(relativeGlob(target));
  });
  scanFiles(files, provideMap, requireMap);

  var results = genAddDependency(basePath, provideMap, requireMap);
  return results.join('\n');
}
258607
def write_targets(targets, **params):
    """"""
    handler = ReplacementHandler(**params)
    for target, regexer in regexer_for_targets(targets):
        with open(target) as fh:
            lines = fh.readlines()
        lines = replace_lines(regexer, handler, lines)
        with open(target, "w") as fh:
            fh.writelines(lines)
    if handler.missing:
        raise Exception(
            "Failed to complete all expected replacements: %r" % handler.missing
        )
1159555
def _walk_src(self, targets, flags, pipeline):
        """"""

        for target in targets:
            for f in glob.iglob(target, flags=flags | glob.S):
                if not os.path.isdir(f):
                    self.log('', 2)
                    self.log('> Processing: %s' % f, 1)
                    if pipeline:
                        try:
                            yield pipeline[0]._run_first(f)
                        except Exception as e:
                            err = self.get_error(e)
                            yield [filters.SourceText('', f, '', '', err)]
                    else:
                        try:
                            if self.default_encoding:
                                encoding = filters.PYTHON_ENCODING_NAMES.get(
                                    self.default_encoding, self.default_encoding
                                ).lower()
                                encoding = codecs.lookup(encoding).name
                            else:
                                encoding = self.default_encoding
                            yield [filters.SourceText('', f, encoding, 'file')]
                        except Exception as e:
                            err = self.get_error(e)
                            yield [filters.SourceText('', f, '', '', err)]
323530
def gen_totals(report, file_type):
    
    label = clr.stringc(file_type + " files   ", "bright purple")

    ok = field_value(report["ok_role"], "ok", c.LOG_COLOR["ok"], 0)
    skipped = field_value(report["skipped_role"], "skipped",
                          c.LOG_COLOR["skipped"], 16)
    changed = field_value(report["changed_role"], "changed",
                          c.LOG_COLOR["changed"], 16)

    # missing_meta = field_value(report["missing_meta_role"],
    #                            "missing meta(s)",
    #                            c.LOG_COLOR["missing_meta"], 16)

    # print "\n{0} {1} {2} {3}".format(ok, skipped, changed, missing_meta)

    print "\n{0} {1} {2} {3}".format(label, ok, skipped, changed)
22187
def analyze_log_file(logfile, pattern, reverse_paths=True, progress=True):
    ""
    if progress:
        lines = count_lines_in(logfile)
        pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=lines+1).start()
        counter = 0
    
    data = {}
    
    compiled_pattern = compile(pattern)
    for line in fileinput.input([logfile]):
        
        if progress:
            counter = counter + 1
        
        parsed = compiled_pattern.findall(line)[0]
        date = parsed[0]
        method = parsed[1]
        path = parsed[2]
        status = parsed[3]
        time = parsed[4]
        sql = parsed[5]
        sqltime = parsed[6]

        try:
            ignore = False
            for ignored_path in IGNORE_PATHS:
                compiled_path = compile(ignored_path)
                if compiled_path.match(path):
                    ignore = True
            if not ignore:
                if reverse_paths:
                    view = view_name_from(path)
                else:
                    view = path
                key = "%s-%s-%s" % (view, status, method)
                try:
                    data[key]['count'] = data[key]['count'] + 1
                    data[key]['times'].append(float(time))
                    data[key]['sql'].append(int(sql))
                    data[key]['sqltime'].append(float(sqltime))
                except KeyError:
                    data[key] = {
                        'count': 1,
                        'status': status,
                        'view': view,
                        'method': method,
                        'times': [float(time)],
                        'sql': [int(sql)],
                        'sqltime': [float(sqltime)],
                    }
        except Resolver404:
            pass
        
        if progress:
            pbar.update(counter)
    
    if progress:
        pbar.finish()
    
    return data
269213
def scan(text, filename='(none)')
      warnings = scan_for_file_warnings(text, filename)
      text = filter_fixable(warnings).inject(text) do |text, warning|
        warning.fix(text)
      end
      with_fixing_piped_to_output do
        text.split(/\n/).each_with_index do |line, number|
          warnings.concat process_line(line, number + 1, filename)
        end
      end
      warnings += unused_method_warnings
      warnings
    end
785797
def make_file_object_logger(fh):
    
    def logger_func(stmt, args, fh=fh):
        """
        A logger that logs everything sent to a file object.
        """
        now = datetime.datetime.now()
        six.print_("Executing (%s):" % now.isoformat(), file=fh)
        six.print_(textwrap.dedent(stmt), file=fh)
        six.print_("Arguments:", file=fh)
        pprint.pprint(args, fh)
    return logger_func
788825
def get_file_lines(self, subsystem, option):
        
        assert subsystem in self
        with open(os.path.join(self.per_subsystem[subsystem], subsystem + '.' + option)) as f:
            for line in f:
                yield line
511883
def set_lines( lines, target_level, indent_string="    ", indent_empty_lines=False ):
    

    first_non_empty_line_index = _get_first_non_empty_line_index( lines )
    first_line_original_level =  get_line_level( lines[first_non_empty_line_index], indent_string )

    for i in range(first_non_empty_line_index, len(lines)):
        if not indent_empty_lines and lines[i] == "":
            continue

        line_i_unindented = get_line_unindented( lines[i], indent_string )
        line_i_level =      get_line_level( lines[i], indent_string )

        on_second_line_or_later = i > first_non_empty_line_index
        if on_second_line_or_later:
            first_line_final_level = get_line_level( lines[first_non_empty_line_index], indent_string )
            relative_indent_move =   first_line_final_level - first_line_original_level
            target_level =           line_i_level + relative_indent_move

        if line_i_level == target_level:
            continue

        lines[i] = indent_string * target_level + line_i_unindented
1120573
public function trace( string $file, int $line, string $target, string $message, string $tag = NULL )
    {
        self::log( $file, $line, "T:$target", $message, $tag );
    }
212785
def apply_filters(target, lines):
    
    filters = get_filters(target)
    if filters:
        for l in lines:
            if any(f in l for f in filters):
                yield l
    else:
        for l in lines:
            yield l
1271037
def action(arguments):
    
    for input_file in arguments.input_files:
        logging.info(input_file)
        # Generate a temporary file
        with common.atomic_write(
                input_file.name, file_factory=common.FileType('wt')) as tf:
            convert.transform_file(input_file, tf, arguments)
            if hasattr(input_file, 'close'):
                input_file.close()
306577
def _variable_parts(self, line, codeline):
        """"""
        var_subs = []
        # codeline has pattern and then has the outputs in different versions
        if codeline:
            var_subs = self._find_variable(codeline.pattern, line)
        else:
            # make variable part of the line string without all the other stuff
            line_str = self._strip_datetime(self._strip_counters(line))
            var_subs = [line_str.strip()]
        return var_subs
1108029
def faz(input_file, variables=None):
    
    logging.debug("input file:\n {0}\n".format(input_file))
    tasks = parse_input_file(input_file, variables=variables)
    print("Found {0} tasks.".format(len(tasks)))
    graph = DependencyGraph(tasks)
    graph.show_tasks()
    graph.execute()