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
|
# Copyright 2013-2016 Christoph Reiter
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
AppData Specification: https://www.freedesktop.org/software/appstream/docs/
"""
import os
from distutils.dep_util import newer
from .util import Command
from .gettextutil import merge_file
class build_appdata(Command):
"""Build .appdata.xml files
Move .appdata.xml files to the appropriate location in the build tree.
If there is a .appdata.xml.in file, process it with gettext.
"""
description = "build .appdata.xml files"
user_options = []
def initialize_options(self):
self.build_base = None
self.appdata = None
self.po_build_dir = None
def finalize_options(self):
self.appdata = self.distribution.appdata
self.set_undefined_options('build', ('build_base', 'build_base'))
self.set_undefined_options(
'build_po', ('po_build_dir', 'po_build_dir'))
def run(self):
self.run_command("build_po")
basepath = os.path.join(self.build_base, 'share', 'appdata')
self.mkpath(basepath)
for appdata in self.appdata:
if os.path.exists(appdata + ".in"):
fullpath = os.path.join(basepath, os.path.basename(appdata))
if newer(appdata + ".in", fullpath):
merge_file(self.po_build_dir, "xml",
appdata + ".in", fullpath)
else:
self.copy_file(appdata, os.path.join(basepath, appdata))
class install_appdata(Command):
"""Install .appdata.xml files
Install any .appdata.xml files from the build tree to their final
location, under $prefix/share/appdata.
"""
description = "install .appdata.xml files"
user_options = []
def initialize_options(self):
self.install_dir = None
self.skip_build = None
self.appdata = None
self.build_base = None
self.outfiles = []
def finalize_options(self):
self.set_undefined_options('build', ('build_base', 'build_base'))
self.set_undefined_options(
'install',
('install_data', 'install_dir'),
('skip_build', 'skip_build'))
self.set_undefined_options(
'build_appdata', ('appdata', 'appdata'))
def get_outputs(self):
return self.outfiles
def run(self):
if not self.skip_build:
self.run_command('build_appdata')
basepath = os.path.join(self.install_dir, 'share', 'appdata')
srcpath = os.path.join(self.build_base, 'share', 'appdata')
out = self.mkpath(basepath)
self.outfiles.extend(out or [])
for appdata in self.appdata:
appdata = os.path.basename(appdata)
fullsrc = os.path.join(srcpath, appdata)
fullpath = os.path.join(basepath, appdata)
(out, _) = self.copy_file(fullsrc, fullpath)
self.outfiles.append(out)
__all__ = ["build_appdata", "install_appdata"]
|