1 # Copyright 2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
10 from portage import os
11 from portage import _unicode_decode
12 from portage.const import PORTAGE_BASE_PATH, PORTAGE_BIN_PATH, PORTAGE_PYM_PATH
13 from portage.process import find_binary
14 from portage.tests import TestCase
15 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
16 from portage.util import ensure_dirs
17 from repoman.utilities import _update_copyright_year
19 class SimpleRepomanTestCase(TestCase):
21 def testCopyrightUpdate(self):
25 '# Copyright 1999-2008 Gentoo Foundation; Distributed under the GPL v2',
26 '# Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL v2',
30 '# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2',
31 '# Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL v2',
35 '# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2',
36 '# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2',
40 for year, before, after in test_cases:
41 self.assertEqual(_update_copyright_year(year, before), after)
44 xmllint = find_binary("xmllint")
46 return "xmllint not found"
49 __import__("xml.etree.ElementTree")
50 __import__("xml.parsers.expat").parsers.expat.ExpatError
51 except (AttributeError, ImportError):
52 return "python is missing xml support"
57 skip_reason = self._must_skip()
59 self.portage_skip = skip_reason
60 self.assertFalse(True, skip_reason)
63 copyright_header = """# Copyright 1999-%s Gentoo Foundation
64 # Distributed under the terms of the GNU General Public License v2
66 """ % time.gmtime().tm_year
72 "update-changelog = true",
78 ("x86", "default/linux/x86/test_profile", "stable"),
83 "COPYRIGHT_HEADER" : copyright_header,
84 "DESCRIPTION" : "Desc goes here",
86 "HOMEPAGE" : "http://example.com",
90 "RDEPEND": "flag? ( dev-libs/B[flag] )",
93 "COPYRIGHT_HEADER" : copyright_header,
94 "DESCRIPTION" : "Desc goes here",
96 "HOMEPAGE" : "http://example.com",
104 metadata_dtd = os.path.join(PORTAGE_BASE_PATH, "cnf/metadata.dtd")
105 metadata_xml_files = (
109 "herd" : "base-system",
110 "flags" : "<flag name='flag'>Description of how USE='flag' affects this package</flag>",
117 "flags" : "<flag name='flag'>Description of how USE='flag' affects this package</flag>",
123 ("flag", "Description of how USE='flag' affects packages"),
126 playground = ResolverPlayground(ebuilds=ebuilds,
127 repo_configs=repo_configs, debug=debug)
128 settings = playground.settings
129 eprefix = settings["EPREFIX"]
130 eroot = settings["EROOT"]
131 portdb = playground.trees[playground.eroot]["porttree"].dbapi
132 homedir = os.path.join(eroot, "home")
133 distdir = os.path.join(eprefix, "distdir")
134 portdir = settings["PORTDIR"]
135 profiles_dir = os.path.join(portdir, "profiles")
136 license_dir = os.path.join(portdir, "licenses")
138 repoman_cmd = (portage._python_interpreter, "-Wd",
139 os.path.join(PORTAGE_BIN_PATH, "repoman"))
141 git_binary = find_binary("git")
142 git_cmd = (git_binary,)
144 cp_binary = find_binary("cp")
145 self.assertEqual(cp_binary is None, False,
146 "cp command not found")
147 cp_cmd = (cp_binary,)
149 test_ebuild = portdb.findname("dev-libs/A-1")
150 self.assertFalse(test_ebuild is None)
152 committer_name = "Gentoo Dev"
153 committer_email = "gentoo-dev@gentoo.org"
156 ("", repoman_cmd + ("manifest",)),
157 ("", git_cmd + ("config", "--global", "user.name", committer_name,)),
158 ("", git_cmd + ("config", "--global", "user.email", committer_email,)),
159 ("", git_cmd + ("init-db",)),
160 ("", git_cmd + ("add", ".")),
161 ("", git_cmd + ("commit", "-a", "-m", "add whole repo")),
162 ("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "2.ebuild")),
163 ("", git_cmd + ("add", test_ebuild[:-8] + "2.ebuild")),
164 ("", repoman_cmd + ("commit", "-m", "bump to version 2")),
165 ("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "3.ebuild")),
166 ("", git_cmd + ("add", test_ebuild[:-8] + "3.ebuild")),
167 ("dev-libs", repoman_cmd + ("commit", "-m", "bump to version 3")),
168 ("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "4.ebuild")),
169 ("", git_cmd + ("add", test_ebuild[:-8] + "4.ebuild")),
170 ("dev-libs/A", repoman_cmd + ("commit", "-m", "bump to version 4")),
173 pythonpath = os.environ.get("PYTHONPATH")
174 if pythonpath is not None and not pythonpath.strip():
176 if pythonpath is not None and \
177 pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
180 if pythonpath is None:
183 pythonpath = ":" + pythonpath
184 pythonpath = PORTAGE_PYM_PATH + pythonpath
187 "__REPOMAN_TEST_EPREFIX" : eprefix,
189 "GENTOO_COMMITTER_NAME" : committer_name,
190 "GENTOO_COMMITTER_EMAIL" : committer_email,
192 "PATH" : os.environ["PATH"],
193 "PORTAGE_GRPNAME" : os.environ["PORTAGE_GRPNAME"],
194 "PORTAGE_USERNAME" : os.environ["PORTAGE_USERNAME"],
196 "PYTHONPATH" : pythonpath,
199 dirs = [homedir, license_dir, profiles_dir, distdir]
203 with open(os.path.join(portdir, "skel.ChangeLog"), 'w') as f:
204 f.write(copyright_header)
205 with open(os.path.join(profiles_dir, "profiles.desc"), 'w') as f:
207 f.write("%s %s %s\n" % x)
209 open(os.path.join(license_dir, x), 'wb').close()
210 with open(os.path.join(profiles_dir, "arch.list"), 'w') as f:
213 with open(os.path.join(profiles_dir, "use.desc"), 'w') as f:
214 for k, v in use_desc:
215 f.write("%s - %s\n" % (k, v))
216 for cp, xml_data in metadata_xml_files:
217 with open(os.path.join(portdir, cp, "metadata.xml"), 'w') as f:
218 f.write(playground.metadata_xml_template % xml_data)
219 # Use a symlink to portdir, in order to trigger bugs
220 # involving canonical vs. non-canonical paths.
221 portdir_symlink = os.path.join(eroot, "portdir_symlink")
222 os.symlink(portdir, portdir_symlink)
223 # repoman checks metadata.dtd for recent CTIME, so copy the file in
224 # order to ensure that the CTIME is current
225 shutil.copyfile(metadata_dtd, os.path.join(distdir, "metadata.dtd"))
228 # The subprocess inherits both stdout and stderr, for
229 # debugging purposes.
232 # The subprocess inherits stderr so that any warnings
233 # triggered by python -Wd will be visible.
234 stdout = subprocess.PIPE
236 for cwd in ("", "dev-libs", "dev-libs/A", "dev-libs/B"):
237 abs_cwd = os.path.join(portdir_symlink, cwd)
238 proc = subprocess.Popen([portage._python_interpreter, "-Wd",
239 os.path.join(PORTAGE_BIN_PATH, "repoman"), "full"],
240 cwd=abs_cwd, env=env, stdout=stdout)
245 output = proc.stdout.readlines()
248 if proc.returncode != os.EX_OK:
250 sys.stderr.write(_unicode_decode(line))
252 self.assertEqual(os.EX_OK, proc.returncode,
253 "repoman failed in %s" % (cwd,))
255 if git_binary is not None:
256 for cwd, cmd in git_test:
257 abs_cwd = os.path.join(portdir_symlink, cwd)
258 proc = subprocess.Popen(cmd,
259 cwd=abs_cwd, env=env, stdout=stdout)
264 output = proc.stdout.readlines()
267 if proc.returncode != os.EX_OK:
269 sys.stderr.write(_unicode_decode(line))
271 self.assertEqual(os.EX_OK, proc.returncode,
272 "%s failed in %s" % (cmd, cwd,))