4
4
from time import time
6
from kupfer import pretty
7
import cPickle as pickle
9
from kupfer import pretty, config
10
from kupfer import scheduler
8
12
kupfer_env = "KUPFER_APP_ID"
40
44
screen = wnck.screen_get_default()
41
45
screen.get_windows_stacked()
46
scheduler.GetScheduler().connect("finish", self._finish)
49
def _get_filename(self):
51
return path.join(config.get_cache_home(),
52
"application_identification_v%d.pickle" % version)
54
reg = self._unpickle_register(self._get_filename())
55
self.register = reg if reg else {}
56
def _finish(self, sched):
57
self._pickle_register(self.register, self._get_filename())
58
def _unpickle_register(self, pickle_file):
60
pfile = open(pickle_file, "rb")
64
source = pickle.loads(pfile.read())
65
assert isinstance(source, dict), "Stored object not a dict"
66
self.output_debug("Reading from %s" % (pickle_file, ))
67
except (pickle.PickleError, Exception), e:
69
self.output_info("Error loading %s: %s" % (pickle_file, e))
72
def _pickle_register(self, reg, pickle_file):
73
output = open(pickle_file, "wb")
74
self.output_debug("Saving to %s" % (pickle_file, ))
75
output.write(pickle.dumps(reg, pickle.HIGHEST_PROTOCOL))
42
79
def _store(self, app_id, application):
43
80
self.register[app_id] = application.get_name()
44
81
self.output_debug("storing", app_id, "as", application.get_name())
50
87
return self.register[app_id] == application.get_name()
52
89
def launched_application(self, app_id):
90
if self._has_match(app_id):
53
92
timeout = time() + 10
55
94
gobject.timeout_add_seconds(2, self._find_application, app_id, timeout, envcache)