-
Notifications
You must be signed in to change notification settings - Fork 0
/
osc_service_add.py
executable file
·67 lines (51 loc) · 2.34 KB
/
osc_service_add.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
#!/usr/bin/env python3
from xml.etree import ElementTree
from pathlib import Path
import argparse
opt_tar_git = True
opt_webhook = True
parser = argparse.ArgumentParser(
prog = 'osc_service_add',
description = 'Create osc _service for tar_git and webhook',
epilog = '')
parser.add_argument('service_file')
parser.add_argument('-w', '--webhook', dest = 'webhook', action="store_true",
help = "Create Webhook service")
parser.add_argument('-P', '--project', dest = 'obs_project',
required = True,
help = "OBS Project to upload to")
parser.add_argument('-p', '--package', dest = 'obs_package',
required = True,
help = "OBS Package to create")
parser.add_argument('-r', '--repository', dest = 'repository',
required = True,
help = "repository url")
parser.add_argument('-b', '--branch', dest = 'branch',
default = 'master',
help = "Target branch (default: master)")
args = parser.parse_args()
service = Path(args.service_file)
services = ElementTree.Element("services")
xmlFile = ElementTree.ElementTree(element=services)
if args.webhook:
webhook = ElementTree.SubElement(services, "service", name="webhook")
webhook_params = dict()
webhook_params['repourl'] = ElementTree.SubElement(webhook, "param",
name = "repourl")
webhook_params['repourl'].text = args.repository
webhook_params['branch'] = ElementTree.SubElement(webhook, "param",
name = "branch")
webhook_params['branch'].text = args.branch
tar_git = ElementTree.SubElement(services, "service", name="tar_git")
tar_git_params = dict()
tar_git_params['url'] = ElementTree.SubElement(tar_git, "param",
name = "url")
tar_git_params['url'].text = args.repository
tar_git_params['branch'] = ElementTree.SubElement(tar_git, "param",
name = "branch")
tar_git_params['branch'].text = args.branch
tar_git_params['dumb'] = ElementTree.SubElement(tar_git, "param",
name = "dumb")
tar_git_params['dumb'].text = "N"
ElementTree.indent(xmlFile)
xmlFile.write(service)