SF.net SVN: fclient: [249] trunk/sandbox/fcp/fcp_lib/tools.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-26 09:07:54
|
Revision: 249
http://fclient.svn.sourceforge.net/fclient/?rev=249&view=rev
Author: jurner
Date: 2008-02-26 01:07:59 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
added tools module
Added Paths:
-----------
trunk/sandbox/fcp/fcp_lib/tools.py
Added: trunk/sandbox/fcp/fcp_lib/tools.py
===================================================================
--- trunk/sandbox/fcp/fcp_lib/tools.py (rev 0)
+++ trunk/sandbox/fcp/fcp_lib/tools.py 2008-02-26 09:07:59 UTC (rev 249)
@@ -0,0 +1,57 @@
+"""Fcp tools and helpers"""
+
+import os
+#**********************************************************************
+# namespace helpers
+#**********************************************************************
+def saveReadFile(fpath):
+ """Reads contents of a file in the savest manner possible
+ @param fpath: file to write
+ @return: contents of the file if successful, None otherwise
+ """
+ read = None
+ try:
+ fp = open(fpath, 'rb')
+ except: pass
+ else:
+ try:
+ read = fp.read()
+ except: pass
+ fp.close()
+ return read
+
+def saveRemoveFile(fpath):
+ """Savely removes a file
+ @param fpath: filepath of the file to remove or None
+ @return: True if the file was removed, False otherwise
+ """
+ if fpath is not None:
+ if os.path.isfile(fpath):
+ try:
+ os.remove(fpath)
+ except Exception, d:
+ pass
+ else:
+ return True
+ return False
+
+
+def saveWriteFile(fpath, data):
+ """Writes data to a file in the savest manner possible
+ @param fpath: file to write
+ @param data: data to write to file
+ @return: True if successful, False otherwise
+ """
+ written = False
+ try:
+ fp = open(fpath, 'wb')
+ except: pass
+ else:
+ try:
+ fp.write(data)
+ written = True
+ except:
+ fp.Close()
+ else:
+ fp.close()
+ return written
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|