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