|
4 | 4 | import time
|
5 | 5 | import os
|
6 | 6 | import subprocess
|
| 7 | +import re |
7 | 8 |
|
8 | 9 | gtm_settings = {}
|
9 | 10 |
|
@@ -39,47 +40,49 @@ def plugin_loaded():
|
39 | 40 | set_status_bar()
|
40 | 41 |
|
41 | 42 | def set_status_bar():
|
42 |
| - if GTM.status_option_found and gtm_settings.get('gtm_status_bar', True): |
| 43 | + if gtm_settings.get('gtm_status_bar', True): |
43 | 44 | GTM.status_option = '--status'
|
44 | 45 | print("Enabling reporting time in status bar")
|
45 | 46 | else:
|
46 | 47 | GTM.status_option = ''
|
47 | 48 | print("Disabling reporting time in status bar")
|
48 | 49 |
|
49 | 50 | class GTM(sublime_plugin.EventListener):
|
| 51 | + gtm_ver_req = '>= 1.0-beta.6' |
| 52 | + |
50 | 53 | update_interval = 30
|
51 | 54 | last_update = 0
|
52 | 55 | last_path = None
|
53 |
| - status_option = "" |
| 56 | + status_option = '' |
54 | 57 |
|
55 |
| - no_gtm_err = ("GTM executable not found. " |
| 58 | + no_gtm_err = ("GTM executable not found.\n\n" |
56 | 59 | "Install GTM and/or update your system path. "
|
57 |
| - "Make sure to restart Sublime after install. \n\n" |
58 |
| - "See https://www.github.com/git-time-metric/gtm") |
| 60 | + "Make sure to restart Sublime after install.\n\n" |
| 61 | + "See https://github.com/git-time-metric/gtm/blob/master/README.md") |
59 | 62 |
|
60 |
| - record_err = ("GTM error saving time. " |
61 |
| - "Install GTM and/or update your system path. " |
| 63 | + record_err = ("GTM error saving time.\n\n" |
| 64 | + "Install GTM and/or update the system path. " |
62 | 65 | "Make sure to restart Sublime after install.\n\n"
|
63 |
| - "See https://www.github.com/git-time-metric/gtm") |
| 66 | + "See https://github.com/git-time-metric/gtm/blob/master/README.md") |
64 | 67 |
|
65 |
| - ver_warn = ("GTM executable does not support all required features. " |
| 68 | + ver_warn = ("GTM executable is out of date.\n\n" |
| 69 | + "The plug-in may not work properly. " |
66 | 70 | "Please install the latest GTM version and restart Sublime.\n\n"
|
67 |
| - "See https://www.github.com/git-time-metric/gtm") |
| 71 | + "See https://github.com/git-time-metric/gtm/blob/master/README.md") |
68 | 72 |
|
69 | 73 | gtm_path = find_gtm_path()
|
70 | 74 |
|
71 | 75 | if not gtm_path:
|
72 | 76 | sublime.error_message(no_gtm_err)
|
73 | 77 | else:
|
74 |
| - # check support for [gtm record --status] feature |
75 |
| - p = subprocess.Popen('"{0}" record --help'.format(gtm_path), |
| 78 | + p = subprocess.Popen('"{0}" verify "{1}"'.format(gtm_path, gtm_ver_req), |
76 | 79 | shell=True,
|
77 | 80 | stdin=subprocess.PIPE,
|
78 | 81 | stdout=subprocess.PIPE,
|
79 | 82 | stderr=subprocess.STDOUT)
|
80 | 83 | output = p.stdout.read()
|
81 |
| - status_option_found = '-status' in output.decode('utf-8') |
82 |
| - if not status_option_found: |
| 84 | + version_ok = 'true' in output.decode('utf-8') |
| 85 | + if not version_ok: |
83 | 86 | sublime.error_message(ver_warn)
|
84 | 87 |
|
85 | 88 | def on_post_save_async(self, view):
|
@@ -109,9 +112,17 @@ def record(self, view, path):
|
109 | 112 |
|
110 | 113 | try:
|
111 | 114 | cmd_output = subprocess.check_output(cmd, shell=True)
|
112 |
| - if GTM.status_option != "": |
113 |
| - view.set_status("gtm-statusbar", cmd_output.decode('utf-8')) |
| 115 | + if GTM.status_option: |
| 116 | + view.set_status( |
| 117 | + "gtm-statusbar", |
| 118 | + GTM.format_status(cmd_output)) |
114 | 119 | else:
|
115 | 120 | view.erase_status("gtm-statusbar")
|
116 | 121 | except subprocess.CalledProcessError as e:
|
117 | 122 | sublime.error_message(GTM.record_err)
|
| 123 | + |
| 124 | + def format_status(t): |
| 125 | + s = t.decode('utf-8').strip() |
| 126 | + if s: |
| 127 | + s = ' '.join(re.sub("\\s*\\d*s\\s*", "", s).split()) |
| 128 | + return "[ {0} ]".format(s) |
0 commit comments