upgrade wakatime cli to v4.1.6
This commit is contained in:
parent
1d1c59dbe1
commit
9dc1a35939
12 changed files with 61 additions and 50 deletions
|
@ -1,7 +1,7 @@
|
|||
__title__ = 'wakatime'
|
||||
__description__ = 'Common interface to the WakaTime api.'
|
||||
__url__ = 'https://github.com/wakatime/wakatime'
|
||||
__version_info__ = ('4', '1', '4')
|
||||
__version_info__ = ('4', '1', '6')
|
||||
__version__ = '.'.join(__version_info__)
|
||||
__author__ = 'Alan Hamlett'
|
||||
__author_email__ = 'alan@wakatime.com'
|
||||
|
|
|
@ -26,9 +26,12 @@ if is_py2: # pragma: nocover
|
|||
return text.decode('utf-8')
|
||||
except:
|
||||
try:
|
||||
return unicode(text)
|
||||
return text.decode(sys.getdefaultencoding())
|
||||
except:
|
||||
return text
|
||||
try:
|
||||
return unicode(text)
|
||||
except:
|
||||
return text
|
||||
open = codecs.open
|
||||
basestring = basestring
|
||||
|
||||
|
@ -39,8 +42,17 @@ elif is_py3: # pragma: nocover
|
|||
if text is None:
|
||||
return None
|
||||
if isinstance(text, bytes):
|
||||
return text.decode('utf-8')
|
||||
return str(text)
|
||||
try:
|
||||
return text.decode('utf-8')
|
||||
except:
|
||||
try:
|
||||
return text.decode(sys.getdefaultencoding())
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
return str(text)
|
||||
except:
|
||||
return text
|
||||
open = open
|
||||
basestring = (str, bytes)
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ except ImportError:
|
|||
from .packages.ordereddict import OrderedDict # pragma: nocover
|
||||
try:
|
||||
from .packages import simplejson as json # pragma: nocover
|
||||
except (ImportError, SyntaxError):
|
||||
import json # pragma: nocover
|
||||
except (ImportError, SyntaxError): # pragma: nocover
|
||||
import json
|
||||
|
||||
|
||||
class CustomEncoder(json.JSONEncoder):
|
||||
|
|
|
@ -393,8 +393,9 @@ def send_heartbeat(project=None, branch=None, hostname=None, stats={}, key=None,
|
|||
return False
|
||||
|
||||
|
||||
def execute(argv):
|
||||
sys.argv = ['wakatime'] + argv
|
||||
def execute(argv=None):
|
||||
if argv:
|
||||
sys.argv = ['wakatime'] + argv
|
||||
|
||||
args, configs = parseArguments()
|
||||
if configs is None:
|
||||
|
|
|
@ -18,7 +18,7 @@ from time import sleep
|
|||
try:
|
||||
import sqlite3
|
||||
HAS_SQL = True
|
||||
except ImportError:
|
||||
except ImportError: # pragma: nocover
|
||||
HAS_SQL = False
|
||||
|
||||
from .compat import u
|
||||
|
@ -117,12 +117,12 @@ class Queue(object):
|
|||
'plugin': row[8],
|
||||
}
|
||||
loop = False
|
||||
except sqlite3.Error:
|
||||
except sqlite3.Error: # pragma: nocover
|
||||
log.debug(traceback.format_exc())
|
||||
sleep(wait)
|
||||
tries -= 1
|
||||
try:
|
||||
conn.close()
|
||||
except sqlite3.Error:
|
||||
except sqlite3.Error: # pragma: nocover
|
||||
log.debug(traceback.format_exc())
|
||||
return heartbeat
|
||||
|
|
|
@ -25,22 +25,12 @@ class BaseProject(object):
|
|||
self.path = path
|
||||
self._configs = configs
|
||||
|
||||
def project_type(self):
|
||||
""" Returns None if this is the base class.
|
||||
Returns the type of project if this is a
|
||||
valid project.
|
||||
"""
|
||||
project_type = self.__class__.__name__.lower()
|
||||
if project_type == 'baseproject':
|
||||
project_type = None
|
||||
return project_type
|
||||
|
||||
def process(self):
|
||||
""" Processes self.path into a project and
|
||||
returns True if project is valid, otherwise
|
||||
returns False.
|
||||
"""
|
||||
return False
|
||||
return False # pragma: nocover
|
||||
|
||||
def name(self):
|
||||
""" Returns the project's name.
|
||||
|
@ -50,4 +40,4 @@ class BaseProject(object):
|
|||
def branch(self):
|
||||
""" Returns the current branch.
|
||||
"""
|
||||
return None
|
||||
return None # pragma: nocover
|
||||
|
|
|
@ -30,7 +30,7 @@ class Git(BaseProject):
|
|||
base = self._project_base()
|
||||
if base:
|
||||
return u(os.path.basename(base))
|
||||
return None
|
||||
return None # pragma: nocover
|
||||
|
||||
def branch(self):
|
||||
base = self._project_base()
|
||||
|
@ -39,13 +39,13 @@ class Git(BaseProject):
|
|||
try:
|
||||
with open(head, 'r', encoding='utf-8') as fh:
|
||||
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||
except UnicodeDecodeError:
|
||||
except UnicodeDecodeError: # pragma: nocover
|
||||
try:
|
||||
with open(head, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||
return u(fh.readline().strip().rsplit('/', 1)[-1])
|
||||
except:
|
||||
log.exception("Exception:")
|
||||
except IOError:
|
||||
except IOError: # pragma: nocover
|
||||
log.exception("Exception:")
|
||||
return None
|
||||
|
||||
|
|
|
@ -47,14 +47,14 @@ class ProjectMap(BaseProject):
|
|||
|
||||
if self._configs.get(path.lower()):
|
||||
return self._configs.get(path.lower())
|
||||
if self._configs.get('%s/' % path.lower()):
|
||||
if self._configs.get('%s/' % path.lower()): # pragma: nocover
|
||||
return self._configs.get('%s/' % path.lower())
|
||||
if self._configs.get('%s\\' % path.lower()):
|
||||
if self._configs.get('%s\\' % path.lower()): # pragma: nocover
|
||||
return self._configs.get('%s\\' % path.lower())
|
||||
|
||||
split_path = os.path.split(path)
|
||||
if split_path[1] == '':
|
||||
return None
|
||||
return None # pragma: nocover
|
||||
return self._find_project(split_path[0])
|
||||
|
||||
def branch(self):
|
||||
|
@ -63,4 +63,4 @@ class ProjectMap(BaseProject):
|
|||
def name(self):
|
||||
if self.project:
|
||||
return u(self.project)
|
||||
return None
|
||||
return None # pragma: nocover
|
||||
|
|
|
@ -19,7 +19,7 @@ from ..compat import u, open
|
|||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from ..packages.ordereddict import OrderedDict
|
||||
from ..packages.ordereddict import OrderedDict # pragma: nocover
|
||||
|
||||
|
||||
log = logging.getLogger('WakaTime')
|
||||
|
@ -32,10 +32,14 @@ class Subversion(BaseProject):
|
|||
return self._find_project_base(self.path)
|
||||
|
||||
def name(self):
|
||||
return u(self.info['Repository Root'].split('/')[-1])
|
||||
if 'Repository Root' not in self.info:
|
||||
return None
|
||||
return u(self.info['Repository Root'].split('/')[-1].split('\\')[-1])
|
||||
|
||||
def branch(self):
|
||||
return u(self.info['URL'].split('/')[-1])
|
||||
if 'URL' not in self.info:
|
||||
return None
|
||||
return u(self.info['URL'].split('/')[-1].split('\\')[-1])
|
||||
|
||||
def _find_binary(self):
|
||||
if self.binary_location:
|
||||
|
@ -69,8 +73,7 @@ class Subversion(BaseProject):
|
|||
else:
|
||||
if stdout:
|
||||
for line in stdout.splitlines():
|
||||
if isinstance(line, bytes):
|
||||
line = bytes.decode(line)
|
||||
line = u(line)
|
||||
line = line.split(': ', 1)
|
||||
if len(line) == 2:
|
||||
info[line[0]] = line[1]
|
||||
|
@ -78,7 +81,7 @@ class Subversion(BaseProject):
|
|||
|
||||
def _find_project_base(self, path, found=False):
|
||||
if platform.system() == 'Windows':
|
||||
return False
|
||||
return False # pragma: nocover
|
||||
path = os.path.realpath(path)
|
||||
if os.path.isfile(path):
|
||||
path = os.path.split(path)[0]
|
||||
|
|
|
@ -35,14 +35,14 @@ class WakaTimeProjectFile(BaseProject):
|
|||
with open(self.config, 'r', encoding='utf-8') as fh:
|
||||
self._project_name = u(fh.readline().strip())
|
||||
self._project_branch = u(fh.readline().strip())
|
||||
except UnicodeDecodeError:
|
||||
except UnicodeDecodeError: # pragma: nocover
|
||||
try:
|
||||
with open(self.config, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
||||
self._project_name = u(fh.readline().strip())
|
||||
self._project_branch = u(fh.readline().strip())
|
||||
except:
|
||||
log.exception("Exception:")
|
||||
except IOError:
|
||||
except IOError: # pragma: nocover
|
||||
log.exception("Exception:")
|
||||
|
||||
return True
|
||||
|
|
|
@ -19,7 +19,7 @@ import traceback
|
|||
try:
|
||||
import sqlite3
|
||||
HAS_SQL = True
|
||||
except ImportError:
|
||||
except ImportError: # pragma: nocover
|
||||
HAS_SQL = False
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'packages'))
|
||||
|
@ -47,7 +47,7 @@ class SessionCache(object):
|
|||
"""
|
||||
|
||||
if not HAS_SQL:
|
||||
return
|
||||
return # pragma: nocover
|
||||
try:
|
||||
conn, c = self.connect()
|
||||
c.execute('DELETE FROM session')
|
||||
|
@ -57,7 +57,7 @@ class SessionCache(object):
|
|||
c.execute('INSERT INTO session VALUES (:value)', values)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except:
|
||||
except: # pragma: nocover
|
||||
log.error(traceback.format_exc())
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ class SessionCache(object):
|
|||
conn, c = self.connect()
|
||||
except:
|
||||
log.error(traceback.format_exc())
|
||||
return requests.session()
|
||||
return requests.session() # pragma: nocover
|
||||
|
||||
session = None
|
||||
try:
|
||||
|
|
|
@ -63,7 +63,7 @@ def smart_guess_lexer(file_name):
|
|||
lexer = lexer1
|
||||
if (lexer2 and accuracy2 and
|
||||
(not accuracy1 or accuracy2 > accuracy1)):
|
||||
lexer = lexer2
|
||||
lexer = lexer2 # pragma: nocover
|
||||
|
||||
return lexer
|
||||
|
||||
|
@ -84,7 +84,7 @@ def guess_lexer_using_filename(file_name, text):
|
|||
if lexer is not None:
|
||||
try:
|
||||
accuracy = lexer.analyse_text(text)
|
||||
except:
|
||||
except: # pragma: nocover
|
||||
pass
|
||||
|
||||
return lexer, accuracy
|
||||
|
@ -101,19 +101,19 @@ def guess_lexer_using_modeline(text):
|
|||
file_type = None
|
||||
try:
|
||||
file_type = get_filetype_from_buffer(text)
|
||||
except:
|
||||
except: # pragma: nocover
|
||||
pass
|
||||
|
||||
if file_type is not None:
|
||||
try:
|
||||
lexer = get_lexer_by_name(file_type)
|
||||
except ClassNotFound:
|
||||
except ClassNotFound: # pragma: nocover
|
||||
pass
|
||||
|
||||
if lexer is not None:
|
||||
try:
|
||||
accuracy = lexer.analyse_text(text)
|
||||
except:
|
||||
except: # pragma: nocover
|
||||
pass
|
||||
|
||||
return lexer, accuracy
|
||||
|
@ -123,11 +123,16 @@ def get_language_from_extension(file_name):
|
|||
"""Returns a matching language for the given file extension.
|
||||
"""
|
||||
|
||||
extension = os.path.splitext(file_name)[1].lower()
|
||||
filepart, extension = os.path.splitext(file_name)
|
||||
|
||||
if os.path.exists(u('{0}{1}').format(u(filepart), u('.c'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.C'))):
|
||||
return 'C'
|
||||
|
||||
extension = extension.lower()
|
||||
if extension == '.h':
|
||||
directory = os.path.dirname(file_name)
|
||||
available_files = os.listdir(directory)
|
||||
available_extensions = zip(*map(os.path.splitext, available_files))[1]
|
||||
available_extensions = list(zip(*map(os.path.splitext, available_files)))[1]
|
||||
available_extensions = [ext.lower() for ext in available_extensions]
|
||||
if '.cpp' in available_extensions:
|
||||
return 'C++'
|
||||
|
|
Loading…
Reference in a new issue