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', src.vpath, { 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);
125 [ src.gitpath, 'add', src.vpath ],
126 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
127 [ src.gitpath , 'push', { all: true } ]
131 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
132 Git.run(src.gitpath , 'push', '--all' );
133 notify(src.name,"CHANGED", sp);
137 onDeleted : function(src)
140 if (this.shouldIgnore(src)) {
143 // should check if monitor needs removing..
144 // it should also check if it was a directory.. - so we dont have to commit all..
148 [ src.gitpath, 'rm' , src.vpath ],
149 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
150 [ src.gitpath, 'push', { all: true } ]
156 var sp = Git.run(src.gitpath,'rm' , src.vpath);
157 Git.run(src.gitpath , 'push', { all: true } );
159 notify(src.name,"DELETED", sp);
162 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
163 Git.run(src.gitpath , 'push',{ all: true });
164 notify(src.name,"DELETED", sp);
168 onCreated : function(src)
171 if (this.shouldIgnore(src)) {
175 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
176 this.just_created[src.path] = true;
177 return; // we do not handle file create flags... - use done hint.
179 // director has bee created
180 this.monitor(src.path);
183 [ src.gitpath, 'add' , src.vpath, { all: true } ],
184 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
185 [ src.gitpath, 'push', { all: true } ]
190 var sp = Git.run(src.gitpath, 'add', src.vpath);
191 Git.run(src.gitpath , 'push', { all: true } );
194 notify(src.path,"CREATED", sp);
197 //uh.call(fm,f,of, event_type);
198 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
199 Git.run(src.gitpath , 'push', { all: true } );
200 notify(src.path,"CREATED", sp);
204 onAttributeChanged : function(src) {
206 if (this.shouldIgnore(src)) {
210 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
211 [ src.gitpath, 'push', { all: true } ]
216 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
217 Git.run(src.gitpath , 'push', { all: true } );
218 notify(src.path,"ATTRIBUTE_CHANGED", sp);
223 onMoved : function(src,dest)
226 this.parsePath(dest);
228 if (src.gitpath != dest.gitpath) {
230 this.onCreated(dest);
231 this.onChangedDoneHint(dest);
234 // needs to handle move to/from unsupported types..
236 if (this.shouldIgnore(src)) {
239 if (this.shouldIgnore(dest)) {
243 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
244 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
245 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
246 [ src.gitpath, 'push', { all: true } ]
253 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
255 notify(dest.path,"MOVED", sp);
258 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
259 Git.run(src.gitpath , 'push', { all: true } );
260 notify(src.path,"MOVED", sp);
270 function notify(fn, act , sp)
272 var sum = act + " " + fn;
274 var notification = new Notify.Notification({
279 notification.set_timeout(500);
287 function errorDialog(data) {
288 var msg = new Gtk.MessageDialog({
289 message_type: Gtk.MessageType.ERROR,
290 buttons : Gtk.ButtonsType.OK,
302 // need a better icon...
305 Notify.init("gitlive");
306 monitor.add(GLib.get_home_dir() + "/gitlive");
309 //icon.signal["activate"].connect(on_left_click);