+++ /dev/null
-///<script type="text/javascript">
-
-Gio = imports.gi.Gio;
-GLib = imports.gi.GLib;
-
-Spawn = imports.Spawn.Spawn;
-File = imports.File.File;
-/**
- * @namespace Git
- *
- * Class to handle git operations..???
- *
- * usage:
- *
- * Git = import.Git.Git;
- *
- * var g = new Git( '/home/me/git' );
- *
- * g.run('commit', { all : true , message : 'test' }, 'filename',)
- *
- * or
- * print(Git.run('/home/me/git', 'log'))
- *
- *
- *
- */
-
-
-/**
- * @class Git
- * @param repo {String} directory that the repo is in, either bare or not.
- *
- *
- */
-//var prototypeInit = false;
-function Git( repo) {
-
- if (!GLib.file_test(repo, GLib.FileTest.IS_DIR)) {
- throw "Repo does not exist";
- }
- this.repo = repo;
- /*
- if (!prototypeInit) {
- // proto type on set up yet..
- // we could list this to generate methods.. /usr/lib/git-core/
- var props = Gil.prototypeInit();
- for (var i in props) {
- this[i]= props[i];
- }
- }
- */
-
-}
-Git.prototype = {
- repo : '',
- /**
- * @method run
- * @arg command {String} command to run
- * @arg arguments.... {String|Object} arguments to send to command
- * { xxxx : yyyy} -> --xxxx YYYYY
- * { x : yyyy} -> -x yyyy
- *
- */
- run : function() {
- //print("GIT RUN");
- var args = ['git'];
-
-
- for (var i=0;i< arguments.length;i++) {
- if (typeof(arguments[i]) == 'string') {
- args.push(arguments[i]);
- continue;
- }
- if (typeof(arguments[i]) == 'object') {
- for(var k in arguments[i]) {
- var v = arguments[i][k];
-
- args.push(k.length > 1 ? ('--' + k) : ('-' + k));
-
- if (v === true) {
- continue;
- }
- args.push(v);
- }
- }
-
- }
- var env = [ "HOME=" + GLib.get_home_dir() ];
-
- if (File.exists(this.repo + '/.git/config')) {
- env.push("GITPATH=" + this.repo );
- }
-
-
- //print(args.join( ' '));
- var sp = new Spawn({
- //env : [ "GITPATH=" + this.repo , "HOME=" + GLib.get_home_dir() ],
- env : env,
- cwd : this.repo,
- args: args,
- debug: true,
- exceptions : false,
- async : false
- });
- var out = sp.run();
- // parse output for some commands ?
- return out;
- }
-}
-
-
-/**
- * @function run
- * @arg command {String} command to run
- * @arg arguments.... {String|Object} arguments to send to command
- *
- *
- */
-
-function run() {
- // print("Git.run()");
- var args = Array.prototype.slice.call(arguments);
- //print(JSON.stringify(args));
- var repo = args.shift(args);
- var x = new Git(repo);
- // print(JSON.stringify(args));
- return x.run.apply(x, args);
-
-}
-
-// test.
-
-//print(run('/home/alan/gitlive/gitlive', 'log'));
-
-
-
* }
* });
*
+*
+*
+* CRITICAL - needs this change to gir in GLib-2.0.gir g_spawn_async_with_pipes
+*
+ <parameter name="argv" transfer-ownership="none">
+ <array c:type="gchar**">
+ <type name="utf8"/>
+ </array>
+ </parameter>
+ <parameter name="envp" transfer-ownership="none" allow-none="1">
+ <array c:type="gchar**">
+ <type name="utf8"/>
+ </array>
+ </parameter>
+*
+*
+*<method name="read_line"
+ c:identifier="g_io_channel_read_line"
+ throws="1">
+ <return-value transfer-ownership="none">
+ <type name="IOStatus" c:type="GIOStatus"/>
+ </return-value>
+ <parameters>
+ <parameter name="str_return" transfer-ownership="full" direction="out">
+ <type name="utf8" c:type="gchar**"/>
+ </parameter>
+ <parameter name="length" transfer-ownership="none" direction="out">
+ <type name="gsize" c:type="gsize*"/>
+ </parameter>
+ <parameter name="terminator_pos" transfer-ownership="none" direction="out">
+ <type name="gsize" c:type="gsize*"/>
+ </parameter>
+ </parameters>
+ </method>
+*
+*
+*
*
*/
cwd: false,
args: false,
exceptions : false,
- debug : false,
+ debug : true,
/**
* @property output {String} resulting output
*/
var ret = {};
if (this.debug) {
- print("spawn : " + this.args.join(" "));
+ print("cd " + this.cwd +";" + this.args.join(" "));
}
GLib.spawn_async_with_pipes(this.cwd, this.args, this.env,
GLib.SpawnFlags.DO_NOT_REAP_CHILD + GLib.SpawnFlags.SEARCH_PATH ,
null, null, ret);
+ print(JSON.stringify(ret));
this.pid = ret.child_pid;
if (this.debug) {
}
+ this.in_ch = GLib.io_channel_unix_new(ret.standard_input);
+ this.out_ch = GLib.io_channel_unix_new(ret.standard_output);
+ this.err_ch = GLib.io_channel_unix_new(ret.standard_error);
+
+ // make everything non-blocking!
+ this.in_ch.set_flags (GLib.IOFlags.NONBLOCK);
+ this.out_ch.set_flags (GLib.IOFlags.NONBLOCK);
+ this.err_ch.set_flags (GLib.IOFlags.NONBLOCK);
+
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, this.pid, function(pid, result) {
_this.result = result;
if (_this.debug) {
- print("result: " + result);
+ print("child_watch_add : result: " + result);
}
_this.read(_this.out_ch);
_this.read(_this.err_ch);
});
- this.in_ch = GLib.io_channel_unix_new(ret.standard_input);
- this.out_ch = GLib.io_channel_unix_new(ret.standard_output);
- this.err_ch = GLib.io_channel_unix_new(ret.standard_error);
- // make everything non-blocking!
- this.in_ch.set_flags (GLib.IOFlags.NONBLOCK);
- this.out_ch.set_flags (GLib.IOFlags.NONBLOCK);
- this.err_ch.set_flags (GLib.IOFlags.NONBLOCK);
// add handlers for output and stderr.
if (this.debug) {
print("starting main loop");
}
+
ctx = new GLib.MainLoop.c_new (null, false);
ctx.run(false); // wait fore exit?
read: function(ch)
{
var prop = ch == this.out_ch ? 'output' : 'stderr';
+ print("prop: " + prop);
var _this = this;
+
+ //print(JSON.stringify(ch, null,4));
while (true) {
- var x = new GLib.String();
- var status = ch.read_line_string( x);
+ var x = {};
+ var status = ch.read_line(x);
+ //print("READ LINE STRING STATUS: " + status);
+ //print("got: " + JSON.stringify(x, null,4));
+
switch(status) {
case GLib.IOStatus.NORMAL:
+
//write(fn, x.str);
if (this.listeners[prop]) {
- this.listeners[prop].call(this, x.str);
+ this.listeners[prop].call(this, x.str_return);
}
- _this[prop] += x.str;
+ _this[prop] += x.str_return;
if (_this.debug) {
- print(prop + ':' + x.str);
+ print(prop + ':' + x.str_return);
}
continue;
case GLib.IOStatus.AGAIN:
var ret = s.run();
return s.output;
}
-
+ /*
// test
+try {
+ Seed.print(run({
+ args: ['ls', '/tmp'],
+ debug : true
+ }));
+} catch (e) { print(JSON.stringify(e)); }
+
+var secs = (new Date()).getSeconds()
+try {
+Seed.print(run({
+ args: ['/bin/touch', '/tmp/spawntest-' + secs ],
+ debug : true
+}));
+} catch (e) { print( 'Error: ' + JSON.stringify(e)); }
-//Seed.print(run({
-// args: ['ls', '/tmp'],
-// //debug : true
-//}));
-
-
\ No newline at end of file
+ */
+++ /dev/null
-#!/usr/bin/seed
-///<script type="text/javascript">
-/**
-* Git Live
-*
-* inotify hooks for ~/gitlive
-* that commit and push any changes made.
-* Bit like a revision controled backed up file system!?
-*
-*
-* The aims of this
-* A) have a gitlive branch - where all our commits go.. - so they can be replicated on the server
-* B) HEAD branch - where things get merged to..
-* -- eventually on closing issues..
-* -- currently when we switch from one feature to another..
-*
-* CURRENT HEAD?
-* git log -n 1
-* --pretty=format:%H BRANCHNAME
-*
-*
-* Notes on feature branch implementation
-* We need to add a gitlive branch on the remote server..
-* git push origin origin:refs/heads/gitlive
-* git checkout --track -b gitlive origin/gitlive << means pull will use both branches..
-*
-*
-* On our feature tree..
-* git push origin origin:refs/heads/feature_2
-*
-* we clone directory into gitlive_feature/XXXXX
-* git branch issue_XXX
-* git checkout issue_XXX
-*
-* run this on the feature branch it merges and commits..
-* git pull origin master << or gitlive..
-*
-*
-* Standard change file (same bug as before..)
-* cd gitlive
-* commit etc.. (with bug no..)
-* cd featuredir
-* git pull origin gitlive
-* git push
-* cd gitlive
-* git push
-*
-* Change to new bug number..
-* cd featuredir
-* git checkout -b master origin/master
-* git checkout master <<< make sure
-* git pull --squash origin gitlive
-* git commit -m 'done with old bug number'
-* git push
-* cd gitlive
-* git push
-* cd featuredir
-* git push origin origin:refs/heads/feature_XXX
-* git checkout feature_XXX
-* cd gitlive
-* commit etc. (with new bug number)
-* cd featuredir
-* git pull origin gitlive
-* git push
-* cd gitlive
-* git push
-*
-*/
-
-GI = imports.gi.GIRepository
-GLib = imports.gi.GLib;
-
-print(JSON.stringify(GI, null,4));
-// we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
-GI.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
-
-Gio = imports.gi.Gio;
-Gtk = imports.gi.Gtk;
-Notify = imports.gi.Notify;
-
-Spawn = imports.Spawn;
-Git = imports.Git;
-StatusIcon = imports.StatusIcon.StatusIcon;
-Monitor = imports.Monitor.Monitor;
-
-
-//File = imports[__script_path__+'/../introspection-doc-generator/File.js'].File
-Gtk.init (null, null);
-
-var gitlive = GLib.get_home_dir() + "/gitlive";
-
-if (!GLib.file_test(gitlive, GLib.FileTest.IS_DIR)) {
- var msg = new Gtk.MessageDialog({message_type:
- Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - ~/gitlive does not exist."});
- msg.run();
- msg.destroy();
-
- Seed.quit();
-}
-
-
-var monitor = new Monitor({
- /**
- *
- * queue objects
- * action: 'add' | rm | update
- * repo : 'gitlive'
- * file : XXXXX
- *
- *
- *
- */
- action_queue : [],
- queueRunning : false,
-
- start: function()
- {
- var _this = this;
- this.lastAdd = new Date();
-
- // start monitoring first..
- Monitor.prototype.start.call(this);
-
- // then start our queue runner..
- GLib.timeout_add(GLib.PRIORITY_LOW, 500, function() {
- //TIMEOUT", _this.action_queue.length , _this.queueRunning].join(', '));
- if (!_this.action_queue.length || _this.queueRunning) {
- return 1;
- }
- var last = Math.floor(((new Date()) - this.lastAdd) / 100);
- if (last < 4) { // wait 1/2 a seconnd before running.
- return 1;
- }
- _this.runQueue();
- return 1;
- },null,null);
-
-
- var notification = new Notify.Notification({
- summary: "Git Live",
- body : gitlive + "\nMonitoring " + this.monitors.length + " Directories"
- });
-
- notification.set_timeout(2000);
- notification.show();
- },
- /**
- * run the queue.
- * - pulls the items off the queue
- * (as commands run concurrently and new items may get added while it's running)
- * - runs the queue items
- * - pushes upstream.
- *
- */
- runQueue: function()
- {
- this.queueRunning = true;
- var cmds = [];
- //this.queue.forEach(function (q) {
- // cmds.push(q);
- //});
-
- this.action_queue.forEach(function (q) {
- cmds.push(q);
- });
- //this.queue = []; // empty queue!
- this.action_queue = [];
- var success = [];
- var failure = [];
- var repos = [];
- var done = [];
-
- function readResult(sp) {
- switch (sp.result * 1) {
- case 0: // success:
- success.push(sp.args.join(' '));
- if (sp.output.length) success.push(sp.output + '');
- // if (sp.stderr.length) success.push(sp.stderr + '');
- break;
- default:
- failure.push(sp.args.join(' '));
- if (sp.output.length) failure.push(sp.output);
- if (sp.stderr.length) failure.push(sp.stderr);
- break;
- }
- }
-
- cmds.forEach(function(cmd) {
- // prevent duplicate calls..
- if (done.indexOf(JSON.stringify(cmd)) > -1) {
- return;
- }
- done.push(JSON.stringify(cmd));
- // --- we keep a list of repositories that will be pushed to at the end..
-
- if (repos.indexOf(cmd.repo) < 0) {
- repos.push(cmd.repo);
- // Git.run(cmd.repos , 'pull'); // pull before we push!
- }
-
- var gp = gitlive + '/' + cmd.repo;
-
- switch( cmd.action ) {
- case 'add':
- readResult(Git.run(gp, 'add', cmd.file ));
- readResult(Git.run(gp, 'commit', cmd.file, { message: cmd.file} ));
- break;
-
- case 'rm':
- readResult(Git.run(gp, 'rm', cmd.file ));
- readResult(Git.run(gp, 'commit', { all: true, message: cmd.file} ));
- break;
-
- case 'update':
- readResult(Git.run(gp, 'commit', cmd.file , { message: cmd.file} ));
- break;
-
- case 'mv':
- readResult(Git.run(gp, 'mv', cmd.file , cmd.target));
- readResult(Git.run(gp, 'commit', cmd.file , cmd.target,
- { message: 'MOVED ' + cmd.file +' to ' + cmd.target } ));
- break;
- }
-
-
-
- });
-
- // push upstream.
- repos.forEach(function(r) {
- var sp = Git.run(gitlive + '/' +r , 'push', { all: true } );
- if (sp.length) {
- success.push(sp);
- }
-
- });
-
- if (success.length) {
- print(success.join("\n"));
- var notification = new Notify.Notification({
- summary: "Git Live Commited",
- body : success.join("\n")
-
- });
-
- notification.set_timeout(2000);
- notification.show();
- }
- if (failure.length) {
-
- var notification = new Notify.Notification({
- summary: "Git Live ERROR!!",
- body : failure.join("\n")
-
- });
-
- notification.set_timeout(5000); // show errros for longer
- notification.show();
- }
- this.queueRunning = false;
- },
-
- shouldIgnore: function(f)
- {
- if (f.name[0] == '.') {
- // except!
- if (f.name == '.htaccess') {
- return false;
- }
-
- return true;
- }
- if (f.name.match(/~$/)) {
- return true;
- }
- // ignore anything in top level!!!!
- if (!f.vpath.length) {
- return true;
- }
-
- return false;
-
- },
-
- /**
- * set gitpath and vpath
- *
- *
- */
-
- parsePath: function(f)
- {
-
- var vpath_ar = f.path.substring(gitlive.length +1).split('/');
- f.repo = vpath_ar.shift();
- f.gitpath = gitlive + '/' + f.repo;
- f.vpath = vpath_ar.join('/');
-
-
- },
-
- just_created : {},
-
- onChanged : function(src)
- {
- return; // always ignore this..?
- //this.parsePath(src);
- },
-
- /**
- * results in git add + git commit..
- *
- *
- *
- */
-
- onChangesDoneHint : function(src)
- {
- this.parsePath(src);
- if (this.shouldIgnore(src)) {
- return;
- }
-
- var add_it = false;
- if (typeof(this.just_created[src.path]) !='undefined') {
- delete this.just_created[src.path];
- this.lastAdd = new Date();
- //this.queue.push(
- // [ src.gitpath, 'add', src.vpath ],
- // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
- //
- //);
- this.action_queue.push({
- action: 'add',
- repo : src.repo,
- file : src.vpath
- });
-
-
-
- return;
- }
- this.lastAdd = new Date();
- //this.queue.push(
- // [ src.gitpath, 'add', src.vpath ],
- // [ src.gitpath, 'commit', src.vpath, { message: src.vpath} ]
- //
- //);
-
- this.action_queue.push({
- action: 'add',
- repo : src.repo,
- file : src.vpath
- });
-
-
- },
- onDeleted : function(src)
- {
- this.parsePath(src);
- if (this.shouldIgnore(src)) {
- return;
- }
- // should check if monitor needs removing..
- // it should also check if it was a directory.. - so we dont have to commit all..
-
- this.lastAdd = new Date();
- //this.queue.push(
- // [ src.gitpath, 'rm' , src.vpath ],
- // [ src.gitpath, 'commit', { all: true, message: src.vpath} ]
- //
- //);
- this.action_queue.push({
- action: 'rm',
- repo : src.repo,
- file : src.vpath
- });
-
- },
- onCreated : function(src)
- {
- this.parsePath(src);
- if (this.shouldIgnore(src)) {
- return;
- }
-
- if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
- this.just_created[src.path] = true;
- return; // we do not handle file create flags... - use done hint.
- }
- // director has bee created
- this.monitor(src.path);
-
- /*
- since git does not really handle directory adds...
-
- this.lastAdd = new Date();
- this.action_queue.push({
- action: 'add',
- repo : src.repo,
- file : src.vpath
- });
-
- this.queue.push(
- [ src.gitpath, 'add' , src.vpath, { all: true } ],
- [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
-
- );
- */
-
-
- },
- onAttributeChanged : function(src) {
- this.parsePath(src);
- if (this.shouldIgnore(src)) {
- return;
- }
- this.lastAdd = new Date();
-
-
- //this.queue.push(
- // [ src.gitpath, 'commit' , src.vpath, { message: src.vpath} ]
- // );
- this.action_queue.push({
- action: 'update',
- repo : src.repo,
- file : src.vpath
- });
-
-
- },
-
- onMoved : function(src,dest)
- {
- this.parsePath(src);
- this.parsePath(dest);
-
- if (src.gitpath != dest.gitpath) {
- this.onDeleted(src);
- this.onCreated(dest);
- this.onChangedDoneHint(dest);
- return;
- }
- // needs to handle move to/from unsupported types..
-
- if (this.shouldIgnore(src)) {
- return;
- }
- if (this.shouldIgnore(dest)) {
- return;
- }
- this.lastAdd = new Date();
- // this.queue.push(
- // [ src.gitpath, 'mv', '-k', src.vpath, dest.vpath ],
- // [ src.gitpath, 'commit' , src.vpath, dest.vpath ,
- // { message: 'MOVED ' + src.vpath +' to ' + dest.vpath} ]
- // );
-
- this.action_queue.push({
- action: 'mv',
- repo : src.repo,
- file : src.vpath,
- target : dest.vpath
-
- });
-
- }
-
-
-});
-
-
-
-
-function errorDialog(data) {
- var msg = new Gtk.MessageDialog({
- message_type: Gtk.MessageType.ERROR,
- buttons : Gtk.ButtonsType.OK,
- text: data
- });
- msg.run();
- msg.destroy();
-}
-
-
-
-
-
-//
-// need a better icon...
-
-
-StatusIcon.init();
-
-
-Notify.init("gitlive");
-
-monitor.add(GLib.get_home_dir() + "/gitlive");
-monitor.start();
-Gtk.main();
-//icon.signal["activate"].connect(on_left_click);
-