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 Monitor.prototype.start.call(this);
48 var notification = new Notify.Notification({
50 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
53 notification.set_timeout(500);
58 shouldIgnore: function(f)
60 if (f.name[0] == '.') {
62 if (f.name == '.htaccess') {
68 if (f.name.match(/~$/)) {
71 // ignore anything in top level!!!!
72 if (!f.vpath.length) {
80 parsePath: function(f) {
82 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
84 f.gitpath = gitlive + '/' + vpath_ar.shift();
85 f.vpath = vpath_ar.join('/');
92 onChanged : function(src)
94 return; // always ignore this..?
95 //this.parsePath(src);
97 onChangesDoneHint : function(src)
100 if (this.shouldIgnore(src)) {
105 if (typeof(this.just_created[src.path]) !='undefined') {
106 delete this.just_created[src.path];
109 [ src.gitpath, 'add', src.vpath ],
110 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
111 [ src.gitpath , 'push', { all: true } ]
116 Git.run(src.gitpath, 'add', src.vpath);
117 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
118 Git.run(src.gitpath , 'push', { all: true } );
119 notify(src.name,"CHANGED", sp);
124 //[ src.gitpath, 'add', src.vpath ],
125 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
126 [ src.gitpath , 'push', { all: true } ]
130 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
131 Git.run(src.gitpath , 'push', '--all' );
132 notify(src.name,"CHANGED", sp);
136 onDeleted : function(src)
139 if (this.shouldIgnore(src)) {
142 // should check if monitor needs removing..
143 // it should also check if it was a directory.. - so we dont have to commit all..
147 [ src.gitpath, 'rm' , src.vpath ],
148 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
149 [ src.gitpath, 'push', { all: true } ]
155 var sp = Git.run(src.gitpath,'rm' , src.vpath);
156 Git.run(src.gitpath , 'push', { all: true } );
158 notify(src.name,"DELETED", sp);
161 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
162 Git.run(src.gitpath , 'push',{ all: true });
163 notify(src.name,"DELETED", sp);
167 onCreated : function(src)
170 if (this.shouldIgnore(src)) {
174 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
175 this.just_created[src.path] = true;
176 return; // we do not handle file create flags... - use done hint.
178 // director has bee created
179 this.monitor(src.path);
182 [ src.gitpath, 'add' , src.vpath, { all: true } ],
183 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
184 [ src.gitpath, 'push', { all: true } ]
189 var sp = Git.run(src.gitpath, 'add', src.vpath);
190 Git.run(src.gitpath , 'push', { all: true } );
193 notify(src.path,"CREATED", sp);
196 //uh.call(fm,f,of, event_type);
197 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
198 Git.run(src.gitpath , 'push', { all: true } );
199 notify(src.path,"CREATED", sp);
203 onAttributeChanged : function(src) {
205 if (this.shouldIgnore(src)) {
209 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
210 [ src.gitpath, 'push', { all: true } ]
215 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
216 Git.run(src.gitpath , 'push', { all: true } );
217 notify(src.path,"ATTRIBUTE_CHANGED", sp);
222 onMoved : function(src,dest)
225 this.parsePath(dest);
227 if (src.gitpath != dest.gitpath) {
229 this.onCreated(dest);
230 this.onChangedDoneHint(dest);
233 // needs to handle move to/from unsupported types..
235 if (this.shouldIgnore(src)) {
238 if (this.shouldIgnore(dest)) {
242 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
243 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
244 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
245 [ src.gitpath, 'push', { all: true } ]
252 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
254 notify(dest.path,"MOVED", sp);
257 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
258 Git.run(src.gitpath , 'push', { all: true } );
259 notify(src.path,"MOVED", sp);
269 function notify(fn, act , sp)
271 var sum = act + " " + fn;
273 var notification = new Notify.Notification({
278 notification.set_timeout(500);
286 function errorDialog(data) {
287 var msg = new Gtk.MessageDialog({
288 message_type: Gtk.MessageType.ERROR,
289 buttons : Gtk.ButtonsType.OK,
301 // need a better icon...
304 Notify.init("gitlive");
305 monitor.add(GLib.get_home_dir() + "/gitlive");
308 //icon.signal["activate"].connect(on_left_click);