upgraded wakatime package to v0.1.3

This commit is contained in:
Alan Hamlett 2013-07-20 15:28:38 -07:00
parent 239c6f56b5
commit fae7b4a8e4
20 changed files with 195 additions and 46 deletions

35
packages/wakatime/.gitignore vendored Normal file
View File

@ -0,0 +1,35 @@
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject

View File

@ -0,0 +1,17 @@
History
-------
0.1.1 (2013-07-07)
++++++++++++++++++
- Refactored
- Simplified action events schema
0.0.1 (2013-07-05)
++++++++++++++++++
- Birth

29
packages/wakatime/LICENSE Normal file
View File

@ -0,0 +1,29 @@
Copyright (c) 2013 Alan Hamlett https://wakati.me
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided
with the distribution.
* Neither the names of Wakatime or Wakati.Me, nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,2 @@
include README.rst LICENSE HISTORY.rst
recursive-include wakatime *.py

View File

@ -0,0 +1,12 @@
Wakati.Me
=========
Wakati.Me is a time tracking api for text editors. This is the command line
action event appender for the Wakati.Me api. You shouldn't need to directly
use this outside of a text editor plugin.
Installation
------------
https://www.wakati.me/help/plugins/installing-plugins

View File

@ -0,0 +1,39 @@
from setuptools import setup
from wakatime.__init__ import __version__ as VERSION
packages = [
'wakatime',
]
setup(
name='wakatime',
version=VERSION,
license='BSD 3 Clause',
description=' '.join([
'Action event appender for Wakati.Me, a time',
'tracking api for text editors.',
]),
long_description=open('README.rst').read(),
author='Alan Hamlett',
author_email='alan.hamlett@gmail.com',
url='https://github.com/wakatime/wakatime',
packages=packages,
package_dir={'wakatime': 'wakatime'},
include_package_data=True,
zip_safe=False,
platforms='any',
entry_points={
'console_scripts': ['wakatime = wakatime.__init__:main'],
},
classifiers=(
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Programming Language :: Python',
'Topic :: Text Editors',
),
)

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""
wakatime-cli
~~~~~~~~~~~~
Action event appender for Wakati.Me, auto time tracking for text editors.
:copyright: (c) 2013 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""
from __future__ import print_function
import sys
import wakatime
if __name__ == '__main__':
sys.exit(wakatime.main(sys.argv))

View File

@ -3,7 +3,7 @@
wakatime
~~~~~~~~
Action event appender for Wakati.Me, a time tracking api for text editors.
Action event appender for Wakati.Me, auto time tracking for text editors.
:copyright: (c) 2013 Alan Hamlett.
:license: BSD, see LICENSE for more details.
@ -12,22 +12,12 @@
from __future__ import print_function
__title__ = 'wakatime'
__version__ = '0.1.2'
__version__ = '0.1.3'
__author__ = 'Alan Hamlett'
__license__ = 'BSD'
__copyright__ = 'Copyright 2013 Alan Hamlett'
# allow running script directly
if __name__ == '__main__' and __package__ is None:
import os, sys
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent_dir)
import wakatime
__package__ = 'wakatime'
del os, sys
import base64
import json
import logging
@ -41,11 +31,7 @@ import urllib2
from .log import setup_logging
from .project import find_project
try:
import argparse
except ImportError:
from .packages import argparse
from .packages import argparse
log = logging.getLogger(__name__)
@ -58,7 +44,7 @@ class FileAction(argparse.Action):
setattr(namespace, self.dest, values)
def parseArguments():
def parseArguments(argv):
parser = argparse.ArgumentParser(
description='Wakati.Me event api appender')
parser.add_argument('--file', dest='targetFile', metavar='file',
@ -88,7 +74,7 @@ def parseArguments():
parser.add_argument('--verbose', dest='verbose', action='store_true',
help='turns on debug messages in log file')
parser.add_argument('--version', action='version', version=__version__)
args = parser.parse_args()
args = parser.parse_args(args=argv[1:])
if not args.timestamp:
args.timestamp = time.time()
if not args.key:
@ -138,7 +124,7 @@ def send_action(project=None, tags=None, key=None, targetFile=None,
if project:
data['project'] = project
if tags:
data['tags'] = tags
data['tags'] = list(set(tags))
log.debug(data)
request = urllib2.Request(url=url, data=json.dumps(data))
user_agent = get_user_agent(plugin)
@ -178,8 +164,10 @@ def send_action(project=None, tags=None, key=None, targetFile=None,
return False
def main():
args = parseArguments()
def main(argv=None):
if not argv:
argv = sys.argv
args = parseArguments(argv)
setup_logging(args, __version__)
if os.path.isfile(args.targetFile):
project = find_project(args.targetFile)
@ -191,6 +179,3 @@ def main():
log.debug('File does not exist; ignoring this action.')
return 101
if __name__ == '__main__':
sys.exit(main())

View File

@ -37,13 +37,14 @@ class Git(BaseProject):
def tags(self):
tags = []
if self.config:
base = self._project_base()
if base:
tags.append(base)
proj_name = self.name()
if proj_name:
tags.append(proj_name)
sections = self._parse_config()
for section in sections:
if section.split(' ', 1)[0] == 'remote' and 'url' in sections[section]:
tags.append(sections[section]['url'])
remote = sections[section]['url'].rsplit(':', 1)[1].rsplit('/', 1)[1].split('.git', 1)[0]
tags.append(remote)
branch = self._current_branch()
if branch is not None:
tags.append(branch)

View File

@ -23,20 +23,23 @@ log = logging.getLogger(__name__)
class Subversion(BaseProject):
def process(self):
self.info = self._get_info()
if 'Repository Root' in self.info:
return True
return False
return self._find_project_base(self.path)
def name(self):
return self.info['Repository Root'].split('/')[-1]
def _get_info(self):
def tags(self):
tags = []
if self.base:
tags.append(os.path.basename(self.base))
return tags
def _get_info(self, path):
info = OrderedDict()
stdout = None
try:
stdout, stderr = Popen([
'svn', 'info', os.path.realpath(self.path)
'svn', 'info', os.path.realpath(path)
], stdout=PIPE, stderr=PIPE).communicate()
except OSError:
pass
@ -53,11 +56,19 @@ class Subversion(BaseProject):
info[line[0]] = line[1]
return info
def tags(self):
tags = []
for key in self.info:
if key == 'Repository UUID':
tags.append(self.info[key])
if key == 'URL':
tags.append(os.path.dirname(self.info[key]))
return tags
def _find_project_base(self, path, found=False):
path = os.path.realpath(path)
if os.path.isfile(path):
path = os.path.split(path)[0]
info = self._get_info(path)
if len(info) > 0:
found = True
self.base = path
self.info = info
elif found:
return True
split_path = os.path.split(path)
if split_path[1] == '':
return found
return self._find_project_base(split_path[0], found)

View File

@ -20,7 +20,7 @@ import sublime_plugin
AWAY_MINUTES = 10
ACTION_FREQUENCY = 5
PLUGIN_DIR = dirname(realpath(__file__))
API_CLIENT = '%s/packages/wakatime/wakatime.py' % PLUGIN_DIR
API_CLIENT = '%s/packages/wakatime/wakatime-cli.py' % PLUGIN_DIR
LAST_ACTION = 0
LAST_USAGE = 0
LAST_FILE = None
@ -51,11 +51,11 @@ def api(targetFile, timestamp, isWrite=False, endtime=0):
if not targetFile:
targetFile = LAST_FILE
if targetFile:
python_cmd = 'python'
if(platform.system() == 'Windows'):
python_cmd = 'pythonw'
cmd = [python_cmd, API_CLIENT,
'--file', targetFile,
'--time', str('%f' % timestamp),