gstreamer/debug-viewer/setup.py

335 lines
11 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8; mode: python; -*-
#
# GStreamer Debug Viewer - View and analyze GStreamer debug log files
#
# Copyright (C) 2007 René Stadler <mail@renestadler.de>
#
# This program 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.
#
# This program 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
# this program. If not, see <http://www.gnu.org/licenses/>.
"""GStreamer Debug Viewer distutils setup script."""
import sys
import os
import os.path
import distutils.cmd
2018-04-14 15:04:22 +00:00
from setuptools import setup
from distutils.command.clean import clean
from distutils.command.build import build
from distutils.command.sdist import sdist
from distutils.command.install_scripts import install_scripts
from distutils.errors import *
2018-04-14 15:04:22 +00:00
def perform_substitution(filename, values):
2018-04-14 15:04:22 +00:00
fp = file(filename, "rt")
data = fp.read()
fp.close()
2018-04-14 15:04:22 +00:00
for name, value in list(values.items()):
data = data.replace("$%s$" % (name,), value)
2018-04-14 15:04:22 +00:00
fp = file(filename, "wt")
fp.write(data)
fp.close()
class clean_custom (clean):
2018-04-14 15:04:22 +00:00
def remove_file(self, path):
2018-04-14 15:04:22 +00:00
if os.path.exists(path):
print("removing '%s'" % (path,))
if not self.dry_run:
2018-04-14 15:04:22 +00:00
os.unlink(path)
2018-04-14 15:04:22 +00:00
def remove_directory(self, path):
from distutils import dir_util
2018-04-14 15:04:22 +00:00
if os.path.exists(path):
dir_util.remove_tree(path, dry_run=self.dry_run)
2018-04-14 15:04:22 +00:00
def run(self):
2018-04-14 15:04:22 +00:00
clean.run(self)
2018-04-14 15:04:22 +00:00
if os.path.exists("MANIFEST.in"):
# MANIFEST is generated, get rid of it.
2018-04-14 15:04:22 +00:00
self.remove_file("MANIFEST")
2018-04-14 15:04:22 +00:00
pot_file = os.path.join("po", "gst-debug-viewer.pot")
self.remove_file(pot_file)
2018-04-14 15:04:22 +00:00
self.remove_directory("build")
self.remove_directory("dist")
2018-04-14 15:04:22 +00:00
for path, dirs, files in os.walk("."):
for filename in files:
2018-04-14 15:04:22 +00:00
if filename.endswith(".pyc") or filename.endswith(".pyo"):
file_path = os.path.join(path, filename)
self.remove_file(file_path)
class build_custom (build):
2018-04-14 15:04:22 +00:00
def build_l10n(self):
return self.l10n
sub_commands = build.sub_commands + [("build_l10n", build_l10n,)]
2018-04-14 15:04:22 +00:00
user_options = build.user_options + \
[("l10n", None, "enable translations",)]
boolean_options = build.boolean_options + ["l10n"]
2018-04-14 15:04:22 +00:00
def initialize_options(self):
2018-04-14 15:04:22 +00:00
build.initialize_options(self)
self.l10n = False
2018-04-14 15:04:22 +00:00
class build_l10n (distutils.cmd.Command):
# Based on code from python-distutils-extra by Sebastian Heinlein.
description = "gettext framework integration"
user_options = [("merge-desktop-files=", "m", ".desktop.in files to merge"),
("merge-xml-files=", "x", ".xml.in files to merge"),
("merge-schemas-files=", "s", ".schemas.in files to merge"),
("merge-rfc822deb-files=", "d", "RFC822 files to merge"),
("merge-key-files=", "k", ".key.in files to merge"),
("domain=", "d", "gettext domain"),
("bug-contact=", "c", "contact address for msgid bugs")]
2018-04-14 15:04:22 +00:00
def initialize_options(self):
self.merge_desktop_files = []
self.merge_xml_files = []
self.merge_key_files = []
self.merge_schemas_files = []
self.merge_rfc822deb_files = []
self.domain = None
self.bug_contact = None
2018-04-14 15:04:22 +00:00
def finalize_options(self):
for attr in ("desktop", "xml", "key", "schemas", "rfc822deb",):
2018-04-14 15:04:22 +00:00
value = getattr(self, "merge_%s_files" % (attr,))
if not value:
value = []
else:
2018-04-14 15:04:22 +00:00
value = eval(value)
setattr(self, "merge_%s_files" % (attr,), value)
if self.domain is None:
self.domain = self.distribution.metadata.name
2018-04-14 15:04:22 +00:00
def run(self):
from glob import glob
data_files = self.distribution.data_files
2018-04-14 15:04:22 +00:00
po_makefile = os.path.join("po", "Makefile")
if os.path.exists(po_makefile):
raise DistutilsFileError("file %s exists (intltool will pick up "
"values from there)" % (po_makefile,))
2018-04-14 15:04:22 +00:00
cwd = os.getcwd()
if self.bug_contact is not None:
2018-04-14 15:04:22 +00:00
os.environ["XGETTEXT_ARGS"] = "--msgid-bugs-address=%s" % (
self.bug_contact,)
os.chdir(os.path.join(cwd, "po"))
# Update .pot file.
2018-04-14 15:04:22 +00:00
self.spawn(["intltool-update", "-p", "-g", self.domain])
# Merge new strings into .po files.
2018-04-14 15:04:22 +00:00
self.spawn(["intltool-update", "-r", "-g", self.domain])
2018-04-14 15:04:22 +00:00
os.chdir(cwd)
2018-04-14 15:04:22 +00:00
for po_file in glob(os.path.join("po", "*.po")):
lang = os.path.basename(po_file[:-3])
if lang.startswith("."):
# Hidden file, like auto-save data from an editor.
continue
2018-04-14 15:04:22 +00:00
mo_dir = os.path.join("build", "mo", lang, "LC_MESSAGES")
mo_file = os.path.join(mo_dir, "%s.mo" % (self.domain,))
self.mkpath(mo_dir)
self.spawn(["msgfmt", po_file, "-o", mo_file])
2018-04-14 15:04:22 +00:00
targetpath = os.path.join("share", "locale", lang, "LC_MESSAGES")
data_files.append((targetpath, (mo_file,)))
for parameter, option in ((self.merge_xml_files, "-x",),
(self.merge_desktop_files, "-d",),
(self.merge_schemas_files, "-s",),
(self.merge_rfc822deb_files, "-r",),
(self.merge_key_files, "-k",),):
if not parameter:
continue
for target, files in parameter:
2018-04-14 15:04:22 +00:00
build_target = os.path.join("build", target)
for file in files:
2018-04-14 15:04:22 +00:00
if file.endswith(".in"):
file_merged = os.path.basename(file[:-3])
else:
2018-04-14 15:04:22 +00:00
file_merged = os.path.basename(file)
self.mkpath(build_target)
file_merged = os.path.join(build_target, file_merged)
self.spawn(["intltool-merge", option, "po", file, file_merged])
data_files.append((target, [file_merged],))
class distcheck (sdist):
# Originally based on code from telepathy-python.
description = "verify self-containedness of source distribution"
2018-04-14 15:04:22 +00:00
def run(self):
from distutils import dir_util
from distutils.spawn import spawn
# This creates e.g. dist/gst-debug-viewer-0.1.tar.gz.
2018-04-14 15:04:22 +00:00
sdist.run(self)
2018-04-14 15:04:22 +00:00
base_dir = self.distribution.get_fullname()
distcheck_dir = os.path.join(self.dist_dir, "distcheck")
self.mkpath(distcheck_dir)
self.mkpath(os.path.join(distcheck_dir, "again"))
2018-04-14 15:04:22 +00:00
cwd = os.getcwd()
os.chdir(distcheck_dir)
2018-04-14 15:04:22 +00:00
if os.path.isdir(base_dir):
dir_util.remove_tree(base_dir)
# Unpack tarball into dist/distcheck, creating
# e.g. dist/distcheck/gst-debug-viewer-0.1.
for archive in self.archive_files:
2018-04-14 15:04:22 +00:00
if archive.endswith(".tar.gz"):
archive_rel = os.path.join(os.pardir, os.pardir, archive)
spawn(["tar", "-xzf", archive_rel, base_dir])
break
else:
2018-04-14 15:04:22 +00:00
raise ValueError("no supported archives were created")
2018-04-14 15:04:22 +00:00
os.chdir(cwd)
os.chdir(os.path.join(distcheck_dir, base_dir))
spawn([sys.executable, "setup.py", "sdist", "--formats", "gztar"])
# Unpack tarball into dist/distcheck/again.
2018-04-14 15:04:22 +00:00
os.chdir(cwd)
os.chdir(os.path.join(distcheck_dir, "again"))
archive_rel = os.path.join(
os.pardir, base_dir, "dist", "%s.tar.gz" % (base_dir,))
spawn(["tar", "-xzf", archive_rel, base_dir])
2018-04-14 15:04:22 +00:00
os.chdir(cwd)
os.chdir(os.path.join(distcheck_dir, base_dir))
spawn([sys.executable, "setup.py", "clean"])
2018-04-14 15:04:22 +00:00
os.chdir(cwd)
spawn(["diff", "-ru",
os.path.join(distcheck_dir, base_dir),
os.path.join(distcheck_dir, "again", base_dir)])
if not self.keep_temp:
2018-04-14 15:04:22 +00:00
dir_util.remove_tree(distcheck_dir)
class install_scripts_custom (install_scripts):
user_options = install_scripts.user_options \
2018-04-14 15:04:22 +00:00
+ [("substitute-files=", None,
"files to perform substitution on")]
2018-04-14 15:04:22 +00:00
def initialize_options(self):
2018-04-14 15:04:22 +00:00
install_scripts.initialize_options(self)
self.substitute_files = "[]"
2018-04-14 15:04:22 +00:00
def run(self):
from os.path import normpath
2018-04-14 15:04:22 +00:00
install = self.distribution.get_command_obj("install")
install.ensure_finalized()
2009-03-14 21:02:45 +00:00
2018-04-14 15:04:22 +00:00
values = {"DATADIR": install.install_data or "",
"PREFIX": install.home or install.prefix or "",
"SCRIPTSDIR": self.install_dir or ""}
if install.home:
2018-04-14 15:04:22 +00:00
values["LIBDIR"] = os.path.normpath(install.install_lib)
if install.root:
2018-04-14 15:04:22 +00:00
root = normpath(install.root)
len_root = len(root)
for name, value in list(values.items()):
if normpath(value).startswith(root):
values[name] = normpath(value)[len_root:]
# Perform installation as normal...
2018-04-14 15:04:22 +00:00
install_scripts.run(self)
if self.dry_run:
return
# ...then substitute in-place:
2018-04-14 15:04:22 +00:00
for filename in eval(self.substitute_files):
perform_substitution(os.path.join(
self.install_dir, filename), values)
cmdclass = {"build": build_custom,
"clean": clean_custom,
"install_scripts": install_scripts_custom,
"build_l10n": build_l10n,
"distcheck": distcheck}
setup(cmdclass=cmdclass,
packages=["GstDebugViewer",
"GstDebugViewer.Common",
"GstDebugViewer.GUI",
"GstDebugViewer.Plugins",
"GstDebugViewer.tests"],
scripts=["gst-debug-viewer"],
data_files=[("share/gst-debug-viewer", ["data/about-dialog.ui",
"data/main-window.ui",
"data/menus.ui"],),
("share/icons/hicolor/48x48/apps",
["data/gst-debug-viewer.png"],),
("share/icons/hicolor/scalable/apps", ["data/gst-debug-viewer.svg"],)],
name="gst-debug-viewer",
version="0.1",
description="GStreamer Debug Viewer",
long_description="""""",
test_suite="GstDebugViewer.tests",
license="GNU GPL",
author="Rene Stadler",
author_email="mail@renestadler.de",
url="http://renestadler.de/projects/gst-debug-viewer")