Mercurial > treepkg
comparison recipes/kde_enterprise_4/kde_l10n.py @ 211:56aa89c588a1
Add more KDEPIM Enterprise 4 recipes: l10n, kdebase_runtime, kdebase_workspace
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Fri, 14 Nov 2008 19:46:56 +0000 |
parents | |
children | 93301afac8d4 |
comparison
equal
deleted
inserted
replaced
210:63f73bb9c459 | 211:56aa89c588a1 |
---|---|
1 # Copyright (C) 2007, 2008 by Intevation GmbH | |
2 # Authors: | |
3 # Bernhard Herzog <bh@intevation.de> | |
4 # | |
5 # This program is free software under the GPL (>=v2) | |
6 # Read the file COPYING coming with the software for details. | |
7 | |
8 import os | |
9 import logging | |
10 import shutil | |
11 import time | |
12 | |
13 import treepkg.packager | |
14 import treepkg.util | |
15 import treepkg.subversion as subversion | |
16 | |
17 | |
18 class SubversionSubset(object): | |
19 | |
20 """Manage a subversion working copy that contains a subset of a repository | |
21 | |
22 The SVN repository for the enterprise 4 l10n sources contains all | |
23 languages. Only a small subset of those languages are actually | |
24 maintained, though. This class provides a way to manage a working | |
25 copy that contains only the part that actually need to be packaged. | |
26 """ | |
27 | |
28 def __init__(self, baseurl, localdir, subdirectories): | |
29 self.baseurl = baseurl | |
30 self.localdir = localdir | |
31 self.subdirectories = subdirectories | |
32 | |
33 def update_or_checkout(self, revision=None): | |
34 for desc in self.subdirectories: | |
35 if len(desc) == 2: | |
36 subdir, recurse = desc | |
37 else: | |
38 subdir = desc[0] | |
39 recurse = True | |
40 self.update_or_checkout_subdir(subdir, revision, recurse=recurse) | |
41 | |
42 def update_or_checkout_subdir(self, subdir, revision, recurse): | |
43 localdir = os.path.join(self.localdir, subdir) | |
44 svn_url = self.baseurl + subdir | |
45 if os.path.exists(localdir): | |
46 logging.info("Updating the working copy in %r", localdir) | |
47 subversion.update(localdir, revision=revision, recurse=recurse) | |
48 else: | |
49 logging.info("The working copy in %r doesn't exist yet." | |
50 " Checking out from %r", localdir, svn_url) | |
51 subversion.checkout(svn_url, localdir, revision=revision, | |
52 recurse=recurse) | |
53 | |
54 def export(self, destdir): | |
55 for desc in self.subdirectories: | |
56 subdir = desc[0] | |
57 subversion.export(os.path.join(self.localdir, subdir), | |
58 os.path.join(destdir, subdir)) | |
59 | |
60 def last_changed_revision(self): | |
61 return max([subversion.last_changed_revision(os.path.join(self.localdir, | |
62 desc[0])) | |
63 for desc in self.subdirectories]) | |
64 | |
65 | |
66 | |
67 class SourcePackager(treepkg.packager.SourcePackager): | |
68 | |
69 """Creates the debian source package for the l10n files | |
70 | |
71 This is a bit more complicated than for other packages. The | |
72 orig.tar.gz file of the debian source package contains one .tar.bz2 | |
73 file for every language. Those .tar.bz files are the kde-18n-<lang> | |
74 files released by the KDE project. For now, we only have the German | |
75 localization in the enterprise source package, so the orig.tar.gz | |
76 file will have the following contents: | |
77 | |
78 kde-l10n-<version>/ | |
79 kde-l10n-<version>/kde-l10n-de-<version>.tar.bz2 | |
80 | |
81 <version> is the same everywhere. | |
82 """ | |
83 | |
84 pkg_basename = "kde-l10n" | |
85 | |
86 createtarball_script = """\ | |
87 #! /bin/bash | |
88 set -e | |
89 | |
90 apt-get --assume-yes --force-yes install %(builddeps)s | |
91 | |
92 # copy the source tree to a directory that's under pbuilder control so | |
93 # that it gets removed along with the build environment. Otherwise we | |
94 # end up with a directory containing files that cannot be removed by | |
95 # treepkg | |
96 workdir=/tmp/work | |
97 cp -a %(basedir)s $workdir | |
98 cd $workdir | |
99 | |
100 # only handle the de subdirectory | |
101 echo de > subdirs | |
102 | |
103 # create the CMakeFiles | |
104 ./scripts/autogen.sh | |
105 mv de kde-l10n-de-%(version)s | |
106 tar cjf %(tarball)s kde-l10n-de-%(version)s | |
107 """ | |
108 | |
109 | |
110 def __init__(self, *args, **kw): | |
111 super(SourcePackager, self).__init__(*args, **kw) | |
112 self.enterprise_version = (time.strftime("%Y%m%d", time.localtime()) | |
113 + "." + str(self.revision)) | |
114 | |
115 def determine_package_version(self, directory): | |
116 enterprise_version = self.enterprise_version | |
117 return self.track.version_template % locals() | |
118 | |
119 def create_l10n_de_tarball(self, pkgbaseversion, pkgbasedir): | |
120 logging.info("Creating kde-l10n-de tarball") | |
121 de_tarball = os.path.join(self.work_dir, | |
122 "kde-l10n-de-" + pkgbaseversion + ".tar.bz2") | |
123 # imake is needed for the revpath script | |
124 script = (self.createtarball_script | |
125 % dict(builddeps="imake", tarball=de_tarball, | |
126 basedir=pkgbasedir, version=pkgbaseversion)) | |
127 script_name = os.path.join(self.work_dir, "createtarball") | |
128 treepkg.util.writefile(script_name, script, 0755) | |
129 treepkg.util.ensure_directory(self.src_dir) | |
130 treepkg.util.ensure_directory(self.log_dir) | |
131 self.track.builder.run_script([script_name], | |
132 logfile=os.path.join(self.log_dir, | |
133 "tarball_log.txt"), | |
134 bindmounts=[self.work_dir]) | |
135 return de_tarball | |
136 | |
137 def do_package(self): | |
138 pkgbaseversion, pkgbasedir = self.export_sources() | |
139 de_tarball = self.create_l10n_de_tarball(pkgbaseversion, pkgbasedir) | |
140 shutil.rmtree(pkgbasedir) | |
141 | |
142 os.mkdir(pkgbasedir) | |
143 pkgbasename = self.pkg_basename + "_" + pkgbaseversion | |
144 origtargz = os.path.join(self.work_dir, | |
145 pkgbasename + ".orig.tar.gz") | |
146 os.rename(de_tarball, | |
147 os.path.join(pkgbasedir, os.path.basename(de_tarball))) | |
148 self.create_tarball(origtargz, self.work_dir, | |
149 os.path.basename(pkgbasedir)) | |
150 | |
151 changemsg = ("Update to SVN enterprise4 branch rev. %d" | |
152 % (self.revision,)) | |
153 self.copy_debian_directory(pkgbasedir, pkgbaseversion, changemsg) | |
154 | |
155 self.create_source_package(pkgbasedir, origtargz) | |
156 self.move_source_package(pkgbasename) | |
157 | |
158 | |
159 class RevisionPackager(treepkg.packager.RevisionPackager): | |
160 | |
161 source_packager_cls = SourcePackager | |
162 | |
163 | |
164 class PackageTrack(treepkg.packager.PackageTrack): | |
165 | |
166 extra_config_desc = ["version_template"] | |
167 | |
168 revision_packager_cls = RevisionPackager | |
169 | |
170 def __init__(self, *args, **kw): | |
171 self.version_template = kw.pop("version_template") | |
172 super(PackageTrack, self).__init__(*args, **kw) | |
173 self.working_copy = SubversionSubset(self.svn_url, self.checkout_dir, | |
174 subdirectories= [("", False), | |
175 ("de",), | |
176 ("scripts",)]) | |
177 | |
178 def last_changed_revision(self): | |
179 return self.working_copy.last_changed_revision() | |
180 | |
181 def update_checkout(self, revision=None): | |
182 self.working_copy.update_or_checkout(revision=revision) | |
183 | |
184 def export_sources(self, to_dir): | |
185 self.working_copy.export(to_dir) |