2018-01-28 04:46:39 +08:00
|
|
|
#!/usr/bin/env python3
|
2018-03-21 03:00:02 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
|
|
|
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2019-06-15 04:34:00 +08:00
|
|
|
import sys
|
|
|
|
if sys.version_info.major < 3:
|
|
|
|
print("virt-manager is python3 only. Run this as ./setup.py")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2013-03-17 09:32:29 +08:00
|
|
|
import glob
|
|
|
|
import os
|
2020-07-08 22:54:13 +08:00
|
|
|
from pathlib import Path
|
2021-05-23 03:34:41 +08:00
|
|
|
import shutil
|
|
|
|
import sysconfig
|
2020-07-18 02:16:18 +08:00
|
|
|
import subprocess
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
# distutils will be deprecated in python 3.12 in favor of setuptools,
|
|
|
|
# but as of this writing there's standard no setuptools way to extend the
|
|
|
|
# 'build' or 'build_scripts' commands which are the only standard
|
|
|
|
# commands we trigger.
|
2015-11-03 06:06:46 +08:00
|
|
|
import distutils.command.build
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
import setuptools
|
|
|
|
import setuptools.command.install
|
|
|
|
import setuptools.command.install_egg_info
|
2018-12-07 16:28:55 +08:00
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
SYSPREFIX = sysconfig.get_config_var("prefix")
|
2018-03-22 06:00:38 +08:00
|
|
|
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2019-06-17 23:14:39 +08:00
|
|
|
def _import_buildconfig():
|
|
|
|
# A bit of crazyness to import the buildconfig file without importing
|
|
|
|
# the rest of virtinst, so the build process doesn't require all the
|
|
|
|
# runtime deps to be installed
|
|
|
|
import warnings
|
2019-06-15 04:34:00 +08:00
|
|
|
|
2019-06-17 23:14:39 +08:00
|
|
|
# 'imp' is deprecated. We use it elsewhere though too. Deal with using
|
|
|
|
# the modern replacement when we replace all usage
|
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
|
|
import imp
|
|
|
|
buildconfig = imp.load_source('buildconfig', 'virtinst/buildconfig.py')
|
|
|
|
if "libvirt" in sys.modules:
|
|
|
|
raise RuntimeError("Found libvirt in sys.modules. setup.py should "
|
|
|
|
"not import virtinst.")
|
|
|
|
return buildconfig.BuildConfig
|
2019-06-15 04:34:00 +08:00
|
|
|
|
|
|
|
|
2019-06-17 23:14:39 +08:00
|
|
|
BuildConfig = _import_buildconfig()
|
2016-04-19 04:42:12 +08:00
|
|
|
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2014-04-03 06:39:43 +08:00
|
|
|
# pylint: disable=attribute-defined-outside-init
|
|
|
|
|
2016-06-18 05:31:24 +08:00
|
|
|
_desktop_files = [
|
|
|
|
("share/applications", ["data/virt-manager.desktop.in"]),
|
|
|
|
]
|
|
|
|
_appdata_files = [
|
2020-01-06 21:43:17 +08:00
|
|
|
("share/metainfo", ["data/virt-manager.appdata.xml.in"]),
|
2016-06-18 05:31:24 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class my_build_i18n(setuptools.Command):
|
2013-03-17 09:32:29 +08:00
|
|
|
"""
|
|
|
|
Add our desktop files to the list, saves us having to track setup.cfg
|
|
|
|
"""
|
2013-04-19 04:51:44 +08:00
|
|
|
user_options = [
|
|
|
|
('merge-po', 'm', 'merge po files against template'),
|
|
|
|
]
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2013-04-19 04:51:44 +08:00
|
|
|
def initialize_options(self):
|
|
|
|
self.merge_po = False
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2013-04-04 07:07:42 +08:00
|
|
|
def run(self):
|
2013-04-19 04:51:44 +08:00
|
|
|
po_dir = "po"
|
2020-07-08 22:54:14 +08:00
|
|
|
if self.merge_po:
|
|
|
|
pot_file = os.path.join("po", "virt-manager.pot")
|
|
|
|
for po_file in glob.glob("%s/*.po" % po_dir):
|
|
|
|
cmd = ["msgmerge", "--previous", "-o", po_file, po_file, pot_file]
|
|
|
|
self.spawn(cmd)
|
2013-04-19 04:51:44 +08:00
|
|
|
|
|
|
|
max_po_mtime = 0
|
|
|
|
for po_file in glob.glob("%s/*.po" % po_dir):
|
|
|
|
lang = os.path.basename(po_file[:-3])
|
|
|
|
mo_dir = os.path.join("build", "mo", lang, "LC_MESSAGES")
|
|
|
|
mo_file = os.path.join(mo_dir, "virt-manager.mo")
|
|
|
|
if not os.path.exists(mo_dir):
|
|
|
|
os.makedirs(mo_dir)
|
|
|
|
|
|
|
|
cmd = ["msgfmt", po_file, "-o", mo_file]
|
|
|
|
po_mtime = os.path.getmtime(po_file)
|
|
|
|
mo_mtime = (os.path.exists(mo_file) and
|
|
|
|
os.path.getmtime(mo_file)) or 0
|
|
|
|
if po_mtime > max_po_mtime:
|
|
|
|
max_po_mtime = po_mtime
|
|
|
|
if po_mtime > mo_mtime:
|
|
|
|
self.spawn(cmd)
|
|
|
|
|
|
|
|
targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
|
|
|
|
self.distribution.data_files.append((targetpath, (mo_file,)))
|
|
|
|
|
2020-07-08 22:54:16 +08:00
|
|
|
# Merge .in with translations using gettext
|
2020-07-08 22:54:17 +08:00
|
|
|
for (file_set, switch) in [(_appdata_files, "--xml"),
|
|
|
|
(_desktop_files, "--desktop")]:
|
2020-07-08 22:54:16 +08:00
|
|
|
for (target, files) in file_set:
|
|
|
|
build_target = os.path.join("build", target)
|
|
|
|
if not os.path.exists(build_target):
|
|
|
|
os.makedirs(build_target)
|
|
|
|
|
|
|
|
files_merged = []
|
|
|
|
for f in files:
|
|
|
|
if f.endswith(".in"):
|
|
|
|
file_merged = os.path.basename(f[:-3])
|
|
|
|
else:
|
|
|
|
file_merged = os.path.basename(f)
|
|
|
|
|
|
|
|
file_merged = os.path.join(build_target, file_merged)
|
|
|
|
cmd = ["msgfmt", switch, "--template", f, "-d", po_dir,
|
|
|
|
"-o", file_merged]
|
|
|
|
mtime_merged = (os.path.exists(file_merged) and
|
|
|
|
os.path.getmtime(file_merged)) or 0
|
|
|
|
mtime_file = os.path.getmtime(f)
|
|
|
|
if (mtime_merged < max_po_mtime or
|
|
|
|
mtime_merged < mtime_file):
|
|
|
|
# Only build if output is older than input (.po,.in)
|
|
|
|
self.spawn(cmd)
|
|
|
|
files_merged.append(file_merged)
|
|
|
|
self.distribution.data_files.append((target, files_merged))
|
|
|
|
|
2013-04-19 04:51:44 +08:00
|
|
|
|
2015-11-03 06:06:46 +08:00
|
|
|
class my_build(distutils.command.build.build):
|
2013-03-18 07:32:19 +08:00
|
|
|
def _make_bin_wrappers(self):
|
2020-01-27 06:12:09 +08:00
|
|
|
template = """#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
sys.path.insert(0, "%(sharepath)s")
|
|
|
|
from %(pkgname)s import %(filename)s
|
|
|
|
|
|
|
|
%(filename)s.runcli()
|
|
|
|
"""
|
2013-03-18 07:32:19 +08:00
|
|
|
if not os.path.exists("build"):
|
|
|
|
os.mkdir("build")
|
2020-01-27 06:12:09 +08:00
|
|
|
sharepath = os.path.join(BuildConfig.prefix, "share", "virt-manager")
|
2013-03-18 07:32:19 +08:00
|
|
|
|
2020-01-27 06:12:09 +08:00
|
|
|
def make_script(pkgname, filename, toolname):
|
|
|
|
assert os.path.exists(pkgname + "/" + filename + ".py")
|
|
|
|
content = template % {
|
|
|
|
"sharepath": sharepath,
|
|
|
|
"pkgname": pkgname,
|
|
|
|
"filename": filename}
|
2013-03-18 07:32:19 +08:00
|
|
|
|
2020-01-27 06:12:09 +08:00
|
|
|
newpath = os.path.abspath(os.path.join("build", toolname))
|
2017-05-06 02:16:59 +08:00
|
|
|
print("Generating %s" % newpath)
|
2020-01-27 06:12:09 +08:00
|
|
|
open(newpath, "w").write(content)
|
|
|
|
|
|
|
|
make_script("virtinst", "virtinstall", "virt-install")
|
|
|
|
make_script("virtinst", "virtclone", "virt-clone")
|
|
|
|
make_script("virtinst", "virtxml", "virt-xml")
|
|
|
|
make_script("virtManager", "virtmanager", "virt-manager")
|
2013-03-18 07:32:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
def _make_man_pages(self):
|
2021-05-23 03:34:41 +08:00
|
|
|
rstbin = shutil.which("rst2man")
|
2020-09-12 03:15:17 +08:00
|
|
|
if not rstbin:
|
2021-05-23 03:34:41 +08:00
|
|
|
rstbin = shutil.which("rst2man.py")
|
2020-09-12 03:15:17 +08:00
|
|
|
if not rstbin:
|
|
|
|
sys.exit("Didn't find rst2man or rst2man.py")
|
|
|
|
|
|
|
|
for path in glob.glob("man/*.rst"):
|
2013-03-18 07:32:19 +08:00
|
|
|
base = os.path.basename(path)
|
2014-09-07 06:05:43 +08:00
|
|
|
appname = os.path.splitext(base)[0]
|
2013-03-18 07:32:19 +08:00
|
|
|
newpath = os.path.join(os.path.dirname(path),
|
2014-09-07 06:05:43 +08:00
|
|
|
appname + ".1")
|
2013-03-18 07:32:19 +08:00
|
|
|
|
2017-05-06 02:16:59 +08:00
|
|
|
print("Generating %s" % newpath)
|
2020-09-12 03:15:17 +08:00
|
|
|
out = subprocess.check_output([rstbin, "--strict", path])
|
|
|
|
open(newpath, "wb").write(out)
|
|
|
|
|
|
|
|
self.distribution.data_files.append(
|
|
|
|
('share/man/man1', (newpath,)))
|
2013-03-18 07:32:19 +08:00
|
|
|
|
2013-04-19 04:51:44 +08:00
|
|
|
def _build_icons(self):
|
|
|
|
for size in glob.glob(os.path.join("data/icons", "*")):
|
2013-03-17 09:32:29 +08:00
|
|
|
for category in glob.glob(os.path.join(size, "*")):
|
|
|
|
icons = []
|
2013-04-14 02:34:52 +08:00
|
|
|
for icon in glob.glob(os.path.join(category, "*")):
|
2013-04-19 04:51:44 +08:00
|
|
|
icons.append(icon)
|
2013-03-17 09:32:29 +08:00
|
|
|
if not icons:
|
|
|
|
continue
|
|
|
|
|
|
|
|
category = os.path.basename(category)
|
|
|
|
dest = ("share/icons/hicolor/%s/%s" %
|
|
|
|
(os.path.basename(size), category))
|
|
|
|
if category != "apps":
|
|
|
|
dest = dest.replace("share/", "share/virt-manager/")
|
|
|
|
|
2013-04-19 04:51:44 +08:00
|
|
|
self.distribution.data_files.append((dest, icons))
|
|
|
|
|
|
|
|
|
2018-12-07 16:28:55 +08:00
|
|
|
def _make_bash_completion_files(self):
|
2020-01-25 05:18:00 +08:00
|
|
|
scripts = ["virt-install", "virt-clone", "virt-xml"]
|
2018-12-19 00:58:52 +08:00
|
|
|
srcfile = "data/bash-completion.sh.in"
|
|
|
|
builddir = "build/bash-completion/"
|
|
|
|
if not os.path.exists(builddir):
|
|
|
|
os.makedirs(builddir)
|
|
|
|
|
|
|
|
instpaths = []
|
2018-12-07 16:28:55 +08:00
|
|
|
for script in scripts:
|
2018-12-19 00:58:52 +08:00
|
|
|
genfile = os.path.join(builddir, script)
|
|
|
|
print("Generating %s" % genfile)
|
|
|
|
src = open(srcfile, "r")
|
|
|
|
dst = open(genfile, "w")
|
|
|
|
dst.write(src.read().replace("::SCRIPTNAME::", script))
|
|
|
|
dst.close()
|
|
|
|
instpaths.append(genfile)
|
2018-12-07 16:28:55 +08:00
|
|
|
|
2018-12-19 00:58:52 +08:00
|
|
|
bashdir = "share/bash-completion/completions/"
|
|
|
|
self.distribution.data_files.append((bashdir, instpaths))
|
2018-12-07 16:28:55 +08:00
|
|
|
|
|
|
|
|
2013-04-19 04:51:44 +08:00
|
|
|
def run(self):
|
|
|
|
self._make_bin_wrappers()
|
|
|
|
self._make_man_pages()
|
|
|
|
self._build_icons()
|
2018-12-07 16:28:55 +08:00
|
|
|
self._make_bash_completion_files()
|
2013-04-19 04:51:44 +08:00
|
|
|
|
|
|
|
self.run_command("build_i18n")
|
2015-11-03 06:06:46 +08:00
|
|
|
distutils.command.build.build.run(self)
|
2013-03-17 09:32:29 +08:00
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class my_egg_info(setuptools.command.install_egg_info.install_egg_info):
|
2013-03-17 09:32:29 +08:00
|
|
|
"""
|
|
|
|
Disable egg_info installation, seems pointless for a non-library
|
|
|
|
"""
|
|
|
|
def run(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class my_install(setuptools.command.install.install):
|
2013-04-11 05:25:39 +08:00
|
|
|
"""
|
|
|
|
Error if we weren't 'configure'd with the correct install prefix
|
|
|
|
"""
|
|
|
|
def finalize_options(self):
|
|
|
|
if self.prefix is None:
|
2021-05-23 03:34:41 +08:00
|
|
|
if BuildConfig.prefix != SYSPREFIX:
|
|
|
|
print("Using configured prefix=%s instead of SYSPREFIX=%s" % (
|
|
|
|
BuildConfig.prefix, SYSPREFIX))
|
2019-06-15 04:34:00 +08:00
|
|
|
self.prefix = BuildConfig.prefix
|
2015-09-24 07:29:13 +08:00
|
|
|
else:
|
2021-05-23 03:34:41 +08:00
|
|
|
print("Using SYSPREFIX=%s" % SYSPREFIX)
|
|
|
|
self.prefix = SYSPREFIX
|
2015-09-24 07:29:13 +08:00
|
|
|
|
2019-06-15 04:34:00 +08:00
|
|
|
elif self.prefix != BuildConfig.prefix:
|
2014-02-12 23:30:48 +08:00
|
|
|
print("Install prefix=%s doesn't match configure prefix=%s\n"
|
|
|
|
"Pass matching --prefix to 'setup.py configure'" %
|
2019-06-15 04:34:00 +08:00
|
|
|
(self.prefix, BuildConfig.prefix))
|
2013-04-11 05:25:39 +08:00
|
|
|
sys.exit(1)
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
setuptools.command.install.install.finalize_options(self)
|
2013-04-11 05:25:39 +08:00
|
|
|
|
2015-11-03 05:19:31 +08:00
|
|
|
def run(self):
|
|
|
|
if not self.distribution.no_update_icon_cache:
|
2021-05-23 03:34:41 +08:00
|
|
|
print("running gtk-update-icon-cache")
|
|
|
|
icon_path = os.path.join(self.install_data, "share/icons/hicolor")
|
2015-11-03 05:19:31 +08:00
|
|
|
self.spawn(["gtk-update-icon-cache", "-q", "-t", icon_path])
|
|
|
|
|
|
|
|
if not self.distribution.no_compile_schemas:
|
2021-05-23 03:34:41 +08:00
|
|
|
print("compiling gsettings schemas")
|
|
|
|
gschema_install = os.path.join(self.install_data,
|
2015-11-03 05:19:31 +08:00
|
|
|
"share/glib-2.0/schemas")
|
|
|
|
self.spawn(["glib-compile-schemas", gschema_install])
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
setuptools.command.install.install.run(self)
|
|
|
|
|
2015-11-03 05:19:31 +08:00
|
|
|
|
2013-03-17 09:32:29 +08:00
|
|
|
###################
|
|
|
|
# Custom commands #
|
|
|
|
###################
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class my_rpm(setuptools.Command):
|
2015-04-07 02:51:14 +08:00
|
|
|
user_options = []
|
2020-07-18 02:16:18 +08:00
|
|
|
description = "Build RPMs and output to the source directory."
|
2013-03-17 09:32:29 +08:00
|
|
|
|
|
|
|
def initialize_options(self):
|
2015-04-07 02:51:14 +08:00
|
|
|
pass
|
2013-03-17 09:32:29 +08:00
|
|
|
def finalize_options(self):
|
2015-04-07 02:51:14 +08:00
|
|
|
pass
|
2013-03-17 09:32:29 +08:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.run_command('sdist')
|
2020-07-18 02:16:18 +08:00
|
|
|
srcdir = os.path.dirname(__file__)
|
|
|
|
cmd = [
|
|
|
|
"rpmbuild", "-ta",
|
|
|
|
"--define", "_rpmdir %s" % srcdir,
|
|
|
|
"--define", "_srcrpmdir %s" % srcdir,
|
|
|
|
"--define", "_specdir /tmp",
|
|
|
|
"dist/virt-manager-%s.tar.gz" % BuildConfig.version,
|
|
|
|
]
|
|
|
|
subprocess.check_call(cmd)
|
2013-03-17 09:32:29 +08:00
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class configure(setuptools.Command):
|
2013-03-17 09:32:29 +08:00
|
|
|
user_options = [
|
2013-04-11 05:25:39 +08:00
|
|
|
("prefix=", None, "installation prefix"),
|
2013-03-17 09:32:29 +08:00
|
|
|
("default-graphics=", None,
|
2013-05-28 06:51:12 +08:00
|
|
|
"Default graphics type (spice or vnc) (default=spice)"),
|
2015-04-07 04:29:28 +08:00
|
|
|
("default-hvs=", None,
|
|
|
|
"Comma separated list of hypervisors shown in 'Open Connection' "
|
|
|
|
"wizard. (default=all hvs)"),
|
2013-03-17 09:32:29 +08:00
|
|
|
|
|
|
|
]
|
|
|
|
description = "Configure the build, similar to ./configure"
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def initialize_options(self):
|
2021-05-23 03:34:41 +08:00
|
|
|
self.prefix = SYSPREFIX
|
2013-10-03 06:50:01 +08:00
|
|
|
self.default_graphics = None
|
2015-04-07 04:29:28 +08:00
|
|
|
self.default_hvs = None
|
2013-03-17 09:32:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
template = ""
|
|
|
|
template += "[config]\n"
|
2013-04-11 05:25:39 +08:00
|
|
|
template += "prefix = %s\n" % self.prefix
|
2013-10-03 06:50:01 +08:00
|
|
|
if self.default_graphics is not None:
|
|
|
|
template += "default_graphics = %s\n" % self.default_graphics
|
2015-04-07 04:29:28 +08:00
|
|
|
if self.default_hvs is not None:
|
|
|
|
template += "default_hvs = %s\n" % self.default_hvs
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2019-06-15 04:34:00 +08:00
|
|
|
open(BuildConfig.cfgpath, "w").write(template)
|
|
|
|
print("Generated %s" % BuildConfig.cfgpath)
|
2013-03-17 09:32:29 +08:00
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class TestCommand(setuptools.Command):
|
2020-07-18 00:25:55 +08:00
|
|
|
user_options = []
|
|
|
|
description = "DEPRECATED: Use `pytest`. See CONTRIBUTING.md"
|
2013-03-18 06:18:22 +08:00
|
|
|
def finalize_options(self):
|
2020-07-18 00:25:55 +08:00
|
|
|
pass
|
2019-03-24 23:22:50 +08:00
|
|
|
def initialize_options(self):
|
2020-07-18 00:25:55 +08:00
|
|
|
pass
|
2018-02-21 01:33:57 +08:00
|
|
|
def run(self):
|
2020-07-18 00:25:55 +08:00
|
|
|
sys.exit("ERROR: `test` is deprecated. Call `pytest` instead. "
|
|
|
|
"See CONTRIBUTING.md for more info.")
|
2018-02-21 01:33:57 +08:00
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class CheckPylint(setuptools.Command):
|
2017-09-09 17:08:31 +08:00
|
|
|
user_options = [
|
|
|
|
("jobs=", "j", "use multiple processes to speed up Pylint"),
|
|
|
|
]
|
2017-07-24 16:26:47 +08:00
|
|
|
description = "Check code using pylint and pycodestyle"
|
2013-04-11 04:02:28 +08:00
|
|
|
|
|
|
|
def initialize_options(self):
|
2017-09-09 17:08:31 +08:00
|
|
|
self.jobs = None
|
|
|
|
|
2013-04-11 04:02:28 +08:00
|
|
|
def finalize_options(self):
|
2017-09-09 17:08:31 +08:00
|
|
|
if self.jobs:
|
|
|
|
self.jobs = int(self.jobs)
|
2013-04-11 04:02:28 +08:00
|
|
|
|
|
|
|
def run(self):
|
2018-03-02 16:01:21 +08:00
|
|
|
import pylint.lint
|
2018-03-02 16:01:25 +08:00
|
|
|
import pycodestyle
|
2018-03-02 16:01:21 +08:00
|
|
|
|
2021-04-07 06:28:18 +08:00
|
|
|
lintfiles = [
|
|
|
|
# Put this first so pylint learns what Gtk version we
|
|
|
|
# want to lint against
|
|
|
|
"virtManager/virtmanager.py",
|
2021-07-29 23:44:26 +08:00
|
|
|
"setup.py",
|
|
|
|
"tests",
|
|
|
|
"virtinst",
|
2021-04-07 06:28:18 +08:00
|
|
|
"virtManager"]
|
2020-01-29 03:31:28 +08:00
|
|
|
|
|
|
|
spellfiles = lintfiles[:]
|
|
|
|
spellfiles += list(glob.glob("*.md"))
|
2020-09-12 03:15:17 +08:00
|
|
|
spellfiles += list(glob.glob("man/*.rst"))
|
2020-01-29 03:31:28 +08:00
|
|
|
spellfiles += ["data/virt-manager.appdata.xml.in",
|
|
|
|
"data/virt-manager.desktop.in",
|
|
|
|
"data/org.virt-manager.virt-manager.gschema.xml",
|
2020-07-18 02:27:53 +08:00
|
|
|
"virt-manager.spec"]
|
2020-01-29 03:31:28 +08:00
|
|
|
spellfiles.remove("NEWS.md")
|
2013-04-11 04:02:28 +08:00
|
|
|
|
2019-05-16 19:19:17 +08:00
|
|
|
try:
|
|
|
|
import codespell_lib
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
print("running codespell")
|
|
|
|
codespell_lib._codespell.main(
|
2020-01-27 07:11:43 +08:00
|
|
|
'-I', 'tests/data/codespell_dict.txt',
|
2020-01-29 03:31:28 +08:00
|
|
|
'--skip', '*.pyc,*.iso,*.xml', *spellfiles)
|
2019-05-16 19:19:17 +08:00
|
|
|
except ImportError:
|
|
|
|
print("codespell is not installed. skipping...")
|
|
|
|
except Exception as e:
|
|
|
|
print("Error running codespell: %s" % e)
|
|
|
|
|
2013-04-11 04:02:28 +08:00
|
|
|
output_format = sys.stdout.isatty() and "colorized" or "text"
|
|
|
|
|
2017-07-24 16:26:47 +08:00
|
|
|
print("running pycodestyle")
|
2018-03-02 16:01:25 +08:00
|
|
|
style_guide = pycodestyle.StyleGuide(
|
2019-01-27 06:56:23 +08:00
|
|
|
config_file='setup.cfg',
|
2019-01-27 07:04:26 +08:00
|
|
|
format="pylint",
|
2020-01-29 03:31:28 +08:00
|
|
|
paths=lintfiles,
|
2018-03-02 16:01:25 +08:00
|
|
|
)
|
|
|
|
report = style_guide.check_files()
|
|
|
|
if style_guide.options.count:
|
|
|
|
sys.stderr.write(str(report.total_errors) + '\n')
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2017-05-06 02:16:59 +08:00
|
|
|
print("running pylint")
|
2018-03-02 16:01:21 +08:00
|
|
|
pylint_opts = [
|
2020-07-18 02:41:02 +08:00
|
|
|
"--rcfile", ".pylintrc",
|
2018-03-02 16:01:21 +08:00
|
|
|
"--output-format=%s" % output_format,
|
2018-10-25 20:37:42 +08:00
|
|
|
]
|
2017-09-09 17:08:31 +08:00
|
|
|
if self.jobs:
|
2018-03-02 16:01:21 +08:00
|
|
|
pylint_opts += ["--jobs=%d" % self.jobs]
|
|
|
|
|
2020-01-29 03:31:28 +08:00
|
|
|
pylint.lint.Run(lintfiles + pylint_opts)
|
2015-09-14 03:07:23 +08:00
|
|
|
|
2013-04-11 04:02:28 +08:00
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class VMMDistribution(setuptools.dist.Distribution):
|
|
|
|
global_options = setuptools.dist.Distribution.global_options + [
|
2015-11-03 05:19:31 +08:00
|
|
|
("no-update-icon-cache", None, "Don't run gtk-update-icon-cache"),
|
|
|
|
("no-compile-schemas", None, "Don't compile gsettings schemas"),
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.no_update_icon_cache = False
|
|
|
|
self.no_compile_schemas = False
|
2021-05-23 03:34:41 +08:00
|
|
|
setuptools.dist.Distribution.__init__(self, *args, **kwargs)
|
2015-11-03 05:19:31 +08:00
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
class ExtractMessages(setuptools.Command):
|
2020-07-08 22:54:13 +08:00
|
|
|
user_options = [
|
|
|
|
]
|
|
|
|
description = "Extract the translation messages"
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
bug_address = "https://github.com/virt-manager/virt-manager/issues"
|
2020-07-12 06:30:31 +08:00
|
|
|
potfile = "po/virt-manager.pot"
|
2020-07-08 22:54:13 +08:00
|
|
|
xgettext_args = [
|
|
|
|
"xgettext",
|
2020-07-12 06:46:33 +08:00
|
|
|
"--add-comments=translators",
|
2020-07-08 22:54:13 +08:00
|
|
|
"--msgid-bugs-address=" + bug_address,
|
|
|
|
"--package-name=virt-manager",
|
2020-07-12 06:30:31 +08:00
|
|
|
"--output=" + potfile,
|
|
|
|
"--sort-by-file",
|
|
|
|
"--join-existing",
|
2020-07-08 22:54:13 +08:00
|
|
|
]
|
|
|
|
|
2020-07-12 06:30:31 +08:00
|
|
|
# Truncate .pot file to ensure it exists
|
|
|
|
open(potfile, "w").write("")
|
|
|
|
|
2020-07-08 22:54:17 +08:00
|
|
|
# First extract the messages from the AppStream sources,
|
|
|
|
# creating the template
|
|
|
|
appdata_files = [f for sublist in _appdata_files for f in sublist[1]]
|
|
|
|
cmd = xgettext_args + appdata_files
|
|
|
|
self.spawn(cmd)
|
2020-07-08 22:54:13 +08:00
|
|
|
|
2020-07-08 22:54:16 +08:00
|
|
|
# Extract the messages from the desktop files
|
|
|
|
desktop_files = [f for sublist in _desktop_files for f in sublist[1]]
|
2020-07-12 06:30:31 +08:00
|
|
|
cmd = xgettext_args + ["--language=Desktop"] + desktop_files
|
2020-07-08 22:54:16 +08:00
|
|
|
self.spawn(cmd)
|
|
|
|
|
2020-07-08 22:54:13 +08:00
|
|
|
# Extract the messages from the Python sources
|
|
|
|
py_sources = list(Path("virtManager").rglob("*.py"))
|
|
|
|
py_sources += list(Path("virtinst").rglob("*.py"))
|
|
|
|
py_sources = [str(src) for src in py_sources]
|
2020-07-12 06:30:31 +08:00
|
|
|
cmd = xgettext_args + ["--language=Python"] + py_sources
|
2020-07-08 22:54:13 +08:00
|
|
|
self.spawn(cmd)
|
|
|
|
|
|
|
|
# Extract the messages from the Glade UI files
|
|
|
|
ui_files = list(Path(".").rglob("*.ui"))
|
|
|
|
ui_files = [str(src) for src in ui_files]
|
2020-07-12 06:30:31 +08:00
|
|
|
cmd = xgettext_args + ["--language=Glade"] + ui_files
|
2020-07-08 22:54:13 +08:00
|
|
|
self.spawn(cmd)
|
|
|
|
|
|
|
|
|
2021-05-23 03:34:41 +08:00
|
|
|
setuptools.setup(
|
2013-04-14 02:34:52 +08:00
|
|
|
name="virt-manager",
|
2019-06-17 23:14:39 +08:00
|
|
|
version=BuildConfig.version,
|
2013-04-14 02:34:52 +08:00
|
|
|
author="Cole Robinson",
|
|
|
|
author_email="virt-tools-list@redhat.com",
|
|
|
|
url="http://virt-manager.org",
|
|
|
|
license="GPLv2+",
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2013-03-18 07:32:19 +08:00
|
|
|
# These wrappers are generated in our custom build command
|
2013-04-14 02:34:52 +08:00
|
|
|
scripts=([
|
2013-03-18 07:32:19 +08:00
|
|
|
"build/virt-manager",
|
|
|
|
"build/virt-clone",
|
|
|
|
"build/virt-install",
|
2014-01-19 23:37:14 +08:00
|
|
|
"build/virt-xml"]),
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
data_files=[
|
2013-04-18 05:39:25 +08:00
|
|
|
("share/glib-2.0/schemas",
|
|
|
|
["data/org.virt-manager.virt-manager.gschema.xml"]),
|
2013-03-17 09:32:29 +08:00
|
|
|
("share/virt-manager/ui", glob.glob("ui/*.ui")),
|
|
|
|
|
2013-03-18 07:32:19 +08:00
|
|
|
("share/man/man1", [
|
|
|
|
"man/virt-manager.1",
|
|
|
|
"man/virt-install.1",
|
|
|
|
"man/virt-clone.1",
|
2014-01-19 23:37:14 +08:00
|
|
|
"man/virt-xml.1"
|
2013-03-18 07:32:19 +08:00
|
|
|
]),
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2019-06-17 13:27:08 +08:00
|
|
|
("share/virt-manager/virtManager", glob.glob("virtManager/*.py")),
|
|
|
|
("share/virt-manager/virtManager/details",
|
|
|
|
glob.glob("virtManager/details/*.py")),
|
|
|
|
("share/virt-manager/virtManager/device",
|
|
|
|
glob.glob("virtManager/device/*.py")),
|
|
|
|
("share/virt-manager/virtManager/lib",
|
|
|
|
glob.glob("virtManager/lib/*.py")),
|
|
|
|
("share/virt-manager/virtManager/object",
|
|
|
|
glob.glob("virtManager/object/*.py")),
|
2019-06-15 04:34:00 +08:00
|
|
|
("share/virt-manager/virtinst",
|
2019-06-17 13:27:08 +08:00
|
|
|
glob.glob("virtinst/*.py") + glob.glob("virtinst/build.cfg")),
|
|
|
|
("share/virt-manager/virtinst/devices",
|
|
|
|
glob.glob("virtinst/devices/*.py")),
|
|
|
|
("share/virt-manager/virtinst/domain",
|
|
|
|
glob.glob("virtinst/domain/*.py")),
|
|
|
|
("share/virt-manager/virtinst/install",
|
|
|
|
glob.glob("virtinst/install/*.py")),
|
2013-04-19 04:03:43 +08:00
|
|
|
],
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
cmdclass={
|
2013-03-17 09:32:29 +08:00
|
|
|
'build': my_build,
|
|
|
|
'build_i18n': my_build_i18n,
|
2013-04-11 05:25:39 +08:00
|
|
|
|
|
|
|
'install': my_install,
|
2013-03-17 09:32:29 +08:00
|
|
|
'install_egg_info': my_egg_info,
|
|
|
|
|
|
|
|
'configure': configure,
|
|
|
|
|
2013-04-11 04:02:28 +08:00
|
|
|
'pylint': CheckPylint,
|
2013-03-17 09:32:29 +08:00
|
|
|
'rpm': my_rpm,
|
2013-03-18 06:18:22 +08:00
|
|
|
'test': TestCommand,
|
2020-07-08 22:54:13 +08:00
|
|
|
|
|
|
|
'extract_messages': ExtractMessages,
|
2015-11-03 05:19:31 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
distclass=VMMDistribution,
|
2013-03-17 09:32:29 +08:00
|
|
|
)
|