move LOCALE to config.py

Reviewed By: jeremydubreil

Differential Revision: D2642346

fb-gh-sync-id: 43a3b00
master
Jules Villard 9 years ago committed by facebook-github-bot-7
parent 2ec2858b66
commit 0490e739b0

@ -70,7 +70,7 @@ def split_args_to_parse():
sys.argv.index(CMD_MARKER) if CMD_MARKER in sys.argv else len(sys.argv) sys.argv.index(CMD_MARKER) if CMD_MARKER in sys.argv else len(sys.argv)
cmd_raw = sys.argv[dd_index + 1:] cmd_raw = sys.argv[dd_index + 1:]
return (sys.argv[1:dd_index], return (sys.argv[1:dd_index],
[arg.decode(utils.LOCALE) for arg in cmd_raw]) [arg.decode(config.LOCALE) for arg in cmd_raw])
def create_argparser(parents=[]): def create_argparser(parents=[]):
@ -171,7 +171,7 @@ def main():
utils.JSON_REPORT_FILENAME) utils.JSON_REPORT_FILENAME)
try: try:
with codecs.open(bugs_filename, 'r', with codecs.open(bugs_filename, 'r',
encoding=utils.LOCALE) as bugs_file: encoding=config.LOCALE) as bugs_file:
bugs = json.load(bugs_file) bugs = json.load(bugs_file)
if len(bugs) > 0: if len(bugs) > 0:
sys.exit(config.BUG_FOUND_ERROR_CODE) sys.exit(config.BUG_FOUND_ERROR_CODE)

@ -21,7 +21,7 @@ import shutil
import subprocess import subprocess
import sys import sys
from inferlib import analyze, source, utils from inferlib import analyze, config, source, utils
HTML_REPORT_DIR = 'report.html' HTML_REPORT_DIR = 'report.html'
TRACES_REPORT_DIR = 'traces' TRACES_REPORT_DIR = 'traces'
@ -357,14 +357,14 @@ def generate_html_report(args, reports):
for bug in sel: for bug in sel:
bug_trace_path = path_of_bug_number(traces_dir, i) bug_trace_path = path_of_bug_number(traces_dir, i)
with codecs.open(bug_trace_path, 'w', with codecs.open(bug_trace_path, 'w',
encoding=utils.LOCALE) as bug_trace_file: encoding=config.LOCALE) as bug_trace_file:
bug_trace_file.write(html_bug_trace(args, bug, i)) bug_trace_file.write(html_bug_trace(args, bug, i))
i += 1 i += 1
remote_source_template = get_remote_source_template() remote_source_template = get_remote_source_template()
bug_list_path = os.path.join(html_dir, 'index.html') bug_list_path = os.path.join(html_dir, 'index.html')
with codecs.open(bug_list_path, 'w', with codecs.open(bug_list_path, 'w',
encoding=utils.LOCALE) as bug_list_file: encoding=config.LOCALE) as bug_list_file:
bug_list_file.write(html_list_of_bugs(args, bug_list_file.write(html_list_of_bugs(args,
remote_source_template, remote_source_template,
sel)) sel))
@ -377,7 +377,7 @@ def main():
report_filename = os.path.join(args.infer_out, utils.JSON_REPORT_FILENAME) report_filename = os.path.join(args.infer_out, utils.JSON_REPORT_FILENAME)
with codecs.open(report_filename, 'r', with codecs.open(report_filename, 'r',
encoding=utils.LOCALE) as report_file: encoding=config.LOCALE) as report_file:
reports = json.load(report_file) reports = json.load(report_file)
if args.html: if args.html:

@ -506,7 +506,7 @@ class Infer:
# capture and compile mode do not create proc_stats.json # capture and compile mode do not create proc_stats.json
if os.path.isfile(proc_stats_path): if os.path.isfile(proc_stats_path):
with codecs.open(proc_stats_path, 'r', with codecs.open(proc_stats_path, 'r',
encoding=utils.LOCALE) as proc_stats_file: encoding=config.LOCALE) as proc_stats_file:
proc_stats = json.load(proc_stats_file) proc_stats = json.load(proc_stats_file)
self.stats['int'].update(proc_stats) self.stats['int'].update(proc_stats)
@ -525,7 +525,8 @@ class Infer:
} }
stats_path = os.path.join(self.args.infer_out, utils.STATS_FILENAME) stats_path = os.path.join(self.args.infer_out, utils.STATS_FILENAME)
with codecs.open(stats_path, 'w', encoding=utils.LOCALE) as stats_file: with codecs.open(stats_path, 'w',
encoding=config.LOCALE) as stats_file:
json.dump(self.stats, stats_file, indent=2) json.dump(self.stats, stats_file, indent=2)

@ -10,9 +10,16 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
import locale
LOCALE = locale.getpreferredencoding()
# exit value when infer finds something to report # exit value when infer finds something to report
BUG_FOUND_ERROR_CODE = 2 BUG_FOUND_ERROR_CODE = 2
# list of possible analyzers # list of possible analyzers
ANALYZER_INFER = 'infer' ANALYZER_INFER = 'infer'
ANALYZER_ERADICATE = 'eradicate' ANALYZER_ERADICATE = 'eradicate'

@ -101,14 +101,14 @@ def clean_json(args, json_report):
def print_errors(json_report, bugs_out): def print_errors(json_report, bugs_out):
with codecs.open(json_report, 'r', encoding=utils.LOCALE) as file_in: with codecs.open(json_report, 'r', encoding=config.LOCALE) as file_in:
errors = json.load(file_in) errors = json.load(file_in)
errors = filter(lambda row: row[utils.JSON_INDEX_KIND] in errors = filter(lambda row: row[utils.JSON_INDEX_KIND] in
[ISSUE_KIND_ERROR, ISSUE_KIND_WARNING], [ISSUE_KIND_ERROR, ISSUE_KIND_WARNING],
errors) errors)
with codecs.open(bugs_out, 'w', encoding=utils.LOCALE) as file_out: with codecs.open(bugs_out, 'w', encoding=config.LOCALE) as file_out:
text_errors_list = [] text_errors_list = []
for row in errors: for row in errors:
filename = row[utils.JSON_INDEX_FILENAME] filename = row[utils.JSON_INDEX_FILENAME]

@ -10,6 +10,8 @@ import argparse
import os import os
import tempfile import tempfile
import subprocess import subprocess
import config
import utils import utils
FILELISTS = 'filelists' FILELISTS = 'filelists'

@ -19,7 +19,7 @@ except ImportError:
pygments = None pygments = None
import sys import sys
from . import utils from . import config, utils
BASE_INDENT = 2 BASE_INDENT = 2
# how many lines of context around each report # how many lines of context around each report
@ -53,7 +53,7 @@ class Indenter(str):
def add(self, x): def add(self, x):
if type(x) != unicode: if type(x) != unicode:
x = x.decode(utils.LOCALE) x = x.decode(config.LOCALE)
lines = x.splitlines() lines = x.splitlines()
indent = self.indent_get() indent = self.indent_get()
lines = [indent + l for l in lines] lines = [indent + l for l in lines]
@ -63,7 +63,7 @@ class Indenter(str):
return self.text return self.text
def __str__(self): def __str__(self):
return unicode(self).encode(utils.LOCALE) return unicode(self).encode(config.LOCALE)
def build_source_context(source_name, mode, report_line): def build_source_context(source_name, mode, report_line):
@ -74,7 +74,7 @@ def build_source_context(source_name, mode, report_line):
n_length = len(str(end_line)) n_length = len(str(end_line))
line_number = 1 line_number = 1
s = '' s = ''
with codecs.open(source_name, 'r', encoding=utils.LOCALE) as source_file: with codecs.open(source_name, 'r', encoding=config.LOCALE) as source_file:
for line in source_file: for line in source_file:
if start_line <= line_number <= end_line: if start_line <= line_number <= end_line:
num = str(line_number).zfill(n_length) num = str(line_number).zfill(n_length)

@ -16,7 +16,6 @@ import csv
import fnmatch import fnmatch
import gzip import gzip
import json import json
import locale
import logging import logging
import os import os
import re import re
@ -25,13 +24,13 @@ import sys
import tempfile import tempfile
import time import time
from . import config
LOCALE = locale.getpreferredencoding()
# this assumes that this file lives in infer/lib/python/infer/ and the binaries # this assumes that this file lives in infer/lib/python/infer/ and the binaries
# are in infer/bin/ # are in infer/bin/
INFER_PYTHON_DIRECTORY = os.path.dirname(os.path.realpath(__file__) INFER_PYTHON_DIRECTORY = os.path.dirname(os.path.realpath(__file__)
.decode(LOCALE)) .decode(config.LOCALE))
INFER_INFER_DIRECTORY = os.path.join(INFER_PYTHON_DIRECTORY, INFER_INFER_DIRECTORY = os.path.join(INFER_PYTHON_DIRECTORY,
os.pardir, os.pardir, os.pardir) os.pardir, os.pardir, os.pardir)
INFER_ROOT_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, os.pardir) INFER_ROOT_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, os.pardir)
@ -45,7 +44,8 @@ ANNOT_PROCESSOR_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'processor.jar')
WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers') WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers')
XCODE_WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'xcode_wrappers') XCODE_WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'xcode_wrappers')
DEFAULT_INFER_OUT = os.path.join(os.getcwd().decode(LOCALE), 'infer-out') DEFAULT_INFER_OUT = os.path.join(os.getcwd().decode(config.LOCALE),
'infer-out')
CSV_PERF_FILENAME = 'performances.csv' CSV_PERF_FILENAME = 'performances.csv'
STATS_FILENAME = 'stats.json' STATS_FILENAME = 'stats.json'
PROC_STATS_FILENAME = 'proc_stats.json' PROC_STATS_FILENAME = 'proc_stats.json'
@ -128,7 +128,7 @@ if "check_output" not in dir(subprocess):
def locale_csv_reader(iterable, dialect='excel', **kwargs): def locale_csv_reader(iterable, dialect='excel', **kwargs):
rows = csv.reader(iterable, dialect=dialect, **kwargs) rows = csv.reader(iterable, dialect=dialect, **kwargs)
for row in rows: for row in rows:
yield [unicode(cell, LOCALE) for cell in row] yield [unicode(cell, config.LOCALE) for cell in row]
def configure_logging(debug, quiet=False): def configure_logging(debug, quiet=False):
@ -163,7 +163,7 @@ def get_cmd_in_bin_dir(binary_name):
def write_cmd_streams_to_file(logfile, cmd=None, out=None, err=None): def write_cmd_streams_to_file(logfile, cmd=None, out=None, err=None):
with codecs.open(logfile, 'w', encoding=LOCALE) as log_filedesc: with codecs.open(logfile, 'w', encoding=config.LOCALE) as log_filedesc:
if cmd: if cmd:
log_filedesc.write(' '.join(cmd) + '\n') log_filedesc.write(' '.join(cmd) + '\n')
if err is not None: if err is not None:

Loading…
Cancel
Save