<commit_before>#!/usr/bin/env python

import os
import sqlite3
import sys


def print_format(wc_path):
  entries = os.path.join(wc_path, '.svn', 'entries')
  wc_db = os.path.join(wc_path, '.svn', 'wc.db')

  if os.path.exists(entries):
    formatno = int(open(entries).readline())
  elif os.path.exists(wc_db):
    conn = sqlite3.connect(wc_db)
    curs = conn.cursor()
    curs.execute('pragma user_version;')
    formatno = curs.fetchone()[0]
  else:
    formatno = 'not under version control'

  # see subversion/libsvn_wc/wc.h for format values and information
  #   1.0.x -> 1.3.x: format 4
  #   1.4.x: format 8
  #   1.5.x: format 9
  #   1.6.x: format 10
  #   1.7.x: format XXX
  print '%s: %s' % (wc_path, formatno)


if __name__ == '__main__':
  paths = sys.argv[1:]
  if not paths:
    paths = ['.']
  for wc_path in paths:
    print_format(wc_path)<commit_msg>Teach a helper script to look for .svn directories in the parents.<commit_after>#!/usr/bin/env python

import os
import sqlite3
import sys


def get_format(wc_path):
  entries = os.path.join(wc_path, '.svn', 'entries')
  wc_db = os.path.join(wc_path, '.svn', 'wc.db')

  if os.path.exists(entries):
    formatno = int(open(entries).readline())
  elif os.path.exists(wc_db):
    conn = sqlite3.connect(wc_db)
    curs = conn.cursor()
    curs.execute('pragma user_version;')
    formatno = curs.fetchone()[0]
  else:
    parent_path = os.path.dirname(os.path.abspath(wc_path))
    if wc_path != parent_path:
      return get_format(parent_path)
    else:
      return 'not under version control'

  return formatno

def print_format(wc_path):
  # see subversion/libsvn_wc/wc.h for format values and information
  #   1.0.x -> 1.3.x: format 4
  #   1.4.x: format 8
  #   1.5.x: format 9
  #   1.6.x: format 10
  #   1.7.x: format XXX
  formatno = get_format(wc_path)
  print '%s: %s' % (wc_path, formatno)


if __name__ == '__main__':
  paths = sys.argv[1:]
  if not paths:
    paths = ['.']
  for wc_path in paths:
    print_format(wc_path)
{'fraction_non_alphanumeric': 0.14512922465208747, 'fraction_numerical': 0.020874751491053677, 'mean_word_length': 3.13347022587269, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3589026', 'n_tokens_mistral': 814, 'n_tokens_neox': 775, 'n_words': 184}