Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- n/a
### Fixed
- Fixed certain exceptions from requests library not being propagated properly while
getting maintenance report.

## [2.3.0] - 2019-09-25

Expand Down
25 changes: 10 additions & 15 deletions examples/set-maintenance
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def set_maintenance(client, regex):

report = client.get_maintenance_report().result()

crit = Criteria.with_field("id", Matcher.regex(regex))
# search repo
repos = client.search_repository(crit).result()
crit = Criteria.with_field("relative_url", Matcher.regex(regex))
# search repos by distributor's relative_url
distributors = client.search_distributor(crit).result()

repo_ids = [repo.id for repo in repos]
repo_ids = [dist.repo_id for dist in distributors]
report = report.add(repo_ids)
# get the repo ids and feed to report

Expand All @@ -26,13 +26,8 @@ def set_maintenance(client, regex):
report = client.get_maintenance_report().result()
log.info("maintenance mode set: %s", report.entries)

to_remove = []
for entry in report.entries:
if re.match(regex, entry.id):
to_remove.append(entry.id)

report = report.remove(to_remove)
tasks = client.set_maintainenance(report).result()
report = report.remove(repo_ids)
tasks = client.set_maintenance(report).result()

report = client.get_maintenance_report().result()
log.info("maintenance mode unset: %s", report.entries)
Expand Down Expand Up @@ -64,22 +59,22 @@ def main():
)
parser.add_argument("--debug", action="store_true")
parser.add_argument("--insecure", default=False, action="store_true")
parser.add_argument("--regex", action="store")
parser.add_argument("--repo-url-regex", action="store")

p = parser.parse_args()

if not p.url:
parser.error("--url is required")

if not p.regex:
parser.error("--regex is required")
if not p.repo_url_regex:
parser.error("--repo-url-regex is required")

if p.debug:
logging.getLogger("pubtools.pulplib").setLevel(logging.DEBUG)
log.setLevel(logging.DEBUG)

client = make_client(p)
return set_maintenance(client, p.regex)
return set_maintenance(client, p.repo_url_regex)


if __name__ == "__main__":
Expand Down
5 changes: 4 additions & 1 deletion pubtools/pulplib/_impl/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ def _delete_upload_request(self, upload_id):
def _do_get_maintenance(self):
def map_404_to_none(exception):
# Translates 404 errors to a None response (no maintenance report).
if hasattr(exception, "response") and exception.response.status_code == 404:
if (
getattr(exception, "response", None) is not None
and exception.response.status_code == 404
):
return None
# Any other types of errors are raised unchanged.
raise exception
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_requirements():

setup(
name="pubtools-pulplib",
version="2.3.0",
version="2.3.1",
packages=find_packages(exclude=["tests"]),
package_data={"pubtools.pulplib._impl.schema": ["*.yaml"]},
url="https://github.com/release-engineering/pubtools-pulplib",
Expand Down