diff --git a/mpcdf_common.py b/mpcdf_common.py index 8d94d492ffe0de78eaa010bd6fb92e2a8b614782..f1dfc5e2dc99c716a0782277435dacbfa252e0fd 100644 --- a/mpcdf_common.py +++ b/mpcdf_common.py @@ -33,6 +33,10 @@ def project_meta(api_url, project): return ElementTree.fromstringlist(osc.core.show_project_meta(api_url, project)) +class UnsetAttributeException(Exception): + pass + + def get_attribute(api_url, project, package, attribute, with_project=False): attribute_meta = osc.core.show_attribute_meta(api_url, project, package, None, attribute, False, with_project) if attribute_meta is None: @@ -43,7 +47,7 @@ def get_attribute(api_url, project, package, attribute, with_project=False): if attribute is not None: return root else: - raise Exception("Attribute not set") + raise UnsetAttributeException("Attribute not set") def get_attribute_values(api_url, project, package, attribute, with_project=False): diff --git a/mpcdf_sync_projects.py b/mpcdf_sync_projects.py index 16adc5f93f980b6bdf7d192b59afb9d46908259a..29ecb1ab80b47c230e907af958b90ea1d43378da 100644 --- a/mpcdf_sync_projects.py +++ b/mpcdf_sync_projects.py @@ -76,7 +76,9 @@ def do_mpcdf_sync_projects(self, subcmd, opts, *args): for attribute in package_attributes: try: attr = mpcdf_common.get_attribute(api_url, from_project, orig_package, attribute) - except Exception: + except mpcdf_common.UnsetAttributeException: + if mpcdf_common.has_attribute(api_url, to_project, orig_package, attribute): + mpcdf_common.remove_attribute(api_url, to_project, orig_package, attribute) continue mpcdf_common.set_attribute(api_url, to_project, orig_package, attr)