forked from jisaacks/GitGutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_collection.py
64 lines (54 loc) · 1.86 KB
/
view_collection.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import tempfile
import time
class ViewCollection:
views = {}
git_times = {}
git_files = {}
buf_files = {}
@staticmethod
def add(view):
key = ViewCollection.get_key(view)
try:
from GitGutter.git_gutter_handler import GitGutterHandler
except ImportError:
from git_gutter_handler import GitGutterHandler
ViewCollection.views[key] = GitGutterHandler(view)
ViewCollection.views[key].reset()
@staticmethod
def git_path(view):
key = ViewCollection.get_key(view)
if key in ViewCollection.views:
return ViewCollection.views[key].get_git_path()
else:
return False
@staticmethod
def get_key(view):
return view.file_name()
@staticmethod
def diff(view):
key = ViewCollection.get_key(view)
return ViewCollection.views[key].diff()
@staticmethod
def git_time(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.git_times:
ViewCollection.git_times[key] = 0
return time.time() - ViewCollection.git_times[key]
@staticmethod
def update_git_time(view):
key = ViewCollection.get_key(view)
ViewCollection.git_times[key] = time.time()
@staticmethod
def git_tmp_file(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.git_files:
ViewCollection.git_files[key] = tempfile.NamedTemporaryFile()
ViewCollection.git_files[key].close()
return ViewCollection.git_files[key]
@staticmethod
def buf_tmp_file(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.buf_files:
ViewCollection.buf_files[key] = tempfile.NamedTemporaryFile()
ViewCollection.buf_files[key].close()
return ViewCollection.buf_files[key]