disable lines count for files larger than 2MB

This commit is contained in:
Alan Hamlett 2017-04-19 23:05:40 -07:00
parent 051ae85f69
commit 149ab8d00e
5 changed files with 80 additions and 7 deletions

View file

@ -25,6 +25,22 @@ except ImportError:
from .packages import configparser
def getConfigFile():
"""Returns the config file location.
If $WAKATIME_HOME env varialbe is defined, returns
$WAKATIME_HOME/.wakatime.cfg, otherwise ~/.wakatime.cfg.
"""
fileName = '.wakatime.cfg'
home = os.environ.get('WAKATIME_HOME')
if home:
return os.path.join(os.path.expanduser(home), fileName)
return os.path.join(os.path.expanduser('~'), fileName)
def parseConfigFile(configFile=None):
"""Returns a configparser.SafeConfigParser instance with configs
read from the config file. Default location of the config file is
@ -32,13 +48,8 @@ def parseConfigFile(configFile=None):
"""
# get config file location from ENV
home = os.environ.get('WAKATIME_HOME')
if not configFile and home:
configFile = os.path.join(os.path.expanduser(home), '.wakatime.cfg')
# use default config file location
if not configFile:
configFile = os.path.join(os.path.expanduser('~'), '.wakatime.cfg')
configFile = getConfigFile()
configs = configparser.ConfigParser(delimiters=('='), strict=False)
try:

View file

@ -38,3 +38,9 @@ UNKNOWN_ERROR = 105
Exit code used when the JSON input from `--extra-heartbeats` is malformed.
"""
MALFORMED_HEARTBEAT_ERROR = 106
""" Max file size supporting line number count stats.
Files larger than this in bytes will not have a line count stat for performance.
Default is 2MB.
"""
MAX_FILE_SIZE_SUPPORTED = 2000000

View file

@ -15,6 +15,7 @@ import re
import sys
from .compat import u, open
from .constants import MAX_FILE_SIZE_SUPPORTED
from .dependencies import DependencyParser
from .language_priorities import LANGUAGES
@ -184,6 +185,11 @@ def get_language_from_extension(file_name):
def number_lines_in_file(file_name):
try:
if os.path.getsize(file_name) > MAX_FILE_SIZE_SUPPORTED:
return None
except os.error:
pass
lines = 0
try:
with open(file_name, 'r', encoding='utf-8') as fh: