Skip to content

Commit

Permalink
move project_exists to copr module utils
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Dec 20, 2023
1 parent 7cfa0e5 commit 728b8f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 16 additions & 0 deletions obal/data/module_utils/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ def full_name(user, project):
Returns a full Copr name: user/project
"""
return "{}/{}".format(user, project)

def project_exists(user, project, module, config_file=None):
"""
Return true if a project already exists for a user
"""
command = [
'list',
user
]

try:
project_list = copr_cli(command, config_file=config_file)
except CoprCliCommandError as error:
module.fail_json(msg='Copr project listing failed', command=' '.join(error.command), output=error.message)

return re.search("Name: {}\n".format(project), project_list) is not None
18 changes: 1 addition & 17 deletions obal/data/modules/copr_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,9 @@

import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name, project_exists # pylint:disable=import-error,no-name-in-module


def project_exists(user, project, module, config_file=None):
"""
Return true if a project already exists for a user
"""
command = [
'list',
user
]

try:
project_list = copr_cli(command, config_file=config_file)
except CoprCliCommandError as error:
module.fail_json(msg='Copr project listing failed', command=' '.join(error.command), output=error.message)

return re.search("Name: {}\n".format(project), project_list) is not None

def main():
"""
Create a Project in Copr
Expand Down

0 comments on commit 728b8f3

Please sign in to comment.