Permalink
Browse files

Merged package refactoring

  • Loading branch information...
2 parents 7a2e69b + 0e9328e commit 7defb1d4211556ea98c597c7cae6319ee6cae622 David Fendrich committed Dec 18, 2012
View
@@ -1 +1,4 @@
-*.pyc
+*.pyc
+*.egg-info
+dist/
+build/
View
@@ -2,7 +2,6 @@ SQLAlchemy==0.7.6
lockfile==0.9.1
pycrypto==2.5
python-daemon==1.6
+pyobjc-core==2.4
pyobjc==2.4
-pyobjc-framework-Cocoa==2.4
-pyobjc-framework-Quartz==2.4
-pyobjc-framework-CoreData==2.4
+
@@ -30,9 +30,9 @@
import hashlib
from Crypto.Cipher import Blowfish
-from activity_store import ActivityStore
-from password_dialog import get_password
-import check_password
+from selfspy.activity_store import ActivityStore
+from selfspy.password_dialog import get_password
+from selfspy import check_password
DATA_DIR = '~/.selfspy'
@@ -72,7 +72,8 @@ def make_encrypter(password):
encrypter = Blowfish.new(hashlib.md5(password).digest())
return encrypter
-if __name__ == '__main__':
+
+def main():
args = vars(parse_config())
args['data_dir'] = os.path.expanduser(args['data_dir'])
@@ -117,6 +118,7 @@ def check_with_encrypter(password):
print 'Password failed'
sys.exit(1)
+<<<<<<< HEAD:selfspy.py
if args['change_password']:
new_password = get_password(message="New Password: ")
new_encrypter = make_encrypter(new_password)
@@ -135,8 +137,16 @@ def check_with_encrypter(password):
astore = ActivityStore(os.path.join(args['data_dir'], DBNAME),
encrypter,
store_text=(not args['no_text']))
+=======
+ astore = ActivityStore(os.path.join(args['data_dir'], DBNAME),
+ encrypter, store_text=(not args['no_text']))
+>>>>>>> marksteve/master:selfspy/__init__.py
try:
astore.run()
except SystemExit:
astore.close()
+
+
+if __name__ == '__main__':
+ main()
@@ -23,12 +23,12 @@
import platform
if platform.system() == 'Darwin':
- import sniff_cocoa
+ from selfspy import sniff_cocoa
else:
- import sniff_x
+ from selfspy import sniff_x
-import models
-from models import Process, Window, Geometry, Click, Keys
+from selfspy import models
+from selfspy.models import Process, Window, Geometry, Click, Keys
SKIP_MODIFIERS = {"", "Shift_L", "Control_L", "Super_L", "Alt_L", "Super_R", "Control_R", "Shift_R", "[65027]"} # [65027] is AltGr in X for some ungodly reason.
@@ -40,17 +40,17 @@
class Display:
def __init__(self):
self.proc_id = None
- self.win_id = None
+ self.win_id = None
self.geo_id = None
-
+
class KeyPress:
def __init__(self, key, time, is_repeat):
self.key = key
self.time = time
self.is_repeat = is_repeat
-
+
class ActivityStore:
def __init__(self, db_name, encrypter=None, store_text=True):
self.session_maker = models.initialize(db_name)
@@ -62,13 +62,17 @@ def __init__(self, db_name, encrypter=None, store_text=True):
self.key_presses = []
self.mouse_path = []
-
+
self.current_window = Display()
+<<<<<<< HEAD:activity_store.py
self.last_scroll = {button: 0 for button in SCROLL_BUTTONS}
self.last_key_time = time.time()
self.last_commit = time.time()
+=======
+ self.last_key_time = time.time()
+>>>>>>> marksteve/master:selfspy/activity_store.py
self.started = NOW()
def trycommit(self):
@@ -98,7 +102,7 @@ def got_screen_change(self, process_name, window_name, win_x, win_y, win_width,
""" Receives a screen change and stores any changes. If the process or window has
changed it will also store any queued pressed keys.
process_name is the name of the process running the current window
- window_name is the name of the window
+ window_name is the name of the window
win_x is the x position of the window
win_y is the y position of the window
win_width is the width of the window
@@ -107,15 +111,15 @@ def got_screen_change(self, process_name, window_name, win_x, win_y, win_width,
if not cur_process:
cur_process = Process(process_name)
self.session.add(cur_process)
-
- cur_geometry = self.session.query(Geometry).filter_by(xpos=win_x,
- ypos=win_y,
- width=win_width,
+
+ cur_geometry = self.session.query(Geometry).filter_by(xpos=win_x,
+ ypos=win_y,
+ width=win_width,
height=win_height).scalar()
if not cur_geometry:
cur_geometry = Geometry(win_x, win_y, win_width, win_height)
self.session.add(cur_geometry)
-
+
cur_window = self.session.query(Window).filter_by(title=window_name,
process_id=cur_process.id).scalar()
if not cur_window:
@@ -139,7 +143,7 @@ def filter_many(self):
if specials_in_row and key != lastpress.key:
if specials_in_row > 1:
lastpress.key = '%s]x%d>' % (lastpress.key[:-2], specials_in_row)
-
+
newpresses.append(lastpress)
specials_in_row = 0
@@ -148,31 +152,31 @@ def filter_many(self):
lastpress = press
else:
newpresses.append(press)
-
+
if specials_in_row:
if specials_in_row > 1:
lastpress.key = '%s]x%d>' % (lastpress.key[:-2], specials_in_row)
newpresses.append(lastpress)
self.key_presses = newpresses
-
+
def store_keys(self):
""" Stores the current queued key-presses """
self.filter_many()
-
+
if self.key_presses:
keys = [press.key for press in self.key_presses]
timings = [press.time for press in self.key_presses]
add = lambda count, press: count + (0 if press.is_repeat else 1)
nrkeys = reduce(add, self.key_presses, 0)
-
+
curtext = u""
if not self.store_text:
keys = []
else:
curtext = ''.join(keys)
- self.session.add(Keys(curtext.encode('utf8'),
+ self.session.add(Keys(curtext.encode('utf8'),
keys,
timings,
nrkeys,
@@ -186,7 +190,7 @@ def store_keys(self):
self.started = NOW()
self.key_presses = []
self.last_key_time = time.time()
-
+
def got_key(self, keycode, state, string, is_repeat):
""" Receives key-presses and queues them for storage.
keycode is the code sent by the keyboard to represent the pressed key
@@ -210,12 +214,12 @@ def got_key(self, keycode, state, string, is_repeat):
def store_click(self, button, x, y):
""" Stores incoming mouse-clicks """
- self.session.add(Click(button,
- True,
+ self.session.add(Click(button,
+ True,
x, y,
len(self.mouse_path),
self.current_window.proc_id,
- self.current_window.win_id,
+ self.current_window.win_id,
self.current_window.geo_id))
self.mouse_path = []
self.trycommit()
@@ -236,7 +240,7 @@ def got_mouse_move(self, x, y):
""" Queues mouse movements.
x,y are the new coorinates on moving the mouse"""
self.mouse_path.append([x, y])
-
+
def close(self):
""" stops the sniffer and stores the latest keys. To be used on shutdown of program"""
self.sniffer.cancel()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.

0 comments on commit 7defb1d

Please sign in to comment.