2 ///<script type="text/javascript">
6 * inotify hooks for ~/gitlive
7 * that commit and push any changes made.
8 * Bit like a revision controled backed up file system!?
12 GI = imports.gi.GIRepository;
14 GLib = imports.gi.GLib;
16 Notify = imports.gi.Notify;
18 Spawn = imports.Spawn;
20 StatusIcon = imports.StatusIcon.StatusIcon;
21 Monitor = imports.Monitor.Monitor;
24 //File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
25 Gtk.init (null, null);
27 var gitlive = GLib.get_home_dir() + "/gitlive";
29 if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
30 var msg = new Gtk.MessageDialog({message_type:
31 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
40 var monitor = new Monitor({
43 nqv : true, // temp var while I switch to queued version.
47 this.lastAdd = new Date();
48 Glib.idle_add(PRIORITY_LOW, function() {
51 Monitor.prototype.start.call(this);
52 var notification = new Notify.Notification({
54 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
57 notification.set_timeout(500);
62 shouldIgnore: function(f)
64 if (f.name[0] == '.') {
66 if (f.name == '.htaccess') {
72 if (f.name.match(/~$/)) {
75 // ignore anything in top level!!!!
76 if (!f.vpath.length) {
84 parsePath: function(f) {
86 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
88 f.gitpath = gitlive + '/' + vpath_ar.shift();
89 f.vpath = vpath_ar.join('/');
96 onChanged : function(src)
98 return; // always ignore this..?
99 //this.parsePath(src);
101 onChangesDoneHint : function(src)
104 if (this.shouldIgnore(src)) {
109 if (typeof(this.just_created[src.path]) !='undefined') {
110 delete this.just_created[src.path];
111 this.lastAdd = new Date();
113 [ src.gitpath, 'add', src.vpath ],
114 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
115 [ src.gitpath , 'push', { all: true } ]
120 Git.run(src.gitpath, 'add', src.vpath);
121 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
122 Git.run(src.gitpath , 'push', { all: true } );
123 notify(src.name,"CHANGED", sp);
127 this.lastAdd = new Date();
129 [ src.gitpath, 'add', src.vpath ],
130 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
131 [ src.gitpath , 'push', { all: true } ]
135 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
136 Git.run(src.gitpath , 'push', '--all' );
137 notify(src.name,"CHANGED", sp);
141 onDeleted : function(src)
144 if (this.shouldIgnore(src)) {
147 // should check if monitor needs removing..
148 // it should also check if it was a directory.. - so we dont have to commit all..
150 this.lastAdd = new Date();
152 [ src.gitpath, 'rm' , src.vpath ],
153 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
154 [ src.gitpath, 'push', { all: true } ]
160 var sp = Git.run(src.gitpath,'rm' , src.vpath);
161 Git.run(src.gitpath , 'push', { all: true } );
163 notify(src.name,"DELETED", sp);
166 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
167 Git.run(src.gitpath , 'push',{ all: true });
168 notify(src.name,"DELETED", sp);
172 onCreated : function(src)
175 if (this.shouldIgnore(src)) {
179 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
180 this.just_created[src.path] = true;
181 return; // we do not handle file create flags... - use done hint.
183 // director has bee created
184 this.monitor(src.path);
185 this.lastAdd = new Date();
187 [ src.gitpath, 'add' , src.vpath, { all: true } ],
188 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
189 [ src.gitpath, 'push', { all: true } ]
194 var sp = Git.run(src.gitpath, 'add', src.vpath);
195 Git.run(src.gitpath , 'push', { all: true } );
198 notify(src.path,"CREATED", sp);
201 //uh.call(fm,f,of, event_type);
202 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
203 Git.run(src.gitpath , 'push', { all: true } );
204 notify(src.path,"CREATED", sp);
208 onAttributeChanged : function(src) {
210 if (this.shouldIgnore(src)) {
213 this.lastAdd = new Date();
215 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
216 [ src.gitpath, 'push', { all: true } ]
221 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
222 Git.run(src.gitpath , 'push', { all: true } );
223 notify(src.path,"ATTRIBUTE_CHANGED", sp);
228 onMoved : function(src,dest)
231 this.parsePath(dest);
233 if (src.gitpath != dest.gitpath) {
235 this.onCreated(dest);
236 this.onChangedDoneHint(dest);
239 // needs to handle move to/from unsupported types..
241 if (this.shouldIgnore(src)) {
244 if (this.shouldIgnore(dest)) {
247 this.lastAdd = new Date();
249 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
250 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
251 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
252 [ src.gitpath, 'push', { all: true } ]
259 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
261 notify(dest.path,"MOVED", sp);
264 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
265 Git.run(src.gitpath , 'push', { all: true } );
266 notify(src.path,"MOVED", sp);
276 function notify(fn, act , sp)
278 var sum = act + " " + fn;
280 var notification = new Notify.Notification({
285 notification.set_timeout(500);
293 function errorDialog(data) {
294 var msg = new Gtk.MessageDialog({
295 message_type: Gtk.MessageType.ERROR,
296 buttons : Gtk.ButtonsType.OK,
308 // need a better icon...
311 Notify.init("gitlive");
312 monitor.add(GLib.get_home_dir() + "/gitlive");
315 //icon.signal["activate"].connect(on_left_click);