Type: | rpmPackager |
Uses (at least one of): | |
Requires (at least one of): |
SourceWithSetupSaverModule >
MetadataModule > ExecuteModule > |
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 | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2012-2013, Marten de Vries
#
# This file is part of OpenTeacher.
#
# OpenTeacher is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenTeacher is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
import sys
import subprocess
import os
import shutil
import glob
import platform
SETUP_CFG = """
[install]
prefix = /usr
""".strip()
POST_CHANGES = """
/usr/bin/update-mime-database %{_datadir}/mime &> /dev/null || :
/usr/bin/update-desktop-database &> /dev/null || :
/usr/bin/gtk-update-icon-cache -f %{_datadir}/icons/hicolor &>/dev/null || :
""".strip()
class RpmPackagerModule:
def __init__(self, moduleManager, *args, **kwargs):
super().__init__(*args, **kwargs)
self._mm = moduleManager
self.type = "rpmPackager"
self.requires = (
self._mm.mods(type="sourceWithSetupSaver"),
self._mm.mods(type="metadata"),
self._mm.mods(type="execute"),
)
self.priorities = {
"package-rpm": 0,
"default": -1,
}
def enable(self):
if not platform.linux_distribution()[0].strip() in ("Fedora", "openSUSE"):
return #rpm based distro only module, remain inactive
self._modules = set(self._mm.mods(type="modules")).pop()
self._metadata= self._modules.default("active", type="metadata").metadata
self._modules.default(type="execute").startRunning.handle(self._run)
self._platform = platform.linux_distribution()[0].strip()
self.active = True
def _run(self):
try:
release = sys.argv[1]
path = sys.argv[2]
except IndexError:
sys.stderr.write("Please specify a .rpm release number and a path for the rpm file (ending in .rpm) as the last command line arguments.\n")
return
sourcePath = self._modules.default("active", type="sourceWithSetupSaver").saveSource()
#set install prefix to /usr
with open(os.path.join(sourcePath, "setup.cfg"), "w", encoding='UTF-8') as f:
f.write(SETUP_CFG)
#make sure all caches etc. are updated.
with open(os.path.join(sourcePath, "post-changes.sh"), "w", encoding='UTF-8') as f:
f.write(POST_CHANGES)
#determine requirements based on distribution
if self._platform == "Fedora":
requirements = "python3, python3-qt5, python3-qt5-webkit, espeak, python3-chardet, python3-enchant, tesseract, python3-imaging, python3-urwid"
elif self._platform == "openSUSE":
# add python-enchant if OpenSUSE adds it to the repos
requirements = "python3-qt5, espeak, python3-chardet, tesseract-ocr, python3-Pillow, python3-urwid"
oldCwd = os.getcwd()
os.chdir(sourcePath)
subprocess.check_call([
sys.executable or "python",
"setup.py",
"bdist_rpm",
"--group", "Applications/Productivity",
"--packager", "%s <%s>" % (self._metadata["authors"], self._metadata["email"]),
"--release", release,
#temporarily not needed: python-django, python-django-guardian
#add if packaged somewhere in the future: python-graphviz
"--requires", requirements,
"--post-install", "post-changes.sh",
"--post-uninstall", "post-changes.sh",
])
os.chdir(oldCwd)
shutil.copy(
glob.glob(os.path.join(sourcePath, "dist/*.noarch.rpm"))[0],
path
)
print("Please keep in mind that an rpm built on one distro, might not work on another.")
def disable(self):
self.active = False
del self._modules
def init(moduleManager):
return RpmPackagerModule(moduleManager)
|