Forráskód Böngészése

implement most of Sys

Simon Krajewski 11 éve
szülő
commit
ce1117e4a6
4 módosított fájl, 25 hozzáadás és 22 törlés
  1. 11 7
      std/python/_std/Sys.hx
  2. 4 4
      std/python/lib/Os.hx
  3. 4 2
      std/python/lib/Subprocess.hx
  4. 6 9
      std/python/lib/Sys.hx

+ 11 - 7
std/python/_std/Sys.hx

@@ -23,23 +23,25 @@ class Sys {
 	}
 
 	public static function args() : Array<String> {
-		return [];
+		return python.lib.Sys.argv;
 	}
 
 	public static function getEnv( s : String ) : String {
-		return "";
+		return python.lib.Os.environ.get(s, null);
 	}
 
 	public static function putEnv( s : String, v : String ) : Void {
-
+		python.lib.Os.environ.set(s, v);
 	}
 
 	public static function environment() : haxe.ds.StringMap<String> {
-		return new haxe.ds.StringMap();
+		var map = new haxe.ds.StringMap();
+		untyped map.h = python.lib.Os.environ;
+		return map;
 	}
 
 	public static function sleep( seconds : Float ) : Void {
-
+		python.lib.Time.sleep(seconds);
 	}
 
 	public static function setTimeLocale( loc : String ) : Bool {
@@ -47,10 +49,11 @@ class Sys {
 	}
 
 	public static function getCwd() : String {
-		return "";
+		return python.lib.Os.getcwd();
 	}
 
 	public static function setCwd( s : String ) : Void {
+		python.lib.Os.chdir(s);
 	}
 
 	public static function systemName() : String {
@@ -58,7 +61,8 @@ class Sys {
 	}
 
 	public static function command( cmd : String, ?args : Array<String> ) : Int {
-		return 0;
+		var args = args == null ? [cmd] : [cmd].concat(args);
+		return python.lib.Subprocess.call(args);
 	}
 
 	public static function cpuTime() : Float {

+ 4 - 4
std/python/lib/Os.hx

@@ -38,6 +38,8 @@ extern class Os {
 	public static function unlink (path:String):Void;
 	public static function remove (path:String):Void;
 
+	public static function getcwd():String;
+
 	public static function getcwdb():Bytes;
 
 	public static function removedirs (path:String):Void;
@@ -56,16 +58,14 @@ extern class Os {
 
 	public static function walk (top:String, topdown:Bool = true, onerror:OSError->Void = null, followlinks:Bool = false):Tup3<String, Array<String>, Array<String>>;
 
-	//public static inline function environ ():Dict<String, String>;
-
 	public static var sep(default, null) : String;
 	public static var pathsep(default, null):String;
-	
+
 	public static function makedirs (path:String, mode : Int = 511 /* Oktal 777 */, exist_ok:Bool = false):Void;
 
 	public static function mkdir (path:String, mode : Int = 511 /* Oktal 777 */):Void;
 
-	static function __init__ ():Void 
+	static function __init__ ():Void
 	{
 		python.Macros.importAs("os", "python.lib.Os");
 	}

+ 4 - 2
std/python/lib/Subprocess.hx

@@ -25,9 +25,11 @@ extern class Subprocess {
 
 	public static var PIPE:Dynamic;
 
-	public static var STDOUT:Dynamic;	
+	public static var STDOUT:Dynamic;
 
-	static function __init__ ():Void 
+	public static function call(args:Array<String>):Int;
+
+	static function __init__ ():Void
 	{
 		python.Macros.importAs("subprocess", "python.lib.Subprocess");
 	}

+ 6 - 9
std/python/lib/Sys.hx

@@ -1,16 +1,13 @@
-
 package python.lib;
 
 import python.lib.io.RawIOBase;
 import python.lib.io.TextIOBase;
 import python.lib.Types;
 
-
-
-
-
 extern class Sys {
 
+	public static var argv(default, never):Array<String>;
+
 	public static function exit (x:Int):Void;
 
 	public static function getfilesystemencoding():String;
@@ -18,15 +15,15 @@ extern class Sys {
 	public static var version:String;
 
 	public static var stdout(default, never):TextIOBase;
-	
+
 
 	public static function getsizeof (t:Dynamic):Int;
 
 	public static var maxsize:Int;
-	
-	static function __init__ ():Void 
+
+	static function __init__ ():Void
 	{
 		python.Macros.importAs("sys", "python.lib.Sys");
 	}
-	
+
 }