/usr/share/pyshared/ninja_ide/core/cliparser.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 | # -*- 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/>.
from __future__ import absolute_import
import sys
import ninja_ide
try:
# For Python2
str = unicode # lint:ok
except NameError:
# We are in Python3
pass
usage = "$python ninja-ide.py <option, [option3...option n]>"
epilog = ("This program comes with ABSOLUTELY NO WARRANTY."
"This is free software, and you are welcome to redistribute "
"it under certain conditions; for details see LICENSE.txt.")
try:
import argparse
new_parser = True
def _get_parser():
global usage
global epilog
parser = argparse.ArgumentParser(description=usage, epilog=epilog)
parser.add_argument('file', metavar='file', type=str,
nargs='*', help='A file/s to edit', default=[])
parser.add_argument('-f', '--files', metavar='file', type=str,
nargs='+', help='A file/s to edit', default=[])
parser.add_argument('-l', '--lineno', metavar='lineno', type=int,
nargs='+',
help='Line number for the files to open',
default=[])
parser.add_argument('-p', '--project', metavar='project', type=str,
nargs='+', help='A project/s to edit', default=[])
parser.add_argument('--plugin',
metavar='plugin', type=str,
nargs='+', help='A plugin to load', default=[])
parser.add_argument('--loglevel', help="Level to use for logging, "
"one of 'DEBUG', 'INFO', 'WARNING', 'ERROR', "
"'CRITICAL'",
default=None, metavar="loglevel")
parser.add_argument('--logfile', help="A file path to log, special "
"words STDOUT or STDERR are accepted",
default=None, metavar="logfile")
return parser
except ImportError:
import optparse
new_parser = False
def _resolve_nargs(*opts):
final_nargs = 1
for opt in opts:
nargs = 0
try:
start = sys.argv.index(opt) + 1
for idx, arg in enumerate(sys.argv[start:]):
if str(arg).startswith("-"):
break
nargs += 1
return nargs
except ValueError:
nargs = 1
if final_nargs < nargs:
final_nargs = nargs
return final_nargs
def _get_parser(): # lint:ok
global usage
global epilog
parser = optparse.OptionParser(usage, version=ninja_ide.__version__,
epilog=epilog)
parser.add_option("-f", "--file",
type="string",
action="store",
dest="file",
default=[],
help="A file/s to edit",
nargs=_resolve_nargs("-f", "--file"))
parser.add_option("-p", "--project",
type="string",
action="store",
dest="project",
default=[],
help="A project/s to edit",
nargs=_resolve_nargs("-p", "--project"))
parser.add_option("-l", "--lineno",
type="int",
action="store",
dest="lineno",
default=[],
help="Line number for the files to open",
nargs=_resolve_nargs("-l", "--lineno"))
parser.add_option("--plugin",
type="string",
action="store",
dest="plugin",
default=[],
help="A plugin to load",
nargs=_resolve_nargs("--plugin"))
return parser
def parse():
filenames = None
projects_path = None
linenos = None
extra_plugins = None
log_level = None
log_file = None
try:
if new_parser:
opts = _get_parser().parse_args()
else:
opts = _get_parser().parse_args()[0]
filenames = opts.file \
if isinstance(opts.file, list) \
else [opts.file]
filenames += opts.files \
if hasattr(opts, 'files') \
else []
projects_path = opts.project \
if isinstance(opts.project, list) \
else [opts.project]
linenos = opts.lineno \
if hasattr(opts, 'lineno') \
else [opts.lineno]
extra_plugins = opts.plugin \
if isinstance(opts.plugin, list) \
else [opts.plugin]
log_level = opts.loglevel
log_file = opts.logfile
except Exception as reason:
print("Args couldn't be parsed.")
print(reason)
return (filenames, projects_path, extra_plugins, linenos, log_level,
log_file)
|