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 Glib.idle_add(PRIORITY_LOW, function() {
50 Monitor.prototype.start.call(this);
51 var notification = new Notify.Notification({
53 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
56 notification.set_timeout(500);
61 shouldIgnore: function(f)
63 if (f.name[0] == '.') {
65 if (f.name == '.htaccess') {
71 if (f.name.match(/~$/)) {
74 // ignore anything in top level!!!!
75 if (!f.vpath.length) {
83 parsePath: function(f) {
85 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
87 f.gitpath = gitlive + '/' + vpath_ar.shift();
88 f.vpath = vpath_ar.join('/');
95 onChanged : function(src)
97 return; // always ignore this..?
98 //this.parsePath(src);
100 onChangesDoneHint : function(src)
103 if (this.shouldIgnore(src)) {
108 if (typeof(this.just_created[src.path]) !='undefined') {
109 delete this.just_created[src.path];
112 [ src.gitpath, 'add', src.vpath ],
113 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
114 [ src.gitpath , 'push', { all: true } ]
119 Git.run(src.gitpath, 'add', src.vpath);
120 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
121 Git.run(src.gitpath , 'push', { all: true } );
122 notify(src.name,"CHANGED", sp);
128 [ src.gitpath, 'add', src.vpath ],
129 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ],
130 [ src.gitpath , 'push', { all: true } ]
134 var sp = Git.run(src.gitpath, 'commit', { all: true, message: src.vpath});
135 Git.run(src.gitpath , 'push', '--all' );
136 notify(src.name,"CHANGED", sp);
140 onDeleted : function(src)
143 if (this.shouldIgnore(src)) {
146 // should check if monitor needs removing..
147 // it should also check if it was a directory.. - so we dont have to commit all..
151 [ src.gitpath, 'rm' , src.vpath ],
152 [ src.gitpath, 'commit', { all: true, message: src.vpath} ],
153 [ src.gitpath, 'push', { all: true } ]
159 var sp = Git.run(src.gitpath,'rm' , src.vpath);
160 Git.run(src.gitpath , 'push', { all: true } );
162 notify(src.name,"DELETED", sp);
165 sp = Git.run(src.gitpath,'commit' ,{ all: true, message: src.vpath});
166 Git.run(src.gitpath , 'push',{ all: true });
167 notify(src.name,"DELETED", sp);
171 onCreated : function(src)
174 if (this.shouldIgnore(src)) {
178 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
179 this.just_created[src.path] = true;
180 return; // we do not handle file create flags... - use done hint.
182 // director has bee created
183 this.monitor(src.path);
186 [ src.gitpath, 'add' , src.vpath, { all: true } ],
187 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ],
188 [ src.gitpath, 'push', { all: true } ]
193 var sp = Git.run(src.gitpath, 'add', src.vpath);
194 Git.run(src.gitpath , 'push', { all: true } );
197 notify(src.path,"CREATED", sp);
200 //uh.call(fm,f,of, event_type);
201 sp = Git.run(src.gitpath,'commit' , { all: true, message: src.vpath});
202 Git.run(src.gitpath , 'push', { all: true } );
203 notify(src.path,"CREATED", sp);
207 onAttributeChanged : function(src) {
209 if (this.shouldIgnore(src)) {
213 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ],
214 [ src.gitpath, 'push', { all: true } ]
219 var sp = Git.run(src.gitpath, 'commit',{ all: true, message: src.vpath});
220 Git.run(src.gitpath , 'push', { all: true } );
221 notify(src.path,"ATTRIBUTE_CHANGED", sp);
226 onMoved : function(src,dest)
229 this.parsePath(dest);
231 if (src.gitpath != dest.gitpath) {
233 this.onCreated(dest);
234 this.onChangedDoneHint(dest);
237 // needs to handle move to/from unsupported types..
239 if (this.shouldIgnore(src)) {
242 if (this.shouldIgnore(dest)) {
246 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
247 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
248 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ],
249 [ src.gitpath, 'push', { all: true } ]
256 var sp = Git.run(src.gitpath, 'mv', '-k', src.vpath, dest.vpath);
258 notify(dest.path,"MOVED", sp);
261 sp = Git.run(src.gitpath,'commit' , { all: true, message: 'MOVED ' + src.vpath +' to ' + dest.vpath} );
262 Git.run(src.gitpath , 'push', { all: true } );
263 notify(src.path,"MOVED", sp);
273 function notify(fn, act , sp)
275 var sum = act + " " + fn;
277 var notification = new Notify.Notification({
282 notification.set_timeout(500);
290 function errorDialog(data) {
291 var msg = new Gtk.MessageDialog({
292 message_type: Gtk.MessageType.ERROR,
293 buttons : Gtk.ButtonsType.OK,
305 // need a better icon...
308 Notify.init("gitlive");
309 monitor.add(GLib.get_home_dir() + "/gitlive");
312 //icon.signal["activate"].connect(on_left_click);