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();
49 Glib.idle_add(PRIORITY_LOW, function() {
50 if (!_this.queue.length) {
53 Math.floor(((new Date()) - this.lastAdd) / 100)
57 Monitor.prototype.start.call(this);
58 var notification = new Notify.Notification({
60 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
63 notification.set_timeout(500);
68 shouldIgnore: function(f)
70 if (f.name[0] == '.') {
72 if (f.name == '.htaccess') {
78 if (f.name.match(/~$/)) {
81 // ignore anything in top level!!!!
82 if (!f.vpath.length) {
90 parsePath: function(f) {
92 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
94 f.gitpath = gitlive + '/' + vpath_ar.shift();
95 f.vpath = vpath_ar.join('/');
102 onChanged : function(src)
104 return; // always ignore this..?
105 //this.parsePath(src);
107 onChangesDoneHint : function(src)
110 if (this.shouldIgnore(src)) {
115 if (typeof(this.just_created[src.path]) !='undefined') {
116 delete this.just_created[src.path];
117 this.lastAdd = new Date();
119 [ src.gitpath, 'add', src.vpath ],
120 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
121 [ src.gitpath , 'push', { all: true } ]
126 Git.run(src.gitpath, 'add', src.vpath);
127 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
128 Git.run(src.gitpath , 'push', { all: true } );
129 notify(src.name,"CHANGED", sp);
133 this.lastAdd = new Date();
135 [ src.gitpath, 'add', src.vpath ],
136 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
137 [ src.gitpath , 'push', { all: true } ]
141 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
142 Git.run(src.gitpath , 'push', '--all' );
143 notify(src.name,"CHANGED", sp);
147 onDeleted : function(src)
150 if (this.shouldIgnore(src)) {
153 // should check if monitor needs removing..
154 // it should also check if it was a directory.. - so we dont have to commit all..
156 this.lastAdd = new Date();
158 [ src.gitpath, 'rm' , src.vpath ],
159 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
160 [ src.gitpath, 'push', { all: true } ]
166 var sp = Git.run(src.gitpath,'rm' , src.vpath);
167 Git.run(src.gitpath , 'push', { all: true } );
169 notify(src.name,"DELETED", sp);
172 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
173 Git.run(src.gitpath , 'push',{ all: true });
174 notify(src.name,"DELETED", sp);
178 onCreated : function(src)
181 if (this.shouldIgnore(src)) {
185 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
186 this.just_created[src.path] = true;
187 return; // we do not handle file create flags... - use done hint.
189 // director has bee created
190 this.monitor(src.path);
191 this.lastAdd = new Date();
193 [ src.gitpath, 'add' , src.vpath, { all: true } ],
194 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
195 [ src.gitpath, 'push', { all: true } ]
200 var sp = Git.run(src.gitpath, 'add', src.vpath);
201 Git.run(src.gitpath , 'push', { all: true } );
204 notify(src.path,"CREATED", sp);
207 //uh.call(fm,f,of, event_type);
208 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
209 Git.run(src.gitpath , 'push', { all: true } );
210 notify(src.path,"CREATED", sp);
214 onAttributeChanged : function(src) {
216 if (this.shouldIgnore(src)) {
219 this.lastAdd = new Date();
221 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
222 [ src.gitpath, 'push', { all: true } ]
227 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
228 Git.run(src.gitpath , 'push', { all: true } );
229 notify(src.path,"ATTRIBUTE_CHANGED", sp);
234 onMoved : function(src,dest)
237 this.parsePath(dest);
239 if (src.gitpath != dest.gitpath) {
241 this.onCreated(dest);
242 this.onChangedDoneHint(dest);
245 // needs to handle move to/from unsupported types..
247 if (this.shouldIgnore(src)) {
250 if (this.shouldIgnore(dest)) {
253 this.lastAdd = new Date();
255 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
256 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
257 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
258 [ src.gitpath, 'push', { all: true } ]
265 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
267 notify(dest.path,"MOVED", sp);
270 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
271 Git.run(src.gitpath , 'push', { all: true } );
272 notify(src.path,"MOVED", sp);
282 function notify(fn, act , sp)
284 var sum = act + " " + fn;
286 var notification = new Notify.Notification({
291 notification.set_timeout(500);
299 function errorDialog(data) {
300 var msg = new Gtk.MessageDialog({
301 message_type: Gtk.MessageType.ERROR,
302 buttons : Gtk.ButtonsType.OK,
314 // need a better icon...
317 Notify.init("gitlive");
318 monitor.add(GLib.get_home_dir() + "/gitlive");
321 //icon.signal["activate"].connect(on_left_click);