generate gjs documentation, run under gjs
[gnome.introspection-doc-generator] / File.js
diff --git a/File.js b/File.js
index 7cbed3d..c09d036 100755 (executable)
--- a/File.js
+++ b/File.js
@@ -1,8 +1,10 @@
 // <script type ="text/Javascript">
-GLib = imports.gi.GLib;
-Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gio  = imports.gi.Gio;
+
+//const String  = imports.String.String;
+const console = imports.console.console;
 
-String  = imports.String.String; 
 /**
 * @namespace File
 * 
@@ -21,9 +23,8 @@ var File = {
 
     SEPARATOR : '/',
 
- // fixme - this needs a bitter location.. 
+    // fixme - this needs a bitter location..
     // they where in a string class before, but  overriding String methods is not a good normally a good idea..
-       
     rtrim : function (s,toTrim) {
         if (s.substr(s.length - toTrim.length) == toTrim) {
             return s.slice(0, s.length - toTrim.length);
@@ -31,6 +32,7 @@ var File = {
    
         return s;
     },
+
     trim : function (s,toTrim) {
         var out = this.ltrim(s,toTrim);
         out = this.rtrim(out,toTrim);
@@ -60,18 +62,28 @@ var File = {
         }
         return out;
     }, 
+
     read : function (path) {
         var out = {};
-        GLib.file_get_contents(path, out, null, null);
-        return out['value'];
+        if (typeof(Seed) == 'undefined') {
+            var ret;
+            var err;
+            [ret, out, err] = GLib.file_get_contents(path, out, null, null);
+            return out;
+        } else {
+            GLib.file_get_contents(path, out, null);
+            return out['value'];
+        }
     },
 
     isFile : function (path) {
       return GLib.file_test(path, GLib.FileTest.IS_REGULAR);
     },
+
     exists : function (path) {
       return GLib.file_test(path, GLib.FileTest.EXISTS);
     },
+
     isDirectory : function (path) {
       return GLib.file_test(path, GLib.FileTest.IS_DIR);
     },
@@ -79,7 +91,8 @@ var File = {
     list : function (path) {
         var listing = [];
 
-        var f = Gio.file_new_for_path(String(path));
+        //var f = Gio.file_new_for_path(String(path));
+        var f = Gio.file_new_for_path(path);
         var file_enum = f.enumerate_children(Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, Gio.FileQueryInfoFlags.NONE, null);
 
         var next_file = null;
@@ -96,7 +109,8 @@ var File = {
     },
 
     mtime : function (path) {
-        var f = Gio.file_new_for_path(String(path));
+        //var f = Gio.file_new_for_path(String(path));
+        var f = Gio.file_new_for_path(path);
         var mtime = new GLib.TimeVal();
 
         var info = f.query_info(Gio.FILE_ATTRIBUTE_TIME_MODIFIED, Gio.FileQueryInfoFlags.NONE, null);
@@ -106,7 +120,8 @@ var File = {
     },
 
     canonical : function (path) {
-        var f = Gio.file_new_for_path(String(path));
+        //var f = Gio.file_new_for_path(String(path));
+        var f = Gio.file_new_for_path(path);
         var can = f.resolve_relative_path('');
         return can.get_path();
     },
@@ -118,11 +133,13 @@ var File = {
      * 
      */
     write : function (path, string) {
-        var f = Gio.file_new_for_path(String(path));
+        //var f = Gio.file_new_for_path(String(path));
+        var f = Gio.file_new_for_path(path);
         var data_out = new Gio.DataOutputStream({base_stream:f.replace(null, false, Gio.FileCreateFlags.NONE, null)});
         data_out.put_string(string, null);
         data_out.close(null);
     },
+
     /**
      * append
      * @arg path {String} File to write to
@@ -130,13 +147,15 @@ var File = {
      * 
      */
     append : function (path, string) {
-        var f = Gio.file_new_for_path(String(path));
+        //var f = Gio.file_new_for_path(String(path));
+        var f = Gio.file_new_for_path(path);
         var data_out = new Gio.DataOutputStream({
                 base_stream:f.append_to(Gio.FileCreateFlags.NONE, null)
         });
         data_out.put_string(string, null);
         data_out.close(null);
     },
+
     /**
      * remove 
      * Delete a file.
@@ -146,9 +165,11 @@ var File = {
      */
     remove : function (path)
     {
-        var f = Gio.file_new_for_path(String(path));
+        //var f = Gio.file_new_for_path(String(path));
+        var f = Gio.file_new_for_path(path);
         return f['delete']();
     },
+
     /**
      * silentRecursiveCopy
      * copy files recursively from fromDir, silently ignore them if they already exist in toDir
@@ -160,45 +181,50 @@ var File = {
      * 
      */
     silentRecursiveCopy : function (fromDir, toDir, opts) {
-        
+
         var filesToCopy = File.recursiveListing(fromDir);
         var srcPath, destPath, src, dest;
         if (typeof(opts) =='undefined') {
             opts = Gio.FileCopyFlags.NONE;
         }
-        
+
         for (var index in filesToCopy) {
-            srcPath = File.join(String(fromDir), filesToCopy[index]);
-            destPath = File.join(String(toDir), filesToCopy[index]);
+            //srcPath  = File.join(String(fromDir), filesToCopy[index]);
+            //destPath = File.join(String(toDir), filesToCopy[index]);
+            srcPath  = File.join(fromDir, filesToCopy[index]);
+            destPath = File.join(toDir,   filesToCopy[index]);
 
             if (File.isDirectory(srcPath) && !File.isDirectory(destPath)) {
                 File.mkdir(destPath);
                 continue;
             }
+
             // source is not file..?!?!?
             if (!File.isFile(srcPath)) {
                 continue;
             }
+
             if (File.isFile(destPath) && opts == Gio.FileCopyFlags.NONE) {
                 // do not overwrite.. - if file exists and we are not flaged to overwrite.
                 continue;
             }
-            
+
             File.copyFile(srcPath, destPath, opts);
-           
         }
     },
-    
+
     /**
      * mkdir
      * make a directory..
      * @arg {String} dstPath directory to make
      */
     mkdir : function (destPath) {
-        var dest = Gio.file_new_for_path(String(destPath));
-        
+        //var dest = Gio.file_new_for_path(String(destPath));
+        var dest = Gio.file_new_for_path(destPath);
+
         return dest.make_directory(null, null);
     },
+
     /**
      * copyFile
      * @arg {String} src source path
@@ -211,11 +237,18 @@ var File = {
             opts = Gio.FileCopyFlags.NONE;
         }
         var dest = Gio.file_new_for_path(String(destPath));
-        var src = Gio.file_new_for_path(String(srcPath));
+        //var dest = Gio.file_new_for_path(destPath);
+        var src  = Gio.file_new_for_path(String(srcPath));
+        //var src  = Gio.file_new_for_path(srcPath);
 
         // a bit of a hack for the fact that Gio.File.copy arguments
         // can be nulled, but not according to the GIR file
-        return src.copy(dest, opts);
+        //return src.copy(dest, opts);
+        if (typeof(Seed) != 'undefined')
+            return src.copy(dest, opts, null);
+        else
+            return src.copy(dest, opts, null, null);
+
     },
 
     recursiveListing : function (dir) {