use sublime project from sublime-project file when no revision control project found

This commit is contained in:
Alan Hamlett 2014-06-18 10:10:28 -07:00
parent 7b854d4041
commit e19f85f081
3 changed files with 31 additions and 9 deletions

View file

@ -18,7 +18,7 @@ import sys
import time import time
import threading import threading
import uuid import uuid
from os.path import expanduser, dirname, realpath, isfile, join, exists from os.path import expanduser, dirname, basename, realpath, isfile, join, exists
# globals # globals
@ -53,7 +53,9 @@ if HAS_SSL:
def prompt_api_key(): def prompt_api_key():
global SETTINGS global SETTINGS
if not SETTINGS.get('api_key'): if SETTINGS.get('api_key'):
return True
else:
def got_key(text): def got_key(text):
if text: if text:
SETTINGS.set('api_key', str(text)) SETTINGS.set('api_key', str(text))
@ -91,7 +93,10 @@ def handle_action(view, is_write=False):
with LOCK: with LOCK:
target_file = view.file_name() target_file = view.file_name()
if target_file: if target_file:
thread = SendActionThread(target_file, is_write=is_write) project = view.window().project_file_name()
if project:
project = basename(project).replace('.sublime-project', '', 1)
thread = SendActionThread(target_file, is_write=is_write, project=project)
thread.start() thread.start()
LAST_ACTION = { LAST_ACTION = {
'file': target_file, 'file': target_file,
@ -102,10 +107,11 @@ def handle_action(view, is_write=False):
class SendActionThread(threading.Thread): class SendActionThread(threading.Thread):
def __init__(self, target_file, is_write=False, force=False): def __init__(self, target_file, is_write=False, project=None, force=False):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.target_file = target_file self.target_file = target_file
self.is_write = is_write self.is_write = is_write
self.project = project
self.force = force self.force = force
self.debug = SETTINGS.get('debug') self.debug = SETTINGS.get('debug')
self.api_key = SETTINGS.get('api_key', '') self.api_key = SETTINGS.get('api_key', '')
@ -132,13 +138,15 @@ class SendActionThread(threading.Thread):
] ]
if self.is_write: if self.is_write:
cmd.append('--write') cmd.append('--write')
if self.project:
cmd.extend(['--project', self.project])
for pattern in self.ignore: for pattern in self.ignore:
cmd.extend(['--ignore', pattern]) cmd.extend(['--ignore', pattern])
if self.debug: if self.debug:
cmd.append('--verbose') cmd.append('--verbose')
if HAS_SSL: if HAS_SSL:
if self.debug: if self.debug:
print(cmd) print('[WakaTime] %s' % ' '.join(cmd))
code = wakatime.main(cmd) code = wakatime.main(cmd)
if code != 0: if code != 0:
print('[WakaTime] Error: Response code %d from wakatime package.' % code) print('[WakaTime] Error: Response code %d from wakatime package.' % code)
@ -147,7 +155,7 @@ class SendActionThread(threading.Thread):
if python: if python:
cmd.insert(0, python) cmd.insert(0, python)
if self.debug: if self.debug:
print(cmd) print('[WakaTime] %s' % ' '.join(cmd))
if platform.system() == 'Windows': if platform.system() == 'Windows':
Popen(cmd, shell=False) Popen(cmd, shell=False)
else: else:
@ -159,6 +167,7 @@ class SendActionThread(threading.Thread):
def plugin_loaded(): def plugin_loaded():
global SETTINGS global SETTINGS
print('[WakaTime] Initializing WakaTime plugin v%s' % __version__)
SETTINGS = sublime.load_settings(SETTINGS_FILE) SETTINGS = sublime.load_settings(SETTINGS_FILE)
after_loaded() after_loaded()

View file

@ -3,6 +3,19 @@ History
------- -------
2.0.3 (2014-06-18)
++++++++++++++++++
- use project from command line arg when no revision control project is found
2.0.2 (2014-06-09)
++++++++++++++++++
- include python3.2 compatible versions of simplejson, pytz, and tzlocal
- disable offline logging when Python was not compiled with sqlite3 module
2.0.1 (2014-05-26) 2.0.1 (2014-05-26)
++++++++++++++++++ ++++++++++++++++++

View file

@ -13,7 +13,7 @@
from __future__ import print_function from __future__ import print_function
__title__ = 'wakatime' __title__ = 'wakatime'
__version__ = '2.0.2' __version__ = '2.0.3'
__author__ = 'Alan Hamlett' __author__ = 'Alan Hamlett'
__license__ = 'BSD' __license__ = 'BSD'
__copyright__ = 'Copyright 2014 Alan Hamlett' __copyright__ = 'Copyright 2014 Alan Hamlett'
@ -348,10 +348,10 @@ def main(argv=None):
project = find_project(args.targetFile, configs=configs) project = find_project(args.targetFile, configs=configs)
branch = None branch = None
project_name = None project_name = args.project_name
if project: if project:
branch = project.branch() branch = project.branch()
project_name = args.project_name or project.name() project_name = project.name()
if send_action( if send_action(
project=project_name, project=project_name,