Switch the YAML loader/dumper to CSafeLoader/CSafeDumper

This should be much faster than the regular loader/dumper.
The current sources.patches file is 82MB so it takes a while to parse.
parent 3ab69f19
......@@ -18,7 +18,7 @@ sources_files = sys.argv[-1]
try:
f = open(sources_files)
files = yaml.safe_load(f)
files = yaml.load(f, Loader=yaml.CSafeLoader)
f.close()
except IOError:
files = {}
......@@ -30,7 +30,7 @@ for deriv in derivatives:
# their files may go missing at any time.
try:
f = open(os.path.join(deriv,'sources.files'))
data = yaml.safe_load(f)
data = yaml.load(f, Loader=yaml.CSafeLoader)
f.close()
except IOError:
continue
......@@ -50,5 +50,5 @@ for sha1 in set(files)-set(new_files):
files[sha1]['obsolete'] = True
f = open(sources_files,'w')
yaml.safe_dump(files, f)
yaml.dump(files, f, Dumper=yaml.CSafeDumper)
f.close()
......@@ -24,7 +24,7 @@ sources_patches_pts = sys.argv[-1]
# Load the old information about patched versions
try:
f = open(sources_patches)
old_patches = yaml.safe_load(f)
old_patches = yaml.load(f, Loader=yaml.CSafeLoader)
f.close()
except IOError:
old_patches = []
......@@ -37,7 +37,7 @@ for deriv in derivatives:
# their files may go missing at any time.
try:
f = open(os.path.join(deriv,'sources.patches'))
data = yaml.safe_load(f)
data = yaml.load(f, Loader=yaml.CSafeLoader)
f.close()
except IOError:
continue
......@@ -63,10 +63,10 @@ patches = old_patches + new_patches
debian_names = set([patch['debian_name'] for patch in patches if not patch.get('obsolete', False) and patch['deriv'] != 'Ubuntu'])
patches_pts = dict((name, '/'.join((url,shortslug(name),name,''))) for name in debian_names)
f = open(sources_patches_pts,'w')
yaml.safe_dump(patches_pts, f)
yaml.dump(patches_pts, f, Dumper=yaml.CSafeDumper)
f.close()
# The general patch metadata
f = open(sources_patches,'w')
yaml.safe_dump(patches, f)
yaml.dump(patches, f, Dumper=yaml.CSafeDumper)
f.close()
......@@ -1193,7 +1193,7 @@ if data:
elif hash_type != 'sha1' and hash != output_data[sha1][hash_type]:
logging.warning('hashes mismatched: %s: %s %s != %s', sha1, hash_type, hash, output_data[sha1][hash_type])
with open(os.path.abspath(filename), 'w') as output:
yaml.safe_dump(output_data, output)
yaml.dump(output_data, output, Dumper=yaml.CSafeDumper)
filename = sys.argv[4]
data = patches
......@@ -1220,7 +1220,7 @@ if data:
item['parts'] = parts_sha1
output_data.append(item)
with open (os.path.abspath(filename), 'w') as output:
yaml.safe_dump(output_data, output)
yaml.dump(output_data, output, Dumper=yaml.CSafeDumper)
else:
remove(filename)
......@@ -1241,7 +1241,7 @@ if data:
item['dsc'] = dsc_url
output_data[debian_name][debian_version].append(item)
with open (os.path.abspath(filename), 'w') as output:
yaml.safe_dump(output_data, output)
yaml.dump(output_data, output, Dumper=yaml.CSafeDumper)
else:
remove(filename)
......@@ -1258,7 +1258,7 @@ if data:
output_data[name][version] = []
output_data[name][version].append(str(dsc_url))
with open(os.path.abspath(filename), 'w') as output:
yaml.safe_dump(output_data, output)
yaml.dump(output_data, output, Dumper=yaml.CSafeDumper)
else:
remove(filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment