sync
[gitlive] / old_seed_version / Netrc.js
diff --git a/old_seed_version/Netrc.js b/old_seed_version/Netrc.js
new file mode 100644 (file)
index 0000000..52f287e
--- /dev/null
@@ -0,0 +1,60 @@
+const GLib = imports.gi.GLib;
+
+const File  = imports.File.File;
+
+/**
+ * usage:
+ * var cfg = Netrc.forHost('www.google.com');
+ * var uname = cfg.login
+ * var pass = cfg.password
+ *
+ *
+ */
+Netrc = {
+    
+    forHost: function(name)
+    {
+        try {
+            return this._data[name];
+        } catch(e) {
+            throw "Host " + name + " was not found in netrc file (or parser could not read file..)\n";
+        }
+    
+    },
+    
+    _data : {},
+    /**
+     * private - called at the bottom..
+     */
+    _load : function()
+    {
+        
+        var netrc = File.read(GLib.get_home_dir() + "/.netrc");
+        var authdata = {};
+        netrc.split("\n").forEach(function(nl) {
+            var line = {};
+            var k = false
+             
+            nl.replace(/\s+$/,'').replace(/^\s+/,'').split(/\s+/).forEach(function(kv) {
+              
+                if (!k) {
+                    k = kv;
+                    return
+                }
+                line[k] = kv
+                k = false;
+           });
+               
+           authdata[line.machine] = line;
+            
+        });
+        this._data = authdata;
+         
+    }
+    
+  
+    
+    
+}
+// load the file up.
+Netrc._load();
\ No newline at end of file