diff options
author | Remi Collet <fedora@famillecollet.com> | 2016-09-28 11:36:18 +0200 |
---|---|---|
committer | Remi Collet <fedora@famillecollet.com> | 2016-09-28 11:36:18 +0200 |
commit | 72359abd9ed3ec9d1cd0550db3f743d82913a03d (patch) | |
tree | c2b98cc5a41eb9f6130aa5115c27b5cef4e44b8a /getspec | |
parent | 4f93f81e1060b7d8e77a5add91bb7d4ddcebebe9 (diff) |
save help to copy spec from remi to fedora
Diffstat (limited to 'getspec')
-rwxr-xr-x | getspec | 115 |
1 files changed, 115 insertions, 0 deletions
@@ -0,0 +1,115 @@ +#!/usr/bin/php +<?php + +$ignorechangelog = false; +$remi = false; +$fedo = false; +// Parsing arg +for ($i=1 ; $i < $_SERVER['argc'] ; $i++) { + switch ($arg=$_SERVER['argv'][$i]) { + case '-n': + $ignorechangelog = true; + break; + default: + if ($arg[0] == '-') { + die("Unkown option $arg\n"); + } else if ($fedo) { + die("Too much arguments\n"); + } else if ($remi) { + $fedo = $arg; + } else { + $remi = $arg; + } + } +} + +if (!$remi) { + die(" +Usage getspec [ -n ] <remispec> [ <fedoraspec> ] + +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)); + |