2012-05-07 09:38:11 +02:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
|
|
|
# Copyright © 2012 Ejwa Software. All rights reserved.
|
|
|
|
#
|
|
|
|
# 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-03-11 00:23:50 +01:00
|
|
|
from outputable import Outputable
|
2012-05-07 09:38:11 +02:00
|
|
|
import os
|
2012-05-28 16:35:47 +02:00
|
|
|
import subprocess
|
2012-05-24 02:00:24 +02:00
|
|
|
import terminal
|
2012-11-03 01:26:49 +01:00
|
|
|
import textwrap
|
2012-05-07 09:38:11 +02:00
|
|
|
|
|
|
|
__checkout_missing__ = False
|
|
|
|
__missing_files__ = set()
|
|
|
|
|
2012-05-20 22:02:08 +02:00
|
|
|
def add(file_name):
|
|
|
|
if not os.path.exists(file_name):
|
2012-05-07 09:38:11 +02:00
|
|
|
if __checkout_missing__:
|
2012-11-03 01:25:53 +01:00
|
|
|
subprocess.call("git checkout \"" + file_name.strip() + "\"", shell=True)
|
2012-05-07 09:38:11 +02:00
|
|
|
else:
|
|
|
|
__missing_files__.add(file_name)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def set_checkout_missing(checkout):
|
|
|
|
global __checkout_missing__
|
|
|
|
__checkout_missing__ = checkout
|
|
|
|
|
2012-11-03 01:26:49 +01:00
|
|
|
__missing_info_text__ = ("The following files were missing in the repository and were therefore not "
|
|
|
|
"completely included in the statistical analysis. To include them, you can "
|
|
|
|
"either checkout manually using git or use the -c option in gitinspector")
|
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
class Missing(Outputable):
|
2013-03-14 00:47:40 +01:00
|
|
|
def output_html(self):
|
|
|
|
if __missing_files__:
|
|
|
|
missing_xml = "<div><div class=\"box\">"
|
|
|
|
missing_xml += "<p>" + __missing_info_text__ + ".</p>"
|
|
|
|
|
|
|
|
for missing in __missing_files__:
|
|
|
|
missing_xml += "<p class=\"error\">" + missing + "</p>"
|
|
|
|
|
|
|
|
missing_xml += "</div></div>"
|
|
|
|
print(missing_xml)
|
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
def output_text(self):
|
|
|
|
if __missing_files__:
|
|
|
|
print("\n" + textwrap.fill(__missing_info_text__ + ":", width=terminal.get_size()[0]))
|
2012-11-03 01:26:49 +01:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
for missing in __missing_files__:
|
|
|
|
(width, _) = terminal.get_size()
|
|
|
|
print("...%s" % missing[-width+3:] if len(missing) > width else missing)
|
2012-05-07 09:38:11 +02:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
def output_xml(self):
|
|
|
|
if __missing_files__:
|
|
|
|
message_xml = "\t\t<message>" + __missing_info_text__ + "</message>\n"
|
|
|
|
missing_xml = ""
|
2012-11-03 01:26:49 +01:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
for missing in __missing_files__:
|
|
|
|
missing_xml += "\t\t\t<file>" + missing + "</file>\n"
|
2012-11-03 01:26:49 +01:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
print("\t<missing>\n" + message_xml + "\t\t<files>\n" + missing_xml + "\t\t</files>\n\t</missing>")
|