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."});
39 var monitor = new Monitor({
46 this.lastAdd = new Date();
48 GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
49 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
50 if (!_this.queue.length || _this.queueRunning) {
53 var last = Math.floor(((new Date()) - this.lastAdd) / 100);
54 if (last < 4) { // wait 1/2 a seconnd before running.
61 Monitor.prototype.start.call(this);
62 var notification = new Notify.Notification({
64 body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
67 notification.set_timeout(2000);
72 * - pulls the items off the queue
73 * (as commands run concurrently and new items may get added while it's running)
74 * - runs the queue items
80 this.queueRunning = true;
82 this.queue.forEach(function (q) {
85 this.queue = []; // empty queue!
90 cmds.forEach(function(cmd) {
91 if (repos.indexOf(cmd[0]) < 0) {
93 Git.run(cmd[0] , 'pull'); // pull before we push!
95 var sp = Git.run.apply(Git,cmd);
97 switch (sp.result * 1) {
99 success.push(sp.args.join(' '));
100 if (sp.output.length) success.push(sp.output + '');
101 // if (sp.stderr.length) success.push(sp.stderr + '');
104 failure.push(sp.args.join(' '));
105 if (sp.output.length) failure.push(sp.output);
106 if (sp.stderr.length) failure.push(sp.stderr);
113 repos.forEach(function(r) {
114 var sp = Git.run(r , 'push', { all: true } );
121 if (success.length) {
122 print(success.join("\n"));
123 var notification = new Notify.Notification({
124 summary: "Git Live Commited",
125 body : success.join("\n")
129 notification.set_timeout(2000);
132 if (failure.length) {
134 var notification = new Notify.Notification({
135 summary: "Git Live ERROR!!",
136 body : failure.join("\n")
140 notification.set_timeout(5000); // show errros for longer
143 this.queueRunning = false;
146 shouldIgnore: function(f)
148 if (f.name[0] == '.') {
150 if (f.name == '.htaccess') {
156 if (f.name.match(/~$/)) {
159 // ignore anything in top level!!!!
160 if (!f.vpath.length) {
168 parsePath: function(f) {
170 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
172 f.gitpath = gitlive + '/' + vpath_ar.shift();
173 f.vpath = vpath_ar.join('/');
180 onChanged : function(src)
182 return; // always ignore this..?
183 //this.parsePath(src);
185 onChangesDoneHint : function(src)
188 if (this.shouldIgnore(src)) {
193 if (typeof(this.just_created[src.path]) !='undefined') {
194 delete this.just_created[src.path];
195 this.lastAdd = new Date();
197 [ src.gitpath, 'add', src.vpath ],
198 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
204 this.lastAdd = new Date();
206 [ src.gitpath, 'add', src.vpath ],
207 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
214 onDeleted : function(src)
217 if (this.shouldIgnore(src)) {
220 // should check if monitor needs removing..
221 // it should also check if it was a directory.. - so we dont have to commit all..
223 this.lastAdd = new Date();
225 [ src.gitpath, 'rm' , src.vpath ],
226 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
232 onCreated : function(src)
235 if (this.shouldIgnore(src)) {
239 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
240 this.just_created[src.path] = true;
241 return; // we do not handle file create flags... - use done hint.
243 // director has bee created
244 this.monitor(src.path);
245 this.lastAdd = new Date();
247 [ src.gitpath, 'add' , src.vpath, { all: true } ],
248 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
254 onAttributeChanged : function(src) {
256 if (this.shouldIgnore(src)) {
259 this.lastAdd = new Date();
261 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
267 onMoved : function(src,dest)
270 this.parsePath(dest);
272 if (src.gitpath != dest.gitpath) {
274 this.onCreated(dest);
275 this.onChangedDoneHint(dest);
278 // needs to handle move to/from unsupported types..
280 if (this.shouldIgnore(src)) {
283 if (this.shouldIgnore(dest)) {
286 this.lastAdd = new Date();
288 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
289 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
290 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
301 function errorDialog(data) {
302 var msg = new Gtk.MessageDialog({
303 message_type: Gtk.MessageType.ERROR,
304 buttons : Gtk.ButtonsType.OK,
316 // need a better icon...
319 Notify.init("gitlive");
320 monitor.add(GLib.get_home_dir() + "/gitlive");
323 //icon.signal["activate"].connect(on_left_click);