Skip to content

Commit 782fd37

Browse files
committed
upgrade wakatime-cli to v12.0.0
1 parent 40dbc16 commit 782fd37

File tree

4 files changed

+83
-37
lines changed

4 files changed

+83
-37
lines changed

packages/wakatime/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__title__ = 'wakatime'
22
__description__ = 'Common interface to the WakaTime api.'
33
__url__ = 'https://github.com/wakatime/wakatime'
4-
__version_info__ = ('11', '0', '0')
4+
__version_info__ = ('12', '0', '0')
55
__version__ = '.'.join(__version_info__)
66
__author__ = 'Alan Hamlett'
77
__author_email__ = '[email protected]'

packages/wakatime/arguments.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def parse_arguments():
153153
'folder name as the project, a ' +
154154
'.wakatime-project file is created with a ' +
155155
'random project name.')
156+
parser.add_argument('--hide-branch-names', dest='hide_branch_names',
157+
action='store_true',
158+
help='Obfuscate branch names. Will not send revision ' +
159+
'control branch names to api.')
156160
parser.add_argument('--exclude', dest='exclude', action='append',
157161
help='Filename patterns to exclude from logging. ' +
158162
'POSIX regex syntax. Can be used more than once.')
@@ -294,8 +298,9 @@ def parse_arguments():
294298
pass
295299
if not args.exclude_unknown_project and configs.has_option('settings', 'exclude_unknown_project'):
296300
args.exclude_unknown_project = configs.getboolean('settings', 'exclude_unknown_project')
297-
boolean_or_list('hide_file_names', args, configs, alternative_names=['hide_filenames', 'hidefilenames'])
298-
boolean_or_list('hide_project_names', args, configs, alternative_names=['hide_projectnames', 'hideprojectnames'])
301+
_boolean_or_list('hide_file_names', args, configs, alternative_names=['hide_filenames', 'hidefilenames'])
302+
_boolean_or_list('hide_project_names', args, configs, alternative_names=['hide_projectnames', 'hideprojectnames'])
303+
_boolean_or_list('hide_branch_names', args, configs, alternative_names=['hide_branchnames', 'hidebranchnames'], default=None)
299304
if args.offline_deprecated:
300305
args.offline = False
301306
if args.offline and configs.has_option('settings', 'offline'):
@@ -340,7 +345,7 @@ def parse_arguments():
340345
return args, configs
341346

342347

343-
def boolean_or_list(config_name, args, configs, alternative_names=[]):
348+
def _boolean_or_list(config_name, args, configs, alternative_names=[], default=[]):
344349
"""Get a boolean or list of regexes from args and configs."""
345350

346351
# when argument flag present, set to wildcard regex
@@ -349,7 +354,7 @@ def boolean_or_list(config_name, args, configs, alternative_names=[]):
349354
setattr(args, config_name, ['.*'])
350355
return
351356

352-
setattr(args, config_name, [])
357+
setattr(args, config_name, default)
353358

354359
option = None
355360
alternative_names.insert(0, config_name)
@@ -361,7 +366,11 @@ def boolean_or_list(config_name, args, configs, alternative_names=[]):
361366
if option is not None:
362367
if option.strip().lower() == 'true':
363368
setattr(args, config_name, ['.*'])
364-
elif option.strip().lower() != 'false':
369+
elif option.strip().lower() == 'false':
370+
setattr(args, config_name, [])
371+
else:
365372
for pattern in option.split("\n"):
366373
if pattern.strip() != '':
374+
if not getattr(args, config_name):
375+
setattr(args, config_name, [])
367376
getattr(args, config_name).append(pattern)

packages/wakatime/heartbeat.py

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ class Heartbeat(object):
4343
cursorpos = None
4444
user_agent = None
4545

46-
_sensitive = ('dependencies', 'lines', 'lineno', 'cursorpos', 'branch')
46+
_sensitive_when_hiding_filename = (
47+
'dependencies',
48+
'lines',
49+
'lineno',
50+
'cursorpos',
51+
)
52+
_sensitive_when_hiding_branch = (
53+
'branch',
54+
)
4755

4856
def __init__(self, data, args, configs, _clone=None):
4957
if not data:
@@ -141,21 +149,24 @@ def sanitize(self):
141149
Returns a Heartbeat.
142150
"""
143151

144-
if not self.args.hide_file_names:
145-
return self
146-
147152
if self.entity is None:
148153
return self
149154

150155
if self.type != 'file':
151156
return self
152157

153-
if self.should_obfuscate_filename():
154-
self._sanitize_metadata()
158+
if self._should_obfuscate_filename():
159+
self._sanitize_metadata(keys=self._sensitive_when_hiding_filename)
160+
if self._should_obfuscate_branch(default=True):
161+
self._sanitize_metadata(keys=self._sensitive_when_hiding_branch)
155162
extension = u(os.path.splitext(self.entity)[1])
156163
self.entity = u('HIDDEN{0}').format(extension)
157164
elif self.should_obfuscate_project():
158-
self._sanitize_metadata()
165+
self._sanitize_metadata(keys=self._sensitive_when_hiding_filename)
166+
if self._should_obfuscate_branch(default=True):
167+
self._sanitize_metadata(keys=self._sensitive_when_hiding_branch)
168+
elif self._should_obfuscate_branch():
169+
self._sanitize_metadata(keys=self._sensitive_when_hiding_branch)
159170

160171
return self
161172

@@ -193,7 +204,24 @@ def get_id(self):
193204
is_write=self.is_write,
194205
)
195206

196-
def should_obfuscate_filename(self):
207+
def should_obfuscate_project(self):
208+
"""Returns True if hide_project_names is true or the entity file path
209+
matches one in the list of obfuscated project paths."""
210+
211+
for pattern in self.args.hide_project_names:
212+
try:
213+
compiled = re.compile(pattern, re.IGNORECASE)
214+
if compiled.search(self.entity):
215+
return True
216+
except re.error as ex:
217+
log.warning(u('Regex error ({msg}) for hide_project_names pattern: {pattern}').format(
218+
msg=u(ex),
219+
pattern=u(pattern),
220+
))
221+
222+
return False
223+
224+
def _should_obfuscate_filename(self):
197225
"""Returns True if hide_file_names is true or the entity file path
198226
matches one in the list of obfuscated file paths."""
199227

@@ -207,22 +235,32 @@ def should_obfuscate_filename(self):
207235
msg=u(ex),
208236
pattern=u(pattern),
209237
))
238+
210239
return False
211240

212-
def should_obfuscate_project(self):
213-
"""Returns True if hide_project_names is true or the entity file path
214-
matches one in the list of obfuscated project paths."""
241+
def _should_obfuscate_branch(self, default=False):
242+
"""Returns True if hide_file_names is true or the entity file path
243+
matches one in the list of obfuscated file paths."""
215244

216-
for pattern in self.args.hide_project_names:
245+
# when project names or file names are hidden and hide_branch_names is
246+
# not set, we default to hiding branch names along with file/project.
247+
if default and self.args.hide_branch_names is None:
248+
return True
249+
250+
if not self.branch or not self.args.hide_branch_names:
251+
return False
252+
253+
for pattern in self.args.hide_branch_names:
217254
try:
218255
compiled = re.compile(pattern, re.IGNORECASE)
219-
if compiled.search(self.entity):
256+
if compiled.search(self.entity) or compiled.search(self.branch):
220257
return True
221258
except re.error as ex:
222-
log.warning(u('Regex error ({msg}) for hide_project_names pattern: {pattern}').format(
259+
log.warning(u('Regex error ({msg}) for hide_branch_names pattern: {pattern}').format(
223260
msg=u(ex),
224261
pattern=u(pattern),
225262
))
263+
226264
return False
227265

228266
def _unicode(self, value):
@@ -333,8 +371,8 @@ def _excluded_by_missing_project_file(self):
333371
return False
334372
return find_project_file(self.entity) is None
335373

336-
def _sanitize_metadata(self):
337-
for key in self._sensitive:
374+
def _sanitize_metadata(self, keys=[]):
375+
for key in keys:
338376
setattr(self, key, None)
339377

340378
def __repr__(self):

packages/wakatime/project.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,32 @@ def get_project_info(configs, heartbeat, data):
6969
project_name = data.get('project') or heartbeat.args.project
7070

7171
hide_project = heartbeat.should_obfuscate_project()
72-
if hide_project and project_name is not None:
73-
return project_name, None
7472

7573
if project_name is None or branch_name is None:
7674

7775
for plugin_cls in REV_CONTROL_PLUGINS:
7876

7977
plugin_name = plugin_cls.__name__.lower()
8078
plugin_configs = get_configs_for_plugin(plugin_name, configs)
81-
8279
project = plugin_cls(heartbeat.entity, configs=plugin_configs)
80+
8381
if project.process():
84-
project_name = project_name or project.name()
82+
if not hide_project:
83+
project_name = project_name or project.name()
8584
branch_name = branch_name or project.branch()
86-
if hide_project:
87-
branch_name = None
88-
project_name = generate_project_name()
89-
project_file = os.path.join(project.folder(), '.wakatime-project')
90-
try:
91-
with open(project_file, 'w') as fh:
92-
fh.write(project_name)
93-
except IOError:
94-
project_name = None
9585
break
9686

97-
if project_name is None and not hide_project:
98-
project_name = data.get('alternate_project') or heartbeat.args.alternate_project
87+
if project_name is None:
88+
if not hide_project:
89+
project_name = data.get('alternate_project') or heartbeat.args.alternate_project
90+
else:
91+
project_name = generate_project_name()
92+
project_file = os.path.join(project.folder(), '.wakatime-project')
93+
try:
94+
with open(project_file, 'w') as fh:
95+
fh.write(project_name)
96+
except IOError:
97+
project_name = None
9998

10099
return project_name, branch_name
101100

0 commit comments

Comments
 (0)