Fix #5662 - Gitlive - create a tracking branch
[gitlive] / old_seed_version / Netrc.js
1 const GLib = imports.gi.GLib;
2
3 const File  = imports.File.File;
4
5 /**
6  * usage:
7  * var cfg = Netrc.forHost('www.google.com');
8  * var uname = cfg.login
9  * var pass = cfg.password
10  *
11  *
12  */
13 Netrc = {
14     
15     forHost: function(name)
16     {
17         try {
18             return this._data[name];
19         } catch(e) {
20             throw "Host " + name + " was not found in netrc file (or parser could not read file..)\n";
21         }
22     
23     },
24     
25     _data : {},
26     /**
27      * private - called at the bottom..
28      */
29     _load : function()
30     {
31         
32         var netrc = File.read(GLib.get_home_dir() + "/.netrc");
33         var authdata = {};
34         netrc.split("\n").forEach(function(nl) {
35             var line = {};
36             var k = false
37              
38             nl.replace(/\s+$/,'').replace(/^\s+/,'').split(/\s+/).forEach(function(kv) {
39               
40                 if (!k) {
41                     k = kv;
42                     return
43                 }
44                 line[k] = kv
45                 k = false;
46            });
47                
48            authdata[line.machine] = line;
49             
50         });
51         this._data = authdata;
52          
53     }
54     
55   
56     
57     
58 }
59 // load the file up.
60 Netrc._load();