From d35c003cc53d4723d1dfe0d81eeb9bea78cee594 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 31 Dec 2011 16:01:24 +0100 Subject: new crypter plugin API, now decrypting possible for now. --- module/utils/fs.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 module/utils/fs.py (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py new file mode 100644 index 000000000..23f87a326 --- /dev/null +++ b/module/utils/fs.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- + +import os +import sys +from os.path import join +from . import decode, remove_chars + +# File System Encoding functions: +# Use fs_encode before accesing files on disk, it will encode the string properly + +if sys.getfilesystemencoding().startswith('ANSI'): + def fs_encode(string): + if type(string) == unicode: + return string.encode('utf8') + + fs_decode = decode #decode utf8 + +else: + fs_encode = fs_decode = lambda x: x # do nothing + +# FS utilities +def chmod(path, mode): + return os.chmod(fs_encode(path), mode) + +def chown(path, uid, gid): + return os.chown(fs_encode(path), uid, gid) + +def remove(path): + return os.remove(fs_encode(path)) + +def exists(path): + return os.path.exists(fs_encode(path)) + +def makedirs(path, mode=0660): + return os.makedirs(fs_encode(path), mode) + +def listdir(path): + return os.listdir(fs_encode(path)) + +def save_path(name): + #remove some chars + if os.name == 'nt': + return remove_chars(name, '/\\?%*:|"<>') + else: + return remove_chars(name, '/\\"') + +def stat(name): + return os.stat(fs_encode(name)) + +def save_join(*args): + """ joins a path, encoding aware """ + return fs_encode(join(*[x if type(x) == unicode else decode(x) for x in args])) + +def free_space(folder): + folder = fs_encode(folder) + + if os.name == "nt": + import ctypes + + free_bytes = ctypes.c_ulonglong(0) + ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) + return free_bytes.value + else: + from os import statvfs + + s = statvfs(folder) + return s.f_bsize * s.f_bavail \ No newline at end of file -- cgit v1.2.3 From 35742c2cb023ac49ab3056752d2040cdb030cc2b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 1 Jan 2012 13:36:59 +0100 Subject: Happy new Year ! --- module/utils/fs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 23f87a326..037165b6b 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -20,7 +20,10 @@ else: # FS utilities def chmod(path, mode): - return os.chmod(fs_encode(path), mode) + try: + return os.chmod(fs_encode(path), mode) + except : + pass def chown(path, uid, gid): return os.chown(fs_encode(path), uid, gid) -- cgit v1.2.3 From c6fd282189ebf5964ae421ae40d04373701b8357 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 3 Jan 2012 21:11:46 +0100 Subject: fs_encode fix --- module/utils/fs.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 037165b6b..1b5f61c17 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -12,6 +12,7 @@ if sys.getfilesystemencoding().startswith('ANSI'): def fs_encode(string): if type(string) == unicode: return string.encode('utf8') + return string fs_decode = decode #decode utf8 -- cgit v1.2.3 From 1ecdd9f6b53fec45e1d48592e3ff56aa7a576bec Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 8 Jan 2012 16:47:52 +0100 Subject: some cleanups, closed #490 --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 1b5f61c17..03832e368 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -41,7 +41,7 @@ def makedirs(path, mode=0660): def listdir(path): return os.listdir(fs_encode(path)) -def save_path(name): +def save_filename(name): #remove some chars if os.name == 'nt': return remove_chars(name, '/\\?%*:|"<>') -- cgit v1.2.3 From c7ad1cc5b4a5d190a060e3ddd9274c3065da6708 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 13 Jan 2012 23:24:21 +0100 Subject: plugin unit test, closed #499, #500 --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 03832e368..c1927423a 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -35,7 +35,7 @@ def remove(path): def exists(path): return os.path.exists(fs_encode(path)) -def makedirs(path, mode=0660): +def makedirs(path, mode=0777): return os.makedirs(fs_encode(path), mode) def listdir(path): -- cgit v1.2.3 From 828cc89cc9b7a2ecacf98fc73928d988e15f0b98 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 14 Jan 2012 15:49:08 +0100 Subject: captcha and attachments for plugin tester --- module/utils/fs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index c1927423a..350283275 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -35,7 +35,7 @@ def remove(path): def exists(path): return os.path.exists(fs_encode(path)) -def makedirs(path, mode=0777): +def makedirs(path, mode=0755): return os.makedirs(fs_encode(path), mode) def listdir(path): @@ -68,4 +68,4 @@ def free_space(folder): from os import statvfs s = statvfs(folder) - return s.f_bsize * s.f_bavail \ No newline at end of file + return s.f_bsize * s.f_bavail -- cgit v1.2.3 From 58c48fbbbac6b85732d6a4f44ccb1aa126d6117d Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 29 Jan 2012 12:41:21 +0100 Subject: closed #523 --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 350283275..276ff04b5 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -44,7 +44,7 @@ def listdir(path): def save_filename(name): #remove some chars if os.name == 'nt': - return remove_chars(name, '/\\?%*:|"<>') + return remove_chars(name, '/\\?%*:|"<>,') else: return remove_chars(name, '/\\"') -- cgit v1.2.3 From b40b32ee05f611323a7827fad2a25fa0a28dcb24 Mon Sep 17 00:00:00 2001 From: X3n0m0rph59 Date: Sun, 22 Apr 2012 19:56:17 +0200 Subject: a huge pile of spelling fixes --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 276ff04b5..631b25002 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -6,7 +6,7 @@ from os.path import join from . import decode, remove_chars # File System Encoding functions: -# Use fs_encode before accesing files on disk, it will encode the string properly +# Use fs_encode before accessing files on disk, it will encode the string properly if sys.getfilesystemencoding().startswith('ANSI'): def fs_encode(string): -- cgit v1.2.3 From 208b857c3f9b9233037847b9c5d98ab9e958ce19 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 17 Aug 2012 16:11:13 +0200 Subject: renamed default_mobile to mobile --- module/utils/fs.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 631b25002..9b9eb9040 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -38,6 +38,7 @@ def exists(path): def makedirs(path, mode=0755): return os.makedirs(fs_encode(path), mode) +# fs_decode? def listdir(path): return os.listdir(fs_encode(path)) -- cgit v1.2.3 From 265840a2448ec3c87594b3a73e95a364f85aa23b Mon Sep 17 00:00:00 2001 From: godofdream Date: Thu, 30 Aug 2012 00:34:41 +0200 Subject: Fixed free space issue closed #676 --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils/fs.py') diff --git a/module/utils/fs.py b/module/utils/fs.py index 9b9eb9040..1894bc49a 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -69,4 +69,4 @@ def free_space(folder): from os import statvfs s = statvfs(folder) - return s.f_bsize * s.f_bavail + return s.f_frsize * s.f_bavail -- cgit v1.2.3