|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2019 - Swiss Data Science Center (SDSC) |
| 4 | +# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and |
| 5 | +# Eidgenössische Technische Hochschule Zürich (ETHZ). |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +"""Check missing references.""" |
| 19 | + |
| 20 | +import click |
| 21 | + |
| 22 | +from .._echo import WARNING |
| 23 | + |
| 24 | + |
| 25 | +def check_missing_references(client): |
| 26 | + """Find missing references.""" |
| 27 | + from renku.models.refs import LinkReference |
| 28 | + |
| 29 | + missing = [ |
| 30 | + ref for ref in LinkReference.iter_items(client) |
| 31 | + if not ref.reference.exists() |
| 32 | + ] |
| 33 | + |
| 34 | + if not missing: |
| 35 | + return True |
| 36 | + |
| 37 | + click.secho( |
| 38 | + WARNING + 'There are missing references.' |
| 39 | + '\n (use "git rm <name>" to clean them)\n\n\t' + '\n\t '.join( |
| 40 | + click.style(str(ref.path), fg='yellow') + ' -> ' + |
| 41 | + click.style(str(ref.reference), fg='red') for ref in missing |
| 42 | + ) + '\n' |
| 43 | + ) |
| 44 | + return False |
0 commit comments