-
Notifications
You must be signed in to change notification settings - Fork 219
/
appdata.py
99 lines (76 loc) · 3.02 KB
/
appdata.py
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
# -*- coding: utf-8 -*-
# Copyright 2013 Christoph Reiter
#
# This software and accompanying documentation, if any, may be freely
# used, distributed, and/or modified, in any form and for any purpose,
# as long as this notice is preserved. There is no warranty, either
# express or implied, for this software.
"""
AppData Specification: http://people.freedesktop.org/~hughsient/appdata/
"""
import os
from distutils.dep_util import newer
from distutils.core import Command
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 intltool.
"""
description = "build .appdata.xml files"
user_options = []
build_base = None
def initialize_options(self):
pass
def finalize_options(self):
self.appdata = self.distribution.appdata
self.po_directory = self.distribution.po_directory
self.set_undefined_options('build', ('build_base', 'build_base'))
def run(self):
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):
self.spawn(["intltool-merge",
"-x", self.po_directory,
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 = []
install_dir = None
skip_build = None
appdata = None
build_base = None
def initialize_options(self):
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"]