forked from SublimeText/GenerateUUID
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_uuid.py
More file actions
46 lines (40 loc) · 1.64 KB
/
generate_uuid.py
File metadata and controls
46 lines (40 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sublime
import sublime_plugin
import uuid
class GenerateUuidCommand(sublime_plugin.TextCommand):
"""
Generate a UUID version 4.
Plugin logic for the 'generate_uuid' command.
Searches for "uuid_uppercase" setting in user preferences, capitalizes
UUID if true. - author Matt Morrison mattdmo@pigimal.com
Author: Eric Hamiter
Seealso: https://github.com/ehamiter/Sublime-Text-2-Plugins
"""
def run(self, edit):
for r in self.view.sel():
settings = sublime.load_settings('Preferences.sublime-settings')
if settings.get('uuid_uppercase'):
value = str(uuid.uuid4()).upper()
else:
value = str(uuid.uuid4())
self.view.replace(edit, r, value)
class GenerateUuidListenerCommand(sublime_plugin.EventListener):
"""
Expand 'uuid' and 'uuid4' to a random uuid (uuid4) and
'uuid1' to a uuid based on host and current time (uuid1).
Searches for "uuid_uppercase" setting in user preferences, capitalizes
UUID if true. - author Matt Morrison mattdmo@pigimal.com
Author: Rob Cowie
Seealso: https://github.com/SublimeText/GenerateUUID/issues/1
"""
def on_query_completions(self, view, prefix, locations):
if prefix in ('uuid', 'uuid4'): # random
val = uuid.uuid4()
elif prefix == 'uuid1': # host and current time
val = uuid.uuid1()
else:
return []
settings = sublime.load_settings('Preferences.sublime-settings')
if settings.get('uuid_uppercase'):
val = str(val).upper()
return [(prefix, prefix, val)] if val else []