| |
@@ -27,6 +27,7 @@
|
| |
XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
|
| |
CACHEDIR = os.path.join(XDG_CACHE_HOME, "rust2rpm")
|
| |
API_URL = "https://crates.io/api/v1/"
|
| |
+ DIST_GIT_URL = "https://src.fedoraproject.org/api/0/"
|
| |
JINJA_ENV = jinja2.Environment(
|
| |
loader=jinja2.ChoiceLoader([
|
| |
jinja2.FileSystemLoader(["/"]),
|
| |
@@ -239,6 +240,15 @@
|
| |
if matcher.match(f) and not LICENSES.match(f) and not matcherex.match(f):
|
| |
yield os.path.relpath(os.path.join(root, f), path)
|
| |
|
| |
+ def get_package_info(package):
|
| |
+ url = requests.compat.urljoin(DIST_GIT_URL, f"rpms/{package}")
|
| |
+ req = requests.get(url, headers={"User-Agent": "rust2rpm"})
|
| |
+ json = req.json()
|
| |
+ if "name" in json:
|
| |
+ return json
|
| |
+ else:
|
| |
+ return None
|
| |
+
|
| |
def make_diff_metadata(crate, version, patch=False, store=False):
|
| |
if _is_path(crate):
|
| |
# Only things that look like a paths are considered local arguments
|
| |
@@ -294,6 +304,8 @@
|
| |
help="Print mapping for specified license and exit")
|
| |
parser.add_argument("--no-auto-changelog-entry", action="store_true",
|
| |
help="Do not generate a changelog entry")
|
| |
+ parser.add_argument("--no-existence-check", action="store_true",
|
| |
+ help="Do not check whether the package already exists in dist-git")
|
| |
parser.add_argument("-", "--stdout", action="store_true",
|
| |
help="Print spec and patches into stdout")
|
| |
parser.add_argument("-t", "--target", action="store",
|
| |
@@ -374,6 +386,14 @@
|
| |
kwargs["pkg_suffix"] = suffix
|
| |
spec_file = pathlib.Path(f"rust-{metadata.name}{suffix}.spec")
|
| |
|
| |
+ if args.target in {"fedora"} and not args.no_existence_check and not os.path.exists(spec_file):
|
| |
+ # No specfile, so this is probably a new package
|
| |
+ package_info = get_package_info(f"rust-{metadata.name}{suffix}")
|
| |
+ if package_info:
|
| |
+ print(f"Crate {metadata.name}{suffix} is already packaged in Fedora ({package_info['full_url']}).")
|
| |
+ print("Re-run with --no-existence-check if you still want to convert it.")
|
| |
+ sys.exit(1)
|
| |
+
|
| |
kwargs["auto_changelog_entry"] = not args.no_auto_changelog_entry
|
| |
|
| |
if args.rpmautospec:
|
| |
Basic implementation for #126. As @ngompa mentioned there, this will need some generalization to make it distro-independent, but it's a start.