-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmemsource_job.py
141 lines (121 loc) · 3.38 KB
/
memsource_job.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: memsource_job
short_description: Manage a Memsource job
version_added: 0.0.1
description:
- Manage a Memsource job
author: 'Yanis Guenane (@Spredzy)'
options:
uid:
description:
- UID of the job
type: str
project_uid:
description:
- UID of the project the job's belong to
type: str
source_lang:
description:
- Source language of the job
type: str
langs:
description:
- Target languages for the job
type: list
preTranslate:
description:
- Adds a flag to pre-populate data with cached strings
extends_documentation_fragment:
- ansible.memsource.memsource
requirements: [memsource]
"""
EXAMPLES = """
# Project creation
#
- name: Create job
ansible.memsource.memsource_job:
project_uid: project_uid
langs:
- ja_jp
- zh_cn
filename: /path/to/file
- name: Retrieve job information
ansible.memsource.memsource_job:
uid: uid
project_uid: project_uid
- name: Delete job
ansible.memsource.memsource_job:
uid: uid
project_uid: project_uid
state: absent
"""
RETURN = """
job:
returned: on success
description: >
Job's up to date information
type: dict
"""
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.memsource.plugins.module_utils.memsource import (
get_action,
get_default_argspec,
get_memsource_client,
)
def main():
argument_spec = get_default_argspec()
argument_spec.update(
dict(
uid=dict(type="str"),
project_uid=dict(type="str"),
langs=dict(type="list"),
filename=dict(type="path"),
use_project_file_import_settings=dict(type="bool"),
purge_on_delete=dict(type="bool"),
split_filename_on_dir=dict(type="bool"),
preTranslate=dict(type="bool"),
state=dict(type="str", default="present", choices=["absent", "present"]),
),
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)
_memsource = get_memsource_client(module.params)
_action = get_action(module.params)
_result = {}
job = {}
if _action == "create":
kwargs = {
"useProjectFileImportSettings": module.params.get(
"use_project_file_import_settings", True
)
}
job = _memsource.create_job(
module.params.get("project_uid"),
module.params.get("langs"),
module.params.get("filename"),
module.params.get("split_filename_on_dir", False),
module.params.get("preTranslate", True),
**kwargs
)
_result.update({"changed": True})
elif _action == "read":
job = _memsource.get_job_by_id(
module.params["uid"], module.params["project_uid"]
)
elif _action == "update":
pass
else:
res = _memsource.delete_job(
module.params["uid"],
module.params["project_uid"],
purge=module.params.get("purge_on_delete", False),
do_not_fail_on_404=True,
)
if res.status_code == 204:
_result.update({"changed": True})
_result.update({"job": job})
module.exit_json(**_result)
if __name__ == "__main__":
main()