forked from lbt/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddrepos.py
59 lines (52 loc) · 2.15 KB
/
addrepos.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
#!/usr/bin/python
try:
from xml.etree import cElementTree as ET
except ImportError:
import cElementTree as ET
def do_addrepos(self, subcmd, opts, myproject, targetproject):
"""${cmd_name}: Configures a project with repositories that build against
all the repositories in another project, with matching architectures
This command creates a set of repositories in a project each with a single
path that builds only against one repository of another project.
${cmd_usage}
${cmd_option_list}
"""
path = quote_plus(myproject),
kind = 'prj'
data = meta_exists(metatype=kind,
path_args=path,
template_args=None,
create_new=False)
if data:
root = ET.fromstring(''.join(data))
repos = {}
for repo in get_repos_of_project(conf.config['apiurl'], targetproject):
if repo.name not in repos:
repos[repo.name] = []
repos[repo.name].append(repo.arch)
if not repos:
print "osc: no repositories found in %s" % targetproject
return False
comment_element = ET.Comment(text="Repositories to build against project %s" % targetproject )
root.append(comment_element)
for reponame, archs in repos.iteritems():
if not archs:
print "no archs enabled in %s, skipping" % reponame
continue
new_reponame = "%s_%s_%s" % (targetproject.replace(":","_"),
reponame,
"_".join(archs))
repo_element = ET.Element('repository', name=new_reponame)
repo_element.append(ET.Element('path', repository=reponame, project=targetproject))
for arch in archs:
arch_element = ET.Element('arch')
arch_element.text = arch
repo_element.append(arch_element)
root.append(repo_element)
else:
print "osc: an error occured"
xmlindent(root)
edit_meta(metatype=kind,
path_args=path,
edit=True,
data=ET.tostring(root))