comparison recipes/kde/enterprise/generic.py @ 314:2c345bfbfb90

Create generic kde enterprise packager by copying and adapting recipes/kde_enterprise_3_5/base.py. This packager can handle most of the KDE4 based enterprise packages and the basics of enterprise 3.5.
author Bernhard Herzog <bh@intevation.de>
date Thu, 03 Dec 2009 11:13:02 +0000
parents recipes/kde_enterprise_3_5/base.py@3749b8285b93
children 781074885633
comparison
equal deleted inserted replaced
313:170c8be38d84 314:2c345bfbfb90
1 # Copyright (C) 2007, 2008, 2009 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 """Base classes for all kde entperprise packagers"""
9
10 import re
11 import time
12 import logging
13
14 import treepkg.packager
15 import treepkg.subversion as subversion
16
17
18 class SourcePackager(treepkg.packager.SourcePackager):
19
20 def __init__(self, *args, **kw):
21 super(SourcePackager, self).__init__(*args, **kw)
22 self.enterprise_version = (self.parent.pkg_date + "."
23 + str(self.revision))
24
25 def determine_package_version(self, directory):
26 enterprise_version = self.enterprise_version
27 return self.track.version_template % locals()
28
29 def prepare_sources_for_tarball(self, pkgbasedir, pkgbaseversion):
30 self.update_version_numbers(pkgbasedir)
31
32 def update_version_numbers(self, pkgbasedir):
33 """Updates the version numbers in the code in pkgbasedir.
34 The default implementation does nothing. Derived classes should
35 override this method if necessary.
36 """
37
38
39 class RevisionPackager(treepkg.packager.RevisionPackager):
40
41 source_packager_cls = SourcePackager
42
43 def __init__(self, *args, **kw):
44 self.pkg_date = kw.pop("pkg_date",
45 time.strftime("%Y%m%d", time.localtime()))
46 super(RevisionPackager, self).__init__(*args, **kw)
47
48
49 class PackageTrack(treepkg.packager.PackageTrack):
50
51 revision_packager_cls = RevisionPackager
52
53 extra_config_desc = [("tags_url", str, ""),
54 ("tags_pattern", str, ""),
55 ("tags_subdir", str, "")]
56
57 def __init__(self, *args, **kw):
58 tags_url = kw.pop("tags_url")
59 tags_pattern = kw.pop("tags_pattern")
60 tags_subdir = kw.pop("tags_subdir")
61 super(PackageTrack, self).__init__(*args, **kw)
62 self.tag_detector = subversion.TagDetector(tags_url, tags_pattern,
63 tags_subdir)
64
65 def packager_for_new_revision(self):
66 logging.info("Checking tags")
67 self.tag_url = None
68 tag_url, tag_revision = self.tag_detector.newest_tag_revision()
69 logging.info("Found: %s: %s", tag_url, tag_revision)
70 if tag_url is not None:
71 revision = (tag_revision,
72 self.rules_working_copy.last_changed_revision())
73 logging.info("New revision is %s", revision)
74 if revision not in self.get_revision_numbers():
75 logging.info("Revision %s has not been packaged yet",
76 revision)
77 self.tag_url = tag_url
78 self.tag_revision = tag_revision
79 tag_date, tag_change_count = self.tag_pkg_parameters(tag_url)
80 pkg_revision = (self.pkg_revision_template
81 % dict(pkg_revision=tag_change_count))
82 return self.revision_packager_cls(self, tag=tag_url,
83 pkg_revision=pkg_revision,
84 pkg_date=tag_date,
85 *revision)
86 else:
87 logging.info("Revision %s has already been packaged.",
88 revision)
89
90 return super(PackageTrack, self).packager_for_new_revision()
91
92 def export_sources(self, to_dir):
93 if self.tag_url is not None:
94 logging.info("Exporting sources for tarball from %r to %r",
95 self.tag_url, to_dir)
96 self.working_copy.export_tag(self.tag_url, to_dir,
97 revision=self.tag_revision)
98 else:
99 super(PackageTrack, self).export_sources(to_dir)
100
101 def tag_pkg_parameters(self, tag_url):
102 match = re.search(r"/enterprise[^.]*\.[^.]*\."
103 r"(?P<date>[0-9]{8})\.(?P<baserev>[0-9]+)/",
104 tag_url)
105 if match:
106 date = match.group("date")
107 baserev = int(match.group("baserev"))
108 xml_log = subversion.log_xml(tag_url, baserev)
109 revisions = subversion.extract_tag_revisions(xml_log)
110 tag_change_count = len(revisions)
111 return (date, tag_change_count)
112 else:
113 raise RuntimeError("Cannot determine tag parameters from %r"
114 % tag_url)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)