Output information for a directory of replays.
186648
def _replay_index(replay_dir):
  """"""
  run_config = run_configs.get()
  replay_dir = run_config.abs_replay_path(replay_dir)
  print("Checking: ", replay_dir)

  with run_config.start(want_rgb=False) as controller:
    print("-" * 60)
    print(",".join((
        "filename",
        "build",
        "map_name",
        "game_duration_loops",
        "players",
        "P1-outcome",
        "P1-race",
        "P1-apm",
        "P2-race",
        "P2-apm",
    )))

    try:
      bad_replays = []
      for file_path in run_config.replay_paths(replay_dir):
        file_name = os.path.basename(file_path)
        try:
          info = controller.replay_info(run_config.replay_data(file_path))
        except remote_controller.RequestError as e:
          bad_replays.append("%s: %s" % (file_name, e))
          continue
        if info.HasField("error"):
          print("failed:", file_name, info.error, info.error_details)
          bad_replays.append(file_name)
        else:
          out = [
              file_name,
              info.base_build,
              info.map_name,
              info.game_duration_loops,
              len(info.player_info),
              sc_pb.Result.Name(info.player_info[0].player_result.result),
              sc_common.Race.Name(info.player_info[0].player_info.race_actual),
              info.player_info[0].player_apm,
          ]
          if len(info.player_info) >= 2:
            out += [
                sc_common.Race.Name(
                    info.player_info[1].player_info.race_actual),
                info.player_info[1].player_apm,
            ]
          print(u",".join(str(s) for s in out))
    except KeyboardInterrupt:
      pass
    finally:
      if bad_replays:
        print("\n")
        print("Replays with errors:")
        print("\n".join(bad_replays))
548167
def info(filename):
    ''''''
    try:
        out = subprocess.check_output([_dicom_hdr,'-sexinfo',filename])
    except subprocess.CalledProcessError:
        return None
    slice_timing_out = subprocess.check_output([_dicom_hdr,'-slice_times',filename])
    slice_timing = [float(x) for x in slice_timing_out.strip().split()[5:]]
    frames = []
    for frame in re.findall(r'^(\w{4}) (\w{4})\s+(\d+) \[(\d+)\s+\] \/\/(.*?)\/\/(.*?)$',out,re.M):
        new_frame = {}
        new_frame['addr'] = (int(frame[0],16),int(frame[1],16))
        new_frame['size'] = int(frame[2])
        new_frame['offset'] = int(frame[3])
        new_frame['label'] = frame[4].strip()
        new_frame['value'] = frame[5].strip()
        frames.append(new_frame)
    sex_info = {}
    for i in re.findall(r'^(.*?)\s+= (.*)$',out,re.M):
        sex_info[i[0]] = i[1]

    return DicomInfo(frames,sex_info,slice_timing)
219525
def geist_replay(wrapped, instance, args, kwargs):
    """"""
    path_parts = []
    file_parts = []

    if hasattr(wrapped, '__module__'):
        module = wrapped.__module__
        module_file = sys.modules[module].__file__
        root, _file = os.path.split(module_file)
        path_parts.append(root)
        _file, _ = os.path.splitext(_file)
        file_parts.append(_file)
    if hasattr(wrapped, '__objclass__'):
        file_parts.append(wrapped.__objclass__.__name__)
    elif hasattr(wrapped, '__self__'):
        file_parts.append(wrapped.__self__.__class__.__name__)
    file_parts.append(wrapped.__name__ + '.log')
    path_parts.append('_'.join(file_parts))
    filename = os.path.join(*path_parts)

    if is_in_record_mode():
        platform_backend = get_platform_backend()
        backend = RecordingBackend(
            source_backend=platform_backend,
            recording_filename=filename
        )
    else:
        backend = PlaybackBackend(
            recording_filename=filename
        )
    gui = GUI(backend)
    return wrapped(gui, *args, **kwargs)
1036529
def output_files(self):
        
        outs = [os.path.join(self.address.repo, self.address.path, x)
                for x in self.params['outs']]
        return outs
1252722
def _get_all_run_infos(self):
    """"""
    info_dir = self._settings.info_dir
    if not os.path.isdir(info_dir):
      return []
    paths = [os.path.join(info_dir, x) for x in os.listdir(info_dir)]

    # We copy the RunInfo as a dict, so we can add stuff to it to pass to the template.
    # We filter only those that have a timestamp, to avoid a race condition with writing
    # that field.
    return [d for d in
            [RunInfo(os.path.join(p, 'info')).get_as_dict() for p in paths
             if os.path.isdir(p) and not os.path.islink(p)]
            if 'timestamp' in d]
1011202
def show(self):
        """"""
        for entry in self._entries:
            print "{'%s': %s, 'records': %s}" % (
                entry._record_type, entry.host, entry.records)
        print
1112810
def dumps():
    """"""
    d = {}
    for k, v in FILTERS.items():
        d[dr.get_name(k)] = list(v)
    return _dumps(d)
586662
def live_dirs(self):
    """"""
    # The only caller of this function is the workdir cleaning pipeline. It is not clear that the previous_results_dir
    # should be returned for that purpose. And, by the time this is called, the contents have already been copied.
    if self.has_results_dir:
      yield self.results_dir
      yield self.current_results_dir
      if self.has_previous_results_dir:
        yield self.previous_results_dir
1190811
def records(self):
        """"""

        return (self._session.query(Process)
                .filter(Process.d_vid == self._d_vid)).all()
95991
def _collect_data(directory):
  
  # Returns:
  data_files = []
  transcripts = [
      filename for filename in os.listdir(directory)
      if filename.endswith(".csv")
  ]
  for transcript in transcripts:
    transcript_path = os.path.join(directory, transcript)
    with open(transcript_path, "r") as transcript_file:
      transcript_reader = csv.reader(transcript_file)
      # skip header
      _ = next(transcript_reader)
      for transcript_line in transcript_reader:
        media_name, label = transcript_line[0:2]
        filename = os.path.join(directory, media_name)
        data_files.append((media_name, filename, label))
  return data_files
890928
def history(directory, rev_range, verbose, indicate_current):
    """"""
    _history(directory, rev_range, verbose, indicate_current)
1285418
def write_to_files_rec(instances, tokenizer, max_seq_length,
                       max_predictions_per_seq, output_files):
    """"""
    writers = []
    for output_file in output_files:
        writers.append(
            mx.recordio.MXIndexedRecordIO(
                os.path.splitext(output_file)[0] + '.idx', output_file, 'w'))

    writer_index = 0
    total_written = 0
    for (inst_index, instance) in enumerate(instances):
        features = transform(instance, tokenizer, max_seq_length, max_predictions_per_seq)
        example = features

        writers[writer_index].write_idx(inst_index, json.dumps(example).encode('UTF-8'))
        writer_index = (writer_index + 1) % len(writers)
        total_written += 1

    for writer in writers:
        writer.close()

    logging.info('Wrote %d total instances', total_written)
158421
def output_for_debugging(self, stream, data):
        """"""
        with open('%s.spec.out' % stream.name, 'w') as f: f.write(str(data))
1275715
def inspect(self):
        """"""
        results = {}
        for fname in dir(self):
            if not fname.startswith('_'):
                value = getattr(self, fname)
                if isinstance(value, collections.Callable):
                    continue
                results[fname] = value
        return results
372452
def list_dms (archive, compression, cmd, verbosity, interactive):
    """"""
    check_archive_ext(archive)
    return [cmd, 'v', archive]
1196259
def _stage_output_files(self, file_mapping, dry_run=True):
        """"""
        # print ("Staging output ", file_mapping)
        if self._file_stage is None:
            return
        self._file_stage.copy_from_scratch(file_mapping, dry_run)
948469
def _generate_examples(self, archive, directory):
    """"""
    reg = re.compile(os.path.join("^%s" % directory, "(?P<label>neg|pos)", ""))
    for path, imdb_f in archive:
      res = reg.match(path)
      if not res:
        continue
      text = imdb_f.read().strip()
      yield {
          "text": text,
          "label": res.groupdict()["label"],
      }