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) {
94 var sp = Git.run.apply(Git,cmd);
96 switch (sp.result * 1) {
98 success.push(sp.args.join(' '));
99 if (sp.output.length) success.push(sp.output + '');
100 // if (sp.stderr.length) success.push(sp.stderr + '');
103 failure.push(sp.args.join(' '));
104 if (sp.output.length) failure.push(sp.output);
105 if (sp.stderr.length) failure.push(sp.stderr);
112 repos.forEach(function(r) {
113 var sp = Git.run(r , 'push', { all: true } );
120 if (success.length) {
121 print(success.join("\n"));
122 var notification = new Notify.Notification({
123 summary: "Git Live Commited",
124 body : success.join("\n")
128 notification.set_timeout(2000);
131 if (failure.length) {
133 var notification = new Notify.Notification({
134 summary: "Git Live ERROR!!",
135 body : failure.join("\n")
139 notification.set_timeout(2000);
142 this.queueRunning = false;
145 shouldIgnore: function(f)
147 if (f.name[0] == '.') {
149 if (f.name == '.htaccess') {
155 if (f.name.match(/~$/)) {
158 // ignore anything in top level!!!!
159 if (!f.vpath.length) {
167 parsePath: function(f) {
169 var vpath_ar = f.path.substring(gitlive.length +1).split('/');
171 f.gitpath = gitlive + '/' + vpath_ar.shift();
172 f.vpath = vpath_ar.join('/');
179 onChanged : function(src)
181 return; // always ignore this..?
182 //this.parsePath(src);
184 onChangesDoneHint : function(src)
187 if (this.shouldIgnore(src)) {
192 if (typeof(this.just_created[src.path]) !='undefined') {
193 delete this.just_created[src.path];
194 this.lastAdd = new Date();
196 [ src.gitpath, 'add', src.vpath ],
197 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
203 this.lastAdd = new Date();
205 [ src.gitpath, 'add', src.vpath ],
206 [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
213 onDeleted : function(src)
216 if (this.shouldIgnore(src)) {
219 // should check if monitor needs removing..
220 // it should also check if it was a directory.. - so we dont have to commit all..
222 this.lastAdd = new Date();
224 [ src.gitpath, 'rm' , src.vpath ],
225 [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
231 onCreated : function(src)
234 if (this.shouldIgnore(src)) {
238 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
239 this.just_created[src.path] = true;
240 return; // we do not handle file create flags... - use done hint.
242 // director has bee created
243 this.monitor(src.path);
244 this.lastAdd = new Date();
246 [ src.gitpath, 'add' , src.vpath, { all: true } ],
247 [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
253 onAttributeChanged : function(src) {
255 if (this.shouldIgnore(src)) {
258 this.lastAdd = new Date();
260 [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
266 onMoved : function(src,dest)
269 this.parsePath(dest);
271 if (src.gitpath != dest.gitpath) {
273 this.onCreated(dest);
274 this.onChangedDoneHint(dest);
277 // needs to handle move to/from unsupported types..
279 if (this.shouldIgnore(src)) {
282 if (this.shouldIgnore(dest)) {
285 this.lastAdd = new Date();
287 [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
288 [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
289 { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
300 function errorDialog(data) {
301 var msg = new Gtk.MessageDialog({
302 message_type: Gtk.MessageType.ERROR,
303 buttons : Gtk.ButtonsType.OK,
315 // need a better icon...
318 Notify.init("gitlive");
319 monitor.add(GLib.get_home_dir() + "/gitlive");
322 //icon.signal["activate"].connect(on_left_click);