This file is indexed.

/usr/lib/python2.7/dist-packages/pygccxml/parser/config.py is in python-pygccxml 1.8.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# Copyright 2014-2016 Insight Software Consortium.
# Copyright 2004-2008 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

"""
Defines C++ parser configuration classes.

"""

import os
import copy
import platform
import subprocess
import warnings
try:
    from configparser import ConfigParser
except ImportError:
    from ConfigParser import SafeConfigParser as ConfigParser
from .. import utils


class parser_configuration_t(object):

    """
    C++ parser configuration holder

    This class serves as a base class for the parameters that can be used
    to customize the call to a C++ parser.

    This class also allows users to work with relative files paths. In this
    case files are searched in the following order:

       1. current directory
       2. working directory
       3. additional include paths specified by the user

    """

    def __init__(
            self,
            working_directory='.',
            include_paths=None,
            define_symbols=None,
            undefine_symbols=None,
            cflags="",
            compiler=None,
            xml_generator="castxml",
            keep_xml=False,
            compiler_path=None,
            flags=None):

        object.__init__(self)
        self.__working_directory = working_directory

        if not include_paths:
            include_paths = []
        self.__include_paths = include_paths

        if not define_symbols:
            define_symbols = []
        self.__define_symbols = define_symbols

        if not undefine_symbols:
            undefine_symbols = []
        self.__undefine_symbols = undefine_symbols

        self.__cflags = cflags

        self.__compiler = compiler

        self.__xml_generator = xml_generator

        self.__keep_xml = keep_xml

        if flags is None:
            flags = []
        self.__flags = flags

        # If no compiler path was set and we are using castxml, set the path
        self.__compiler_path = create_compiler_path(
            xml_generator, compiler_path)

    def clone(self):
        raise NotImplementedError(self.__class__.__name__)

    @property
    def working_directory(self):
        return self.__working_directory

    @working_directory.setter
    def working_directory(self, working_dir):
        self.__working_directory = working_dir

    @property
    def include_paths(self):
        """list of include paths to look for header files"""
        return self.__include_paths

    @property
    def define_symbols(self):
        """list of "define" directives """
        return self.__define_symbols

    @property
    def undefine_symbols(self):
        """list of "undefine" directives """
        return self.__undefine_symbols

    @property
    def compiler(self):
        """get compiler name to simulate"""
        return self.__compiler

    @compiler.setter
    def compiler(self, compiler):
        """set compiler name to simulate"""
        self.__compiler = compiler

    @property
    def xml_generator(self):
        """get xml_generator (gccxml or castxml)"""
        return self.__xml_generator

    @xml_generator.setter
    def xml_generator(self, xml_generator):
        """set xml_generator (gccxml or castxml)"""
        if "real" in xml_generator:
            # Support for gccxml.real from newer gccxml package
            # Can be removed once gccxml support is dropped.
            xml_generator = "gccxml"
        self.__xml_generator = xml_generator

    @property
    def keep_xml(self):
        """Are xml files kept after errors."""
        return self.__keep_xml

    @keep_xml.setter
    def keep_xml(self, keep_xml):
        """Set if xml files kept after errors."""
        self.__keep_xml = keep_xml

    @property
    def flags(self):
        """Optional flags for pygccxml."""
        return self.__flags

    @flags.setter
    def flags(self, flags):
        """Optional flags for pygccxml."""
        if flags is None:
            flags = []
        self.__flags = flags

    @property
    def compiler_path(self):
        """Get the path for the compiler."""
        return self.__compiler_path

    @compiler_path.setter
    def compiler_path(self, compiler_path):
        """Set the path for the compiler."""
        self.__compiler_path = compiler_path

    @property
    def cflags(self):
        """additional flags to pass to compiler"""
        return self.__cflags

    @cflags.setter
    def cflags(self, val):
        self.__cflags = val

    def append_cflags(self, val):
        self.__cflags = self.__cflags + ' ' + val

    def __ensure_dir_exists(self, dir_path, meaning):
        if os.path.isdir(dir_path):
            return
        if os.path.exists(self.working_directory):
            raise RuntimeError(
                '%s("%s") does not exist!' % (meaning, dir_path))
        else:
            raise RuntimeError(
                '%s("%s") should be "directory", not a file.' %
                (meaning, dir_path))

    def raise_on_wrong_settings(self):
        """validates the configuration settings and raises RuntimeError on
        error"""
        self.__ensure_dir_exists(self.working_directory, 'working directory')
        for idir in self.include_paths:
            self.__ensure_dir_exists(idir, 'include directory')


class xml_generator_configuration_t(parser_configuration_t):
    """
    Configuration object to collect parameters for invoking gccxml or castxml.

    This class serves as a container for the parameters that can be used
    to customize the call to gccxml or castxml.

    """

    def __init__(
            self,
            gccxml_path='',
            xml_generator_path='',
            working_directory='.',
            include_paths=None,
            define_symbols=None,
            undefine_symbols=None,
            start_with_declarations=None,
            ignore_gccxml_output=False,
            cflags="",
            compiler=None,
            xml_generator="castxml",
            keep_xml=False,
            compiler_path=None,
            flags=None):

        parser_configuration_t.__init__(
            self,
            working_directory=working_directory,
            include_paths=include_paths,
            define_symbols=define_symbols,
            undefine_symbols=undefine_symbols,
            cflags=cflags,
            compiler=compiler,
            xml_generator=xml_generator,
            keep_xml=keep_xml,
            compiler_path=compiler_path,
            flags=flags)

        if gccxml_path != '':
            self.__gccxml_path = gccxml_path
        self.__xml_generator_path = xml_generator_path

        if not start_with_declarations:
            start_with_declarations = []
        self.__start_with_declarations = start_with_declarations

        self.__ignore_gccxml_output = ignore_gccxml_output

    def clone(self):
        return copy.deepcopy(self)

    @property
    def xml_generator_path(self):
        """
        XML generator binary location

        """

        return self.__xml_generator_path

    @xml_generator_path.setter
    def xml_generator_path(self, new_path):
        self.__xml_generator_path = new_path

    @property
    def start_with_declarations(self):
        """list of declarations gccxml should start with, when it dumps
        declaration tree"""
        return self.__start_with_declarations

    @property
    def ignore_gccxml_output(self):
        """set this property to True, if you want pygccxml to ignore any
            error warning that comes from gccxml"""
        return self.__ignore_gccxml_output

    @ignore_gccxml_output.setter
    def ignore_gccxml_output(self, val=True):
        self.__ignore_gccxml_output = val

    def raise_on_wrong_settings(self):
        super(xml_generator_configuration_t, self).raise_on_wrong_settings()
        if os.path.isfile(self.xml_generator_path):
            return
        if os.name == 'nt':
            gccxml_name = 'gccxml' + '.exe'
            environment_var_delimiter = ';'
        elif os.name == 'posix':
            gccxml_name = 'gccxml'
            environment_var_delimiter = ':'
        else:
            raise RuntimeError(
                'unable to find out location of the xml generator')
        may_be_gccxml = os.path.join(self.xml_generator_path, gccxml_name)
        if os.path.isfile(may_be_gccxml):
            self.xml_generator_path = may_be_gccxml
        else:
            for path in os.environ['PATH'].split(environment_var_delimiter):
                xml_generator_path = os.path.join(path, gccxml_name)
                if os.path.isfile(xml_generator_path):
                    self.xml_generator_path = xml_generator_path
                    break
            else:
                msg = (
                    'xml_generator_path("%s") should exists or to be a ' +
                    'valid file name.') % self.xml_generator_path
                raise RuntimeError(msg)


class _StringDeprecationWrapper(str):
    """
    A small wrapper class useful when deprecation strings.

    This class is not part of the public API.

    """

    def __new__(cls, content):
        cls.content = content
        return str.__new__(cls, content)

    def __str__(self):
        warnings.warn(
            "gccxml_configuration_example is deprecated. There is an " +
            "example file here if you need one: unittests/xml_generator.cfg"
            "This will be removed in version 1.9.0",
            DeprecationWarning)
        return self.content


gccxml_configuration_example = _StringDeprecationWrapper(
    """
[gccxml]
#path to gccxml executable file - optional, if not provided, os.environ['PATH']
#variable is used to find it
gccxml_path=(deprecated)
xml_generator_path=
#gccxml working directory - optional, could be set to your source code
directory
working_directory=
#additional include directories, separated by ';'
include_paths=
#gccxml has a nice algorithms, which selects what C++ compiler to emulate.
#You can explicitly set what compiler it should emulate.
#Valid options are: g++, msvc6, msvc7, msvc71, msvc8, cl.
compiler=
# gccxml or castxml
xml_generator=
# Do we keep xml files or not after errors
keep_xml=
# Set the path to the compiler
compiler_path=
""")


def load_xml_generator_configuration(configuration, **defaults):
    """
    Loads CastXML or GCC-XML configuration.

    Args:
         configuration (string|configparser.ConfigParser): can be
             a string (file path to a configuration file) or
             instance of :class:`configparser.ConfigParser`.
         defaults: can be used to override single configuration values.

    Returns:
        :class:`.xml_generator_configuration_t`: a configuration object


    The file passed needs to be in a format that can be parsed by
    :class:`configparser.ConfigParser`.

    An example configuration file skeleton can be found
    `here <https://github.com/gccxml/pygccxml/blob/develop/
    unittests/xml_generator.cfg>`_.

    """
    parser = configuration
    if utils.is_str(configuration):
        parser = ConfigParser()
        parser.read(configuration)

    # Create a new empty configuration
    cfg = xml_generator_configuration_t()

    values = defaults
    if not values:
        values = {}

    if parser.has_section('gccxml'):
        warnings.warn(
            "The [gccxml] section in your configuration file is deprecated. "
            "Please use [xml_generator] instead. This will no more work with "
            "version 1.9.0")
        for name, value in parser.items('gccxml'):
            if value.strip():
                values[name] = value

    if parser.has_section('xml_generator'):
        for name, value in parser.items('xml_generator'):
            if value.strip():
                values[name] = value

    for name, value in values.items():
        if isinstance(value, str):
            value = value.strip()
        if name == 'gccxml_path':
            cfg.gccxml_path = value
        if name == 'xml_generator_path':
            cfg.xml_generator_path = value
        elif name == 'working_directory':
            cfg.working_directory = value
        elif name == 'include_paths':
            for p in value.split(';'):
                p = p.strip()
                if p:
                    cfg.include_paths.append(p)
        elif name == 'compiler':
            cfg.compiler = value
        elif name == 'xml_generator':
            cfg.xml_generator = value
        elif name == 'keep_xml':
            cfg.keep_xml = value
        elif name == 'cflags':
            cfg.cflags = value
        elif name == 'flags':
            cfg.flags = value
        elif name == 'compiler_path':
            cfg.compiler_path = value
        else:
            print('\n%s entry was ignored' % name)

    # If no compiler path was set and we are using castxml, set the path
    # Here we overwrite the default configuration done in the cfg because
    # the xml_generator was set through the setter after the creation of a new
    # emppty configuration object.
    cfg.compiler_path = create_compiler_path(
        cfg.xml_generator, cfg.compiler_path)

    return cfg


def create_compiler_path(xml_generator, compiler_path):
    """
    Try to guess a path for the compiler.

    If you want ot use a specific compiler, please provide the compiler
    path manually, as the guess may not be what you are expecting.
    Providing the path can be done by passing it as an argument (compiler_path)
    to the xml_generator_configuration_t() or by defining it in your pygccxml
    configuration file.

    """

    if xml_generator == 'castxml' and compiler_path is None:
        if platform.system() == 'Windows':
            # Look for msvc
            p = subprocess.Popen(
                ['where', 'cl'],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            compiler_path = p.stdout.read().decode("utf-8").rstrip()
            p.stdout.close()
            p.stderr.close()
            # No mscv found; look for mingw
            if compiler_path == '':
                p = subprocess.Popen(
                    ['where', 'mingw'],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
                compiler_path = p.stdout.read().decode("utf-8").rstrip()
                p.stdout.close()
                p.stderr.close()
        else:
            # OS X or Linux
            # Look for clang first, then gcc
            p = subprocess.Popen(
                ['which', 'clang++'],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            compiler_path = p.stdout.read().decode("utf-8").rstrip()
            p.stdout.close()
            p.stderr.close()
            # No clang found; use gcc
            if compiler_path == '':
                p = subprocess.Popen(
                    ['which', 'c++'],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
                compiler_path = p.stdout.read().decode("utf-8").rstrip()
                p.stdout.close()
                p.stderr.close()

        if compiler_path == "":
            compiler_path = None

    return compiler_path


gccxml_configuration_t = utils.utils.DeprecationWrapper(
    xml_generator_configuration_t,
    "gccxml_configuration_t",
    "xml_generator_configuration_t",
    "1.9.0")
load_gccxml_configuration = utils.utils.DeprecationWrapper(
    load_xml_generator_configuration,
    "load_gccxml_configuration",
    "load_xml_generator_configuration",
    "1.9.0")


if __name__ == '__main__':
    print(load_xml_generator_configuration('xml_generator.cfg').__dict__)