Unverified Commit 08656b92 authored by Paul Wise's avatar Paul Wise

Add a script for importing patches/ directories into sources.patches

Some sources.patches files got corrupted due to lack of disk space,
this script will allow restoring sources.patches for inactive distros,
which will not have their sources.patches created by the normal method.
parent 504a9688
#!/usr/bin/python3
# Copyright 2019 Paul Wise
# Released under the MIT/Expat license, see doc/COPYING
# Fixes up the list of changed source packages
#
# Usage:
# fixup-source-patches <patches directory> <source patches list>
import os
import sys
import yaml
deriv = os.path.basename(os.getcwd())
patches_dir = sys.argv[1]
sources_patches = sys.argv[2]
# Nothing to do if the patches dir doesn't exist
if not os.path.isdir(patches_dir):
sys.exit()
# Helper functions
def shortslug(name):
return name[:4] if name.startswith('lib') else name[0]
ext_patch = '.patch'
ext_dpatch = '.debian.patch'
def strip_extensions(string):
if string.endswith(ext_dpatch):
return string[:-len(ext_dpatch)]
elif string.endswith(ext_patch):
return string[:-len(ext_patch)]
else:
return string
# Load the old information about patched versions
try:
f = open(sources_patches)
patches = yaml.load(f, Loader=yaml.CSafeLoader)
f.close()
except IOError:
patches = []
# Load data about patches from patch symlinks
for root, dirs, files in os.walk(patches_dir):
for file in files:
if not file.endswith(ext_patch): continue
info = strip_extensions(file).split('_')
type = 'deriv' if len(info) == 4 else 'global'
if type == 'deriv':
debian_name, debian_version, name, version = info
elif type == 'global':
debian, debian_name, debian_version, deriv, name, version = info
path = os.path.join(root, file)
link = os.readlink(path)
info = strip_extensions(link).split('/')
debian_sha1 = info[7]
sha1 = info[10]
patch = '_'.join((debian_name, debian_version, name, version)) + ext_patch
patch = os.path.join(shortslug(debian_name), debian_name, patch)
debian_patch = '_'.join((debian_name, debian_version, name, version)) + ext_dpatch
debian_patch = os.path.join(shortslug(debian_name), debian_name, debian_patch)
info = {
'debian_name': debian_name,
'debian_version': debian_version,
'name': name,
'version': version,
'debian_sha1': debian_sha1,
'sha1': sha1,
'patches': [patch, debian_patch],
}
if type == 'global':
info['deriv'] = deriv
patches.append(info)
# Calculate the output
# The general patch metadata
f = open(sources_patches,'w')
yaml.dump(patches, f, Dumper=yaml.CSafeDumper)
f.close()
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