#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, unicode_literals

import bikeshed
import datetime
import io
import json
import os
import subprocess

def main():
	updateAndCommit()

def updateAndCommit():
	print datetime.datetime.utcnow()

	scriptPath = os.path.dirname(os.path.realpath(__file__))
	dataPath = os.path.join(scriptPath, "data")

	try:
		with io.open(os.path.join(dataPath, "manifest.txt"), 'r', encoding="utf-8") as fh:
			oldDate,_,oldManifest = fh.read().partition("\n")
	except:
		raise

	updateDataFiles(path=dataPath)

	try:
		with io.open(os.path.join(dataPath, "manifest.txt"), 'r', encoding="utf-8") as fh:
			_,_,newManifest = fh.read().partition("\n")
	except:
		raise
	if oldManifest == newManifest:
		# No change
		print "Manifest is unchanged since {0}, nothing to be committed".format(oldDate)
		return

	os.chdir(scriptPath)
	print subprocess.check_output("git add data", shell=True)
	print subprocess.check_output("git commit -m 'update data'", shell=True)
	print subprocess.check_output("git push", shell=True)

def updateDataFiles(path):
	# First, update the Bikeshed-managed data files
	# (This updates the manifest file automatically.)
	bikeshed.config.quiet = False
	bikeshed.update.update(path=path, force=True)

	# Then the WPT data files, adding the file to Bikeshed's data folder
	#updateWptDataFiles(dataPath=path)

	# And now manually update the Bikeshed manifest again.
	#bikeshed.update.manifest.createManifest(path=path)

def updateWptDataFiles(dataPath):
	return # no-op for now until WPT is fixed
	scriptPath = os.path.dirname(os.path.realpath(__file__))
	wptPath = os.path.join(scriptPath, "web-platform-tests")

	os.chdir(scriptPath)
	try:
		subprocess.check_call("git submodule update --remote", shell=True)
	except Exception as e:
		print e
		return
	os.chdir(wptPath)
	try:
		subprocess.check_call("wpt manifest", shell=True)
	except Exception as e:
		print e
		return

	paths = []
	with io.open(os.path.join(wptPath, "MANIFEST.json"), 'r', encoding="utf-8") as infile:
		jsonData = json.load(infile)
		for testType, typePaths in jsonData["items"].items():
			if testType in ("support", "reftest_node"):
				# Not tests
				continue
			paths.extend(typePaths.keys())
	with io.open(os.path.join(dataPath, "wpt-tests.txt"), "w", encoding="utf-8") as outfile:
		for path in sorted(paths):
			outfile.write(path + "\n")

if __name__ == "__main__":
	main()

@@ -1100,1303 +1100,86 @@
 ):%0A%09
-# First, update the Bikeshed-managed data files%0A%09# (This updates the manifest file automatically.)%0A%09bikeshed.config.quiet = False%0A%09bikeshed.update.update(path=path, force=True)%0A%0A%09# Then the WPT data files, adding the file to Bikeshed's data folder%0A%09#updateWptDataFiles(dataPath=path)%0A%0A%09# And now manually update the Bikeshed manifest again.%0A%09#bikeshed.update.manifest.createManifest(path=path)%0A%0Adef updateWptDataFiles(dataPath):%0A%09return # no-op for now until WPT is fixed%0A%09scriptPath = os.path.dirname(os.path.realpath(__file__))%0A%09wptPath = os.path.join(scriptPath, %22web-platform-tests%22)%0A%0A%09os.chdir(scriptPath)%0A%09try:%0A%09%09subprocess.check_call(%22git submodule update --remote%22, shell=True)%0A%09except Exception as e:%0A%09%09print e%0A%09%09return%0A%09os.chdir(wptPath)%0A%09try:%0A%09%09subprocess.check_call(%22wpt manifest%22, shell=True)%0A%09except Exception as e:%0A%09%09print e%0A%09%09return%0A%0A%09paths = %5B%5D%0A%09with io.open(os.path.join(wptPath, %22MANIFEST.json%22), 'r', encoding=%22utf-8%22) as infile:%0A%09%09jsonData = json.load(infile)%0A%09%09for testType, typePaths in jsonData%5B%22items%22%5D.items():%0A%09%09%09if testType in (%22support%22, %22reftest_node%22):%0A%09%09%09%09# Not tests%0A%09%09%09%09continue%0A%09%09%09paths.extend(typePaths.keys())%0A%09with io.open(os.path.join(dataPath, %22wpt-tests.txt%22), %22w%22, encoding=%22utf-8%22) as outfile:%0A%09%09for path in sorted(paths):%0A%09%09%09outfile.write(path + %22%5Cn%22)
+bikeshed.config.quiet = False%0A%09bikeshed.update.update(path=path, force=True)%0A%0A
 %0A%0Aif

Remove the old WPT stuff.