-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add archiving option, fix exceptions, caused by multiline content in …
…tag in spec files
- Loading branch information
u
committed
Jan 8, 2025
1 parent
4eccd09
commit 743682c
Showing
10 changed files
with
53 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2013, Sascha Peilicke <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -40,6 +37,11 @@ | |
get_metadata) | ||
|
||
from email import parser | ||
try: | ||
import libarchive | ||
except ModuleNotFoundError: | ||
libarchive = None | ||
import io | ||
|
||
|
||
def replace_string(output_string, replaces): | ||
|
@@ -51,6 +53,7 @@ def replace_string(output_string, replaces): | |
|
||
warnings.simplefilter('always', DeprecationWarning) | ||
|
||
|
||
SPDX_LICENSES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'spdx_license_map.json') | ||
with open(SPDX_LICENSES_FILE, 'r') as fp: | ||
SPDX_LICENSES = json.load(fp) | ||
|
@@ -69,7 +72,11 @@ def pypi_json(project, release=None): | |
|
||
def pypi_text_file(pkg_info_path): | ||
with open(pkg_info_path, 'r') as pkg_info_file: | ||
pkg_info_lines = parser.Parser().parse(pkg_info_file) | ||
return pypi_text_stream(pkg_info_file) | ||
|
||
|
||
def pypi_text_stream(pkg_info_stream): | ||
pkg_info_lines = parser.Parser().parse(pkg_info_stream) | ||
pkg_info_dict = {} | ||
for key, value in pkg_info_lines.items(): | ||
key = key.lower().replace('-', '_') | ||
|
@@ -86,14 +93,33 @@ def pypi_text_file(pkg_info_path): | |
|
||
def pypi_json_file(file_path): | ||
with open(file_path, 'r') as json_file: | ||
js = json.load(json_file) | ||
return pypi_json_stream(json_file) | ||
|
||
|
||
def pypi_json_stream(json_stream): | ||
js = json.load(json_stream) | ||
if 'info' not in js: | ||
js = {'info': js} | ||
if 'urls' not in js: | ||
js['urls'] = [] | ||
return js | ||
|
||
|
||
def pypi_archive_file(file_path): | ||
if libarchive is None: | ||
return None | ||
try: | ||
with libarchive.file_reader(file_path) as archive: | ||
for entry in archive: | ||
# Check if the entry's pathname matches the target filename | ||
if entry.pathname == 'PKG-INFO': | ||
return pypi_text_stream(io.StringIO(entry.read().decode())) | ||
else: | ||
return None | ||
except Exception: | ||
return None | ||
|
||
|
||
def _get_template_dirs(): | ||
"""existing directories where to search for jinja2 templates. The order | ||
is important. The first found template from the first found dir wins!""" | ||
|
@@ -427,7 +453,9 @@ def fetch_local_data(args): | |
try: | ||
data = pypi_json_file(localfile) | ||
except json.decoder.JSONDecodeError: | ||
data = pypi_text_file(localfile) | ||
data = pypi_archive_file(localfile) | ||
if data is None: | ||
data = pypi_text_file(localfile) | ||
args.fetched_data = data | ||
args.version = args.fetched_data['info']['version'] | ||
return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters