class Ebuild(object):
"""This class represents an .ebuild file."""
+ KEYWORDS_MODS = ["unmodified", "testing", "remove"]
+
def __init__(self, logger, filename, category=None):
assert os.path.isfile(filename)
self.logger = logger
filename = self.name + "-" + self.version + ".ebuild"
return os.path.join(self.category, self.name, filename)
+ def modify_keywords(self, modification):
+ """Modify the KEYWORDS variable in the ebuild file
+
+ If modification is set to "unmodified", the ebuild file will not be
+ changed.
+
+ If modification is set to "testing", all keywords get a ~ as prefix
+ (e.g. "amd64" becomes "~amd64") unless they already have ~ as prefix.
+ Disabled prefixes (e.g. "-amd64") will not be modified.
+
+ If modification is set to "remove", the KEYWORDS variable will get
+ prefixed with a shell comment and therefore it will be removed when
+ the shell script is executed.
+
+ """
+ def add_tilde(match):
+ """Add ~ as prefix for every keyword.
+
+ KEYWORDS="amd64 ~x86 -ppc arm" becomes
+ KEYWORDS="~amd64 ~x86 -ppc ~arm", for example.
+ """
+ keywords = [w.strip() for w in match.group(2).split()]
+ for i in range(len(keywords)):
+ if keywords[i][0] not in ("-", "~"):
+ keywords[i] = "~" + keywords[i]
+ return match.group(1) + '"' + " ".join(keywords) + '"'
+
+ assert modification in Ebuild.KEYWORDS_MODS
+ if modification == "unmodified":
+ return
+ if modification == "testing":
+ keyword_re = r'^(\s*KEYWORDS=)\s*"?([^"]*)"?\s*$'
+ (self.ebuild, n_subs) = re_subn(keyword_re, add_tilde,
+ self.ebuild, flags=re.MULTILINE)
+ elif modification == "remove":
+ (self.ebuild, n_subs) = re_subn(r"^(\s*KEYWORDS=)", r"#\1",
+ self.ebuild, flags=re.MULTILINE)
+ if n_subs == 0:
+ self.logger.warn("No KEYWORDS variable found in ebuild file!")
+ elif n_subs > 1:
+ self.logger.warn("Replaced {n} occurrences of the KEYWORDS "
+ "variable in the ebuild file, but expected only "
+ "exactly one!".format(n=n_subs))
+
def save(self, base_path):
"""Save the ebuild file below the given base_path."""
fullpath = os.path.join(base_path, self.get_relpath())
def set_git_commit(self, commit):
"""Set EGIT_COMMIT in the ebuild file to the given commit."""
- (self.ebuild, n_subs) = re_subn(r'^\s*EGIT_COMMIT=.*$',
- 'EGIT_COMMIT="' + commit + '"',
+ (self.ebuild, n_subs) = re_subn(r'^(\s*EGIT_COMMIT=).*$',
+ r'\1"' + commit + '"',
self.ebuild, flags=re.MULTILINE)
if n_subs == 0:
self.logger.warn("No EGIT_COMMIT variable found in ebuild file!")
parser.add_option("--keep", dest="keep", action="store_true",
help="keep the temporary cloned directory of the "
"release repository")
+ parser.add_option("--keywords", dest="keywords",
+ choices=Ebuild.KEYWORDS_MODS, default="unmodified",
+ help="Action to modify the KEYWORDS variable ({mods}). "
+ "Default: unmodified".format(
+ mods=", ".join(Ebuild.KEYWORDS_MODS)))
parser.add_option("--tag-from-debian-changelog", dest="tag_from_debian",
action="store_true", help="tag head commit with version "
"from debian/changelog")
for ebuild in ebuilds:
ebuild.set_version(git_tag)
ebuild.set_git_commit(git_tag)
+ ebuild.modify_keywords(options.keywords)
tmpdir = tempfile.mkdtemp(prefix=script_name+".")
try:
# Checkout release repository