prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>setup.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python from distutils.core import setup<|fim▁hole|> from dangagearman import __version__ as version setup( name = 'danga-gearman', version = version, description = 'Client for the Danga (Perl) Gearman implementation', author = 'Samuel Stauffer', author_email = '[email protected]', url = 'http://github.com/saymedia/python-danga-gearman/tree/master', packages = ['dangagearman'], classifiers = [ 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Software Development :: Libraries :: Python Modules', ], )<|fim▁end|>
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain)<|fim▁hole|> raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user)<|fim▁end|>
for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): <|fim_middle|> class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): <|fim_middle|> def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return hkc.KeystoneClient(self.context)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): <|fim_middle|> def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return isinstance(ex, exceptions.NotFound)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): <|fim_middle|> def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return isinstance(ex, exceptions.RequestEntityTooLarge)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): <|fim_middle|> def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return isinstance(ex, exceptions.Conflict)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): <|fim_middle|> def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): <|fim_middle|> def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): <|fim_middle|> def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): <|fim_middle|> def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): <|fim_middle|> def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): <|fim_middle|> class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): <|fim_middle|> class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): <|fim_middle|> class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
client.client_plugin('keystone').get_role_id(role)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): <|fim_middle|> class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): <|fim_middle|> class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
client.client_plugin('keystone').get_domain_id(domain)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): <|fim_middle|> class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): <|fim_middle|> class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
client.client_plugin('keystone').get_project_id(project)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): <|fim_middle|> class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): <|fim_middle|> class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
client.client_plugin('keystone').get_group_id(group)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): <|fim_middle|> class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): <|fim_middle|> class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
client.client_plugin('keystone').get_service_id(service)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): <|fim_middle|> <|fim▁end|>
expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): <|fim_middle|> <|fim▁end|>
client.client_plugin('keystone').get_user_id(user)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: <|fim_middle|> raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return role_obj.id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: <|fim_middle|> raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return project_obj.id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: <|fim_middle|> raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return domain_obj.id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: <|fim_middle|> raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return group_obj.id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: <|fim_middle|> elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return service_list[0].id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: <|fim_middle|> else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
raise exception.KeystoneServiceNameConflict(service=service)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: <|fim_middle|> def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
raise exception.EntityNotFound(entity='KeystoneService', name=service)
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: <|fim_middle|> raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
return user_obj.id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def <|fim_middle|>(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
_create
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def <|fim_middle|>(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
is_not_found
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def <|fim_middle|>(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
is_over_limit
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def <|fim_middle|>(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
is_conflict
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def <|fim_middle|>(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
get_role_id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def <|fim_middle|>(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
get_project_id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def <|fim_middle|>(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
get_domain_id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def <|fim_middle|>(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
get_group_id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def <|fim_middle|>(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
get_service_id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def <|fim_middle|>(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
get_user_id
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def <|fim_middle|>(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
validate_with_client
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def <|fim_middle|>(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
validate_with_client
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def <|fim_middle|>(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
validate_with_client
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def <|fim_middle|>(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
validate_with_client
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def <|fim_middle|>(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
validate_with_client
<|file_name|>keystone.py<|end_file_name|><|fim▁begin|># # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from keystoneclient import exceptions from heat.common import exception from heat.common import heat_keystoneclient as hkc from heat.engine.clients import client_plugin from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions service_types = [IDENTITY] = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) def is_not_found(self, ex): return isinstance(ex, exceptions.NotFound) def is_over_limit(self, ex): return isinstance(ex, exceptions.RequestEntityTooLarge) def is_conflict(self, ex): return isinstance(ex, exceptions.Conflict) def get_role_id(self, role): try: role_obj = self.client().client.roles.get(role) return role_obj.id except exceptions.NotFound: role_list = self.client().client.roles.list(name=role) for role_obj in role_list: if role_obj.name == role: return role_obj.id raise exception.EntityNotFound(entity='KeystoneRole', name=role) def get_project_id(self, project): try: project_obj = self.client().client.projects.get(project) return project_obj.id except exceptions.NotFound: project_list = self.client().client.projects.list(name=project) for project_obj in project_list: if project_obj.name == project: return project_obj.id raise exception.EntityNotFound(entity='KeystoneProject', name=project) def get_domain_id(self, domain): try: domain_obj = self.client().client.domains.get(domain) return domain_obj.id except exceptions.NotFound: domain_list = self.client().client.domains.list(name=domain) for domain_obj in domain_list: if domain_obj.name == domain: return domain_obj.id raise exception.EntityNotFound(entity='KeystoneDomain', name=domain) def get_group_id(self, group): try: group_obj = self.client().client.groups.get(group) return group_obj.id except exceptions.NotFound: group_list = self.client().client.groups.list(name=group) for group_obj in group_list: if group_obj.name == group: return group_obj.id raise exception.EntityNotFound(entity='KeystoneGroup', name=group) def get_service_id(self, service): try: service_obj = self.client().client.services.get(service) return service_obj.id except exceptions.NotFound: service_list = self.client().client.services.list(name=service) if len(service_list) == 1: return service_list[0].id elif len(service_list) > 1: raise exception.KeystoneServiceNameConflict(service=service) else: raise exception.EntityNotFound(entity='KeystoneService', name=service) def get_user_id(self, user): try: user_obj = self.client().client.users.get(user) return user_obj.id except exceptions.NotFound: user_list = self.client().client.users.list(name=user) for user_obj in user_list: if user_obj.name == user: return user_obj.id raise exception.EntityNotFound(entity='KeystoneUser', name=user) class KeystoneRoleConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, role): client.client_plugin('keystone').get_role_id(role) class KeystoneDomainConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, domain): client.client_plugin('keystone').get_domain_id(domain) class KeystoneProjectConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, project): client.client_plugin('keystone').get_project_id(project) class KeystoneGroupConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, group): client.client_plugin('keystone').get_group_id(group) class KeystoneServiceConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound, exception.KeystoneServiceNameConflict,) def validate_with_client(self, client, service): client.client_plugin('keystone').get_service_id(service) class KeystoneUserConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.EntityNotFound,) def <|fim_middle|>(self, client, user): client.client_plugin('keystone').get_user_id(user) <|fim▁end|>
validate_with_client
<|file_name|>switch.py<|end_file_name|><|fim▁begin|>"""Support for Zigbee switches.""" import voluptuous as vol from homeassistant.components.switch import SwitchDevice from homeassistant.components.zigbee import ( ZigBeeDigitalOut, ZigBeeDigitalOutConfig, PLATFORM_SCHEMA) DEPENDENCIES = ['zigbee'] CONF_ON_STATE = 'on_state' DEFAULT_ON_STATE = 'high' DEPENDENCIES = ['zigbee'] STATES = ['high', 'low'] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_ON_STATE): vol.In(STATES),<|fim▁hole|> def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Zigbee switch platform.""" add_entities([ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config))]) class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice): """Representation of a Zigbee Digital Out device.""" pass<|fim▁end|>
})
<|file_name|>switch.py<|end_file_name|><|fim▁begin|>"""Support for Zigbee switches.""" import voluptuous as vol from homeassistant.components.switch import SwitchDevice from homeassistant.components.zigbee import ( ZigBeeDigitalOut, ZigBeeDigitalOutConfig, PLATFORM_SCHEMA) DEPENDENCIES = ['zigbee'] CONF_ON_STATE = 'on_state' DEFAULT_ON_STATE = 'high' DEPENDENCIES = ['zigbee'] STATES = ['high', 'low'] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_ON_STATE): vol.In(STATES), }) def setup_platform(hass, config, add_entities, discovery_info=None): <|fim_middle|> class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice): """Representation of a Zigbee Digital Out device.""" pass <|fim▁end|>
"""Set up the Zigbee switch platform.""" add_entities([ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config))])
<|file_name|>switch.py<|end_file_name|><|fim▁begin|>"""Support for Zigbee switches.""" import voluptuous as vol from homeassistant.components.switch import SwitchDevice from homeassistant.components.zigbee import ( ZigBeeDigitalOut, ZigBeeDigitalOutConfig, PLATFORM_SCHEMA) DEPENDENCIES = ['zigbee'] CONF_ON_STATE = 'on_state' DEFAULT_ON_STATE = 'high' DEPENDENCIES = ['zigbee'] STATES = ['high', 'low'] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_ON_STATE): vol.In(STATES), }) def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Zigbee switch platform.""" add_entities([ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config))]) class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice): <|fim_middle|> <|fim▁end|>
"""Representation of a Zigbee Digital Out device.""" pass
<|file_name|>switch.py<|end_file_name|><|fim▁begin|>"""Support for Zigbee switches.""" import voluptuous as vol from homeassistant.components.switch import SwitchDevice from homeassistant.components.zigbee import ( ZigBeeDigitalOut, ZigBeeDigitalOutConfig, PLATFORM_SCHEMA) DEPENDENCIES = ['zigbee'] CONF_ON_STATE = 'on_state' DEFAULT_ON_STATE = 'high' DEPENDENCIES = ['zigbee'] STATES = ['high', 'low'] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_ON_STATE): vol.In(STATES), }) def <|fim_middle|>(hass, config, add_entities, discovery_info=None): """Set up the Zigbee switch platform.""" add_entities([ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config))]) class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice): """Representation of a Zigbee Digital Out device.""" pass <|fim▁end|>
setup_platform
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: <|fim▁hole|> ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp')<|fim▁end|>
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): <|fim_middle|> # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
""" Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir)
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: <|fim_middle|> # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists <|fim_middle|> # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
axc=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
ayc=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
arad=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
rxc=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
ryc=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
filterwidth=int(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
filterfreq=int(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
itmax=int(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
conv=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: <|fim_middle|> # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
fitwidth=float(array[0])
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: <|fim_middle|> # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
logfile = baselog
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': <|fim_middle|> # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
saltsafeio.fileexists(image) infile = image
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': <|fim_middle|> # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
raise SaltIOError(basein + ' list input instead of a file' )
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: <|fim_middle|> else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
dir = pathin
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def saltfpringfilter(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: <|fim_middle|> infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
dir = './'
<|file_name|>saltfpringfilter.py<|end_file_name|><|fim▁begin|>################################# LICENSE ################################## # Copyright (c) 2009, South African Astronomical Observatory (SAAO) # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # # # # * Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer # # in the documentation and/or other materials provided with the # # distribution. # # * Neither the name of the South African Astronomical Observatory # # (SAAO) nor the names of its contributors may be used to endorse # # or promote products derived from this software without specific # # prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE SAAO ''AS IS'' AND ANY EXPRESS OR # # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # # DISCLAIMED. IN NO EVENT SHALL THE SAAO BE LIABLE FOR ANY # # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ """ RINGFILTER determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. It uses T. Williams code. The code assumes all the files are in the same directory. Also assumes that if there is a config file, it is also in the same directory as the data. Note that this config file is in the original FORTRAN code format so that the user does not have to write another file. Updates: 20100706 * First wrote the code """ # Ensure python 2.5 compatibility from __future__ import with_statement import os import sys import numpy as np #import pyfits from pyraf import iraf from pyraf.iraf import pysalt import saltsafekey import saltsafeio import fpsafeio from saltsafelog import logging from salterror import SaltIOError # This reads the FORTRAN config file if it exists from fortranfp import ringfilter_wrapper from fortranfp.ringfilter_wrapper import getpfp debug=True def <|fim_middle|>(axc,ayc,arad,rxc,ryc,filterfreq,filterwidth,itmax,conv, fitwidth,image,logfile,useconfig,configfile,verbose): """ Determines the center coordinates of a ring, bins the ring radially and computes its power spectrum, and allows the user to select a smoothing filter for the ring. """ # default parameter values are set up in the pyraf .par file. The values used are then changed if a FORTRAN config file exists and the user elects to override the pyraf .par file. # Is the input FORTRAN config file specified? # If it is blank, then it will be ignored. if useconfig: configfile = configfile.strip() if len(configfile) > 0: #check exists saltsafeio.fileexists(configfile) # read updated parameters from the file array=getpfp(configfile,"axc") s=len(array) flag = array[s-1] if flag == 1: axc=float(array[0]) array=getpfp(configfile,"ayc") s=len(array) flag = array[s-1] if flag == 1: ayc=float(array[0]) array=getpfp(configfile,"arad") s=len(array) flag = array[s-1] if flag == 1: arad=float(array[0]) array=getpfp(configfile,"rxc") s=len(array) flag = array[s-1] if flag == 1: rxc=float(array[0]) array=getpfp(configfile,"ryc") s=len(array) flag = array[s-1] if flag == 1: ryc=float(array[0]) array=getpfp(configfile,"calring_filter_width") s=len(array) flag = array[s-1] if flag == 1: filterwidth=int(array[0]) array=getpfp(configfile,"calring_filter_freq") s=len(array) flag = array[s-1] if flag == 1: filterfreq=int(array[0]) array=getpfp(configfile,"calring_itmax") s=len(array) flag = array[s-1] if flag == 1: itmax=int(array[0]) array=getpfp(configfile,"calring_conv") s=len(array) flag = array[s-1] if flag == 1: conv=float(array[0]) array=getpfp(configfile,"calring_fitwidth") s=len(array) flag = array[s-1] if flag == 1: fitwidth=float(array[0]) # getting paths for filenames pathin = os.path.dirname(image) basein = os.path.basename(image) pathlog = os.path.dirname(logfile) baselog = os.path.basename(logfile) # forcing logfiles to be created in the same directory as the input data # (we change to this directory once starting the fortran code) if len(pathin) > 0: logfile = baselog # start log now that all parameter are set up with logging(logfile, debug) as log: # Some basic checks, many tests are done in the FORTRAN code itself # is the input file specified? saltsafeio.filedefined('Input',image) # if the input file is a file, does it exist? if basein[0] != '@': saltsafeio.fileexists(image) infile = image # if the input file is a list, throw an error if basein[0] == '@': raise SaltIOError(basein + ' list input instead of a file' ) # optionally update the FORTRAN config file with new values - not implemented currently # If all looks OK, run the FORTRAN code if len(pathin) > 0: dir = pathin else: dir = './' infile = basein print dir, infile, 'input directory and input file' # Get current working directory as the Fortran code changes dir startdir = os.getcwd() ringfilter_wrapper.ringfilter(dir,axc, ayc,arad, rxc,ryc,filterfreq,filterwidth,itmax,conv,fitwidth,infile) # go back to starting directory os.chdir(startdir) # ----------------------------------------------------------- # main code parfile = iraf.osfn("saltfp$saltfpringfilter.par") t = iraf.IrafTaskFactory(taskname="saltfpringfilter",value=parfile,function=saltfpringfilter,pkgname='saltfp') <|fim▁end|>
saltfpringfilter
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator <|fim▁hole|>- monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath<|fim▁end|>
- caching
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): <|fim_middle|> def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): <|fim_middle|> return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
global call_count call_count += 1 return func(*args, **kw)
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): <|fim_middle|> hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
print 'Invoked hello'
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): <|fim_middle|> """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
""" decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): <|fim_middle|> return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): <|fim_middle|> <|fim▁end|>
""" yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): <|fim_middle|> if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
found = arg break
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: <|fim_middle|> data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
directory = os.path.dirname(arg) if directory: os.chdir(directory)
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: <|fim_middle|> data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
os.chdir(directory)
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: <|fim_middle|> else: yield filepath <|fim▁end|>
for child in find_files(filepath, recurse): yield child
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: <|fim_middle|> <|fim▁end|>
yield filepath
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def <|fim_middle|>(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
count
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def <|fim_middle|>(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
wrapper
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def <|fim_middle|>(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
hello
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def <|fim_middle|>(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
cwd_decorator
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def <|fim_middle|>(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def find_files(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
wrapper
<|file_name|>decorator.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python """ Since functions are function instances you can wrap them Allow you to - modify arguments - modify function - modify results """ call_count = 0 def count(func): def wrapper(*args, **kw): global call_count call_count += 1 return func(*args, **kw) return wrapper def hello(): print 'Invoked hello' hello = count(hello) ## Now decorating hello to increment call count hello() print call_count hello() print call_count """ ## Syntactic Sugar >>> @count ... def hello(): ... print "Invoked hello" equals hello = count(hello) ## Syntactic Sugar 2 Dont add parens to the decorator >>> @count() ... def hello(): ... print "Invoked hello" ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: count() takes exactly 1 argument (0 given) >>> ##Decorator Template def decorator(func_to_decorate): def wrapper(*args, **kwargs): # do something before invocation result = func_to_decorate(*args,**kwargs) # do something after invocation return result #update wrapper.__doc__ and .func_name # or functools.wraps return wrapper ##Decorators can also be classes, to have a class that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result ##Decorators can also be classes 2, to have a instance that Decorates class decorator(object): def __init__(self, function): self.function = function def __call__(self, *args, **kw): def wrapper(*args, **kw): # do something before invocation result = self.function(*args, **kw) # do something after return result return wrapper ## The aboves lets you have an instance of a decorator that stores state (rather than using global state) ## Parameterized decorators (need 2 closures) def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result return wrapper return decorator >>> @limit(5) ## Decorating the simple function echo with limit 5 as parameter ... def echo(foo): ... return foo ... >>> echo ('123456') '12345' >>> Or you can use following as well , to limit the echo function with 3 as parameter >>> echo = limit(3)(echo) >>> echo ('123456') '123' >>> ## Decorator Tidying function attributes get mangled >>> def echo2(input): ... ###return input### I used ### instead of 3 coz that was causing some error ... return input ... >>> echo2.__doc__ 'return input' >>> echo2.func_name 'echo2' >>> >>> echo3 = limit(3)(echo2) >>> echo3.__doc__ >>> echo3.func_name 'wrapper' >>> #Now to fix above define your limit decorator as below def limit(length): def decorator(function): def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result wrapper.__doc__ = function.__doc__ wrapper.func_name = function.func_name return wrapper return decorator >>> echo4 = limit(3)(echo2) >>> echo4.__doc__ 'return input' >>> echo4.func_name 'echo2' >>> #Decorator tidying (3) , using functools , more simple import functools def limit(length): def decorator(function): @functools.wraps(function) def wrapper(*args, **kw): result = function(*args, **kw) result = result[:length] return result #wrapper.__doc__ = function.__doc__ #wrapper.func_name = function.func_name return wrapper return decorator Uses for decorator - caching - monkey patching stdio - memoize - jsonify - logging time in function call - change cwd """ def cwd_decorator(func): """ decorator to change cwd to directory containing rst for this function """ def wrapper(*args, **kw): cur_dir = os.getcwd() found = False for arg in sys.argv: if arg.endswith(".rst"): found = arg break if found: directory = os.path.dirname(arg) if directory: os.chdir(directory) data = func(*args, **kw) os.chdir(cur_dir) return data return wrapper """ ### Properties Call get/set methods via an instance attributes class C(object): def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") from property.__doc__ """ import os def <|fim_middle|>(base_dir, recurse=True): """ yeild files found in base_dir """ for name in os.listdir(base_dir): filepath = os.path.join(base_dir, name) if os.path.isdir(filepath) and recurse: for child in find_files(filepath, recurse): yield child else: yield filepath <|fim▁end|>
find_files
<|file_name|>const.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- __author__ = 'LIWEI240' """<|fim▁hole|>Constants definition """ class Const(object): class RetCode(object): OK = 0 InvalidParam = -1 NotExist = -2 ParseError = -3<|fim▁end|>
<|file_name|>const.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- __author__ = 'LIWEI240' """ Constants definition """ class Const(object): <|fim_middle|> <|fim▁end|>
class RetCode(object): OK = 0 InvalidParam = -1 NotExist = -2 ParseError = -3
<|file_name|>const.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- __author__ = 'LIWEI240' """ Constants definition """ class Const(object): class RetCode(object): <|fim_middle|> <|fim▁end|>
OK = 0 InvalidParam = -1 NotExist = -2 ParseError = -3
<|file_name|>utils.py<|end_file_name|><|fim▁begin|># (c) Copyright 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # @author: Swaminathan Vasudevan, Hewlett-Packard. # """VPN Utilities and helper functions.""" from neutronclient.common import exceptions from neutronclient.i18n import _ dpd_supported_actions = ['hold', 'clear', 'restart', 'restart-by-peer', 'disabled'] dpd_supported_keys = ['action', 'interval', 'timeout'] lifetime_keys = ['units', 'value'] lifetime_units = ['seconds'] def validate_dpd_dict(dpd_dict): for key, value in dpd_dict.items(): if key not in dpd_supported_keys: message = _( "DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': dpd_supported_keys} raise exceptions.CommandError(message) if key == 'action' and value not in dpd_supported_actions: message = _( "DPD Dictionary ValueError: " "Reason-Invalid DPD action : " "'%(key_value)s' not in %(supported_action)s ") % { 'key_value': value, 'supported_action': dpd_supported_actions} raise exceptions.CommandError(message) if key in ('interval', 'timeout'): try: if int(value) <= 0:<|fim▁hole|> "DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s ") % { 'key': key, 'value': value} raise exceptions.CommandError(message) else: dpd_dict[key] = int(value) return def validate_lifetime_dict(lifetime_dict): for key, value in lifetime_dict.items(): if key not in lifetime_keys: message = _( "Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': lifetime_keys} raise exceptions.CommandError(message) if key == 'units' and value not in lifetime_units: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid units : " "'%(key_value)s' not in %(supported_units)s ") % { 'key_value': key, 'supported_units': lifetime_units} raise exceptions.CommandError(message) if key == 'value': try: if int(value) < 60: raise ValueError() except ValueError: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid value should be at least 60:" "'%(key_value)s' = %(value)s ") % { 'key_value': key, 'value': value} raise exceptions.CommandError(message) else: lifetime_dict['value'] = int(value) return def lifetime_help(policy): lifetime = _("%s lifetime attributes. " "'units'-seconds, default:seconds. " "'value'-non negative integer, default:3600.") % policy return lifetime def dpd_help(policy): dpd = _(" %s Dead Peer Detection attributes." " 'action'-hold,clear,disabled,restart,restart-by-peer." " 'interval' and 'timeout' are non negative integers. " " 'interval' should be less than 'timeout' value. " " 'action', default:hold 'interval', default:30, " " 'timeout', default:120.") % policy.capitalize() return dpd<|fim▁end|>
raise ValueError() except ValueError: message = _(
<|file_name|>utils.py<|end_file_name|><|fim▁begin|># (c) Copyright 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # @author: Swaminathan Vasudevan, Hewlett-Packard. # """VPN Utilities and helper functions.""" from neutronclient.common import exceptions from neutronclient.i18n import _ dpd_supported_actions = ['hold', 'clear', 'restart', 'restart-by-peer', 'disabled'] dpd_supported_keys = ['action', 'interval', 'timeout'] lifetime_keys = ['units', 'value'] lifetime_units = ['seconds'] def validate_dpd_dict(dpd_dict): <|fim_middle|> def validate_lifetime_dict(lifetime_dict): for key, value in lifetime_dict.items(): if key not in lifetime_keys: message = _( "Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': lifetime_keys} raise exceptions.CommandError(message) if key == 'units' and value not in lifetime_units: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid units : " "'%(key_value)s' not in %(supported_units)s ") % { 'key_value': key, 'supported_units': lifetime_units} raise exceptions.CommandError(message) if key == 'value': try: if int(value) < 60: raise ValueError() except ValueError: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid value should be at least 60:" "'%(key_value)s' = %(value)s ") % { 'key_value': key, 'value': value} raise exceptions.CommandError(message) else: lifetime_dict['value'] = int(value) return def lifetime_help(policy): lifetime = _("%s lifetime attributes. " "'units'-seconds, default:seconds. " "'value'-non negative integer, default:3600.") % policy return lifetime def dpd_help(policy): dpd = _(" %s Dead Peer Detection attributes." " 'action'-hold,clear,disabled,restart,restart-by-peer." " 'interval' and 'timeout' are non negative integers. " " 'interval' should be less than 'timeout' value. " " 'action', default:hold 'interval', default:30, " " 'timeout', default:120.") % policy.capitalize() return dpd <|fim▁end|>
for key, value in dpd_dict.items(): if key not in dpd_supported_keys: message = _( "DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': dpd_supported_keys} raise exceptions.CommandError(message) if key == 'action' and value not in dpd_supported_actions: message = _( "DPD Dictionary ValueError: " "Reason-Invalid DPD action : " "'%(key_value)s' not in %(supported_action)s ") % { 'key_value': value, 'supported_action': dpd_supported_actions} raise exceptions.CommandError(message) if key in ('interval', 'timeout'): try: if int(value) <= 0: raise ValueError() except ValueError: message = _( "DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s ") % { 'key': key, 'value': value} raise exceptions.CommandError(message) else: dpd_dict[key] = int(value) return
<|file_name|>utils.py<|end_file_name|><|fim▁begin|># (c) Copyright 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # @author: Swaminathan Vasudevan, Hewlett-Packard. # """VPN Utilities and helper functions.""" from neutronclient.common import exceptions from neutronclient.i18n import _ dpd_supported_actions = ['hold', 'clear', 'restart', 'restart-by-peer', 'disabled'] dpd_supported_keys = ['action', 'interval', 'timeout'] lifetime_keys = ['units', 'value'] lifetime_units = ['seconds'] def validate_dpd_dict(dpd_dict): for key, value in dpd_dict.items(): if key not in dpd_supported_keys: message = _( "DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': dpd_supported_keys} raise exceptions.CommandError(message) if key == 'action' and value not in dpd_supported_actions: message = _( "DPD Dictionary ValueError: " "Reason-Invalid DPD action : " "'%(key_value)s' not in %(supported_action)s ") % { 'key_value': value, 'supported_action': dpd_supported_actions} raise exceptions.CommandError(message) if key in ('interval', 'timeout'): try: if int(value) <= 0: raise ValueError() except ValueError: message = _( "DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s ") % { 'key': key, 'value': value} raise exceptions.CommandError(message) else: dpd_dict[key] = int(value) return def validate_lifetime_dict(lifetime_dict): <|fim_middle|> def lifetime_help(policy): lifetime = _("%s lifetime attributes. " "'units'-seconds, default:seconds. " "'value'-non negative integer, default:3600.") % policy return lifetime def dpd_help(policy): dpd = _(" %s Dead Peer Detection attributes." " 'action'-hold,clear,disabled,restart,restart-by-peer." " 'interval' and 'timeout' are non negative integers. " " 'interval' should be less than 'timeout' value. " " 'action', default:hold 'interval', default:30, " " 'timeout', default:120.") % policy.capitalize() return dpd <|fim▁end|>
for key, value in lifetime_dict.items(): if key not in lifetime_keys: message = _( "Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': lifetime_keys} raise exceptions.CommandError(message) if key == 'units' and value not in lifetime_units: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid units : " "'%(key_value)s' not in %(supported_units)s ") % { 'key_value': key, 'supported_units': lifetime_units} raise exceptions.CommandError(message) if key == 'value': try: if int(value) < 60: raise ValueError() except ValueError: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid value should be at least 60:" "'%(key_value)s' = %(value)s ") % { 'key_value': key, 'value': value} raise exceptions.CommandError(message) else: lifetime_dict['value'] = int(value) return
<|file_name|>utils.py<|end_file_name|><|fim▁begin|># (c) Copyright 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # @author: Swaminathan Vasudevan, Hewlett-Packard. # """VPN Utilities and helper functions.""" from neutronclient.common import exceptions from neutronclient.i18n import _ dpd_supported_actions = ['hold', 'clear', 'restart', 'restart-by-peer', 'disabled'] dpd_supported_keys = ['action', 'interval', 'timeout'] lifetime_keys = ['units', 'value'] lifetime_units = ['seconds'] def validate_dpd_dict(dpd_dict): for key, value in dpd_dict.items(): if key not in dpd_supported_keys: message = _( "DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': dpd_supported_keys} raise exceptions.CommandError(message) if key == 'action' and value not in dpd_supported_actions: message = _( "DPD Dictionary ValueError: " "Reason-Invalid DPD action : " "'%(key_value)s' not in %(supported_action)s ") % { 'key_value': value, 'supported_action': dpd_supported_actions} raise exceptions.CommandError(message) if key in ('interval', 'timeout'): try: if int(value) <= 0: raise ValueError() except ValueError: message = _( "DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s ") % { 'key': key, 'value': value} raise exceptions.CommandError(message) else: dpd_dict[key] = int(value) return def validate_lifetime_dict(lifetime_dict): for key, value in lifetime_dict.items(): if key not in lifetime_keys: message = _( "Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': lifetime_keys} raise exceptions.CommandError(message) if key == 'units' and value not in lifetime_units: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid units : " "'%(key_value)s' not in %(supported_units)s ") % { 'key_value': key, 'supported_units': lifetime_units} raise exceptions.CommandError(message) if key == 'value': try: if int(value) < 60: raise ValueError() except ValueError: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid value should be at least 60:" "'%(key_value)s' = %(value)s ") % { 'key_value': key, 'value': value} raise exceptions.CommandError(message) else: lifetime_dict['value'] = int(value) return def lifetime_help(policy): <|fim_middle|> def dpd_help(policy): dpd = _(" %s Dead Peer Detection attributes." " 'action'-hold,clear,disabled,restart,restart-by-peer." " 'interval' and 'timeout' are non negative integers. " " 'interval' should be less than 'timeout' value. " " 'action', default:hold 'interval', default:30, " " 'timeout', default:120.") % policy.capitalize() return dpd <|fim▁end|>
lifetime = _("%s lifetime attributes. " "'units'-seconds, default:seconds. " "'value'-non negative integer, default:3600.") % policy return lifetime
<|file_name|>utils.py<|end_file_name|><|fim▁begin|># (c) Copyright 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # @author: Swaminathan Vasudevan, Hewlett-Packard. # """VPN Utilities and helper functions.""" from neutronclient.common import exceptions from neutronclient.i18n import _ dpd_supported_actions = ['hold', 'clear', 'restart', 'restart-by-peer', 'disabled'] dpd_supported_keys = ['action', 'interval', 'timeout'] lifetime_keys = ['units', 'value'] lifetime_units = ['seconds'] def validate_dpd_dict(dpd_dict): for key, value in dpd_dict.items(): if key not in dpd_supported_keys: message = _( "DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': dpd_supported_keys} raise exceptions.CommandError(message) if key == 'action' and value not in dpd_supported_actions: message = _( "DPD Dictionary ValueError: " "Reason-Invalid DPD action : " "'%(key_value)s' not in %(supported_action)s ") % { 'key_value': value, 'supported_action': dpd_supported_actions} raise exceptions.CommandError(message) if key in ('interval', 'timeout'): try: if int(value) <= 0: raise ValueError() except ValueError: message = _( "DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s ") % { 'key': key, 'value': value} raise exceptions.CommandError(message) else: dpd_dict[key] = int(value) return def validate_lifetime_dict(lifetime_dict): for key, value in lifetime_dict.items(): if key not in lifetime_keys: message = _( "Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': lifetime_keys} raise exceptions.CommandError(message) if key == 'units' and value not in lifetime_units: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid units : " "'%(key_value)s' not in %(supported_units)s ") % { 'key_value': key, 'supported_units': lifetime_units} raise exceptions.CommandError(message) if key == 'value': try: if int(value) < 60: raise ValueError() except ValueError: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid value should be at least 60:" "'%(key_value)s' = %(value)s ") % { 'key_value': key, 'value': value} raise exceptions.CommandError(message) else: lifetime_dict['value'] = int(value) return def lifetime_help(policy): lifetime = _("%s lifetime attributes. " "'units'-seconds, default:seconds. " "'value'-non negative integer, default:3600.") % policy return lifetime def dpd_help(policy): <|fim_middle|> <|fim▁end|>
dpd = _(" %s Dead Peer Detection attributes." " 'action'-hold,clear,disabled,restart,restart-by-peer." " 'interval' and 'timeout' are non negative integers. " " 'interval' should be less than 'timeout' value. " " 'action', default:hold 'interval', default:30, " " 'timeout', default:120.") % policy.capitalize() return dpd
<|file_name|>utils.py<|end_file_name|><|fim▁begin|># (c) Copyright 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # # @author: Swaminathan Vasudevan, Hewlett-Packard. # """VPN Utilities and helper functions.""" from neutronclient.common import exceptions from neutronclient.i18n import _ dpd_supported_actions = ['hold', 'clear', 'restart', 'restart-by-peer', 'disabled'] dpd_supported_keys = ['action', 'interval', 'timeout'] lifetime_keys = ['units', 'value'] lifetime_units = ['seconds'] def validate_dpd_dict(dpd_dict): for key, value in dpd_dict.items(): if key not in dpd_supported_keys: <|fim_middle|> if key == 'action' and value not in dpd_supported_actions: message = _( "DPD Dictionary ValueError: " "Reason-Invalid DPD action : " "'%(key_value)s' not in %(supported_action)s ") % { 'key_value': value, 'supported_action': dpd_supported_actions} raise exceptions.CommandError(message) if key in ('interval', 'timeout'): try: if int(value) <= 0: raise ValueError() except ValueError: message = _( "DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s ") % { 'key': key, 'value': value} raise exceptions.CommandError(message) else: dpd_dict[key] = int(value) return def validate_lifetime_dict(lifetime_dict): for key, value in lifetime_dict.items(): if key not in lifetime_keys: message = _( "Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': lifetime_keys} raise exceptions.CommandError(message) if key == 'units' and value not in lifetime_units: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid units : " "'%(key_value)s' not in %(supported_units)s ") % { 'key_value': key, 'supported_units': lifetime_units} raise exceptions.CommandError(message) if key == 'value': try: if int(value) < 60: raise ValueError() except ValueError: message = _( "Lifetime Dictionary ValueError: " "Reason-Invalid value should be at least 60:" "'%(key_value)s' = %(value)s ") % { 'key_value': key, 'value': value} raise exceptions.CommandError(message) else: lifetime_dict['value'] = int(value) return def lifetime_help(policy): lifetime = _("%s lifetime attributes. " "'units'-seconds, default:seconds. " "'value'-non negative integer, default:3600.") % policy return lifetime def dpd_help(policy): dpd = _(" %s Dead Peer Detection attributes." " 'action'-hold,clear,disabled,restart,restart-by-peer." " 'interval' and 'timeout' are non negative integers. " " 'interval' should be less than 'timeout' value. " " 'action', default:hold 'interval', default:30, " " 'timeout', default:120.") % policy.capitalize() return dpd <|fim▁end|>
message = _( "DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s ") % { 'key': key, 'supported_key': dpd_supported_keys} raise exceptions.CommandError(message)