2012-05-04 11:40:30 +02:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
2014-01-08 03:51:02 +01:00
|
|
|
# Copyright © 2012-2014 Ejwa Software. All rights reserved.
|
2012-05-04 11:40:30 +02:00
|
|
|
#
|
|
|
|
# This file is part of gitinspector.
|
|
|
|
#
|
|
|
|
# gitinspector 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
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# gitinspector 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 gitinspector. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-05-25 16:42:29 +02:00
|
|
|
from __future__ import print_function
|
2013-06-25 16:37:18 +02:00
|
|
|
from __future__ import unicode_literals
|
2013-07-10 13:55:23 +02:00
|
|
|
from localization import N_
|
2013-03-11 00:23:50 +01:00
|
|
|
from outputable import Outputable
|
2012-05-16 05:04:55 +02:00
|
|
|
import terminal
|
2012-10-19 02:01:10 +02:00
|
|
|
import textwrap
|
2012-05-16 05:04:55 +02:00
|
|
|
|
2014-01-08 03:51:02 +01:00
|
|
|
DEFAULT_EXTENSIONS = ["java", "c", "cc", "cpp", "h", "hh", "hpp", "py", "glsl", "rb", "js", "sql"]
|
2013-07-09 12:40:59 +02:00
|
|
|
|
2013-07-14 00:07:36 +02:00
|
|
|
__extensions__ = DEFAULT_EXTENSIONS
|
2012-05-04 15:15:41 +02:00
|
|
|
__located_extensions__ = set()
|
2012-05-04 11:40:30 +02:00
|
|
|
|
|
|
|
def get():
|
2012-05-04 15:15:41 +02:00
|
|
|
return __extensions__
|
2012-05-04 11:40:30 +02:00
|
|
|
|
2012-05-04 15:15:41 +02:00
|
|
|
def define(string):
|
|
|
|
global __extensions__
|
|
|
|
__extensions__ = string.split(",")
|
2012-05-04 11:40:30 +02:00
|
|
|
|
|
|
|
def add_located(string):
|
|
|
|
if len(string) > 0:
|
2012-05-04 15:15:41 +02:00
|
|
|
__located_extensions__.add(string)
|
2012-05-04 11:40:30 +02:00
|
|
|
|
2013-07-10 13:55:23 +02:00
|
|
|
EXTENSIONS_INFO_TEXT = N_("The extensions below were found in the repository history")
|
|
|
|
EXTENSIONS_MARKED_TEXT = N_("(extensions used during statistical analysis are marked)")
|
2012-10-19 02:01:10 +02:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
class Extensions(Outputable):
|
2013-03-11 09:59:13 +01:00
|
|
|
def output_html(self):
|
|
|
|
if __located_extensions__:
|
|
|
|
extensions_xml = "<div><div class=\"box\">"
|
2013-07-10 05:24:18 +02:00
|
|
|
extensions_xml += "<p>{0} {1}.</p><p>".format(_(EXTENSIONS_INFO_TEXT), _(EXTENSIONS_MARKED_TEXT))
|
2013-03-11 09:59:13 +01:00
|
|
|
|
|
|
|
for i in __located_extensions__:
|
|
|
|
if i in __extensions__:
|
|
|
|
extensions_xml += "<strong>" + i + "</strong>"
|
|
|
|
else:
|
|
|
|
extensions_xml += i
|
2013-05-08 18:26:25 +02:00
|
|
|
extensions_xml += " "
|
2013-03-11 09:59:13 +01:00
|
|
|
|
|
|
|
extensions_xml += "</p></div></div>"
|
|
|
|
print(extensions_xml)
|
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
def output_text(self):
|
|
|
|
if __located_extensions__:
|
2013-07-10 05:24:18 +02:00
|
|
|
print("\n" + textwrap.fill("{0} {1}:".format(_(EXTENSIONS_INFO_TEXT), _(EXTENSIONS_MARKED_TEXT)),
|
2013-03-11 00:23:50 +01:00
|
|
|
width=terminal.get_size()[0]))
|
2012-10-19 02:01:10 +02:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
for i in __located_extensions__:
|
|
|
|
if i in __extensions__:
|
|
|
|
print("[" + terminal.__bold__ + i + terminal.__normal__ + "]", end=" ")
|
|
|
|
else:
|
|
|
|
print (i, end=" ")
|
|
|
|
print("")
|
2012-05-16 05:04:55 +02:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
def output_xml(self):
|
|
|
|
if __located_extensions__:
|
2013-07-10 05:24:18 +02:00
|
|
|
message_xml = "\t\t<message>" + _(EXTENSIONS_INFO_TEXT) + "</message>\n"
|
2013-03-11 00:23:50 +01:00
|
|
|
used_extensions_xml = ""
|
|
|
|
unused_extensions_xml = ""
|
2012-10-19 02:01:10 +02:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
for i in __located_extensions__:
|
|
|
|
if i in __extensions__:
|
|
|
|
used_extensions_xml += "\t\t\t<extension>" + i + "</extension>\n"
|
|
|
|
else:
|
|
|
|
unused_extensions_xml += "\t\t\t<extension>" + i + "</extension>\n"
|
2012-10-19 02:01:10 +02:00
|
|
|
|
2013-03-25 03:21:40 +01:00
|
|
|
print("\t<extensions>\n" + message_xml + "\t\t<used>\n" + used_extensions_xml + "\t\t</used>\n" +
|
2013-03-11 00:23:50 +01:00
|
|
|
"\t\t<unused>\n" + unused_extensions_xml + "\t\t</unused>\n" + "\t</extensions>")
|