You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rust-packaging/0008-Mangle-summary-automag...

86 lines
2.7 KiB

From 216de8e4271f9dbca1f009e8c0e046a7f5a198fd Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Wed, 15 May 2019 08:01:46 +0200
Subject: [PATCH 08/14] Mangle summary automagically
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
---
rust2rpm/metadata.py | 35 ++++++++++++++++++++++++++++++++++-
rust2rpm/templates/main.spec | 3 +--
2 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/rust2rpm/metadata.py b/rust2rpm/metadata.py
index 77c2932..e41902d 100644
--- a/rust2rpm/metadata.py
+++ b/rust2rpm/metadata.py
@@ -3,6 +3,7 @@ __all__ = ["Dependency", "Metadata"]
import collections
import copy
import json
+import re
import subprocess
import semantic_version as semver
@@ -116,11 +117,43 @@ class Metadata:
self.license = None
self.license_file = None
self.readme = None
- self.description = None
+ self._description = None
+ self._summary = None
self.targets = set()
self.dependencies = {}
self.dev_dependencies = set()
+ @property
+ def description(self):
+ return self._description
+
+ @property
+ def summary(self):
+ return self._summary
+
+ @description.setter
+ def description(self, description):
+ # https://salsa.debian.org/rust-team/debcargo/blob/master/src/crates.rs
+ # get_summary_description()
+ if description is None:
+ self._description = self._summary = None
+ return
+ description = description.replace('\n\n', '\r').replace('\n', ' ').replace('\r', '\n').strip()
+ description = re.sub(r'^(?:a|an|the)\s+', '', description, flags=re.I)
+ description = f'{description[0].upper()}{description[1:]}'
+ if description[-1] != '.':
+ description = f'{description}.'
+
+ p1 = description.find('.')
+ p2 = description.find('\n')
+ if p2 != -1:
+ p = min(p1, p2)
+ else:
+ p = p1
+
+ self._description = description
+ self._summary = description[:p]
+
@classmethod
def from_json(cls, metadata):
md = metadata
diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec
index 0ef0b10..803b74e 100644
--- a/rust2rpm/templates/main.spec
+++ b/rust2rpm/templates/main.spec
@@ -16,8 +16,7 @@ Release: {{ pkg_release }}
{% if md.description is none %}
Summary: # FIXME
{% else %}
-{% set description_lines = md.description.split("\n") %}
-Summary: {{ description_lines|join(" ")|trim }}
+Summary: {{ md.summary }}
{% endif %}
{% if rust_group is defined %}
Group: {{ rust_group }}
--
2.22.0.rc3