<commit_before>#!/usr/bin/python

import os
import os.path
import sys
import json

DIRECTORY = "/home/tannewt/code/rcbuild.info-parts"
def merge(original, new):
  if "name" not in original or not original["name"]:
    original["name"] = new["name"]
  if "manufacturer" in new and ("manufacturer" not in original or not original["manufacturer"]):
    original["manufacturer"] = new["manufacturer"]
  for urltype in ["store", "manufacturer", "related"]:
    for url in new["urls"][urltype]:
      if url not in original["urls"][urltype]:
        original["urls"]["store"].append(url)
  return original


def mergeFiles(merges, destination, part = None, test = False):
  if os.path.isfile(destination):
    with open(destination, "r") as f:
      part = json.load(f)
  for fn in merges:
    print fn
    with open(fn, "r") as f:
      this_part = json.load(f)
      if part:
        part = merge(part, this_part)
      else:
        part = this_part

  for fn in merges:
    print fn
    target = os.path.relpath(destination, os.path.dirname(fn))
    if not test:
      os.remove(fn)
      os.symlink(target, fn)
    else:
      print "symlink " + fn + " -> " + target
  if not test:
    with open(destination, "w") as f:
      json.dump(part, f, indent=1, sort_keys=True)
  else:
    print destination
    print part
    print

if __name__ == "__main__":
  merges = sys.argv[1:-1]
  destination = sys.argv[-1]
  mergeFiles(merges, destination)<commit_msg>python3 style print calls<commit_after>#!/usr/bin/python

import os
import os.path
import sys
import json

DIRECTORY = "/home/tannewt/code/rcbuild.info-parts"
def merge(original, new):
  if "name" not in original or not original["name"]:
    original["name"] = new["name"]
  if "manufacturer" in new and ("manufacturer" not in original or not original["manufacturer"]):
    original["manufacturer"] = new["manufacturer"]
  for urltype in ["store", "manufacturer", "related"]:
    for url in new["urls"][urltype]:
      if url not in original["urls"][urltype]:
        original["urls"]["store"].append(url)
  return original


def mergeFiles(merges, destination, part = None, test = False):
  if os.path.isfile(destination):
    with open(destination, "r") as f:
      part = json.load(f)
  for fn in merges:
    with open(fn, "r") as f:
      this_part = json.load(f)
      if part:
        part = merge(part, this_part)
      else:
        part = this_part

  for fn in merges:
    target = os.path.relpath(destination, os.path.dirname(fn))
    if not test:
      os.remove(fn)
      os.symlink(target, fn)
    else:
      print("symlink " + fn + " -> " + target)
  if not test:
    with open(destination, "w") as f:
      json.dump(part, f, indent=1, sort_keys=True)
  else:
    print(destination)
    print(part)
    print

if __name__ == "__main__":
  merges = sys.argv[1:-1]
  destination = sys.argv[-1]
  mergeFiles(merges, destination)
{'fraction_non_alphanumeric': 0.13955094991364422, 'fraction_numerical': 0.0031088082901554403, 'mean_word_length': 3.2031930333817127, 'pattern_counts': {'":': 2, '<': 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': '6782929', 'n_tokens_mistral': 976, 'n_tokens_neox': 968, 'n_words': 275}