From 72359abd9ed3ec9d1cd0550db3f743d82913a03d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Wed, 28 Sep 2016 11:36:18 +0200 Subject: save help to copy spec from remi to fedora --- getspec | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100755 getspec (limited to 'getspec') diff --git a/getspec b/getspec new file mode 100755 index 0000000..ad45dd1 --- /dev/null +++ b/getspec @@ -0,0 +1,115 @@ +#!/usr/bin/php + [ ] + +Otions: + -n : no new changelog entry +\n"); +} +if (!$fedo) { + $fedo = basename($remi); +} +if (!file_exists($fedo) && strpos($fedo, '-dev')) { + $fedo = str_replace('-dev', '', $fedo); +} + +printf("Reading remi's spec: %s\n", $remi); +$rem = file_get_contents($remi); +if (!$rem) { + die("Cannot read $remi\n"); +} +$rem = explode("\n", $rem); + +printf("Reading fedora's spec: %s\n", $fedo); +$fed = file_get_contents($fedo); +if (!$fed) { + die("Cannot read $fedo\n"); +} +$fed = explode("\n", $fed); + +printf("Merging\n"); + +$out = []; +$inchangelog = false; +$empty = 0; +$skip = 0; +foreach ($rem as $l) { + if ($l == '%changelog') { + $inchangelog = true; + } + if (preg_match('/^BuildRoot:/', $l) || + preg_match('/^rm -rf( )*%{buildroot}$/', $l) || + preg_match('/^%defattr/', $l) || + preg_match('/^# remirepo spec/', $l) || + preg_match('/%clean/', $l)) { + continue; + } + if (preg_match("/# remirepo:([0-9]+)/", $l, $reg)) { + $skip = $reg[1]; + continue; + } + if ($skip) { + $skip--; + continue; + } + if ($l) { + $out[] = $l; + $empty = 0; + } else { + if ($empty < 2) { + $out[] = $l; + } + $empty++; + } + + if ($inchangelog) { + if ($ignorechangelog) { + // After entering changelog + break; + } + if (!$l) { + // After 1st new Changelog entry + break; + } + } +} + +$inchangelog = false; +foreach ($fed as $l) { + if ($l == '%changelog') { + $inchangelog = true; + continue; + } + if ($inchangelog) { + $out[] = $l; + } +} + +printf("Saving $fedo\n"); +file_put_contents($fedo, implode("\n", $out)); + -- cgit