-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.py
More file actions
109 lines (97 loc) · 3.84 KB
/
loop.py
File metadata and controls
109 lines (97 loc) · 3.84 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import asyncore
import pyinotify
import client
import settings
from Tkinter import *
# Watches Directory specified by watch_dir
def watch_directory(watch_dir):
wm = pyinotify.WatchManager()
mask = pyinotify.IN_DELETE | pyinotify.IN_DELETE_SELF | pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVE_SELF | pyinotify.IN_OPEN | pyinotify.IN_MOVED_TO | pyinotify.IN_MOVED_FROM | pyinotify.IN_ISDIR
def isValid(filename):
a=filename.split('/');
if (a[-1][0]=='.' or a[-1][-1]=='~' or a[-1]== "4913" ): #4913???
return 0
else:
#Now check if the level is not too deep
root=settings.main_dir.split('/');
return len(a)>=len(root) and len(a) <= len(root) + 2
def isValidFolderDepth(filename):
a=filename.split('/');
root=settings.main_dir.split('/');
return len(a) <= len(root) + 1
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
filename=event.pathname
if (isValid(filename)):
#print "Adding:", filename, ", Folder: ", os.path.isdir(filename)
if (event.dir):
if (isValidFolderDepth(filename)):
client.add_folder(filename)
else:
pass
#client.add_file(filename) #Uncomment to create empty files
def process_IN_DELETE(self, event):
filename=event.pathname
if (isValid(filename)):
print "Removing:", filename
if (event.dir):
print "FOLDER"
if (isValidFolderDepth(filename)):
client.remove_folder(filename)
else:
print "FILE"
client.remove_file(filename)
def process_IN_CLOSE_WRITE(self, event):
filename=event.pathname
if (isValid(filename)):
#print "Close Write:",filename
client.add_file(filename)
def process_IN_MOVE_SELF(self, event):
pass
# print "Move Self:", event.pathname
def process_IN_MOVED_TO(self, event):
filename=event.pathname
if (isValid(filename)):
#print "Move From:", filename
if (event.dir):
if (isValidFolderDepth(filename)):
client.add_folder(filename)
else:
client.add_file(filename)
def process_IN_MOVED_FROM(self, event):
filename=event.pathname
if (isValid(filename)):
#print "Move From:", filename
if (event.dir):
if (isValidFolderDepth(filename)):
client.remove_folder(filename)
else:
client.remove_file(filename)
def process_IN_OPEN(self, event):
pass
# print "Open:", event.pathname
#notifier = pyinotify.AsyncNotifier(wm, EventHandler())
notifier = pyinotify.ThreadedNotifier(wm, EventHandler())
notifier.start()
wdd = wm.add_watch(watch_dir, mask, rec=True, auto_add = True)
#asyncore.loop()
print 'GUI Starting'
# Opens a popup where users can see status, pull etc
# Saves the details in secrets file
root = Tk()
root.title('DROPBOX!!')
root.minsize(width=200, height=100)
def onpull():
#Does a pull request
#notifier.stop()
client.pull()
#notifier.start()
def onclose():
notifier.stop()
root.destroy()
def onpush():
client.push()
Button(root, text='PULL', command=onpull).pack(side=LEFT)
Button(root, text='PUSH', command=onpush).pack(side=LEFT)
Button(root, text='CLOSE', command=onclose).pack(side= BOTTOM)
root.mainloop()