This file is indexed.

/usr/share/pyshared/ninja_ide/tools/json_manager.py is in ninja-ide 2.3-2.

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
# -*- coding: utf-8 -*-
#
# This file is part of NINJA-IDE (http://ninja-ide.org).
#
# NINJA-IDE is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# NINJA-IDE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NINJA-IDE; If not, see <http://www.gnu.org/licenses/>.

import os
import json

from ninja_ide import resources
from ninja_ide.core import settings

from ninja_ide.tools.logger import NinjaLogger

logger = NinjaLogger('ninja_ide.tools.json_manager')


def parse(descriptor):
    try:
        return json.load(descriptor)
    except:
        logger.error("The file couldn't be parsed'")
        logger.error(descriptor)
    return {}


def read_json(arg_):

    structure = dict()
    fileName = None

    if os.path.isdir(arg_):
        path = arg_
        json_file = get_ninja_json_file(path)
        fileName = os.path.join(path, json_file)

    if os.path.isfile(arg_):
        fileName = arg_

    if fileName is None:
        return structure

    with open(fileName, 'r') as fp:
        try:
            structure = json.load(fp)
        except Exception as exc:
            logger.error('Error reading Ninja File %s' % fileName)
            logger.error(exc)
            return structure

    return structure


def read_json_from_stream(stream):
    structure = json.load(stream)
    return structure


def write_json(structure, filename, indent=2):
    with open(filename, 'w') as fp:
        json.dump(structure, fp, indent)


def load_syntax():

    empty = dict()
    files = os.listdir(resources.SYNTAX_FILES)

    for f in files:

        if not f.endswith('.json'):
            continue

        fname = os.path.join(resources.SYNTAX_FILES, f)
        structure = read_json(fname)
        if structure == empty:
            continue

        name = f[:-5]
        settings.SYNTAX[name] = structure
        for ext in structure.get('extension'):
            if ext is not None:
                settings.EXTENSIONS[ext] = name


def create_ninja_project(path, project, structure):
    projectName = project.lower().strip().replace(' ', '_') + '.nja'
    fileName = os.path.join(path, projectName)
    with open(fileName, mode='w') as fp:
        json.dump(structure, fp, indent=2)


def get_ninja_file(path, extension, only_first=False):
    files = os.listdir(path)
    if not extension.startswith('.'):
        extension = '.'.join(extension)

    nja = list([y for y in files if y.endswith(extension)])

    if only_first:
        nja = nja[0] if nja else None

    return nja if nja else []


def get_ninja_json_file(path):

    extension = '.json'
    return get_ninja_file(path, extension, only_first=True)


def get_ninja_plugin_file(path):

    extension = '.plugin'
    return get_ninja_file(path, extension, only_first=True)


def get_ninja_project_file(path):

    extension = '.nja'
    return get_ninja_file(path, extension, only_first=True)


def get_ninja_editor_skins_files(path):

    extension = '.color'
    return get_ninja_file(path, extension)


def read_ninja_project(path):

    empty = dict()
    project_file = get_ninja_project_file(path)

    if not project_file:
        return empty

    return read_json(os.path.join(path, project_file))


def read_ninja_plugin(path):

    empty = dict()
    plugin_file = get_ninja_plugin_file(path)

    if plugin_file is None:
        return empty

    return read_json(os.path.join(path, plugin_file))


def load_editor_skins():

    skins = dict()
    files = get_ninja_editor_skins_files(resources.EDITOR_SKINS)

    for fname in files:
        file_name = os.path.join(resources.EDITOR_SKINS, fname)
        structure = read_json(file_name)
        if structure is None:
            continue
        name = fname[:-6]
        skins[name] = structure

    return skins


def save_editor_skins(filename, scheme):

    with open(filename, 'w') as fp:
        try:
            json.dump(scheme, fp, indent=2)
        except Exception as exc:
            logger.error('Error writing file %s' % filename)
            logger.error(exc)