-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsplit-library-packages
executable file
·191 lines (153 loc) · 5.58 KB
/
split-library-packages
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import pisi
import time
dont_bump = False
#available_packages = pisi.api.list_available()
def is_in_system_base(package_name):
"""Checks whether the given package is in system.base."""
packages = []
cdb = pisi.db.componentdb.ComponentDB()
for repo in pisi.db.repodb.RepoDB().list_repos():
try:
packages.extend(cdb.get_packages('system.base', repo))
except:
pass
return package_name in packages
def is_in_repositories(package_name):
"""Checks whether the given package is in the repositories."""
if package_name not in available_packages:
print "%s is not in the repositories, skipping rename operation" % package_name
def split_translations(package_name):
addition = """\
<Package>
<Name>%s-devel</Name>
<Summary xml:lang="tr">%s için geliştirme dosyaları</Summary>
</Package>
"""
new_translations = ""
with open("translations.xml", "r") as _file:
for line in _file:
if "</PISI>" in line:
# Add new translations
new_translations += "\n%s" % (addition % (package_name, package_name))
new_translations += line
open("translations.xml", "w").write(new_translations)
def split_devel_package(package_name):
release = """\
<History>
<Update release="%s">
<Date>%s</Date>
<Version>%s</Version>
<Comment>Split devel package.</Comment>
<Name>%s</Name>
<Email>%s</Email>
</Update>
"""
addition = """\
<Package>
<Name>%s-devel</Name>
"""
if is_in_system_base(package_name):
addition += """\
<PartOf>system.devel</PartOf>
"""
addition += """\
<Summary>Development files for %s</Summary>
<RuntimeDependencies>
<Dependency release="current">%s</Dependency>
</RuntimeDependencies>
<Files>
%s
<!-- FIXME: Remove this if not necessary -->
<Path fileType="man">/usr/share/man/man3</Path>
</Files>
</Package>
"""
pspec = pisi.specfile.SpecFile("pspec.xml")
next_release = int(pspec.history[0].release) + (0 if dont_bump else 1)
current_version = pspec.history[0].version
# Check whether the package is already split
for pkg in pspec.packages:
if pkg.name.endswith("-devel"):
print "The package seems already be split, exiting."
return
packager_name, packager_email = get_and_save_user_info()
files = []
new_pspec = ""
are_runtime_deps = False
with open("pspec.xml", "r") as _file:
for line in _file:
if "<Dependency" in line and not are_runtime_deps \
and not "-devel</Dependency>" in line:
# Change build dep into -devel one
line = line.replace("</Dependency", "-devel</Dependency")
# Check whether we've crossed the build dep list
if "<RuntimeDependencies>" in line:
are_runtime_deps = True
if 'fileType="header"' in line or \
'/pkgconfig' in line or \
'/share/aclocal' in line:
files.append(line.rstrip("\n"))
continue
if "<History>" in line:
# Add the new package here
new_pspec += addition % (package_name,
package_name,
package_name,
"\n".join(files))
if not dont_bump:
# Bump package
new_pspec += release % (next_release,
time.strftime("%Y-%m-%d"),
current_version,
packager_name,
packager_email)
continue
new_pspec += line
open("pspec.xml", "w").write(new_pspec)
def split(package_name):
split_translations(package_name)
split_devel_package(package_name)
def usage():
print """\
Usage: %s if in a source package's directory
%s DIR where DIR is a source package's directory.""" % (sys.argv[0], sys.argv[0])
return 1
def get_and_save_user_info():
name = "PACKAGER_NAME"
email = "PACKAGER_EMAIL"
conf_file = os.path.expanduser("~/.packagerinfo")
if os.path.exists(conf_file):
# Read from it
name, email = open(conf_file, "r").read().strip().split(",")
else:
print "Please enter your full name as seen in pspec files"
name = raw_input("> ")
print "Please enter your e-mail as seen in pspec files"
email = raw_input("> ")
print "Saving packager info into %s" % conf_file
open(conf_file, "w").write("%s,%s" % (name, email))
return name, email
def main():
if "--no-bump" in sys.argv:
global dont_bump
dont_bump = True
sys.argv.remove("--no-bump")
if len(sys.argv) < 2:
# Assuming that we are in a source package's directory
if not os.path.exists("pspec.xml"):
return usage()
else:
split(os.path.basename(os.getcwd()))
else:
package = sys.argv[1].rstrip("/")
if os.path.isdir(package) and not os.path.exists(os.path.join(package, "pspec.xml")):
return usage()
else:
os.chdir(package)
split(os.path.basename(package))
if __name__ == "__main__":
sys.exit(main())