Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
common.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# Copyright 2015 The PDFium Authors
3
# Use of this source code is governed by a BSD-style license that can be
4
# found in the LICENSE file.
5
6
import
datetime
7
import
glob
8
import
os
9
import
re
10
import
subprocess
11
import
sys
12
13
import
pdfium_root
14
15
16
def
os_name
():
17
if
sys.platform.startswith(
'linux'
):
18
return
'linux'
19
if
sys.platform.startswith(
'win'
):
20
return
'win'
21
if
sys.platform.startswith(
'darwin'
):
22
return
'mac'
23
raise
Exception(
'Confused, can not determine OS, aborting.'
)
24
25
26
def
RunCommandPropagateErr
(cmd,
27
stdout_has_errors=False,
28
exit_status_on_error=None):
29
"""Run a command as a subprocess.
30
31
Errors in that subprocess are printed out if it returns an error exit code.
32
33
Args:
34
cmd: Command to run as a list of strings.
35
stdout_has_errors: Whether to print stdout instead of stderr on an error
36
exit.
37
exit_status_on_error: If specified, upon an error in the subprocess the
38
caller script exits immediately with the given status.
39
"""
40
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41
output, err = p.communicate()
42
43
if
p.returncode:
44
PrintErr
(
'\nError when invoking "%s"'
%
' '
.join(cmd))
45
if
stdout_has_errors:
46
PrintErr
(output)
47
48
PrintErr
(err)
49
50
if
exit_status_on_error
is
not
None
:
51
sys.exit(exit_status_on_error)
52
53
return
None
54
55
return
output
56
57
58
class
DirectoryFinder
:
59
'''A class for finding directories and paths under either a standalone
60
checkout or a chromium checkout of PDFium.'''
61
62
def
__init__
(self, build_location):
63
# `build_location` is typically "out/Debug" or "out/Release".
64
root_finder =
pdfium_root.RootDirectoryFinder
()
65
self.
testing_dir
= os.path.join(root_finder.pdfium_root,
'testing'
)
66
self.
my_dir
= os.path.join(self.
testing_dir
,
'tools'
)
67
self.
pdfium_dir
= root_finder.pdfium_root
68
self.
base_dir
= root_finder.source_root
69
self.
build_dir
= os.path.join(self.
base_dir
, build_location)
70
self.
os_name
=
os_name
()
71
72
def
ExecutablePath
(self, name):
73
'''Finds compiled binaries under the build path.'''
74
result = os.path.join(self.
build_dir
, name)
75
if
self.
os_name
==
'win'
:
76
result = result +
'.exe'
77
return
result
78
79
def
ScriptPath
(self, name):
80
'''Finds other scripts in the same directory as this one.'''
81
return
os.path.join(self.
my_dir
, name)
82
83
def
WorkingDir
(self, other_components=''):
84
'''Places generated files under the build directory, not source dir.'''
85
result = os.path.join(self.
build_dir
,
'gen'
,
'pdfium'
)
86
if
other_components:
87
result = os.path.join(result, other_components)
88
return
result
89
90
def
TestingDir
(self, other_components=''):
91
'''Finds test files somewhere under the testing directory.'''
92
result = self.
testing_dir
93
if
other_components:
94
result = os.path.join(result, other_components)
95
return
result
96
97
def
ThirdPartyFontsDir
(self):
98
'''Finds directory with the test fonts.'''
99
return
os.path.join(self.
base_dir
,
'third_party'
,
'test_fonts'
)
100
101
102
def
GetBooleanGnArg
(arg_name, build_dir, verbose=False):
103
'''Extract the value of a boolean flag in args.gn'''
104
cwd = os.getcwd()
105
os.chdir(build_dir)
106
gn_args_output = subprocess.check_output(
107
[
'gn'
,
'args'
,
'.'
,
'--list=%s'
% arg_name,
'--short'
]).
decode
(
'utf8'
)
108
os.chdir(cwd)
109
arg_match_output = re.search(
'%s = (.*)'
% arg_name, gn_args_output).group(1)
110
if
verbose:
111
print
(
112
"Found '%s' for value of %s"
% (arg_match_output, arg_name),
113
file=sys.stderr)
114
return
arg_match_output ==
'true'
115
116
117
def
PrintWithTime
(s):
118
"""Prints s prepended by a timestamp."""
119
print
(
'[%s] %s'
% (datetime.datetime.now().strftime(
"%Y%m%d %H:%M:%S"
), s))
120
121
122
def
PrintErr
(s):
123
"""Prints s to stderr."""
124
print
(s, file=sys.stderr)
testing.tools.common.DirectoryFinder
Definition
common.py:58
testing.tools.common.DirectoryFinder.ScriptPath
ScriptPath(self, name)
Definition
common.py:79
testing.tools.common.DirectoryFinder.TestingDir
TestingDir(self, other_components='')
Definition
common.py:90
testing.tools.common.DirectoryFinder.ThirdPartyFontsDir
ThirdPartyFontsDir(self)
Definition
common.py:97
testing.tools.common.DirectoryFinder.WorkingDir
WorkingDir(self, other_components='')
Definition
common.py:83
testing.tools.common.DirectoryFinder.base_dir
base_dir
Definition
common.py:68
testing.tools.common.DirectoryFinder.my_dir
my_dir
Definition
common.py:66
testing.tools.common.DirectoryFinder.os_name
str os_name
Definition
common.py:70
testing.tools.common.DirectoryFinder.build_dir
build_dir
Definition
common.py:69
testing.tools.common.DirectoryFinder.pdfium_dir
pdfium_dir
Definition
common.py:67
testing.tools.common.DirectoryFinder.__init__
__init__(self, build_location)
Definition
common.py:62
testing.tools.common.DirectoryFinder.testing_dir
testing_dir
Definition
common.py:65
testing.tools.common.DirectoryFinder.ExecutablePath
ExecutablePath(self, name)
Definition
common.py:72
testing.tools.pdfium_root.RootDirectoryFinder
Definition
pdfium_root.py:10
testing.tools.common.GetBooleanGnArg
GetBooleanGnArg(arg_name, build_dir, verbose=False)
Definition
common.py:102
testing.tools.common.RunCommandPropagateErr
RunCommandPropagateErr(cmd, stdout_has_errors=False, exit_status_on_error=None)
Definition
common.py:28
testing.tools.common.os_name
os_name()
Definition
common.py:16
testing.tools.common.PrintWithTime
PrintWithTime(s)
Definition
common.py:117
testing.tools.common.PrintErr
PrintErr(s)
Definition
common.py:122
print
QDebug print(QDebug debug, QSslError::SslError error)
Definition
qsslerror.cpp:344
decode
#define decode(x)
Definition
qurlquery.cpp:211
qtwebengine
src
3rdparty
chromium
third_party
pdfium
testing
tools
common.py
Generated on
for Qt by
1.18.0