Anonymous avatar Anonymous committed 6347b8d

Yaml-rewriting attempts that used to be in Chrysoberyl.

Comments (0)

Files changed (3)

python/canonicalize-yaml.py

+#!/usr/bin/env python
+# encoding: UTF-8
+
+import os
+import sys
+import re
+
+for line in sys.stdin:
+    match = re.match(r'^(\s*\-?\s*version:\s*)([0123456789.]*?)$', line)
+    if match:
+        sys.stdout.write(match.group(1) + '"' + match.group(2) + '"\n')
+        continue
+    match = re.match(r'^(\s*\-?\s*revision:\s*)([0123456789.]*?)$', line)
+    if match:
+        sys.stdout.write(match.group(1) + '"' + match.group(2) + '"\n')
+        continue
+    match = re.match(r'^(.*?): yes$', line)
+    if match:
+        sys.stdout.write(match.group(1) + ": true\n")
+        continue
+    match = re.match(r'^(.*?): no$', line)
+    if match:
+        sys.stdout.write(match.group(1) + ": false\n")
+        continue
+    if re.match(r'^.*?:$', line.rstrip()):
+        sys.stdout.write(line.rstrip() + " \n")
+    else:
+        sys.stdout.write(line)
+
+      

python/rewrite-yaml.py

+#!/usr/bin/env python
+# encoding: UTF-8
+
+# This isn't very good, as it doesn't retain order within a YAML file.
+
+import os
+import sys
+
+import yaml
+try:
+    from yaml import CLoader as Loader, CDumper as Dumper
+except ImportError:
+    from yaml import Loader, Dumper
+
+
+if __name__ == '__main__':
+    file = open(sys.argv[1])
+    data = yaml.load(file, Loader=Loader)
+    file.close()
+
+    for key in data:
+        if 'type' not in data[key]:
+            data[key]['type'] = 'Distribution'
+
+    file = open(sys.argv[1] + ".out", 'w')
+    file.write(yaml.dump(data, Dumper=Dumper, default_flow_style=False))
+    file.close()

ruby/rewrite-yaml.rb

+#!/usr/bin/env ruby1.9.1
+# encoding: UTF-8
+
+# Requires Ruby 1.9.1 for its order-retaining hashes.
+
+require 'yaml'
+
+data = YAML.load_file(ARGV[0])
+
+open('output.yaml', 'w') do |f|
+  YAML::dump(data, f)
+end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.